@atlaspack/packager-js 2.23.8-dev-compiled-hash-e5f8a1735.0 → 2.24.0
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 +31 -0
- package/dist/DevPackager.js +1 -2
- package/dist/ScopeHoistingPackager.js +40 -8
- package/lib/DevPackager.js +1 -2
- package/lib/ScopeHoistingPackager.js +43 -8
- package/lib/types/DevPackager.d.ts +1 -1
- package/lib/types/ScopeHoistingPackager.d.ts +3 -1
- package/lib/types/utils.d.ts +1 -1
- package/package.json +9 -10
- package/src/DevPackager.ts +1 -2
- package/src/ScopeHoistingPackager.ts +49 -8
- package/src/index.ts +1 -1
- package/src/utils.ts +1 -1
- package/tsconfig.json +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/LICENSE +0 -201
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @atlaspack/packager-js
|
|
2
2
|
|
|
3
|
+
## 2.24.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#858](https://github.com/atlassian-labs/atlaspack/pull/858) [`8eb84ee`](https://github.com/atlassian-labs/atlaspack/commit/8eb84ee61a42bfe87c58079b610802b07a6a13e4) Thanks [@marcins](https://github.com/marcins)! - Introduce a new `getReferencedAssets(bundle)` method to the BundleGraph to pre-compute referenced assets, this is used by the scope hoisting packager behind a new `precomputeReferencedAssets` feature flag.
|
|
8
|
+
|
|
9
|
+
- [#789](https://github.com/atlassian-labs/atlaspack/pull/789) [`73168c2`](https://github.com/atlassian-labs/atlaspack/commit/73168c275a5d9abff9907bcf536b340bca1ed5f0) Thanks [@marcins](https://github.com/marcins)! - Use an in-sourced version of @parcel/source-map, as @atlaspack/source-map
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`7dd5bd8`](https://github.com/atlassian-labs/atlaspack/commit/7dd5bd89ff60c7b324347d772729eb4c3314f01e), [`c8a0e51`](https://github.com/atlassian-labs/atlaspack/commit/c8a0e51b1096d038a64644ad02fe68383f58682a), [`8eb84ee`](https://github.com/atlassian-labs/atlaspack/commit/8eb84ee61a42bfe87c58079b610802b07a6a13e4), [`71900f3`](https://github.com/atlassian-labs/atlaspack/commit/71900f3508d53c3882ca8ea71501ba3069687d4e), [`73168c2`](https://github.com/atlassian-labs/atlaspack/commit/73168c275a5d9abff9907bcf536b340bca1ed5f0), [`617a318`](https://github.com/atlassian-labs/atlaspack/commit/617a318ddc9419b38360257353fec50b9051ee13), [`2c4953e`](https://github.com/atlassian-labs/atlaspack/commit/2c4953e20dc1a6b012792081667aefeb9340505e), [`3fe7d4e`](https://github.com/atlassian-labs/atlaspack/commit/3fe7d4e821bee162fcbbaf9278b107a5eead944f)]:
|
|
14
|
+
- @atlaspack/rust@3.11.0
|
|
15
|
+
- @atlaspack/feature-flags@2.27.0
|
|
16
|
+
- @atlaspack/source-map@3.1.0
|
|
17
|
+
- @atlaspack/utils@3.2.0
|
|
18
|
+
- @atlaspack/plugin@2.14.39
|
|
19
|
+
- @atlaspack/types@2.15.29
|
|
20
|
+
|
|
21
|
+
## 2.23.8
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- [#882](https://github.com/atlassian-labs/atlaspack/pull/882) [`13d23e8`](https://github.com/atlassian-labs/atlaspack/commit/13d23e8a23091f92eb1b8dd7c9a452fe33cf1aac) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Fix an issue where in rare cases, scope hoisting could cause 'Cannot find module'
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [[`ec3abe4`](https://github.com/atlassian-labs/atlaspack/commit/ec3abe4dffc98560a850fd2f71fb566577e6c99c), [`c7fe3f7`](https://github.com/atlassian-labs/atlaspack/commit/c7fe3f76f247e9e20299e205e2df0a16c418eaf2), [`cfb4707`](https://github.com/atlassian-labs/atlaspack/commit/cfb4707087498e4fa4dcf10753fe984a248d196b), [`1468695`](https://github.com/atlassian-labs/atlaspack/commit/1468695fc0c9d06f060a6da9e9b0e154f11dff34), [`f31b041`](https://github.com/atlassian-labs/atlaspack/commit/f31b04107e9077c9946aadb99f6f91bb69703bb7), [`8180981`](https://github.com/atlassian-labs/atlaspack/commit/8180981be14c00f9570adb70d3f350bd91d6ec0a), [`ae77e74`](https://github.com/atlassian-labs/atlaspack/commit/ae77e7452a466b43b3fa5bed24d4ba26345ed765), [`f0a496f`](https://github.com/atlassian-labs/atlaspack/commit/f0a496f70fc8652e090cf1b3f6260e8cfbb796e2), [`7d7a55d`](https://github.com/atlassian-labs/atlaspack/commit/7d7a55dd6395ec391a2e4c33b3dec0d1ea477d4c), [`540f253`](https://github.com/atlassian-labs/atlaspack/commit/540f253dfdcd1a5caebbdc0b197319d439404aae)]:
|
|
28
|
+
- @atlaspack/feature-flags@2.26.2
|
|
29
|
+
- @atlaspack/rust@3.10.0
|
|
30
|
+
- @atlaspack/utils@3.1.2
|
|
31
|
+
- @atlaspack/plugin@2.14.38
|
|
32
|
+
- @atlaspack/types@2.15.28
|
|
33
|
+
|
|
3
34
|
## 2.23.7
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
package/dist/DevPackager.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DevPackager = void 0;
|
|
7
7
|
const utils_1 = require("@atlaspack/utils");
|
|
8
|
-
const source_map_1 = __importDefault(require("@
|
|
8
|
+
const source_map_1 = __importDefault(require("@atlaspack/source-map"));
|
|
9
9
|
const feature_flags_1 = require("@atlaspack/feature-flags");
|
|
10
10
|
const assert_1 = __importDefault(require("assert"));
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
@@ -162,7 +162,6 @@ class DevPackager {
|
|
|
162
162
|
// @ts-expect-error TS2339
|
|
163
163
|
script.code, entryMap, this.parcelRequireName);
|
|
164
164
|
if (this.bundle.env.sourceMap && entryMap) {
|
|
165
|
-
// @ts-expect-error TS2551
|
|
166
165
|
map.addSourceMap(entryMap, lineOffset);
|
|
167
166
|
}
|
|
168
167
|
}
|
|
@@ -38,7 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.ScopeHoistingPackager = void 0;
|
|
40
40
|
const utils_1 = require("@atlaspack/utils");
|
|
41
|
-
const source_map_1 = __importDefault(require("@
|
|
41
|
+
const source_map_1 = __importDefault(require("@atlaspack/source-map"));
|
|
42
42
|
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
43
43
|
const assert_1 = __importStar(require("assert"));
|
|
44
44
|
const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
|
|
@@ -95,6 +95,7 @@ class ScopeHoistingPackager {
|
|
|
95
95
|
this.externalAssets = new Set();
|
|
96
96
|
this.useBothScopeHoistingImprovements = (0, feature_flags_1.getFeatureFlag)('applyScopeHoistingImprovementV2') ||
|
|
97
97
|
(0, feature_flags_1.getFeatureFlag)('applyScopeHoistingImprovement');
|
|
98
|
+
this.referencedAssetsCache = new Map();
|
|
98
99
|
this.options = options;
|
|
99
100
|
this.bundleGraph = bundleGraph;
|
|
100
101
|
this.bundle = bundle;
|
|
@@ -135,7 +136,6 @@ class ScopeHoistingPackager {
|
|
|
135
136
|
this.seenHoistedRequires.clear();
|
|
136
137
|
let [content, map, lines] = this.visitAsset(asset);
|
|
137
138
|
if (sourceMap && map) {
|
|
138
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
139
139
|
sourceMap.addSourceMap(map, lineCount);
|
|
140
140
|
}
|
|
141
141
|
else if (this.bundle.env.sourceMap) {
|
|
@@ -301,6 +301,36 @@ class ScopeHoistingPackager {
|
|
|
301
301
|
];
|
|
302
302
|
return `$parcel$global.rwr(${params.join(', ')});`;
|
|
303
303
|
}
|
|
304
|
+
// Helper to check if an asset is referenced, with cache-first + fast-check hybrid approach
|
|
305
|
+
isAssetReferencedInBundle(bundle, asset) {
|
|
306
|
+
// STEP 1: Check expensive computation cache first (fastest when it hits)
|
|
307
|
+
if ((0, feature_flags_1.getFeatureFlag)('precomputeReferencedAssets')) {
|
|
308
|
+
let bundleId = bundle.id;
|
|
309
|
+
let referencedAssets = this.referencedAssetsCache.get(bundleId);
|
|
310
|
+
if (referencedAssets) {
|
|
311
|
+
// Cache hit - fastest path (~0.001ms)
|
|
312
|
+
return referencedAssets.has(asset);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
// STEP 2: Cache miss - try fast checks (~0.01ms)
|
|
316
|
+
let fastCheckResult = this.bundleGraph.isAssetReferencedFastCheck(bundle, asset);
|
|
317
|
+
if (fastCheckResult === true) {
|
|
318
|
+
// Fast check succeeded - asset is referenced
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
// STEP 3: Need expensive computation (~20-2000ms)
|
|
322
|
+
if ((0, feature_flags_1.getFeatureFlag)('precomputeReferencedAssets')) {
|
|
323
|
+
// Compute and cache expensive results for this bundle
|
|
324
|
+
let bundleId = bundle.id;
|
|
325
|
+
let referencedAssets = this.bundleGraph.getReferencedAssets(bundle);
|
|
326
|
+
this.referencedAssetsCache.set(bundleId, referencedAssets);
|
|
327
|
+
return referencedAssets.has(asset);
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
// No caching - fall back to original expensive method
|
|
331
|
+
return this.bundleGraph.isAssetReferenced(bundle, asset);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
304
334
|
async loadAssets() {
|
|
305
335
|
let queue = new utils_1.PromiseQueue({
|
|
306
336
|
maxConcurrent: 32,
|
|
@@ -315,7 +345,7 @@ class ScopeHoistingPackager {
|
|
|
315
345
|
});
|
|
316
346
|
if (asset.meta.shouldWrap ||
|
|
317
347
|
this.bundle.env.sourceType === 'script' ||
|
|
318
|
-
this.
|
|
348
|
+
this.isAssetReferencedInBundle(this.bundle, asset) ||
|
|
319
349
|
this.bundleGraph
|
|
320
350
|
.getIncomingDependencies(asset)
|
|
321
351
|
.some((dep) => dep.meta.shouldWrap && dep.specifierType !== 'url')) {
|
|
@@ -515,6 +545,11 @@ class ScopeHoistingPackager {
|
|
|
515
545
|
if (this.bundle.hasAsset(resolved) && !this.seenAssets.has(resolved)) {
|
|
516
546
|
if (this.useBothScopeHoistingImprovements &&
|
|
517
547
|
this.wrappedAssets.has(resolved)) {
|
|
548
|
+
if (this.wrappedAssets.has(asset)) {
|
|
549
|
+
// If both the asset and the dep are wrapped there's no need to
|
|
550
|
+
// drop a side-effect require. This is an extremely rare case.
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
518
553
|
// When the dep is wrapped then we just need to drop a side effect
|
|
519
554
|
// require instead of inlining
|
|
520
555
|
depCode += `parcelRequire("${this.bundleGraph.getAssetPublicId(resolved)}");\n`;
|
|
@@ -524,7 +559,6 @@ class ScopeHoistingPackager {
|
|
|
524
559
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
525
560
|
depCode += code + '\n';
|
|
526
561
|
if (sourceMap && map) {
|
|
527
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
528
562
|
sourceMap.addSourceMap(map, lineCount);
|
|
529
563
|
}
|
|
530
564
|
lineCount += lines + 1;
|
|
@@ -647,7 +681,6 @@ class ScopeHoistingPackager {
|
|
|
647
681
|
sourceMap.offsetLines(lineCount + 1, lines);
|
|
648
682
|
}
|
|
649
683
|
if (map) {
|
|
650
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
651
684
|
sourceMap.addSourceMap(map, lineCount);
|
|
652
685
|
}
|
|
653
686
|
}
|
|
@@ -691,7 +724,6 @@ ${code}
|
|
|
691
724
|
continue;
|
|
692
725
|
code += depCode + '\n';
|
|
693
726
|
if (sourceMap && map) {
|
|
694
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
695
727
|
sourceMap.addSourceMap(map, lineCount);
|
|
696
728
|
}
|
|
697
729
|
lineCount += lines + 1;
|
|
@@ -737,7 +769,7 @@ ${code}
|
|
|
737
769
|
if (referencedBundle &&
|
|
738
770
|
referencedBundle.getMainEntry() === resolved &&
|
|
739
771
|
referencedBundle.type === 'js' &&
|
|
740
|
-
!this.
|
|
772
|
+
!this.isAssetReferencedInBundle(referencedBundle, resolved)) {
|
|
741
773
|
this.addExternal(dep, replacements, referencedBundle);
|
|
742
774
|
this.externalAssets.add(resolved);
|
|
743
775
|
continue;
|
|
@@ -1343,7 +1375,7 @@ ${code}
|
|
|
1343
1375
|
}
|
|
1344
1376
|
return (asset.sideEffects === false &&
|
|
1345
1377
|
(0, nullthrows_1.default)(this.bundleGraph.getUsedSymbols(asset)).size == 0 &&
|
|
1346
|
-
!this.
|
|
1378
|
+
!this.isAssetReferencedInBundle(this.bundle, asset));
|
|
1347
1379
|
}
|
|
1348
1380
|
isScriptEntry(asset) {
|
|
1349
1381
|
return (this.bundle.env.outputFormat === 'global' &&
|
package/lib/DevPackager.js
CHANGED
|
@@ -12,7 +12,7 @@ function _utils() {
|
|
|
12
12
|
return data;
|
|
13
13
|
}
|
|
14
14
|
function _sourceMap() {
|
|
15
|
-
const data = _interopRequireDefault(require("@
|
|
15
|
+
const data = _interopRequireDefault(require("@atlaspack/source-map"));
|
|
16
16
|
_sourceMap = function () {
|
|
17
17
|
return data;
|
|
18
18
|
};
|
|
@@ -182,7 +182,6 @@ class DevPackager {
|
|
|
182
182
|
// @ts-expect-error TS2339
|
|
183
183
|
script.code, entryMap, this.parcelRequireName);
|
|
184
184
|
if (this.bundle.env.sourceMap && entryMap) {
|
|
185
|
-
// @ts-expect-error TS2551
|
|
186
185
|
map.addSourceMap(entryMap, lineOffset);
|
|
187
186
|
}
|
|
188
187
|
}
|
|
@@ -12,7 +12,7 @@ function _utils() {
|
|
|
12
12
|
return data;
|
|
13
13
|
}
|
|
14
14
|
function _sourceMap2() {
|
|
15
|
-
const data = _interopRequireDefault(require("@
|
|
15
|
+
const data = _interopRequireDefault(require("@atlaspack/source-map"));
|
|
16
16
|
_sourceMap2 = function () {
|
|
17
17
|
return data;
|
|
18
18
|
};
|
|
@@ -110,6 +110,7 @@ class ScopeHoistingPackager {
|
|
|
110
110
|
usedHelpers = new Set();
|
|
111
111
|
externalAssets = new Set();
|
|
112
112
|
useBothScopeHoistingImprovements = (0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovementV2') || (0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovement');
|
|
113
|
+
referencedAssetsCache = new Map();
|
|
113
114
|
constructor(options, bundleGraph, bundle, parcelRequireName, useAsyncBundleRuntime, manualStaticBindingExports, logger) {
|
|
114
115
|
this.options = options;
|
|
115
116
|
this.bundleGraph = bundleGraph;
|
|
@@ -147,7 +148,6 @@ class ScopeHoistingPackager {
|
|
|
147
148
|
this.seenHoistedRequires.clear();
|
|
148
149
|
let [content, map, lines] = this.visitAsset(asset);
|
|
149
150
|
if (sourceMap && map) {
|
|
150
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
151
151
|
sourceMap.addSourceMap(map, lineCount);
|
|
152
152
|
} else if (this.bundle.env.sourceMap) {
|
|
153
153
|
sourceMap = map;
|
|
@@ -300,6 +300,38 @@ class ScopeHoistingPackager {
|
|
|
300
300
|
let params = [JSON.stringify(this.bundle.publicId), (0, _helpers.fnExpr)(this.bundle.env, [], [codeToRun]), `${JSON.stringify(deps)}${conditions.length > 0 ? `.concat([${conditions.map(conditions => `...${conditions}`).join(',')}])` : ''}`];
|
|
301
301
|
return `$parcel$global.rwr(${params.join(', ')});`;
|
|
302
302
|
}
|
|
303
|
+
|
|
304
|
+
// Helper to check if an asset is referenced, with cache-first + fast-check hybrid approach
|
|
305
|
+
isAssetReferencedInBundle(bundle, asset) {
|
|
306
|
+
// STEP 1: Check expensive computation cache first (fastest when it hits)
|
|
307
|
+
if ((0, _featureFlags().getFeatureFlag)('precomputeReferencedAssets')) {
|
|
308
|
+
let bundleId = bundle.id;
|
|
309
|
+
let referencedAssets = this.referencedAssetsCache.get(bundleId);
|
|
310
|
+
if (referencedAssets) {
|
|
311
|
+
// Cache hit - fastest path (~0.001ms)
|
|
312
|
+
return referencedAssets.has(asset);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// STEP 2: Cache miss - try fast checks (~0.01ms)
|
|
317
|
+
let fastCheckResult = this.bundleGraph.isAssetReferencedFastCheck(bundle, asset);
|
|
318
|
+
if (fastCheckResult === true) {
|
|
319
|
+
// Fast check succeeded - asset is referenced
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// STEP 3: Need expensive computation (~20-2000ms)
|
|
324
|
+
if ((0, _featureFlags().getFeatureFlag)('precomputeReferencedAssets')) {
|
|
325
|
+
// Compute and cache expensive results for this bundle
|
|
326
|
+
let bundleId = bundle.id;
|
|
327
|
+
let referencedAssets = this.bundleGraph.getReferencedAssets(bundle);
|
|
328
|
+
this.referencedAssetsCache.set(bundleId, referencedAssets);
|
|
329
|
+
return referencedAssets.has(asset);
|
|
330
|
+
} else {
|
|
331
|
+
// No caching - fall back to original expensive method
|
|
332
|
+
return this.bundleGraph.isAssetReferenced(bundle, asset);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
303
335
|
async loadAssets() {
|
|
304
336
|
let queue = new (_utils().PromiseQueue)({
|
|
305
337
|
maxConcurrent: 32
|
|
@@ -312,7 +344,7 @@ class ScopeHoistingPackager {
|
|
|
312
344
|
map
|
|
313
345
|
}];
|
|
314
346
|
});
|
|
315
|
-
if (asset.meta.shouldWrap || this.bundle.env.sourceType === 'script' || this.
|
|
347
|
+
if (asset.meta.shouldWrap || this.bundle.env.sourceType === 'script' || this.isAssetReferencedInBundle(this.bundle, asset) || this.bundleGraph.getIncomingDependencies(asset).some(dep => dep.meta.shouldWrap && dep.specifierType !== 'url')) {
|
|
316
348
|
// Don't wrap constant "entry" modules _except_ if they are referenced by any lazy dependency
|
|
317
349
|
if (!asset.meta.isConstantModule || this.bundleGraph.getIncomingDependencies(asset).some(dep => dep.priority === 'lazy')) {
|
|
318
350
|
this.wrappedAssets.add(asset);
|
|
@@ -506,6 +538,12 @@ class ScopeHoistingPackager {
|
|
|
506
538
|
}
|
|
507
539
|
if (this.bundle.hasAsset(resolved) && !this.seenAssets.has(resolved)) {
|
|
508
540
|
if (this.useBothScopeHoistingImprovements && this.wrappedAssets.has(resolved)) {
|
|
541
|
+
if (this.wrappedAssets.has(asset)) {
|
|
542
|
+
// If both the asset and the dep are wrapped there's no need to
|
|
543
|
+
// drop a side-effect require. This is an extremely rare case.
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
|
|
509
547
|
// When the dep is wrapped then we just need to drop a side effect
|
|
510
548
|
// require instead of inlining
|
|
511
549
|
depCode += `parcelRequire("${this.bundleGraph.getAssetPublicId(resolved)}");\n`;
|
|
@@ -514,7 +552,6 @@ class ScopeHoistingPackager {
|
|
|
514
552
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
515
553
|
depCode += code + '\n';
|
|
516
554
|
if (sourceMap && map) {
|
|
517
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
518
555
|
sourceMap.addSourceMap(map, lineCount);
|
|
519
556
|
}
|
|
520
557
|
lineCount += lines + 1;
|
|
@@ -633,7 +670,6 @@ class ScopeHoistingPackager {
|
|
|
633
670
|
sourceMap.offsetLines(lineCount + 1, lines);
|
|
634
671
|
}
|
|
635
672
|
if (map) {
|
|
636
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
637
673
|
sourceMap.addSourceMap(map, lineCount);
|
|
638
674
|
}
|
|
639
675
|
}
|
|
@@ -678,7 +714,6 @@ ${code}
|
|
|
678
714
|
if (!depCode) continue;
|
|
679
715
|
code += depCode + '\n';
|
|
680
716
|
if (sourceMap && map) {
|
|
681
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
682
717
|
sourceMap.addSourceMap(map, lineCount);
|
|
683
718
|
}
|
|
684
719
|
lineCount += lines + 1;
|
|
@@ -716,7 +751,7 @@ ${code}
|
|
|
716
751
|
// Handle imports from other bundles in libraries.
|
|
717
752
|
if (this.bundle.env.isLibrary && !this.bundle.hasAsset(resolved)) {
|
|
718
753
|
let referencedBundle = this.bundleGraph.getReferencedBundle(dep, this.bundle);
|
|
719
|
-
if (referencedBundle && referencedBundle.getMainEntry() === resolved && referencedBundle.type === 'js' && !this.
|
|
754
|
+
if (referencedBundle && referencedBundle.getMainEntry() === resolved && referencedBundle.type === 'js' && !this.isAssetReferencedInBundle(referencedBundle, resolved)) {
|
|
720
755
|
this.addExternal(dep, replacements, referencedBundle);
|
|
721
756
|
this.externalAssets.add(resolved);
|
|
722
757
|
continue;
|
|
@@ -1252,7 +1287,7 @@ ${code}
|
|
|
1252
1287
|
if (this.isScriptEntry(asset)) {
|
|
1253
1288
|
return true;
|
|
1254
1289
|
}
|
|
1255
|
-
return asset.sideEffects === false && (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(asset)).size == 0 && !this.
|
|
1290
|
+
return asset.sideEffects === false && (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(asset)).size == 0 && !this.isAssetReferencedInBundle(this.bundle, asset);
|
|
1256
1291
|
}
|
|
1257
1292
|
isScriptEntry(asset) {
|
|
1258
1293
|
return this.bundle.env.outputFormat === 'global' && this.bundle.env.sourceType === 'script' && asset === this.bundle.getMainEntry();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BundleGraph, PluginOptions, NamedBundle } from '@atlaspack/types';
|
|
2
|
-
import SourceMap from '@
|
|
2
|
+
import SourceMap from '@atlaspack/source-map';
|
|
3
3
|
export declare class DevPackager {
|
|
4
4
|
options: PluginOptions;
|
|
5
5
|
bundleGraph: BundleGraph<NamedBundle>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Asset, BundleGraph, Dependency, PluginOptions, NamedBundle, PluginLogger } from '@atlaspack/types';
|
|
2
|
-
import SourceMap from '@
|
|
2
|
+
import SourceMap from '@atlaspack/source-map';
|
|
3
3
|
export interface OutputFormat {
|
|
4
4
|
buildBundlePrelude(): [string, number];
|
|
5
5
|
buildBundlePostlude(): [string, number];
|
|
@@ -44,10 +44,12 @@ export declare class ScopeHoistingPackager {
|
|
|
44
44
|
externalAssets: Set<Asset>;
|
|
45
45
|
logger: PluginLogger;
|
|
46
46
|
useBothScopeHoistingImprovements: boolean;
|
|
47
|
+
referencedAssetsCache: Map<string, Set<Asset>>;
|
|
47
48
|
constructor(options: PluginOptions, bundleGraph: BundleGraph<NamedBundle>, bundle: NamedBundle, parcelRequireName: string, useAsyncBundleRuntime: boolean, manualStaticBindingExports: string[] | null, logger: PluginLogger);
|
|
48
49
|
package(): Promise<PackageResult>;
|
|
49
50
|
shouldBundleQueue(bundle: NamedBundle): boolean;
|
|
50
51
|
runWhenReady(bundle: NamedBundle, codeToRun: string): string;
|
|
52
|
+
isAssetReferencedInBundle(bundle: NamedBundle, asset: Asset): boolean;
|
|
51
53
|
loadAssets(): Promise<void>;
|
|
52
54
|
isReExported(asset: Asset): boolean;
|
|
53
55
|
buildExportedSymbols(): void;
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BundleGraph, Dependency, NamedBundle } from '@atlaspack/types';
|
|
2
|
-
import type SourceMap from '@
|
|
2
|
+
import type SourceMap from '@atlaspack/source-map';
|
|
3
3
|
export declare function replaceScriptDependencies(bundleGraph: BundleGraph<NamedBundle>, bundle: NamedBundle, code: string, map: SourceMap | null | undefined, parcelRequireName: string): string;
|
|
4
4
|
export declare function getSpecifier(dep: Dependency): string;
|
|
5
5
|
export declare function isValidIdentifier(id: string): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.24.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/diagnostic": "2.14.
|
|
20
|
-
"@atlaspack/feature-flags": "2.
|
|
21
|
-
"@atlaspack/plugin": "2.14.
|
|
22
|
-
"@atlaspack/rust": "3.
|
|
23
|
-
"@atlaspack/
|
|
24
|
-
"@atlaspack/
|
|
25
|
-
"@
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.4",
|
|
20
|
+
"@atlaspack/feature-flags": "2.27.0",
|
|
21
|
+
"@atlaspack/plugin": "2.14.39",
|
|
22
|
+
"@atlaspack/rust": "3.11.0",
|
|
23
|
+
"@atlaspack/source-map": "3.1.0",
|
|
24
|
+
"@atlaspack/types": "2.15.29",
|
|
25
|
+
"@atlaspack/utils": "3.2.0",
|
|
26
26
|
"globals": "^13.2.0",
|
|
27
27
|
"nullthrows": "^1.1.1",
|
|
28
28
|
"outdent": "^0.8.0"
|
|
@@ -30,6 +30,5 @@
|
|
|
30
30
|
"type": "commonjs",
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
33
|
-
}
|
|
34
|
-
"gitHead": "e5f8a173505611c1fafafd6e7dddb2f6b483f67c"
|
|
33
|
+
}
|
|
35
34
|
}
|
package/src/DevPackager.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
countLines,
|
|
7
7
|
normalizeSeparators,
|
|
8
8
|
} from '@atlaspack/utils';
|
|
9
|
-
import SourceMap from '@
|
|
9
|
+
import SourceMap from '@atlaspack/source-map';
|
|
10
10
|
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
11
11
|
import invariant from 'assert';
|
|
12
12
|
import path from 'path';
|
|
@@ -229,7 +229,6 @@ export class DevPackager {
|
|
|
229
229
|
this.parcelRequireName,
|
|
230
230
|
);
|
|
231
231
|
if (this.bundle.env.sourceMap && entryMap) {
|
|
232
|
-
// @ts-expect-error TS2551
|
|
233
232
|
map.addSourceMap(entryMap, lineOffset);
|
|
234
233
|
}
|
|
235
234
|
}
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
debugTools,
|
|
17
17
|
globToRegex,
|
|
18
18
|
} from '@atlaspack/utils';
|
|
19
|
-
import SourceMap from '@
|
|
19
|
+
import SourceMap from '@atlaspack/source-map';
|
|
20
20
|
import nullthrows from 'nullthrows';
|
|
21
21
|
import invariant, {AssertionError} from 'assert';
|
|
22
22
|
import ThrowableDiagnostic, {
|
|
@@ -131,6 +131,7 @@ export class ScopeHoistingPackager {
|
|
|
131
131
|
useBothScopeHoistingImprovements: boolean =
|
|
132
132
|
getFeatureFlag('applyScopeHoistingImprovementV2') ||
|
|
133
133
|
getFeatureFlag('applyScopeHoistingImprovement');
|
|
134
|
+
referencedAssetsCache: Map<string, Set<Asset>> = new Map();
|
|
134
135
|
|
|
135
136
|
constructor(
|
|
136
137
|
options: PluginOptions,
|
|
@@ -190,7 +191,6 @@ export class ScopeHoistingPackager {
|
|
|
190
191
|
let [content, map, lines] = this.visitAsset(asset);
|
|
191
192
|
|
|
192
193
|
if (sourceMap && map) {
|
|
193
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
194
194
|
sourceMap.addSourceMap(map, lineCount);
|
|
195
195
|
} else if (this.bundle.env.sourceMap) {
|
|
196
196
|
sourceMap = map;
|
|
@@ -412,6 +412,44 @@ export class ScopeHoistingPackager {
|
|
|
412
412
|
return `$parcel$global.rwr(${params.join(', ')});`;
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
+
// Helper to check if an asset is referenced, with cache-first + fast-check hybrid approach
|
|
416
|
+
isAssetReferencedInBundle(bundle: NamedBundle, asset: Asset): boolean {
|
|
417
|
+
// STEP 1: Check expensive computation cache first (fastest when it hits)
|
|
418
|
+
if (getFeatureFlag('precomputeReferencedAssets')) {
|
|
419
|
+
let bundleId = bundle.id;
|
|
420
|
+
let referencedAssets = this.referencedAssetsCache.get(bundleId);
|
|
421
|
+
|
|
422
|
+
if (referencedAssets) {
|
|
423
|
+
// Cache hit - fastest path (~0.001ms)
|
|
424
|
+
return referencedAssets.has(asset);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// STEP 2: Cache miss - try fast checks (~0.01ms)
|
|
429
|
+
let fastCheckResult = this.bundleGraph.isAssetReferencedFastCheck(
|
|
430
|
+
bundle,
|
|
431
|
+
asset,
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
if (fastCheckResult === true) {
|
|
435
|
+
// Fast check succeeded - asset is referenced
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// STEP 3: Need expensive computation (~20-2000ms)
|
|
440
|
+
if (getFeatureFlag('precomputeReferencedAssets')) {
|
|
441
|
+
// Compute and cache expensive results for this bundle
|
|
442
|
+
let bundleId = bundle.id;
|
|
443
|
+
let referencedAssets = this.bundleGraph.getReferencedAssets(bundle);
|
|
444
|
+
this.referencedAssetsCache.set(bundleId, referencedAssets);
|
|
445
|
+
|
|
446
|
+
return referencedAssets.has(asset);
|
|
447
|
+
} else {
|
|
448
|
+
// No caching - fall back to original expensive method
|
|
449
|
+
return this.bundleGraph.isAssetReferenced(bundle, asset);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
415
453
|
async loadAssets() {
|
|
416
454
|
type QueueItem = [Asset, {code: string; map: Buffer | undefined | null}];
|
|
417
455
|
let queue = new PromiseQueue<QueueItem>({
|
|
@@ -431,7 +469,7 @@ export class ScopeHoistingPackager {
|
|
|
431
469
|
if (
|
|
432
470
|
asset.meta.shouldWrap ||
|
|
433
471
|
this.bundle.env.sourceType === 'script' ||
|
|
434
|
-
this.
|
|
472
|
+
this.isAssetReferencedInBundle(this.bundle, asset) ||
|
|
435
473
|
this.bundleGraph
|
|
436
474
|
.getIncomingDependencies(asset)
|
|
437
475
|
.some((dep) => dep.meta.shouldWrap && dep.specifierType !== 'url')
|
|
@@ -692,6 +730,12 @@ export class ScopeHoistingPackager {
|
|
|
692
730
|
this.useBothScopeHoistingImprovements &&
|
|
693
731
|
this.wrappedAssets.has(resolved)
|
|
694
732
|
) {
|
|
733
|
+
if (this.wrappedAssets.has(asset)) {
|
|
734
|
+
// If both the asset and the dep are wrapped there's no need to
|
|
735
|
+
// drop a side-effect require. This is an extremely rare case.
|
|
736
|
+
continue;
|
|
737
|
+
}
|
|
738
|
+
|
|
695
739
|
// When the dep is wrapped then we just need to drop a side effect
|
|
696
740
|
// require instead of inlining
|
|
697
741
|
depCode += `parcelRequire("${this.bundleGraph.getAssetPublicId(resolved)}");\n`;
|
|
@@ -700,7 +744,6 @@ export class ScopeHoistingPackager {
|
|
|
700
744
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
701
745
|
depCode += code + '\n';
|
|
702
746
|
if (sourceMap && map) {
|
|
703
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
704
747
|
sourceMap.addSourceMap(map, lineCount);
|
|
705
748
|
}
|
|
706
749
|
lineCount += lines + 1;
|
|
@@ -856,7 +899,6 @@ export class ScopeHoistingPackager {
|
|
|
856
899
|
}
|
|
857
900
|
|
|
858
901
|
if (map) {
|
|
859
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
860
902
|
sourceMap.addSourceMap(map, lineCount);
|
|
861
903
|
}
|
|
862
904
|
}
|
|
@@ -913,7 +955,6 @@ ${code}
|
|
|
913
955
|
if (!depCode) continue;
|
|
914
956
|
code += depCode + '\n';
|
|
915
957
|
if (sourceMap && map) {
|
|
916
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
917
958
|
sourceMap.addSourceMap(map, lineCount);
|
|
918
959
|
}
|
|
919
960
|
lineCount += lines + 1;
|
|
@@ -987,7 +1028,7 @@ ${code}
|
|
|
987
1028
|
referencedBundle &&
|
|
988
1029
|
referencedBundle.getMainEntry() === resolved &&
|
|
989
1030
|
referencedBundle.type === 'js' &&
|
|
990
|
-
!this.
|
|
1031
|
+
!this.isAssetReferencedInBundle(referencedBundle, resolved)
|
|
991
1032
|
) {
|
|
992
1033
|
this.addExternal(dep, replacements, referencedBundle);
|
|
993
1034
|
this.externalAssets.add(resolved);
|
|
@@ -1786,7 +1827,7 @@ ${code}
|
|
|
1786
1827
|
return (
|
|
1787
1828
|
asset.sideEffects === false &&
|
|
1788
1829
|
nullthrows(this.bundleGraph.getUsedSymbols(asset)).size == 0 &&
|
|
1789
|
-
!this.
|
|
1830
|
+
!this.isAssetReferencedInBundle(this.bundle, asset)
|
|
1790
1831
|
);
|
|
1791
1832
|
}
|
|
1792
1833
|
|
package/src/index.ts
CHANGED
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {BundleGraph, Dependency, NamedBundle} from '@atlaspack/types';
|
|
2
|
-
import type SourceMap from '@
|
|
2
|
+
import type SourceMap from '@atlaspack/source-map';
|
|
3
3
|
import nullthrows from 'nullthrows';
|
|
4
4
|
|
|
5
5
|
// This replaces __parcel__require__ references left by the transformer with
|