From 871fdf2f062e78e510173ba37d7fcd022581dbdf Mon Sep 17 00:00:00 2001 From: David Michon Date: Fri, 22 Nov 2024 16:16:27 -0800 Subject: [PATCH] [heft-jest] Fix node-modules-symlink-resolver (#5013) Co-authored-by: David Michon --- .../fix-jest-bug_2024-11-22-23-43.json | 10 ++++++++++ heft-plugins/heft-jest-plugin/src/JestRealPathPatch.ts | 7 +------ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 common/changes/@rushstack/heft-jest-plugin/fix-jest-bug_2024-11-22-23-43.json diff --git a/common/changes/@rushstack/heft-jest-plugin/fix-jest-bug_2024-11-22-23-43.json b/common/changes/@rushstack/heft-jest-plugin/fix-jest-bug_2024-11-22-23-43.json new file mode 100644 index 00000000000..772b87caa4d --- /dev/null +++ b/common/changes/@rushstack/heft-jest-plugin/fix-jest-bug_2024-11-22-23-43.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@rushstack/heft-jest-plugin", + "comment": "Fix a bug in `jest-node-modules-symlink-resolver` with respect to evaluating paths that don't exist. Expected behavior in that situation is to return the input path.", + "type": "patch" + } + ], + "packageName": "@rushstack/heft-jest-plugin" +} \ No newline at end of file diff --git a/heft-plugins/heft-jest-plugin/src/JestRealPathPatch.ts b/heft-plugins/heft-jest-plugin/src/JestRealPathPatch.ts index 4f2eb44079e..404af5e3766 100644 --- a/heft-plugins/heft-jest-plugin/src/JestRealPathPatch.ts +++ b/heft-plugins/heft-jest-plugin/src/JestRealPathPatch.ts @@ -5,7 +5,6 @@ import * as path from 'node:path'; import { RealNodeModulePathResolver } from '@rushstack/node-core-library/lib/RealNodeModulePath'; const jestResolvePackageFolder: string = path.dirname(require.resolve('jest-resolve/package.json')); -const jestResolveFileWalkersPath: string = path.resolve(jestResolvePackageFolder, './build/fileWalkers.js'); const jestUtilPackageFolder: string = path.dirname( require.resolve('jest-util/package.json', { paths: [jestResolvePackageFolder] }) @@ -14,11 +13,6 @@ const jestUtilTryRealpathPath: string = path.resolve(jestUtilPackageFolder, './b const { realNodeModulePath }: RealNodeModulePathResolver = new RealNodeModulePathResolver(); -const fileWalkersModule: { - realpathSync: (filePath: string) => string; -} = require(jestResolveFileWalkersPath); -fileWalkersModule.realpathSync = realNodeModulePath; - const tryRealpathModule: { default: (filePath: string) => string; } = require(jestUtilTryRealpathPath); @@ -28,6 +22,7 @@ tryRealpathModule.default = (input: string): string => { } catch (error) { // Not using the helper from FileSystem here because this code loads in every Jest worker process // and FileSystem has a lot of extra dependencies + // These error codes cloned from the logic in jest-util's tryRealpath.js if (error.code !== 'ENOENT' && error.code !== 'EISDIR') { throw error; }