Skip to content

Commit 4362983

Browse files
committed
update
1 parent 49820ff commit 4362983

File tree

7 files changed

+24
-28
lines changed

7 files changed

+24
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ myResolver.resolve(
111111
| restrictions | [] | A list of resolve restrictions |
112112
| roots | [] | A list of root paths |
113113
| symlinks | true | Whether to resolve symlinks to their symlinked location |
114-
| tsconfig | "auto" | Path to the tsconfig.json file to use for paths mapping, The default value "auto" means it will try to load tsconfig.json. |
114+
| tsconfig | true | Path to tsconfig.json for paths mapping. Default true loads tsconfig.json, or pass a string path. |
115115
| unsafeCache | false | Use this cache object to unsafely cache the successful requests |
116116

117117
## Plugins

lib/Resolver.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ const {
309309
* @property {string=} relativePath relative path
310310
* @property {boolean=} ignoreSymlinks true when need to ignore symlinks, otherwise false
311311
* @property {boolean=} fullySpecified true when full specified, otherwise false
312-
* @property {TsconfigPathsData | null=} tsconfigPathsData tsconfig file data
313312
* @property {string=} __innerRequest inner request for internal usage
314313
* @property {string=} __innerRequest_request inner request for internal usage
315314
* @property {string=} __innerRequest_relativePath inner relative path for internal usage

lib/ResolverFactory.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ function createOptions(options) {
297297
preferRelative: options.preferRelative || false,
298298
preferAbsolute: options.preferAbsolute || false,
299299
restrictions: new Set(options.restrictions),
300-
tsconfig:
301-
typeof options.tsconfig === "undefined" ? "auto" : options.tsconfig,
300+
tsconfig: typeof options.tsconfig === "undefined" ? true : options.tsconfig,
302301
};
303302
}
304303

lib/TsconfigPathsPlugin.js

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

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

3235
/**
@@ -102,26 +105,23 @@ module.exports = class TsconfigPathsPlugin {
102105
* @returns {Promise<TsconfigPathsData | null>} the pre-processed request
103106
*/
104107
async loadTsconfigPathsData(resolver, request, resolveContext) {
105-
if (typeof request.tsconfigPathsData === "undefined") {
106-
request.tsconfigPathsData =
107-
await TsconfigPathsUtils.loadTsconfigPathsData(
108-
resolver.fileSystem,
109-
this.configFile,
110-
request.path || undefined,
111-
);
108+
if (typeof this.tsconfigPathsData === "undefined") {
109+
this.tsconfigPathsData = await TsconfigPathsUtils.loadTsconfigPathsData(
110+
resolver.fileSystem,
111+
this.configFile,
112+
request.path || undefined,
113+
);
112114
}
113115

114-
const { tsconfigPathsData } = request;
115-
116-
if (!tsconfigPathsData) {
116+
if (!this.tsconfigPathsData) {
117117
return null;
118118
}
119119

120-
for (const fileDependency of tsconfigPathsData.fileDependencies) {
120+
for (const fileDependency of this.tsconfigPathsData.fileDependencies) {
121121
if (resolveContext.fileDependencies) {
122122
resolveContext.fileDependencies.add(fileDependency);
123123
}
124124
}
125-
return tsconfigPathsData;
125+
return this.tsconfigPathsData;
126126
}
127127
};

lib/TsconfigPathsUtils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ async function readTsconfigCompilerOptions(fileSystem, absTsconfigPath) {
224224
* @param {string} baseUrl Base URL for resolving paths
225225
* @returns {Omit<TsconfigPathsData, "fileDependencies">} the resolver options
226226
*/
227-
function pathsToResolveOptions(paths, baseUrl) {
227+
function tsconfigPathsToResolveOptions(paths, baseUrl) {
228228
/** @type {string[]} */
229229
const sortedKeys = sortByLongestPrefix(Object.keys(paths));
230230
/** @type {AliasOption[]} */
@@ -285,7 +285,10 @@ async function loadTsconfigPathsData(
285285
if (!compilerOptions) return null;
286286

287287
return {
288-
...pathsToResolveOptions(compilerOptions.paths, compilerOptions.baseUrl),
288+
...tsconfigPathsToResolveOptions(
289+
compilerOptions.paths,
290+
compilerOptions.baseUrl,
291+
),
289292
fileDependencies,
290293
};
291294
} catch (_e) {

test/tsconfig-paths.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ describe("TsconfigPathsPlugin", () => {
166166
extensions: [".ts", ".tsx"],
167167
mainFields: ["browser", "main"],
168168
mainFiles: ["index"],
169-
tsconfig: "auto",
170169
});
171170

172171
resolver.resolve(

types.d.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ declare interface BaseResolveRequest {
6666
*/
6767
fullySpecified?: boolean;
6868

69-
/**
70-
* tsconfig file data
71-
*/
72-
tsconfigPathsData?: null | TsconfigPathsData;
73-
7469
/**
7570
* inner request for internal usage
7671
*/
@@ -1603,6 +1598,7 @@ declare interface TsconfigPathsData {
16031598
declare class TsconfigPathsPlugin {
16041599
constructor(configFile: string | true);
16051600
configFile: string;
1601+
tsconfigPathsData?: null | TsconfigPathsData;
16061602
apply(resolver: Resolver): void;
16071603

16081604
/**

0 commit comments

Comments
 (0)