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
This commit is contained in:
David Aurelio
2016-02-23 06:09:38 -08:00
committed by facebook-github-bot-7
parent ac12f98689
commit b41ad9f5dc
9 changed files with 159 additions and 149 deletions

View File

@@ -2,6 +2,7 @@
jest
.dontMock('node-haste/lib/lib/getPlatformExtension')
.dontMock('node-haste/node_modules/throat')
.dontMock('../');
jest

View File

@@ -10,6 +10,7 @@
jest
.setMock('worker-farm', () => () => undefined)
.dontMock('node-haste/node_modules/throat')
.dontMock('underscore')
.dontMock('../../lib/ModuleTransport')
.setMock('uglify-js')

View File

@@ -25,8 +25,7 @@ describe('Transformer', function() {
var workers;
beforeEach(function() {
Cache = require('node-haste').Cache;
Cache = jest.genMockFn();
Cache.prototype.get = jest.genMockFn().mockImpl((a, b, c) => c());
workers = jest.genMockFn();

View File

@@ -15,25 +15,37 @@ jest.mock('path');
const Promise = require('promise');
const Resolver = require('../');
const DependencyGraph = require('node-haste');
const path = require('path');
const _ = require('underscore');
let DependencyGraph = jest.genMockFn();
jest.setMock('node-haste', DependencyGraph);
let Module;
let Polyfill;
describe('Resolver', function() {
beforeEach(function() {
Module = require('node-haste').Module;
Polyfill = require('node-haste').Polyfill;
DependencyGraph.mockClear();
Module = jest.genMockFn().mockImpl(function() {
this.getName = jest.genMockFn();
this.getDependencies = jest.genMockFn();
this.isPolyfill = jest.genMockFn().mockReturnValue(false);
});
Polyfill = jest.genMockFn().mockImpl(function() {
var polyfill = new Module();
polyfill.isPolyfill.mockReturnValue(true);
return polyfill;
});
DependencyGraph.replacePatterns = require.requireActual('node-haste/lib/lib/replacePatterns');
DependencyGraph.prototype.createPolyfill = jest.genMockFn();
DependencyGraph.prototype.getDependencies = jest.genMockFn();
// For the polyfillDeps
path.join = jest.genMockFn().mockImpl((a, b) => b);
DependencyGraph.prototype.load.mockImpl(() => Promise.resolve());
DependencyGraph.prototype.load = jest.genMockFn().mockImpl(() => Promise.resolve());
});
class ResolutionResponseMock {
@@ -60,9 +72,9 @@ describe('Resolver', function() {
function createPolyfill(id, dependencies) {
var polyfill = new Polyfill({});
polyfill.getName.mockImpl(() => Promise.resolve(id));
polyfill.getDependencies.mockImpl(() => Promise.resolve(dependencies));
polyfill.isPolyfill.mockReturnValue(true);
polyfill.getName = jest.genMockFn().mockImpl(() => Promise.resolve(id));
polyfill.getDependencies =
jest.genMockFn().mockImpl(() => Promise.resolve(dependencies));
return polyfill;
}
@@ -86,30 +98,26 @@ describe('Resolver', function() {
.then(function(result) {
expect(result.mainModuleId).toEqual('index');
expect(result.dependencies[result.dependencies.length - 1]).toBe(module);
expect(_.pluck(Polyfill.mock.calls, 0)).toEqual([
{ path: 'polyfills/polyfills.js',
expect(_.pluck(DependencyGraph.prototype.createPolyfill.mock.calls, 0)).toEqual([
{ file: 'polyfills/polyfills.js',
id: 'polyfills/polyfills.js',
isPolyfill: true,
dependencies: []
},
{ id: 'polyfills/console.js',
isPolyfill: true,
path: 'polyfills/console.js',
file: 'polyfills/console.js',
dependencies: [
'polyfills/polyfills.js'
],
},
{ id: 'polyfills/error-guard.js',
isPolyfill: true,
path: 'polyfills/error-guard.js',
file: 'polyfills/error-guard.js',
dependencies: [
'polyfills/polyfills.js',
'polyfills/console.js'
],
},
{ id: 'polyfills/String.prototype.es6.js',
isPolyfill: true,
path: 'polyfills/String.prototype.es6.js',
file: 'polyfills/String.prototype.es6.js',
dependencies: [
'polyfills/polyfills.js',
'polyfills/console.js',
@@ -117,8 +125,7 @@ describe('Resolver', function() {
],
},
{ id: 'polyfills/Array.prototype.es6.js',
isPolyfill: true,
path: 'polyfills/Array.prototype.es6.js',
file: 'polyfills/Array.prototype.es6.js',
dependencies: [
'polyfills/polyfills.js',
'polyfills/console.js',
@@ -127,8 +134,7 @@ describe('Resolver', function() {
],
},
{ id: 'polyfills/Array.es6.js',
isPolyfill: true,
path: 'polyfills/Array.es6.js',
file: 'polyfills/Array.es6.js',
dependencies: [
'polyfills/polyfills.js',
'polyfills/console.js',
@@ -138,8 +144,7 @@ describe('Resolver', function() {
],
},
{ id: 'polyfills/Object.es7.js',
isPolyfill: true,
path: 'polyfills/Object.es7.js',
file: 'polyfills/Object.es7.js',
dependencies: [
'polyfills/polyfills.js',
'polyfills/console.js',
@@ -150,8 +155,7 @@ describe('Resolver', function() {
],
},
{ id: 'polyfills/babelHelpers.js',
isPolyfill: true,
path: 'polyfills/babelHelpers.js',
file: 'polyfills/babelHelpers.js',
dependencies: [
'polyfills/polyfills.js',
'polyfills/console.js',
@@ -181,12 +185,14 @@ describe('Resolver', function() {
}));
});
const polyfill = {};
DependencyGraph.prototype.createPolyfill.mockReturnValueOnce(polyfill);
return depResolver.getDependencies('/root/index.js', { dev: true })
.then(function(result) {
expect(result.mainModuleId).toEqual('index');
expect(DependencyGraph.mock.instances[0].getDependencies)
.toBeCalledWith('/root/index.js', undefined, true);
expect(result.dependencies[0]).toBe(Polyfill.mock.instances[0]);
.toBeCalledWith({entryPath: '/root/index.js', recursive: true});
expect(result.dependencies[0]).toBe(polyfill);
expect(result.dependencies[result.dependencies.length - 1])
.toBe(module);
});
@@ -211,10 +217,9 @@ describe('Resolver', function() {
return depResolver.getDependencies('/root/index.js', { dev: false })
.then((result) => {
expect(result.mainModuleId).toEqual('index');
expect(Polyfill.mock.calls[result.dependencies.length - 2]).toEqual([
{ path: 'some module',
expect(DependencyGraph.prototype.createPolyfill.mock.calls[result.dependencies.length - 2]).toEqual([
{ file: 'some module',
id: 'some module',
isPolyfill: true,
dependencies: [
'polyfills/polyfills.js',
'polyfills/console.js',

View File

@@ -13,7 +13,6 @@ const path = require('path');
const Activity = require('../Activity');
const DependencyGraph = require('node-haste');
const replacePatterns = require('node-haste').replacePatterns;
const Polyfill = require('node-haste').Polyfill;
const declareOpts = require('../lib/declareOpts');
const Promise = require('promise');
@@ -121,14 +120,13 @@ class Resolver {
return this._depGraph.getModuleForPath(entryFile);
}
getDependencies(main, options) {
const opts = getDependenciesValidateOpts(options);
return this._depGraph.getDependencies(
main,
opts.platform,
opts.recursive,
).then(resolutionResponse => {
getDependencies(entryPath, options) {
const {platform, recursive} = getDependenciesValidateOpts(options);
return this._depGraph.getDependencies({
entryPath,
platform,
recursive,
}).then(resolutionResponse => {
this._getPolyfillDependencies().reverse().forEach(
polyfill => resolutionResponse.prependDependency(polyfill)
);
@@ -151,11 +149,10 @@ class Resolver {
return [
prelude,
moduleSystem
].map(moduleName => new Polyfill({
path: moduleName,
].map(moduleName => this._depGraph.createPolyfill({
file: moduleName,
id: moduleName,
dependencies: [],
isPolyfill: true,
}));
}
@@ -172,11 +169,10 @@ class Resolver {
].concat(this._polyfillModuleNames);
return polyfillModuleNames.map(
(polyfillModuleName, idx) => new Polyfill({
path: polyfillModuleName,
(polyfillModuleName, idx) => this._depGraph.createPolyfill({
file: polyfillModuleName,
id: polyfillModuleName,
dependencies: polyfillModuleNames.slice(0, idx),
isPolyfill: true,
})
);
}

View File

@@ -9,6 +9,7 @@
'use strict';
jest.setMock('worker-farm', function() { return () => {}; })
.dontMock('node-haste/node_modules/throat')
.dontMock('os')
.dontMock('underscore')
.dontMock('path')

View File

@@ -11,6 +11,7 @@
jest.setMock('uglify-js')
.mock('net')
.mock('fs')
.dontMock('node-haste/node_modules/throat')
.dontMock('../SocketServer');
var PackagerServer = require('../../Server');