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