Skip to content

Commit

Permalink
add support for relative paths to --tsconfig-path argument
Browse files Browse the repository at this point in the history
  • Loading branch information
xxmichas committed Jun 7, 2024
1 parent a4b3999 commit 2c1ca9b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const resolve = require("resolve");
const fs = require("graceful-fs");
const crypto = require("crypto");
const { join, basename, dirname, extname, resolve: pathResolve } = require("path");
const { basename, dirname, extname, isAbsolute, join, resolve: pathResolve } = require("path");
const webpack = require("webpack");
const MemoryFS = require("memory-fs");
const terser = require("terser");
Expand Down Expand Up @@ -110,16 +110,25 @@ function ncc (
existingAssetNames.push(`${filename}.cache${ext}`);
}
const resolvePlugins = [];

let configFileAbsolutePath;
if (tsconfigPath !== undefined) {
configFileAbsolutePath = isAbsolute(tsconfigPath)
? tsconfigPath
: join(process.cwd(), tsconfigPath);
} else {
configFileAbsolutePath = walkParentDirs({
base: process.cwd(),
start: dirname(entry),
filename: 'tsconfig.json',
});
}

// 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
let fullTsconfig = {};
try {
const configFileAbsolutePath = walkParentDirs({
base: process.cwd(),
start: tsconfigPath !== undefined ? dirname(tsconfigPath) : dirname(entry),
filename: tsconfigPath !== undefined ? basename(tsconfigPath) : 'tsconfig.json',
});
fullTsconfig = loadTsconfig(configFileAbsolutePath) || {
compilerOptions: {}
};
Expand Down Expand Up @@ -359,7 +368,7 @@ function ncc (
loader: eval('__dirname + "/loaders/ts-loader.js"'),
options: {
transpileOnly,
configFile: tsconfigPath,
configFile: configFileAbsolutePath,
compiler: eval('__dirname + "/typescript.js"'),
compilerOptions: {
module: 'esnext',
Expand Down

0 comments on commit 2c1ca9b

Please sign in to comment.