@atlaspack/runtime-js 2.14.5-dev.72 → 2.14.5-dev.93
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/CHANGELOG.md +29 -0
- package/lib/JSRuntime.js +34 -47
- package/lib/helpers/browser/css-loader.js +4 -3
- package/lib/helpers/browser/html-loader.js +1 -1
- package/lib/helpers/browser/import-polyfill.js +1 -1
- package/lib/helpers/browser/js-loader.js +4 -3
- package/lib/helpers/browser/prefetch-loader.js +1 -1
- package/lib/helpers/browser/preload-loader.js +1 -1
- package/lib/helpers/browser/wasm-loader.js +1 -1
- package/lib/helpers/cacheLoader.js +1 -1
- package/lib/helpers/conditional-loader-dev.js +1 -1
- package/lib/helpers/conditional-loader.js +1 -1
- package/lib/helpers/get-worker-url.js +1 -1
- package/lib/helpers/node/css-loader.js +1 -1
- package/lib/helpers/node/html-loader.js +1 -1
- package/lib/helpers/node/js-loader.js +1 -1
- package/lib/helpers/node/wasm-loader.js +1 -1
- package/lib/helpers/worker/js-loader.js +1 -1
- package/lib/helpers/worker/wasm-loader.js +1 -1
- package/package.json +7 -10
- package/src/JSRuntime.js +47 -51
- package/lib/helpers/browser/esm-js-loader-shards-super.js +0 -7
- package/src/helpers/browser/esm-js-loader-shards-super.js +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @atlaspack/runtime-js
|
|
2
2
|
|
|
3
|
+
## 2.14.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`644b157`](https://github.com/atlassian-labs/atlaspack/commit/644b157dee72a871acc2d0facf0b87b8eea51956)]:
|
|
8
|
+
- @atlaspack/feature-flags@2.18.2
|
|
9
|
+
- @atlaspack/utils@2.15.2
|
|
10
|
+
- @atlaspack/plugin@2.14.14
|
|
11
|
+
|
|
12
|
+
## 2.14.13
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#633](https://github.com/atlassian-labs/atlaspack/pull/633) [`26aa9c5`](https://github.com/atlassian-labs/atlaspack/commit/26aa9c599d2be45ce1438a74c5fa22f39b9b554b) Thanks [@sbhuiyan-atlassian](https://github.com/sbhuiyan-atlassian)! - Ported various HMR changes from Parcel
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`26aa9c5`](https://github.com/atlassian-labs/atlaspack/commit/26aa9c599d2be45ce1438a74c5fa22f39b9b554b), [`0501255`](https://github.com/atlassian-labs/atlaspack/commit/05012550da35b05ce7d356a8cc29311e7f9afdca)]:
|
|
19
|
+
- @atlaspack/feature-flags@2.18.1
|
|
20
|
+
- @atlaspack/utils@2.15.1
|
|
21
|
+
- @atlaspack/plugin@2.14.13
|
|
22
|
+
|
|
23
|
+
## 2.14.12
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [[`10fbcfb`](https://github.com/atlassian-labs/atlaspack/commit/10fbcfbfa49c7a83da5d7c40983e36e87f524a75), [`85c52d3`](https://github.com/atlassian-labs/atlaspack/commit/85c52d3f7717b3c84a118d18ab98cfbfd71dcbd2), [`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
|
|
28
|
+
- @atlaspack/feature-flags@2.18.0
|
|
29
|
+
- @atlaspack/utils@2.15.0
|
|
30
|
+
- @atlaspack/plugin@2.14.12
|
|
31
|
+
|
|
3
32
|
## 2.14.11
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
package/lib/JSRuntime.js
CHANGED
|
@@ -46,24 +46,7 @@ function _featureFlags() {
|
|
|
46
46
|
};
|
|
47
47
|
return data;
|
|
48
48
|
}
|
|
49
|
-
function _core() {
|
|
50
|
-
const data = require("@atlaspack/core");
|
|
51
|
-
_core = function () {
|
|
52
|
-
return data;
|
|
53
|
-
};
|
|
54
|
-
return data;
|
|
55
|
-
}
|
|
56
49
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
57
|
-
const domainShardingImports = (0, _core().isSuperPackage)() ? {
|
|
58
|
-
specifier: 'atlaspack/lib/domain-sharding.js',
|
|
59
|
-
helper: './helpers/browser/esm-js-loader-shards-super.js'
|
|
60
|
-
} : {
|
|
61
|
-
specifier: '@atlaspack/domain-sharding',
|
|
62
|
-
helper: './helpers/browser/esm-js-loader-shards.js'
|
|
63
|
-
};
|
|
64
|
-
const filename = /*#__ATLASPACK_IGNORE__*/__filename;
|
|
65
|
-
const dirname = /*#__ATLASPACK_IGNORE__*/__dirname;
|
|
66
|
-
|
|
67
50
|
// Used for as="" in preload/prefetch
|
|
68
51
|
const TYPE_TO_RESOURCE_PRIORITY = {
|
|
69
52
|
css: 'style',
|
|
@@ -179,9 +162,11 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
179
162
|
// If this bundle already has the asset this dependency references,
|
|
180
163
|
// return a simple runtime of `Promise.resolve(internalRequire(assetId))`.
|
|
181
164
|
// The linker handles this for scope-hoisting.
|
|
165
|
+
|
|
166
|
+
const requireName = (0, _featureFlags().getFeatureFlag)('hmrImprovements') ? 'parcelRequire' : 'module.bundle.root';
|
|
182
167
|
assets.push({
|
|
183
|
-
filePath:
|
|
184
|
-
code: `module.exports = Promise.resolve(
|
|
168
|
+
filePath: __filename,
|
|
169
|
+
code: `module.exports = Promise.resolve(${requireName}(${JSON.stringify(bundleGraph.getAssetPublicId(resolved.value))}))`,
|
|
185
170
|
dependency,
|
|
186
171
|
env: {
|
|
187
172
|
sourceType: 'module'
|
|
@@ -194,7 +179,7 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
194
179
|
let referencedBundle = bundleGraph.getReferencedBundle(dependency, bundle);
|
|
195
180
|
if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline') {
|
|
196
181
|
assets.push({
|
|
197
|
-
filePath: _path().default.join(
|
|
182
|
+
filePath: _path().default.join(__dirname, `/bundles/${referencedBundle.id}.js`),
|
|
198
183
|
code: `module.exports = Promise.resolve(${JSON.stringify(dependency.id)});`,
|
|
199
184
|
dependency,
|
|
200
185
|
env: {
|
|
@@ -222,10 +207,10 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
222
207
|
// replaced with a reference to this asset to implement the selection.
|
|
223
208
|
const conditions = bundleGraph.getConditionsForDependencies(conditionalDependencies, bundle);
|
|
224
209
|
for (const cond of conditions) {
|
|
225
|
-
const requireName = bundle.env.shouldScopeHoist ? 'parcelRequire' : '__parcel__require__';
|
|
210
|
+
const requireName = (0, _featureFlags().getFeatureFlag)('hmrImprovements') || bundle.env.shouldScopeHoist ? 'parcelRequire' : '__parcel__require__';
|
|
226
211
|
const assetCode = `module.exports = require('../helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}')('${cond.key}', function (){return ${requireName}('${cond.ifTrueAssetId}')}, function (){return ${requireName}('${cond.ifFalseAssetId}')})`;
|
|
227
212
|
assets.push({
|
|
228
|
-
filePath: _path().default.join(
|
|
213
|
+
filePath: _path().default.join(__dirname, `/conditions/${cond.publicId}.js`),
|
|
229
214
|
code: assetCode,
|
|
230
215
|
// This dependency is important, as it's the last symbol handled in scope hoisting.
|
|
231
216
|
// That means that scope hoisting will use the module id for this asset to replace the symbol
|
|
@@ -243,7 +228,7 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
243
228
|
let referencedBundle = bundleGraph.getReferencedBundle(dependency, bundle);
|
|
244
229
|
if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline') {
|
|
245
230
|
assets.push({
|
|
246
|
-
filePath: _path().default.join(
|
|
231
|
+
filePath: _path().default.join(__dirname, `/bundles/${referencedBundle.id}.js`),
|
|
247
232
|
code: `module.exports = ${JSON.stringify(dependency.id)};`,
|
|
248
233
|
dependency,
|
|
249
234
|
env: {
|
|
@@ -260,7 +245,7 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
260
245
|
// If a URL dependency was not able to be resolved, add a runtime that
|
|
261
246
|
// exports the original specifier.
|
|
262
247
|
assets.push({
|
|
263
|
-
filePath:
|
|
248
|
+
filePath: __filename,
|
|
264
249
|
code: `module.exports = ${JSON.stringify(dependency.specifier)}`,
|
|
265
250
|
dependency,
|
|
266
251
|
env: {
|
|
@@ -278,15 +263,6 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
278
263
|
return entries.some(e => bundleGroup.entryAssetId === e.id);
|
|
279
264
|
}));
|
|
280
265
|
|
|
281
|
-
// Skip URL runtime for native node imports as they need to be require
|
|
282
|
-
// directly
|
|
283
|
-
// Currently enabled only for internal builds
|
|
284
|
-
if (process.env.ATLASPACK_SUPER_BUILD === 'true') {
|
|
285
|
-
if (mainBundle.bundleBehavior === 'isolated' && mainBundle.env.context === 'node' && mainBundle.type === 'node') {
|
|
286
|
-
continue;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
266
|
// Skip URL runtimes for library builds. This is handled in packaging so that
|
|
291
267
|
// the url is inlined and statically analyzable.
|
|
292
268
|
if (bundle.env.isLibrary && mainBundle.bundleBehavior !== 'isolated') {
|
|
@@ -314,7 +290,7 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
314
290
|
let relativePathExpr = getRelativePathExpr(bundle, referencedBundle, options);
|
|
315
291
|
let loaderCode = `require(${JSON.stringify(loader)})(${getAbsoluteUrlExpr(relativePathExpr, bundle, config.domainSharding)})`;
|
|
316
292
|
assets.push({
|
|
317
|
-
filePath:
|
|
293
|
+
filePath: __filename,
|
|
318
294
|
code: loaderCode,
|
|
319
295
|
isEntry: true,
|
|
320
296
|
env: {
|
|
@@ -325,7 +301,7 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
325
301
|
}
|
|
326
302
|
if (shouldUseRuntimeManifest(bundle, options) && bundleGraph.getChildBundles(bundle).some(b => b.bundleBehavior !== 'inline') && isNewContext(bundle, bundleGraph)) {
|
|
327
303
|
assets.push({
|
|
328
|
-
filePath:
|
|
304
|
+
filePath: __filename,
|
|
329
305
|
code: getRegisterCode(bundle, bundleGraph),
|
|
330
306
|
isEntry: true,
|
|
331
307
|
env: {
|
|
@@ -435,7 +411,7 @@ function getLoaderRuntime({
|
|
|
435
411
|
let publicId = JSON.stringify(to.publicId);
|
|
436
412
|
absoluteUrlExpr = `require('./helpers/bundle-manifest').resolve(${publicId})`;
|
|
437
413
|
if (shardingConfig) {
|
|
438
|
-
absoluteUrlExpr = `require('
|
|
414
|
+
absoluteUrlExpr = `require('@atlaspack/domain-sharding').shardUrl(${absoluteUrlExpr}, ${shardingConfig.maxShards})`;
|
|
439
415
|
}
|
|
440
416
|
} else {
|
|
441
417
|
absoluteUrlExpr = getAbsoluteUrlExpr(relativePathExpr, bundle, shardingConfig);
|
|
@@ -514,7 +490,7 @@ function getLoaderRuntime({
|
|
|
514
490
|
loaderCode = `(${loaderCode})`;
|
|
515
491
|
}
|
|
516
492
|
if (mainBundle.type === 'js') {
|
|
517
|
-
let parcelRequire = bundle.env.shouldScopeHoist ? 'parcelRequire' : 'module.bundle.root';
|
|
493
|
+
let parcelRequire = (0, _featureFlags().getFeatureFlag)('hmrImprovements') || bundle.env.shouldScopeHoist ? 'parcelRequire' : 'module.bundle.root';
|
|
518
494
|
loaderCode += `.then(() => ${parcelRequire}('${bundleGraph.getAssetPublicId(bundleGraph.getAssetById(bundleGroup.entryAssetId))}'))`;
|
|
519
495
|
}
|
|
520
496
|
if (needsEsmLoadPrelude && options.featureFlags.importRetry) {
|
|
@@ -527,7 +503,7 @@ function getLoaderRuntime({
|
|
|
527
503
|
});
|
|
528
504
|
}})`;
|
|
529
505
|
return {
|
|
530
|
-
filePath:
|
|
506
|
+
filePath: __filename,
|
|
531
507
|
code: loaderCode,
|
|
532
508
|
dependency,
|
|
533
509
|
env: {
|
|
@@ -537,12 +513,12 @@ function getLoaderRuntime({
|
|
|
537
513
|
}
|
|
538
514
|
let code = [];
|
|
539
515
|
if (needsEsmLoadPrelude) {
|
|
540
|
-
let preludeLoad = shardingConfig ? `let load = require('
|
|
516
|
+
let preludeLoad = shardingConfig ? `let load = require('./helpers/browser/esm-js-loader-shards')(${shardingConfig.maxShards});` : `let load = require('./helpers/browser/esm-js-loader');`;
|
|
541
517
|
code.push(preludeLoad);
|
|
542
518
|
}
|
|
543
519
|
code.push(`module.exports = ${loaderCode};`);
|
|
544
520
|
return {
|
|
545
|
-
filePath:
|
|
521
|
+
filePath: __filename,
|
|
546
522
|
code: code.join('\n'),
|
|
547
523
|
dependency,
|
|
548
524
|
env: {
|
|
@@ -597,7 +573,12 @@ function isNewContext(bundle, bundleGraph) {
|
|
|
597
573
|
return isInEntryBundleGroup || parents.length === 0 || parents.some(parent => parent.env.context !== bundle.env.context || parent.type !== 'js');
|
|
598
574
|
}
|
|
599
575
|
function getURLRuntime(dependency, from, to, options, shardingConfig) {
|
|
600
|
-
let relativePathExpr
|
|
576
|
+
let relativePathExpr;
|
|
577
|
+
if ((0, _featureFlags().getFeatureFlag)('hmrImprovements')) {
|
|
578
|
+
relativePathExpr = getRelativePathExpr(from, to, options, true);
|
|
579
|
+
} else {
|
|
580
|
+
relativePathExpr = getRelativePathExpr(from, to, options);
|
|
581
|
+
}
|
|
601
582
|
let code;
|
|
602
583
|
if (dependency.meta.webworker === true && !from.env.isLibrary) {
|
|
603
584
|
code = `let workerURL = require('./helpers/get-worker-url');\n`;
|
|
@@ -608,7 +589,7 @@ function getURLRuntime(dependency, from, to, options, shardingConfig) {
|
|
|
608
589
|
code += `let bundleURL = require('./helpers/bundle-url');\n`;
|
|
609
590
|
code += `let url = bundleURL.getBundleURL('${from.publicId}') + ${relativePathExpr};`;
|
|
610
591
|
if (shardingConfig) {
|
|
611
|
-
code += `url = require('
|
|
592
|
+
code += `url = require('@atlaspack/domain-sharding').shardUrl(url, ${shardingConfig.maxShards});`;
|
|
612
593
|
}
|
|
613
594
|
code += `module.exports = workerURL(url, bundleURL.getOrigin(url), ${String(from.env.outputFormat === 'esmodule')});`;
|
|
614
595
|
}
|
|
@@ -616,7 +597,7 @@ function getURLRuntime(dependency, from, to, options, shardingConfig) {
|
|
|
616
597
|
code = `module.exports = ${getAbsoluteUrlExpr(relativePathExpr, from, shardingConfig)};`;
|
|
617
598
|
}
|
|
618
599
|
return {
|
|
619
|
-
filePath:
|
|
600
|
+
filePath: __filename,
|
|
620
601
|
code,
|
|
621
602
|
dependency,
|
|
622
603
|
env: {
|
|
@@ -651,13 +632,19 @@ function getRegisterCode(entryBundle, bundleGraph) {
|
|
|
651
632
|
: `require('./helpers/bundle-url').getBundleURL('${entryBundle.publicId}')`;
|
|
652
633
|
return `require('./helpers/bundle-manifest').register(${baseUrl},JSON.parse(${JSON.stringify(JSON.stringify(mappings))}));`;
|
|
653
634
|
}
|
|
654
|
-
function getRelativePathExpr(from, to, options) {
|
|
635
|
+
function getRelativePathExpr(from, to, options, isURL = to.type !== 'js') {
|
|
655
636
|
let relativePath = (0, _utils().relativeBundlePath)(from, to, {
|
|
656
637
|
leadingDotSlash: false
|
|
657
638
|
});
|
|
658
639
|
let res = JSON.stringify(relativePath);
|
|
659
|
-
if (
|
|
660
|
-
|
|
640
|
+
if ((0, _featureFlags().getFeatureFlag)('hmrImprovements')) {
|
|
641
|
+
if (isURL && options.hmrOptions) {
|
|
642
|
+
res += ' + "?" + Date.now()';
|
|
643
|
+
}
|
|
644
|
+
} else {
|
|
645
|
+
if (options.hmrOptions) {
|
|
646
|
+
res += ' + "?" + Date.now()';
|
|
647
|
+
}
|
|
661
648
|
}
|
|
662
649
|
return res;
|
|
663
650
|
}
|
|
@@ -670,7 +657,7 @@ function getAbsoluteUrlExpr(relativePathExpr, fromBundle, shardingConfig) {
|
|
|
670
657
|
if (!shardingConfig) {
|
|
671
658
|
return regularBundleUrl;
|
|
672
659
|
}
|
|
673
|
-
return `require('
|
|
660
|
+
return `require('@atlaspack/domain-sharding').shardUrl(${regularBundleUrl}, ${shardingConfig.maxShards})`;
|
|
674
661
|
}
|
|
675
662
|
function shouldUseRuntimeManifest(bundle, options) {
|
|
676
663
|
let env = bundle.env;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function loadCSSBundle(bundle) {
|
|
5
5
|
return new Promise(function (resolve, reject) {
|
|
6
6
|
// Don't insert the same link element twice (e.g. if it was already in the HTML)
|
|
7
7
|
let existingLinks = document.getElementsByTagName('link');
|
|
8
|
-
|
|
8
|
+
let isCurrentBundle = function (link) {
|
|
9
9
|
return link.href === bundle && link.rel.indexOf('stylesheet') > -1;
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
|
+
if ([].concat(existingLinks).some(isCurrentBundle)) {
|
|
11
12
|
resolve();
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function importModule(bundle) {
|
|
5
5
|
return new Promise((resolve, reject) => {
|
|
6
6
|
// Add a global function to handle when the script loads.
|
|
7
7
|
let globalName = `i${('' + Math.random()).slice(2)}`;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function loadJSBundle(bundle) {
|
|
5
5
|
return new Promise(function (resolve, reject) {
|
|
6
6
|
// Don't insert the same script twice (e.g. if it was already in the HTML)
|
|
7
7
|
let existingScripts = document.getElementsByTagName('script');
|
|
8
|
-
|
|
8
|
+
let isCurrentBundle = function (script) {
|
|
9
9
|
return script.src === bundle;
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
|
+
if ([].concat(existingScripts).some(isCurrentBundle)) {
|
|
11
12
|
resolve();
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle, priority) {
|
|
4
|
+
module.exports = cacheLoader(function prefetchJSBundle(bundle, priority) {
|
|
5
5
|
var link = document.createElement('link');
|
|
6
6
|
link.rel = 'prefetch';
|
|
7
7
|
link.href = bundle;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle, priority, isModule) {
|
|
4
|
+
module.exports = cacheLoader(function preloadJSBundle(bundle, priority, isModule) {
|
|
5
5
|
var link = document.createElement('link');
|
|
6
6
|
link.charset = 'utf-8';
|
|
7
7
|
link.rel = isModule ? 'modulepreload' : 'preload';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function loadWASMBundle(bundle) {
|
|
5
5
|
return fetch(bundle).then(function (res) {
|
|
6
6
|
if (WebAssembly.instantiateStreaming) {
|
|
7
7
|
return WebAssembly.instantiateStreaming(res);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
module.exports = function (cond, ifTrue, ifFalse) {
|
|
3
|
+
module.exports = function loadCond(cond, ifTrue, ifFalse) {
|
|
4
4
|
if (typeof globalThis.__MCOND !== 'function') {
|
|
5
5
|
throw new TypeError('"globalThis.__MCOND" was not set to an object. Ensure the function is set to return the key condition for conditional bundles to load with.');
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
module.exports = function (workerUrl, origin, isESM) {
|
|
3
|
+
module.exports = function loadWorker(workerUrl, origin, isESM) {
|
|
4
4
|
if (origin === self.location.origin) {
|
|
5
5
|
// If the worker bundle's url is on the same origin as the document,
|
|
6
6
|
// use the worker bundle's own url.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const cacheLoader = require('../cacheLoader');
|
|
5
|
-
module.exports = cacheLoader(function (bundle) {
|
|
5
|
+
module.exports = cacheLoader(function loadHTMLBundle(bundle) {
|
|
6
6
|
return new Promise(function (resolve, reject) {
|
|
7
7
|
fs.readFile(__dirname + bundle, 'utf8', function (err, data) {
|
|
8
8
|
if (err) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const cacheLoader = require('../cacheLoader');
|
|
5
|
-
module.exports = cacheLoader(function (bundle) {
|
|
5
|
+
module.exports = cacheLoader(function loadJSBundle(bundle) {
|
|
6
6
|
return new Promise(function (resolve, reject) {
|
|
7
7
|
fs.readFile(__dirname + bundle, 'utf8', function (err, data) {
|
|
8
8
|
if (err) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const cacheLoader = require('../cacheLoader');
|
|
5
|
-
module.exports = cacheLoader(function (bundle) {
|
|
5
|
+
module.exports = cacheLoader(function loadWASMBundle(bundle) {
|
|
6
6
|
return new Promise(function (resolve, reject) {
|
|
7
7
|
fs.readFile(__dirname + bundle, function (err, data) {
|
|
8
8
|
if (err) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/* global __parcel__importScripts__:readonly*/
|
|
4
4
|
const cacheLoader = require('../cacheLoader');
|
|
5
|
-
module.exports = cacheLoader(function (bundle) {
|
|
5
|
+
module.exports = cacheLoader(function loadJSBundle(bundle) {
|
|
6
6
|
return new Promise(function (resolve, reject) {
|
|
7
7
|
try {
|
|
8
8
|
__parcel__importScripts__(bundle);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function loadWASMBundle(bundle) {
|
|
5
5
|
return fetch(bundle).then(function (res) {
|
|
6
6
|
if (WebAssembly.instantiateStreaming) {
|
|
7
7
|
return WebAssembly.instantiateStreaming(res);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/runtime-js",
|
|
3
|
-
"version": "2.14.5-dev.
|
|
3
|
+
"version": "2.14.5-dev.93+207d003c0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -11,20 +11,17 @@
|
|
|
11
11
|
},
|
|
12
12
|
"main": "lib/JSRuntime.js",
|
|
13
13
|
"source": "src/JSRuntime.js",
|
|
14
|
-
"atlaspackReferences": [
|
|
15
|
-
"./src/helpers/**/*"
|
|
16
|
-
],
|
|
17
14
|
"engines": {
|
|
18
15
|
"node": ">= 16.0.0"
|
|
19
16
|
},
|
|
20
17
|
"dependencies": {
|
|
21
|
-
"@atlaspack/diagnostic": "2.14.1-dev.
|
|
22
|
-
"@atlaspack/domain-sharding": "2.14.1-dev.
|
|
23
|
-
"@atlaspack/feature-flags": "2.14.1-dev.
|
|
24
|
-
"@atlaspack/plugin": "2.14.5-dev.
|
|
25
|
-
"@atlaspack/utils": "2.14.5-dev.
|
|
18
|
+
"@atlaspack/diagnostic": "2.14.1-dev.161+207d003c0",
|
|
19
|
+
"@atlaspack/domain-sharding": "2.14.1-dev.161+207d003c0",
|
|
20
|
+
"@atlaspack/feature-flags": "2.14.1-dev.161+207d003c0",
|
|
21
|
+
"@atlaspack/plugin": "2.14.5-dev.93+207d003c0",
|
|
22
|
+
"@atlaspack/utils": "2.14.5-dev.93+207d003c0",
|
|
26
23
|
"nullthrows": "^1.1.1"
|
|
27
24
|
},
|
|
28
25
|
"type": "commonjs",
|
|
29
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "207d003c0f1d4ffa6a1c52d2f8841d998616c523"
|
|
30
27
|
}
|
package/src/JSRuntime.js
CHANGED
|
@@ -19,20 +19,6 @@ import {encodeJSONKeyComponent} from '@atlaspack/diagnostic';
|
|
|
19
19
|
import path from 'path';
|
|
20
20
|
import nullthrows from 'nullthrows';
|
|
21
21
|
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
22
|
-
import {isSuperPackage} from '@atlaspack/core';
|
|
23
|
-
|
|
24
|
-
const domainShardingImports = isSuperPackage()
|
|
25
|
-
? {
|
|
26
|
-
specifier: 'atlaspack/lib/domain-sharding.js',
|
|
27
|
-
helper: './helpers/browser/esm-js-loader-shards-super.js',
|
|
28
|
-
}
|
|
29
|
-
: {
|
|
30
|
-
specifier: '@atlaspack/domain-sharding',
|
|
31
|
-
helper: './helpers/browser/esm-js-loader-shards.js',
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const filename = /*#__ATLASPACK_IGNORE__*/ __filename;
|
|
35
|
-
const dirname = /*#__ATLASPACK_IGNORE__*/ __dirname;
|
|
36
22
|
|
|
37
23
|
// Used for as="" in preload/prefetch
|
|
38
24
|
const TYPE_TO_RESOURCE_PRIORITY = {
|
|
@@ -170,9 +156,14 @@ export default (new Runtime({
|
|
|
170
156
|
// If this bundle already has the asset this dependency references,
|
|
171
157
|
// return a simple runtime of `Promise.resolve(internalRequire(assetId))`.
|
|
172
158
|
// The linker handles this for scope-hoisting.
|
|
159
|
+
|
|
160
|
+
const requireName = getFeatureFlag('hmrImprovements')
|
|
161
|
+
? 'parcelRequire'
|
|
162
|
+
: 'module.bundle.root';
|
|
163
|
+
|
|
173
164
|
assets.push({
|
|
174
|
-
filePath:
|
|
175
|
-
code: `module.exports = Promise.resolve(
|
|
165
|
+
filePath: __filename,
|
|
166
|
+
code: `module.exports = Promise.resolve(${requireName}(${JSON.stringify(
|
|
176
167
|
bundleGraph.getAssetPublicId(resolved.value),
|
|
177
168
|
)}))`,
|
|
178
169
|
dependency,
|
|
@@ -188,7 +179,10 @@ export default (new Runtime({
|
|
|
188
179
|
);
|
|
189
180
|
if (referencedBundle?.bundleBehavior === 'inline') {
|
|
190
181
|
assets.push({
|
|
191
|
-
filePath: path.join(
|
|
182
|
+
filePath: path.join(
|
|
183
|
+
__dirname,
|
|
184
|
+
`/bundles/${referencedBundle.id}.js`,
|
|
185
|
+
),
|
|
192
186
|
code: `module.exports = Promise.resolve(${JSON.stringify(
|
|
193
187
|
dependency.id,
|
|
194
188
|
)});`,
|
|
@@ -222,9 +216,10 @@ export default (new Runtime({
|
|
|
222
216
|
bundle,
|
|
223
217
|
);
|
|
224
218
|
for (const cond of conditions) {
|
|
225
|
-
const requireName =
|
|
226
|
-
|
|
227
|
-
|
|
219
|
+
const requireName =
|
|
220
|
+
getFeatureFlag('hmrImprovements') || bundle.env.shouldScopeHoist
|
|
221
|
+
? 'parcelRequire'
|
|
222
|
+
: '__parcel__require__';
|
|
228
223
|
|
|
229
224
|
const assetCode = `module.exports = require('../helpers/conditional-loader${
|
|
230
225
|
options.mode === 'development' ? '-dev' : ''
|
|
@@ -233,7 +228,7 @@ export default (new Runtime({
|
|
|
233
228
|
}')}, function (){return ${requireName}('${cond.ifFalseAssetId}')})`;
|
|
234
229
|
|
|
235
230
|
assets.push({
|
|
236
|
-
filePath: path.join(
|
|
231
|
+
filePath: path.join(__dirname, `/conditions/${cond.publicId}.js`),
|
|
237
232
|
code: assetCode,
|
|
238
233
|
// This dependency is important, as it's the last symbol handled in scope hoisting.
|
|
239
234
|
// That means that scope hoisting will use the module id for this asset to replace the symbol
|
|
@@ -253,7 +248,7 @@ export default (new Runtime({
|
|
|
253
248
|
);
|
|
254
249
|
if (referencedBundle?.bundleBehavior === 'inline') {
|
|
255
250
|
assets.push({
|
|
256
|
-
filePath: path.join(
|
|
251
|
+
filePath: path.join(__dirname, `/bundles/${referencedBundle.id}.js`),
|
|
257
252
|
code: `module.exports = ${JSON.stringify(dependency.id)};`,
|
|
258
253
|
dependency,
|
|
259
254
|
env: {sourceType: 'module'},
|
|
@@ -268,7 +263,7 @@ export default (new Runtime({
|
|
|
268
263
|
// If a URL dependency was not able to be resolved, add a runtime that
|
|
269
264
|
// exports the original specifier.
|
|
270
265
|
assets.push({
|
|
271
|
-
filePath:
|
|
266
|
+
filePath: __filename,
|
|
272
267
|
code: `module.exports = ${JSON.stringify(dependency.specifier)}`,
|
|
273
268
|
dependency,
|
|
274
269
|
env: {sourceType: 'module'},
|
|
@@ -288,19 +283,6 @@ export default (new Runtime({
|
|
|
288
283
|
}),
|
|
289
284
|
);
|
|
290
285
|
|
|
291
|
-
// Skip URL runtime for native node imports as they need to be require
|
|
292
|
-
// directly
|
|
293
|
-
// Currently enabled only for internal builds
|
|
294
|
-
if (process.env.ATLASPACK_SUPER_BUILD === 'true') {
|
|
295
|
-
if (
|
|
296
|
-
mainBundle.bundleBehavior === 'isolated' &&
|
|
297
|
-
mainBundle.env.context === 'node' &&
|
|
298
|
-
mainBundle.type === 'node'
|
|
299
|
-
) {
|
|
300
|
-
continue;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
286
|
// Skip URL runtimes for library builds. This is handled in packaging so that
|
|
305
287
|
// the url is inlined and statically analyzable.
|
|
306
288
|
if (bundle.env.isLibrary && mainBundle.bundleBehavior !== 'isolated') {
|
|
@@ -348,7 +330,7 @@ export default (new Runtime({
|
|
|
348
330
|
config.domainSharding,
|
|
349
331
|
)})`;
|
|
350
332
|
assets.push({
|
|
351
|
-
filePath:
|
|
333
|
+
filePath: __filename,
|
|
352
334
|
code: loaderCode,
|
|
353
335
|
isEntry: true,
|
|
354
336
|
env: {sourceType: 'module'},
|
|
@@ -364,7 +346,7 @@ export default (new Runtime({
|
|
|
364
346
|
isNewContext(bundle, bundleGraph)
|
|
365
347
|
) {
|
|
366
348
|
assets.push({
|
|
367
|
-
filePath:
|
|
349
|
+
filePath: __filename,
|
|
368
350
|
code: getRegisterCode(bundle, bundleGraph),
|
|
369
351
|
isEntry: true,
|
|
370
352
|
env: {sourceType: 'module'},
|
|
@@ -513,7 +495,7 @@ function getLoaderRuntime({
|
|
|
513
495
|
absoluteUrlExpr = `require('./helpers/bundle-manifest').resolve(${publicId})`;
|
|
514
496
|
|
|
515
497
|
if (shardingConfig) {
|
|
516
|
-
absoluteUrlExpr = `require('
|
|
498
|
+
absoluteUrlExpr = `require('@atlaspack/domain-sharding').shardUrl(${absoluteUrlExpr}, ${shardingConfig.maxShards})`;
|
|
517
499
|
}
|
|
518
500
|
} else {
|
|
519
501
|
absoluteUrlExpr = getAbsoluteUrlExpr(
|
|
@@ -690,9 +672,11 @@ function getLoaderRuntime({
|
|
|
690
672
|
}
|
|
691
673
|
|
|
692
674
|
if (mainBundle.type === 'js') {
|
|
693
|
-
let parcelRequire =
|
|
694
|
-
|
|
695
|
-
|
|
675
|
+
let parcelRequire =
|
|
676
|
+
getFeatureFlag('hmrImprovements') || bundle.env.shouldScopeHoist
|
|
677
|
+
? 'parcelRequire'
|
|
678
|
+
: 'module.bundle.root';
|
|
679
|
+
|
|
696
680
|
loaderCode += `.then(() => ${parcelRequire}('${bundleGraph.getAssetPublicId(
|
|
697
681
|
bundleGraph.getAssetById(bundleGroup.entryAssetId),
|
|
698
682
|
)}'))`;
|
|
@@ -709,7 +693,7 @@ function getLoaderRuntime({
|
|
|
709
693
|
}})`;
|
|
710
694
|
|
|
711
695
|
return {
|
|
712
|
-
filePath:
|
|
696
|
+
filePath: __filename,
|
|
713
697
|
code: loaderCode,
|
|
714
698
|
dependency,
|
|
715
699
|
env: {sourceType: 'module'},
|
|
@@ -720,7 +704,7 @@ function getLoaderRuntime({
|
|
|
720
704
|
|
|
721
705
|
if (needsEsmLoadPrelude) {
|
|
722
706
|
let preludeLoad = shardingConfig
|
|
723
|
-
? `let load = require('
|
|
707
|
+
? `let load = require('./helpers/browser/esm-js-loader-shards')(${shardingConfig.maxShards});`
|
|
724
708
|
: `let load = require('./helpers/browser/esm-js-loader');`;
|
|
725
709
|
|
|
726
710
|
code.push(preludeLoad);
|
|
@@ -729,7 +713,7 @@ function getLoaderRuntime({
|
|
|
729
713
|
code.push(`module.exports = ${loaderCode};`);
|
|
730
714
|
|
|
731
715
|
return {
|
|
732
|
-
filePath:
|
|
716
|
+
filePath: __filename,
|
|
733
717
|
code: code.join('\n'),
|
|
734
718
|
dependency,
|
|
735
719
|
env: {sourceType: 'module'},
|
|
@@ -825,7 +809,12 @@ function getURLRuntime(
|
|
|
825
809
|
options: PluginOptions,
|
|
826
810
|
shardingConfig: JSRuntimeConfig['domainSharding'],
|
|
827
811
|
): RuntimeAsset {
|
|
828
|
-
let relativePathExpr
|
|
812
|
+
let relativePathExpr;
|
|
813
|
+
if (getFeatureFlag('hmrImprovements')) {
|
|
814
|
+
relativePathExpr = getRelativePathExpr(from, to, options, true);
|
|
815
|
+
} else {
|
|
816
|
+
relativePathExpr = getRelativePathExpr(from, to, options);
|
|
817
|
+
}
|
|
829
818
|
let code;
|
|
830
819
|
|
|
831
820
|
if (dependency.meta.webworker === true && !from.env.isLibrary) {
|
|
@@ -842,7 +831,7 @@ function getURLRuntime(
|
|
|
842
831
|
code += `let bundleURL = require('./helpers/bundle-url');\n`;
|
|
843
832
|
code += `let url = bundleURL.getBundleURL('${from.publicId}') + ${relativePathExpr};`;
|
|
844
833
|
if (shardingConfig) {
|
|
845
|
-
code += `url = require('
|
|
834
|
+
code += `url = require('@atlaspack/domain-sharding').shardUrl(url, ${shardingConfig.maxShards});`;
|
|
846
835
|
}
|
|
847
836
|
code += `module.exports = workerURL(url, bundleURL.getOrigin(url), ${String(
|
|
848
837
|
from.env.outputFormat === 'esmodule',
|
|
@@ -857,7 +846,7 @@ function getURLRuntime(
|
|
|
857
846
|
}
|
|
858
847
|
|
|
859
848
|
return {
|
|
860
|
-
filePath:
|
|
849
|
+
filePath: __filename,
|
|
861
850
|
code,
|
|
862
851
|
dependency,
|
|
863
852
|
env: {sourceType: 'module'},
|
|
@@ -913,11 +902,18 @@ function getRelativePathExpr(
|
|
|
913
902
|
from: NamedBundle,
|
|
914
903
|
to: NamedBundle,
|
|
915
904
|
options: PluginOptions,
|
|
905
|
+
isURL = to.type !== 'js',
|
|
916
906
|
): string {
|
|
917
907
|
let relativePath = relativeBundlePath(from, to, {leadingDotSlash: false});
|
|
918
908
|
let res = JSON.stringify(relativePath);
|
|
919
|
-
if (
|
|
920
|
-
|
|
909
|
+
if (getFeatureFlag('hmrImprovements')) {
|
|
910
|
+
if (isURL && options.hmrOptions) {
|
|
911
|
+
res += ' + "?" + Date.now()';
|
|
912
|
+
}
|
|
913
|
+
} else {
|
|
914
|
+
if (options.hmrOptions) {
|
|
915
|
+
res += ' + "?" + Date.now()';
|
|
916
|
+
}
|
|
921
917
|
}
|
|
922
918
|
|
|
923
919
|
return res;
|
|
@@ -943,7 +939,7 @@ function getAbsoluteUrlExpr(
|
|
|
943
939
|
return regularBundleUrl;
|
|
944
940
|
}
|
|
945
941
|
|
|
946
|
-
return `require('
|
|
942
|
+
return `require('@atlaspack/domain-sharding').shardUrl(${regularBundleUrl}, ${shardingConfig.maxShards})`;
|
|
947
943
|
}
|
|
948
944
|
|
|
949
945
|
function shouldUseRuntimeManifest(
|