How to use the tsconfig-paths.createMatchPath 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 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;
      resolver.resolve = function (context, path, request, resolveContext, callback) {
        resolve.call(resolver, context, path, request, resolveContext, function (err, result) {
          if (!err) return callback(null, result);
          if (!err.missing || !err.missing.length)
            return callback(err);
          // make not found errors runtime errors
          callback(null, __dirname + '/@@notfound.js' + '?' + (externalMap.get(request) || request));
        });
      };
    }
github Igmat / baset / packages / baset-reader-ts / src / index.ts View on Github external
registerHook = (addHook: AddHook, addFileResolver: AddFileResolver) => {
        const matchPath = createMatchPath(
            this.absoluteBaseUrl,
            this.config.compilerOptions.paths || {},
        );
        addHook(this.compile, { exts: this.exts, matcher: () => true });
        addFileResolver(original =>
            (request: string) => {
                const found = matchPath(request, undefined, undefined, this.exts);

                return found
                    ? original(found)
                    : original(request);
            });
    };
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 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 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,
        {
          "~/*": ["*"],
          "@/*": ["*", "src/*"]
        },
        undefined,
        true
      );
    }
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,
        {
          "~/*": ["*"],
          "@/*": ["*", "src/*"]
        },
        undefined,
        true
      );
    }
  }

tsconfig-paths

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

MIT
Latest version published 2 years ago

Package Health Score

79 / 100
Full package analysis