packager: node-haste: cleanup the load() function
Reviewed By: davidaurelio Differential Revision: D4659391 fbshipit-source-id: a83e218ba89ad459fed07a4dfb61c422a6b4db5d
This commit is contained in:
Родитель
a435fbcbd1
Коммит
0ff379bb76
|
@ -204,7 +204,9 @@ class Bundler {
|
||||||
this._transformer.kill();
|
this._transformer.kill();
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
this._cache.end(),
|
this._cache.end(),
|
||||||
this.getResolver().getDependencyGraph().getWatcher().end(),
|
this.getResolver().getDependencyGraph().then(dependencyGraph => {
|
||||||
|
dependencyGraph.getWatcher().end();
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
jest.useRealTimers();
|
||||||
|
|
||||||
jest.unmock('../');
|
jest.unmock('../');
|
||||||
jest.unmock('../../../defaults');
|
jest.unmock('../../../defaults');
|
||||||
jest.mock('path');
|
jest.mock('path');
|
||||||
|
@ -37,6 +39,7 @@ describe('Resolver', function() {
|
||||||
return polyfill;
|
return polyfill;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
DependencyGraph.load = jest.fn().mockImplementation(opts => Promise.resolve(new DependencyGraph(opts)));
|
||||||
DependencyGraph.replacePatterns = require.requireActual('../../node-haste/lib/replacePatterns');
|
DependencyGraph.replacePatterns = require.requireActual('../../node-haste/lib/replacePatterns');
|
||||||
DependencyGraph.prototype.createPolyfill = jest.fn();
|
DependencyGraph.prototype.createPolyfill = jest.fn();
|
||||||
DependencyGraph.prototype.getDependencies = jest.fn();
|
DependencyGraph.prototype.getDependencies = jest.fn();
|
||||||
|
@ -91,20 +94,23 @@ describe('Resolver', function() {
|
||||||
|
|
||||||
describe('getDependencies', function() {
|
describe('getDependencies', function() {
|
||||||
it('forwards transform options to the dependency graph', function() {
|
it('forwards transform options to the dependency graph', function() {
|
||||||
|
expect.assertions(1);
|
||||||
const transformOptions = {arbitrary: 'options'};
|
const transformOptions = {arbitrary: 'options'};
|
||||||
const platform = 'ios';
|
const platform = 'ios';
|
||||||
const entry = '/root/index.js';
|
const entry = '/root/index.js';
|
||||||
|
|
||||||
DependencyGraph.prototype.getDependencies.mockImplementation(
|
DependencyGraph.prototype.getDependencies.mockImplementation(
|
||||||
() => Promise.reject());
|
() => Promise.reject());
|
||||||
new Resolver({projectRoot: '/root'})
|
return new Resolver({projectRoot: '/root'})
|
||||||
.getDependencies(entry, {platform}, transformOptions);
|
.getDependencies(entry, {platform}, transformOptions)
|
||||||
expect(DependencyGraph.prototype.getDependencies).toBeCalledWith({
|
.catch(() => {
|
||||||
entryPath: entry,
|
expect(DependencyGraph.prototype.getDependencies).toBeCalledWith({
|
||||||
platform,
|
entryPath: entry,
|
||||||
transformOptions,
|
platform,
|
||||||
recursive: true,
|
transformOptions,
|
||||||
});
|
recursive: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes custom platforms to the dependency graph', function() {
|
it('passes custom platforms to the dependency graph', function() {
|
||||||
|
|
|
@ -50,12 +50,13 @@ type Options = {
|
||||||
|
|
||||||
class Resolver {
|
class Resolver {
|
||||||
|
|
||||||
|
_depGraphPromise: Promise<DependencyGraph>;
|
||||||
_depGraph: DependencyGraph;
|
_depGraph: DependencyGraph;
|
||||||
_minifyCode: MinifyCode;
|
_minifyCode: MinifyCode;
|
||||||
_polyfillModuleNames: Array<string>;
|
_polyfillModuleNames: Array<string>;
|
||||||
|
|
||||||
constructor(opts: Options) {
|
constructor(opts: Options) {
|
||||||
this._depGraph = new DependencyGraph({
|
this._depGraphPromise = DependencyGraph.load({
|
||||||
assetDependencies: ['react-native/Libraries/Image/AssetRegistry'],
|
assetDependencies: ['react-native/Libraries/Image/AssetRegistry'],
|
||||||
assetExts: opts.assetExts,
|
assetExts: opts.assetExts,
|
||||||
cache: opts.cache,
|
cache: opts.cache,
|
||||||
|
@ -89,10 +90,15 @@ class Resolver {
|
||||||
this._minifyCode = opts.minifyCode;
|
this._minifyCode = opts.minifyCode;
|
||||||
this._polyfillModuleNames = opts.polyfillModuleNames || [];
|
this._polyfillModuleNames = opts.polyfillModuleNames || [];
|
||||||
|
|
||||||
this._depGraph.load().catch(err => {
|
this._depGraphPromise.then(
|
||||||
console.error(err.message + '\n' + err.stack);
|
depGraph => { this._depGraph = depGraph; },
|
||||||
process.exit(1);
|
err => {
|
||||||
});
|
console.error(err.message + '\n' + err.stack);
|
||||||
|
// FIXME(jeanlauliac): we shall never exit the process by ourselves,
|
||||||
|
// packager may be used in a server application or the like.
|
||||||
|
process.exit(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getShallowDependencies(
|
getShallowDependencies(
|
||||||
|
@ -114,17 +120,18 @@ class Resolver {
|
||||||
getModuleId: mixed,
|
getModuleId: mixed,
|
||||||
): Promise<ResolutionResponse> {
|
): Promise<ResolutionResponse> {
|
||||||
const {platform, recursive = true} = options;
|
const {platform, recursive = true} = options;
|
||||||
return this._depGraph.getDependencies({
|
return this._depGraphPromise.then(depGraph => depGraph.getDependencies({
|
||||||
entryPath,
|
entryPath,
|
||||||
platform,
|
platform,
|
||||||
transformOptions,
|
transformOptions,
|
||||||
recursive,
|
recursive,
|
||||||
onProgress,
|
onProgress,
|
||||||
}).then(resolutionResponse => {
|
})).then(resolutionResponse => {
|
||||||
this._getPolyfillDependencies().reverse().forEach(
|
this._getPolyfillDependencies().reverse().forEach(
|
||||||
polyfill => resolutionResponse.prependDependency(polyfill)
|
polyfill => resolutionResponse.prependDependency(polyfill)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/* $FlowFixMe: monkey patching */
|
||||||
resolutionResponse.getModuleId = getModuleId;
|
resolutionResponse.getModuleId = getModuleId;
|
||||||
return resolutionResponse.finalize();
|
return resolutionResponse.finalize();
|
||||||
});
|
});
|
||||||
|
@ -245,8 +252,8 @@ class Resolver {
|
||||||
return this._minifyCode(path, code, map);
|
return this._minifyCode(path, code, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
getDependencyGraph(): DependencyGraph {
|
getDependencyGraph(): Promise<DependencyGraph> {
|
||||||
return this._depGraph;
|
return this._depGraphPromise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,10 +80,10 @@ describe('processRequest', () => {
|
||||||
Bundler.prototype.invalidateFile = invalidatorFunc;
|
Bundler.prototype.invalidateFile = invalidatorFunc;
|
||||||
Bundler.prototype.getResolver =
|
Bundler.prototype.getResolver =
|
||||||
jest.fn().mockReturnValue({
|
jest.fn().mockReturnValue({
|
||||||
getDependencyGraph: jest.fn().mockReturnValue({
|
getDependencyGraph: jest.fn().mockReturnValue(Promise.resolve({
|
||||||
getHasteMap: jest.fn().mockReturnValue({on: jest.fn()}),
|
getHasteMap: jest.fn().mockReturnValue({on: jest.fn()}),
|
||||||
load: jest.fn(() => Promise.resolve()),
|
load: jest.fn(() => Promise.resolve()),
|
||||||
}),
|
})),
|
||||||
});
|
});
|
||||||
|
|
||||||
server = new Server(options);
|
server = new Server(options);
|
||||||
|
|
|
@ -251,8 +251,7 @@ class Server {
|
||||||
this._bundler = new Bundler(bundlerOpts);
|
this._bundler = new Bundler(bundlerOpts);
|
||||||
|
|
||||||
// changes to the haste map can affect resolution of files in the bundle
|
// changes to the haste map can affect resolution of files in the bundle
|
||||||
const dependencyGraph = this._bundler.getResolver().getDependencyGraph();
|
this._bundler.getResolver().getDependencyGraph().then(dependencyGraph => {
|
||||||
dependencyGraph.load().then(() => {
|
|
||||||
dependencyGraph.getWatcher().on(
|
dependencyGraph.getWatcher().on(
|
||||||
'change',
|
'change',
|
||||||
({eventsQueue}) => eventsQueue.forEach(processFileChange),
|
({eventsQueue}) => eventsQueue.forEach(processFileChange),
|
||||||
|
@ -307,7 +306,7 @@ class Server {
|
||||||
entryFile: string,
|
entryFile: string,
|
||||||
platform?: string,
|
platform?: string,
|
||||||
}): Promise<Bundle> {
|
}): Promise<Bundle> {
|
||||||
return this._bundler.getResolver().getDependencyGraph().load().then(() => {
|
return this._bundler.getResolver().getDependencyGraph().then(() => {
|
||||||
if (!options.platform) {
|
if (!options.platform) {
|
||||||
options.platform = getPlatformExtension(options.entryFile);
|
options.platform = getPlatformExtension(options.entryFile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,9 @@ describe('DependencyGraph', function() {
|
||||||
let ResolutionRequest;
|
let ResolutionRequest;
|
||||||
let defaults;
|
let defaults;
|
||||||
|
|
||||||
function getOrderedDependenciesAsJSON(dgraph, entryPath, platform, recursive = true) {
|
function getOrderedDependenciesAsJSON(dgraphPromise, entryPath, platform, recursive = true) {
|
||||||
return dgraph.getDependencies({entryPath, platform, recursive})
|
return dgraphPromise
|
||||||
|
.then(dgraph => dgraph.getDependencies({entryPath, platform, recursive}))
|
||||||
.then(response => response.finalize())
|
.then(response => response.finalize())
|
||||||
.then(({dependencies}) => Promise.all(dependencies.map(dep => Promise.all([
|
.then(({dependencies}) => Promise.all(dependencies.map(dep => Promise.all([
|
||||||
dep.getName(),
|
dep.getName(),
|
||||||
|
@ -167,7 +168,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -220,7 +221,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -264,7 +265,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -316,7 +317,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -364,7 +365,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -418,7 +419,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -466,7 +467,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -519,7 +520,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -594,7 +595,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -665,7 +666,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -714,7 +715,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -763,7 +764,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -820,7 +821,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -872,7 +873,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -919,7 +920,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -965,7 +966,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1008,7 +1009,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1055,7 +1056,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1100,7 +1101,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1138,12 +1139,12 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
|
||||||
return dgraph.load().catch(err => {
|
return dgraph.catch(err => {
|
||||||
expect(err.message).toEqual(
|
expect(err.message).toEqual(
|
||||||
`Failed to build DependencyGraph: @providesModule naming collision:\n` +
|
`Failed to build DependencyGraph: @providesModule naming collision:\n` +
|
||||||
` Duplicate module name: index\n` +
|
` Duplicate module name: index\n` +
|
||||||
|
@ -1169,7 +1170,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1203,7 +1204,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1258,7 +1259,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1344,7 +1345,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1397,7 +1398,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1450,7 +1451,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
assetExts: ['png', 'jpg'],
|
assetExts: ['png', 'jpg'],
|
||||||
|
@ -1504,7 +1505,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
assetExts: ['png', 'jpg'],
|
assetExts: ['png', 'jpg'],
|
||||||
|
@ -1573,7 +1574,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const dgraph = new DependencyGraph({
|
const dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1668,7 +1669,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1735,7 +1736,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const dgraph = new DependencyGraph({
|
const dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1812,7 +1813,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1877,7 +1878,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const dgraph = new DependencyGraph({
|
const dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -1939,7 +1940,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const dgraph = new DependencyGraph({
|
const dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -2023,7 +2024,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -2075,7 +2076,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -2186,7 +2187,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -2254,7 +2255,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
extraNodeModules: {
|
extraNodeModules: {
|
||||||
|
@ -2308,7 +2309,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
extraNodeModules: {
|
extraNodeModules: {
|
||||||
|
@ -2354,7 +2355,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
extraNodeModules: {
|
extraNodeModules: {
|
||||||
|
@ -2428,7 +2429,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -2478,7 +2479,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -2531,7 +2532,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -2634,7 +2635,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -2710,7 +2711,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -2788,7 +2789,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -2879,7 +2880,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -2959,7 +2960,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -3094,7 +3095,7 @@ describe('DependencyGraph', function() {
|
||||||
};
|
};
|
||||||
setMockFileSystem(filesystem);
|
setMockFileSystem(filesystem);
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root, otherRoot],
|
roots: [root, otherRoot],
|
||||||
});
|
});
|
||||||
|
@ -3200,7 +3201,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -3251,7 +3252,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -3308,7 +3309,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -3365,7 +3366,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
platforms: new Set(['ios', 'android', 'web']),
|
platforms: new Set(['ios', 'android', 'web']),
|
||||||
roots: [root],
|
roots: [root],
|
||||||
|
@ -3411,7 +3412,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -3469,7 +3470,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -3531,7 +3532,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -3609,7 +3610,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -3685,7 +3686,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -3763,7 +3764,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -3854,7 +3855,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -3934,7 +3935,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4068,7 +4069,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root, otherRoot],
|
roots: [root, otherRoot],
|
||||||
});
|
});
|
||||||
|
@ -4166,7 +4167,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4218,7 +4219,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4260,7 +4261,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4317,7 +4318,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4374,7 +4375,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4419,7 +4420,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4477,7 +4478,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4566,7 +4567,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4628,7 +4629,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4691,7 +4692,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4731,7 +4732,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4808,7 +4809,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
assetExts: ['png'],
|
assetExts: ['png'],
|
||||||
|
@ -4820,7 +4821,6 @@ describe('DependencyGraph', function() {
|
||||||
}
|
}
|
||||||
).then(() => {
|
).then(() => {
|
||||||
filesystem.root['foo.png'] = '';
|
filesystem.root['foo.png'] = '';
|
||||||
dgraph._hasteFS._files[root + '/foo.png'] = ['', 8648460, 1, []];
|
|
||||||
return triggerAndProcessWatchEvent(dgraph, 'change', root + '/foo.png');
|
return triggerAndProcessWatchEvent(dgraph, 'change', root + '/foo.png');
|
||||||
}).then(
|
}).then(
|
||||||
() => getOrderedDependenciesAsJSON(dgraph, '/root/index.js'),
|
() => getOrderedDependenciesAsJSON(dgraph, '/root/index.js'),
|
||||||
|
@ -4873,7 +4873,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4933,7 +4933,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -4948,11 +4948,11 @@ describe('DependencyGraph', function() {
|
||||||
name: 'bPackage',
|
name: 'bPackage',
|
||||||
main: 'main.js',
|
main: 'main.js',
|
||||||
});
|
});
|
||||||
return new Promise(resolve => {
|
return dgraph.then(dg => new Promise(resolve => {
|
||||||
dgraph.once('change', () => resolve());
|
dg.once('change', () => resolve());
|
||||||
triggerWatchEvent('change', root + '/index.js');
|
triggerWatchEvent('change', root + '/index.js');
|
||||||
triggerWatchEvent('change', root + '/aPackage/package.json');
|
triggerWatchEvent('change', root + '/aPackage/package.json');
|
||||||
});
|
}));
|
||||||
}).then(
|
}).then(
|
||||||
() => getOrderedDependenciesAsJSON(dgraph, '/root/index.js'),
|
() => getOrderedDependenciesAsJSON(dgraph, '/root/index.js'),
|
||||||
).then(function(deps) {
|
).then(function(deps) {
|
||||||
|
@ -5012,7 +5012,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -5105,7 +5105,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -5168,7 +5168,7 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
});
|
});
|
||||||
|
@ -5214,13 +5214,14 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dgraph = new DependencyGraph({
|
var dgraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: [root],
|
roots: [root],
|
||||||
extensions: ['jsx', 'coffee'],
|
extensions: ['jsx', 'coffee'],
|
||||||
});
|
});
|
||||||
|
|
||||||
return dgraph.matchFilesByPattern('.*')
|
return dgraph
|
||||||
|
.then(dg => dg.matchFilesByPattern('.*'))
|
||||||
.then(files => {
|
.then(files => {
|
||||||
expect(files).toEqual([
|
expect(files).toEqual([
|
||||||
'/root/index.jsx', '/root/a.coffee',
|
'/root/index.jsx', '/root/a.coffee',
|
||||||
|
@ -5285,10 +5286,10 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const DependencyGraph = require('../');
|
const DependencyGraph = require('../');
|
||||||
dependencyGraph = new DependencyGraph({
|
return DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: ['/root'],
|
roots: ['/root'],
|
||||||
});
|
}).then(dg => { dependencyGraph = dg; });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls back for each finished module', () => {
|
it('calls back for each finished module', () => {
|
||||||
|
@ -5330,15 +5331,13 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const dependencyGraph = new DependencyGraph({
|
DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
assetDependencies,
|
assetDependencies,
|
||||||
roots: ['/root'],
|
roots: ['/root'],
|
||||||
});
|
}).then(dependencyGraph => dependencyGraph.getDependencies({
|
||||||
|
|
||||||
return dependencyGraph.getDependencies({
|
|
||||||
entryPath: '/root/index.js',
|
entryPath: '/root/index.js',
|
||||||
}).then(({dependencies}) => {
|
})).then(({dependencies}) => {
|
||||||
const [, assetModule] = dependencies;
|
const [, assetModule] = dependencies;
|
||||||
return assetModule.getDependencies()
|
return assetModule.getDependencies()
|
||||||
.then(deps => expect(deps).toBe(assetDependencies));
|
.then(deps => expect(deps).toBe(assetDependencies));
|
||||||
|
@ -5374,7 +5373,7 @@ describe('DependencyGraph', function() {
|
||||||
'f.js': 'require("./c");', // circular dependency
|
'f.js': 'require("./c");', // circular dependency
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dependencyGraph = new DependencyGraph({
|
dependencyGraph = DependencyGraph.load({
|
||||||
...defaults,
|
...defaults,
|
||||||
roots: ['/root'],
|
roots: ['/root'],
|
||||||
});
|
});
|
||||||
|
@ -5462,11 +5461,11 @@ describe('DependencyGraph', function() {
|
||||||
return require('graceful-fs').__setMockFilesystem(object);
|
return require('graceful-fs').__setMockFilesystem(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerAndProcessWatchEvent(dgraph, eventType, filename) {
|
function triggerAndProcessWatchEvent(dgraphPromise, eventType, filename) {
|
||||||
return new Promise(resolve => {
|
return dgraphPromise.then(dgraph => new Promise(resolve => {
|
||||||
dgraph.once('change', () => resolve());
|
dgraph.once('change', () => resolve());
|
||||||
triggerWatchEvent(eventType, filename);
|
triggerWatchEvent(eventType, filename);
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerWatchEvent(eventType, filename) {
|
function triggerWatchEvent(eventType, filename) {
|
||||||
|
|
|
@ -72,90 +72,102 @@ type Options = {
|
||||||
};
|
};
|
||||||
|
|
||||||
class DependencyGraph extends EventEmitter {
|
class DependencyGraph extends EventEmitter {
|
||||||
|
|
||||||
_opts: Options;
|
_opts: Options;
|
||||||
_haste: JestHasteMap;
|
_haste: JestHasteMap;
|
||||||
_hasteFS: HasteFS;
|
|
||||||
_helpers: DependencyGraphHelpers;
|
_helpers: DependencyGraphHelpers;
|
||||||
_moduleCache: ModuleCache;
|
_moduleCache: ModuleCache;
|
||||||
|
_hasteFS: HasteFS;
|
||||||
_moduleMap: ModuleMap;
|
_moduleMap: ModuleMap;
|
||||||
|
|
||||||
_loading: Promise<void>;
|
constructor(config: {
|
||||||
|
opts: Options,
|
||||||
constructor(opts: Options) {
|
haste: JestHasteMap,
|
||||||
|
initialHasteFS: HasteFS,
|
||||||
|
initialModuleMap: ModuleMap,
|
||||||
|
}) {
|
||||||
super();
|
super();
|
||||||
this._opts = {...opts};
|
this._opts = {...config.opts};
|
||||||
|
this._haste = config.haste;
|
||||||
|
this._hasteFS = config.initialHasteFS;
|
||||||
|
this._moduleMap = config.initialModuleMap;
|
||||||
this._helpers = new DependencyGraphHelpers(this._opts);
|
this._helpers = new DependencyGraphHelpers(this._opts);
|
||||||
this.load();
|
this._haste.on('change', this._onHasteChange.bind(this));
|
||||||
|
this._moduleCache = this._createModuleCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
load(): Promise<void> {
|
static _createHaste(opts: Options): JestHasteMap {
|
||||||
if (this._loading) {
|
const mw = opts.maxWorkers;
|
||||||
return this._loading;
|
return new JestHasteMap({
|
||||||
}
|
extensions: opts.extensions.concat(opts.assetExts),
|
||||||
|
forceNodeFilesystemAPI: opts.forceNodeFilesystemAPI,
|
||||||
const mw = this._opts.maxWorkers;
|
ignorePattern: {test: opts.ignoreFilePath},
|
||||||
this._haste = new JestHasteMap({
|
|
||||||
extensions: this._opts.extensions.concat(this._opts.assetExts),
|
|
||||||
forceNodeFilesystemAPI: this._opts.forceNodeFilesystemAPI,
|
|
||||||
ignorePattern: {test: this._opts.ignoreFilePath},
|
|
||||||
maxWorkers: typeof mw === 'number' && mw >= 1 ? mw : getMaxWorkers(),
|
maxWorkers: typeof mw === 'number' && mw >= 1 ? mw : getMaxWorkers(),
|
||||||
mocksPattern: '',
|
mocksPattern: '',
|
||||||
name: 'react-native-packager',
|
name: 'react-native-packager',
|
||||||
platforms: Array.from(this._opts.platforms),
|
platforms: Array.from(opts.platforms),
|
||||||
providesModuleNodeModules: this._opts.providesModuleNodeModules,
|
providesModuleNodeModules: opts.providesModuleNodeModules,
|
||||||
resetCache: this._opts.resetCache,
|
resetCache: opts.resetCache,
|
||||||
retainAllFiles: true,
|
retainAllFiles: true,
|
||||||
roots: this._opts.roots,
|
roots: opts.roots,
|
||||||
useWatchman: this._opts.useWatchman,
|
useWatchman: opts.useWatchman,
|
||||||
watch: this._opts.watch,
|
watch: opts.watch,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static load(opts: Options): Promise<DependencyGraph> {
|
||||||
const initializingPackagerLogEntry =
|
const initializingPackagerLogEntry =
|
||||||
log(createActionStartEntry('Initializing Packager'));
|
log(createActionStartEntry('Initializing Packager'));
|
||||||
this._opts.reporter.update({type: 'dep_graph_loading'});
|
opts.reporter.update({type: 'dep_graph_loading'});
|
||||||
this._loading = this._haste.build().then(({hasteFS, moduleMap}) => {
|
const haste = DependencyGraph._createHaste(opts);
|
||||||
this._hasteFS = hasteFS;
|
return haste.build().then(({hasteFS, moduleMap}) => {
|
||||||
this._moduleMap = moduleMap;
|
|
||||||
|
|
||||||
this._moduleCache = new ModuleCache({
|
|
||||||
cache: this._opts.cache,
|
|
||||||
getTransformCacheKey: this._opts.getTransformCacheKey,
|
|
||||||
globalTransformCache: this._opts.globalTransformCache,
|
|
||||||
transformCode: this._opts.transformCode,
|
|
||||||
depGraphHelpers: this._helpers,
|
|
||||||
assetDependencies: this._opts.assetDependencies,
|
|
||||||
moduleOptions: this._opts.moduleOptions,
|
|
||||||
reporter: this._opts.reporter,
|
|
||||||
getClosestPackage: filePath => {
|
|
||||||
const parsedPath = path.parse(filePath);
|
|
||||||
const root = parsedPath.root;
|
|
||||||
let dir = parsedPath.dir;
|
|
||||||
do {
|
|
||||||
const candidate = path.join(dir, 'package.json');
|
|
||||||
if (this._hasteFS.exists(candidate)) {
|
|
||||||
return candidate;
|
|
||||||
}
|
|
||||||
dir = path.dirname(dir);
|
|
||||||
} while (dir !== '.' && dir !== root);
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
}, this._opts.platforms);
|
|
||||||
|
|
||||||
this._haste.on('change', event => {
|
|
||||||
this._hasteFS = event.hasteFS;
|
|
||||||
this._moduleMap = event.moduleMap;
|
|
||||||
event.eventsQueue.forEach(({type, filePath, stat}) =>
|
|
||||||
this._moduleCache.processFileChange(type, filePath, stat)
|
|
||||||
);
|
|
||||||
this.emit('change');
|
|
||||||
});
|
|
||||||
|
|
||||||
log(createActionEndEntry(initializingPackagerLogEntry));
|
log(createActionEndEntry(initializingPackagerLogEntry));
|
||||||
this._opts.reporter.update({type: 'dep_graph_loaded'});
|
opts.reporter.update({type: 'dep_graph_loaded'});
|
||||||
|
return new DependencyGraph({
|
||||||
|
opts,
|
||||||
|
haste,
|
||||||
|
initialHasteFS: hasteFS,
|
||||||
|
initialModuleMap: moduleMap,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return this._loading;
|
_getClosestPackage(filePath: string): ?string {
|
||||||
|
const parsedPath = path.parse(filePath);
|
||||||
|
const root = parsedPath.root;
|
||||||
|
let dir = parsedPath.dir;
|
||||||
|
do {
|
||||||
|
const candidate = path.join(dir, 'package.json');
|
||||||
|
if (this._hasteFS.exists(candidate)) {
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
dir = path.dirname(dir);
|
||||||
|
} while (dir !== '.' && dir !== root);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_onHasteChange({eventsQueue, hasteFS, moduleMap}) {
|
||||||
|
this._hasteFS = hasteFS;
|
||||||
|
this._moduleMap = moduleMap;
|
||||||
|
eventsQueue.forEach(({type, filePath, stat}) =>
|
||||||
|
this._moduleCache.processFileChange(type, filePath, stat)
|
||||||
|
);
|
||||||
|
this.emit('change');
|
||||||
|
}
|
||||||
|
|
||||||
|
_createModuleCache() {
|
||||||
|
const {_opts} = this;
|
||||||
|
return new ModuleCache({
|
||||||
|
cache: _opts.cache,
|
||||||
|
getTransformCacheKey: _opts.getTransformCacheKey,
|
||||||
|
globalTransformCache: _opts.globalTransformCache,
|
||||||
|
transformCode: _opts.transformCode,
|
||||||
|
depGraphHelpers: this._helpers,
|
||||||
|
assetDependencies: _opts.assetDependencies,
|
||||||
|
moduleOptions: _opts.moduleOptions,
|
||||||
|
reporter: _opts.reporter,
|
||||||
|
getClosestPackage: this._getClosestPackage.bind(this),
|
||||||
|
}, _opts.platforms);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,7 +192,7 @@ class DependencyGraph extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllModules() {
|
getAllModules() {
|
||||||
return this.load().then(() => this._moduleCache.getAllModules());
|
return Promise.resolve(this._moduleCache.getAllModules());
|
||||||
}
|
}
|
||||||
|
|
||||||
getDependencies({
|
getDependencies({
|
||||||
|
@ -195,42 +207,40 @@ class DependencyGraph extends EventEmitter {
|
||||||
transformOptions: TransformOptions,
|
transformOptions: TransformOptions,
|
||||||
onProgress?: ?(finishedModules: number, totalModules: number) => mixed,
|
onProgress?: ?(finishedModules: number, totalModules: number) => mixed,
|
||||||
recursive: boolean,
|
recursive: boolean,
|
||||||
}) {
|
}): Promise<ResolutionResponse> {
|
||||||
return this.load().then(() => {
|
platform = this._getRequestPlatform(entryPath, platform);
|
||||||
platform = this._getRequestPlatform(entryPath, platform);
|
const absPath = this._getAbsolutePath(entryPath);
|
||||||
const absPath = this._getAbsolutePath(entryPath);
|
const dirExists = filePath => {
|
||||||
const dirExists = filePath => {
|
try {
|
||||||
try {
|
return fs.lstatSync(filePath).isDirectory();
|
||||||
return fs.lstatSync(filePath).isDirectory();
|
} catch (e) {}
|
||||||
} catch (e) {}
|
return false;
|
||||||
return false;
|
};
|
||||||
};
|
const req = new ResolutionRequest({
|
||||||
const req = new ResolutionRequest({
|
dirExists,
|
||||||
dirExists,
|
entryPath: absPath,
|
||||||
entryPath: absPath,
|
extraNodeModules: this._opts.extraNodeModules,
|
||||||
extraNodeModules: this._opts.extraNodeModules,
|
hasteFS: this._hasteFS,
|
||||||
hasteFS: this._hasteFS,
|
helpers: this._helpers,
|
||||||
helpers: this._helpers,
|
moduleCache: this._moduleCache,
|
||||||
moduleCache: this._moduleCache,
|
moduleMap: this._moduleMap,
|
||||||
moduleMap: this._moduleMap,
|
platform,
|
||||||
platform,
|
platforms: this._opts.platforms,
|
||||||
platforms: this._opts.platforms,
|
preferNativePlatform: this._opts.preferNativePlatform,
|
||||||
preferNativePlatform: this._opts.preferNativePlatform,
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = new ResolutionResponse({transformOptions});
|
|
||||||
|
|
||||||
return req.getOrderedDependencies({
|
|
||||||
response,
|
|
||||||
transformOptions,
|
|
||||||
onProgress,
|
|
||||||
recursive,
|
|
||||||
}).then(() => response);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const response = new ResolutionResponse({transformOptions});
|
||||||
|
|
||||||
|
return req.getOrderedDependencies({
|
||||||
|
response,
|
||||||
|
transformOptions,
|
||||||
|
onProgress,
|
||||||
|
recursive,
|
||||||
|
}).then(() => response);
|
||||||
}
|
}
|
||||||
|
|
||||||
matchFilesByPattern(pattern: RegExp) {
|
matchFilesByPattern(pattern: RegExp) {
|
||||||
return this.load().then(() => this._hasteFS.matchFiles(pattern));
|
return Promise.resolve(this._hasteFS.matchFiles(pattern));
|
||||||
}
|
}
|
||||||
|
|
||||||
_getRequestPlatform(entryPath: string, platform: string) {
|
_getRequestPlatform(entryPath: string, platform: string) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче