Skip to content

Commit 6a9defb

Browse files
committed
fix: ../../node_modules redirection
1 parent 361d97c commit 6a9defb

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

__fixtures__/simple-project/verify.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function verifyDirectoryStructure() {
2222
assertExists('src/entry1.test.js');
2323
assertExists('src/entry2.test.js');
2424
assertExists('_.._/linked-dependencies/bundled/reporters/default.js');
25-
assertExists('bundled_externals/jest-environment-emit/node.js');
26-
assertExists('bundled_externals/lodash/noop.js');
25+
assertExists('bundled_modules/jest-environment-emit/node.js');
26+
assertExists('bundled_modules/lodash/noop.js');
2727
assertDoesNotExist('node_modules');
2828
assertDoesNotExist('_.._/linked-dependencies/external');
2929
}
@@ -39,8 +39,8 @@ function verifyJestConfig() {
3939
assertEqual(reporters[2][0], '@linked-dependencies/external/reporter', 'reporters[2]');
4040
assertEqual(reporters[3][0], '<rootDir>/customReporter.js', 'reporters[3]');
4141
assertEqual(setupFilesAfterEnv.length, 1, 'setupFilesAfterEnv.length');
42-
assertEqual(setupFilesAfterEnv[0], '<rootDir>/bundled_externals/lodash/noop.js', 'setupFilesAfterEnv[0]');
43-
assertEqual(testEnvironment, '<rootDir>/bundled_externals/jest-environment-emit/node.js', 'testEnvironment');
42+
assertEqual(setupFilesAfterEnv[0], '<rootDir>/bundled_modules/lodash/noop.js', 'setupFilesAfterEnv[0]');
43+
assertEqual(testEnvironment, '<rootDir>/bundled_modules/jest-environment-emit/node.js', 'testEnvironment');
4444
assertEqual(testMatch.length, 2, 'testMatch.length');
4545
assertEqual(testMatch[0], '<rootDir>/src/entry1.test.js', 'testMatch[0]');
4646
assertEqual(testMatch[1], '<rootDir>/src/entry2.test.js', 'testMatch[1]');

plugin.mjs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { writeFile } from 'node:fs/promises';
2-
import { sep, join, resolve } from 'node:path';
2+
import { sep, join, relative, resolve } from 'node:path';
33
import importFrom from 'import-from';
44
import { logger, optimizeTracing } from "./utils/logger.mjs";
55
import { convertPathToImport } from "./utils/resolve-module.mjs";
@@ -102,13 +102,9 @@ export default ({
102102
}
103103

104104
function redirectExternalModule(modulePath) {
105+
let replacements = 0;
105106
const segments = modulePath.split(sep);
106-
const nodeModulesIndex = segments.indexOf('node_modules');
107-
if (nodeModulesIndex < 0) {
108-
return modulePath;
109-
}
110-
111-
return [outdir, 'bundled_externals', ...segments.slice(nodeModulesIndex + 1)].join(sep);
107+
return segments.map(x => x === 'node_modules' && replacements++ === 0 ? 'bundled_modules' : x).join(sep);
112108
}
113109

114110
await moveExternalEntryPointsBackToRoot();

0 commit comments

Comments
 (0)