diff --git a/packager/src/Resolver/__tests__/Resolver-test.js b/packager/src/Resolver/__tests__/Resolver-test.js index 33205179d..ca294f09b 100644 --- a/packager/src/Resolver/__tests__/Resolver-test.js +++ b/packager/src/Resolver/__tests__/Resolver-test.js @@ -113,7 +113,7 @@ describe('Resolver', function() { platforms: ['ios', 'windows', 'vr'], }); const platforms = DependencyGraph.mock.calls[0][0].platforms; - expect(platforms).toEqual(['ios', 'windows', 'vr']); + expect(Array.from(platforms)).toEqual(['ios', 'windows', 'vr']); }); it('should get dependencies with polyfills', function() { diff --git a/packager/src/Resolver/index.js b/packager/src/Resolver/index.js index eb8432e4e..36f85f962 100644 --- a/packager/src/Resolver/index.js +++ b/packager/src/Resolver/index.js @@ -59,23 +59,27 @@ class Resolver { assetExts: opts.assetExts, cache: opts.cache, extraNodeModules: opts.extraNodeModules, + extensions: ['js', 'json'], + forceNodeFilesystemAPI: false, getTransformCacheKey: opts.getTransformCacheKey, globalTransformCache: opts.globalTransformCache, ignoreFilePath: function(filepath) { return filepath.indexOf('__tests__') !== -1 || (opts.blacklistRE != null && opts.blacklistRE.test(filepath)); }, + maxWorkers: null, moduleOptions: { cacheTransformResults: true, resetCache: opts.resetCache, }, - platforms: opts.platforms, + platforms: new Set(opts.platforms), preferNativePlatform: true, providesModuleNodeModules: opts.providesModuleNodeModules || defaults.providesModuleNodeModules, reporter: opts.reporter, resetCache: opts.resetCache, roots: opts.projectRoots, transformCode: opts.transformCode, + useWatchman: true, watch: opts.watch || false, }); diff --git a/packager/src/node-haste/__tests__/DependencyGraph-test.js b/packager/src/node-haste/__tests__/DependencyGraph-test.js index b87c0600f..a1318d828 100644 --- a/packager/src/node-haste/__tests__/DependencyGraph-test.js +++ b/packager/src/node-haste/__tests__/DependencyGraph-test.js @@ -106,15 +106,18 @@ describe('DependencyGraph', function() { defaults = { assetExts: ['png', 'jpg'], cache: new Cache(), + extensions: ['js', 'json'], forceNodeFilesystemAPI: true, providesModuleNodeModules: [ 'haste-fbjs', 'react-haste', 'react-native', ], - platforms: ['ios', 'android'], + platforms: new Set(['ios', 'android']), useWatchman: false, + ignoreFilePath: () => false, maxWorkers: 1, + moduleOptions: {cacheTransformResults: true}, resetCache: true, transformCode: (module, sourceCode, transformOptions) => { return new Promise(resolve => { @@ -127,6 +130,7 @@ describe('DependencyGraph', function() { }, getTransformCacheKey: () => 'abcdef', reporter: require('../../lib/reporting').nullReporter, + watch: false, }; }); @@ -3423,7 +3427,7 @@ describe('DependencyGraph', function() { var dgraph = new DependencyGraph({ ...defaults, - platforms: ['ios', 'android', 'web'], + platforms: new Set(['ios', 'android', 'web']), roots: [root], }); return getOrderedDependenciesAsJSON(dgraph, '/root/index.ios.js').then(function(deps) { diff --git a/packager/src/node-haste/index.js b/packager/src/node-haste/index.js index 995a64989..0357f7b46 100644 --- a/packager/src/node-haste/index.js +++ b/packager/src/node-haste/index.js @@ -49,114 +49,42 @@ import type {HasteFS} from './types'; const ERROR_BUILDING_DEP_GRAPH = 'DependencyGraphError'; +type Options = { + assetDependencies: Array, + assetExts: Array, + cache: Cache, + extensions: Array, + extraNodeModules: ?Object, + forceNodeFilesystemAPI: boolean, + getTransformCacheKey: GetTransformCacheKey, + globalTransformCache: ?GlobalTransformCache, + ignoreFilePath: (filePath: string) => boolean, + maxWorkers: ?number, + moduleOptions: ModuleOptions, + platforms: Set, + preferNativePlatform: boolean, + providesModuleNodeModules: Array, + reporter: Reporter, + resetCache: boolean, + roots: Array, + transformCode: TransformCode, + useWatchman: boolean, + watch: boolean, +}; + class DependencyGraph { - _opts: {| - assetExts: Array, - extensions: Array, - extraNodeModules: ?Object, - forceNodeFilesystemAPI: boolean, - globalTransformCache: ?GlobalTransformCache, - ignoreFilePath: (filePath: string) => boolean, - maxWorkers: ?number, - mocksPattern: mixed, - moduleOptions: ModuleOptions, - platforms: Set, - preferNativePlatform: boolean, - providesModuleNodeModules: Array, - resetCache: boolean, - roots: Array, - shouldThrowOnUnresolvedErrors: () => boolean, - getTransformCacheKey: GetTransformCacheKey, - transformCode: TransformCode, - useWatchman: boolean, - watch: boolean, - |}; - _assetDependencies: Array; - _cache: Cache; + _opts: Options; _haste: JestHasteMap; _hasteFS: HasteFS; _hasteMap: HasteMap; _hasteMapError: ?Error; _helpers: DependencyGraphHelpers; _moduleCache: ModuleCache; - _reporter: Reporter; _loading: Promise; - constructor({ - assetDependencies, - assetExts, - cache, - extensions, - extraNodeModules, - forceNodeFilesystemAPI, - getTransformCacheKey, - globalTransformCache, - ignoreFilePath, - maxWorkers, - mocksPattern, - moduleOptions, - platforms, - preferNativePlatform, - providesModuleNodeModules, - resetCache, - roots, - shouldThrowOnUnresolvedErrors = () => true, - transformCode, - useWatchman, - watch, - reporter, - }: { - assetDependencies: Array, - assetExts: Array, - cache: Cache, - extensions?: ?Array, - extraNodeModules: ?Object, - forceNodeFilesystemAPI?: boolean, - getTransformCacheKey: GetTransformCacheKey, - globalTransformCache: ?GlobalTransformCache, - ignoreFilePath: (filePath: string) => boolean, - maxWorkers?: ?number, - mocksPattern?: mixed, - moduleOptions: ?ModuleOptions, - platforms: Array, - preferNativePlatform: boolean, - providesModuleNodeModules: Array, - resetCache: boolean, - roots: Array, - shouldThrowOnUnresolvedErrors?: () => boolean, - transformCode: TransformCode, - useWatchman?: ?boolean, - watch: boolean, - reporter: Reporter, - }) { - this._opts = { - assetExts: assetExts || [], - extensions: extensions || ['js', 'json'], - extraNodeModules, - forceNodeFilesystemAPI: !!forceNodeFilesystemAPI, - getTransformCacheKey, - globalTransformCache, - ignoreFilePath: ignoreFilePath || (() => {}), - maxWorkers, - mocksPattern, - moduleOptions: moduleOptions || { - cacheTransformResults: true, - }, - platforms: new Set(platforms || []), - preferNativePlatform: preferNativePlatform || false, - providesModuleNodeModules, - resetCache, - roots, - shouldThrowOnUnresolvedErrors, - transformCode, - useWatchman: useWatchman !== false, - watch: !!watch, - }; - - this._reporter = reporter; - this._cache = cache; - this._assetDependencies = assetDependencies; + constructor(opts: Options) { + this._opts = {...opts}; this._helpers = new DependencyGraphHelpers(this._opts); this.load(); } @@ -185,20 +113,20 @@ class DependencyGraph { const initializingPackagerLogEntry = log(createActionStartEntry('Initializing Packager')); - this._reporter.update({type: 'dep_graph_loading'}); + this._opts.reporter.update({type: 'dep_graph_loading'}); this._loading = this._haste.build().then(({hasteFS}) => { this._hasteFS = hasteFS; const hasteFSFiles = hasteFS.getAllFiles(); this._moduleCache = new ModuleCache({ - cache: this._cache, + cache: this._opts.cache, getTransformCacheKey: this._opts.getTransformCacheKey, globalTransformCache: this._opts.globalTransformCache, transformCode: this._opts.transformCode, depGraphHelpers: this._helpers, - assetDependencies: this._assetDependencies, + assetDependencies: this._opts.assetDependencies, moduleOptions: this._opts.moduleOptions, - reporter: this._reporter, + reporter: this._opts.reporter, getClosestPackage: filePath => { let {dir, root} = path.parse(filePath); do { @@ -235,7 +163,7 @@ class DependencyGraph { map => { log(createActionEndEntry(buildingHasteMapLogEntry)); log(createActionEndEntry(initializingPackagerLogEntry)); - this._reporter.update({type: 'dep_graph_loaded'}); + this._opts.reporter.update({type: 'dep_graph_loaded'}); return map; }, err => {