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
moduleDirectories are 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.length will not change
dirs will contain paths.length duplicates of each absolute path in modules
- 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
lines: 47 - 53
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
modules is only returned for a particular iteration of paths.reduce()
- other iterations inject a null value
dirs is then filtered to remove these null values
dirs.length will be reduced, which could slightly boost performance
- absolute paths will be valid
- absolute paths for Windows OS will no-longer be broken
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:
moduleDirectoriesare invalid in Windows OSevidence:
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 inmodulespatch v2:
file:
packages/jest-resolve/src/node_modules_paths.js
lines: 47 - 53
original code:
modified code:
effects:
modulesis only returned for a particular iteration ofpaths.reduce()dirsis then filtered to remove these null valuesdirs.lengthwill be reduced, which could slightly boost performance