mirror of https://github.com/status-im/metro.git
metro-buck: get rid of unecessary createBuildSetup
Reviewed By: mjesun Differential Revision: D6712304 fbshipit-source-id: b720ff00a329b7dd4629751973f102e9b2034e2c
This commit is contained in:
parent
826d68d4f5
commit
69ae428091
|
@ -12,17 +12,26 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const ModuleGraph = require('../ModuleGraph');
|
||||
|
||||
const build = require('../build');
|
||||
const defaults = require('../../defaults');
|
||||
|
||||
const FILE_TYPE = 'module';
|
||||
|
||||
describe('build setup', () => {
|
||||
const buildSetup = ModuleGraph.createBuildSetup(graph, mds => {
|
||||
// TODO: the .sort() function returns -1 1 or 0 for sorting, not boolean
|
||||
return [...mds].sort((l, r) => l.file.path > r.file.path);
|
||||
});
|
||||
const buildSetup = (entryPointPaths, options) =>
|
||||
build({
|
||||
entryPointPaths,
|
||||
getPolyfills: () => [],
|
||||
graphFn,
|
||||
optimize: false,
|
||||
platform: 'ios',
|
||||
postProcessModules: mds => {
|
||||
// TODO: the .sort() function returns -1 1 or 0 for sorting, not boolean
|
||||
return [...mds].sort((l, r) => l.file.path > r.file.path);
|
||||
},
|
||||
translateDefaultsPath: x => x,
|
||||
...options,
|
||||
});
|
||||
const polyfillOptions = {getPolyfills: () => ['polyfill-a', 'polyfill-b']};
|
||||
const noOptions = {};
|
||||
const noEntryPoints = [];
|
||||
|
@ -80,7 +89,7 @@ function moduleFromPath(path) {
|
|||
};
|
||||
}
|
||||
|
||||
async function graph(entryPoints, platform, options, callback) {
|
||||
async function graphFn(entryPoints, platform, options, callback) {
|
||||
const modules = Array.from(entryPoints, moduleFromPath);
|
||||
const depModules = Array.prototype.concat.apply(
|
||||
[],
|
|
@ -17,26 +17,25 @@ const getPreludeCode = require('../lib/getPreludeCode');
|
|||
|
||||
import type {BuildResult, GraphFn, PostProcessModules} from './types.flow';
|
||||
|
||||
export type BuildFn = (
|
||||
entryPoints: Iterable<string>,
|
||||
options: BuildOptions,
|
||||
) => Promise<BuildResult>;
|
||||
|
||||
type BuildOptions = {|
|
||||
getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
|
||||
optimize: boolean,
|
||||
platform: string,
|
||||
+entryPointPaths: Iterable<string>,
|
||||
+getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
|
||||
+graphFn: GraphFn,
|
||||
+optimize: boolean,
|
||||
+platform: string,
|
||||
+postProcessModules: PostProcessModules,
|
||||
+translateDefaultsPath: string => string,
|
||||
|};
|
||||
|
||||
exports.createBuildSetup = (
|
||||
graphFn: GraphFn,
|
||||
postProcessModules: PostProcessModules,
|
||||
translateDefaultsPath: string => string = x => x,
|
||||
): BuildFn => async (entryPoints, options) => {
|
||||
async function build(options: BuildOptions): Promise<BuildResult> {
|
||||
const {
|
||||
getPolyfills = ({platform}) => [],
|
||||
optimize = false,
|
||||
platform = defaults.platforms[0],
|
||||
entryPointPaths,
|
||||
getPolyfills,
|
||||
graphFn,
|
||||
optimize,
|
||||
platform,
|
||||
postProcessModules,
|
||||
translateDefaultsPath,
|
||||
} = options;
|
||||
const graphOptions = {optimize};
|
||||
|
||||
|
@ -45,9 +44,9 @@ exports.createBuildSetup = (
|
|||
|
||||
const [graph, moduleSystem, polyfills] = await Promise.all([
|
||||
(async () => {
|
||||
const result = await graphWithOptions(entryPoints);
|
||||
const result = await graphWithOptions(entryPointPaths);
|
||||
const {modules, entryModules} = result;
|
||||
const prModules = postProcessModules(modules, [...entryPoints]);
|
||||
const prModules = postProcessModules(modules, [...entryPointPaths]);
|
||||
return {modules: prModules, entryModules};
|
||||
})(),
|
||||
graphOnlyModules([translateDefaultsPath(defaults.moduleSystem)]),
|
||||
|
@ -62,4 +61,6 @@ exports.createBuildSetup = (
|
|||
modules: [...prependedScripts, ...graph.modules],
|
||||
prependedScripts,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = build;
|
|
@ -1 +0,0 @@
|
|||
{"main": "ModuleGraph.js"}
|
Loading…
Reference in New Issue