1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | import { PackageRelativeUrl, ResolvedUrl, UrlResolver } from 'polymer-analyzer';
|
15 |
|
16 |
|
17 |
|
18 | export declare type BundleStrategy = (bundles: Bundle[]) => Bundle[];
|
19 |
|
20 |
|
21 |
|
22 | export declare type BundleUrlMapper = (bundles: Bundle[]) => Map<ResolvedUrl, Bundle>;
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export declare type TransitiveDependenciesMap = Map<ResolvedUrl, Set<ResolvedUrl>>;
|
30 |
|
31 |
|
32 |
|
33 | export declare type BundleType = 'html-fragment' | 'es6-module';
|
34 | export declare const bundleTypeExtnames: Map<BundleType, string>;
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | export declare class Bundle {
|
40 | type: BundleType;
|
41 | entrypoints: Set<ResolvedUrl>;
|
42 | files: Set<ResolvedUrl>;
|
43 | stripImports: Set<ResolvedUrl>;
|
44 | missingImports: Set<ResolvedUrl>;
|
45 | inlinedHtmlImports: Set<ResolvedUrl>;
|
46 | inlinedScripts: Set<ResolvedUrl>;
|
47 | inlinedStyles: Set<ResolvedUrl>;
|
48 | bundledExports: Map<ResolvedUrl, Map<string, string>>;
|
49 | constructor(type: BundleType, entrypoints?: Set<ResolvedUrl>, files?: Set<ResolvedUrl>);
|
50 | readonly extname: string | undefined;
|
51 | }
|
52 | /**
|
53 | * Represents a bundle assigned to an output URL.
|
54 | */
|
55 | export declare class AssignedBundle {
|
56 | bundle: Bundle;
|
57 | url: ResolvedUrl;
|
58 | }
|
59 | export interface BundleManifestJson {
|
60 | [entrypoint: string]: PackageRelativeUrl[];
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 | export declare class BundleManifest {
|
66 | bundles: Map<ResolvedUrl, Bundle>;
|
67 | private _bundleUrlForFile;
|
68 | |
69 |
|
70 |
|
71 |
|
72 | constructor(bundles: Bundle[], urlMapper: BundleUrlMapper);
|
73 | fork(): BundleManifest;
|
74 | getBundleForFile(url: ResolvedUrl): AssignedBundle | undefined;
|
75 | toJson(urlResolver: UrlResolver): BundleManifestJson;
|
76 | }
|
77 | /**
|
78 | * Chains multiple bundle strategy functions together so the output of one
|
79 | * becomes the input of the next and so-on.
|
80 | */
|
81 | export declare function composeStrategies(strategies: BundleStrategy[]): BundleStrategy;
|
82 | /**
|
83 | * Given an index of files and their dependencies, produce an array of bundles,
|
84 | * where a bundle is defined for each set of dependencies.
|
85 | *
|
86 | * For example, a dependency index representing the graph:
|
87 | * `a->b, b->c, b->d, e->c, e->f`
|
88 | *
|
89 | * Would produce an array of three bundles:
|
90 | * `[a]->[a,b,d], [e]->[e,f], [a,e]->[c]`
|
91 | */
|
92 | export declare function generateBundles(depsIndex: TransitiveDependenciesMap): Bundle[];
|
93 | /**
|
94 | * Instances of `<script type="module">` generate synthetic entrypoints in the
|
95 | * depsIndex and are treated as entrypoints during the initial phase of
|
96 | * `generateBundles`. Any bundle which provides dependencies to a single
|
97 | * synthetic entrypoint of this type (aka a single entrypoint sub-bundle) are
|
98 | * merged back into the bundle for the HTML containing the script tag.
|
99 | *
|
100 | * For example, the following bundles:
|
101 | * `[a]->[a], [a>1]->[x], [a>1,a>2]->[y], [a>2]->[z]`
|
102 | *
|
103 | * Would be merged into the following set of bundles:
|
104 | * `[a]->[a,x,z], [a>1,a>2]->[y]`
|
105 | *
|
106 | * `a>1` and `a>2` represent script tag entrypoints. Only `x` and `z` are
|
107 | * bundled with `a` because they each serve only a single script tag entrypoint.
|
108 | * `y` has to be in a separate bundle so that it is not inlined into bundle `a`
|
109 | * in both script tags.
|
110 | */
|
111 | export declare function mergeSingleEntrypointSubBundles(bundles: Bundle[]): void;
|
112 | /**
|
113 | * Creates a bundle URL mapper function which takes a prefix and appends an
|
114 | * incrementing value, starting with `1` to the filename.
|
115 | */
|
116 | export declare function generateCountingSharedBundleUrlMapper(urlPrefix: ResolvedUrl): BundleUrlMapper;
|
117 | /**
|
118 | * Generates a strategy function which finds all non-entrypoint bundles which
|
119 | * are dependencies of the given entrypoint and merges them into that
|
120 | * entrypoint's bundle.
|
121 | */
|
122 | export declare function generateEagerMergeStrategy(entrypoint: ResolvedUrl): BundleStrategy;
|
123 | /**
|
124 | * Generates a strategy function which finds all bundles matching the predicate
|
125 | * function and merges them into the bundle containing the target file.
|
126 | */
|
127 | export declare function generateMatchMergeStrategy(predicate: (b: Bundle) => boolean): BundleStrategy;
|
128 | /**
|
129 | * Creates a bundle URL mapper function which maps non-shared bundles to the
|
130 | * URLs of their single entrypoint and yields responsibility for naming
|
131 | * remaining shared bundle URLs to the `mapper` function argument. The
|
132 | * mapper function takes a collection of shared bundles and a URL map, calling
|
133 | * `.set(url, bundle)` for each.
|
134 | */
|
135 | export declare function generateSharedBundleUrlMapper(mapper: (sharedBundles: Bundle[]) => ResolvedUrl[]): BundleUrlMapper;
|
136 | /**
|
137 | * Generates a strategy function to merge all bundles where the dependencies
|
138 | * for a bundle are shared by at least 2 entrypoints (default; set
|
139 | * `minEntrypoints` to change threshold).
|
140 | *
|
141 | * This function will convert an array of 4 bundles:
|
142 | * `[a]->[a,b], [a,c]->[d], [c]->[c,e], [f,g]->[f,g,h]`
|
143 | *
|
144 | * Into the following 3 bundles, including a single bundle for all of the
|
145 | * dependencies which are shared by at least 2 entrypoints:
|
146 | * `[a]->[a,b], [c]->[c,e], [a,c,f,g]->[d,f,g,h]`
|
147 | */
|
148 | export declare function generateSharedDepsMergeStrategy(maybeMinEntrypoints?: number): BundleStrategy;
|
149 | /**
|
150 | * A bundle strategy function which merges all shared dependencies into a
|
151 | * bundle for an application shell.
|
152 | */
|
153 | export declare function generateShellMergeStrategy(shell: ResolvedUrl, maybeMinEntrypoints?: number): BundleStrategy;
|
154 | /**
|
155 | * Generates a strategy function that ensures bundles do not link to given URLs.
|
156 | * Bundles which contain matching files will still have them inlined.
|
157 | */
|
158 | export declare function generateNoBackLinkStrategy(urls: ResolvedUrl[]): BundleStrategy;
|
159 | /**
|
160 | * Given an Array of bundles, produce a single bundle with the entrypoints and
|
161 | * files of all bundles represented. By default, bundles of different types
|
162 | * can not be merged, but this constraint can be skipped by providing
|
163 | * `ignoreTypeCheck` argument with value `true`, which is necessary to merge a
|
164 | * bundle containining an inline document's unique transitive dependencies, as
|
165 | * inline documents typically are of different type (`<script type="module">`
|
166 | * within HTML document contains JavaScript document).
|
167 | */
|
168 | export declare function mergeBundles(bundles: Bundle[], ignoreTypeCheck?: boolean): Bundle;
|
169 | /**
|
170 | * Return a new bundle array where bundles within it matching the predicate
|
171 | * are merged together. Note that merge operations are segregated by type so
|
172 | * that no attempt to merge bundles of different types will occur.
|
173 | */
|
174 | export declare function mergeMatchingBundles(bundles: Bundle[], predicate: (bundle: Bundle) => boolean): Bundle[];
|