mirror of
https://github.com/status-im/metro.git
synced 2025-02-28 02:30:29 +00:00
Remove logic to calculate polyfills from Resolver
Reviewed By: jeanlauliac Differential Revision: D6674424 fbshipit-source-id: 20c0ace056150c1f6910edc7eadf8effb9ddf38d
This commit is contained in:
parent
fbe441febd
commit
eb489bf105
@ -16,7 +16,9 @@ const DeltaCalculator = require('./DeltaCalculator');
|
|||||||
|
|
||||||
const addParamsToDefineCall = require('../lib/addParamsToDefineCall');
|
const addParamsToDefineCall = require('../lib/addParamsToDefineCall');
|
||||||
const createModuleIdFactory = require('../lib/createModuleIdFactory');
|
const createModuleIdFactory = require('../lib/createModuleIdFactory');
|
||||||
|
const defaults = require('../defaults');
|
||||||
const nullthrows = require('fbjs/lib/nullthrows');
|
const nullthrows = require('fbjs/lib/nullthrows');
|
||||||
|
const path = require('path');
|
||||||
const removeInlineRequiresBlacklistFromOptions = require('../lib/removeInlineRequiresBlacklistFromOptions');
|
const removeInlineRequiresBlacklistFromOptions = require('../lib/removeInlineRequiresBlacklistFromOptions');
|
||||||
|
|
||||||
const {EventEmitter} = require('events');
|
const {EventEmitter} = require('events');
|
||||||
@ -328,21 +330,17 @@ class DeltaTransformer extends EventEmitter {
|
|||||||
platform: this._bundleOptions.platform,
|
platform: this._bundleOptions.platform,
|
||||||
}).concat(this._polyfillModuleNames);
|
}).concat(this._polyfillModuleNames);
|
||||||
|
|
||||||
// The module system dependencies are scripts that need to be included at
|
// Build the module system dependencies (scripts that need to
|
||||||
// the very beginning of the bundle (before any polyfill).
|
// be included at the very beginning of the bundle) + any polifyll.
|
||||||
const moduleSystemDeps = this._resolver.getModuleSystemDependencies({
|
const modules = this._getModuleSystemDependencies()
|
||||||
dev: this._bundleOptions.dev,
|
.concat(polyfillModuleNames)
|
||||||
});
|
.map(polyfillModuleName =>
|
||||||
|
|
||||||
const modules = moduleSystemDeps.concat(
|
|
||||||
polyfillModuleNames.map((polyfillModuleName, idx) =>
|
|
||||||
this._resolver.getDependencyGraph().createPolyfill({
|
this._resolver.getDependencyGraph().createPolyfill({
|
||||||
file: polyfillModuleName,
|
file: polyfillModuleName,
|
||||||
id: polyfillModuleName,
|
id: polyfillModuleName,
|
||||||
dependencies: [],
|
dependencies: [],
|
||||||
}),
|
}),
|
||||||
),
|
);
|
||||||
);
|
|
||||||
|
|
||||||
return await this._transformModules(
|
return await this._transformModules(
|
||||||
modules,
|
modules,
|
||||||
@ -534,6 +532,16 @@ class DeltaTransformer extends EventEmitter {
|
|||||||
_onFileChange = () => {
|
_onFileChange = () => {
|
||||||
this.emit('change');
|
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;
|
module.exports = DeltaTransformer;
|
||||||
|
@ -14,26 +14,22 @@
|
|||||||
|
|
||||||
const DependencyGraph = require('../node-haste/DependencyGraph');
|
const DependencyGraph = require('../node-haste/DependencyGraph');
|
||||||
|
|
||||||
const defaults = require('../defaults');
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
compactMapping,
|
compactMapping,
|
||||||
fromRawMappings,
|
fromRawMappings,
|
||||||
toRawMappings,
|
toRawMappings,
|
||||||
} = require('metro-source-map');
|
} = 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 {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 {
|
import type {
|
||||||
TransformCache,
|
TransformCache,
|
||||||
GetTransformCacheKey,
|
GetTransformCacheKey,
|
||||||
} from '../lib/TransformCaching';
|
} from '../lib/TransformCaching';
|
||||||
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
import type {Reporter} from '../lib/reporting';
|
||||||
|
import type {HasteImpl, TransformCode} from '../node-haste/Module';
|
||||||
import typeof {minify as MinifyCode} from '../JSTransformer/worker';
|
|
||||||
|
|
||||||
type Options = {|
|
type Options = {|
|
||||||
+assetExts: Array<string>,
|
+assetExts: Array<string>,
|
||||||
@ -61,16 +57,12 @@ type Options = {|
|
|||||||
|
|
||||||
class Resolver {
|
class Resolver {
|
||||||
_depGraph: DependencyGraph;
|
_depGraph: DependencyGraph;
|
||||||
_getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>;
|
|
||||||
_minifyCode: MinifyCode;
|
_minifyCode: MinifyCode;
|
||||||
_postMinifyProcess: PostMinifyProcess;
|
_postMinifyProcess: PostMinifyProcess;
|
||||||
_polyfillModuleNames: Array<string>;
|
|
||||||
|
|
||||||
constructor(opts: Options, depGraph: DependencyGraph) {
|
constructor(opts: Options, depGraph: DependencyGraph) {
|
||||||
this._getPolyfills = opts.getPolyfills;
|
|
||||||
this._minifyCode = opts.minifyCode;
|
this._minifyCode = opts.minifyCode;
|
||||||
this._postMinifyProcess = opts.postMinifyProcess;
|
this._postMinifyProcess = opts.postMinifyProcess;
|
||||||
this._polyfillModuleNames = opts.polyfillModuleNames || [];
|
|
||||||
this._depGraph = depGraph;
|
this._depGraph = depGraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,22 +92,6 @@ class Resolver {
|
|||||||
return new Resolver(opts, depGraph);
|
return new Resolver(opts, depGraph);
|
||||||
}
|
}
|
||||||
|
|
||||||
getModuleSystemDependencies({dev = true}: {dev?: boolean}): Array<Module> {
|
|
||||||
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(
|
async minifyModule(
|
||||||
path: string,
|
path: string,
|
||||||
code: string,
|
code: string,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user