From dd70576cdd809d1ddf480f7c956a9c769c32fda4 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 28 Jan 2023 11:45:16 +0100 Subject: [PATCH] leave require.resolve.paths alone [skip ci] --- packages/jest-config/src/normalize.ts | 13 ++++++++----- packages/jest-runner/src/runTest.ts | 3 ++- scripts/buildUtils.mjs | 3 +++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index 23bcf4a1f089..25ef99b2e954 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -60,6 +60,9 @@ export type AllOptions = Config.ProjectConfig & Config.GlobalConfig; const createConfigError = (message: string) => new ValidationError(ERROR, message, DOCUMENTATION_NOTE); +// we wanna avoid webpack trying to be clever +const requireResolve = (module: string) => require.resolve(module); + function verifyDirectoryExists(path: string, key: string) { try { const rootStat = statSync(path); @@ -525,7 +528,7 @@ export default async function normalize( } options.testEnvironment = resolveTestEnvironment({ - requireResolveFunction: require.resolve, + requireResolveFunction: requireResolve, rootDir: options.rootDir, testEnvironment: options.testEnvironment || @@ -667,7 +670,7 @@ export default async function normalize( option && resolveRunner(newOptions.resolver, { filePath: option, - requireResolveFunction: require.resolve, + requireResolveFunction: requireResolve, rootDir: options.rootDir, }); } @@ -951,7 +954,7 @@ export default async function normalize( config: {}, path: resolveWatchPlugin(newOptions.resolver, { filePath: watchPlugin, - requireResolveFunction: require.resolve, + requireResolveFunction: requireResolve, rootDir: options.rootDir, }), }; @@ -960,7 +963,7 @@ export default async function normalize( config: watchPlugin[1] || {}, path: resolveWatchPlugin(newOptions.resolver, { filePath: watchPlugin[0], - requireResolveFunction: require.resolve, + requireResolveFunction: requireResolve, rootDir: options.rootDir, }), }; @@ -995,7 +998,7 @@ export default async function normalize( newOptions.testSequencer = resolveSequencer(newOptions.resolver, { filePath: options.testSequencer || require.resolve(DEFAULT_CONFIG.testSequencer), - requireResolveFunction: require.resolve, + requireResolveFunction: requireResolve, rootDir: options.rootDir, }); diff --git a/packages/jest-runner/src/runTest.ts b/packages/jest-runner/src/runTest.ts index ffb458157587..13b623d21e2b 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -98,7 +98,8 @@ async function runTestInternal( } testEnvironment = resolveTestEnvironment({ ...projectConfig, - requireResolveFunction: require.resolve, + // we wanna avoid webpack trying to be clever + requireResolveFunction: module => require.resolve(module), testEnvironment: customEnvironment, }); } diff --git a/scripts/buildUtils.mjs b/scripts/buildUtils.mjs index a7d909756c76..54cdb2e3b1ca 100644 --- a/scripts/buildUtils.mjs +++ b/scripts/buildUtils.mjs @@ -325,6 +325,9 @@ class IgnoreDynamicRequire { parser.hooks.call .for('require.resolve') .tap('IgnoreDynamicRequire', () => true); + parser.hooks.call + .for('require.resolve.paths') + .tap('IgnoreDynamicRequire', () => true); }); }); }