How to use tsconfig-paths - 10 common examples

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 trimox / angular-mdc-web / gulpfile.js View on Github external
if (projectDir.includes(' ')) {
  console.error('Error: Cannot run the Angular MDC build tasks if the project is ' +
    'located in a directory with spaces in between. Please rename your project directory.');
  process.exit(1);
}

// Register TS compilation.
require('ts-node').register({
  project: tsconfigPath,
  transpileOnly: true
});

// The gulp tsconfig file maps specific imports to relative paths. In combination with ts-node
// this doesn't work because the JavaScript output will still refer to the imports instead of
// to the relative path. Tsconfig-paths can be used to support path mapping inside of Node.
require('tsconfig-paths').register({
  baseUrl: path.dirname(tsconfigPath),
  paths: tsconfig.compilerOptions.paths
});

require('./tools/gulp/gulpfile');
github siggame / Cerveau / src / core / setup-thread.ts View on Github external
export function setupThread(): void {
    // yes read in sync. We don't want async stuff running without having their
    // tsconfig paths setup, or they will probably break.
    const file = readFileSync("tsconfig.json");
    const tsconfig = parse(file.toString()) as Tsconfig;

    if (!tsconfig.compilerOptions || !tsconfig.compilerOptions.paths) {
        throw new Error("Cannot setup thread as tsconfig has no paths!");
    }

    register({
        baseUrl: "./",
        paths: tsconfig.compilerOptions.paths,
    });
}
github angular / flex-layout / gulpfile.js View on Github external
*/

const path = require('path');

const tsconfigPath = path.join(__dirname, 'tools/gulp/tsconfig.json');
const tsconfig = require(tsconfigPath);

// Register TS compilation.
require('ts-node').register({
  project: tsconfigPath
});

// The gulp tsconfig file maps specific imports to relative paths. In combination with ts-node
// this doesn't work because the JavaScript output will still refer to the imports instead of
// to the relative path. Tsconfig-paths can be used to support path mapping inside of Node.
require('tsconfig-paths').register({
  baseUrl: path.dirname(tsconfigPath),
  paths: tsconfig.compilerOptions.paths
});

require('./tools/gulp/gulpfile');
github penta-jelly / re-radio / server / src / radio.ts View on Github external
/* eslint-disable import/first */
/* eslint-disable import/no-unassigned-import */
require('tsconfig-paths').register({ baseUrl: 'lib', paths: {} });
require('source-map-support/register');
/* eslint-enable import/no-unassigned-import */
import Fs from 'fs';
import Path from 'path';
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { ConfigService } from 'core/config/config.service';
import { EnvVariables } from 'core/config/config.variables';
import { RadioModule } from 'radio/radio.module';

const RADIO_READY_STATE_FILE_PATH = Path.join(__dirname, 'radio.ready');
const REAL_TIME_RADIO_READY_STATE_FILE_PATH = Path.join(__dirname, 'real-time-radio.ready');
Fs.existsSync(RADIO_READY_STATE_FILE_PATH) && Fs.unlinkSync(RADIO_READY_STATE_FILE_PATH);

async function bootstrap() {
github penta-jelly / re-radio / server / src / real-time-radio.ts View on Github external
/* eslint-disable import/first */
/* eslint-disable import/no-unassigned-import */
require('tsconfig-paths').register({ baseUrl: 'lib', paths: {} });
require('source-map-support/register');
/* eslint-enable import/no-unassigned-import */
import Fs from 'fs';
import Path from 'path';
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { ConfigService } from 'core/config/config.service';
import { RealTimeRadioModule } from 'real-time-radio/real-time-radio.module';
import { EnvVariables } from 'core/config/config.variables';

const REAL_TIME_RADIO_READY_STATE_FILE_PATH = Path.join(__dirname, 'real-time-radio.ready');
Fs.existsSync(REAL_TIME_RADIO_READY_STATE_FILE_PATH) && Fs.unlinkSync(REAL_TIME_RADIO_READY_STATE_FILE_PATH);

async function bootstrap() {
  const logger = new Logger('RealTimeRadioService');
github penta-jelly / re-radio / server / src / workers.ts View on Github external
/* eslint-disable import/first */
/* eslint-disable import/no-unassigned-import */
require('tsconfig-paths').register({ baseUrl: 'lib', paths: {} });
require('source-map-support/register');
/* eslint-enable import/no-unassigned-import */
import Path from 'path';
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { DevSeederService } from 'workers/seeder/dev-seeder.service';
import { WorkersModule } from 'workers/workers.module';

const RADIO_READY_STATE_FILE_PATH = Path.join(__dirname, 'radio.ready');

async function bootstrap() {
  const logger = new Logger('Workers');

  logger.log(`Wait until Graphql service response.`);
  // eslint-disable-next-line @typescript-eslint/no-var-requires
  await require('wait-on')({ resources: [RADIO_READY_STATE_FILE_PATH], timeout: 30000 });
github dynatrace-oss / barista / gulpfile.js View on Github external
*/

const path = require('path');

const tsconfigPath = path.join(__dirname, 'tools/gulp/tsconfig.json');
const tsconfig = require(tsconfigPath);

// Register TS compilation.
require('ts-node').register({
  project: tsconfigPath,
});

// The gulp tsconfig file maps specific imports to relative paths. In combination with ts-node
// this doesn't work because the JavaScript output will still refer to the imports instead of
// to the relative path. Tsconfig-paths can be used to support path mapping inside of Node.
require('tsconfig-paths').register({
  baseUrl: path.dirname(tsconfigPath),
  paths: tsconfig.compilerOptions.paths,
});

require('./tools/gulp/gulpfile');
github sharpangles / platform / modules / bootstrap / src / platforms / server / commonjs_module_loader.ts View on Github external
const path = require('path');
            let paths: { [ key: string ]: string[] } = {};
            for (let tsconfigPath in tsconfigPaths) {
                let tsconfig = require(path.isAbsolute(tsconfigPath) ? tsconfigPath : path.resolve(baseUrl, tsconfigPath));
                let tsconfigPathSettings = tsconfig && tsconfig.compilerOptions && tsconfig.compilerOptions.paths;
                if (!tsconfigPathSettings) {
                    continue;
                }
                for (let attrname in tsconfigPathSettings) {
                    // For each path in the tsconfig, push its unique values in the array onto a new or existing array for that module.
                    let existing: string[] = paths.hasOwnProperty(attrname) ? paths[attrname] : (paths[attrname] = []);
                    existing = existing.concat(tsconfigPathSettings[attrname]).filter((val, ind, self) => self.indexOf(val) === ind);
                    paths[attrname] = tsconfigPathSettings[attrname];
                }
            }
            require('tsconfig-paths').register({ baseUrl, paths: paths });
        }
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 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;

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

78 / 100
Full package analysis