From 2c1ca9b4f65dfa58da186ec49e4aa847e5692418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Orkisz?= Date: Fri, 7 Jun 2024 14:20:06 +0200 Subject: [PATCH] add support for relative paths to --tsconfig-path argument --- src/index.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index d35636c8..4737e68d 100644 --- a/src/index.js +++ b/src/index.js @@ -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"); @@ -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: {} }; @@ -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',