88const { aliasResolveHandler } = require ( "./AliasUtils" ) ;
99const { modulesResolveHandler } = require ( "./ModulesUtils" ) ;
1010const { readJson } = require ( "./util/fs" ) ;
11- const {
12- PathType : _PathType ,
13- cachedDirname : dirname ,
14- cachedJoin : join ,
15- isSubPath,
16- normalize,
17- } = require ( "./util/path" ) ;
11+ const { PathType : _PathType , isSubPath, normalize } = require ( "./util/path" ) ;
1812
1913/** @typedef {import("./Resolver") } Resolver */
2014/** @typedef {import("./Resolver").ResolveStepHook } ResolveStepHook */
@@ -102,10 +96,11 @@ function substituteConfigDir(pathValue, configDir) {
10296 * Convert tsconfig paths to resolver options
10397 * @param {string } configDir Config file directory
10498 * @param {{ [key: string]: string[] } } paths TypeScript paths mapping
99+ * @param {(rootPath: string, request: string) => string } join join function
105100 * @param {string= } baseUrl Base URL for resolving paths (relative to configDir)
106101 * @returns {TsconfigPathsData } the resolver options
107102 */
108- function tsconfigPathsToResolveOptions ( configDir , paths , baseUrl ) {
103+ function tsconfigPathsToResolveOptions ( configDir , paths , join , baseUrl ) {
109104 // Calculate absolute base URL
110105 const absoluteBaseUrl = ! baseUrl ? configDir : join ( configDir , baseUrl ) ;
111106
@@ -155,10 +150,11 @@ function tsconfigPathsToResolveOptions(configDir, paths, baseUrl) {
155150/**
156151 * Get the base context for the current project
157152 * @param {string } context the context
153+ * @param {(rootPath: string, request: string) => string } join join function
158154 * @param {string= } baseUrl base URL for resolving paths
159155 * @returns {string } the base context
160156 */
161- function getAbsoluteBaseUrl ( context , baseUrl ) {
157+ function getAbsoluteBaseUrl ( context , join , baseUrl ) {
162158 return ! baseUrl ? context : join ( context , baseUrl ) ;
163159}
164160
@@ -295,12 +291,12 @@ module.exports = class TsconfigPathsPlugin {
295291 async _getTsconfigPathsMap ( resolver , request , resolveContext ) {
296292 if ( typeof request . tsconfigPathsMap === "undefined" ) {
297293 try {
298- const absTsconfigPath = join (
294+ const absTsconfigPath = resolver . join (
299295 request . path || process . cwd ( ) ,
300296 this . configFile ,
301297 ) ;
302298 const result = await this . _loadTsconfigPathsMap (
303- resolver . fileSystem ,
299+ resolver ,
304300 absTsconfigPath ,
305301 ) ;
306302
@@ -332,28 +328,29 @@ module.exports = class TsconfigPathsPlugin {
332328 /**
333329 * Load tsconfig.json and build complete TsconfigPathsMap
334330 * Includes main project paths and all referenced projects
335- * @param {FileSystem } fileSystem the file system
331+ * @param {Resolver } resolver the resolver
336332 * @param {string } absTsconfigPath absolute path to tsconfig.json
337333 * @returns {Promise<TsconfigPathsMap> } the complete tsconfig paths map
338334 */
339- async _loadTsconfigPathsMap ( fileSystem , absTsconfigPath ) {
335+ async _loadTsconfigPathsMap ( resolver , absTsconfigPath ) {
340336 /** @type {Set<string> } */
341337 const fileDependencies = new Set ( ) ;
342338 const config = await this . _loadTsconfig (
343- fileSystem ,
339+ resolver ,
344340 absTsconfigPath ,
345341 fileDependencies ,
346342 ) ;
347343
348344 const compilerOptions = config . compilerOptions || { } ;
349- const mainContext = dirname ( absTsconfigPath ) ;
345+ const mainContext = resolver . dirname ( absTsconfigPath ) ;
350346
351347 const baseUrl =
352348 this . baseUrl !== undefined ? this . baseUrl : compilerOptions . baseUrl ;
353349
354350 const main = tsconfigPathsToResolveOptions (
355351 mainContext ,
356352 compilerOptions . paths || { } ,
353+ resolver . join ,
357354 baseUrl ,
358355 ) ;
359356 /** @type {{ [baseUrl: string]: TsconfigPathsData } } */
@@ -368,7 +365,7 @@ module.exports = class TsconfigPathsPlugin {
368365
369366 if ( Array . isArray ( referencesToUse ) ) {
370367 await this . _loadTsconfigReferences (
371- fileSystem ,
368+ resolver ,
372369 mainContext ,
373370 referencesToUse ,
374371 fileDependencies ,
@@ -418,20 +415,22 @@ module.exports = class TsconfigPathsPlugin {
418415
419416 /**
420417 * Load tsconfig from extends path
421- * @param {FileSystem } fileSystem the file system
418+ * @param {Resolver } resolver the resolver
422419 * @param {string } configFilePath current config file path
423420 * @param {string } extendedConfigValue extends value
424421 * @param {Set<string> } fileDependencies the file dependencies
425422 * @param {Set<string> } visitedConfigPaths config paths being loaded (for circular extends detection)
426423 * @returns {Promise<Tsconfig> } the extended tsconfig
427424 */
428425 async _loadTsconfigFromExtends (
429- fileSystem ,
426+ resolver ,
430427 configFilePath ,
431428 extendedConfigValue ,
432429 fileDependencies ,
433430 visitedConfigPaths ,
434431 ) {
432+ const { join, dirname } = resolver ;
433+ const { fileSystem } = resolver ;
435434 const currentDir = dirname ( configFilePath ) ;
436435
437436 // Substitute ${configDir} in extends path
@@ -482,7 +481,7 @@ module.exports = class TsconfigPathsPlugin {
482481 }
483482
484483 const config = await this . _loadTsconfig (
485- fileSystem ,
484+ resolver ,
486485 extendedConfigPath ,
487486 fileDependencies ,
488487 visitedConfigPaths ,
@@ -493,6 +492,7 @@ module.exports = class TsconfigPathsPlugin {
493492 const extendedConfigDir = dirname ( extendedConfigPath ) ;
494493 compilerOptions . baseUrl = getAbsoluteBaseUrl (
495494 extendedConfigDir ,
495+ join ,
496496 compilerOptions . baseUrl ,
497497 ) ;
498498 }
@@ -506,28 +506,29 @@ module.exports = class TsconfigPathsPlugin {
506506 * Load referenced tsconfig projects and store in referenceMatchMap
507507 * Simple implementation matching tsconfig-paths-webpack-plugin:
508508 * Just load each reference and store independently
509- * @param {FileSystem } fileSystem the file system
509+ * @param {Resolver } resolver the resolver
510510 * @param {string } context the context
511511 * @param {TsconfigReference[] } references array of references
512512 * @param {Set<string> } fileDependencies the file dependencies
513513 * @param {{ [baseUrl: string]: TsconfigPathsData } } referenceMatchMap the map to populate
514514 * @returns {Promise<void> }
515515 */
516516 async _loadTsconfigReferences (
517- fileSystem ,
517+ resolver ,
518518 context ,
519519 references ,
520520 fileDependencies ,
521521 referenceMatchMap ,
522522 ) {
523+ const { join, dirname } = resolver ;
523524 await Promise . all (
524525 references . map ( async ( ref ) => {
525526 const refPath = substituteConfigDir ( ref . path , context ) ;
526527 const refConfigPath = join ( join ( context , refPath ) , DEFAULT_CONFIG_FILE ) ;
527528
528529 try {
529530 const refConfig = await this . _loadTsconfig (
530- fileSystem ,
531+ resolver ,
531532 refConfigPath ,
532533 fileDependencies ,
533534 ) ;
@@ -538,6 +539,7 @@ module.exports = class TsconfigPathsPlugin {
538539 referenceMatchMap [ refContext ] = tsconfigPathsToResolveOptions (
539540 refContext ,
540541 refConfig . compilerOptions . paths || { } ,
542+ join ,
541543 refConfig . compilerOptions . baseUrl ,
542544 ) ;
543545 }
@@ -547,7 +549,7 @@ module.exports = class TsconfigPathsPlugin {
547549 Array . isArray ( refConfig . references )
548550 ) {
549551 await this . _loadTsconfigReferences (
550- fileSystem ,
552+ resolver ,
551553 dirname ( refConfigPath ) ,
552554 refConfig . references ,
553555 fileDependencies ,
@@ -563,14 +565,14 @@ module.exports = class TsconfigPathsPlugin {
563565
564566 /**
565567 * Load tsconfig.json with extends support
566- * @param {FileSystem } fileSystem the file system
568+ * @param {Resolver } resolver the resolver
567569 * @param {string } configFilePath absolute path to tsconfig.json
568570 * @param {Set<string> } fileDependencies the file dependencies
569571 * @param {Set<string>= } visitedConfigPaths config paths being loaded (for circular extends detection)
570572 * @returns {Promise<Tsconfig> } the merged tsconfig
571573 */
572574 async _loadTsconfig (
573- fileSystem ,
575+ resolver ,
574576 configFilePath ,
575577 fileDependencies ,
576578 visitedConfigPaths = new Set ( ) ,
@@ -579,7 +581,7 @@ module.exports = class TsconfigPathsPlugin {
579581 return /** @type {Tsconfig } */ ( { } ) ;
580582 }
581583 visitedConfigPaths . add ( configFilePath ) ;
582- const config = await readJson ( fileSystem , configFilePath , {
584+ const config = await readJson ( resolver . fileSystem , configFilePath , {
583585 stripComments : true ,
584586 } ) ;
585587 fileDependencies . add ( configFilePath ) ;
@@ -594,7 +596,7 @@ module.exports = class TsconfigPathsPlugin {
594596 base = { } ;
595597 for ( const extendedConfigElement of extendedConfig ) {
596598 const extendedTsconfig = await this . _loadTsconfigFromExtends (
597- fileSystem ,
599+ resolver ,
598600 configFilePath ,
599601 extendedConfigElement ,
600602 fileDependencies ,
@@ -604,7 +606,7 @@ module.exports = class TsconfigPathsPlugin {
604606 }
605607 } else {
606608 base = await this . _loadTsconfigFromExtends (
607- fileSystem ,
609+ resolver ,
608610 configFilePath ,
609611 extendedConfig ,
610612 fileDependencies ,
0 commit comments