From eb489bf105552e07a45dbc4d4f7d469e06ab5b3a Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Tue, 9 Jan 2018 17:40:47 -0800 Subject: [PATCH] Remove logic to calculate polyfills from Resolver Reviewed By: jeanlauliac Differential Revision: D6674424 fbshipit-source-id: 20c0ace056150c1f6910edc7eadf8effb9ddf38d --- .../src/DeltaBundler/DeltaTransformer.js | 28 +++++++++------ packages/metro/src/Resolver/index.js | 34 +++---------------- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/packages/metro/src/DeltaBundler/DeltaTransformer.js b/packages/metro/src/DeltaBundler/DeltaTransformer.js index f04ff2ae..620ac184 100644 --- a/packages/metro/src/DeltaBundler/DeltaTransformer.js +++ b/packages/metro/src/DeltaBundler/DeltaTransformer.js @@ -16,7 +16,9 @@ const DeltaCalculator = require('./DeltaCalculator'); const addParamsToDefineCall = require('../lib/addParamsToDefineCall'); const createModuleIdFactory = require('../lib/createModuleIdFactory'); +const defaults = require('../defaults'); const nullthrows = require('fbjs/lib/nullthrows'); +const path = require('path'); const removeInlineRequiresBlacklistFromOptions = require('../lib/removeInlineRequiresBlacklistFromOptions'); const {EventEmitter} = require('events'); @@ -328,21 +330,17 @@ class DeltaTransformer extends EventEmitter { platform: this._bundleOptions.platform, }).concat(this._polyfillModuleNames); - // The module system dependencies are scripts that need to be included at - // the very beginning of the bundle (before any polyfill). - const moduleSystemDeps = this._resolver.getModuleSystemDependencies({ - dev: this._bundleOptions.dev, - }); - - const modules = moduleSystemDeps.concat( - polyfillModuleNames.map((polyfillModuleName, idx) => + // Build the module system dependencies (scripts that need to + // be included at the very beginning of the bundle) + any polifyll. + const modules = this._getModuleSystemDependencies() + .concat(polyfillModuleNames) + .map(polyfillModuleName => this._resolver.getDependencyGraph().createPolyfill({ file: polyfillModuleName, id: polyfillModuleName, dependencies: [], }), - ), - ); + ); return await this._transformModules( modules, @@ -534,6 +532,16 @@ class DeltaTransformer extends EventEmitter { _onFileChange = () => { this.emit('change'); }; + + _getModuleSystemDependencies() { + const prelude = this._bundleOptions.dev + ? path.resolve(__dirname, '../Resolver/polyfills/prelude_dev.js') + : path.resolve(__dirname, '../Resolver/polyfills/prelude.js'); + + const moduleSystem = defaults.moduleSystem; + + return [prelude, moduleSystem]; + } } module.exports = DeltaTransformer; diff --git a/packages/metro/src/Resolver/index.js b/packages/metro/src/Resolver/index.js index df2383ca..f979b996 100644 --- a/packages/metro/src/Resolver/index.js +++ b/packages/metro/src/Resolver/index.js @@ -14,26 +14,22 @@ const DependencyGraph = require('../node-haste/DependencyGraph'); -const defaults = require('../defaults'); - const { compactMapping, fromRawMappings, toRawMappings, } = require('metro-source-map'); -const pathJoin = require('path').join; -import type Module, {HasteImpl, TransformCode} from '../node-haste/Module'; -import type {CompactRawMappings} from '../lib/SourceMap'; import type {PostMinifyProcess} from '../Bundler'; -import type {Reporter} from '../lib/reporting'; +import typeof {minify as MinifyCode} from '../JSTransformer/worker'; +import type {GlobalTransformCache} from '../lib/GlobalTransformCache'; +import type {CompactRawMappings} from '../lib/SourceMap'; import type { TransformCache, GetTransformCacheKey, } from '../lib/TransformCaching'; -import type {GlobalTransformCache} from '../lib/GlobalTransformCache'; - -import typeof {minify as MinifyCode} from '../JSTransformer/worker'; +import type {Reporter} from '../lib/reporting'; +import type {HasteImpl, TransformCode} from '../node-haste/Module'; type Options = {| +assetExts: Array, @@ -61,16 +57,12 @@ type Options = {| class Resolver { _depGraph: DependencyGraph; - _getPolyfills: ({platform: ?string}) => $ReadOnlyArray; _minifyCode: MinifyCode; _postMinifyProcess: PostMinifyProcess; - _polyfillModuleNames: Array; constructor(opts: Options, depGraph: DependencyGraph) { - this._getPolyfills = opts.getPolyfills; this._minifyCode = opts.minifyCode; this._postMinifyProcess = opts.postMinifyProcess; - this._polyfillModuleNames = opts.polyfillModuleNames || []; this._depGraph = depGraph; } @@ -100,22 +92,6 @@ class Resolver { return new Resolver(opts, depGraph); } - getModuleSystemDependencies({dev = true}: {dev?: boolean}): Array { - const prelude = dev - ? pathJoin(__dirname, 'polyfills/prelude_dev.js') - : pathJoin(__dirname, 'polyfills/prelude.js'); - - const moduleSystem = defaults.moduleSystem; - - return [prelude, moduleSystem].map(moduleName => - this._depGraph.createPolyfill({ - file: moduleName, - id: moduleName, - dependencies: [], - }), - ); - } - async minifyModule( path: string, code: string,