@atlaspack/packager-js 2.18.2 → 2.18.3-typescript-08dcc1c9b.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 +0 -1
- package/LICENSE +201 -0
- package/lib/DevPackager.js +8 -1
- package/lib/ScopeHoistingPackager.js +124 -16
- package/lib/dev-prelude.js +6 -6
- package/lib/index.js +4 -10
- package/package.json +14 -9
- package/src/{CJSOutputFormat.js → CJSOutputFormat.ts} +0 -1
- package/src/{DevPackager.js → DevPackager.ts} +18 -5
- package/src/{ESMOutputFormat.js → ESMOutputFormat.ts} +2 -3
- package/src/{GlobalOutputFormat.js → GlobalOutputFormat.ts} +0 -1
- package/src/{ScopeHoistingPackager.js → ScopeHoistingPackager.ts} +123 -41
- package/src/dev-prelude.js +6 -6
- package/src/{helpers.js → helpers.ts} +1 -2
- package/src/{index.js → index.ts} +13 -15
- package/src/{utils.js → utils.ts} +1 -2
- package/tsconfig.json +4 -0
|
@@ -77,7 +77,6 @@ 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
|
-
//
|
|
81
80
|
// For conditional bundling the only difference in this regex is adding `importCond` where we have `importAsync` etc..
|
|
82
81
|
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;
|
|
83
82
|
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;
|
|
@@ -97,6 +96,8 @@ const OUTPUT_FORMATS = {
|
|
|
97
96
|
global: _GlobalOutputFormat.GlobalOutputFormat
|
|
98
97
|
};
|
|
99
98
|
class ScopeHoistingPackager {
|
|
99
|
+
// @ts-expect-error TS2564
|
|
100
|
+
|
|
100
101
|
exportedSymbols = new Map();
|
|
101
102
|
externals = new Map();
|
|
102
103
|
topLevelNames = new Map();
|
|
@@ -140,9 +141,11 @@ class ScopeHoistingPackager {
|
|
|
140
141
|
}
|
|
141
142
|
let res = '';
|
|
142
143
|
let lineCount = 0;
|
|
144
|
+
// @ts-expect-error TS7034
|
|
143
145
|
let sourceMap = null;
|
|
144
146
|
let processAsset = asset => {
|
|
145
147
|
let [content, map, lines] = this.visitAsset(asset);
|
|
148
|
+
// @ts-expect-error TS7005
|
|
146
149
|
if (sourceMap && map) {
|
|
147
150
|
sourceMap.addSourceMap(map, lineCount);
|
|
148
151
|
} else if (this.bundle.env.sourceMap) {
|
|
@@ -181,6 +184,7 @@ class ScopeHoistingPackager {
|
|
|
181
184
|
let [prelude, preludeLines] = this.buildBundlePrelude();
|
|
182
185
|
res = prelude + res;
|
|
183
186
|
lineCount += preludeLines;
|
|
187
|
+
// @ts-expect-error TS2339
|
|
184
188
|
(_sourceMap = sourceMap) === null || _sourceMap === void 0 || _sourceMap.offsetLines(1, preludeLines);
|
|
185
189
|
let entries = this.bundle.getEntryAssets();
|
|
186
190
|
let mainEntry = this.bundle.getMainEntry();
|
|
@@ -200,9 +204,14 @@ class ScopeHoistingPackager {
|
|
|
200
204
|
if (this.wrappedAssets.has(entry.id) && !this.isScriptEntry(entry)) {
|
|
201
205
|
var _entry$symbols$get;
|
|
202
206
|
let parcelRequire = `parcelRequire(${JSON.stringify(this.bundleGraph.getAssetPublicId(entry))});\n`;
|
|
207
|
+
|
|
208
|
+
// @ts-expect-error TS2345
|
|
203
209
|
let entryExports = (_entry$symbols$get = entry.symbols.get('*')) === null || _entry$symbols$get === void 0 ? void 0 : _entry$symbols$get.local;
|
|
204
|
-
if (entryExports && entry === mainEntry &&
|
|
210
|
+
if (entryExports && entry === mainEntry &&
|
|
211
|
+
// @ts-expect-error TS2345
|
|
212
|
+
this.exportedSymbols.has(entryExports)) {
|
|
205
213
|
(0, _assert().default)(!needsBundleQueue, 'Entry exports are not yet compaitble with async bundles');
|
|
214
|
+
// @ts-expect-error TS2731
|
|
206
215
|
res += `\nvar ${entryExports} = ${parcelRequire}`;
|
|
207
216
|
} else {
|
|
208
217
|
if (needsBundleQueue) {
|
|
@@ -234,6 +243,7 @@ class ScopeHoistingPackager {
|
|
|
234
243
|
}
|
|
235
244
|
res += (0, _utils2.replaceScriptDependencies)(this.bundleGraph, this.bundle, code, map, this.parcelRequireName);
|
|
236
245
|
if (sourceMap && map) {
|
|
246
|
+
// @ts-expect-error TS2339
|
|
237
247
|
sourceMap.addSourceMap(map, lineCount);
|
|
238
248
|
}
|
|
239
249
|
}
|
|
@@ -338,6 +348,8 @@ class ScopeHoistingPackager {
|
|
|
338
348
|
}, wrappedAssetRoot);
|
|
339
349
|
}
|
|
340
350
|
}
|
|
351
|
+
|
|
352
|
+
// @ts-expect-error TS2769
|
|
341
353
|
this.assetOutputs = new Map(await queue.run());
|
|
342
354
|
return {
|
|
343
355
|
wrapped,
|
|
@@ -362,6 +374,7 @@ class ScopeHoistingPackager {
|
|
|
362
374
|
// TODO: handle ESM exports of wrapped entry assets...
|
|
363
375
|
let entry = this.bundle.getMainEntry();
|
|
364
376
|
if (entry && !this.wrappedAssets.has(entry.id)) {
|
|
377
|
+
// @ts-expect-error TS2345
|
|
365
378
|
let hasNamespace = entry.symbols.hasExportSymbol('*');
|
|
366
379
|
for (let {
|
|
367
380
|
asset,
|
|
@@ -377,11 +390,14 @@ class ScopeHoistingPackager {
|
|
|
377
390
|
if (hasNamespace && this.isAsyncBundle && exportAs !== '*') {
|
|
378
391
|
continue;
|
|
379
392
|
}
|
|
380
|
-
let symbols = (_this$exportedSymbols = this.exportedSymbols.get(
|
|
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;
|
|
381
396
|
if (!symbols) {
|
|
382
397
|
symbols = [];
|
|
383
398
|
this.exportedSymbols.set(symbol, {
|
|
384
399
|
asset,
|
|
400
|
+
// @ts-expect-error TS2322
|
|
385
401
|
exportSymbol,
|
|
386
402
|
local: symbol,
|
|
387
403
|
exportAs: symbols
|
|
@@ -390,6 +406,8 @@ class ScopeHoistingPackager {
|
|
|
390
406
|
if (exportAs === '*') {
|
|
391
407
|
exportAs = 'default';
|
|
392
408
|
}
|
|
409
|
+
|
|
410
|
+
// @ts-expect-error TS2345
|
|
393
411
|
symbols.push(exportAs);
|
|
394
412
|
} else if (symbol === null) {
|
|
395
413
|
// TODO `meta.exportsIdentifier[exportSymbol]` should be exported
|
|
@@ -466,6 +484,7 @@ class ScopeHoistingPackager {
|
|
|
466
484
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
467
485
|
depCode += code + '\n';
|
|
468
486
|
if (sourceMap && map) {
|
|
487
|
+
// @ts-expect-error TS2551
|
|
469
488
|
sourceMap.addSourceMap(map, lineCount);
|
|
470
489
|
}
|
|
471
490
|
lineCount += lines + 1;
|
|
@@ -491,6 +510,7 @@ class ScopeHoistingPackager {
|
|
|
491
510
|
}
|
|
492
511
|
code += append;
|
|
493
512
|
let lineCount = 0;
|
|
513
|
+
// @ts-expect-error TS2552
|
|
494
514
|
let depContent = [];
|
|
495
515
|
if (depMap.size === 0 && replacements.size === 0) {
|
|
496
516
|
// If there are no dependencies or replacements, use a simple function to count the number of lines.
|
|
@@ -572,6 +592,7 @@ class ScopeHoistingPackager {
|
|
|
572
592
|
sourceMap.offsetLines(lineCount + 1, lines);
|
|
573
593
|
}
|
|
574
594
|
if (map) {
|
|
595
|
+
// @ts-expect-error TS2551
|
|
575
596
|
sourceMap.addSourceMap(map, lineCount);
|
|
576
597
|
}
|
|
577
598
|
}
|
|
@@ -616,6 +637,7 @@ ${code}
|
|
|
616
637
|
if (!depCode) continue;
|
|
617
638
|
code += depCode + '\n';
|
|
618
639
|
if (sourceMap && map) {
|
|
640
|
+
// @ts-expect-error TS2551
|
|
619
641
|
sourceMap.addSourceMap(map, lineCount);
|
|
620
642
|
}
|
|
621
643
|
lineCount += lines + 1;
|
|
@@ -662,9 +684,12 @@ ${code}
|
|
|
662
684
|
for (let [imported, {
|
|
663
685
|
local
|
|
664
686
|
}] of dep.symbols) {
|
|
687
|
+
// @ts-expect-error TS2367
|
|
665
688
|
if (local === '*') {
|
|
666
689
|
continue;
|
|
667
690
|
}
|
|
691
|
+
|
|
692
|
+
// @ts-expect-error TS2345
|
|
668
693
|
let symbol = this.getSymbolResolution(asset, resolved, imported, dep);
|
|
669
694
|
replacements.set(local,
|
|
670
695
|
// If this was an internalized async asset, wrap in a Promise.resolve.
|
|
@@ -686,6 +711,7 @@ ${code}
|
|
|
686
711
|
// which will be provided to us by the wrapper.
|
|
687
712
|
if (this.wrappedAssets.has(asset.id) || this.bundle.env.outputFormat === 'commonjs' && asset === this.bundle.getMainEntry()) {
|
|
688
713
|
var _asset$symbols$get;
|
|
714
|
+
// @ts-expect-error TS2345
|
|
689
715
|
let exportsName = ((_asset$symbols$get = asset.symbols.get('*')) === null || _asset$symbols$get === void 0 ? void 0 : _asset$symbols$get.local) || `$${assetId}$exports`;
|
|
690
716
|
replacements.set(exportsName, 'module.exports');
|
|
691
717
|
}
|
|
@@ -718,8 +744,11 @@ ${code}
|
|
|
718
744
|
local
|
|
719
745
|
}] of dep.symbols) {
|
|
720
746
|
// If already imported, just add the already renamed variable to the mapping.
|
|
747
|
+
// @ts-expect-error TS2345
|
|
721
748
|
let renamed = external.get(imported);
|
|
749
|
+
// @ts-expect-error TS2367
|
|
722
750
|
if (renamed && local !== '*' && replacements) {
|
|
751
|
+
// @ts-expect-error TS2345
|
|
723
752
|
replacements.set(local, renamed);
|
|
724
753
|
continue;
|
|
725
754
|
}
|
|
@@ -732,16 +761,25 @@ ${code}
|
|
|
732
761
|
if (referencedBundle) {
|
|
733
762
|
var _entry$symbols$get3;
|
|
734
763
|
let entry = (0, _nullthrows().default)(referencedBundle.getMainEntry());
|
|
735
|
-
|
|
764
|
+
// @ts-expect-error TS2322
|
|
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`;
|
|
736
768
|
} else {
|
|
737
769
|
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${specifier}`);
|
|
738
770
|
}
|
|
771
|
+
|
|
772
|
+
// @ts-expect-error TS2345
|
|
739
773
|
external.set('*', renamed);
|
|
740
774
|
}
|
|
775
|
+
|
|
776
|
+
// @ts-expect-error TS2367
|
|
741
777
|
if (local !== '*' && replacements) {
|
|
742
778
|
let replacement;
|
|
779
|
+
// @ts-expect-error TS2367
|
|
743
780
|
if (imported === '*') {
|
|
744
781
|
replacement = renamed;
|
|
782
|
+
// @ts-expect-error TS2367
|
|
745
783
|
} else if (imported === 'default') {
|
|
746
784
|
let needsDefaultInterop = true;
|
|
747
785
|
if (referencedBundle) {
|
|
@@ -755,32 +793,41 @@ ${code}
|
|
|
755
793
|
replacement = `${renamed}.default`;
|
|
756
794
|
}
|
|
757
795
|
} else {
|
|
796
|
+
// @ts-expect-error TS2345
|
|
758
797
|
replacement = this.getPropertyAccess(renamed, imported);
|
|
759
798
|
}
|
|
799
|
+
|
|
800
|
+
// @ts-expect-error TS2345
|
|
760
801
|
replacements.set(local, replacement);
|
|
761
802
|
}
|
|
762
803
|
} else {
|
|
763
804
|
let property;
|
|
764
805
|
if (referencedBundle) {
|
|
765
806
|
let entry = (0, _nullthrows().default)(referencedBundle.getMainEntry());
|
|
807
|
+
// @ts-expect-error TS2345
|
|
766
808
|
if (entry.symbols.hasExportSymbol('*')) {
|
|
767
809
|
// If importing * and the referenced module has a * export (e.g. CJS), use default instead.
|
|
768
810
|
// This mirrors the logic in buildExportedSymbols.
|
|
769
811
|
property = imported;
|
|
812
|
+
// @ts-expect-error TS2322
|
|
770
813
|
imported = (referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.env.outputFormat) === 'esmodule' ? 'default' : '*';
|
|
771
814
|
} else {
|
|
815
|
+
// @ts-expect-error TS2367
|
|
772
816
|
if (imported === '*') {
|
|
773
817
|
let exportedSymbols = this.bundleGraph.getExportedSymbols(entry);
|
|
818
|
+
// @ts-expect-error TS2367
|
|
774
819
|
if (local === '*') {
|
|
775
820
|
// Re-export all symbols.
|
|
776
821
|
for (let exported of exportedSymbols) {
|
|
777
822
|
if (exported.symbol) {
|
|
823
|
+
// @ts-expect-error TS2345
|
|
778
824
|
external.set(exported.exportSymbol, exported.symbol);
|
|
779
825
|
}
|
|
780
826
|
}
|
|
781
827
|
continue;
|
|
782
828
|
}
|
|
783
829
|
}
|
|
830
|
+
// @ts-expect-error TS2322
|
|
784
831
|
renamed = this.bundleGraph.getSymbolResolution(entry, imported, this.bundle).symbol;
|
|
785
832
|
}
|
|
786
833
|
}
|
|
@@ -789,25 +836,37 @@ ${code}
|
|
|
789
836
|
// are deduplicated. We have to prefix the imported name with the bundle id so that
|
|
790
837
|
// local variables do not shadow it.
|
|
791
838
|
if (!renamed) {
|
|
839
|
+
// @ts-expect-error TS2345
|
|
792
840
|
if (this.exportedSymbols.has(local)) {
|
|
841
|
+
// @ts-expect-error TS2322
|
|
793
842
|
renamed = local;
|
|
843
|
+
// @ts-expect-error TS2367
|
|
794
844
|
} else if (imported === 'default' || imported === '*') {
|
|
795
845
|
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${specifier}`);
|
|
796
846
|
} else {
|
|
797
|
-
renamed = this.getTopLevelName(
|
|
847
|
+
renamed = this.getTopLevelName(
|
|
848
|
+
// @ts-expect-error TS2731
|
|
849
|
+
`$${this.bundle.publicId}$${imported}`);
|
|
798
850
|
}
|
|
799
851
|
}
|
|
852
|
+
|
|
853
|
+
// @ts-expect-error TS2345
|
|
800
854
|
external.set(imported, renamed);
|
|
855
|
+
// @ts-expect-error TS2367
|
|
801
856
|
if (local !== '*' && replacements) {
|
|
802
857
|
let replacement = renamed;
|
|
858
|
+
// @ts-expect-error TS2367
|
|
803
859
|
if (property === '*') {
|
|
804
860
|
replacement = renamed;
|
|
861
|
+
// @ts-expect-error TS2367
|
|
805
862
|
} else if (property === 'default') {
|
|
806
863
|
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
807
864
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
808
865
|
} else if (property) {
|
|
866
|
+
// @ts-expect-error TS2345
|
|
809
867
|
replacement = this.getPropertyAccess(renamed, property);
|
|
810
868
|
}
|
|
869
|
+
// @ts-expect-error TS2345
|
|
811
870
|
replacements.set(local, replacement);
|
|
812
871
|
}
|
|
813
872
|
}
|
|
@@ -829,6 +888,7 @@ ${code}
|
|
|
829
888
|
asset: resolvedAsset,
|
|
830
889
|
exportSymbol,
|
|
831
890
|
symbol
|
|
891
|
+
// @ts-expect-error TS2345
|
|
832
892
|
} = this.bundleGraph.getSymbolResolution(resolved, imported, this.bundle);
|
|
833
893
|
if (resolvedAsset.type !== 'js' || dep && this.bundleGraph.isDependencySkipped(dep)) {
|
|
834
894
|
// Graceful fallback for non-js imports or when trying to resolve a symbol
|
|
@@ -862,7 +922,13 @@ ${code}
|
|
|
862
922
|
|
|
863
923
|
// If this is an ESM default import of a CJS module with a `default` symbol,
|
|
864
924
|
// and no __esModule flag, we need to resolve to the namespace instead.
|
|
865
|
-
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') &&
|
|
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');
|
|
866
932
|
|
|
867
933
|
// Find the namespace object for the resolved module. If wrapped and this
|
|
868
934
|
// is an inline require (not top-level), use a parcelRequire call, otherwise
|
|
@@ -878,7 +944,9 @@ ${code}
|
|
|
878
944
|
obj = `$${publicId}`;
|
|
879
945
|
} else {
|
|
880
946
|
var _resolvedAsset$symbol;
|
|
947
|
+
// @ts-expect-error TS2345
|
|
881
948
|
obj = ((_resolvedAsset$symbol = resolvedAsset.symbols.get('*')) === null || _resolvedAsset$symbol === void 0 ? void 0 : _resolvedAsset$symbol.local) || `$${assetId}$exports`;
|
|
949
|
+
// @ts-expect-error TS2345
|
|
882
950
|
obj = (replacements === null || replacements === void 0 ? void 0 : replacements.get(obj)) || obj;
|
|
883
951
|
}
|
|
884
952
|
if (imported === '*' || exportSymbol === '*' || isDefaultInterop) {
|
|
@@ -887,6 +955,7 @@ ${code}
|
|
|
887
955
|
// Directly use module.exports for wrapped assets importing themselves.
|
|
888
956
|
return 'module.exports';
|
|
889
957
|
} else {
|
|
958
|
+
// @ts-expect-error TS2322
|
|
890
959
|
return obj;
|
|
891
960
|
}
|
|
892
961
|
} else if ((!staticExports || isWrapped || !symbol || isExternalCommonJS) && resolvedAsset !== parentAsset) {
|
|
@@ -895,15 +964,20 @@ ${code}
|
|
|
895
964
|
// than a direct reference. If importing default from a CJS module,
|
|
896
965
|
// use a helper to check the __esModule flag at runtime.
|
|
897
966
|
let kind = dep === null || dep === void 0 ? void 0 : dep.meta.kind;
|
|
898
|
-
if ((!dep || kind === 'Import' || kind === 'Export') && exportSymbol === 'default' &&
|
|
967
|
+
if ((!dep || kind === 'Import' || kind === 'Export') && exportSymbol === 'default' &&
|
|
968
|
+
// @ts-expect-error TS2345
|
|
969
|
+
resolvedAsset.symbols.hasExportSymbol('*') && this.needsDefaultInterop(resolvedAsset)) {
|
|
899
970
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
971
|
+
// @ts-expect-error TS2731
|
|
900
972
|
return `(/*@__PURE__*/$parcel$interopDefault(${obj}))`;
|
|
901
973
|
} else {
|
|
974
|
+
// @ts-expect-error TS2345
|
|
902
975
|
return this.getPropertyAccess(obj, exportSymbol);
|
|
903
976
|
}
|
|
904
977
|
} else if (!symbol) {
|
|
905
978
|
(0, _assert().default)(false, 'Asset was skipped or not found.');
|
|
906
979
|
} else {
|
|
980
|
+
// @ts-expect-error TS2322
|
|
907
981
|
return (replacements === null || replacements === void 0 ? void 0 : replacements.get(symbol)) || symbol;
|
|
908
982
|
}
|
|
909
983
|
}
|
|
@@ -943,20 +1017,32 @@ ${code}
|
|
|
943
1017
|
// If the asset has a namespace export symbol, it is CommonJS.
|
|
944
1018
|
// If there's no __esModule flag, and default is a used symbol, we need
|
|
945
1019
|
// to insert an interop helper.
|
|
946
|
-
let defaultInterop =
|
|
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');
|
|
947
1027
|
let usedNamespace;
|
|
948
1028
|
if ((0, _featureFlags().getFeatureFlag)('inlineConstOptimisationFix') && asset.meta.isConstantModule) {
|
|
949
1029
|
// Only set usedNamespace if there is an incoming dependency in the current bundle that uses '*'
|
|
950
|
-
usedNamespace = this.bundleGraph.getIncomingDependencies(asset).some(dep => this.bundle.hasDependency(dep) &&
|
|
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('*'));
|
|
951
1033
|
} else {
|
|
952
1034
|
usedNamespace =
|
|
953
1035
|
// If the asset has * in its used symbols, we might need the exports namespace.
|
|
954
1036
|
// The one case where this isn't true is in ESM library entries, where the only
|
|
955
1037
|
// dependency on * is the entry dependency. In this case, we will use ESM exports
|
|
956
1038
|
// instead of the namespace object.
|
|
957
|
-
|
|
1039
|
+
// @ts-expect-error TS2345
|
|
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('*'))) ||
|
|
958
1043
|
// If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
959
1044
|
// we fallback on the namespace object.
|
|
1045
|
+
// @ts-expect-error TS2345
|
|
960
1046
|
asset.symbols.hasExportSymbol('*') && [...usedSymbols].some(s => !asset.symbols.hasExportSymbol(s)) ||
|
|
961
1047
|
// If the exports has this asset's namespace (e.g. ESM output from CJS input),
|
|
962
1048
|
// include the namespace object for the default export.
|
|
@@ -981,6 +1067,7 @@ ${code}
|
|
|
981
1067
|
// Insert the __esModule interop flag for this module if it has a `default` export
|
|
982
1068
|
// and the namespace symbol is used.
|
|
983
1069
|
// TODO: only if required by CJS?
|
|
1070
|
+
// @ts-expect-error TS2345
|
|
984
1071
|
if (asset.symbols.hasExportSymbol('default') && usedSymbols.has('*')) {
|
|
985
1072
|
prepend += `\n$parcel$defineInteropFlag($${assetId}$exports);\n`;
|
|
986
1073
|
prependLineCount += 2;
|
|
@@ -999,6 +1086,7 @@ ${code}
|
|
|
999
1086
|
for (let [imported, {
|
|
1000
1087
|
local
|
|
1001
1088
|
}] of dep.symbols) {
|
|
1089
|
+
// @ts-expect-error TS2367
|
|
1002
1090
|
if (imported === '*' && local === '*') {
|
|
1003
1091
|
if (!resolved) {
|
|
1004
1092
|
// Re-exporting an external module. This should have already been handled in buildReplacements.
|
|
@@ -1011,20 +1099,29 @@ ${code}
|
|
|
1011
1099
|
// If the resolved asset has an exports object, use the $parcel$exportWildcard helper
|
|
1012
1100
|
// to re-export all symbols. Otherwise, if there's no namespace object available, add
|
|
1013
1101
|
// $parcel$export calls for each used symbol of the dependency.
|
|
1014
|
-
if (isWrapped || resolved.meta.staticExports === false ||
|
|
1102
|
+
if (isWrapped || resolved.meta.staticExports === false ||
|
|
1103
|
+
// @ts-expect-error TS2345
|
|
1104
|
+
(0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(resolved)).has('*') ||
|
|
1015
1105
|
// an empty asset
|
|
1016
|
-
!resolved.meta.hasCJSExports &&
|
|
1106
|
+
!resolved.meta.hasCJSExports &&
|
|
1107
|
+
// @ts-expect-error TS2345
|
|
1108
|
+
resolved.symbols.hasExportSymbol('*')) {
|
|
1017
1109
|
let obj = this.getSymbolResolution(asset, resolved, '*', dep, replacements);
|
|
1018
1110
|
append += `$parcel$exportWildcard($${assetId}$exports, ${obj});\n`;
|
|
1019
1111
|
this.usedHelpers.add('$parcel$exportWildcard');
|
|
1020
1112
|
} else {
|
|
1021
1113
|
for (let symbol of (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep))) {
|
|
1022
|
-
if (
|
|
1114
|
+
if (
|
|
1115
|
+
// @ts-expect-error TS2367
|
|
1116
|
+
symbol === 'default' ||
|
|
1023
1117
|
// `export * as ...` does not include the default export
|
|
1118
|
+
// @ts-expect-error TS2367
|
|
1024
1119
|
symbol === '__esModule') {
|
|
1025
1120
|
continue;
|
|
1026
1121
|
}
|
|
1027
|
-
let resolvedSymbol = this.getSymbolResolution(asset, resolved,
|
|
1122
|
+
let resolvedSymbol = this.getSymbolResolution(asset, resolved,
|
|
1123
|
+
// @ts-expect-error TS2345
|
|
1124
|
+
symbol, undefined, replacements);
|
|
1028
1125
|
let get = this.buildFunctionExpression([], resolvedSymbol);
|
|
1029
1126
|
let set = asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolvedSymbol} = v`) : '';
|
|
1030
1127
|
prepend += `$parcel$export($${assetId}$exports, ${JSON.stringify(symbol)}, ${get}${set});\n`;
|
|
@@ -1041,6 +1138,7 @@ ${code}
|
|
|
1041
1138
|
// re-exported symbols rather than only symbols declared in this asset.
|
|
1042
1139
|
let incomingDeps = this.bundleGraph.getIncomingDependencies(asset);
|
|
1043
1140
|
let usedExports = [...asset.symbols.exportSymbols()].filter(symbol => {
|
|
1141
|
+
// @ts-expect-error TS2367
|
|
1044
1142
|
if (symbol === '*') {
|
|
1045
1143
|
return false;
|
|
1046
1144
|
}
|
|
@@ -1055,6 +1153,8 @@ ${code}
|
|
|
1055
1153
|
|
|
1056
1154
|
// No used symbols available for the asset, make sure we keep all of them
|
|
1057
1155
|
if (!symbols) return false;
|
|
1156
|
+
|
|
1157
|
+
// @ts-expect-error TS2345
|
|
1058
1158
|
return !symbols.has(symbol) && !symbols.has('*');
|
|
1059
1159
|
});
|
|
1060
1160
|
return !unused;
|
|
@@ -1066,7 +1166,9 @@ ${code}
|
|
|
1066
1166
|
// additional assignments after each mutation of the original binding.
|
|
1067
1167
|
prepend += `\n${usedExports.map(exp => {
|
|
1068
1168
|
var _asset$symbols$get2;
|
|
1069
|
-
let resolved = this.getSymbolResolution(asset, asset,
|
|
1169
|
+
let resolved = this.getSymbolResolution(asset, asset,
|
|
1170
|
+
// @ts-expect-error TS2345
|
|
1171
|
+
exp, undefined, replacements);
|
|
1070
1172
|
let get = this.buildFunctionExpression([], resolved);
|
|
1071
1173
|
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);
|
|
1072
1174
|
let set = !isEsmExport && asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolved} = v`) : '';
|
|
@@ -1104,8 +1206,10 @@ ${code}
|
|
|
1104
1206
|
this.usedHelpers.add('$parcel$global');
|
|
1105
1207
|
}
|
|
1106
1208
|
for (let helper of this.usedHelpers) {
|
|
1209
|
+
// @ts-expect-error TS7053
|
|
1107
1210
|
let currentHelper = _helpers.helpers[helper];
|
|
1108
1211
|
if (typeof currentHelper === 'function') {
|
|
1212
|
+
// @ts-expect-error TS7053
|
|
1109
1213
|
currentHelper = _helpers.helpers[helper](this.bundle.env);
|
|
1110
1214
|
}
|
|
1111
1215
|
res += currentHelper;
|
|
@@ -1161,7 +1265,11 @@ ${code}
|
|
|
1161
1265
|
return [res, lines];
|
|
1162
1266
|
}
|
|
1163
1267
|
needsDefaultInterop(asset) {
|
|
1164
|
-
if (
|
|
1268
|
+
if (
|
|
1269
|
+
// @ts-expect-error TS2345
|
|
1270
|
+
asset.symbols.hasExportSymbol('*') &&
|
|
1271
|
+
// @ts-expect-error TS2345
|
|
1272
|
+
!asset.symbols.hasExportSymbol('default')) {
|
|
1165
1273
|
return true;
|
|
1166
1274
|
}
|
|
1167
1275
|
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,8 +77,10 @@ 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
|
|
80
81
|
parcelRequireName: 'parcelRequire' + (0, _rust().hashString)(name).slice(-4),
|
|
81
|
-
unstable_asyncBundleRuntime: Boolean(
|
|
82
|
+
unstable_asyncBundleRuntime: Boolean( // @ts-expect-error TS2339
|
|
83
|
+
conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.unstable_asyncBundleRuntime)
|
|
82
84
|
};
|
|
83
85
|
},
|
|
84
86
|
async package({
|
|
@@ -101,15 +103,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
105
|
if (contents == null) {
|
|
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);
|
|
106
|
+
let packager = bundle.env.shouldScopeHoist ? new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName, (0, _nullthrows().default)(config).unstable_asyncBundleRuntime, logger) : new _DevPackager.DevPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName);
|
|
113
107
|
({
|
|
114
108
|
contents,
|
|
115
109
|
map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-js",
|
|
3
|
-
"version": "2.18.
|
|
3
|
+
"version": "2.18.3-typescript-08dcc1c9b.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -10,21 +10,26 @@
|
|
|
10
10
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
11
11
|
},
|
|
12
12
|
"main": "lib/index.js",
|
|
13
|
-
"source": "src/index.
|
|
13
|
+
"source": "src/index.ts",
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">= 16.0.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@atlaspack/diagnostic": "2.14.
|
|
19
|
-
"@atlaspack/feature-flags": "2.19.
|
|
20
|
-
"@atlaspack/plugin": "2.14.
|
|
21
|
-
"@atlaspack/rust": "3.4.
|
|
18
|
+
"@atlaspack/diagnostic": "2.14.2-typescript-08dcc1c9b.0",
|
|
19
|
+
"@atlaspack/feature-flags": "2.19.3-typescript-08dcc1c9b.0",
|
|
20
|
+
"@atlaspack/plugin": "2.14.21-typescript-08dcc1c9b.0",
|
|
21
|
+
"@atlaspack/rust": "3.4.2-typescript-08dcc1c9b.0",
|
|
22
|
+
"@atlaspack/types": "2.15.11-typescript-08dcc1c9b.0",
|
|
23
|
+
"@atlaspack/utils": "2.17.3-typescript-08dcc1c9b.0",
|
|
22
24
|
"@parcel/source-map": "^2.1.1",
|
|
23
|
-
"@atlaspack/types": "2.15.10",
|
|
24
|
-
"@atlaspack/utils": "2.17.2",
|
|
25
25
|
"globals": "^13.2.0",
|
|
26
26
|
"nullthrows": "^1.1.1",
|
|
27
27
|
"outdent": "^0.8.0"
|
|
28
28
|
},
|
|
29
|
-
"type": "commonjs"
|
|
29
|
+
"type": "commonjs",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"check-ts": "tsc --noEmit"
|
|
32
|
+
},
|
|
33
|
+
"types": "src/index.ts",
|
|
34
|
+
"gitHead": "08dcc1c9bcdc6ab931d55e05ccc0f45669de2f22"
|
|
30
35
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
import type {BundleGraph, PluginOptions, NamedBundle} from '@atlaspack/types';
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -37,7 +36,10 @@ export class DevPackager {
|
|
|
37
36
|
this.parcelRequireName = parcelRequireName;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
async package(): Promise<{
|
|
39
|
+
async package(): Promise<{
|
|
40
|
+
contents: string;
|
|
41
|
+
map: SourceMap | null | undefined;
|
|
42
|
+
}> {
|
|
41
43
|
// Load assets
|
|
42
44
|
let queue = new PromiseQueue({maxConcurrent: 32});
|
|
43
45
|
this.bundle.traverseAssets((asset) => {
|
|
@@ -59,7 +61,13 @@ export class DevPackager {
|
|
|
59
61
|
|
|
60
62
|
let prefix = this.getPrefix();
|
|
61
63
|
let lineOffset = countLines(prefix);
|
|
62
|
-
let script:
|
|
64
|
+
let script:
|
|
65
|
+
| {
|
|
66
|
+
code: string;
|
|
67
|
+
mapBuffer: Buffer | null | undefined;
|
|
68
|
+
}
|
|
69
|
+
| null
|
|
70
|
+
| undefined = null;
|
|
63
71
|
|
|
64
72
|
this.bundle.traverse((node) => {
|
|
65
73
|
let wrapped = first ? '' : ',';
|
|
@@ -94,11 +102,12 @@ export class DevPackager {
|
|
|
94
102
|
this.bundle.env.sourceType === 'script' &&
|
|
95
103
|
asset === this.bundle.getMainEntry()
|
|
96
104
|
) {
|
|
105
|
+
// @ts-expect-error TS2322
|
|
97
106
|
script = results[i++];
|
|
98
107
|
return;
|
|
99
108
|
}
|
|
100
109
|
|
|
101
|
-
let deps = {};
|
|
110
|
+
let deps: Record<string, any> = {};
|
|
102
111
|
let dependencies = this.bundleGraph.getDependencies(asset);
|
|
103
112
|
for (let dep of dependencies) {
|
|
104
113
|
let resolved = this.bundleGraph.getResolvedAsset(dep, this.bundle);
|
|
@@ -125,6 +134,7 @@ export class DevPackager {
|
|
|
125
134
|
}
|
|
126
135
|
}
|
|
127
136
|
|
|
137
|
+
// @ts-expect-error TS2339
|
|
128
138
|
let {code, mapBuffer} = results[i];
|
|
129
139
|
let output = code || '';
|
|
130
140
|
wrapped +=
|
|
@@ -205,6 +215,7 @@ export class DevPackager {
|
|
|
205
215
|
// runtimes with a parcelRequire call.
|
|
206
216
|
if (this.bundle.env.sourceType === 'script' && script) {
|
|
207
217
|
let entryMap;
|
|
218
|
+
// @ts-expect-error TS2339
|
|
208
219
|
let mapBuffer = script.mapBuffer;
|
|
209
220
|
if (mapBuffer) {
|
|
210
221
|
entryMap = new SourceMap(this.options.projectRoot, mapBuffer);
|
|
@@ -212,11 +223,13 @@ export class DevPackager {
|
|
|
212
223
|
contents += replaceScriptDependencies(
|
|
213
224
|
this.bundleGraph,
|
|
214
225
|
this.bundle,
|
|
226
|
+
// @ts-expect-error TS2339
|
|
215
227
|
script.code,
|
|
216
228
|
entryMap,
|
|
217
229
|
this.parcelRequireName,
|
|
218
230
|
);
|
|
219
231
|
if (this.bundle.env.sourceMap && entryMap) {
|
|
232
|
+
// @ts-expect-error TS2551
|
|
220
233
|
map.addSourceMap(entryMap, lineOffset);
|
|
221
234
|
}
|
|
222
235
|
}
|
|
@@ -228,7 +241,7 @@ export class DevPackager {
|
|
|
228
241
|
}
|
|
229
242
|
|
|
230
243
|
getPrefix(): string {
|
|
231
|
-
let interpreter:
|
|
244
|
+
let interpreter: string | null | undefined;
|
|
232
245
|
let mainEntry = this.bundle.getMainEntry();
|
|
233
246
|
if (mainEntry && this.isEntry() && !this.bundle.target.env.isBrowser()) {
|
|
234
247
|
let _interpreter = mainEntry.meta.interpreter;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {
|
|
3
2
|
ScopeHoistingPackager,
|
|
4
3
|
OutputFormat,
|
|
@@ -18,7 +17,7 @@ export class ESMOutputFormat implements OutputFormat {
|
|
|
18
17
|
for (let [source, specifiers] of this.packager.externals) {
|
|
19
18
|
let defaultSpecifier = null;
|
|
20
19
|
let namespaceSpecifier = null;
|
|
21
|
-
let namedSpecifiers = [];
|
|
20
|
+
let namedSpecifiers: Array<string> = [];
|
|
22
21
|
for (let [imported, symbol] of specifiers) {
|
|
23
22
|
if (imported === 'default' /* || isCommonJS*/) {
|
|
24
23
|
defaultSpecifier = symbol;
|
|
@@ -77,7 +76,7 @@ export class ESMOutputFormat implements OutputFormat {
|
|
|
77
76
|
buildBundlePostlude(): [string, number] {
|
|
78
77
|
let res = '';
|
|
79
78
|
let lines = 0;
|
|
80
|
-
let exportSpecifiers = [];
|
|
79
|
+
let exportSpecifiers: Array<string> = [];
|
|
81
80
|
for (let {
|
|
82
81
|
asset,
|
|
83
82
|
exportSymbol,
|