@atlaspack/packager-js 2.25.11-dev-fix-sourcemaps-50acc1acf.0 → 2.25.11
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 +12 -0
- package/dist/ScopeHoistingPackager.js +4 -76
- package/lib/ScopeHoistingPackager.js +4 -82
- package/lib/types/ScopeHoistingPackager.d.ts +0 -29
- package/package.json +10 -13
- package/src/ScopeHoistingPackager.ts +5 -86
- package/tsconfig.tsbuildinfo +1 -1
- package/LICENSE +0 -201
- package/test/appendHoistedValues.test.ts +0 -94
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaspack/packager-js
|
|
2
2
|
|
|
3
|
+
## 2.25.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`c97de81`](https://github.com/atlassian-labs/atlaspack/commit/c97de81b0b4b866bef4396e9131f37ffd273258d)]:
|
|
8
|
+
- @atlaspack/rust@3.30.0
|
|
9
|
+
- @atlaspack/logger@2.14.56
|
|
10
|
+
- @atlaspack/source-map@3.3.8
|
|
11
|
+
- @atlaspack/utils@3.4.6
|
|
12
|
+
- @atlaspack/types@2.15.54
|
|
13
|
+
- @atlaspack/plugin@2.14.64
|
|
14
|
+
|
|
3
15
|
## 2.25.10
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -37,7 +37,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.ScopeHoistingPackager = void 0;
|
|
40
|
-
exports.appendHoistedValues = appendHoistedValues;
|
|
41
40
|
const utils_1 = require("@atlaspack/utils");
|
|
42
41
|
const source_map_1 = __importDefault(require("@atlaspack/source-map"));
|
|
43
42
|
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
@@ -58,25 +57,6 @@ const utils_2 = require("./utils");
|
|
|
58
57
|
const REPLACEMENT_RE_CONDITIONAL = /\n|import\s+"([0-9a-f]{16,20}:.+?)";|(?:\$[0-9a-f]{16,20}\$exports)|(?:\$[0-9a-f]{16,20}\$(?:import|importAsync|require|importCond)\$[0-9a-f]+(?:\$[0-9a-f]+)?)/g;
|
|
59
58
|
const REPLACEMENT_RE = /\n|import\s+"([0-9a-f]{16,20}:.+?)";|(?:\$[0-9a-f]{16,20}\$exports)|(?:\$[0-9a-f]{16,20}\$(?:import|importAsync|require)\$[0-9a-f]+(?:\$[0-9a-f]+)?)/g;
|
|
60
59
|
const BUILTINS = Object.keys(globals_1.default.builtin);
|
|
61
|
-
/**
|
|
62
|
-
* Joins filtered hoisted parcelRequire values into the bundle output,
|
|
63
|
-
* returning the text to append and the number of newlines it adds.
|
|
64
|
-
*
|
|
65
|
-
* Returns `{text: '', lineCount: 0}` when there are no values, to avoid
|
|
66
|
-
* emitting a stray leading `\n` (which would over-count lineCount and
|
|
67
|
-
* desynchronise the bundle source-map offset bookkeeping).
|
|
68
|
-
*
|
|
69
|
-
* Exported for direct unit testing of the lineCount bookkeeping.
|
|
70
|
-
*/
|
|
71
|
-
function appendHoistedValues(values) {
|
|
72
|
-
if (values.length === 0) {
|
|
73
|
-
return { text: '', lineCount: 0 };
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
text: '\n' + values.join('\n'),
|
|
77
|
-
lineCount: values.length,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
60
|
const GLOBALS_BY_CONTEXT = {
|
|
81
61
|
browser: new Set([...BUILTINS, ...Object.keys(globals_1.default.browser)]),
|
|
82
62
|
'web-worker': new Set([...BUILTINS, ...Object.keys(globals_1.default.worker)]),
|
|
@@ -156,14 +136,10 @@ class ScopeHoistingPackager {
|
|
|
156
136
|
this.seenHoistedRequires.clear();
|
|
157
137
|
let [content, map, lines] = this.visitAsset(asset);
|
|
158
138
|
if (sourceMap && map) {
|
|
159
|
-
this.addAssetBoundaryMarker(sourceMap, asset, lineCount);
|
|
160
139
|
sourceMap.addSourceMap(map, lineCount);
|
|
161
140
|
}
|
|
162
141
|
else if (this.bundle.env.sourceMap) {
|
|
163
142
|
sourceMap = map;
|
|
164
|
-
if (sourceMap) {
|
|
165
|
-
this.addAssetBoundaryMarker(sourceMap, asset, lineCount);
|
|
166
|
-
}
|
|
167
143
|
}
|
|
168
144
|
res += content + '\n';
|
|
169
145
|
lineCount += lines + 1;
|
|
@@ -264,7 +240,6 @@ class ScopeHoistingPackager {
|
|
|
264
240
|
}
|
|
265
241
|
res += (0, utils_2.replaceScriptDependencies)(this.bundleGraph, this.bundle, code, map, this.parcelRequireName);
|
|
266
242
|
if (sourceMap && map) {
|
|
267
|
-
this.addAssetBoundaryMarker(sourceMap, mainEntry, lineCount);
|
|
268
243
|
// @ts-expect-error TS2339 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
269
244
|
sourceMap.addSourceMap(map, lineCount);
|
|
270
245
|
}
|
|
@@ -541,30 +516,6 @@ class ScopeHoistingPackager {
|
|
|
541
516
|
let { code, map } = (0, nullthrows_1.default)(this.assetOutputs.get(asset));
|
|
542
517
|
return this.buildAsset(asset, code, map);
|
|
543
518
|
}
|
|
544
|
-
/**
|
|
545
|
-
* Insert a single "boundary marker" mapping at the start of the line where
|
|
546
|
-
* `asset`'s source map is about to be appended. Without this marker, source
|
|
547
|
-
* map consumers (and downstream optimizers such as swc that need to compose
|
|
548
|
-
* via nearest-neighbour lookups) will attribute the columns at the start of
|
|
549
|
-
* this asset's region to the *previous* asset's last mapping, because there
|
|
550
|
-
* is no mapping anchoring the start of the new asset. This is especially
|
|
551
|
-
* visible for assets with sparse maps (e.g. codegen'd `.graphql.ts` files
|
|
552
|
-
* from Relay) whose first mapping may be hundreds of columns into the line.
|
|
553
|
-
*
|
|
554
|
-
* The marker points at `(asset.filePath, 1, 0)`. Any mapping the asset's
|
|
555
|
-
* own map provides at the same generated position will override this one
|
|
556
|
-
* (last-write-wins inside `parcel_sourcemap`).
|
|
557
|
-
*/
|
|
558
|
-
addAssetBoundaryMarker(sourceMap, asset, lineOffset) {
|
|
559
|
-
if (!sourceMap)
|
|
560
|
-
return;
|
|
561
|
-
let source = this.getAssetFilePath(asset);
|
|
562
|
-
sourceMap.addIndexedMapping({
|
|
563
|
-
generated: { line: lineOffset + 1, column: 0 },
|
|
564
|
-
original: { line: 1, column: 0 },
|
|
565
|
-
source,
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
519
|
getAssetFilePath(asset) {
|
|
569
520
|
return path_1.default.relative(this.options.projectRoot, asset.filePath);
|
|
570
521
|
}
|
|
@@ -574,13 +525,6 @@ class ScopeHoistingPackager {
|
|
|
574
525
|
let sourceMap = this.bundle.env.sourceMap && map
|
|
575
526
|
? new source_map_1.default(this.options.projectRoot, map)
|
|
576
527
|
: null;
|
|
577
|
-
// Anchor the start of this asset's region with a boundary marker so the
|
|
578
|
-
// first columns of the asset don't fall back to a previous asset's
|
|
579
|
-
// mapping during downstream source-map composition. See the
|
|
580
|
-
// addAssetBoundaryMarker JSDoc for the full rationale.
|
|
581
|
-
if (sourceMap) {
|
|
582
|
-
this.addAssetBoundaryMarker(sourceMap, asset, 0);
|
|
583
|
-
}
|
|
584
528
|
// If this asset is skipped, just add dependencies and not the asset's content.
|
|
585
529
|
if (this.shouldSkipAsset(asset)) {
|
|
586
530
|
let depCode = '';
|
|
@@ -614,7 +558,6 @@ class ScopeHoistingPackager {
|
|
|
614
558
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
615
559
|
depCode += code + '\n';
|
|
616
560
|
if (sourceMap && map) {
|
|
617
|
-
this.addAssetBoundaryMarker(sourceMap, resolved, lineCount);
|
|
618
561
|
sourceMap.addSourceMap(map, lineCount);
|
|
619
562
|
}
|
|
620
563
|
lineCount += lines + 1;
|
|
@@ -713,13 +656,7 @@ class ScopeHoistingPackager {
|
|
|
713
656
|
}
|
|
714
657
|
else {
|
|
715
658
|
if (shouldWrap) {
|
|
716
|
-
|
|
717
|
-
depContent.push([
|
|
718
|
-
visited[0],
|
|
719
|
-
visited[1],
|
|
720
|
-
visited[2],
|
|
721
|
-
resolved,
|
|
722
|
-
]);
|
|
659
|
+
depContent.push(this.visitAsset(resolved));
|
|
723
660
|
}
|
|
724
661
|
else {
|
|
725
662
|
let [depCode, depMap, depLines] = this.visitAsset(resolved);
|
|
@@ -743,7 +680,6 @@ class ScopeHoistingPackager {
|
|
|
743
680
|
sourceMap.offsetLines(lineCount + 1, lines);
|
|
744
681
|
}
|
|
745
682
|
if (map) {
|
|
746
|
-
this.addAssetBoundaryMarker(sourceMap, resolved, lineCount);
|
|
747
683
|
sourceMap.addSourceMap(map, lineCount);
|
|
748
684
|
}
|
|
749
685
|
}
|
|
@@ -783,14 +719,11 @@ ${code}
|
|
|
783
719
|
code = `/* ${this.getAssetFilePath(asset)} */\n` + code;
|
|
784
720
|
lineCount += 1;
|
|
785
721
|
}
|
|
786
|
-
for (let [depCode, map, lines
|
|
722
|
+
for (let [depCode, map, lines] of depContent) {
|
|
787
723
|
if (!depCode)
|
|
788
724
|
continue;
|
|
789
725
|
code += depCode + '\n';
|
|
790
726
|
if (sourceMap && map) {
|
|
791
|
-
if (depAsset) {
|
|
792
|
-
this.addAssetBoundaryMarker(sourceMap, depAsset, lineCount);
|
|
793
|
-
}
|
|
794
727
|
sourceMap.addSourceMap(map, lineCount);
|
|
795
728
|
}
|
|
796
729
|
lineCount += lines + 1;
|
|
@@ -1156,13 +1089,8 @@ ${code}
|
|
|
1156
1089
|
for (let val of hoistedValues) {
|
|
1157
1090
|
this.seenHoistedRequires.add(val);
|
|
1158
1091
|
}
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
// emit a stray blank line and the line count would over-count by
|
|
1162
|
-
// `hoisted.size` (which includes the now-filtered entries).
|
|
1163
|
-
let appended = appendHoistedValues(hoistedValues);
|
|
1164
|
-
res += appended.text;
|
|
1165
|
-
lineCount += appended.lineCount;
|
|
1092
|
+
res += '\n' + hoistedValues.join('\n');
|
|
1093
|
+
lineCount += hoisted.size;
|
|
1166
1094
|
}
|
|
1167
1095
|
else {
|
|
1168
1096
|
res += '\n' + [...hoisted.values()].join('\n');
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ScopeHoistingPackager = void 0;
|
|
7
|
-
exports.appendHoistedValues = appendHoistedValues;
|
|
8
7
|
function _utils() {
|
|
9
8
|
const data = require("@atlaspack/utils");
|
|
10
9
|
_utils = function () {
|
|
@@ -81,29 +80,6 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
81
80
|
const REPLACEMENT_RE_CONDITIONAL = /\n|import\s+"([0-9a-f]{16,20}:.+?)";|(?:\$[0-9a-f]{16,20}\$exports)|(?:\$[0-9a-f]{16,20}\$(?:import|importAsync|require|importCond)\$[0-9a-f]+(?:\$[0-9a-f]+)?)/g;
|
|
82
81
|
const REPLACEMENT_RE = /\n|import\s+"([0-9a-f]{16,20}:.+?)";|(?:\$[0-9a-f]{16,20}\$exports)|(?:\$[0-9a-f]{16,20}\$(?:import|importAsync|require)\$[0-9a-f]+(?:\$[0-9a-f]+)?)/g;
|
|
83
82
|
const BUILTINS = Object.keys(_globals().default.builtin);
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Joins filtered hoisted parcelRequire values into the bundle output,
|
|
87
|
-
* returning the text to append and the number of newlines it adds.
|
|
88
|
-
*
|
|
89
|
-
* Returns `{text: '', lineCount: 0}` when there are no values, to avoid
|
|
90
|
-
* emitting a stray leading `\n` (which would over-count lineCount and
|
|
91
|
-
* desynchronise the bundle source-map offset bookkeeping).
|
|
92
|
-
*
|
|
93
|
-
* Exported for direct unit testing of the lineCount bookkeeping.
|
|
94
|
-
*/
|
|
95
|
-
function appendHoistedValues(values) {
|
|
96
|
-
if (values.length === 0) {
|
|
97
|
-
return {
|
|
98
|
-
text: '',
|
|
99
|
-
lineCount: 0
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
text: '\n' + values.join('\n'),
|
|
104
|
-
lineCount: values.length
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
83
|
const GLOBALS_BY_CONTEXT = {
|
|
108
84
|
browser: new Set([...BUILTINS, ...Object.keys(_globals().default.browser)]),
|
|
109
85
|
'web-worker': new Set([...BUILTINS, ...Object.keys(_globals().default.worker)]),
|
|
@@ -171,13 +147,9 @@ class ScopeHoistingPackager {
|
|
|
171
147
|
this.seenHoistedRequires.clear();
|
|
172
148
|
let [content, map, lines] = this.visitAsset(asset);
|
|
173
149
|
if (sourceMap && map) {
|
|
174
|
-
this.addAssetBoundaryMarker(sourceMap, asset, lineCount);
|
|
175
150
|
sourceMap.addSourceMap(map, lineCount);
|
|
176
151
|
} else if (this.bundle.env.sourceMap) {
|
|
177
152
|
sourceMap = map;
|
|
178
|
-
if (sourceMap) {
|
|
179
|
-
this.addAssetBoundaryMarker(sourceMap, asset, lineCount);
|
|
180
|
-
}
|
|
181
153
|
}
|
|
182
154
|
res += content + '\n';
|
|
183
155
|
lineCount += lines + 1;
|
|
@@ -285,7 +257,6 @@ class ScopeHoistingPackager {
|
|
|
285
257
|
}
|
|
286
258
|
res += (0, _utils2.replaceScriptDependencies)(this.bundleGraph, this.bundle, code, map, this.parcelRequireName);
|
|
287
259
|
if (sourceMap && map) {
|
|
288
|
-
this.addAssetBoundaryMarker(sourceMap, mainEntry, lineCount);
|
|
289
260
|
// @ts-expect-error TS2339 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
290
261
|
sourceMap.addSourceMap(map, lineCount);
|
|
291
262
|
}
|
|
@@ -542,36 +513,6 @@ class ScopeHoistingPackager {
|
|
|
542
513
|
} = (0, _nullthrows().default)(this.assetOutputs.get(asset));
|
|
543
514
|
return this.buildAsset(asset, code, map);
|
|
544
515
|
}
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* Insert a single "boundary marker" mapping at the start of the line where
|
|
548
|
-
* `asset`'s source map is about to be appended. Without this marker, source
|
|
549
|
-
* map consumers (and downstream optimizers such as swc that need to compose
|
|
550
|
-
* via nearest-neighbour lookups) will attribute the columns at the start of
|
|
551
|
-
* this asset's region to the *previous* asset's last mapping, because there
|
|
552
|
-
* is no mapping anchoring the start of the new asset. This is especially
|
|
553
|
-
* visible for assets with sparse maps (e.g. codegen'd `.graphql.ts` files
|
|
554
|
-
* from Relay) whose first mapping may be hundreds of columns into the line.
|
|
555
|
-
*
|
|
556
|
-
* The marker points at `(asset.filePath, 1, 0)`. Any mapping the asset's
|
|
557
|
-
* own map provides at the same generated position will override this one
|
|
558
|
-
* (last-write-wins inside `parcel_sourcemap`).
|
|
559
|
-
*/
|
|
560
|
-
addAssetBoundaryMarker(sourceMap, asset, lineOffset) {
|
|
561
|
-
if (!sourceMap) return;
|
|
562
|
-
let source = this.getAssetFilePath(asset);
|
|
563
|
-
sourceMap.addIndexedMapping({
|
|
564
|
-
generated: {
|
|
565
|
-
line: lineOffset + 1,
|
|
566
|
-
column: 0
|
|
567
|
-
},
|
|
568
|
-
original: {
|
|
569
|
-
line: 1,
|
|
570
|
-
column: 0
|
|
571
|
-
},
|
|
572
|
-
source
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
516
|
getAssetFilePath(asset) {
|
|
576
517
|
return _path().default.relative(this.options.projectRoot, asset.filePath);
|
|
577
518
|
}
|
|
@@ -579,13 +520,6 @@ class ScopeHoistingPackager {
|
|
|
579
520
|
let shouldWrap = this.wrappedAssets.has(asset);
|
|
580
521
|
let deps = this.bundleGraph.getDependencies(asset);
|
|
581
522
|
let sourceMap = this.bundle.env.sourceMap && map ? new (_sourceMap2().default)(this.options.projectRoot, map) : null;
|
|
582
|
-
// Anchor the start of this asset's region with a boundary marker so the
|
|
583
|
-
// first columns of the asset don't fall back to a previous asset's
|
|
584
|
-
// mapping during downstream source-map composition. See the
|
|
585
|
-
// addAssetBoundaryMarker JSDoc for the full rationale.
|
|
586
|
-
if (sourceMap) {
|
|
587
|
-
this.addAssetBoundaryMarker(sourceMap, asset, 0);
|
|
588
|
-
}
|
|
589
523
|
|
|
590
524
|
// If this asset is skipped, just add dependencies and not the asset's content.
|
|
591
525
|
if (this.shouldSkipAsset(asset)) {
|
|
@@ -619,7 +553,6 @@ class ScopeHoistingPackager {
|
|
|
619
553
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
620
554
|
depCode += code + '\n';
|
|
621
555
|
if (sourceMap && map) {
|
|
622
|
-
this.addAssetBoundaryMarker(sourceMap, resolved, lineCount);
|
|
623
556
|
sourceMap.addSourceMap(map, lineCount);
|
|
624
557
|
}
|
|
625
558
|
lineCount += lines + 1;
|
|
@@ -714,8 +647,7 @@ class ScopeHoistingPackager {
|
|
|
714
647
|
}
|
|
715
648
|
} else {
|
|
716
649
|
if (shouldWrap) {
|
|
717
|
-
|
|
718
|
-
depContent.push([visited[0], visited[1], visited[2], resolved]);
|
|
650
|
+
depContent.push(this.visitAsset(resolved));
|
|
719
651
|
} else {
|
|
720
652
|
let [depCode, depMap, depLines] = this.visitAsset(resolved);
|
|
721
653
|
res = depCode + '\n' + res;
|
|
@@ -739,7 +671,6 @@ class ScopeHoistingPackager {
|
|
|
739
671
|
sourceMap.offsetLines(lineCount + 1, lines);
|
|
740
672
|
}
|
|
741
673
|
if (map) {
|
|
742
|
-
this.addAssetBoundaryMarker(sourceMap, resolved, lineCount);
|
|
743
674
|
sourceMap.addSourceMap(map, lineCount);
|
|
744
675
|
}
|
|
745
676
|
}
|
|
@@ -781,13 +712,10 @@ ${code}
|
|
|
781
712
|
code = `/* ${this.getAssetFilePath(asset)} */\n` + code;
|
|
782
713
|
lineCount += 1;
|
|
783
714
|
}
|
|
784
|
-
for (let [depCode, map, lines
|
|
715
|
+
for (let [depCode, map, lines] of depContent) {
|
|
785
716
|
if (!depCode) continue;
|
|
786
717
|
code += depCode + '\n';
|
|
787
718
|
if (sourceMap && map) {
|
|
788
|
-
if (depAsset) {
|
|
789
|
-
this.addAssetBoundaryMarker(sourceMap, depAsset, lineCount);
|
|
790
|
-
}
|
|
791
719
|
sourceMap.addSourceMap(map, lineCount);
|
|
792
720
|
}
|
|
793
721
|
lineCount += lines + 1;
|
|
@@ -1106,14 +1034,8 @@ ${code}
|
|
|
1106
1034
|
for (let val of hoistedValues) {
|
|
1107
1035
|
this.seenHoistedRequires.add(val);
|
|
1108
1036
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
// actually have values to write. Otherwise `res += '\n' + ''` would
|
|
1112
|
-
// emit a stray blank line and the line count would over-count by
|
|
1113
|
-
// `hoisted.size` (which includes the now-filtered entries).
|
|
1114
|
-
let appended = appendHoistedValues(hoistedValues);
|
|
1115
|
-
res += appended.text;
|
|
1116
|
-
lineCount += appended.lineCount;
|
|
1037
|
+
res += '\n' + hoistedValues.join('\n');
|
|
1038
|
+
lineCount += hoisted.size;
|
|
1117
1039
|
} else {
|
|
1118
1040
|
res += '\n' + [...hoisted.values()].join('\n');
|
|
1119
1041
|
lineCount += hoisted.size;
|
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import type { Asset, BundleGraph, Dependency, PluginOptions, NamedBundle, PluginLogger } from '@atlaspack/types';
|
|
2
2
|
import SourceMap from '@atlaspack/source-map';
|
|
3
|
-
/**
|
|
4
|
-
* Joins filtered hoisted parcelRequire values into the bundle output,
|
|
5
|
-
* returning the text to append and the number of newlines it adds.
|
|
6
|
-
*
|
|
7
|
-
* Returns `{text: '', lineCount: 0}` when there are no values, to avoid
|
|
8
|
-
* emitting a stray leading `\n` (which would over-count lineCount and
|
|
9
|
-
* desynchronise the bundle source-map offset bookkeeping).
|
|
10
|
-
*
|
|
11
|
-
* Exported for direct unit testing of the lineCount bookkeeping.
|
|
12
|
-
*/
|
|
13
|
-
export declare function appendHoistedValues(values: ReadonlyArray<string>): {
|
|
14
|
-
text: string;
|
|
15
|
-
lineCount: number;
|
|
16
|
-
};
|
|
17
3
|
export interface OutputFormat {
|
|
18
4
|
buildBundlePrelude(): [string, number];
|
|
19
5
|
buildBundlePostlude(): [string, number];
|
|
@@ -70,21 +56,6 @@ export declare class ScopeHoistingPackager {
|
|
|
70
56
|
getTopLevelName(name: string): string;
|
|
71
57
|
getPropertyAccess(obj: string, property: string): string;
|
|
72
58
|
visitAsset(asset: Asset): [string, SourceMap | null | undefined, number];
|
|
73
|
-
/**
|
|
74
|
-
* Insert a single "boundary marker" mapping at the start of the line where
|
|
75
|
-
* `asset`'s source map is about to be appended. Without this marker, source
|
|
76
|
-
* map consumers (and downstream optimizers such as swc that need to compose
|
|
77
|
-
* via nearest-neighbour lookups) will attribute the columns at the start of
|
|
78
|
-
* this asset's region to the *previous* asset's last mapping, because there
|
|
79
|
-
* is no mapping anchoring the start of the new asset. This is especially
|
|
80
|
-
* visible for assets with sparse maps (e.g. codegen'd `.graphql.ts` files
|
|
81
|
-
* from Relay) whose first mapping may be hundreds of columns into the line.
|
|
82
|
-
*
|
|
83
|
-
* The marker points at `(asset.filePath, 1, 0)`. Any mapping the asset's
|
|
84
|
-
* own map provides at the same generated position will override this one
|
|
85
|
-
* (last-write-wins inside `parcel_sourcemap`).
|
|
86
|
-
*/
|
|
87
|
-
addAssetBoundaryMarker(sourceMap: SourceMap, asset: Asset, lineOffset: number): void;
|
|
88
59
|
getAssetFilePath(asset: Asset): string;
|
|
89
60
|
buildAsset(asset: Asset, code: string, map?: Buffer | null): [string, SourceMap | null | undefined, number];
|
|
90
61
|
buildReplacements(asset: Asset, deps: Array<Dependency>): [Map<string, Array<Dependency>>, Map<string, string>];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-js",
|
|
3
|
-
"version": "2.25.11
|
|
3
|
+
"version": "2.25.11",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,23 +16,20 @@
|
|
|
16
16
|
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/diagnostic": "2.14.
|
|
20
|
-
"@atlaspack/feature-flags": "2.31.
|
|
21
|
-
"@atlaspack/logger": "2.14.56
|
|
22
|
-
"@atlaspack/plugin": "2.14.64
|
|
23
|
-
"@atlaspack/rust": "3.
|
|
24
|
-
"@atlaspack/source-map": "3.3.8
|
|
25
|
-
"@atlaspack/types": "2.15.54
|
|
26
|
-
"@atlaspack/utils": "3.4.6
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.4",
|
|
20
|
+
"@atlaspack/feature-flags": "2.31.3",
|
|
21
|
+
"@atlaspack/logger": "2.14.56",
|
|
22
|
+
"@atlaspack/plugin": "2.14.64",
|
|
23
|
+
"@atlaspack/rust": "3.30.0",
|
|
24
|
+
"@atlaspack/source-map": "3.3.8",
|
|
25
|
+
"@atlaspack/types": "2.15.54",
|
|
26
|
+
"@atlaspack/utils": "3.4.6",
|
|
27
27
|
"globals": "^15.15.0",
|
|
28
28
|
"nullthrows": "^1.1.1",
|
|
29
29
|
"outdent": "^0.7.1"
|
|
30
30
|
},
|
|
31
31
|
"type": "commonjs",
|
|
32
32
|
"scripts": {
|
|
33
|
-
"test": "mocha",
|
|
34
|
-
"test-ci": "mocha",
|
|
35
33
|
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
36
|
-
}
|
|
37
|
-
"gitHead": "50acc1acf31d5c8415a8154841a8ed09264e665a"
|
|
34
|
+
}
|
|
38
35
|
}
|
|
@@ -53,29 +53,6 @@ const REPLACEMENT_RE =
|
|
|
53
53
|
/\n|import\s+"([0-9a-f]{16,20}:.+?)";|(?:\$[0-9a-f]{16,20}\$exports)|(?:\$[0-9a-f]{16,20}\$(?:import|importAsync|require)\$[0-9a-f]+(?:\$[0-9a-f]+)?)/g;
|
|
54
54
|
|
|
55
55
|
const BUILTINS = Object.keys(globals.builtin);
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Joins filtered hoisted parcelRequire values into the bundle output,
|
|
59
|
-
* returning the text to append and the number of newlines it adds.
|
|
60
|
-
*
|
|
61
|
-
* Returns `{text: '', lineCount: 0}` when there are no values, to avoid
|
|
62
|
-
* emitting a stray leading `\n` (which would over-count lineCount and
|
|
63
|
-
* desynchronise the bundle source-map offset bookkeeping).
|
|
64
|
-
*
|
|
65
|
-
* Exported for direct unit testing of the lineCount bookkeeping.
|
|
66
|
-
*/
|
|
67
|
-
export function appendHoistedValues(values: ReadonlyArray<string>): {
|
|
68
|
-
text: string;
|
|
69
|
-
lineCount: number;
|
|
70
|
-
} {
|
|
71
|
-
if (values.length === 0) {
|
|
72
|
-
return {text: '', lineCount: 0};
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
text: '\n' + values.join('\n'),
|
|
76
|
-
lineCount: values.length,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
56
|
const GLOBALS_BY_CONTEXT = {
|
|
80
57
|
browser: new Set([...BUILTINS, ...Object.keys(globals.browser)]),
|
|
81
58
|
'web-worker': new Set([...BUILTINS, ...Object.keys(globals.worker)]),
|
|
@@ -214,13 +191,9 @@ export class ScopeHoistingPackager {
|
|
|
214
191
|
let [content, map, lines] = this.visitAsset(asset);
|
|
215
192
|
|
|
216
193
|
if (sourceMap && map) {
|
|
217
|
-
this.addAssetBoundaryMarker(sourceMap, asset, lineCount);
|
|
218
194
|
sourceMap.addSourceMap(map, lineCount);
|
|
219
195
|
} else if (this.bundle.env.sourceMap) {
|
|
220
196
|
sourceMap = map;
|
|
221
|
-
if (sourceMap) {
|
|
222
|
-
this.addAssetBoundaryMarker(sourceMap, asset, lineCount);
|
|
223
|
-
}
|
|
224
197
|
}
|
|
225
198
|
|
|
226
199
|
res += content + '\n';
|
|
@@ -361,7 +334,6 @@ export class ScopeHoistingPackager {
|
|
|
361
334
|
this.parcelRequireName,
|
|
362
335
|
);
|
|
363
336
|
if (sourceMap && map) {
|
|
364
|
-
this.addAssetBoundaryMarker(sourceMap, mainEntry, lineCount);
|
|
365
337
|
// @ts-expect-error TS2339 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
366
338
|
sourceMap.addSourceMap(map, lineCount);
|
|
367
339
|
}
|
|
@@ -724,34 +696,6 @@ export class ScopeHoistingPackager {
|
|
|
724
696
|
return this.buildAsset(asset, code, map);
|
|
725
697
|
}
|
|
726
698
|
|
|
727
|
-
/**
|
|
728
|
-
* Insert a single "boundary marker" mapping at the start of the line where
|
|
729
|
-
* `asset`'s source map is about to be appended. Without this marker, source
|
|
730
|
-
* map consumers (and downstream optimizers such as swc that need to compose
|
|
731
|
-
* via nearest-neighbour lookups) will attribute the columns at the start of
|
|
732
|
-
* this asset's region to the *previous* asset's last mapping, because there
|
|
733
|
-
* is no mapping anchoring the start of the new asset. This is especially
|
|
734
|
-
* visible for assets with sparse maps (e.g. codegen'd `.graphql.ts` files
|
|
735
|
-
* from Relay) whose first mapping may be hundreds of columns into the line.
|
|
736
|
-
*
|
|
737
|
-
* The marker points at `(asset.filePath, 1, 0)`. Any mapping the asset's
|
|
738
|
-
* own map provides at the same generated position will override this one
|
|
739
|
-
* (last-write-wins inside `parcel_sourcemap`).
|
|
740
|
-
*/
|
|
741
|
-
addAssetBoundaryMarker(
|
|
742
|
-
sourceMap: SourceMap,
|
|
743
|
-
asset: Asset,
|
|
744
|
-
lineOffset: number,
|
|
745
|
-
): void {
|
|
746
|
-
if (!sourceMap) return;
|
|
747
|
-
let source = this.getAssetFilePath(asset);
|
|
748
|
-
sourceMap.addIndexedMapping({
|
|
749
|
-
generated: {line: lineOffset + 1, column: 0},
|
|
750
|
-
original: {line: 1, column: 0},
|
|
751
|
-
source,
|
|
752
|
-
});
|
|
753
|
-
}
|
|
754
|
-
|
|
755
699
|
getAssetFilePath(asset: Asset): string {
|
|
756
700
|
return path.relative(this.options.projectRoot, asset.filePath);
|
|
757
701
|
}
|
|
@@ -768,13 +712,6 @@ export class ScopeHoistingPackager {
|
|
|
768
712
|
this.bundle.env.sourceMap && map
|
|
769
713
|
? new SourceMap(this.options.projectRoot, map)
|
|
770
714
|
: null;
|
|
771
|
-
// Anchor the start of this asset's region with a boundary marker so the
|
|
772
|
-
// first columns of the asset don't fall back to a previous asset's
|
|
773
|
-
// mapping during downstream source-map composition. See the
|
|
774
|
-
// addAssetBoundaryMarker JSDoc for the full rationale.
|
|
775
|
-
if (sourceMap) {
|
|
776
|
-
this.addAssetBoundaryMarker(sourceMap, asset, 0);
|
|
777
|
-
}
|
|
778
715
|
|
|
779
716
|
// If this asset is skipped, just add dependencies and not the asset's content.
|
|
780
717
|
if (this.shouldSkipAsset(asset)) {
|
|
@@ -814,7 +751,6 @@ export class ScopeHoistingPackager {
|
|
|
814
751
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
815
752
|
depCode += code + '\n';
|
|
816
753
|
if (sourceMap && map) {
|
|
817
|
-
this.addAssetBoundaryMarker(sourceMap, resolved, lineCount);
|
|
818
754
|
sourceMap.addSourceMap(map, lineCount);
|
|
819
755
|
}
|
|
820
756
|
lineCount += lines + 1;
|
|
@@ -852,9 +788,7 @@ export class ScopeHoistingPackager {
|
|
|
852
788
|
code += append;
|
|
853
789
|
|
|
854
790
|
let lineCount = 0;
|
|
855
|
-
let depContent: Array<
|
|
856
|
-
[string, SourceMap | null | undefined, number, Asset?]
|
|
857
|
-
> = [];
|
|
791
|
+
let depContent: Array<[string, SourceMap | null | undefined, number]> = [];
|
|
858
792
|
if (depMap.size === 0 && replacements.size === 0) {
|
|
859
793
|
// If there are no dependencies or replacements, use a simple function to count the number of lines.
|
|
860
794
|
lineCount = countLines(code) - 1;
|
|
@@ -943,13 +877,7 @@ export class ScopeHoistingPackager {
|
|
|
943
877
|
}
|
|
944
878
|
} else {
|
|
945
879
|
if (shouldWrap) {
|
|
946
|
-
|
|
947
|
-
depContent.push([
|
|
948
|
-
visited[0],
|
|
949
|
-
visited[1],
|
|
950
|
-
visited[2],
|
|
951
|
-
resolved,
|
|
952
|
-
]);
|
|
880
|
+
depContent.push(this.visitAsset(resolved));
|
|
953
881
|
} else {
|
|
954
882
|
let [depCode, depMap, depLines] =
|
|
955
883
|
this.visitAsset(resolved);
|
|
@@ -978,7 +906,6 @@ export class ScopeHoistingPackager {
|
|
|
978
906
|
}
|
|
979
907
|
|
|
980
908
|
if (map) {
|
|
981
|
-
this.addAssetBoundaryMarker(sourceMap, resolved, lineCount);
|
|
982
909
|
sourceMap.addSourceMap(map, lineCount);
|
|
983
910
|
}
|
|
984
911
|
}
|
|
@@ -1032,13 +959,10 @@ ${code}
|
|
|
1032
959
|
lineCount += 1;
|
|
1033
960
|
}
|
|
1034
961
|
|
|
1035
|
-
for (let [depCode, map, lines
|
|
962
|
+
for (let [depCode, map, lines] of depContent) {
|
|
1036
963
|
if (!depCode) continue;
|
|
1037
964
|
code += depCode + '\n';
|
|
1038
965
|
if (sourceMap && map) {
|
|
1039
|
-
if (depAsset) {
|
|
1040
|
-
this.addAssetBoundaryMarker(sourceMap, depAsset, lineCount);
|
|
1041
|
-
}
|
|
1042
966
|
sourceMap.addSourceMap(map, lineCount);
|
|
1043
967
|
}
|
|
1044
968
|
lineCount += lines + 1;
|
|
@@ -1529,13 +1453,8 @@ ${code}
|
|
|
1529
1453
|
this.seenHoistedRequires.add(val);
|
|
1530
1454
|
}
|
|
1531
1455
|
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
// emit a stray blank line and the line count would over-count by
|
|
1535
|
-
// `hoisted.size` (which includes the now-filtered entries).
|
|
1536
|
-
let appended = appendHoistedValues(hoistedValues);
|
|
1537
|
-
res += appended.text;
|
|
1538
|
-
lineCount += appended.lineCount;
|
|
1456
|
+
res += '\n' + hoistedValues.join('\n');
|
|
1457
|
+
lineCount += hoisted.size;
|
|
1539
1458
|
} else {
|
|
1540
1459
|
res += '\n' + [...hoisted.values()].join('\n');
|
|
1541
1460
|
lineCount += hoisted.size;
|