chore: resolve filename in the resolution hook (#18221)

This commit is contained in:
Pavel Feldman 2022-10-20 16:30:34 -04:00 committed by GitHub
parent fb9555fb5d
commit fb643940e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,7 +98,7 @@ const scriptPreprocessor = process.env.PW_TEST_SOURCE_TRANSFORM ?
const builtins = new Set(Module.builtinModules); const builtins = new Set(Module.builtinModules);
export function resolveHook(filename: string, specifier: string): string | undefined { export function resolveHook(filename: string, specifier: string): string | undefined {
if (builtins.has(specifier)) if (specifier.startsWith('node:') || builtins.has(specifier))
return; return;
if (belongsToNodeModules(filename)) if (belongsToNodeModules(filename))
return; return;
@ -154,7 +154,7 @@ export function resolveHook(filename: string, specifier: string): string | undef
for (const ext of ['', '.js', '.ts', '.mjs', '.cjs', '.jsx', '.tsx', '.cjs', '.mts', '.cts']) { for (const ext of ['', '.js', '.ts', '.mjs', '.cjs', '.jsx', '.tsx', '.cjs', '.mts', '.cts']) {
if (fs.existsSync(candidate + ext)) { if (fs.existsSync(candidate + ext)) {
longestPrefixLength = keyPrefix.length; longestPrefixLength = keyPrefix.length;
pathMatchedByLongestPrefix = candidate; pathMatchedByLongestPrefix = candidate + ext;
} }
} }
} }