Skip to content

Commit b41ad9f

Browse files
davidaureliofacebook-github-bot-7
authored andcommitted
Upgrade node-haste to v2.3.0
Summary: This updates to the latest published node-haste version, and also adapts code and tests to that version. Future upgrades should be easier. Reviewed By: bestander Differential Revision: D2963144 fb-gh-sync-id: 9fd2c84fc49643fb85ee5d9674a5e458d43d44ca shipit-source-id: 9fd2c84fc49643fb85ee5d9674a5e458d43d44ca
1 parent ac12f98 commit b41ad9f

9 files changed

Lines changed: 158 additions & 148 deletions

File tree

npm-shrinkwrap.json

Lines changed: 107 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
"mkdirp": "^0.5.1",
149149
"module-deps": "^3.9.1",
150150
"node-fetch": "^1.3.3",
151-
"node-haste": "~2.0.0",
151+
"node-haste": "~2.3.0",
152152
"opn": "^3.0.2",
153153
"optimist": "^0.6.1",
154154
"progress": "^1.1.8",

packager/react-packager/src/AssetServer/__tests__/AssetServer-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
jest
44
.dontMock('node-haste/lib/lib/getPlatformExtension')
5+
.dontMock('node-haste/node_modules/throat')
56
.dontMock('../');
67

78
jest

packager/react-packager/src/Bundler/__tests__/Bundler-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
jest
1212
.setMock('worker-farm', () => () => undefined)
13+
.dontMock('node-haste/node_modules/throat')
1314
.dontMock('underscore')
1415
.dontMock('../../lib/ModuleTransport')
1516
.setMock('uglify-js')

