Remove Resolver module

Reviewed By: jeanlauliac

Differential Revision: D6674419

fbshipit-source-id: 75cd9dbbc90725850ce23b62c9c8c50922145dd3
This commit is contained in:
Rafael Oleza 2018-01-09 17:40:55 -08:00 committed by Facebook Github Bot
parent a5b0f236e4
commit bdaddb2585
10 changed files with 181 additions and 244 deletions

View File

@ -22,12 +22,10 @@ jest
.mock('progress')
.mock('../../node-haste/DependencyGraph')
.mock('../../JSTransformer')
.mock('../../Resolver')
.mock('metro-core')
.mock('/path/to/transformer.js', () => ({}), {virtual: true});
var Bundler = require('../');
var Resolver = require('../../Resolver');
var defaults = require('../../defaults');
var sizeOf = require('image-size');
var fs = require('fs');
@ -62,10 +60,6 @@ describe('Bundler', function() {
projectRoots = ['/root'];
Resolver.load = jest
.fn()
.mockImplementation(opts => Promise.resolve(new Resolver(opts)));
fs.__setMockFilesystem({
path: {to: {'transformer.js': ''}},
});

View File

@ -12,7 +12,7 @@
'use strict';
const Resolver = require('../Resolver');
const DependencyGraph = require('../node-haste/DependencyGraph');
const Transformer = require('../JSTransformer');
const assert = require('assert');
@ -105,7 +105,7 @@ export type Options = {|
class Bundler {
_opts: Options;
_transformer: Transformer;
_resolverPromise: Promise<Resolver>;
_depGraphPromise: Promise<DependencyGraph>;
_projectRoots: $ReadOnlyArray<string>;
_getTransformOptions: void | GetTransformOptions;
@ -126,7 +126,7 @@ class Bundler {
opts.workerPath || undefined,
);
this._resolverPromise = Resolver.load({
this._depGraphPromise = DependencyGraph.load({
assetExts: opts.assetExts,
assetRegistryPath: opts.assetRegistryPath,
blacklistRE: opts.blacklistRE,
@ -172,11 +172,8 @@ class Bundler {
async end() {
this._transformer.kill();
await this._resolverPromise.then(resolver =>
resolver
.getDependencyGraph()
.getWatcher()
.end(),
await this._depGraphPromise.then(dependencyGraph =>
dependencyGraph.getWatcher().end(),
);
}
@ -248,8 +245,8 @@ class Bundler {
};
}
getResolver(): Promise<Resolver> {
return this._resolverPromise;
getDependencyGraph(): Promise<DependencyGraph> {
return this._depGraphPromise;
}
async minifyModule(

View File

@ -25,8 +25,8 @@ const {EventEmitter} = require('events');
import type Bundler from '../Bundler';
import type {Options as JSTransformerOptions} from '../JSTransformer/worker';
import type Resolver from '../Resolver';
import type {CompactRawMappings} from '../lib/SourceMap';
import type DependencyGraph from '../node-haste/DependencyGraph';
import type Module from '../node-haste/Module';
import type {Options as BundleOptions, MainOptions} from './';
import type {DependencyEdges} from './traverseDependencies';
@ -78,7 +78,7 @@ const globalCreateModuleId = createModuleIdFactory();
*/
class DeltaTransformer extends EventEmitter {
_bundler: Bundler;
_resolver: Resolver;
_dependencyGraph: DependencyGraph;
_getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>;
_polyfillModuleNames: $ReadOnlyArray<string>;
_getModuleId: (path: string) => number;
@ -88,7 +88,7 @@ class DeltaTransformer extends EventEmitter {
constructor(
bundler: Bundler,
resolver: Resolver,
dependencyGraph: DependencyGraph,
deltaCalculator: DeltaCalculator,
options: MainOptions,
bundleOptions: BundleOptions,
@ -96,7 +96,7 @@ class DeltaTransformer extends EventEmitter {
super();
this._bundler = bundler;
this._resolver = resolver;
this._dependencyGraph = dependencyGraph;
this._deltaCalculator = deltaCalculator;
this._getPolyfills = options.getPolyfills;
this._polyfillModuleNames = options.polyfillModuleNames;
@ -121,17 +121,17 @@ class DeltaTransformer extends EventEmitter {
options: MainOptions,
bundleOptions: BundleOptions,
): Promise<DeltaTransformer> {
const resolver = await bundler.getResolver();
const dependencyGraph = await bundler.getDependencyGraph();
const deltaCalculator = new DeltaCalculator(
bundler,
resolver.getDependencyGraph(),
dependencyGraph,
bundleOptions,
);
return new DeltaTransformer(
bundler,
resolver,
dependencyGraph,
deltaCalculator,
options,
bundleOptions,
@ -335,7 +335,7 @@ class DeltaTransformer extends EventEmitter {
const modules = this._getModuleSystemDependencies()
.concat(polyfillModuleNames)
.map(polyfillModuleName =>
this._resolver.getDependencyGraph().createPolyfill({
this._dependencyGraph.createPolyfill({
file: polyfillModuleName,
id: polyfillModuleName,
dependencies: [],
@ -350,12 +350,10 @@ class DeltaTransformer extends EventEmitter {
}
async _getAppend(dependencyEdges: DependencyEdges): Promise<DeltaEntries> {
const dependencyGraph = this._resolver.getDependencyGraph();
// Get the absolute path of the entry file, in order to be able to get the
// actual correspondant module (and its moduleId) to be able to add the
// correct require(); call at the very end of the bundle.
const entryPointModulePath = dependencyGraph.getAbsolutePath(
const entryPointModulePath = this._dependencyGraph.getAbsolutePath(
this._bundleOptions.entryFile,
);

View File

@ -13,7 +13,6 @@
'use strict';
jest.mock('../../Bundler');
jest.mock('../../Resolver');
jest.mock('../traverseDependencies');
const Bundler = require('../../Bundler');

View File

@ -16,6 +16,7 @@ jest
.mock('assert')
.mock('progress')
.mock('../DeltaCalculator')
.mock('../../node-haste/DependencyGraph')
.mock('../../JSTransformer')
.mock('/root/to/something.js', () => ({}), {virtual: true})
.mock('/path/to/transformer.js', () => ({}), {virtual: true});
@ -23,8 +24,8 @@ jest
const fs = require('fs');
const Bundler = require('../../Bundler');
const Resolver = require('../../Resolver');
const DeltaTransformer = require('../DeltaTransformer');
const DependencyGraph = require('../../node-haste/DependencyGraph');
const defaults = require('../../defaults');
@ -48,9 +49,9 @@ const bundlerOptions = {
describe('DeltaTransformer', () => {
let bundler;
beforeEach(() => {
Resolver.load = jest
DependencyGraph.load = jest
.fn()
.mockImplementation(opts => Promise.resolve(new Resolver(opts)));
.mockImplementation(opts => Promise.resolve(new DependencyGraph(opts)));
fs.__setMockFilesystem({
path: {to: {'transformer.js': ''}},

View File

@ -103,12 +103,10 @@ describe('traverseDependencies', function() {
emptyTransformOptions = {transformer: {transform: {}}};
defaults = {
assetExts: ['png', 'jpg'],
forceNodeFilesystemAPI: true,
// This pattern is not expected to match anything.
blacklistRE: /.^/,
providesModuleNodeModules: ['haste-fbjs', 'react-haste', 'react-native'],
platforms: new Set(['ios', 'android']),
useWatchman: false,
// This pattern is not expected to match anything.
ignorePattern: /.^/,
maxWorkers: 1,
resetCache: true,
transformCache: require('TransformCaching').mocked(),
@ -164,7 +162,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -219,7 +217,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -261,7 +259,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -305,7 +303,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -353,7 +351,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -397,7 +395,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -446,7 +444,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -509,7 +507,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -568,7 +566,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -613,7 +611,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -658,7 +656,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -711,7 +709,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -757,7 +755,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -798,7 +796,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -840,7 +838,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -879,7 +877,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -922,7 +920,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -959,7 +957,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -987,7 +985,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
// FIXME: This is broken, jest-haste-map does not fatal on modules with
// the same name, because not fataling was required for supporting some
@ -1022,7 +1020,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
try {
await getOrderedDependenciesAsJSON(dgraph, '/root/index.js');
@ -1060,7 +1058,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -1113,7 +1111,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -1202,7 +1200,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -1263,7 +1261,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -1322,7 +1320,11 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, assetExts: ['png', 'jpg'], roots: [root]};
const opts = {
...defaults,
assetExts: ['png', 'jpg'],
projectRoots: [root],
};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -1379,7 +1381,11 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, assetExts: ['png', 'jpg'], roots: [root]};
const opts = {
...defaults,
assetExts: ['png', 'jpg'],
projectRoots: [root],
};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -1439,7 +1445,11 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, assetExts: ['png', 'jpg'], roots: [root]};
const opts = {
...defaults,
assetExts: ['png', 'jpg'],
projectRoots: [root],
};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -1513,7 +1523,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -1608,7 +1618,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -1682,7 +1692,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -1763,7 +1773,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -1834,7 +1844,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -1901,7 +1911,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -1980,7 +1990,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -2028,7 +2038,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -2135,7 +2145,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -2204,7 +2214,7 @@ describe('traverseDependencies', function() {
const opts = {
...defaults,
roots: [root],
projectRoots: [root],
extraNodeModules: {
bar: root + '/provides-bar',
},
@ -2252,7 +2262,7 @@ describe('traverseDependencies', function() {
const opts = {
...defaults,
roots: [root],
projectRoots: [root],
extraNodeModules: {
bar: root + '/provides-bar',
},
@ -2295,7 +2305,7 @@ describe('traverseDependencies', function() {
const opts = {
...defaults,
roots: [root],
projectRoots: [root],
extraNodeModules: {
bar: root + '/provides-bar',
},
@ -2359,7 +2369,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -2406,7 +2416,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -2455,7 +2465,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -2549,7 +2559,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -2617,7 +2627,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -2690,7 +2700,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -2773,7 +2783,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -2845,7 +2855,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -2974,7 +2984,7 @@ describe('traverseDependencies', function() {
};
setMockFileSystem(filesystem);
const opts = {...defaults, roots: [root, otherRoot]};
const opts = {...defaults, projectRoots: [root, otherRoot]};
await processDgraph(opts, async dgraph => {
try {
await getOrderedDependenciesAsJSON(dgraph, '/root/index.js');
@ -3070,7 +3080,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -3117,7 +3127,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -3170,7 +3180,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -3227,7 +3237,7 @@ describe('traverseDependencies', function() {
const opts = {
...defaults,
platforms: new Set(['ios', 'android', 'web']),
roots: [root],
projectRoots: [root],
};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
@ -3269,7 +3279,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -3324,7 +3334,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -3377,7 +3387,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -3464,7 +3474,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -3532,7 +3542,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -3605,7 +3615,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -3688,7 +3698,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -3760,7 +3770,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -3889,7 +3899,7 @@ describe('traverseDependencies', function() {
};
setMockFileSystem(filesystem);
const opts = {...defaults, roots: [root, otherRoot]};
const opts = {...defaults, projectRoots: [root, otherRoot]};
const entryPath = 'C:\\root\\index.js';
await processDgraph(opts, async dgraph => {
try {
@ -3984,7 +3994,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -4031,7 +4041,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -4084,7 +4094,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -4138,7 +4148,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -4179,7 +4189,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -4234,7 +4244,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -4316,7 +4326,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
const entryPath = '/root/index.js';
await processDgraph(opts, async dgraph => {
await getOrderedDependenciesAsJSON(dgraph, entryPath);
@ -4372,7 +4382,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
const entryPath = '/root/index.js';
await processDgraph(opts, async dgraph => {
await getOrderedDependenciesAsJSON(dgraph, entryPath);
@ -4428,7 +4438,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
const entryPath = '/root/index.js';
await processDgraph(opts, async dgraph => {
await getOrderedDependenciesAsJSON(dgraph, entryPath);
@ -4475,7 +4485,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
const entryPath = '/root/index.js';
await processDgraph(opts, async dgraph => {
await getOrderedDependenciesAsJSON(dgraph, entryPath);
@ -4544,7 +4554,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, assetExts: ['png'], roots: [root]};
const opts = {...defaults, assetExts: ['png'], projectRoots: [root]};
const entryPath = '/root/index.js';
await processDgraph(opts, async dgraph => {
try {
@ -4603,7 +4613,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
const entryPath = '/root/index.js';
await processDgraph(opts, async dgraph => {
await getOrderedDependenciesAsJSON(dgraph, entryPath);
@ -4660,7 +4670,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
const entryPath = '/root/index.js';
await processDgraph(opts, async dgraph => {
await getOrderedDependenciesAsJSON(dgraph, entryPath);
@ -4732,7 +4742,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
const entryPath = '/root/index.js';
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(dgraph, entryPath);
@ -4816,7 +4826,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
const entryPath = '/root/index.js';
await processDgraph(opts, async dgraph => {
await getOrderedDependenciesAsJSON(dgraph, entryPath);
@ -4873,7 +4883,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
const entryPath = '/root/index.js';
await processDgraph(opts, async dgraph => {
await getOrderedDependenciesAsJSON(dgraph, entryPath);
@ -4900,7 +4910,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
const entryPath = '/root/index.js';
await processDgraph(opts, async dgraph => {
await getOrderedDependenciesAsJSON(dgraph, entryPath);
@ -4960,7 +4970,11 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root], sourceExts: ['jsx', 'coffee']};
const opts = {
...defaults,
projectRoots: [root],
sourceExts: ['jsx', 'coffee'],
};
await processDgraph(opts, async dgraph => {
const entryPath = '/root/index.jsx';
const deps = await getOrderedDependenciesAsJSON(dgraph, entryPath);
@ -4993,7 +5007,11 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root], sourceExts: ['jsx', 'coffee']};
const opts = {
...defaults,
projectRoots: [root],
sourceExts: ['jsx', 'coffee'],
};
await processDgraph(opts, async dgraph => {
const deps = await getOrderedDependenciesAsJSON(
dgraph,
@ -5028,7 +5046,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, roots: [root]};
const opts = {...defaults, projectRoots: [root]};
await processDgraph(opts, async dgraph => {
try {
await getOrderedDependenciesAsJSON(dgraph, '/root/index.jsx');
@ -5082,10 +5100,13 @@ describe('traverseDependencies', function() {
},
});
const DependencyGraph = require('../../node-haste/DependencyGraph');
return DependencyGraph.load({
return DependencyGraph.load(
{
...defaults,
roots: ['/root'],
}).then(dg => {
projectRoots: ['/root'],
},
false /* since we're mocking the filesystem, we cannot use watchman */,
).then(dg => {
dependencyGraph = dg;
});
});
@ -5130,7 +5151,7 @@ describe('traverseDependencies', function() {
},
});
const opts = {...defaults, assetDependencies, roots: ['/root']};
const opts = {...defaults, assetDependencies, projectRoots: ['/root']};
await processDgraph(opts, async dgraph => {
const {dependencies} = await dgraph.getDependencies({
entryPath: '/root/index.js',
@ -5170,10 +5191,13 @@ describe('traverseDependencies', function() {
'f.js': 'require("./c");', // circular dependency
},
});
dependencyGraph = DependencyGraph.load({
dependencyGraph = DependencyGraph.load(
{
...defaults,
roots: ['/root'],
});
projectRoots: ['/root'],
},
false /* since we're mocking the filesystem, we cannot use watchman */,
);
moduleReadDeferreds = {};
callDeferreds = [defer(), defer()]; // [a.js, b.js]
@ -5276,10 +5300,13 @@ describe('traverseDependencies', function() {
});
DependencyGraph = require('../../node-haste/DependencyGraph');
dependencyGraph = await DependencyGraph.load({
dependencyGraph = await DependencyGraph.load(
{
...defaults,
roots: ['/root'],
});
projectRoots: ['/root'],
},
false /* since we're mocking the filesystem, we cannot use watchman */,
);
});
afterEach(() => {
@ -5305,7 +5332,10 @@ describe('traverseDependencies', function() {
* (regardless if the test passes or fails).
*/
async function processDgraphFor(DependencyGraph, options, processor) {
const dgraph = await DependencyGraph.load(options);
const dgraph = await DependencyGraph.load(
options,
false /* since we're mocking the filesystem, we cannot use watchman */,
);
try {
await processor(dgraph);
} finally {

View File

@ -1,85 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
* @format
*/
'use strict';
const DependencyGraph = require('../node-haste/DependencyGraph');
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
import type {
TransformCache,
GetTransformCacheKey,
} from '../lib/TransformCaching';
import type {Reporter} from '../lib/reporting';
import type {HasteImpl, TransformCode} from '../node-haste/Module';
type Options = {|
+assetExts: Array<string>,
+assetRegistryPath: string,
+blacklistRE?: RegExp,
+extraNodeModules: ?{},
+getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
+getTransformCacheKey: GetTransformCacheKey,
+globalTransformCache: ?GlobalTransformCache,
+hasteImpl?: ?HasteImpl,
+maxWorkers: number,
+platforms: Set<string>,
+polyfillModuleNames?: Array<string>,
+projectRoots: $ReadOnlyArray<string>,
+providesModuleNodeModules: Array<string>,
+reporter: Reporter,
+resetCache: boolean,
+sourceExts: Array<string>,
+transformCache: TransformCache,
+transformCode: TransformCode,
+watch: boolean,
|};
class Resolver {
_depGraph: DependencyGraph;
constructor(opts: Options, depGraph: DependencyGraph) {
this._depGraph = depGraph;
}
static async load(opts: Options): Promise<Resolver> {
const depGraph = await DependencyGraph.load({
assetDependencies: [opts.assetRegistryPath],
assetExts: opts.assetExts,
extraNodeModules: opts.extraNodeModules,
forceNodeFilesystemAPI: false,
getTransformCacheKey: opts.getTransformCacheKey,
globalTransformCache: opts.globalTransformCache,
hasteImpl: opts.hasteImpl,
ignorePattern: opts.blacklistRE || / ^/ /* matches nothing */,
maxWorkers: opts.maxWorkers,
platforms: opts.platforms,
preferNativePlatform: true,
providesModuleNodeModules: opts.providesModuleNodeModules,
reporter: opts.reporter,
resetCache: opts.resetCache,
roots: opts.projectRoots,
sourceExts: opts.sourceExts,
transformCache: opts.transformCache,
transformCode: opts.transformCode,
useWatchman: true,
watch: opts.watch,
});
return new Resolver(opts, depGraph);
}
getDependencyGraph(): DependencyGraph {
return this._depGraph;
}
}
module.exports = Resolver;

View File

@ -109,13 +109,11 @@ describe('processRequest', () => {
);
Bundler.prototype.invalidateFile = invalidatorFunc;
Bundler.prototype.getResolver = jest.fn().mockReturnValue(
Bundler.prototype.getDependencyGraph = jest.fn().mockReturnValue(
Promise.resolve({
getDependencyGraph: jest.fn().mockReturnValue({
getHasteMap: jest.fn().mockReturnValue({on: jest.fn()}),
load: jest.fn(() => Promise.resolve()),
}),
}),
);
server = new Server(options);

View File

@ -169,9 +169,8 @@ class Server {
this._bundler = new Bundler(bundlerOpts);
// changes to the haste map can affect resolution of files in the bundle
this._bundler.getResolver().then(resolver => {
resolver
.getDependencyGraph()
this._bundler.getDependencyGraph().then(dependencyGraph => {
dependencyGraph
.getWatcher()
.on('change', ({eventsQueue}) =>
eventsQueue.forEach(processFileChange),

View File

@ -45,26 +45,24 @@ import type Package from './Package';
import type {HasteFS} from './types';
type Options = {|
+assetDependencies: Array<string>,
+assetExts: Array<string>,
+assetRegistryPath: string,
+blacklistRE?: RegExp,
+extraNodeModules: ?{},
+forceNodeFilesystemAPI: boolean,
+getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
+getTransformCacheKey: GetTransformCacheKey,
+globalTransformCache: ?GlobalTransformCache,
+hasteImpl: ?HasteImpl,
+ignorePattern: RegExp,
+hasteImpl?: ?HasteImpl,
+maxWorkers: number,
+platforms: Set<string>,
+preferNativePlatform: boolean,
+polyfillModuleNames?: Array<string>,
+projectRoots: $ReadOnlyArray<string>,
+providesModuleNodeModules: Array<string>,
+reporter: Reporter,
+resetCache: ?boolean,
+resetCache: boolean,
+roots: $ReadOnlyArray<string>,
+sourceExts: Array<string>,
+transformCache: TransformCache,
+transformCode: TransformCode,
+useWatchman: boolean,
+watch: boolean,
|};
@ -106,11 +104,14 @@ class DependencyGraph extends EventEmitter {
this._createModuleResolver();
}
static _createHaste(opts: Options): JestHasteMap {
static _createHaste(
opts: Options,
useWatchman?: boolean = true,
): JestHasteMap {
return new JestHasteMap({
extensions: opts.sourceExts.concat(opts.assetExts),
forceNodeFilesystemAPI: opts.forceNodeFilesystemAPI,
ignorePattern: opts.ignorePattern,
forceNodeFilesystemAPI: !useWatchman,
ignorePattern: opts.blacklistRE || / ^/,
maxWorkers: opts.maxWorkers,
mocksPattern: '',
name: 'metro-' + JEST_HASTE_MAP_CACHE_BREAKER,
@ -118,19 +119,24 @@ class DependencyGraph extends EventEmitter {
providesModuleNodeModules: opts.providesModuleNodeModules,
resetCache: opts.resetCache,
retainAllFiles: true,
roots: opts.roots,
useWatchman: opts.useWatchman,
roots: opts.projectRoots,
useWatchman,
watch: opts.watch,
});
}
static async load(opts: Options): Promise<DependencyGraph> {
static _getJestHasteMapOptions(opts: Options) {}
static async load(
opts: Options,
useWatchman?: boolean = true,
): Promise<DependencyGraph> {
const initializingMetroLogEntry = log(
createActionStartEntry('Initializing Metro'),
);
opts.reporter.update({type: 'dep_graph_loading'});
const haste = DependencyGraph._createHaste(opts);
const haste = DependencyGraph._createHaste(opts, useWatchman);
const {hasteFS, moduleMap} = await haste.build();
log(createActionEndEntry(initializingMetroLogEntry));
@ -183,7 +189,7 @@ class DependencyGraph extends EventEmitter {
isAssetFile: filePath => this._helpers.isAssetFile(filePath),
moduleCache: this._moduleCache,
moduleMap: this._moduleMap,
preferNativePlatform: this._opts.preferNativePlatform,
preferNativePlatform: true,
resolveAsset: (dirPath, assetName, platform) =>
this._assetResolutionCache.resolve(dirPath, assetName, platform),
sourceExts: this._opts.sourceExts,
@ -194,7 +200,7 @@ class DependencyGraph extends EventEmitter {
const {_opts} = this;
return new ModuleCache(
{
assetDependencies: _opts.assetDependencies,
assetDependencies: [_opts.assetRegistryPath],
depGraphHelpers: this._helpers,
getClosestPackage: this._getClosestPackage.bind(this),
getTransformCacheKey: _opts.getTransformCacheKey,
@ -203,7 +209,7 @@ class DependencyGraph extends EventEmitter {
resetCache: _opts.resetCache,
transformCache: _opts.transformCache,
reporter: _opts.reporter,
roots: _opts.roots,
roots: _opts.projectRoots,
transformCode: _opts.transformCode,
},
_opts.platforms,
@ -274,8 +280,8 @@ class DependencyGraph extends EventEmitter {
return path.resolve(filePath);
}
for (let i = 0; i < this._opts.roots.length; i++) {
const root = this._opts.roots[i];
for (let i = 0; i < this._opts.projectRoots.length; i++) {
const root = this._opts.projectRoots[i];
const potentialAbsPath = path.join(root, filePath);
if (this._hasteFS.exists(potentialAbsPath)) {
return path.resolve(potentialAbsPath);
@ -298,7 +304,7 @@ class DependencyGraph extends EventEmitter {
throw new NotFoundError(
'Cannot find entry file %s in any of the roots: %j',
filePath,
this._opts.roots,
this._opts.projectRoots,
);
}