mirror of https://github.com/status-im/metro.git
Support passing multiple entryPoints to the public buildGraph() method
Reviewed By: mjesun Differential Revision: D7365288 fbshipit-source-id: 1d1b94858d2ad31307157839808b9a6c01c00365
This commit is contained in:
parent
d0fdca73cd
commit
d54a7044f2
|
@ -59,7 +59,10 @@ import type {MetroSourceMap} from 'metro-source-map';
|
||||||
import type {TransformCache} from '../lib/TransformCaching';
|
import type {TransformCache} from '../lib/TransformCaching';
|
||||||
import type {Symbolicate} from './symbolicate/symbolicate';
|
import type {Symbolicate} from './symbolicate/symbolicate';
|
||||||
import type {AssetData} from '../Assets';
|
import type {AssetData} from '../Assets';
|
||||||
import type {TransformedCode} from '../JSTransformer/worker';
|
import type {
|
||||||
|
CustomTransformOptions,
|
||||||
|
TransformedCode,
|
||||||
|
} from '../JSTransformer/worker';
|
||||||
const {
|
const {
|
||||||
Logger: {createActionStartEntry, createActionEndEntry, log},
|
Logger: {createActionStartEntry, createActionEndEntry, log},
|
||||||
} = require('metro-core');
|
} = require('metro-core');
|
||||||
|
@ -73,6 +76,18 @@ type GraphInfo = {|
|
||||||
+sequenceId: string,
|
+sequenceId: string,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
|
type BuildGraphOptions = {|
|
||||||
|
+assetPlugins: Array<string>,
|
||||||
|
+customTransformOptions: CustomTransformOptions,
|
||||||
|
+dev: boolean,
|
||||||
|
+entryFiles: $ReadOnlyArray<string>,
|
||||||
|
+hot: boolean,
|
||||||
|
+minify: boolean,
|
||||||
|
+onProgress: ?(doneCont: number, totalCount: number) => mixed,
|
||||||
|
+platform: ?string,
|
||||||
|
+type: 'module' | 'script',
|
||||||
|
|};
|
||||||
|
|
||||||
type DeltaOptions = BundleOptions & {
|
type DeltaOptions = BundleOptions & {
|
||||||
deltaBundleId: ?string,
|
deltaBundleId: ?string,
|
||||||
};
|
};
|
||||||
|
@ -269,22 +284,19 @@ class Server {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async buildGraph(options: BundleOptions): Promise<Graph> {
|
async buildGraph(options: BuildGraphOptions): Promise<Graph> {
|
||||||
const entryPoint = getAbsolutePath(
|
|
||||||
options.entryFile,
|
|
||||||
this._opts.projectRoots,
|
|
||||||
);
|
|
||||||
|
|
||||||
return await this._deltaBundler.buildGraph({
|
return await this._deltaBundler.buildGraph({
|
||||||
assetPlugins: options.assetPlugins,
|
assetPlugins: options.assetPlugins,
|
||||||
customTransformOptions: options.customTransformOptions,
|
customTransformOptions: options.customTransformOptions,
|
||||||
dev: options.dev,
|
dev: options.dev,
|
||||||
entryPoints: [entryPoint],
|
entryPoints: options.entryFiles.map(entryFile =>
|
||||||
|
getAbsolutePath(entryFile, this._opts.projectRoots),
|
||||||
|
),
|
||||||
hot: options.hot,
|
hot: options.hot,
|
||||||
minify: options.minify,
|
minify: options.minify,
|
||||||
onProgress: options.onProgress,
|
onProgress: options.onProgress,
|
||||||
platform: options.platform,
|
platform: options.platform,
|
||||||
type: 'module',
|
type: options.type,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1123,20 +1135,24 @@ class Server {
|
||||||
return this._opts.projectRoots;
|
return this._opts.projectRoots;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DEFAULT_BUNDLE_OPTIONS = {
|
static DEFAULT_GRAPH_OPTIONS = {
|
||||||
assetPlugins: [],
|
assetPlugins: [],
|
||||||
customTransformOptions: Object.create(null),
|
customTransformOptions: Object.create(null),
|
||||||
dev: true,
|
dev: true,
|
||||||
entryModuleOnly: false,
|
|
||||||
excludeSource: false,
|
|
||||||
hot: false,
|
hot: false,
|
||||||
inlineSourceMap: false,
|
|
||||||
minify: false,
|
minify: false,
|
||||||
onProgress: null,
|
onProgress: null,
|
||||||
|
type: 'module',
|
||||||
|
};
|
||||||
|
|
||||||
|
static DEFAULT_BUNDLE_OPTIONS = {
|
||||||
|
...Server.DEFAULT_GRAPH_OPTIONS,
|
||||||
|
entryModuleOnly: false,
|
||||||
|
excludeSource: false,
|
||||||
|
inlineSourceMap: false,
|
||||||
runBeforeMainModule: [],
|
runBeforeMainModule: [],
|
||||||
runModule: true,
|
runModule: true,
|
||||||
sourceMapUrl: null,
|
sourceMapUrl: null,
|
||||||
type: 'script',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -279,7 +279,7 @@ exports.runServer = async ({
|
||||||
|
|
||||||
type BuildGraphOptions = {|
|
type BuildGraphOptions = {|
|
||||||
...PublicMetroOptions,
|
...PublicMetroOptions,
|
||||||
entry: string,
|
entries: $ReadOnlyArray<string>,
|
||||||
dev?: boolean,
|
dev?: boolean,
|
||||||
onProgress?: (transformedFileCount: number, totalFileCount: number) => void,
|
onProgress?: (transformedFileCount: number, totalFileCount: number) => void,
|
||||||
platform?: string,
|
platform?: string,
|
||||||
|
@ -287,10 +287,12 @@ type BuildGraphOptions = {|
|
||||||
|
|
||||||
type RunBuildOptions = {|
|
type RunBuildOptions = {|
|
||||||
...PublicMetroOptions,
|
...PublicMetroOptions,
|
||||||
...BuildGraphOptions,
|
entry: string,
|
||||||
|
dev?: boolean,
|
||||||
out: string,
|
out: string,
|
||||||
onBegin?: () => void,
|
onBegin?: () => void,
|
||||||
onComplete?: () => void,
|
onComplete?: () => void,
|
||||||
|
onProgress?: (transformedFileCount: number, totalFileCount: number) => void,
|
||||||
optimize?: boolean,
|
optimize?: boolean,
|
||||||
output?: {
|
output?: {
|
||||||
build: (
|
build: (
|
||||||
|
@ -303,6 +305,7 @@ type RunBuildOptions = {|
|
||||||
(...args: Array<string>) => void,
|
(...args: Array<string>) => void,
|
||||||
) => Promise<mixed>,
|
) => Promise<mixed>,
|
||||||
},
|
},
|
||||||
|
platform?: string,
|
||||||
sourceMap?: boolean,
|
sourceMap?: boolean,
|
||||||
sourceMapUrl?: string,
|
sourceMapUrl?: string,
|
||||||
|};
|
|};
|
||||||
|
@ -377,7 +380,7 @@ exports.runBuild = async ({
|
||||||
exports.buildGraph = async function({
|
exports.buildGraph = async function({
|
||||||
config,
|
config,
|
||||||
dev = false,
|
dev = false,
|
||||||
entry,
|
entries,
|
||||||
onProgress,
|
onProgress,
|
||||||
platform = `web`,
|
platform = `web`,
|
||||||
...rest
|
...rest
|
||||||
|
@ -390,10 +393,9 @@ exports.buildGraph = async function({
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await metroServer.buildGraph({
|
return await metroServer.buildGraph({
|
||||||
...MetroServer.DEFAULT_BUNDLE_OPTIONS,
|
...MetroServer.DEFAULT_GRAPH_OPTIONS,
|
||||||
bundleType: 'graph',
|
|
||||||
dev,
|
dev,
|
||||||
entryFile: entry,
|
entryFiles: entries,
|
||||||
onProgress,
|
onProgress,
|
||||||
platform,
|
platform,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue