How to use the tsconfig-paths.loadConfig function in tsconfig-paths

To help you get started, we’ve selected a few tsconfig-paths examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zeit / ncc / src / index.js View on Github external
const existingAssetNames = [filename];
  if (sourceMap) {
    existingAssetNames.push(`${filename}.map`);
    existingAssetNames.push('sourcemap-register.js');
  }
  if (v8cache) {
    existingAssetNames.push(`${filename}.cache`);
    existingAssetNames.push(`${filename}.cache.js`);
  }
  const resolvePlugins = [];
  // add TsconfigPathsPlugin to support `paths` resolution in tsconfig
  // we need to catch here because the plugin will
  // error if there's no tsconfig in the working directory
  try {
    const tsconfig = tsconfigPaths.loadConfig();
    const fullTsconfig = require(tsconfig.configFileAbsolutePath)

    const tsconfigPathsOptions = { silent: true }
    if (fullTsconfig.compilerOptions.allowJs) {
      tsconfigPathsOptions.extensions = SUPPORTED_EXTENSIONS
    }
    resolvePlugins.push(new TsconfigPathsPlugin(tsconfigPathsOptions));

    if (tsconfig.resultType === "success") {
      tsconfigMatchPath = tsconfigPaths.createMatchPath(tsconfig.absoluteBaseUrl, tsconfig.paths);
    }
  } catch (e) {}

  resolvePlugins.push({
    apply(resolver) {
      const resolve = resolver.resolve;
github dyatko / arkit / src / filesystem.ts View on Github external
private resolveTsConfigPaths() {
    const tsConfig = loadConfig(this.config.directory);

    if (tsConfig.resultType === "success") {
      this.tsConfigFilePath = tsConfig.configFileAbsolutePath;
      debug("Found TypeScript config", this.tsConfigFilePath);
      debug("Registering ts-config paths...");
      debug(tsConfig.paths);
      this.tsResolve = createMatchPath(
        tsConfig.absoluteBaseUrl,
        tsConfig.paths,
        tsConfig.mainFields,
        tsConfig.addMatchAll
      );
    } else {
      this.tsResolve = createMatchPath(
        this.config.directory,
        {
github dyatko / arkit / dist / filesystem.js View on Github external
resolveTsConfigPaths() {
        const tsConfig = tsconfig_paths_1.loadConfig(this.config.directory);
        if (tsConfig.resultType === "success") {
            this.tsConfigFilePath = tsConfig.configFileAbsolutePath;
            logger_1.debug("Found TypeScript config", this.tsConfigFilePath);
            logger_1.debug("Registering ts-config paths...");
            logger_1.debug(tsConfig.paths);
            this.tsResolve = tsconfig_paths_1.createMatchPath(tsConfig.absoluteBaseUrl, tsConfig.paths, tsConfig.mainFields, tsConfig.addMatchAll);
        }
        else {
            this.tsResolve = tsconfig_paths_1.createMatchPath(this.config.directory, {
                "~/*": ["*"],
                "@/*": ["*", "src/*"]
            }, undefined, true);
        }
    }
    prepareProject() {
github dividab / tsconfig-paths-webpack-plugin / src / plugin.ts View on Github external
constructor(rawOptions: Partial = {}) {
    this.source = "described-resolve";
    this.target = "resolve";

    const options = Options.getOptions(rawOptions);

    this.extensions = options.extensions;

    const colors = new chalk.constructor({ enabled: options.colors });
    this.log = Logger.makeLogger(options, colors);

    const context = options.context || process.cwd();
    const loadFrom = options.configFile || context;

    const loadResult = TsconfigPaths.loadConfig(loadFrom);
    if (loadResult.resultType === "failed") {
      this.log.logError(`Failed to load ${loadFrom}: ${loadResult.message}`);
    } else {
      this.log.logInfo(
        `tsconfig-paths-webpack-plugin: Using config file at ${
          loadResult.configFileAbsolutePath
        }`
      );
      this.baseUrl = options.baseUrl || loadResult.baseUrl;
      this.absoluteBaseUrl = options.baseUrl
        ? path.resolve(options.baseUrl)
        : loadResult.absoluteBaseUrl;
      this.matchPath = TsconfigPaths.createMatchPathAsync(
        this.absoluteBaseUrl,
        loadResult.paths,
        options.mainFields

tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.

MIT
Latest version published 1 year ago

Package Health Score

74 / 100
Full package analysis