Skip to content

Commit 04f0e88

Browse files
committed
update
1 parent d038351 commit 04f0e88

11 files changed

+31
-16
lines changed

lib/ResolverFactory.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const { PathType, getType } = require("./util/path");
8585
* @property {boolean=} useSyncFileSystemCalls Use only the sync constraints of the file system calls
8686
* @property {boolean=} preferRelative Prefer to resolve module requests as relative requests before falling back to modules
8787
* @property {boolean=} preferAbsolute Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots
88-
* @property {string=} tsconfig tsconfig file path
88+
* @property {string|boolean=} tsconfig tsconfig file path
8989
*/
9090

9191
/**
@@ -117,7 +117,7 @@ const { PathType, getType } = require("./util/path");
117117
* @property {Set<string | RegExp>} restrictions restrictions
118118
* @property {boolean} preferRelative prefer relative
119119
* @property {boolean} preferAbsolute prefer absolute
120-
* @property {string} tsconfig tsconfig file path
120+
* @property {string|boolean=} tsconfig tsconfig file path
121121
*/
122122

123123
/**
@@ -297,7 +297,8 @@ function createOptions(options) {
297297
preferRelative: options.preferRelative || false,
298298
preferAbsolute: options.preferAbsolute || false,
299299
restrictions: new Set(options.restrictions),
300-
tsconfig: options.tsconfig || "",
300+
tsconfig:
301+
typeof options.tsconfig === "undefined" ? "auto" : options.tsconfig,
301302
};
302303
}
303304

lib/TsconfigPathsPlugin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ const DEFAULT_CONFIG_FILE = "tsconfig.json";
2121

2222
module.exports = class TsconfigPathsPlugin {
2323
/**
24-
* @param {"auto" | string} configFile tsconfig file path
24+
* @param {"auto" | true | string} configFile tsconfig file path
2525
*/
2626
constructor(configFile) {
27-
this.configFile = configFile === "auto" ? DEFAULT_CONFIG_FILE : configFile;
27+
this.configFile = ["auto", true].includes(configFile)
28+
? DEFAULT_CONFIG_FILE
29+
: /** @type {string} */ (configFile);
2830
}
2931

