-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Closed
Description
https://github.com/facebook/jest
https://github.com/facebook/jest/tree/master/packages/jest-resolve
https://github.com/facebook/jest/blob/master/packages/jest-resolve/src/node_modules_paths.js
error:
- absolute paths in
moduleDirectoriesare invalid in Windows OS - results in CommonJS modules not being found
- import statements throw an Error
- all tests fail
evidence:
file:
packages/jest-resolve/src/node_modules_paths.js
line: 54
insert code:
console.log('dirs:', JSON.stringify(dirs, null, 2))
patch v1:
file:
packages/jest-resolve/src/node_modules_paths.js
line: 50
original code:
return path.join(prefix, aPath, moduleDir);
modified code:
return path.isAbsolute(moduleDir) ? moduleDir : path.join(prefix, aPath, moduleDir);
effects:
dirs.lengthwill not changedirswill containpaths.lengthduplicates of each absolute path inmodules- absolute paths will be valid
- absolute paths for Windows OS will no-longer be broken
patch v2:
file:
packages/jest-resolve/src/node_modules_paths.js
original code:
const dirs = paths.reduce((dirs, aPath) => {
return dirs.concat(
modules.map(moduleDir => {
return path.join(prefix, aPath, moduleDir);
}),
);
}, []);modified code:
const dirs = paths
.reduce((dirs, aPath) => {
return dirs.concat(
modules.map(moduleDir => {
return path.isAbsolute(moduleDir) ? ((aPath === basedirAbs) ? moduleDir : null) : path.join(prefix, aPath, moduleDir);
}),
);
}, [])
.filter(dir => (dir !== null))
;effects:
- each absolute path in
modulesis only returned for a particular iteration ofpaths.reduce() - other iterations inject a null value
dirsis then filtered to remove these null valuesdirs.lengthwill be reduced, which could slightly boost performance- absolute paths will be valid
- absolute paths for Windows OS will no-longer be broken
Metadata
Metadata
Assignees
Labels
No labels