packager/react-packager/src/JSTransformer/__tests__/Transformer-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ describe('Transformer', function() {
2525
var workers;
2626

2727
beforeEach(function() {
28-
Cache = require('node-haste').Cache;
29-
28+
Cache = jest.genMockFn();
3029
Cache.prototype.get = jest.genMockFn().mockImpl((a, b, c) => c());
3130

3231
workers = jest.genMockFn();

packager/react-packager/src/Resolver/__tests__/Resolver-test.js

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,37 @@ jest.mock('path');
1515

1616
const Promise = require('promise');
1717
const Resolver = require('../');
18-
const DependencyGraph = require('node-haste');
1918

2019
const path = require('path');
2120
const _ = require('underscore');
2221

22+
let DependencyGraph = jest.genMockFn();
23+
jest.setMock('node-haste', DependencyGraph);
2324
let Module;
2425
let Polyfill;
2526

2627
describe('Resolver', function() {
2728
beforeEach(function() {
28-
Module = require('node-haste').Module;
29-
Polyfill = require('node-haste').Polyfill;
29+
DependencyGraph.mockClear();
30+
Module = jest.genMockFn().mockImpl(function() {
31+
this.getName = jest.genMockFn();
32+
this.getDependencies = jest.genMockFn();
33+
this.isPolyfill = jest.genMockFn().mockReturnValue(false);
34+
});
35+
Polyfill = jest.genMockFn().mockImpl(function() {
36+
var polyfill = new Module();
37+
polyfill.isPolyfill.mockReturnValue(true);
38+
return polyfill;
39+
});
3040

3141
DependencyGraph.replacePatterns = require.requireActual('node-haste/lib/lib/replacePatterns');
42+
DependencyGraph.prototype.createPolyfill = jest.genMockFn();
43+
DependencyGraph.prototype.getDependencies = jest.genMockFn();
3244

3345
// For the polyfillDeps
3446
path.join = jest.genMockFn().mockImpl((a, b) => b);
3547

36-
DependencyGraph.prototype.load.mockImpl(() => Promise.resolve());
48+
DependencyGraph.prototype.load = jest.genMockFn().mockImpl(() => Promise.resolve());
3749
});
3850

3951
class ResolutionResponseMock {
@@ -60,9 +72,9 @@ describe('Resolver', function() {
6072

6173
function createPolyfill(id, dependencies) {
6274
var polyfill = new Polyfill({});
63-
polyfill.getName.mockImpl(() => Promise.resolve(id));
64-
polyfill.getDependencies.mockImpl(() => Promise.resolve(dependencies));
65-
polyfill.isPolyfill.mockReturnValue(true);
75+
polyfill.getName = jest.genMockFn().mockImpl(() => Promise.resolve(id));
76+
polyfill.getDependencies =
77+
jest.genMockFn().mockImpl(() => Promise.resolve(dependencies));
6678
return polyfill;
6779
}
6880

@@ -86,39 +98,34 @@ describe('Resolver', function() {
8698
.then(function(result) {
8799
expect(result.mainModuleId).toEqual('index');
88100
expect(result.dependencies[result.dependencies.length - 1]).toBe(module);
89-
expect(_.pluck(Polyfill.mock.calls, 0)).toEqual([
90-
{ path: 'polyfills/polyfills.js',
101+
expect(_.pluck(DependencyGraph.prototype.createPolyfill.mock.calls, 0)).toEqual([
102+
{ file: 'polyfills/polyfills.js',
91103
id: 'polyfills/polyfills.js',
92-
isPolyfill: true,
93104
dependencies: []
94105
},
95106
{ id: 'polyfills/console.js',
96-
isPolyfill: true,
97-
path: 'polyfills/console.js',
107+
file: 'polyfills/console.js',
98108
dependencies: [
99109
'polyfills/polyfills.js'
100110
],
101111
},
102112
{ id: 'polyfills/error-guard.js',
103-
isPolyfill: true,
104-
path: 'polyfills/error-guard.js',
113+
file: 'polyfills/error-guard.js',
105114
dependencies: [
106115
'polyfills/polyfills.js',
107116
'polyfills/console.js'
108117
],
109118
},
110119
{ id: 'polyfills/String.prototype.es6.js',
111-
isPolyfill: true,
112-
path: 'polyfills/String.prototype.es6.js',
120+
file: 'polyfills/String.prototype.es6.js',
113121
dependencies: [
114122
'polyfills/polyfills.js',
115123
'polyfills/console.js',
116124
'polyfills/error-guard.js'
117125
],
118126
},
119127
{ id: 'polyfills/Array.prototype.es6.js',
120-
isPolyfill: true,
121-
path: 'polyfills/Array.prototype.es6.js',
128+
file: 'polyfills/Array.prototype.es6.js',
122129
dependencies: [
123130
'polyfills/polyfills.js',
124131
'polyfills/console.js',
@@ -127,8 +134,7 @@ describe('Resolver', function() {
127134
],
128135
},
129136
{ id: 'polyfills/Array.es6.js',
130-
isPolyfill: true,
131-
path: 'polyfills/Array.es6.js',
137+
file: 'polyfills/Array.es6.js',
132138
dependencies: [
133139
'polyfills/polyfills.js',
134140
'polyfills/console.js',
@@ -138,8 +144,7 @@ describe('Resolver', function() {
138144
],
139145
},
140146
{ id: 'polyfills/Object.es7.js',
141-
isPolyfill: true,
142-
path: 'polyfills/Object.es7.js',
147+
file: 'polyfills/Object.es7.js',
143148
dependencies: [
144149
'polyfills/polyfills.js',
145150
'polyfills/console.js',
@@ -150,8 +155,7 @@ describe('Resolver', function() {
150155
],
151156
},
152157
{ id: 'polyfills/babelHelpers.js',
153-
isPolyfill: true,
154-
path: 'polyfills/babelHelpers.js',
158+
file: 'polyfills/babelHelpers.js',
155159
dependencies: [
156160
'polyfills/polyfills.js',
157161
'polyfills/console.js',
@@ -181,12 +185,14 @@ describe('Resolver', function() {
181185
}));
182186
});
183187

188+
const polyfill = {};
189+
DependencyGraph.prototype.createPolyfill.mockReturnValueOnce(polyfill);
184190
return depResolver.getDependencies('/root/index.js', { dev: true })
185191
.then(function(result) {
186192
expect(result.mainModuleId).toEqual('index');
187193
expect(DependencyGraph.mock.instances[0].getDependencies)
188-
.toBeCalledWith('/root/index.js', undefined, true);
189-
expect(result.dependencies[0]).toBe(Polyfill.mock.instances[0]);
194+
.toBeCalledWith({entryPath: '/root/index.js', recursive: true});
195+
expect(result.dependencies[0]).toBe(polyfill);
190196
expect(result.dependencies[result.dependencies.length - 1])
191197
.toBe(module);
192198
});
@@ -211,10 +217,9 @@ describe('Resolver', function() {
211217
return depResolver.getDependencies('/root/index.js', { dev: false })
212218
.then((result) => {
213219
expect(result.mainModuleId).toEqual('index');
214-
expect(Polyfill.mock.calls[result.dependencies.length - 2]).toEqual([
215-
{ path: 'some module',
220+
expect(DependencyGraph.prototype.createPolyfill.mock.calls[result.dependencies.length - 2]).toEqual([
221+
{ file: 'some module',
216222
id: 'some module',
217-
isPolyfill: true,
218223
dependencies: [
219224
'polyfills/polyfills.js',
220225
'polyfills/console.js',

packager/react-packager/src/Resolver/index.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const path = require('path');
1313
const Activity = require('../Activity');
1414
const DependencyGraph = require('node-haste');
1515
const replacePatterns = require('node-haste').replacePatterns;
16-
const Polyfill = require('node-haste').Polyfill;
1716
const declareOpts = require('../lib/declareOpts');
1817
const Promise = require('promise');
1918

@@ -121,14 +120,13 @@ class Resolver {
121120
return this._depGraph.getModuleForPath(entryFile);
122121
}
123122

124-
getDependencies(main, options) {
125-
const opts = getDependenciesValidateOpts(options);
126-
127-
return this._depGraph.getDependencies(
128-
main,
129-
opts.platform,
130-
opts.recursive,
131-
).then(resolutionResponse => {
123+
getDependencies(entryPath, options) {
124+
const {platform, recursive} = getDependenciesValidateOpts(options);
125+
return this._depGraph.getDependencies({
126+
entryPath,
127+
platform,
128+
recursive,
129+
}).then(resolutionResponse => {
132130
this._getPolyfillDependencies().reverse().forEach(
133131
polyfill => resolutionResponse.prependDependency(polyfill)
134132
);
@@ -151,11 +149,10 @@ class Resolver {
151149
return [
152150
prelude,
153151
moduleSystem
154-
].map(moduleName => new Polyfill({
155-
path: moduleName,
152+
].map(moduleName => this._depGraph.createPolyfill({
153+
file: moduleName,
156154
id: moduleName,
157155
dependencies: [],
158-
isPolyfill: true,
159156
}));
160157
}
161158

@@ -172,11 +169,10 @@ class Resolver {
172169
].concat(this._polyfillModuleNames);
173170

174171
return polyfillModuleNames.map(
175-
(polyfillModuleName, idx) => new Polyfill({
176-
path: polyfillModuleName,
172+
(polyfillModuleName, idx) => this._depGraph.createPolyfill({
173+
file: polyfillModuleName,
177174
id: polyfillModuleName,
178175
dependencies: polyfillModuleNames.slice(0, idx),
179-
isPolyfill: true,
180176
})
181177
);
182178
}

packager/react-packager/src/Server/__tests__/Server-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'use strict';
1010

1111
jest.setMock('worker-farm', function() { return () => {}; })
12+
.dontMock('node-haste/node_modules/throat')
1213
.dontMock('os')
1314
.dontMock('underscore')
1415
.dontMock('path')

packager/react-packager/src/SocketInterface/__tests__/SocketServer-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
jest.setMock('uglify-js')
1212
.mock('net')
1313
.mock('fs')
14+
.dontMock('node-haste/node_modules/throat')
1415
.dontMock('../SocketServer');
1516

1617
var PackagerServer = require('../../Server');

0 commit comments

Comments
 (0)