3032
/**

lib/TsconfigPathsUtils.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"use strict";
77

88
const path = require("path");
9+
const { join, normalize } = require("./util/path");
910

1011
/** @typedef {import("./Resolver")} Resolver */
1112
/** @typedef {import("./Resolver").FileSystem} FileSystem */
@@ -65,7 +66,7 @@ function getAbsoluteMappingEntries(paths, baseUrl) {
6566
const mappings = paths[pattern];
6667
// const aliasName = pattern.replace(/\/\*$/, "");
6768
// Convert targets like "dir/*" -> "dir"
68-
const aliasTargets = mappings.map((mapping) => path.join(baseUrl, mapping));
69+
const aliasTargets = mappings.map((mapping) => join(baseUrl, mapping));
6970
if (aliasTargets.length > 0) {
7071
absolutePaths.push({ name: pattern, alias: aliasTargets });
7172
}
@@ -117,7 +118,7 @@ async function loadTsconfigFromExtends(
117118
}
118119

119120
const currentDir = path.dirname(configFilePath);
120-
let extendedConfigPath = path.join(currentDir, extendedConfigValue);
121+
let extendedConfigPath = join(currentDir, extendedConfigValue);
121122

122123
// Check if file exists, if not try node_modules
123124
const exists = await new Promise((resolve) => {
@@ -130,10 +131,9 @@ async function loadTsconfigFromExtends(
130131
extendedConfigValue.includes("/") &&
131132
extendedConfigValue.includes(".")
132133
) {
133-
extendedConfigPath = path.join(
134+
extendedConfigPath = join(
134135
currentDir,
135-
"node_modules",
136-
extendedConfigValue,
136+
normalize(`node_modules/${extendedConfigValue}`),
137137
);
138138
}
139139

@@ -147,7 +147,7 @@ async function loadTsconfigFromExtends(
147147
// but we need to update it so it is relative to the original tsconfig being loaded
148148
if (compilerOptions.baseUrl) {
149149
const extendsDir = path.dirname(extendedConfigValue);
150-
compilerOptions.baseUrl = path.join(extendsDir, compilerOptions.baseUrl);
150+
compilerOptions.baseUrl = join(extendsDir, compilerOptions.baseUrl);
151151
}
152152

153153
return /** @type {Tsconfig} */ (config);
@@ -238,7 +238,7 @@ async function readTsconfigCompilerOptions(fileSystem, absTsconfigPath) {
238238
if (!baseUrl) {
239239
baseUrl = path.dirname(absTsconfigPath);
240240
} else if (!path.isAbsolute(baseUrl)) {
241-
baseUrl = path.join(path.dirname(absTsconfigPath), baseUrl);
241+
baseUrl = join(path.dirname(absTsconfigPath), baseUrl);
242242
}
243243

244244
const paths = compilerOptions.paths || {};
@@ -295,7 +295,7 @@ async function loadTsconfigPathsData(
295295
try {
296296
const absTsconfigPath = path.isAbsolute(configFile)
297297
? configFile
298-
: path.join(context, configFile);
298+
: join(context, configFile);
299299

300300
const result = await readTsconfigCompilerOptions(
301301
fileSystem,

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const getSyncResolver = memoize(() =>
9494
extensions: [".js", ".json", ".node"],
9595
useSyncFileSystemCalls: true,
9696
fileSystem: getNodeFileSystem(),
97+
tsconfig: false,
9798
}),
9899
);
99100

test/alias.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ describe("alias", () => {
4949
},
5050
modules: "/",
5151
useSyncFileSystemCalls: true,
52+
tsconfig: false,
5253
// @ts-expect-error for tests
5354
fileSystem,
5455
});

test/browserField.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe("browserField", () => {
2727
],
2828
useSyncFileSystemCalls: true,
2929
fileSystem: fs,
30+
tsconfig: false,
3031
});
3132
});
3233

test/fallback.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe("fallback", () => {
4040
},
4141
modules: "/",
4242
useSyncFileSystemCalls: true,
43+
tsconfig: false,
4344
// @ts-expect-error for test
4445
fileSystem,
4546
});

test/fullSpecified.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe("fullSpecified", () => {
3737
aliasFields: ["browser"],
3838
fullySpecified: true,
3939
useSyncFileSystemCalls: true,
40+
tsconfig: false,
4041
// @ts-expect-error for test
4142
fileSystem,
4243
});
@@ -49,6 +50,7 @@ describe("fullSpecified", () => {
4950
fullySpecified: true,
5051
resolveToContext: true,
5152
useSyncFileSystemCalls: true,
53+
tsconfig: false,
5254
// @ts-expect-error for test
5355
fileSystem,
5456
});

test/resolve.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@ const fixtures = path.join(__dirname, "fixtures");
88
const asyncContextResolve = resolve.create({
99
extensions: [".js", ".json", ".node"],
1010
resolveToContext: true,
11+
tsconfig: false,
1112
});
1213

1314
const syncContextResolve = resolve.create.sync({
1415
extensions: [".js", ".json", ".node"],
1516
resolveToContext: true,
17+
tsconfig: false,
1618
});
1719

1820
const issue238Resolve = resolve.create({
1921
extensions: [".js", ".jsx", ".ts", ".tsx"],
2022
modules: ["src/a", "src/b", "src/common", "node_modules"],
23+
tsconfig: false,
2124
});
2225

2326
const preferRelativeResolve = resolve.create({
2427
preferRelative: true,
28+
tsconfig: false,
2529
});
2630

2731
/**

test/symlink.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ describe("symlink", () => {
104104

105105
const resolveWithoutSymlinks = resolve.create({
106106
symlinks: false,
107+
tsconfig: false,
107108
});
108109
const resolveSyncWithoutSymlinks = resolve.create.sync({
109110
symlinks: false,
111+
tsconfig: false,
110112
});
111113

112114
for (const pathToIt of [

0 commit comments

Comments
 (0)