11import fs from 'node:fs'
2+ import module from 'node:module'
23import path from 'node:path'
34
45import isNodeCoreModule from '@nolyfill/is-core-module'
@@ -7,7 +8,7 @@ import type { TsConfigResult } from 'get-tsconfig'
78import { createPathsMatcher , getTsconfig } from 'get-tsconfig'
89import type { Version } from 'is-bun-module'
910import { isBunModule } from 'is-bun-module'
10- import { type NapiResolveOptions , ResolverFactory } from 'oxc -resolver'
11+ import { type NapiResolveOptions , ResolverFactory } from 'rspack -resolver'
1112import { stableHash } from 'stable-hash'
1213import { globSync , isDynamicPattern } from 'tinyglobby'
1314import type { SetRequired } from 'type-fest'
@@ -94,7 +95,7 @@ let previousOptionsHash: string
9495let optionsHash : string
9596let cachedOptions : InternalResolverOptions | undefined
9697
97- let prevCwd : string
98+ let cachedCwd : string
9899
99100let mappersCachedOptions : InternalResolverOptions
100101let mappers : Array < {
@@ -160,6 +161,18 @@ export function resolve(
160161 }
161162 }
162163
164+ /**
165+ * {@link https://github.com/webpack/enhanced-resolve/blob/38e9fd9acb79643a70e7bcd0d85dabc600ea321f/lib/PnpPlugin.js#L81-L83 }
166+ */
167+ if ( process . versions . pnp && source === 'pnpapi' ) {
168+ return {
169+ found : true ,
170+ path : module . findPnpApi ( file ) . resolveToUnqualified ( source , file , {
171+ considerBuiltins : false ,
172+ } ) ,
173+ }
174+ }
175+
163176 initMappers ( cachedOptions )
164177
165178 let mappedPaths = getMappedPaths ( source , file , cachedOptions . extensions , true )
@@ -383,18 +396,18 @@ function initMappers(options: InternalResolverOptions) {
383396 if (
384397 mappers . length > 0 &&
385398 mappersCachedOptions === options &&
386- prevCwd === process . cwd ( )
399+ cachedCwd === process . cwd ( )
387400 ) {
388401 return
389402 }
390- prevCwd = process . cwd ( )
403+ cachedCwd = process . cwd ( )
391404 const configPaths = (
392405 typeof options . project === 'string'
393406 ? [ options . project ]
394407 : // eslint-disable-next-line sonarjs/no-nested-conditional
395408 Array . isArray ( options . project )
396409 ? options . project
397- : [ process . cwd ( ) ]
410+ : [ cachedCwd ]
398411 ) // 'tinyglobby' pattern must have POSIX separator
399412 . map ( config => replacePathSeparator ( config , path . sep , path . posix . sep ) )
400413
@@ -432,20 +445,18 @@ function initMappers(options: InternalResolverOptions) {
432445 }
433446
434447 if ( ! tsconfigResult ) {
435- // eslint-disable-next-line unicorn/no-useless-undefined
436- return undefined
448+ return
437449 }
438450
439451 const mapperFn = createPathsMatcher ( tsconfigResult )
440452
441453 if ( ! mapperFn ) {
442- // eslint-disable-next-line unicorn/no-useless-undefined
443- return undefined
454+ return
444455 }
445456
446457 const files =
447- tsconfigResult . config . files === undefined &&
448- tsconfigResult . config . include === undefined
458+ tsconfigResult . config . files == null &&
459+ tsconfigResult . config . include == null
449460 ? // Include everything if no files or include options
450461 globSync ( defaultInclude , {
451462 absolute : true ,
@@ -458,7 +469,7 @@ function initMappers(options: InternalResolverOptions) {
458469 } )
459470 : [
460471 // https://www.typescriptlang.org/tsconfig/#files
461- ...( tsconfigResult . config . files !== undefined &&
472+ ...( tsconfigResult . config . files != null &&
462473 tsconfigResult . config . files . length > 0
463474 ? tsconfigResult . config . files . map ( file =>
464475 path . normalize (
@@ -467,7 +478,7 @@ function initMappers(options: InternalResolverOptions) {
467478 )
468479 : [ ] ) ,
469480 // https://www.typescriptlang.org/tsconfig/#include
470- ...( tsconfigResult . config . include !== undefined &&
481+ ...( tsconfigResult . config . include != null &&
471482 tsconfigResult . config . include . length > 0
472483 ? globSync ( tsconfigResult . config . include , {
473484 absolute : true ,
@@ -487,7 +498,7 @@ function initMappers(options: InternalResolverOptions) {
487498 mapperFn,
488499 }
489500 } )
490- . filter ( isDefined )
501+ . filter ( Boolean )
491502
492503 mappersCachedOptions = options
493504}
@@ -535,19 +546,6 @@ function toNativePathSeparator(p: string) {
535546 )
536547}
537548
538- /**
539- * Check if value is defined.
540- *
541- * Helper function for TypeScript.
542- * Should be removed when upgrading to TypeScript >= 5.5.
543- *
544- * @param {T | null | undefined } value Value
545- * @returns `true` if value is defined, `false` otherwise
546- */
547- function isDefined < T > ( value : T | null | undefined ) : value is T {
548- return value !== null && value !== undefined
549- }
550-
551549/**
552550 * Counts how many characters in strings `a` and `b` are exactly the same and in the same position.
553551 *
0 commit comments