@atlaspack/runtime-js 2.14.12 → 2.14.14
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 +20 -0
- package/lib/JSRuntime.js +20 -7
- package/package.json +4 -4
- package/src/JSRuntime.js +30 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
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
|
+
|
|
3
23
|
## 2.14.12
|
|
4
24
|
|
|
5
25
|
### 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(
|
|
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
|
|
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 (
|
|
634
|
-
|
|
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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/runtime-js",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.14",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@atlaspack/diagnostic": "2.14.1",
|
|
19
19
|
"@atlaspack/domain-sharding": "2.14.1",
|
|
20
|
-
"@atlaspack/feature-flags": "2.18.
|
|
21
|
-
"@atlaspack/plugin": "2.14.
|
|
22
|
-
"@atlaspack/utils": "2.15.
|
|
20
|
+
"@atlaspack/feature-flags": "2.18.2",
|
|
21
|
+
"@atlaspack/plugin": "2.14.14",
|
|
22
|
+
"@atlaspack/utils": "2.15.2",
|
|
23
23
|
"nullthrows": "^1.1.1"
|
|
24
24
|
},
|
|
25
25
|
"type": "commonjs"
|
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(
|
|
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 =
|
|
215
|
-
|
|
216
|
-
|
|
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 =
|
|
670
|
-
|
|
671
|
-
|
|
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
|
|
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 (
|
|
896
|
-
|
|
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;
|