Skip to content

Commit 039dedb

Browse files
rafecafacebook-github-bot
authored andcommitted
Upgrade jest-haste-map to v24.0.0-alpha.2
Reviewed By: jeanlauliac Differential Revision: D10484195 fbshipit-source-id: e73002bcb8640747fcbcb8a2a17b70d05bb19898
1 parent 6d81022 commit 039dedb

File tree

7 files changed

+315
-179
lines changed

7 files changed

+315
-179
lines changed

packages/metro-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"cleanup-release": "test ! -e build && mv src build && mv src.real src"
1313
},
1414
"dependencies": {
15-
"jest-haste-map": "23.5.0",
15+
"jest-haste-map": "24.0.0-alpha.2",
1616
"lodash.throttle": "^4.1.1",
1717
"metro-resolver": "0.48.1",
1818
"wordwrap": "^1.0.0"

packages/metro/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333
"fs-extra": "^1.0.0",
3434
"graceful-fs": "^4.1.3",
3535
"image-size": "^0.6.0",
36-
"jest-docblock": "23.2.0",
37-
"jest-haste-map": "23.5.0",
38-
"jest-worker": "23.2.0",
36+
"jest-haste-map": "24.0.0-alpha.2",
37+
"jest-worker": "24.0.0-alpha.2",
3938
"json-stable-stringify": "^1.0.1",
4039
"lodash.throttle": "^4.1.1",
4140
"merge-stream": "^1.0.1",

packages/metro/src/DeltaBundler/__tests__/traverseDependencies-integration-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,12 +685,12 @@ describe('traverseDependencies', function() {
685685
} catch (error) {
686686
expect(error.message).toEqual(
687687
[
688-
'jest-haste-map: @providesModule naming collision:',
688+
'jest-haste-map: Haste module naming collision:',
689689
' Duplicate module name: index',
690690
' Paths: /root/b.js collides with /root/index.js',
691691
'',
692-
'This error is caused by a @providesModule declaration with the ' +
693-
'same name across two different files.',
692+
'This error is caused by `hasteImpl` returning the same ' +
693+
'name for different files.',
694694
].join('\n'),
695695
);
696696
}

packages/metro/src/ModuleGraph/node-haste/ModuleCache.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,23 @@ module.exports = class ModuleCache {
3434
}
3535

3636
getModule(path: string): Module {
37-
let m = this.modules.get(path);
37+
// This is hacky as hell... `ModuleGraph` handles relative paths but which
38+
// start with a slash (so we can have `/js/foo.js` or even `/../foo.js`).
39+
// This does not play well with `jest-haste-map`, which tries to convert
40+
// paths to absolute (https://fburl.com/vbwmjsxa) causing an additional
41+
// slashed to be prepended in the file path.
42+
// TODO: Refactor the way metro-buck handles paths to make them either
43+
// relative or absolute.
44+
const normalizedPath = path.startsWith('//') ? path.substr(1) : path;
45+
46+
let m = this.modules.get(normalizedPath);
3847
if (!m) {
39-
m = new Module(path, this, this.getTransformedFile(path));
40-
this.modules.set(path, m);
48+
m = new Module(
49+
normalizedPath,
50+
this,
51+
this.getTransformedFile(normalizedPath),
52+
);
53+
this.modules.set(normalizedPath, m);
4154
}
4255
return m;
4356
}

packages/metro/src/ModuleGraph/node-haste/node-haste.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ const NULL_MODULE: Moduleish = {
5858

5959
// This function maps the ModuleGraph data structure to jest-haste-map's ModuleMap
6060
const createModuleMap = ({files, helpers, moduleCache, sourceExts}) => {
61-
const map = Object.create(null);
61+
const map = new Map();
62+
6263
files.forEach(filePath => {
6364
if (helpers.isNodeModulesDir(filePath)) {
6465
return;
@@ -76,15 +77,15 @@ const createModuleMap = ({files, helpers, moduleCache, sourceExts}) => {
7677
if (!(id && module && module.isHaste())) {
7778
return;
7879
}
79-
if (!map[id]) {
80-
map[id] = Object.create(null);
81-
}
80+
81+
const mapModule = map.get(id) || Object.create(null);
82+
8283
const platform =
8384
parsePlatformFilePath(filePath, platforms).platform || GENERIC_PLATFORM;
8485

85-
const existingModule = map[id][platform];
86+
const existingModule = mapModule[platform];
8687
// 0 = Module, 1 = Package in jest-haste-map
87-
map[id][platform] = [filePath, module.type === 'Package' ? 1 : 0];
88+
mapModule[platform] = [filePath, module.type === 'Package' ? 1 : 0];
8889

8990
if (existingModule && existingModule[0] !== filePath) {
9091
throw new Error(
@@ -98,6 +99,8 @@ const createModuleMap = ({files, helpers, moduleCache, sourceExts}) => {
9899
].join('\n'),
99100
);
100101
}
102+
103+
map.set(id, mapModule);
101104
});
102105
return map;
103106
};
@@ -144,9 +147,10 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
144147
mainFields: options.mainFields,
145148
moduleCache,
146149
moduleMap: new ModuleMap({
147-
duplicates: Object.create(null),
150+
duplicates: new Map(),
148151
map: createModuleMap({files, helpers, moduleCache, sourceExts}),
149-
mocks: Object.create(null),
152+
mocks: new Map(),
153+
rootDir: '',
150154
}),
151155
preferNativePlatform: true,
152156
resolveAsset: (dirPath, assetName, platform) =>

packages/metro/src/node-haste/DependencyGraph.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class DependencyGraph extends EventEmitter {
9393
providesModuleNodeModules: config.resolver.providesModuleNodeModules,
9494
retainAllFiles: true,
9595
resetCache: config.resetCache,
96+
rootDir: config.projectRoot,
9697
roots: config.watchFolders,
9798
throwOnModuleCollision: true,
9899
useWatchman: config.resolver.useWatchman,

0 commit comments

Comments
 (0)