@atlaspack/runtime-js 2.12.1-canary.3354
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/lib/JSRuntime.js +562 -0
- package/lib/helpers/browser/css-loader.js +28 -0
- package/lib/helpers/browser/esm-js-loader-retry.js +51 -0
- package/lib/helpers/browser/esm-js-loader.js +7 -0
- package/lib/helpers/browser/html-loader.js +8 -0
- package/lib/helpers/browser/import-polyfill.js +32 -0
- package/lib/helpers/browser/js-loader.js +35 -0
- package/lib/helpers/browser/prefetch-loader.js +13 -0
- package/lib/helpers/browser/preload-loader.js +14 -0
- package/lib/helpers/browser/wasm-loader.js +16 -0
- package/lib/helpers/bundle-manifest.js +20 -0
- package/lib/helpers/bundle-url.js +39 -0
- package/lib/helpers/cacheLoader.js +27 -0
- package/lib/helpers/get-worker-url.js +15 -0
- package/lib/helpers/node/css-loader.js +6 -0
- package/lib/helpers/node/html-loader.js +19 -0
- package/lib/helpers/node/js-loader.js +21 -0
- package/lib/helpers/node/wasm-loader.js +19 -0
- package/lib/helpers/worker/js-loader.js +14 -0
- package/lib/helpers/worker/wasm-loader.js +16 -0
- package/package.json +25 -0
- package/src/JSRuntime.js +742 -0
- package/src/helpers/.babelrc +9 -0
- package/src/helpers/.eslintrc.json +3 -0
- package/src/helpers/browser/css-loader.js +32 -0
- package/src/helpers/browser/esm-js-loader-retry.js +26 -0
- package/src/helpers/browser/esm-js-loader.js +6 -0
- package/src/helpers/browser/html-loader.js +7 -0
- package/src/helpers/browser/import-polyfill.js +32 -0
- package/src/helpers/browser/js-loader.js +42 -0
- package/src/helpers/browser/prefetch-loader.js +13 -0
- package/src/helpers/browser/preload-loader.js +19 -0
- package/src/helpers/browser/wasm-loader.js +17 -0
- package/src/helpers/bundle-manifest.js +21 -0
- package/src/helpers/bundle-url.js +51 -0
- package/src/helpers/cacheLoader.js +29 -0
- package/src/helpers/get-worker-url.js +15 -0
- package/src/helpers/node/css-loader.js +4 -0
- package/src/helpers/node/html-loader.js +18 -0
- package/src/helpers/node/js-loader.js +20 -0
- package/src/helpers/node/wasm-loader.js +20 -0
- package/src/helpers/worker/js-loader.js +13 -0
- package/src/helpers/worker/wasm-loader.js +17 -0
package/lib/JSRuntime.js
ADDED
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
function _plugin() {
|
|
8
|
+
const data = require("@atlaspack/plugin");
|
|
9
|
+
_plugin = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _utils() {
|
|
15
|
+
const data = require("@atlaspack/utils");
|
|
16
|
+
_utils = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _diagnostic() {
|
|
22
|
+
const data = require("@atlaspack/diagnostic");
|
|
23
|
+
_diagnostic = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _path() {
|
|
29
|
+
const data = _interopRequireDefault(require("path"));
|
|
30
|
+
_path = function () {
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
function _nullthrows() {
|
|
36
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
|
37
|
+
_nullthrows = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
43
|
+
// Used for as="" in preload/prefetch
|
|
44
|
+
const TYPE_TO_RESOURCE_PRIORITY = {
|
|
45
|
+
css: 'style',
|
|
46
|
+
js: 'script'
|
|
47
|
+
};
|
|
48
|
+
const BROWSER_PRELOAD_LOADER = './helpers/browser/preload-loader';
|
|
49
|
+
const BROWSER_PREFETCH_LOADER = './helpers/browser/prefetch-loader';
|
|
50
|
+
const LOADERS = {
|
|
51
|
+
browser: {
|
|
52
|
+
css: './helpers/browser/css-loader',
|
|
53
|
+
html: './helpers/browser/html-loader',
|
|
54
|
+
js: './helpers/browser/js-loader',
|
|
55
|
+
wasm: './helpers/browser/wasm-loader',
|
|
56
|
+
IMPORT_POLYFILL: './helpers/browser/import-polyfill'
|
|
57
|
+
},
|
|
58
|
+
worker: {
|
|
59
|
+
js: './helpers/worker/js-loader',
|
|
60
|
+
wasm: './helpers/worker/wasm-loader',
|
|
61
|
+
IMPORT_POLYFILL: false
|
|
62
|
+
},
|
|
63
|
+
node: {
|
|
64
|
+
css: './helpers/node/css-loader',
|
|
65
|
+
html: './helpers/node/html-loader',
|
|
66
|
+
js: './helpers/node/js-loader',
|
|
67
|
+
wasm: './helpers/node/wasm-loader',
|
|
68
|
+
IMPORT_POLYFILL: null
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
function getLoaders(ctx) {
|
|
72
|
+
if (ctx.isWorker()) return LOADERS.worker;
|
|
73
|
+
if (ctx.isBrowser()) return LOADERS.browser;
|
|
74
|
+
if (ctx.isNode()) return LOADERS.node;
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// This cache should be invalidated if new dependencies get added to the bundle without the bundle objects changing
|
|
79
|
+
// This can happen when we reuse the BundleGraph between subsequent builds
|
|
80
|
+
let bundleDependencies = new WeakMap();
|
|
81
|
+
let defaultConfig = {
|
|
82
|
+
splitManifestThreshold: 100000
|
|
83
|
+
};
|
|
84
|
+
const CONFIG_SCHEMA = {
|
|
85
|
+
type: 'object',
|
|
86
|
+
properties: {
|
|
87
|
+
splitManifestThreshold: {
|
|
88
|
+
type: 'number'
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
additionalProperties: false
|
|
92
|
+
};
|
|
93
|
+
var _default = exports.default = new (_plugin().Runtime)({
|
|
94
|
+
async loadConfig({
|
|
95
|
+
config,
|
|
96
|
+
options
|
|
97
|
+
}) {
|
|
98
|
+
let packageKey = '@atlaspack/runtime-js';
|
|
99
|
+
let conf = await config.getConfig([], {
|
|
100
|
+
packageKey
|
|
101
|
+
});
|
|
102
|
+
if (!conf) {
|
|
103
|
+
return defaultConfig;
|
|
104
|
+
}
|
|
105
|
+
_utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
|
|
106
|
+
data: conf === null || conf === void 0 ? void 0 : conf.contents,
|
|
107
|
+
source: await options.inputFS.readFile(conf.filePath, 'utf8'),
|
|
108
|
+
filePath: conf.filePath,
|
|
109
|
+
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)(packageKey)}`
|
|
110
|
+
}, packageKey, `Invalid config for ${packageKey}`);
|
|
111
|
+
return {
|
|
112
|
+
...defaultConfig,
|
|
113
|
+
...(conf === null || conf === void 0 ? void 0 : conf.contents)
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
apply({
|
|
117
|
+
bundle,
|
|
118
|
+
bundleGraph,
|
|
119
|
+
options,
|
|
120
|
+
config
|
|
121
|
+
}) {
|
|
122
|
+
// Dependency ids in code replaced with referenced bundle names
|
|
123
|
+
// Loader runtime added for bundle groups that don't have a native loader (e.g. HTML/CSS/Worker - isURL?),
|
|
124
|
+
// and which are not loaded by a parent bundle.
|
|
125
|
+
// Loaders also added for modules that were moved to a separate bundle because they are a different type
|
|
126
|
+
// (e.g. WASM, HTML). These should be preloaded prior to the bundle being executed. Replace the entry asset(s)
|
|
127
|
+
// with the preload module.
|
|
128
|
+
|
|
129
|
+
if (bundle.type !== 'js') {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
let {
|
|
133
|
+
asyncDependencies,
|
|
134
|
+
otherDependencies
|
|
135
|
+
} = getDependencies(bundle);
|
|
136
|
+
let assets = [];
|
|
137
|
+
for (let dependency of asyncDependencies) {
|
|
138
|
+
let resolved = bundleGraph.resolveAsyncDependency(dependency, bundle);
|
|
139
|
+
if (resolved == null) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (resolved.type === 'asset') {
|
|
143
|
+
if (!bundle.env.shouldScopeHoist) {
|
|
144
|
+
// If this bundle already has the asset this dependency references,
|
|
145
|
+
// return a simple runtime of `Promise.resolve(internalRequire(assetId))`.
|
|
146
|
+
// The linker handles this for scope-hoisting.
|
|
147
|
+
assets.push({
|
|
148
|
+
filePath: __filename,
|
|
149
|
+
code: `module.exports = Promise.resolve(module.bundle.root(${JSON.stringify(bundleGraph.getAssetPublicId(resolved.value))}))`,
|
|
150
|
+
dependency,
|
|
151
|
+
env: {
|
|
152
|
+
sourceType: 'module'
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
// Resolve the dependency to a bundle. If inline, export the dependency id,
|
|
158
|
+
// which will be replaced with the contents of that bundle later.
|
|
159
|
+
let referencedBundle = bundleGraph.getReferencedBundle(dependency, bundle);
|
|
160
|
+
if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline') {
|
|
161
|
+
assets.push({
|
|
162
|
+
filePath: _path().default.join(__dirname, `/bundles/${referencedBundle.id}.js`),
|
|
163
|
+
code: `module.exports = Promise.resolve(${JSON.stringify(dependency.id)});`,
|
|
164
|
+
dependency,
|
|
165
|
+
env: {
|
|
166
|
+
sourceType: 'module'
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
let loaderRuntime = getLoaderRuntime({
|
|
172
|
+
bundle,
|
|
173
|
+
dependency,
|
|
174
|
+
bundleGraph,
|
|
175
|
+
bundleGroup: resolved.value,
|
|
176
|
+
options
|
|
177
|
+
});
|
|
178
|
+
if (loaderRuntime != null) {
|
|
179
|
+
assets.push(loaderRuntime);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
for (let dependency of otherDependencies) {
|
|
184
|
+
// Resolve the dependency to a bundle. If inline, export the dependency id,
|
|
185
|
+
// which will be replaced with the contents of that bundle later.
|
|
186
|
+
let referencedBundle = bundleGraph.getReferencedBundle(dependency, bundle);
|
|
187
|
+
if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline') {
|
|
188
|
+
assets.push({
|
|
189
|
+
filePath: _path().default.join(__dirname, `/bundles/${referencedBundle.id}.js`),
|
|
190
|
+
code: `module.exports = ${JSON.stringify(dependency.id)};`,
|
|
191
|
+
dependency,
|
|
192
|
+
env: {
|
|
193
|
+
sourceType: 'module'
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Otherwise, try to resolve the dependency to an external bundle group
|
|
200
|
+
// and insert a URL to that bundle.
|
|
201
|
+
let resolved = bundleGraph.resolveAsyncDependency(dependency, bundle);
|
|
202
|
+
if (dependency.specifierType === 'url' && resolved == null) {
|
|
203
|
+
// If a URL dependency was not able to be resolved, add a runtime that
|
|
204
|
+
// exports the original specifier.
|
|
205
|
+
assets.push({
|
|
206
|
+
filePath: __filename,
|
|
207
|
+
code: `module.exports = ${JSON.stringify(dependency.specifier)}`,
|
|
208
|
+
dependency,
|
|
209
|
+
env: {
|
|
210
|
+
sourceType: 'module'
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (resolved == null || resolved.type !== 'bundle_group') {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
let bundleGroup = resolved.value;
|
|
219
|
+
let mainBundle = (0, _nullthrows().default)(bundleGraph.getBundlesInBundleGroup(bundleGroup).find(b => {
|
|
220
|
+
let entries = b.getEntryAssets();
|
|
221
|
+
return entries.some(e => bundleGroup.entryAssetId === e.id);
|
|
222
|
+
}));
|
|
223
|
+
|
|
224
|
+
// Skip URL runtimes for library builds. This is handled in packaging so that
|
|
225
|
+
// the url is inlined and statically analyzable.
|
|
226
|
+
if (bundle.env.isLibrary && mainBundle.bundleBehavior !== 'isolated') {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// URL dependency or not, fall back to including a runtime that exports the url
|
|
231
|
+
assets.push(getURLRuntime(dependency, bundle, mainBundle, options));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// In development, bundles can be created lazily. This means that the parent bundle may not
|
|
235
|
+
// know about all of the sibling bundles of a child when it is written for the first time.
|
|
236
|
+
// Therefore, we need to also ensure that the siblings are loaded when the child loads.
|
|
237
|
+
if (options.shouldBuildLazily && bundle.env.outputFormat === 'global') {
|
|
238
|
+
let referenced = bundleGraph.getReferencedBundles(bundle);
|
|
239
|
+
for (let referencedBundle of referenced) {
|
|
240
|
+
let loaders = getLoaders(bundle.env);
|
|
241
|
+
if (!loaders) {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
let loader = loaders[referencedBundle.type];
|
|
245
|
+
if (!loader) {
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
let relativePathExpr = getRelativePathExpr(bundle, referencedBundle, options);
|
|
249
|
+
let loaderCode = `require(${JSON.stringify(loader)})( ${getAbsoluteUrlExpr(relativePathExpr, bundle)})`;
|
|
250
|
+
assets.push({
|
|
251
|
+
filePath: __filename,
|
|
252
|
+
code: loaderCode,
|
|
253
|
+
isEntry: true,
|
|
254
|
+
env: {
|
|
255
|
+
sourceType: 'module'
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (shouldUseRuntimeManifest(bundle, options) && bundleGraph.getChildBundles(bundle).some(b => b.bundleBehavior !== 'inline') && isNewContext(bundle, bundleGraph)) {
|
|
261
|
+
assets.push({
|
|
262
|
+
filePath: __filename,
|
|
263
|
+
code: getRegisterCode(bundle, bundleGraph),
|
|
264
|
+
isEntry: true,
|
|
265
|
+
env: {
|
|
266
|
+
sourceType: 'module'
|
|
267
|
+
},
|
|
268
|
+
priority: getManifestBundlePriority(bundleGraph, bundle, config.splitManifestThreshold)
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
return assets;
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
function getDependencies(bundle) {
|
|
275
|
+
let cachedDependencies = bundleDependencies.get(bundle);
|
|
276
|
+
if (cachedDependencies) {
|
|
277
|
+
return cachedDependencies;
|
|
278
|
+
} else {
|
|
279
|
+
let asyncDependencies = [];
|
|
280
|
+
let otherDependencies = [];
|
|
281
|
+
bundle.traverse(node => {
|
|
282
|
+
if (node.type !== 'dependency') {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
let dependency = node.value;
|
|
286
|
+
if (dependency.priority === 'lazy' && dependency.specifierType !== 'url') {
|
|
287
|
+
asyncDependencies.push(dependency);
|
|
288
|
+
} else {
|
|
289
|
+
otherDependencies.push(dependency);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
bundleDependencies.set(bundle, {
|
|
293
|
+
asyncDependencies,
|
|
294
|
+
otherDependencies
|
|
295
|
+
});
|
|
296
|
+
return {
|
|
297
|
+
asyncDependencies,
|
|
298
|
+
otherDependencies
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function getLoaderRuntime({
|
|
303
|
+
bundle,
|
|
304
|
+
dependency,
|
|
305
|
+
bundleGroup,
|
|
306
|
+
bundleGraph,
|
|
307
|
+
options
|
|
308
|
+
}) {
|
|
309
|
+
let loaders = getLoaders(bundle.env);
|
|
310
|
+
if (loaders == null) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
let externalBundles = bundleGraph.getBundlesInBundleGroup(bundleGroup);
|
|
314
|
+
let mainBundle = (0, _nullthrows().default)(externalBundles.find(bundle => {
|
|
315
|
+
var _bundle$getMainEntry;
|
|
316
|
+
return ((_bundle$getMainEntry = bundle.getMainEntry()) === null || _bundle$getMainEntry === void 0 ? void 0 : _bundle$getMainEntry.id) === bundleGroup.entryAssetId;
|
|
317
|
+
}));
|
|
318
|
+
|
|
319
|
+
// CommonJS is a synchronous module system, so there is no need to load bundles in parallel.
|
|
320
|
+
// Importing of the other bundles will be handled by the bundle group entry.
|
|
321
|
+
// Do the same thing in library mode for ES modules, as we are building for another bundler
|
|
322
|
+
// and the imports for sibling bundles will be in the target bundle.
|
|
323
|
+
|
|
324
|
+
// Previously we also did this when building lazily, however it seemed to cause issues in some cases.
|
|
325
|
+
// The original comment as to why is left here, in case a future traveller is trying to fix that issue:
|
|
326
|
+
// > [...] the runtime itself could get deduplicated and only exist in the parent. This causes errors if an
|
|
327
|
+
// > old version of the parent without the runtime
|
|
328
|
+
// > is already loaded.
|
|
329
|
+
if (bundle.env.outputFormat === 'commonjs' || bundle.env.isLibrary) {
|
|
330
|
+
externalBundles = [mainBundle];
|
|
331
|
+
} else {
|
|
332
|
+
// Otherwise, load the bundle group entry after the others.
|
|
333
|
+
externalBundles.splice(externalBundles.indexOf(mainBundle), 1);
|
|
334
|
+
externalBundles.reverse().push(mainBundle);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Determine if we need to add a dynamic import() polyfill, or if all target browsers support it natively.
|
|
338
|
+
let needsDynamicImportPolyfill = !bundle.env.isLibrary && !bundle.env.supports('dynamic-import', true);
|
|
339
|
+
let needsEsmLoadPrelude = false;
|
|
340
|
+
let loaderModules = [];
|
|
341
|
+
for (let to of externalBundles) {
|
|
342
|
+
let loader = loaders[to.type];
|
|
343
|
+
if (!loader) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
if (to.type === 'js' && to.env.outputFormat === 'esmodule' && !needsDynamicImportPolyfill && shouldUseRuntimeManifest(bundle, options)) {
|
|
347
|
+
loaderModules.push(`load(${JSON.stringify(to.publicId)})`);
|
|
348
|
+
needsEsmLoadPrelude = true;
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
let relativePathExpr = getRelativePathExpr(bundle, to, options);
|
|
352
|
+
|
|
353
|
+
// Use esmodule loader if possible
|
|
354
|
+
if (to.type === 'js' && to.env.outputFormat === 'esmodule') {
|
|
355
|
+
if (!needsDynamicImportPolyfill) {
|
|
356
|
+
loaderModules.push(`__atlaspack__import__("./" + ${relativePathExpr})`);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
loader = (0, _nullthrows().default)(loaders.IMPORT_POLYFILL, `No import() polyfill available for context '${bundle.env.context}'`);
|
|
360
|
+
} else if (to.type === 'js' && to.env.outputFormat === 'commonjs') {
|
|
361
|
+
loaderModules.push(`Promise.resolve(__atlaspack__require__("./" + ${relativePathExpr}))`);
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
let absoluteUrlExpr = shouldUseRuntimeManifest(bundle, options) ? `require('./helpers/bundle-manifest').resolve(${JSON.stringify(to.publicId)})` : getAbsoluteUrlExpr(relativePathExpr, bundle);
|
|
365
|
+
let code = `require(${JSON.stringify(loader)})(${absoluteUrlExpr})`;
|
|
366
|
+
|
|
367
|
+
// In development, clear the require cache when an error occurs so the
|
|
368
|
+
// user can try again (e.g. after fixing a build error).
|
|
369
|
+
if (options.mode === 'development' && bundle.env.outputFormat === 'global') {
|
|
370
|
+
code += '.catch(err => {delete module.bundle.cache[module.id]; throw err;})';
|
|
371
|
+
}
|
|
372
|
+
loaderModules.push(code);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Similar to the comment above, this also used to be skipped when shouldBuildLazily was true,
|
|
376
|
+
// however it caused issues where a bundle group contained multiple bundles.
|
|
377
|
+
if (bundle.env.context === 'browser') {
|
|
378
|
+
loaderModules.push(...externalBundles
|
|
379
|
+
// TODO: Allow css to preload resources as well
|
|
380
|
+
.filter(to => to.type === 'js').flatMap(from => {
|
|
381
|
+
let {
|
|
382
|
+
preload,
|
|
383
|
+
prefetch
|
|
384
|
+
} = getHintedBundleGroups(bundleGraph, from);
|
|
385
|
+
return [...getHintLoaders(bundleGraph, bundle, preload, BROWSER_PRELOAD_LOADER, options), ...getHintLoaders(bundleGraph, bundle, prefetch, BROWSER_PREFETCH_LOADER, options)];
|
|
386
|
+
}));
|
|
387
|
+
}
|
|
388
|
+
if (loaderModules.length === 0) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
let loaderCode = loaderModules.join(', ');
|
|
392
|
+
if (loaderModules.length > 1) {
|
|
393
|
+
loaderCode = `Promise.all([${loaderCode}])`;
|
|
394
|
+
} else {
|
|
395
|
+
loaderCode = `(${loaderCode})`;
|
|
396
|
+
}
|
|
397
|
+
if (mainBundle.type === 'js') {
|
|
398
|
+
let atlaspackRequire = bundle.env.shouldScopeHoist ? 'atlaspackRequire' : 'module.bundle.root';
|
|
399
|
+
loaderCode += `.then(() => ${atlaspackRequire}('${bundleGraph.getAssetPublicId(bundleGraph.getAssetById(bundleGroup.entryAssetId))}'))`;
|
|
400
|
+
}
|
|
401
|
+
if (needsEsmLoadPrelude && options.featureFlags.importRetry) {
|
|
402
|
+
loaderCode = `
|
|
403
|
+
Object.defineProperty(module, 'exports', { get: () => {
|
|
404
|
+
let load = require('./helpers/browser/esm-js-loader-retry');
|
|
405
|
+
return ${loaderCode}.then((v) => {
|
|
406
|
+
Object.defineProperty(module, "exports", { value: Promise.resolve(v) })
|
|
407
|
+
return v
|
|
408
|
+
});
|
|
409
|
+
}})`;
|
|
410
|
+
return {
|
|
411
|
+
filePath: __filename,
|
|
412
|
+
code: loaderCode,
|
|
413
|
+
dependency,
|
|
414
|
+
env: {
|
|
415
|
+
sourceType: 'module'
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
let code = [];
|
|
420
|
+
if (needsEsmLoadPrelude) {
|
|
421
|
+
code.push(`let load = require('./helpers/browser/esm-js-loader');`);
|
|
422
|
+
}
|
|
423
|
+
code.push(`module.exports = ${loaderCode};`);
|
|
424
|
+
return {
|
|
425
|
+
filePath: __filename,
|
|
426
|
+
code: code.join('\n'),
|
|
427
|
+
dependency,
|
|
428
|
+
env: {
|
|
429
|
+
sourceType: 'module'
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function getHintedBundleGroups(bundleGraph, bundle) {
|
|
434
|
+
let preload = [];
|
|
435
|
+
let prefetch = [];
|
|
436
|
+
let {
|
|
437
|
+
asyncDependencies
|
|
438
|
+
} = getDependencies(bundle);
|
|
439
|
+
for (let dependency of asyncDependencies) {
|
|
440
|
+
var _dependency$meta;
|
|
441
|
+
let attributes = (_dependency$meta = dependency.meta) === null || _dependency$meta === void 0 ? void 0 : _dependency$meta.importAttributes;
|
|
442
|
+
if (typeof attributes === 'object' && attributes != null && (
|
|
443
|
+
// $FlowFixMe
|
|
444
|
+
attributes.preload || attributes.prefetch)) {
|
|
445
|
+
let resolved = bundleGraph.resolveAsyncDependency(dependency, bundle);
|
|
446
|
+
if ((resolved === null || resolved === void 0 ? void 0 : resolved.type) === 'bundle_group') {
|
|
447
|
+
// === true for flow
|
|
448
|
+
if (attributes.preload === true) {
|
|
449
|
+
preload.push(resolved.value);
|
|
450
|
+
}
|
|
451
|
+
if (attributes.prefetch === true) {
|
|
452
|
+
prefetch.push(resolved.value);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return {
|
|
458
|
+
preload,
|
|
459
|
+
prefetch
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
function getHintLoaders(bundleGraph, from, bundleGroups, loader, options) {
|
|
463
|
+
let hintLoaders = [];
|
|
464
|
+
for (let bundleGroupToPreload of bundleGroups) {
|
|
465
|
+
let bundlesToPreload = bundleGraph.getBundlesInBundleGroup(bundleGroupToPreload);
|
|
466
|
+
for (let bundleToPreload of bundlesToPreload) {
|
|
467
|
+
let relativePathExpr = getRelativePathExpr(from, bundleToPreload, options);
|
|
468
|
+
let priority = TYPE_TO_RESOURCE_PRIORITY[bundleToPreload.type];
|
|
469
|
+
hintLoaders.push(`require(${JSON.stringify(loader)})(${getAbsoluteUrlExpr(relativePathExpr, from)}, ${priority ? JSON.stringify(priority) : 'null'}, ${JSON.stringify(bundleToPreload.target.env.outputFormat === 'esmodule')})`);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return hintLoaders;
|
|
473
|
+
}
|
|
474
|
+
function isNewContext(bundle, bundleGraph) {
|
|
475
|
+
let parents = bundleGraph.getParentBundles(bundle);
|
|
476
|
+
let isInEntryBundleGroup = bundleGraph.getBundleGroupsContainingBundle(bundle).some(g => bundleGraph.isEntryBundleGroup(g));
|
|
477
|
+
return isInEntryBundleGroup || parents.length === 0 || parents.some(parent => parent.env.context !== bundle.env.context || parent.type !== 'js');
|
|
478
|
+
}
|
|
479
|
+
function getURLRuntime(dependency, from, to, options) {
|
|
480
|
+
let relativePathExpr = getRelativePathExpr(from, to, options);
|
|
481
|
+
let code;
|
|
482
|
+
if (dependency.meta.webworker === true && !from.env.isLibrary) {
|
|
483
|
+
code = `let workerURL = require('./helpers/get-worker-url');\n`;
|
|
484
|
+
if (from.env.outputFormat === 'esmodule' && from.env.supports('import-meta-url')) {
|
|
485
|
+
code += `let url = new __atlaspack__URL__(${relativePathExpr});\n`;
|
|
486
|
+
code += `module.exports = workerURL(url.toString(), url.origin, ${String(from.env.outputFormat === 'esmodule')});`;
|
|
487
|
+
} else {
|
|
488
|
+
code += `let bundleURL = require('./helpers/bundle-url');\n`;
|
|
489
|
+
code += `let url = bundleURL.getBundleURL('${from.publicId}') + ${relativePathExpr};`;
|
|
490
|
+
code += `module.exports = workerURL(url, bundleURL.getOrigin(url), ${String(from.env.outputFormat === 'esmodule')});`;
|
|
491
|
+
}
|
|
492
|
+
} else {
|
|
493
|
+
code = `module.exports = ${getAbsoluteUrlExpr(relativePathExpr, from)};`;
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
filePath: __filename,
|
|
497
|
+
code,
|
|
498
|
+
dependency,
|
|
499
|
+
env: {
|
|
500
|
+
sourceType: 'module'
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
function getRegisterCode(entryBundle, bundleGraph) {
|
|
505
|
+
let mappings = [];
|
|
506
|
+
bundleGraph.traverseBundles((bundle, _, actions) => {
|
|
507
|
+
if (bundle.bundleBehavior === 'inline') {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// To make the manifest as small as possible all bundle key/values are
|
|
512
|
+
// serialised into a single array e.g. ['id', 'value', 'id2', 'value2'].
|
|
513
|
+
// `./helpers/bundle-manifest` accounts for this by iterating index by 2
|
|
514
|
+
mappings.push(bundle.publicId, (0, _utils().relativeBundlePath)(entryBundle, (0, _nullthrows().default)(bundle), {
|
|
515
|
+
leadingDotSlash: false
|
|
516
|
+
}));
|
|
517
|
+
if (bundle !== entryBundle && isNewContext(bundle, bundleGraph)) {
|
|
518
|
+
for (let referenced of bundleGraph.getReferencedBundles(bundle)) {
|
|
519
|
+
mappings.push(referenced.publicId, (0, _utils().relativeBundlePath)(entryBundle, (0, _nullthrows().default)(referenced), {
|
|
520
|
+
leadingDotSlash: false
|
|
521
|
+
}));
|
|
522
|
+
}
|
|
523
|
+
// New contexts have their own manifests, so there's no need to continue.
|
|
524
|
+
actions.skipChildren();
|
|
525
|
+
}
|
|
526
|
+
}, entryBundle);
|
|
527
|
+
let baseUrl = entryBundle.env.outputFormat === 'esmodule' && entryBundle.env.supports('import-meta-url') ? 'new __atlaspack__URL__("").toString()' // <-- this isn't ideal. We should use `import.meta.url` directly but it gets replaced currently
|
|
528
|
+
: `require('./helpers/bundle-url').getBundleURL('${entryBundle.publicId}')`;
|
|
529
|
+
return `require('./helpers/bundle-manifest').register(${baseUrl},JSON.parse(${JSON.stringify(JSON.stringify(mappings))}));`;
|
|
530
|
+
}
|
|
531
|
+
function getRelativePathExpr(from, to, options) {
|
|
532
|
+
let relativePath = (0, _utils().relativeBundlePath)(from, to, {
|
|
533
|
+
leadingDotSlash: false
|
|
534
|
+
});
|
|
535
|
+
let res = JSON.stringify(relativePath);
|
|
536
|
+
if (options.hmrOptions) {
|
|
537
|
+
res += ' + "?" + Date.now()';
|
|
538
|
+
}
|
|
539
|
+
return res;
|
|
540
|
+
}
|
|
541
|
+
function getAbsoluteUrlExpr(relativePathExpr, bundle) {
|
|
542
|
+
if (bundle.env.outputFormat === 'esmodule' && bundle.env.supports('import-meta-url') || bundle.env.outputFormat === 'commonjs') {
|
|
543
|
+
// This will be compiled to new URL(url, import.meta.url) or new URL(url, 'file:' + __filename).
|
|
544
|
+
return `new __atlaspack__URL__(${relativePathExpr}).toString()`;
|
|
545
|
+
} else {
|
|
546
|
+
return `require('./helpers/bundle-url').getBundleURL('${bundle.publicId}') + ${relativePathExpr}`;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
function shouldUseRuntimeManifest(bundle, options) {
|
|
550
|
+
let env = bundle.env;
|
|
551
|
+
return !env.isLibrary && bundle.bundleBehavior !== 'inline' && env.isBrowser() && options.mode === 'production';
|
|
552
|
+
}
|
|
553
|
+
function getManifestBundlePriority(bundleGraph, bundle, threshold) {
|
|
554
|
+
let bundleSize = 0;
|
|
555
|
+
bundle.traverseAssets((asset, _, actions) => {
|
|
556
|
+
bundleSize += asset.stats.size;
|
|
557
|
+
if (bundleSize > threshold) {
|
|
558
|
+
actions.stop();
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
return bundleSize > threshold ? 'parallel' : 'sync';
|
|
562
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var cacheLoader = require('../cacheLoader');
|
|
4
|
+
module.exports = cacheLoader(function (bundle) {
|
|
5
|
+
return new Promise(function (resolve, reject) {
|
|
6
|
+
// Don't insert the same link element twice (e.g. if it was already in the HTML)
|
|
7
|
+
var existingLinks = document.getElementsByTagName('link');
|
|
8
|
+
if ([].concat(existingLinks).some(function isCurrentBundle(link) {
|
|
9
|
+
return link.href === bundle && link.rel.indexOf('stylesheet') > -1;
|
|
10
|
+
})) {
|
|
11
|
+
resolve();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
var link = document.createElement('link');
|
|
15
|
+
link.rel = 'stylesheet';
|
|
16
|
+
link.href = bundle;
|
|
17
|
+
link.onerror = function (e) {
|
|
18
|
+
link.onerror = link.onload = null;
|
|
19
|
+
link.remove();
|
|
20
|
+
reject(e);
|
|
21
|
+
};
|
|
22
|
+
link.onload = function () {
|
|
23
|
+
link.onerror = link.onload = null;
|
|
24
|
+
resolve();
|
|
25
|
+
};
|
|
26
|
+
document.getElementsByTagName('head')[0].appendChild(link);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : "suspendedYield", p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
5
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
6
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
7
|
+
function load() {
|
|
8
|
+
return _load.apply(this, arguments);
|
|
9
|
+
}
|
|
10
|
+
function _load() {
|
|
11
|
+
_load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(id) {
|
|
12
|
+
var url;
|
|
13
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
14
|
+
while (1) switch (_context.prev = _context.next) {
|
|
15
|
+
case 0:
|
|
16
|
+
if (!atlaspackRequire.retryState) {
|
|
17
|
+
atlaspackRequire.retryState = {};
|
|
18
|
+
}
|
|
19
|
+
if (globalThis.navigator.onLine) {
|
|
20
|
+
_context.next = 4;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
_context.next = 4;
|
|
24
|
+
return new Promise(function (res) {
|
|
25
|
+
return globalThis.addEventListener('online', res, {
|
|
26
|
+
once: true
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
case 4:
|
|
30
|
+
url = require('../bundle-manifest').resolve(id);
|
|
31
|
+
if (atlaspackRequire.retryState[id] != undefined) {
|
|
32
|
+
url = "".concat(url, "?retry=").concat(atlaspackRequire.retryState[id]);
|
|
33
|
+
}
|
|
34
|
+
_context.prev = 6;
|
|
35
|
+
_context.next = 9;
|
|
36
|
+
return __atlaspack__import__(url);
|
|
37
|
+
case 9:
|
|
38
|
+
return _context.abrupt("return", _context.sent);
|
|
39
|
+
case 12:
|
|
40
|
+
_context.prev = 12;
|
|
41
|
+
_context.t0 = _context["catch"](6);
|
|
42
|
+
atlaspackRequire.retryState[id] = Date.now();
|
|
43
|
+
case 15:
|
|
44
|
+
case "end":
|
|
45
|
+
return _context.stop();
|
|
46
|
+
}
|
|
47
|
+
}, _callee, null, [[6, 12]]);
|
|
48
|
+
}));
|
|
49
|
+
return _load.apply(this, arguments);
|
|
50
|
+
}
|
|
51
|
+
module.exports = load;
|