Don't require Activity inside of DependencyResolver
Reviewed By: martinbigio Differential Revision: D2619364 fb-gh-sync-id: 7947388c8041e5d6cbc1e20c8eb9fc7325dc46e0
This commit is contained in:
parent
478a712d20
commit
145a72df80
|
@ -8,7 +8,6 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const Activity = require('../../Activity');
|
||||
const AssetModule_DEPRECATED = require('../AssetModule_DEPRECATED');
|
||||
const Fastfs = require('../fastfs');
|
||||
const debug = require('debug')('ReactNativePackager:DependencyGraph');
|
||||
|
@ -16,7 +15,15 @@ const path = require('path');
|
|||
const Promise = require('promise');
|
||||
|
||||
class DeprecatedAssetMap {
|
||||
constructor({ fsCrawl, roots, assetExts, fileWatcher, ignoreFilePath, helpers }) {
|
||||
constructor({
|
||||
fsCrawl,
|
||||
roots,
|
||||
assetExts,
|
||||
fileWatcher,
|
||||
ignoreFilePath,
|
||||
helpers,
|
||||
activity
|
||||
}) {
|
||||
if (roots == null || roots.length === 0) {
|
||||
this._disabled = true;
|
||||
return;
|
||||
|
@ -29,8 +36,9 @@ class DeprecatedAssetMap {
|
|||
'Assets',
|
||||
roots,
|
||||
fileWatcher,
|
||||
{ ignore: ignoreFilePath, crawling: fsCrawl }
|
||||
{ ignore: ignoreFilePath, crawling: fsCrawl, activity }
|
||||
);
|
||||
this._activity = activity;
|
||||
|
||||
this._fastfs.on('change', this._processFileChange.bind(this));
|
||||
}
|
||||
|
@ -42,15 +50,21 @@ class DeprecatedAssetMap {
|
|||
|
||||
return this._fastfs.build().then(
|
||||
() => {
|
||||
const processAsset_DEPRECATEDActivity = Activity.startEvent(
|
||||
'Building (deprecated) Asset Map',
|
||||
);
|
||||
const activity = this._activity;
|
||||
let processAsset_DEPRECATEDActivity;
|
||||
if (activity) {
|
||||
processAsset_DEPRECATEDActivity = activity.startEvent(
|
||||
'Building (deprecated) Asset Map',
|
||||
);
|
||||
}
|
||||
|
||||
this._fastfs.findFilesByExts(this._assetExts).forEach(
|
||||
file => this._processAsset(file)
|
||||
);
|
||||
|
||||
Activity.endEvent(processAsset_DEPRECATEDActivity);
|
||||
if (activity) {
|
||||
activity.endEvent(processAsset_DEPRECATEDActivity);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const Activity = require('../../Activity');
|
||||
const Fastfs = require('../fastfs');
|
||||
const ModuleCache = require('../ModuleCache');
|
||||
const Promise = require('promise');
|
||||
|
@ -25,14 +24,20 @@ const HasteMap = require('./HasteMap');
|
|||
const DeprecatedAssetMap = require('./DeprecatedAssetMap');
|
||||
|
||||
const validateOpts = declareOpts({
|
||||
activity: {
|
||||
type: 'object',
|
||||
default: {
|
||||
startEvent: () => {},
|
||||
endEvent: () => {},
|
||||
},
|
||||
},
|
||||
roots: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
},
|
||||
ignoreFilePath: {
|
||||
type: 'function',
|
||||
|
||||
default: function(){}
|
||||
default: () => {}
|
||||
},
|
||||
fileWatcher: {
|
||||
type: 'object',
|
||||
|
@ -86,15 +91,16 @@ class DependencyGraph {
|
|||
return this._loading;
|
||||
}
|
||||
|
||||
const depGraphActivity = Activity.startEvent('Building Dependency Graph');
|
||||
const crawlActivity = Activity.startEvent('Crawling File System');
|
||||
const {activity} = this._opts;
|
||||
const depGraphActivity = activity.startEvent('Building Dependency Graph');
|
||||
const crawlActivity = activity.startEvent('Crawling File System');
|
||||
const allRoots = this._opts.roots.concat(this._opts.assetRoots_DEPRECATED);
|
||||
this._crawling = crawl(allRoots, {
|
||||
ignore: this._opts.ignoreFilePath,
|
||||
exts: ['js', 'json'].concat(this._opts.assetExts),
|
||||
fileWatcher: this._opts.fileWatcher,
|
||||
});
|
||||
this._crawling.then((files) => Activity.endEvent(crawlActivity));
|
||||
this._crawling.then((files) => activity.endEvent(crawlActivity));
|
||||
|
||||
this._fastfs = new Fastfs(
|
||||
'JavaScript',
|
||||
|
@ -103,6 +109,7 @@ class DependencyGraph {
|
|||
{
|
||||
ignore: this._opts.ignoreFilePath,
|
||||
crawling: this._crawling,
|
||||
activity: activity,
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -124,17 +131,18 @@ class DependencyGraph {
|
|||
fileWatcher: this._opts.fileWatcher,
|
||||
ignoreFilePath: this._opts.ignoreFilePath,
|
||||
assetExts: this._opts.assetExts,
|
||||
activity: this._opts.activity,
|
||||
});
|
||||
|
||||
this._loading = Promise.all([
|
||||
this._fastfs.build()
|
||||
.then(() => {
|
||||
const hasteActivity = Activity.startEvent('Building Haste Map');
|
||||
return this._hasteMap.build().then(() => Activity.endEvent(hasteActivity));
|
||||
const hasteActivity = activity.startEvent('Building Haste Map');
|
||||
return this._hasteMap.build().then(() => activity.endEvent(hasteActivity));
|
||||
}),
|
||||
this._deprecatedAssetMap.build(),
|
||||
]).then(() =>
|
||||
Activity.endEvent(depGraphActivity)
|
||||
activity.endEvent(depGraphActivity)
|
||||
);
|
||||
|
||||
return this._loading;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
const Activity = require('../Activity');
|
||||
const Promise = require('promise');
|
||||
const {EventEmitter} = require('events');
|
||||
|
||||
|
@ -15,7 +14,7 @@ const hasOwn = Object.prototype.hasOwnProperty;
|
|||
const NOT_FOUND_IN_ROOTS = 'NotFoundInRootsError';
|
||||
|
||||
class Fastfs extends EventEmitter {
|
||||
constructor(name, roots, fileWatcher, {ignore, crawling}) {
|
||||
constructor(name, roots, fileWatcher, {ignore, crawling, activity}) {
|
||||
super();
|
||||
this._name = name;
|
||||
this._fileWatcher = fileWatcher;
|
||||
|
@ -23,6 +22,7 @@ class Fastfs extends EventEmitter {
|
|||
this._roots = roots.map(root => new File(root, { isDir: true }));
|
||||
this._fastPaths = Object.create(null);
|
||||
this._crawling = crawling;
|
||||
this._activity = activity;
|
||||
}
|
||||
|
||||
build() {
|
||||
|
@ -31,7 +31,11 @@ class Fastfs extends EventEmitter {
|
|||
);
|
||||
|
||||
return this._crawling.then(files => {
|
||||
const fastfsActivity = Activity.startEvent('Building in-memory fs for ' + this._name);
|
||||
let fastfsActivity;
|
||||
const activity = this._activity;
|
||||
if (activity) {
|
||||
fastfsActivity = activity.startEvent('Building in-memory fs for ' + this._name);
|
||||
}
|
||||
files.forEach(filePath => {
|
||||
if (filePath.match(rootsPattern)) {
|
||||
const newFile = new File(filePath, { isDir: false });
|
||||
|
@ -48,7 +52,9 @@ class Fastfs extends EventEmitter {
|
|||
}
|
||||
}
|
||||
});
|
||||
Activity.endEvent(fastfsActivity);
|
||||
if (activity) {
|
||||
activity.endEvent(fastfsActivity);
|
||||
}
|
||||
this._fileWatcher.on('all', this._processFileChange.bind(this));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,14 +8,16 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
var DependencyGraph = require('../DependencyResolver/DependencyGraph');
|
||||
var replacePatterns = require('../DependencyResolver/replacePatterns');
|
||||
var Polyfill = require('../DependencyResolver/Polyfill');
|
||||
var declareOpts = require('../lib/declareOpts');
|
||||
var Promise = require('promise');
|
||||
|
||||
var validateOpts = declareOpts({
|
||||
const path = require('path');
|
||||
const Activity = require('../Activity');
|
||||
const DependencyGraph = require('../DependencyResolver/DependencyGraph');
|
||||
const replacePatterns = require('../DependencyResolver/replacePatterns');
|
||||
const Polyfill = require('../DependencyResolver/Polyfill');
|
||||
const declareOpts = require('../lib/declareOpts');
|
||||
const Promise = require('promise');
|
||||
|
||||
const validateOpts = declareOpts({
|
||||
projectRoots: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
|
@ -49,7 +51,7 @@ var validateOpts = declareOpts({
|
|||
},
|
||||
});
|
||||
|
||||
var getDependenciesValidateOpts = declareOpts({
|
||||
const getDependenciesValidateOpts = declareOpts({
|
||||
dev: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
|
@ -63,9 +65,10 @@ var getDependenciesValidateOpts = declareOpts({
|
|||
class Resolver {
|
||||
|
||||
constructor(options) {
|
||||
var opts = validateOpts(options);
|
||||
const opts = validateOpts(options);
|
||||
|
||||
this._depGraph = new DependencyGraph({
|
||||
activity: Activity,
|
||||
roots: opts.projectRoots,
|
||||
assetRoots_DEPRECATED: opts.assetRoots,
|
||||
assetExts: opts.assetExts,
|
||||
|
@ -81,7 +84,7 @@ class Resolver {
|
|||
}
|
||||
|
||||
getDependencies(main, options) {
|
||||
var opts = getDependenciesValidateOpts(options);
|
||||
const opts = getDependenciesValidateOpts(options);
|
||||
|
||||
return this._depGraph.getDependencies(main, opts.platform).then(
|
||||
resolutionResponse => {
|
||||
|
@ -95,7 +98,7 @@ class Resolver {
|
|||
}
|
||||
|
||||
_getPolyfillDependencies(isDev) {
|
||||
var polyfillModuleNames = [
|
||||
const polyfillModuleNames = [
|
||||
isDev
|
||||
? path.join(__dirname, 'polyfills/prelude_dev.js')
|
||||
: path.join(__dirname, 'polyfills/prelude.js'),
|
||||
|
|
Loading…
Reference in New Issue