@atlaspack/packager-js 2.18.3-typescript-bc4459c37.0 → 2.19.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 +26 -0
- package/lib/DevPackager.js +1 -8
- package/lib/ScopeHoistingPackager.js +24 -128
- package/lib/dev-prelude.js +6 -6
- package/lib/index.js +10 -4
- package/package.json +11 -16
- package/src/{CJSOutputFormat.ts → CJSOutputFormat.js} +1 -0
- package/src/{DevPackager.ts → DevPackager.js} +5 -18
- package/src/{ESMOutputFormat.ts → ESMOutputFormat.js} +3 -2
- package/src/{GlobalOutputFormat.ts → GlobalOutputFormat.js} +1 -0
- package/src/{ScopeHoistingPackager.ts → ScopeHoistingPackager.js} +46 -124
- package/src/dev-prelude.js +6 -6
- package/src/{helpers.ts → helpers.js} +2 -1
- package/src/{index.ts → index.js} +15 -13
- package/src/{utils.ts → utils.js} +2 -1
- package/LICENSE +0 -201
- package/lib/CJSOutputFormat.d.ts +0 -7
- package/lib/DevPackager.d.ts +0 -15
- package/lib/ESMOutputFormat.d.ts +0 -7
- package/lib/GlobalOutputFormat.d.ts +0 -7
- package/lib/ScopeHoistingPackager.d.ts +0 -65
- package/lib/helpers.d.ts +0 -11
- package/lib/index.d.ts +0 -3
- package/lib/utils.d.ts +0 -6
- package/tsconfig.json +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @atlaspack/packager-js
|
|
2
2
|
|
|
3
|
+
## 2.19.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#721](https://github.com/atlassian-labs/atlaspack/pull/721) [`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd) Thanks [@benjervis](https://github.com/benjervis)! - Add support for bundle merging based on `webpackChunkName` comments.
|
|
8
|
+
|
|
9
|
+
Adding a `webpackChunkName` comment to an import will allow the bundler to merge multiple imports into a single bundle.
|
|
10
|
+
|
|
11
|
+
e.g.:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import(/* webpackChunkName: "my-chunk" */ './my-module');
|
|
15
|
+
import(/* webpackChunkName: "my-chunk" */ './another-module');
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
This can be enabled with the feature flag `supportWebpackChunkName`.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
|
|
23
|
+
- @atlaspack/feature-flags@2.20.0
|
|
24
|
+
- @atlaspack/types@2.15.11
|
|
25
|
+
- @atlaspack/utils@2.17.3
|
|
26
|
+
- @atlaspack/plugin@2.14.21
|
|
27
|
+
|
|
3
28
|
## 2.18.2
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -110,6 +135,7 @@
|
|
|
110
135
|
### Patch Changes
|
|
111
136
|
|
|
112
137
|
- [#632](https://github.com/atlassian-labs/atlaspack/pull/632) [`10fbcfb`](https://github.com/atlassian-labs/atlaspack/commit/10fbcfbfa49c7a83da5d7c40983e36e87f524a75) Thanks [@marcins](https://github.com/marcins)! - Added a new feature flag `inlineConstOptimisationFix` which when enabled changes the behaviour for output of constant modules. This fixes two issues with constant modules:
|
|
138
|
+
|
|
113
139
|
- Previously constant modules, if they needed a namespace anywhere, would have a namespace everywhere, with this change they only have a namespace in the bundles where needed.
|
|
114
140
|
- Previously in the case of wrapped assets, a constant module dependnecy of that wrapped asset would be rendered after the module - which meant the minifier would not be able to inline the constants safely. With this flag all constant modules are rendered at the top of the bundle.
|
|
115
141
|
|
package/lib/DevPackager.js
CHANGED
|
@@ -98,7 +98,6 @@ class DevPackager {
|
|
|
98
98
|
// If this is the main entry of a script rather than a module, we need to hoist it
|
|
99
99
|
// outside the bundle wrapper function so that its variables are exposed as globals.
|
|
100
100
|
if (this.bundle.env.sourceType === 'script' && asset === this.bundle.getMainEntry()) {
|
|
101
|
-
// @ts-expect-error TS2322
|
|
102
101
|
script = results[i++];
|
|
103
102
|
return;
|
|
104
103
|
}
|
|
@@ -127,8 +126,6 @@ class DevPackager {
|
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
128
|
}
|
|
130
|
-
|
|
131
|
-
// @ts-expect-error TS2339
|
|
132
129
|
let {
|
|
133
130
|
code,
|
|
134
131
|
mapBuffer
|
|
@@ -173,16 +170,12 @@ class DevPackager {
|
|
|
173
170
|
// runtimes with a parcelRequire call.
|
|
174
171
|
if (this.bundle.env.sourceType === 'script' && script) {
|
|
175
172
|
let entryMap;
|
|
176
|
-
// @ts-expect-error TS2339
|
|
177
173
|
let mapBuffer = script.mapBuffer;
|
|
178
174
|
if (mapBuffer) {
|
|
179
175
|
entryMap = new (_sourceMap().default)(this.options.projectRoot, mapBuffer);
|
|
180
176
|
}
|
|
181
|
-
contents += (0, _utils2.replaceScriptDependencies)(this.bundleGraph, this.bundle,
|
|
182
|
-
// @ts-expect-error TS2339
|
|
183
|
-
script.code, entryMap, this.parcelRequireName);
|
|
177
|
+
contents += (0, _utils2.replaceScriptDependencies)(this.bundleGraph, this.bundle, script.code, entryMap, this.parcelRequireName);
|
|
184
178
|
if (this.bundle.env.sourceMap && entryMap) {
|
|
185
|
-
// @ts-expect-error TS2551
|
|
186
179
|
map.addSourceMap(entryMap, lineOffset);
|
|
187
180
|
}
|
|
188
181
|
}
|
|
@@ -77,6 +77,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
77
77
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
78
78
|
// General regex used to replace imports with the resolved code, references with resolutions,
|
|
79
79
|
// and count the number of newlines in the file for source maps.
|
|
80
|
+
//
|
|
80
81
|
// For conditional bundling the only difference in this regex is adding `importCond` where we have `importAsync` etc..
|
|
81
82
|
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
83
|
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;
|
|
@@ -96,8 +97,6 @@ const OUTPUT_FORMATS = {
|
|
|
96
97
|
global: _GlobalOutputFormat.GlobalOutputFormat
|
|
97
98
|
};
|
|
98
99
|
class ScopeHoistingPackager {
|
|
99
|
-
// @ts-expect-error TS2564
|
|
100
|
-
|
|
101
100
|
exportedSymbols = new Map();
|
|
102
101
|
externals = new Map();
|
|
103
102
|
topLevelNames = new Map();
|
|
@@ -141,11 +140,9 @@ class ScopeHoistingPackager {
|
|
|
141
140
|
}
|
|
142
141
|
let res = '';
|
|
143
142
|
let lineCount = 0;
|
|
144
|
-
// @ts-expect-error TS7034
|
|
145
143
|
let sourceMap = null;
|
|
146
144
|
let processAsset = asset => {
|
|
147
145
|
let [content, map, lines] = this.visitAsset(asset);
|
|
148
|
-
// @ts-expect-error TS7005
|
|
149
146
|
if (sourceMap && map) {
|
|
150
147
|
sourceMap.addSourceMap(map, lineCount);
|
|
151
148
|
} else if (this.bundle.env.sourceMap) {
|
|
@@ -184,17 +181,20 @@ class ScopeHoistingPackager {
|
|
|
184
181
|
let [prelude, preludeLines] = this.buildBundlePrelude();
|
|
185
182
|
res = prelude + res;
|
|
186
183
|
lineCount += preludeLines;
|
|
187
|
-
// @ts-expect-error TS2339
|
|
188
184
|
(_sourceMap = sourceMap) === null || _sourceMap === void 0 || _sourceMap.offsetLines(1, preludeLines);
|
|
189
185
|
let entries = this.bundle.getEntryAssets();
|
|
190
186
|
let mainEntry = this.bundle.getMainEntry();
|
|
191
187
|
if (this.isAsyncBundle) {
|
|
192
188
|
// In async bundles we don't want the main entry to execute until we require it
|
|
193
189
|
// as there might be dependencies in a sibling bundle that hasn't loaded yet.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
190
|
+
if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
|
|
191
|
+
entries = [];
|
|
192
|
+
} else {
|
|
193
|
+
entries = entries.filter(a => {
|
|
194
|
+
var _mainEntry;
|
|
195
|
+
return a.id !== ((_mainEntry = mainEntry) === null || _mainEntry === void 0 ? void 0 : _mainEntry.id);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
198
|
mainEntry = null;
|
|
199
199
|
}
|
|
200
200
|
let needsBundleQueue = this.shouldBundleQueue(this.bundle);
|
|
@@ -204,14 +204,9 @@ class ScopeHoistingPackager {
|
|
|
204
204
|
if (this.wrappedAssets.has(entry.id) && !this.isScriptEntry(entry)) {
|
|
205
205
|
var _entry$symbols$get;
|
|
206
206
|
let parcelRequire = `parcelRequire(${JSON.stringify(this.bundleGraph.getAssetPublicId(entry))});\n`;
|
|
207
|
-
|
|
208
|
-
// @ts-expect-error TS2345
|
|
209
207
|
let entryExports = (_entry$symbols$get = entry.symbols.get('*')) === null || _entry$symbols$get === void 0 ? void 0 : _entry$symbols$get.local;
|
|
210
|
-
if (entryExports && entry === mainEntry &&
|
|
211
|
-
// @ts-expect-error TS2345
|
|
212
|
-
this.exportedSymbols.has(entryExports)) {
|
|
208
|
+
if (entryExports && entry === mainEntry && this.exportedSymbols.has(entryExports)) {
|
|
213
209
|
(0, _assert().default)(!needsBundleQueue, 'Entry exports are not yet compaitble with async bundles');
|
|
214
|
-
// @ts-expect-error TS2731
|
|
215
210
|
res += `\nvar ${entryExports} = ${parcelRequire}`;
|
|
216
211
|
} else {
|
|
217
212
|
if (needsBundleQueue) {
|
|
@@ -243,7 +238,6 @@ class ScopeHoistingPackager {
|
|
|
243
238
|
}
|
|
244
239
|
res += (0, _utils2.replaceScriptDependencies)(this.bundleGraph, this.bundle, code, map, this.parcelRequireName);
|
|
245
240
|
if (sourceMap && map) {
|
|
246
|
-
// @ts-expect-error TS2339
|
|
247
241
|
sourceMap.addSourceMap(map, lineCount);
|
|
248
242
|
}
|
|
249
243
|
}
|
|
@@ -348,8 +342,6 @@ class ScopeHoistingPackager {
|
|
|
348
342
|
}, wrappedAssetRoot);
|
|
349
343
|
}
|
|
350
344
|
}
|
|
351
|
-
|
|
352
|
-
// @ts-expect-error TS2769
|
|
353
345
|
this.assetOutputs = new Map(await queue.run());
|
|
354
346
|
return {
|
|
355
347
|
wrapped,
|
|
@@ -374,7 +366,6 @@ class ScopeHoistingPackager {
|
|
|
374
366
|
// TODO: handle ESM exports of wrapped entry assets...
|
|
375
367
|
let entry = this.bundle.getMainEntry();
|
|
376
368
|
if (entry && !this.wrappedAssets.has(entry.id)) {
|
|
377
|
-
// @ts-expect-error TS2345
|
|
378
369
|
let hasNamespace = entry.symbols.hasExportSymbol('*');
|
|
379
370
|
for (let {
|
|
380
371
|
asset,
|
|
@@ -390,14 +381,11 @@ class ScopeHoistingPackager {
|
|
|
390
381
|
if (hasNamespace && this.isAsyncBundle && exportAs !== '*') {
|
|
391
382
|
continue;
|
|
392
383
|
}
|
|
393
|
-
let symbols = (_this$exportedSymbols = this.exportedSymbols.get(
|
|
394
|
-
// @ts-expect-error TS2345
|
|
395
|
-
symbol === '*' ? (0, _nullthrows().default)((_entry$symbols$get2 = entry.symbols.get('*')) === null || _entry$symbols$get2 === void 0 ? void 0 : _entry$symbols$get2.local) : symbol)) === null || _this$exportedSymbols === void 0 ? void 0 : _this$exportedSymbols.exportAs;
|
|
384
|
+
let symbols = (_this$exportedSymbols = this.exportedSymbols.get(symbol === '*' ? (0, _nullthrows().default)((_entry$symbols$get2 = entry.symbols.get('*')) === null || _entry$symbols$get2 === void 0 ? void 0 : _entry$symbols$get2.local) : symbol)) === null || _this$exportedSymbols === void 0 ? void 0 : _this$exportedSymbols.exportAs;
|
|
396
385
|
if (!symbols) {
|
|
397
386
|
symbols = [];
|
|
398
387
|
this.exportedSymbols.set(symbol, {
|
|
399
388
|
asset,
|
|
400
|
-
// @ts-expect-error TS2322
|
|
401
389
|
exportSymbol,
|
|
402
390
|
local: symbol,
|
|
403
391
|
exportAs: symbols
|
|
@@ -406,8 +394,6 @@ class ScopeHoistingPackager {
|
|
|
406
394
|
if (exportAs === '*') {
|
|
407
395
|
exportAs = 'default';
|
|
408
396
|
}
|
|
409
|
-
|
|
410
|
-
// @ts-expect-error TS2345
|
|
411
397
|
symbols.push(exportAs);
|
|
412
398
|
} else if (symbol === null) {
|
|
413
399
|
// TODO `meta.exportsIdentifier[exportSymbol]` should be exported
|
|
@@ -484,7 +470,6 @@ class ScopeHoistingPackager {
|
|
|
484
470
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
485
471
|
depCode += code + '\n';
|
|
486
472
|
if (sourceMap && map) {
|
|
487
|
-
// @ts-expect-error TS2551
|
|
488
473
|
sourceMap.addSourceMap(map, lineCount);
|
|
489
474
|
}
|
|
490
475
|
lineCount += lines + 1;
|
|
@@ -510,7 +495,6 @@ class ScopeHoistingPackager {
|
|
|
510
495
|
}
|
|
511
496
|
code += append;
|
|
512
497
|
let lineCount = 0;
|
|
513
|
-
// @ts-expect-error TS2552
|
|
514
498
|
let depContent = [];
|
|
515
499
|
if (depMap.size === 0 && replacements.size === 0) {
|
|
516
500
|
// If there are no dependencies or replacements, use a simple function to count the number of lines.
|
|
@@ -592,7 +576,6 @@ class ScopeHoistingPackager {
|
|
|
592
576
|
sourceMap.offsetLines(lineCount + 1, lines);
|
|
593
577
|
}
|
|
594
578
|
if (map) {
|
|
595
|
-
// @ts-expect-error TS2551
|
|
596
579
|
sourceMap.addSourceMap(map, lineCount);
|
|
597
580
|
}
|
|
598
581
|
}
|
|
@@ -637,7 +620,6 @@ ${code}
|
|
|
637
620
|
if (!depCode) continue;
|
|
638
621
|
code += depCode + '\n';
|
|
639
622
|
if (sourceMap && map) {
|
|
640
|
-
// @ts-expect-error TS2551
|
|
641
623
|
sourceMap.addSourceMap(map, lineCount);
|
|
642
624
|
}
|
|
643
625
|
lineCount += lines + 1;
|
|
@@ -684,12 +666,9 @@ ${code}
|
|
|
684
666
|
for (let [imported, {
|
|
685
667
|
local
|
|
686
668
|
}] of dep.symbols) {
|
|
687
|
-
// @ts-expect-error TS2367
|
|
688
669
|
if (local === '*') {
|
|
689
670
|
continue;
|
|
690
671
|
}
|
|
691
|
-
|
|
692
|
-
// @ts-expect-error TS2345
|
|
693
672
|
let symbol = this.getSymbolResolution(asset, resolved, imported, dep);
|
|
694
673
|
replacements.set(local,
|
|
695
674
|
// If this was an internalized async asset, wrap in a Promise.resolve.
|
|
@@ -711,7 +690,6 @@ ${code}
|
|
|
711
690
|
// which will be provided to us by the wrapper.
|
|
712
691
|
if (this.wrappedAssets.has(asset.id) || this.bundle.env.outputFormat === 'commonjs' && asset === this.bundle.getMainEntry()) {
|
|
713
692
|
var _asset$symbols$get;
|
|
714
|
-
// @ts-expect-error TS2345
|
|
715
693
|
let exportsName = ((_asset$symbols$get = asset.symbols.get('*')) === null || _asset$symbols$get === void 0 ? void 0 : _asset$symbols$get.local) || `$${assetId}$exports`;
|
|
716
694
|
replacements.set(exportsName, 'module.exports');
|
|
717
695
|
}
|
|
@@ -744,11 +722,8 @@ ${code}
|
|
|
744
722
|
local
|
|
745
723
|
}] of dep.symbols) {
|
|
746
724
|
// If already imported, just add the already renamed variable to the mapping.
|
|
747
|
-
// @ts-expect-error TS2345
|
|
748
725
|
let renamed = external.get(imported);
|
|
749
|
-
// @ts-expect-error TS2367
|
|
750
726
|
if (renamed && local !== '*' && replacements) {
|
|
751
|
-
// @ts-expect-error TS2345
|
|
752
727
|
replacements.set(local, renamed);
|
|
753
728
|
continue;
|
|
754
729
|
}
|
|
@@ -761,25 +736,16 @@ ${code}
|
|
|
761
736
|
if (referencedBundle) {
|
|
762
737
|
var _entry$symbols$get3;
|
|
763
738
|
let entry = (0, _nullthrows().default)(referencedBundle.getMainEntry());
|
|
764
|
-
|
|
765
|
-
renamed =
|
|
766
|
-
// @ts-expect-error TS2345
|
|
767
|
-
((_entry$symbols$get3 = entry.symbols.get('*')) === null || _entry$symbols$get3 === void 0 ? void 0 : _entry$symbols$get3.local) ?? `$${String(entry.meta.id)}$exports`;
|
|
739
|
+
renamed = ((_entry$symbols$get3 = entry.symbols.get('*')) === null || _entry$symbols$get3 === void 0 ? void 0 : _entry$symbols$get3.local) ?? `$${String(entry.meta.id)}$exports`;
|
|
768
740
|
} else {
|
|
769
741
|
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${specifier}`);
|
|
770
742
|
}
|
|
771
|
-
|
|
772
|
-
// @ts-expect-error TS2345
|
|
773
743
|
external.set('*', renamed);
|
|
774
744
|
}
|
|
775
|
-
|
|
776
|
-
// @ts-expect-error TS2367
|
|
777
745
|
if (local !== '*' && replacements) {
|
|
778
746
|
let replacement;
|
|
779
|
-
// @ts-expect-error TS2367
|
|
780
747
|
if (imported === '*') {
|
|
781
748
|
replacement = renamed;
|
|
782
|
-
// @ts-expect-error TS2367
|
|
783
749
|
} else if (imported === 'default') {
|
|
784
750
|
let needsDefaultInterop = true;
|
|
785
751
|
if (referencedBundle) {
|
|
@@ -793,41 +759,32 @@ ${code}
|
|
|
793
759
|
replacement = `${renamed}.default`;
|
|
794
760
|
}
|
|
795
761
|
} else {
|
|
796
|
-
// @ts-expect-error TS2345
|
|
797
762
|
replacement = this.getPropertyAccess(renamed, imported);
|
|
798
763
|
}
|
|
799
|
-
|
|
800
|
-
// @ts-expect-error TS2345
|
|
801
764
|
replacements.set(local, replacement);
|
|
802
765
|
}
|
|
803
766
|
} else {
|
|
804
767
|
let property;
|
|
805
768
|
if (referencedBundle) {
|
|
806
769
|
let entry = (0, _nullthrows().default)(referencedBundle.getMainEntry());
|
|
807
|
-
// @ts-expect-error TS2345
|
|
808
770
|
if (entry.symbols.hasExportSymbol('*')) {
|
|
809
771
|
// If importing * and the referenced module has a * export (e.g. CJS), use default instead.
|
|
810
772
|
// This mirrors the logic in buildExportedSymbols.
|
|
811
773
|
property = imported;
|
|
812
|
-
// @ts-expect-error TS2322
|
|
813
774
|
imported = (referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.env.outputFormat) === 'esmodule' ? 'default' : '*';
|
|
814
775
|
} else {
|
|
815
|
-
// @ts-expect-error TS2367
|
|
816
776
|
if (imported === '*') {
|
|
817
777
|
let exportedSymbols = this.bundleGraph.getExportedSymbols(entry);
|
|
818
|
-
// @ts-expect-error TS2367
|
|
819
778
|
if (local === '*') {
|
|
820
779
|
// Re-export all symbols.
|
|
821
780
|
for (let exported of exportedSymbols) {
|
|
822
781
|
if (exported.symbol) {
|
|
823
|
-
// @ts-expect-error TS2345
|
|
824
782
|
external.set(exported.exportSymbol, exported.symbol);
|
|
825
783
|
}
|
|
826
784
|
}
|
|
827
785
|
continue;
|
|
828
786
|
}
|
|
829
787
|
}
|
|
830
|
-
// @ts-expect-error TS2322
|
|
831
788
|
renamed = this.bundleGraph.getSymbolResolution(entry, imported, this.bundle).symbol;
|
|
832
789
|
}
|
|
833
790
|
}
|
|
@@ -836,37 +793,25 @@ ${code}
|
|
|
836
793
|
// are deduplicated. We have to prefix the imported name with the bundle id so that
|
|
837
794
|
// local variables do not shadow it.
|
|
838
795
|
if (!renamed) {
|
|
839
|
-
// @ts-expect-error TS2345
|
|
840
796
|
if (this.exportedSymbols.has(local)) {
|
|
841
|
-
// @ts-expect-error TS2322
|
|
842
797
|
renamed = local;
|
|
843
|
-
// @ts-expect-error TS2367
|
|
844
798
|
} else if (imported === 'default' || imported === '*') {
|
|
845
799
|
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${specifier}`);
|
|
846
800
|
} else {
|
|
847
|
-
renamed = this.getTopLevelName(
|
|
848
|
-
// @ts-expect-error TS2731
|
|
849
|
-
`$${this.bundle.publicId}$${imported}`);
|
|
801
|
+
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${imported}`);
|
|
850
802
|
}
|
|
851
803
|
}
|
|
852
|
-
|
|
853
|
-
// @ts-expect-error TS2345
|
|
854
804
|
external.set(imported, renamed);
|
|
855
|
-
// @ts-expect-error TS2367
|
|
856
805
|
if (local !== '*' && replacements) {
|
|
857
806
|
let replacement = renamed;
|
|
858
|
-
// @ts-expect-error TS2367
|
|
859
807
|
if (property === '*') {
|
|
860
808
|
replacement = renamed;
|
|
861
|
-
// @ts-expect-error TS2367
|
|
862
809
|
} else if (property === 'default') {
|
|
863
810
|
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
864
811
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
865
812
|
} else if (property) {
|
|
866
|
-
// @ts-expect-error TS2345
|
|
867
813
|
replacement = this.getPropertyAccess(renamed, property);
|
|
868
814
|
}
|
|
869
|
-
// @ts-expect-error TS2345
|
|
870
815
|
replacements.set(local, replacement);
|
|
871
816
|
}
|
|
872
817
|
}
|
|
@@ -888,7 +833,6 @@ ${code}
|
|
|
888
833
|
asset: resolvedAsset,
|
|
889
834
|
exportSymbol,
|
|
890
835
|
symbol
|
|
891
|
-
// @ts-expect-error TS2345
|
|
892
836
|
} = this.bundleGraph.getSymbolResolution(resolved, imported, this.bundle);
|
|
893
837
|
if (resolvedAsset.type !== 'js' || dep && this.bundleGraph.isDependencySkipped(dep)) {
|
|
894
838
|
// Graceful fallback for non-js imports or when trying to resolve a symbol
|
|
@@ -922,13 +866,7 @@ ${code}
|
|
|
922
866
|
|
|
923
867
|
// If this is an ESM default import of a CJS module with a `default` symbol,
|
|
924
868
|
// and no __esModule flag, we need to resolve to the namespace instead.
|
|
925
|
-
let isDefaultInterop = exportSymbol === 'default' && staticExports && !isWrapped && ((dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Import' || (dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Export') &&
|
|
926
|
-
// @ts-expect-error TS2345
|
|
927
|
-
resolvedAsset.symbols.hasExportSymbol('*') &&
|
|
928
|
-
// @ts-expect-error TS2345
|
|
929
|
-
resolvedAsset.symbols.hasExportSymbol('default') &&
|
|
930
|
-
// @ts-expect-error TS2345
|
|
931
|
-
!resolvedAsset.symbols.hasExportSymbol('__esModule');
|
|
869
|
+
let isDefaultInterop = exportSymbol === 'default' && staticExports && !isWrapped && ((dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Import' || (dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Export') && resolvedAsset.symbols.hasExportSymbol('*') && resolvedAsset.symbols.hasExportSymbol('default') && !resolvedAsset.symbols.hasExportSymbol('__esModule');
|
|
932
870
|
|
|
933
871
|
// Find the namespace object for the resolved module. If wrapped and this
|
|
934
872
|
// is an inline require (not top-level), use a parcelRequire call, otherwise
|
|
@@ -944,9 +882,7 @@ ${code}
|
|
|
944
882
|
obj = `$${publicId}`;
|
|
945
883
|
} else {
|
|
946
884
|
var _resolvedAsset$symbol;
|
|
947
|
-
// @ts-expect-error TS2345
|
|
948
885
|
obj = ((_resolvedAsset$symbol = resolvedAsset.symbols.get('*')) === null || _resolvedAsset$symbol === void 0 ? void 0 : _resolvedAsset$symbol.local) || `$${assetId}$exports`;
|
|
949
|
-
// @ts-expect-error TS2345
|
|
950
886
|
obj = (replacements === null || replacements === void 0 ? void 0 : replacements.get(obj)) || obj;
|
|
951
887
|
}
|
|
952
888
|
if (imported === '*' || exportSymbol === '*' || isDefaultInterop) {
|
|
@@ -955,7 +891,6 @@ ${code}
|
|
|
955
891
|
// Directly use module.exports for wrapped assets importing themselves.
|
|
956
892
|
return 'module.exports';
|
|
957
893
|
} else {
|
|
958
|
-
// @ts-expect-error TS2322
|
|
959
894
|
return obj;
|
|
960
895
|
}
|
|
961
896
|
} else if ((!staticExports || isWrapped || !symbol || isExternalCommonJS) && resolvedAsset !== parentAsset) {
|
|
@@ -964,20 +899,15 @@ ${code}
|
|
|
964
899
|
// than a direct reference. If importing default from a CJS module,
|
|
965
900
|
// use a helper to check the __esModule flag at runtime.
|
|
966
901
|
let kind = dep === null || dep === void 0 ? void 0 : dep.meta.kind;
|
|
967
|
-
if ((!dep || kind === 'Import' || kind === 'Export') && exportSymbol === 'default' &&
|
|
968
|
-
// @ts-expect-error TS2345
|
|
969
|
-
resolvedAsset.symbols.hasExportSymbol('*') && this.needsDefaultInterop(resolvedAsset)) {
|
|
902
|
+
if ((!dep || kind === 'Import' || kind === 'Export') && exportSymbol === 'default' && resolvedAsset.symbols.hasExportSymbol('*') && this.needsDefaultInterop(resolvedAsset)) {
|
|
970
903
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
971
|
-
// @ts-expect-error TS2731
|
|
972
904
|
return `(/*@__PURE__*/$parcel$interopDefault(${obj}))`;
|
|
973
905
|
} else {
|
|
974
|
-
// @ts-expect-error TS2345
|
|
975
906
|
return this.getPropertyAccess(obj, exportSymbol);
|
|
976
907
|
}
|
|
977
908
|
} else if (!symbol) {
|
|
978
909
|
(0, _assert().default)(false, 'Asset was skipped or not found.');
|
|
979
910
|
} else {
|
|
980
|
-
// @ts-expect-error TS2322
|
|
981
911
|
return (replacements === null || replacements === void 0 ? void 0 : replacements.get(symbol)) || symbol;
|
|
982
912
|
}
|
|
983
913
|
}
|
|
@@ -1017,32 +947,20 @@ ${code}
|
|
|
1017
947
|
// If the asset has a namespace export symbol, it is CommonJS.
|
|
1018
948
|
// If there's no __esModule flag, and default is a used symbol, we need
|
|
1019
949
|
// to insert an interop helper.
|
|
1020
|
-
let defaultInterop =
|
|
1021
|
-
// @ts-expect-error TS2345
|
|
1022
|
-
asset.symbols.hasExportSymbol('*') &&
|
|
1023
|
-
// @ts-expect-error TS2345
|
|
1024
|
-
usedSymbols.has('default') &&
|
|
1025
|
-
// @ts-expect-error TS2345
|
|
1026
|
-
!asset.symbols.hasExportSymbol('__esModule');
|
|
950
|
+
let defaultInterop = asset.symbols.hasExportSymbol('*') && usedSymbols.has('default') && !asset.symbols.hasExportSymbol('__esModule');
|
|
1027
951
|
let usedNamespace;
|
|
1028
952
|
if ((0, _featureFlags().getFeatureFlag)('inlineConstOptimisationFix') && asset.meta.isConstantModule) {
|
|
1029
953
|
// Only set usedNamespace if there is an incoming dependency in the current bundle that uses '*'
|
|
1030
|
-
usedNamespace = this.bundleGraph.getIncomingDependencies(asset).some(dep => this.bundle.hasDependency(dep) &&
|
|
1031
|
-
// @ts-expect-error TS2345
|
|
1032
|
-
(0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep)).has('*'));
|
|
954
|
+
usedNamespace = this.bundleGraph.getIncomingDependencies(asset).some(dep => this.bundle.hasDependency(dep) && (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep)).has('*'));
|
|
1033
955
|
} else {
|
|
1034
956
|
usedNamespace =
|
|
1035
957
|
// If the asset has * in its used symbols, we might need the exports namespace.
|
|
1036
958
|
// The one case where this isn't true is in ESM library entries, where the only
|
|
1037
959
|
// dependency on * is the entry dependency. In this case, we will use ESM exports
|
|
1038
960
|
// instead of the namespace object.
|
|
1039
|
-
|
|
1040
|
-
usedSymbols.has('*') && (this.bundle.env.outputFormat !== 'esmodule' || !this.bundle.env.isLibrary || asset !== this.bundle.getMainEntry() || this.bundleGraph.getIncomingDependencies(asset).some(dep => !dep.isEntry && this.bundle.hasDependency(dep) &&
|
|
1041
|
-
// @ts-expect-error TS2345
|
|
1042
|
-
(0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep)).has('*'))) ||
|
|
961
|
+
usedSymbols.has('*') && (this.bundle.env.outputFormat !== 'esmodule' || !this.bundle.env.isLibrary || asset !== this.bundle.getMainEntry() || this.bundleGraph.getIncomingDependencies(asset).some(dep => !dep.isEntry && this.bundle.hasDependency(dep) && (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep)).has('*'))) ||
|
|
1043
962
|
// If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
1044
963
|
// we fallback on the namespace object.
|
|
1045
|
-
// @ts-expect-error TS2345
|
|
1046
964
|
asset.symbols.hasExportSymbol('*') && [...usedSymbols].some(s => !asset.symbols.hasExportSymbol(s)) ||
|
|
1047
965
|
// If the exports has this asset's namespace (e.g. ESM output from CJS input),
|
|
1048
966
|
// include the namespace object for the default export.
|
|
@@ -1067,7 +985,6 @@ ${code}
|
|
|
1067
985
|
// Insert the __esModule interop flag for this module if it has a `default` export
|
|
1068
986
|
// and the namespace symbol is used.
|
|
1069
987
|
// TODO: only if required by CJS?
|
|
1070
|
-
// @ts-expect-error TS2345
|
|
1071
988
|
if (asset.symbols.hasExportSymbol('default') && usedSymbols.has('*')) {
|
|
1072
989
|
prepend += `\n$parcel$defineInteropFlag($${assetId}$exports);\n`;
|
|
1073
990
|
prependLineCount += 2;
|
|
@@ -1086,7 +1003,6 @@ ${code}
|
|
|
1086
1003
|
for (let [imported, {
|
|
1087
1004
|
local
|
|
1088
1005
|
}] of dep.symbols) {
|
|
1089
|
-
// @ts-expect-error TS2367
|
|
1090
1006
|
if (imported === '*' && local === '*') {
|
|
1091
1007
|
if (!resolved) {
|
|
1092
1008
|
// Re-exporting an external module. This should have already been handled in buildReplacements.
|
|
@@ -1099,29 +1015,20 @@ ${code}
|
|
|
1099
1015
|
// If the resolved asset has an exports object, use the $parcel$exportWildcard helper
|
|
1100
1016
|
// to re-export all symbols. Otherwise, if there's no namespace object available, add
|
|
1101
1017
|
// $parcel$export calls for each used symbol of the dependency.
|
|
1102
|
-
if (isWrapped || resolved.meta.staticExports === false ||
|
|
1103
|
-
// @ts-expect-error TS2345
|
|
1104
|
-
(0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(resolved)).has('*') ||
|
|
1018
|
+
if (isWrapped || resolved.meta.staticExports === false || (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(resolved)).has('*') ||
|
|
1105
1019
|
// an empty asset
|
|
1106
|
-
!resolved.meta.hasCJSExports &&
|
|
1107
|
-
// @ts-expect-error TS2345
|
|
1108
|
-
resolved.symbols.hasExportSymbol('*')) {
|
|
1020
|
+
!resolved.meta.hasCJSExports && resolved.symbols.hasExportSymbol('*')) {
|
|
1109
1021
|
let obj = this.getSymbolResolution(asset, resolved, '*', dep, replacements);
|
|
1110
1022
|
append += `$parcel$exportWildcard($${assetId}$exports, ${obj});\n`;
|
|
1111
1023
|
this.usedHelpers.add('$parcel$exportWildcard');
|
|
1112
1024
|
} else {
|
|
1113
1025
|
for (let symbol of (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep))) {
|
|
1114
|
-
if (
|
|
1115
|
-
// @ts-expect-error TS2367
|
|
1116
|
-
symbol === 'default' ||
|
|
1026
|
+
if (symbol === 'default' ||
|
|
1117
1027
|
// `export * as ...` does not include the default export
|
|
1118
|
-
// @ts-expect-error TS2367
|
|
1119
1028
|
symbol === '__esModule') {
|
|
1120
1029
|
continue;
|
|
1121
1030
|
}
|
|
1122
|
-
let resolvedSymbol = this.getSymbolResolution(asset, resolved,
|
|
1123
|
-
// @ts-expect-error TS2345
|
|
1124
|
-
symbol, undefined, replacements);
|
|
1031
|
+
let resolvedSymbol = this.getSymbolResolution(asset, resolved, symbol, undefined, replacements);
|
|
1125
1032
|
let get = this.buildFunctionExpression([], resolvedSymbol);
|
|
1126
1033
|
let set = asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolvedSymbol} = v`) : '';
|
|
1127
1034
|
prepend += `$parcel$export($${assetId}$exports, ${JSON.stringify(symbol)}, ${get}${set});\n`;
|
|
@@ -1138,7 +1045,6 @@ ${code}
|
|
|
1138
1045
|
// re-exported symbols rather than only symbols declared in this asset.
|
|
1139
1046
|
let incomingDeps = this.bundleGraph.getIncomingDependencies(asset);
|
|
1140
1047
|
let usedExports = [...asset.symbols.exportSymbols()].filter(symbol => {
|
|
1141
|
-
// @ts-expect-error TS2367
|
|
1142
1048
|
if (symbol === '*') {
|
|
1143
1049
|
return false;
|
|
1144
1050
|
}
|
|
@@ -1153,8 +1059,6 @@ ${code}
|
|
|
1153
1059
|
|
|
1154
1060
|
// No used symbols available for the asset, make sure we keep all of them
|
|
1155
1061
|
if (!symbols) return false;
|
|
1156
|
-
|
|
1157
|
-
// @ts-expect-error TS2345
|
|
1158
1062
|
return !symbols.has(symbol) && !symbols.has('*');
|
|
1159
1063
|
});
|
|
1160
1064
|
return !unused;
|
|
@@ -1166,9 +1070,7 @@ ${code}
|
|
|
1166
1070
|
// additional assignments after each mutation of the original binding.
|
|
1167
1071
|
prepend += `\n${usedExports.map(exp => {
|
|
1168
1072
|
var _asset$symbols$get2;
|
|
1169
|
-
let resolved = this.getSymbolResolution(asset, asset,
|
|
1170
|
-
// @ts-expect-error TS2345
|
|
1171
|
-
exp, undefined, replacements);
|
|
1073
|
+
let resolved = this.getSymbolResolution(asset, asset, exp, undefined, replacements);
|
|
1172
1074
|
let get = this.buildFunctionExpression([], resolved);
|
|
1173
1075
|
let isEsmExport = !!((_asset$symbols$get2 = asset.symbols.get(exp)) !== null && _asset$symbols$get2 !== void 0 && (_asset$symbols$get2 = _asset$symbols$get2.meta) !== null && _asset$symbols$get2 !== void 0 && _asset$symbols$get2.isEsm);
|
|
1174
1076
|
let set = !isEsmExport && asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolved} = v`) : '';
|
|
@@ -1206,10 +1108,8 @@ ${code}
|
|
|
1206
1108
|
this.usedHelpers.add('$parcel$global');
|
|
1207
1109
|
}
|
|
1208
1110
|
for (let helper of this.usedHelpers) {
|
|
1209
|
-
// @ts-expect-error TS7053
|
|
1210
1111
|
let currentHelper = _helpers.helpers[helper];
|
|
1211
1112
|
if (typeof currentHelper === 'function') {
|
|
1212
|
-
// @ts-expect-error TS7053
|
|
1213
1113
|
currentHelper = _helpers.helpers[helper](this.bundle.env);
|
|
1214
1114
|
}
|
|
1215
1115
|
res += currentHelper;
|
|
@@ -1265,11 +1165,7 @@ ${code}
|
|
|
1265
1165
|
return [res, lines];
|
|
1266
1166
|
}
|
|
1267
1167
|
needsDefaultInterop(asset) {
|
|
1268
|
-
if (
|
|
1269
|
-
// @ts-expect-error TS2345
|
|
1270
|
-
asset.symbols.hasExportSymbol('*') &&
|
|
1271
|
-
// @ts-expect-error TS2345
|
|
1272
|
-
!asset.symbols.hasExportSymbol('default')) {
|
|
1168
|
+
if (asset.symbols.hasExportSymbol('*') && !asset.symbols.hasExportSymbol('default')) {
|
|
1273
1169
|
return true;
|
|
1274
1170
|
}
|
|
1275
1171
|
return false;
|
package/lib/dev-prelude.js
CHANGED
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
typeof globalThis !== 'undefined'
|
|
13
13
|
? globalThis
|
|
14
14
|
: typeof self !== 'undefined'
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
? self
|
|
16
|
+
: typeof window !== 'undefined'
|
|
17
|
+
? window
|
|
18
|
+
: typeof global !== 'undefined'
|
|
19
|
+
? global
|
|
20
|
+
: {};
|
|
21
21
|
/* eslint-enable no-undef */
|
|
22
22
|
|
|
23
23
|
// Save the require from previous bundle to this closure if any
|
package/lib/index.js
CHANGED
|
@@ -77,10 +77,8 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
77
77
|
});
|
|
78
78
|
let name = (packageName === null || packageName === void 0 ? void 0 : packageName.contents) ?? '';
|
|
79
79
|
return {
|
|
80
|
-
// @ts-expect-error TS2345
|
|
81
80
|
parcelRequireName: 'parcelRequire' + (0, _rust().hashString)(name).slice(-4),
|
|
82
|
-
unstable_asyncBundleRuntime: Boolean(
|
|
83
|
-
conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.unstable_asyncBundleRuntime)
|
|
81
|
+
unstable_asyncBundleRuntime: Boolean(conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.unstable_asyncBundleRuntime)
|
|
84
82
|
};
|
|
85
83
|
},
|
|
86
84
|
async package({
|
|
@@ -103,7 +101,15 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
103
101
|
}
|
|
104
102
|
}
|
|
105
103
|
if (contents == null) {
|
|
106
|
-
let packager = bundle.env.shouldScopeHoist ? new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle,
|
|
104
|
+
let packager = bundle.env.shouldScopeHoist ? new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle,
|
|
105
|
+
// $FlowFixMe
|
|
106
|
+
// $FlowFixMe
|
|
107
|
+
(0, _nullthrows().default)(config).parcelRequireName,
|
|
108
|
+
// $FlowFixMe
|
|
109
|
+
(0, _nullthrows().default)(config).unstable_asyncBundleRuntime, logger) : new _DevPackager.DevPackager(options, bundleGraph, bundle,
|
|
110
|
+
// $FlowFixMe
|
|
111
|
+
// $FlowFixMe
|
|
112
|
+
(0, _nullthrows().default)(config).parcelRequireName);
|
|
107
113
|
({
|
|
108
114
|
contents,
|
|
109
115
|
map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.19.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -9,27 +9,22 @@
|
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
11
11
|
},
|
|
12
|
-
"main": "
|
|
13
|
-
"source": "
|
|
14
|
-
"types": "./lib/index.d.ts",
|
|
12
|
+
"main": "lib/index.js",
|
|
13
|
+
"source": "src/index.js",
|
|
15
14
|
"engines": {
|
|
16
15
|
"node": ">= 16.0.0"
|
|
17
16
|
},
|
|
18
17
|
"dependencies": {
|
|
19
|
-
"@atlaspack/diagnostic": "2.14.
|
|
20
|
-
"@atlaspack/feature-flags": "2.
|
|
21
|
-
"@atlaspack/plugin": "2.14.21
|
|
22
|
-
"@atlaspack/rust": "3.4.
|
|
23
|
-
"@atlaspack/types": "2.15.11-typescript-bc4459c37.0",
|
|
24
|
-
"@atlaspack/utils": "2.17.3-typescript-bc4459c37.0",
|
|
18
|
+
"@atlaspack/diagnostic": "2.14.1",
|
|
19
|
+
"@atlaspack/feature-flags": "2.20.0",
|
|
20
|
+
"@atlaspack/plugin": "2.14.21",
|
|
21
|
+
"@atlaspack/rust": "3.4.1",
|
|
25
22
|
"@parcel/source-map": "^2.1.1",
|
|
23
|
+
"@atlaspack/types": "2.15.11",
|
|
24
|
+
"@atlaspack/utils": "2.17.3",
|
|
26
25
|
"globals": "^13.2.0",
|
|
27
26
|
"nullthrows": "^1.1.1",
|
|
28
27
|
"outdent": "^0.8.0"
|
|
29
28
|
},
|
|
30
|
-
"type": "commonjs"
|
|
31
|
-
|
|
32
|
-
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
33
|
-
},
|
|
34
|
-
"gitHead": "bc4459c37a38ef1f74772126637e1d8841d1fcb0"
|
|
35
|
-
}
|
|
29
|
+
"type": "commonjs"
|
|
30
|
+
}
|