@atlaspack/runtime-js 2.14.5-dev.73 → 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 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
@@ -162,9 +162,11 @@ var _default = exports.default = new (_plugin().Runtime)({
162
162
  // If this bundle already has the asset this dependency references,
163
163
  // return a simple runtime of `Promise.resolve(internalRequire(assetId))`.
164
164
  // The linker handles this for scope-hoisting.
165
+
166
+ const requireName = (0, _featureFlags().getFeatureFlag)('hmrImprovements') ? 'parcelRequire' : 'module.bundle.root';
165
167
  assets.push({
166
168
  filePath: __filename,
167
- code: `module.exports = Promise.resolve(module.bundle.root(${JSON.stringify(bundleGraph.getAssetPublicId(resolved.value))}))`,
169
+ code: `module.exports = Promise.resolve(${requireName}(${JSON.stringify(bundleGraph.getAssetPublicId(resolved.value))}))`,
168
170
  dependency,
169
171
  env: {
170
172
  sourceType: 'module'
@@ -205,7 +207,7 @@ var _default = exports.default = new (_plugin().Runtime)({
205
207
  // replaced with a reference to this asset to implement the selection.
206
208
  const conditions = bundleGraph.getConditionsForDependencies(conditionalDependencies, bundle);
207
209
  for (const cond of conditions) {
208
- const requireName = bundle.env.shouldScopeHoist ? 'parcelRequire' : '__parcel__require__';
210
+ const requireName = (0, _featureFlags().getFeatureFlag)('hmrImprovements') || bundle.env.shouldScopeHoist ? 'parcelRequire' : '__parcel__require__';
209
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}')})`;
210
212
  assets.push({
211
213
  filePath: _path().default.join(__dirname, `/conditions/${cond.publicId}.js`),
@@ -488,7 +490,7 @@ function getLoaderRuntime({
488
490
  loaderCode = `(${loaderCode})`;
489
491
  }
490
492
  if (mainBundle.type === 'js') {
491
- let parcelRequire = bundle.env.shouldScopeHoist ? 'parcelRequire' : 'module.bundle.root';
493
+ let parcelRequire = (0, _featureFlags().getFeatureFlag)('hmrImprovements') || bundle.env.shouldScopeHoist ? 'parcelRequire' : 'module.bundle.root';
492
494
  loaderCode += `.then(() => ${parcelRequire}('${bundleGraph.getAssetPublicId(bundleGraph.getAssetById(bundleGroup.entryAssetId))}'))`;
493
495
  }
494
496
  if (needsEsmLoadPrelude && options.featureFlags.importRetry) {
@@ -571,7 +573,12 @@ function isNewContext(bundle, bundleGraph) {
571
573
  return isInEntryBundleGroup || parents.length === 0 || parents.some(parent => parent.env.context !== bundle.env.context || parent.type !== 'js');
572
574
  }
573
575
  function getURLRuntime(dependency, from, to, options, shardingConfig) {
574
- let relativePathExpr = getRelativePathExpr(from, to, options);
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
+ }
575
582
  let code;
576
583
  if (dependency.meta.webworker === true && !from.env.isLibrary) {
577
584
  code = `let workerURL = require('./helpers/get-worker-url');\n`;
@@ -625,13 +632,19 @@ function getRegisterCode(entryBundle, bundleGraph) {
625
632
  : `require('./helpers/bundle-url').getBundleURL('${entryBundle.publicId}')`;
626
633
  return `require('./helpers/bundle-manifest').register(${baseUrl},JSON.parse(${JSON.stringify(JSON.stringify(mappings))}));`;
627
634
  }
628
- function getRelativePathExpr(from, to, options) {
635
+ function getRelativePathExpr(from, to, options, isURL = to.type !== 'js') {
629
636
  let relativePath = (0, _utils().relativeBundlePath)(from, to, {
630
637
  leadingDotSlash: false
631
638
  });
632
639
  let res = JSON.stringify(relativePath);
633
- if (options.hmrOptions) {
634
- res += ' + "?" + Date.now()';
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
+ }
635
648
  }
636
649
  return res;
637
650
  }
@@ -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
- if ([].concat(existingLinks).some(function (link) {
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 loadHTMLBundle(bundle) {
5
5
  return fetch(bundle).then(function (res) {
6
6
  return res.text();
7
7
  });
@@ -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
- if ([].concat(existingScripts).some(function (script) {
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);
@@ -13,7 +13,7 @@ function getCache(type) {
13
13
  return cachedBundles;
14
14
  }
15
15
  }
16
- module.exports = function (loader, type) {
16
+ module.exports = function cacheLoader(loader, type) {
17
17
  return function (bundle) {
18
18
  let cache = getCache(type);
19
19
  if (cache[bundle]) {
@@ -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,5 +1,5 @@
1
1
  "use strict";
2
2
 
3
- module.exports = function (cond, ifTrue, ifFalse) {
3
+ module.exports = function loadCond(cond, ifTrue, ifFalse) {
4
4
  return globalThis.__MCOND && globalThis.__MCOND(cond) ? ifTrue() : ifFalse();
5
5
  };
@@ -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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  // loading a CSS style is a no-op in Node.js
4
- module.exports = function () {
4
+ module.exports = function loadCSSBundle() {
5
5
  return Promise.resolve();
6
6
  };
@@ -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.73+84eec3484",
3
+ "version": "2.14.5-dev.93+207d003c0",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,13 +15,13 @@
15
15
  "node": ">= 16.0.0"
16
16
  },
17
17
  "dependencies": {
18
- "@atlaspack/diagnostic": "2.14.1-dev.141+84eec3484",
19
- "@atlaspack/domain-sharding": "2.14.1-dev.141+84eec3484",
20
- "@atlaspack/feature-flags": "2.14.1-dev.141+84eec3484",
21
- "@atlaspack/plugin": "2.14.5-dev.73+84eec3484",
22
- "@atlaspack/utils": "2.14.5-dev.73+84eec3484",
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",
23
23
  "nullthrows": "^1.1.1"
24
24
  },
25
25
  "type": "commonjs",
26
- "gitHead": "84eec348413c647de4872f902c4bc8ff54c347f3"
26
+ "gitHead": "207d003c0f1d4ffa6a1c52d2f8841d998616c523"
27
27
  }
package/src/JSRuntime.js CHANGED
@@ -156,9 +156,14 @@ export default (new Runtime({
156
156
  // If this bundle already has the asset this dependency references,
157
157
  // return a simple runtime of `Promise.resolve(internalRequire(assetId))`.
158
158
  // The linker handles this for scope-hoisting.
159
+
160
+ const requireName = getFeatureFlag('hmrImprovements')
161
+ ? 'parcelRequire'
162
+ : 'module.bundle.root';
163
+
159
164
  assets.push({
160
165
  filePath: __filename,
161
- code: `module.exports = Promise.resolve(module.bundle.root(${JSON.stringify(
166
+ code: `module.exports = Promise.resolve(${requireName}(${JSON.stringify(
162
167
  bundleGraph.getAssetPublicId(resolved.value),
163
168
  )}))`,
164
169
  dependency,
@@ -211,9 +216,10 @@ export default (new Runtime({
211
216
  bundle,
212
217
  );
213
218
  for (const cond of conditions) {
214
- const requireName = bundle.env.shouldScopeHoist
215
- ? 'parcelRequire'
216
- : '__parcel__require__';
219
+ const requireName =
220
+ getFeatureFlag('hmrImprovements') || bundle.env.shouldScopeHoist
221
+ ? 'parcelRequire'
222
+ : '__parcel__require__';
217
223
 
218
224
  const assetCode = `module.exports = require('../helpers/conditional-loader${
219
225
  options.mode === 'development' ? '-dev' : ''
@@ -666,9 +672,11 @@ function getLoaderRuntime({
666
672
  }
667
673
 
668
674
  if (mainBundle.type === 'js') {
669
- let parcelRequire = bundle.env.shouldScopeHoist
670
- ? 'parcelRequire'
671
- : 'module.bundle.root';
675
+ let parcelRequire =
676
+ getFeatureFlag('hmrImprovements') || bundle.env.shouldScopeHoist
677
+ ? 'parcelRequire'
678
+ : 'module.bundle.root';
679
+
672
680
  loaderCode += `.then(() => ${parcelRequire}('${bundleGraph.getAssetPublicId(
673
681
  bundleGraph.getAssetById(bundleGroup.entryAssetId),
674
682
  )}'))`;
@@ -801,7 +809,12 @@ function getURLRuntime(
801
809
  options: PluginOptions,
802
810
  shardingConfig: JSRuntimeConfig['domainSharding'],
803
811
  ): RuntimeAsset {
804
- let relativePathExpr = getRelativePathExpr(from, to, options);
812
+ let relativePathExpr;
813
+ if (getFeatureFlag('hmrImprovements')) {
814
+ relativePathExpr = getRelativePathExpr(from, to, options, true);
815
+ } else {
816
+ relativePathExpr = getRelativePathExpr(from, to, options);
817
+ }
805
818
  let code;
806
819
 
807
820
  if (dependency.meta.webworker === true && !from.env.isLibrary) {
@@ -889,11 +902,18 @@ function getRelativePathExpr(
889
902
  from: NamedBundle,
890
903
  to: NamedBundle,
891
904
  options: PluginOptions,
905
+ isURL = to.type !== 'js',
892
906
  ): string {
893
907
  let relativePath = relativeBundlePath(from, to, {leadingDotSlash: false});
894
908
  let res = JSON.stringify(relativePath);
895
- if (options.hmrOptions) {
896
- res += ' + "?" + Date.now()';
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
+ }
897
917
  }
898
918
 
899
919
  return res;