main
js 50 lines 1.47 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 // A chunk is either a plain chunk filename, or a merged chunk that bundles
11 // several component chunks together, emitted as
12 // `[mergedChunkFilename, componentChunkFilenames, componentChunkSizes]`.
13 export type Chunk =
14 | string
15 | [
16 /* merged chunk filename */ string,
17 /* component chunk filenames */ Array<string>,
18 /* component chunk sizes */ Array<number>,
19 ];
20
21 export type ImportManifestEntry = {
22 id: string,
23 chunks: Array<Chunk>,
24 name: string,
25 async?: boolean,
26 };
27
28 // This is the parsed shape of the wire format which is why it is
29 // condensed to only the essentialy information
30 export type ImportMetadata =
31 | [
32 /* id */ string,
33 /* chunks */ Array<Chunk>,
34 /* name */ string,
35 /* async */ 1,
36 ]
37 | [/* id */ string, /* chunks */ Array<Chunk>, /* name */ string];
38
39 export const ID = 0;
40 export const CHUNKS = 1;
41 export const NAME = 2;
42 // export const ASYNC = 3;
43
44 // This logic is correct because currently only include the 4th tuple member
45 // when the module is async. If that changes we will need to actually assert
46 // the value is true. We don't index into the 4th slot because flow does not
47 // like the potential out of bounds access
48 export function isAsyncImport(metadata: ImportMetadata): boolean {
49 return metadata.length === 4;
50 }