@atlaspack/packager-js 2.23.8 → 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 +18 -0
- package/dist/DevPackager.js +1 -2
- package/dist/ScopeHoistingPackager.js +35 -8
- package/lib/DevPackager.js +1 -2
- package/lib/ScopeHoistingPackager.js +37 -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 +7 -7
- package/src/DevPackager.ts +1 -2
- package/src/ScopeHoistingPackager.ts +43 -8
- package/src/index.ts +1 -1
- package/src/utils.ts +1 -1
- package/tsconfig.json +3 -0
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
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
|
+
|
|
3
21
|
## 2.23.8
|
|
4
22
|
|
|
5
23
|
### 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')) {
|
|
@@ -529,7 +559,6 @@ class ScopeHoistingPackager {
|
|
|
529
559
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
530
560
|
depCode += code + '\n';
|
|
531
561
|
if (sourceMap && map) {
|
|
532
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
533
562
|
sourceMap.addSourceMap(map, lineCount);
|
|
534
563
|
}
|
|
535
564
|
lineCount += lines + 1;
|
|
@@ -652,7 +681,6 @@ class ScopeHoistingPackager {
|
|
|
652
681
|
sourceMap.offsetLines(lineCount + 1, lines);
|
|
653
682
|
}
|
|
654
683
|
if (map) {
|
|
655
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
656
684
|
sourceMap.addSourceMap(map, lineCount);
|
|
657
685
|
}
|
|
658
686
|
}
|
|
@@ -696,7 +724,6 @@ ${code}
|
|
|
696
724
|
continue;
|
|
697
725
|
code += depCode + '\n';
|
|
698
726
|
if (sourceMap && map) {
|
|
699
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
700
727
|
sourceMap.addSourceMap(map, lineCount);
|
|
701
728
|
}
|
|
702
729
|
lineCount += lines + 1;
|
|
@@ -742,7 +769,7 @@ ${code}
|
|
|
742
769
|
if (referencedBundle &&
|
|
743
770
|
referencedBundle.getMainEntry() === resolved &&
|
|
744
771
|
referencedBundle.type === 'js' &&
|
|
745
|
-
!this.
|
|
772
|
+
!this.isAssetReferencedInBundle(referencedBundle, resolved)) {
|
|
746
773
|
this.addExternal(dep, replacements, referencedBundle);
|
|
747
774
|
this.externalAssets.add(resolved);
|
|
748
775
|
continue;
|
|
@@ -1348,7 +1375,7 @@ ${code}
|
|
|
1348
1375
|
}
|
|
1349
1376
|
return (asset.sideEffects === false &&
|
|
1350
1377
|
(0, nullthrows_1.default)(this.bundleGraph.getUsedSymbols(asset)).size == 0 &&
|
|
1351
|
-
!this.
|
|
1378
|
+
!this.isAssetReferencedInBundle(this.bundle, asset));
|
|
1352
1379
|
}
|
|
1353
1380
|
isScriptEntry(asset) {
|
|
1354
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);
|
|
@@ -520,7 +552,6 @@ class ScopeHoistingPackager {
|
|
|
520
552
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
521
553
|
depCode += code + '\n';
|
|
522
554
|
if (sourceMap && map) {
|
|
523
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
524
555
|
sourceMap.addSourceMap(map, lineCount);
|
|
525
556
|
}
|
|
526
557
|
lineCount += lines + 1;
|
|
@@ -639,7 +670,6 @@ class ScopeHoistingPackager {
|
|
|
639
670
|
sourceMap.offsetLines(lineCount + 1, lines);
|
|
640
671
|
}
|
|
641
672
|
if (map) {
|
|
642
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
643
673
|
sourceMap.addSourceMap(map, lineCount);
|
|
644
674
|
}
|
|
645
675
|
}
|
|
@@ -684,7 +714,6 @@ ${code}
|
|
|
684
714
|
if (!depCode) continue;
|
|
685
715
|
code += depCode + '\n';
|
|
686
716
|
if (sourceMap && map) {
|
|
687
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
688
717
|
sourceMap.addSourceMap(map, lineCount);
|
|
689
718
|
}
|
|
690
719
|
lineCount += lines + 1;
|
|
@@ -722,7 +751,7 @@ ${code}
|
|
|
722
751
|
// Handle imports from other bundles in libraries.
|
|
723
752
|
if (this.bundle.env.isLibrary && !this.bundle.hasAsset(resolved)) {
|
|
724
753
|
let referencedBundle = this.bundleGraph.getReferencedBundle(dep, this.bundle);
|
|
725
|
-
if (referencedBundle && referencedBundle.getMainEntry() === resolved && referencedBundle.type === 'js' && !this.
|
|
754
|
+
if (referencedBundle && referencedBundle.getMainEntry() === resolved && referencedBundle.type === 'js' && !this.isAssetReferencedInBundle(referencedBundle, resolved)) {
|
|
726
755
|
this.addExternal(dep, replacements, referencedBundle);
|
|
727
756
|
this.externalAssets.add(resolved);
|
|
728
757
|
continue;
|
|
@@ -1258,7 +1287,7 @@ ${code}
|
|
|
1258
1287
|
if (this.isScriptEntry(asset)) {
|
|
1259
1288
|
return true;
|
|
1260
1289
|
}
|
|
1261
|
-
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);
|
|
1262
1291
|
}
|
|
1263
1292
|
isScriptEntry(asset) {
|
|
1264
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"
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@atlaspack/diagnostic": "2.14.4",
|
|
20
|
-
"@atlaspack/feature-flags": "2.
|
|
21
|
-
"@atlaspack/plugin": "2.14.
|
|
22
|
-
"@atlaspack/rust": "3.
|
|
23
|
-
"@
|
|
24
|
-
"@atlaspack/types": "2.15.
|
|
25
|
-
"@atlaspack/utils": "3.
|
|
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"
|
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')
|
|
@@ -706,7 +744,6 @@ export class ScopeHoistingPackager {
|
|
|
706
744
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
707
745
|
depCode += code + '\n';
|
|
708
746
|
if (sourceMap && map) {
|
|
709
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
710
747
|
sourceMap.addSourceMap(map, lineCount);
|
|
711
748
|
}
|
|
712
749
|
lineCount += lines + 1;
|
|
@@ -862,7 +899,6 @@ export class ScopeHoistingPackager {
|
|
|
862
899
|
}
|
|
863
900
|
|
|
864
901
|
if (map) {
|
|
865
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
866
902
|
sourceMap.addSourceMap(map, lineCount);
|
|
867
903
|
}
|
|
868
904
|
}
|
|
@@ -919,7 +955,6 @@ ${code}
|
|
|
919
955
|
if (!depCode) continue;
|
|
920
956
|
code += depCode + '\n';
|
|
921
957
|
if (sourceMap && map) {
|
|
922
|
-
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
923
958
|
sourceMap.addSourceMap(map, lineCount);
|
|
924
959
|
}
|
|
925
960
|
lineCount += lines + 1;
|
|
@@ -993,7 +1028,7 @@ ${code}
|
|
|
993
1028
|
referencedBundle &&
|
|
994
1029
|
referencedBundle.getMainEntry() === resolved &&
|
|
995
1030
|
referencedBundle.type === 'js' &&
|
|
996
|
-
!this.
|
|
1031
|
+
!this.isAssetReferencedInBundle(referencedBundle, resolved)
|
|
997
1032
|
) {
|
|
998
1033
|
this.addExternal(dep, replacements, referencedBundle);
|
|
999
1034
|
this.externalAssets.add(resolved);
|
|
@@ -1792,7 +1827,7 @@ ${code}
|
|
|
1792
1827
|
return (
|
|
1793
1828
|
asset.sideEffects === false &&
|
|
1794
1829
|
nullthrows(this.bundleGraph.getUsedSymbols(asset)).size == 0 &&
|
|
1795
|
-
!this.
|
|
1830
|
+
!this.isAssetReferencedInBundle(this.bundle, asset)
|
|
1796
1831
|
);
|
|
1797
1832
|
}
|
|
1798
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
|