From 69ae4280911a2d2d0fc783976ae78e4355bda2fe Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Tue, 16 Jan 2018 03:06:50 -0800 Subject: [PATCH] metro-buck: get rid of unecessary createBuildSetup Reviewed By: mjesun Differential Revision: D6712304 fbshipit-source-id: b720ff00a329b7dd4629751973f102e9b2034e2c --- ...eGraph-test.js.snap => build-test.js.snap} | 0 .../{ModuleGraph-test.js => build-test.js} | 23 +++++++---- .../ModuleGraph/{ModuleGraph.js => build.js} | 39 ++++++++++--------- packages/metro/src/ModuleGraph/package.json | 1 - 4 files changed, 36 insertions(+), 27 deletions(-) rename packages/metro/src/ModuleGraph/__tests__/__snapshots__/{ModuleGraph-test.js.snap => build-test.js.snap} (100%) rename packages/metro/src/ModuleGraph/__tests__/{ModuleGraph-test.js => build-test.js} (82%) rename packages/metro/src/ModuleGraph/{ModuleGraph.js => build.js} (72%) delete mode 100644 packages/metro/src/ModuleGraph/package.json diff --git a/packages/metro/src/ModuleGraph/__tests__/__snapshots__/ModuleGraph-test.js.snap b/packages/metro/src/ModuleGraph/__tests__/__snapshots__/build-test.js.snap similarity index 100% rename from packages/metro/src/ModuleGraph/__tests__/__snapshots__/ModuleGraph-test.js.snap rename to packages/metro/src/ModuleGraph/__tests__/__snapshots__/build-test.js.snap diff --git a/packages/metro/src/ModuleGraph/__tests__/ModuleGraph-test.js b/packages/metro/src/ModuleGraph/__tests__/build-test.js similarity index 82% rename from packages/metro/src/ModuleGraph/__tests__/ModuleGraph-test.js rename to packages/metro/src/ModuleGraph/__tests__/build-test.js index 8702cc27..e2d3ca1e 100644 --- a/packages/metro/src/ModuleGraph/__tests__/ModuleGraph-test.js +++ b/packages/metro/src/ModuleGraph/__tests__/build-test.js @@ -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( [], diff --git a/packages/metro/src/ModuleGraph/ModuleGraph.js b/packages/metro/src/ModuleGraph/build.js similarity index 72% rename from packages/metro/src/ModuleGraph/ModuleGraph.js rename to packages/metro/src/ModuleGraph/build.js index 1eea315b..fdfb1b71 100644 --- a/packages/metro/src/ModuleGraph/ModuleGraph.js +++ b/packages/metro/src/ModuleGraph/build.js @@ -17,26 +17,25 @@ const getPreludeCode = require('../lib/getPreludeCode'); import type {BuildResult, GraphFn, PostProcessModules} from './types.flow'; -export type BuildFn = ( - entryPoints: Iterable, - options: BuildOptions, -) => Promise; - type BuildOptions = {| - getPolyfills: ({platform: ?string}) => $ReadOnlyArray, - optimize: boolean, - platform: string, + +entryPointPaths: Iterable, + +getPolyfills: ({platform: ?string}) => $ReadOnlyArray, + +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 { 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; diff --git a/packages/metro/src/ModuleGraph/package.json b/packages/metro/src/ModuleGraph/package.json deleted file mode 100644 index 4c0d77b8..00000000 --- a/packages/metro/src/ModuleGraph/package.json +++ /dev/null @@ -1 +0,0 @@ -{"main": "ModuleGraph.js"}