@atlaspack/packager-js 2.23.5-dev-5779cd2e2.0 → 2.23.5-dev-swc-4fc8a99f4.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.
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DevPackager = void 0;
7
7
  const utils_1 = require("@atlaspack/utils");
8
- const source_map_1 = __importDefault(require("@atlaspack/source-map"));
8
+ const source_map_1 = __importDefault(require("@parcel/source-map"));
9
9
  const feature_flags_1 = require("@atlaspack/feature-flags");
10
10
  const assert_1 = __importDefault(require("assert"));
11
11
  const path_1 = __importDefault(require("path"));
@@ -162,6 +162,7 @@ class DevPackager {
162
162
  // @ts-expect-error TS2339
163
163
  script.code, entryMap, this.parcelRequireName);
164
164
  if (this.bundle.env.sourceMap && entryMap) {
165
+ // @ts-expect-error TS2551
165
166
  map.addSourceMap(entryMap, lineOffset);
166
167
  }
167
168
  }
@@ -38,7 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.ScopeHoistingPackager = void 0;
40
40
  const utils_1 = require("@atlaspack/utils");
41
- const source_map_1 = __importDefault(require("@atlaspack/source-map"));
41
+ const source_map_1 = __importDefault(require("@parcel/source-map"));
42
42
  const nullthrows_1 = __importDefault(require("nullthrows"));
43
43
  const assert_1 = __importStar(require("assert"));
44
44
  const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
@@ -135,6 +135,7 @@ class ScopeHoistingPackager {
135
135
  this.seenHoistedRequires.clear();
136
136
  let [content, map, lines] = this.visitAsset(asset);
137
137
  if (sourceMap && map) {
138
+ // @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
138
139
  sourceMap.addSourceMap(map, lineCount);
139
140
  }
140
141
  else if (this.bundle.env.sourceMap) {
@@ -235,10 +236,14 @@ class ScopeHoistingPackager {
235
236
  sourceMap.addSourceMap(map, lineCount);
236
237
  }
237
238
  }
238
- return {
239
- contents: res,
240
- map: sourceMap,
241
- };
239
+ const result = { contents: res, map: sourceMap };
240
+ if (utils_1.debugTools['scope-hoisting-stats']) {
241
+ result.scopeHoistingStats = {
242
+ totalAssets: this.assetOutputs.size,
243
+ wrappedAssets: this.wrappedAssets.size,
244
+ };
245
+ }
246
+ return result;
242
247
  }
243
248
  shouldBundleQueue(bundle) {
244
249
  let referencingBundles = this.bundleGraph.getReferencingBundles(bundle);
@@ -519,6 +524,7 @@ class ScopeHoistingPackager {
519
524
  let [code, map, lines] = this.visitAsset(resolved);
520
525
  depCode += code + '\n';
521
526
  if (sourceMap && map) {
527
+ // @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
522
528
  sourceMap.addSourceMap(map, lineCount);
523
529
  }
524
530
  lineCount += lines + 1;
@@ -641,6 +647,7 @@ class ScopeHoistingPackager {
641
647
  sourceMap.offsetLines(lineCount + 1, lines);
642
648
  }
643
649
  if (map) {
650
+ // @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
644
651
  sourceMap.addSourceMap(map, lineCount);
645
652
  }
646
653
  }
@@ -684,6 +691,7 @@ ${code}
684
691
  continue;
685
692
  code += depCode + '\n';
686
693
  if (sourceMap && map) {
694
+ // @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
687
695
  sourceMap.addSourceMap(map, lineCount);
688
696
  }
689
697
  lineCount += lines + 1;
package/dist/index.js CHANGED
@@ -55,6 +55,7 @@ exports.default = new plugin_1.Packager({
55
55
  // If this is a non-module script, and there is only one asset with no dependencies,
56
56
  // then we don't need to package at all and can pass through the original code un-wrapped.
57
57
  let contents, map;
58
+ let scopeHoistingStats;
58
59
  if (bundle.env.sourceType === 'script') {
59
60
  let entries = bundle.getEntryAssets();
60
61
  if (entries.length === 1 &&
@@ -64,10 +65,17 @@ exports.default = new plugin_1.Packager({
64
65
  }
65
66
  }
66
67
  if (contents == null) {
67
- let packager = bundle.env.shouldScopeHoist
68
- ? new ScopeHoistingPackager_1.ScopeHoistingPackager(options, bundleGraph, bundle, (0, nullthrows_1.default)(config).parcelRequireName, (0, nullthrows_1.default)(config).unstable_asyncBundleRuntime, (0, nullthrows_1.default)(config).unstable_manualStaticBindingExports, logger)
69
- : new DevPackager_1.DevPackager(options, bundleGraph, bundle, (0, nullthrows_1.default)(config).parcelRequireName);
70
- ({ contents, map } = await packager.package());
68
+ if (bundle.env.shouldScopeHoist) {
69
+ let packager = new ScopeHoistingPackager_1.ScopeHoistingPackager(options, bundleGraph, bundle, (0, nullthrows_1.default)(config).parcelRequireName, (0, nullthrows_1.default)(config).unstable_asyncBundleRuntime, (0, nullthrows_1.default)(config).unstable_manualStaticBindingExports, logger);
70
+ let packageResult = await packager.package();
71
+ ({ contents, map } = packageResult);
72
+ scopeHoistingStats = packageResult.scopeHoistingStats;
73
+ }
74
+ else {
75
+ let packager = new DevPackager_1.DevPackager(options, bundleGraph, bundle, (0, nullthrows_1.default)(config).parcelRequireName);
76
+ let packageResult = await packager.package();
77
+ ({ contents, map } = packageResult);
78
+ }
71
79
  }
72
80
  contents += '\n' + (await getSourceMapSuffix(getSourceMapReference, map));
73
81
  // For library builds, we need to replace URL references with their final resolved paths.
@@ -81,7 +89,7 @@ exports.default = new plugin_1.Packager({
81
89
  getReplacement: (s) => JSON.stringify(s).slice(1, -1),
82
90
  }));
83
91
  }
84
- return (0, utils_1.replaceInlineReferences)({
92
+ let result = await (0, utils_1.replaceInlineReferences)({
85
93
  bundle,
86
94
  bundleGraph,
87
95
  contents,
@@ -92,6 +100,10 @@ exports.default = new plugin_1.Packager({
92
100
  getInlineBundleContents,
93
101
  map,
94
102
  });
103
+ if (utils_1.debugTools['scope-hoisting-stats']) {
104
+ return { ...result, scopeHoistingStats };
105
+ }
106
+ return result;
95
107
  },
96
108
  });
97
109
  async function getSourceMapSuffix(getSourceMapReference, map) {
@@ -12,7 +12,7 @@ function _utils() {
12
12
  return data;
13
13
  }
14
14
  function _sourceMap() {
15
- const data = _interopRequireDefault(require("@atlaspack/source-map"));
15
+ const data = _interopRequireDefault(require("@parcel/source-map"));
16
16
  _sourceMap = function () {
17
17
  return data;
18
18
  };
@@ -182,6 +182,7 @@ class DevPackager {
182
182
  // @ts-expect-error TS2339
183
183
  script.code, entryMap, this.parcelRequireName);
184
184
  if (this.bundle.env.sourceMap && entryMap) {
185
+ // @ts-expect-error TS2551
185
186
  map.addSourceMap(entryMap, lineOffset);
186
187
  }
187
188
  }
@@ -12,7 +12,7 @@ function _utils() {
12
12
  return data;
13
13
  }
14
14
  function _sourceMap2() {
15
- const data = _interopRequireDefault(require("@atlaspack/source-map"));
15
+ const data = _interopRequireDefault(require("@parcel/source-map"));
16
16
  _sourceMap2 = function () {
17
17
  return data;
18
18
  };
@@ -147,6 +147,7 @@ class ScopeHoistingPackager {
147
147
  this.seenHoistedRequires.clear();
148
148
  let [content, map, lines] = this.visitAsset(asset);
149
149
  if (sourceMap && map) {
150
+ // @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
150
151
  sourceMap.addSourceMap(map, lineCount);
151
152
  } else if (this.bundle.env.sourceMap) {
152
153
  sourceMap = map;
@@ -253,10 +254,17 @@ class ScopeHoistingPackager {
253
254
  sourceMap.addSourceMap(map, lineCount);
254
255
  }
255
256
  }
256
- return {
257
+ const result = {
257
258
  contents: res,
258
259
  map: sourceMap
259
260
  };
261
+ if (_utils().debugTools['scope-hoisting-stats']) {
262
+ result.scopeHoistingStats = {
263
+ totalAssets: this.assetOutputs.size,
264
+ wrappedAssets: this.wrappedAssets.size
265
+ };
266
+ }
267
+ return result;
260
268
  }
261
269
  shouldBundleQueue(bundle) {
262
270
  let referencingBundles = this.bundleGraph.getReferencingBundles(bundle);
@@ -506,6 +514,7 @@ class ScopeHoistingPackager {
506
514
  let [code, map, lines] = this.visitAsset(resolved);
507
515
  depCode += code + '\n';
508
516
  if (sourceMap && map) {
517
+ // @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
509
518
  sourceMap.addSourceMap(map, lineCount);
510
519
  }
511
520
  lineCount += lines + 1;
@@ -624,6 +633,7 @@ class ScopeHoistingPackager {
624
633
  sourceMap.offsetLines(lineCount + 1, lines);
625
634
  }
626
635
  if (map) {
636
+ // @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
627
637
  sourceMap.addSourceMap(map, lineCount);
628
638
  }
629
639
  }
@@ -668,6 +678,7 @@ ${code}
668
678
  if (!depCode) continue;
669
679
  code += depCode + '\n';
670
680
  if (sourceMap && map) {
681
+ // @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
671
682
  sourceMap.addSourceMap(map, lineCount);
672
683
  }
673
684
  lineCount += lines + 1;
package/lib/index.js CHANGED
@@ -100,6 +100,7 @@ var _default = exports.default = new (_plugin().Packager)({
100
100
  // If this is a non-module script, and there is only one asset with no dependencies,
101
101
  // then we don't need to package at all and can pass through the original code un-wrapped.
102
102
  let contents, map;
103
+ let scopeHoistingStats;
103
104
  if (bundle.env.sourceType === 'script') {
104
105
  let entries = bundle.getEntryAssets();
105
106
  if (entries.length === 1 && bundleGraph.getDependencies(entries[0]).length === 0) {
@@ -108,11 +109,22 @@ var _default = exports.default = new (_plugin().Packager)({
108
109
  }
109
110
  }
110
111
  if (contents == null) {
111
- let packager = bundle.env.shouldScopeHoist ? new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName, (0, _nullthrows().default)(config).unstable_asyncBundleRuntime, (0, _nullthrows().default)(config).unstable_manualStaticBindingExports, logger) : new _DevPackager.DevPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName);
112
- ({
113
- contents,
114
- map
115
- } = await packager.package());
112
+ if (bundle.env.shouldScopeHoist) {
113
+ let packager = new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName, (0, _nullthrows().default)(config).unstable_asyncBundleRuntime, (0, _nullthrows().default)(config).unstable_manualStaticBindingExports, logger);
114
+ let packageResult = await packager.package();
115
+ ({
116
+ contents,
117
+ map
118
+ } = packageResult);
119
+ scopeHoistingStats = packageResult.scopeHoistingStats;
120
+ } else {
121
+ let packager = new _DevPackager.DevPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName);
122
+ let packageResult = await packager.package();
123
+ ({
124
+ contents,
125
+ map
126
+ } = packageResult);
127
+ }
116
128
  }
117
129
  contents += '\n' + (await getSourceMapSuffix(getSourceMapReference, map));
118
130
 
@@ -130,7 +142,7 @@ var _default = exports.default = new (_plugin().Packager)({
130
142
  getReplacement: s => JSON.stringify(s).slice(1, -1)
131
143
  }));
132
144
  }
133
- return (0, _utils().replaceInlineReferences)({
145
+ let result = await (0, _utils().replaceInlineReferences)({
134
146
  bundle,
135
147
  bundleGraph,
136
148
  contents,
@@ -141,6 +153,13 @@ var _default = exports.default = new (_plugin().Packager)({
141
153
  getInlineBundleContents,
142
154
  map
143
155
  });
156
+ if (_utils().debugTools['scope-hoisting-stats']) {
157
+ return {
158
+ ...result,
159
+ scopeHoistingStats
160
+ };
161
+ }
162
+ return result;
144
163
  }
145
164
  });
146
165
  async function getSourceMapSuffix(getSourceMapReference, map) {
@@ -1,5 +1,5 @@
1
1
  import type { BundleGraph, PluginOptions, NamedBundle } from '@atlaspack/types';
2
- import SourceMap from '@atlaspack/source-map';
2
+ import SourceMap from '@parcel/source-map';
3
3
  export declare class DevPackager {
4
4
  options: PluginOptions;
5
5
  bundleGraph: BundleGraph<NamedBundle>;
@@ -1,9 +1,17 @@
1
1
  import type { Asset, BundleGraph, Dependency, PluginOptions, NamedBundle, PluginLogger } from '@atlaspack/types';
2
- import SourceMap from '@atlaspack/source-map';
2
+ import SourceMap from '@parcel/source-map';
3
3
  export interface OutputFormat {
4
4
  buildBundlePrelude(): [string, number];
5
5
  buildBundlePostlude(): [string, number];
6
6
  }
7
+ export type PackageResult = {
8
+ contents: string;
9
+ map: SourceMap | null | undefined;
10
+ scopeHoistingStats?: {
11
+ totalAssets: number;
12
+ wrappedAssets: number;
13
+ };
14
+ };
7
15
  export declare class ScopeHoistingPackager {
8
16
  options: PluginOptions;
9
17
  bundleGraph: BundleGraph<NamedBundle>;
@@ -37,10 +45,7 @@ export declare class ScopeHoistingPackager {
37
45
  logger: PluginLogger;
38
46
  useBothScopeHoistingImprovements: boolean;
39
47
  constructor(options: PluginOptions, bundleGraph: BundleGraph<NamedBundle>, bundle: NamedBundle, parcelRequireName: string, useAsyncBundleRuntime: boolean, manualStaticBindingExports: string[] | null, logger: PluginLogger);
40
- package(): Promise<{
41
- contents: string;
42
- map: SourceMap | null | undefined;
43
- }>;
48
+ package(): Promise<PackageResult>;
44
49
  shouldBundleQueue(bundle: NamedBundle): boolean;
45
50
  runWhenReady(bundle: NamedBundle, codeToRun: string): string;
46
51
  loadAssets(): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import type { BundleGraph, Dependency, NamedBundle } from '@atlaspack/types';
2
- import type SourceMap from '@atlaspack/source-map';
2
+ import type SourceMap from '@parcel/source-map';
3
3
  export declare function replaceScriptDependencies(bundleGraph: BundleGraph<NamedBundle>, bundle: NamedBundle, code: string, map: SourceMap | null | undefined, parcelRequireName: string): string;
4
4
  export declare function getSpecifier(dep: Dependency): string;
5
5
  export declare function isValidIdentifier(id: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/packager-js",
3
- "version": "2.23.5-dev-5779cd2e2.0",
3
+ "version": "2.23.5-dev-swc-4fc8a99f4.0",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -16,13 +16,13 @@
16
16
  "node": ">= 16.0.0"
17
17
  },
18
18
  "dependencies": {
19
- "@atlaspack/diagnostic": "2.14.5-dev-5779cd2e2.0",
20
- "@atlaspack/feature-flags": "2.25.5-dev-5779cd2e2.0",
21
- "@atlaspack/plugin": "2.14.35-dev-5779cd2e2.0",
22
- "@atlaspack/rust": "3.8.3-dev-5779cd2e2.0",
23
- "@atlaspack/source-map": "3.0.1-dev-5779cd2e2.0",
24
- "@atlaspack/types": "2.15.25-dev-5779cd2e2.0",
25
- "@atlaspack/utils": "3.0.3-dev-5779cd2e2.0",
19
+ "@atlaspack/diagnostic": "2.14.5-dev-swc-4fc8a99f4.0",
20
+ "@atlaspack/feature-flags": "2.25.5-dev-swc-4fc8a99f4.0",
21
+ "@atlaspack/plugin": "2.14.35-dev-swc-4fc8a99f4.0",
22
+ "@atlaspack/rust": "3.8.3-dev-swc-4fc8a99f4.0",
23
+ "@atlaspack/types": "2.15.25-dev-swc-4fc8a99f4.0",
24
+ "@atlaspack/utils": "3.0.3-dev-swc-4fc8a99f4.0",
25
+ "@parcel/source-map": "^2.1.1",
26
26
  "globals": "^13.2.0",
27
27
  "nullthrows": "^1.1.1",
28
28
  "outdent": "^0.8.0"
@@ -31,5 +31,5 @@
31
31
  "scripts": {
32
32
  "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
33
33
  },
34
- "gitHead": "5779cd2e2d554546c84fe2b7e4c57611975a15b2"
34
+ "gitHead": "4fc8a99f4944cddf9c65ed0cb547cba40a83488c"
35
35
  }
@@ -6,7 +6,7 @@ import {
6
6
  countLines,
7
7
  normalizeSeparators,
8
8
  } from '@atlaspack/utils';
9
- import SourceMap from '@atlaspack/source-map';
9
+ import SourceMap from '@parcel/source-map';
10
10
  import {getFeatureFlag} from '@atlaspack/feature-flags';
11
11
  import invariant from 'assert';
12
12
  import path from 'path';
@@ -229,6 +229,7 @@ export class DevPackager {
229
229
  this.parcelRequireName,
230
230
  );
231
231
  if (this.bundle.env.sourceMap && entryMap) {
232
+ // @ts-expect-error TS2551
232
233
  map.addSourceMap(entryMap, lineOffset);
233
234
  }
234
235
  }
@@ -16,7 +16,7 @@ import {
16
16
  debugTools,
17
17
  globToRegex,
18
18
  } from '@atlaspack/utils';
19
- import SourceMap from '@atlaspack/source-map';
19
+ import SourceMap from '@parcel/source-map';
20
20
  import nullthrows from 'nullthrows';
21
21
  import invariant, {AssertionError} from 'assert';
22
22
  import ThrowableDiagnostic, {
@@ -82,6 +82,15 @@ export interface OutputFormat {
82
82
  buildBundlePostlude(): [string, number];
83
83
  }
84
84
 
85
+ export type PackageResult = {
86
+ contents: string;
87
+ map: SourceMap | null | undefined;
88
+ scopeHoistingStats?: {
89
+ totalAssets: number;
90
+ wrappedAssets: number;
91
+ };
92
+ };
93
+
85
94
  export class ScopeHoistingPackager {
86
95
  options: PluginOptions;
87
96
  bundleGraph: BundleGraph<NamedBundle>;
@@ -153,10 +162,7 @@ export class ScopeHoistingPackager {
153
162
  this.globalNames = GLOBALS_BY_CONTEXT[bundle.env.context];
154
163
  }
155
164
 
156
- async package(): Promise<{
157
- contents: string;
158
- map: SourceMap | null | undefined;
159
- }> {
165
+ async package(): Promise<PackageResult> {
160
166
  await this.loadAssets();
161
167
  this.buildExportedSymbols();
162
168
 
@@ -184,6 +190,7 @@ export class ScopeHoistingPackager {
184
190
  let [content, map, lines] = this.visitAsset(asset);
185
191
 
186
192
  if (sourceMap && map) {
193
+ // @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
187
194
  sourceMap.addSourceMap(map, lineCount);
188
195
  } else if (this.bundle.env.sourceMap) {
189
196
  sourceMap = map;
@@ -319,10 +326,16 @@ export class ScopeHoistingPackager {
319
326
  }
320
327
  }
321
328
 
322
- return {
323
- contents: res,
324
- map: sourceMap,
325
- };
329
+ const result: PackageResult = {contents: res, map: sourceMap};
330
+
331
+ if (debugTools['scope-hoisting-stats']) {
332
+ result.scopeHoistingStats = {
333
+ totalAssets: this.assetOutputs.size,
334
+ wrappedAssets: this.wrappedAssets.size,
335
+ };
336
+ }
337
+
338
+ return result;
326
339
  }
327
340
 
328
341
  shouldBundleQueue(bundle: NamedBundle): boolean {
@@ -687,6 +700,7 @@ export class ScopeHoistingPackager {
687
700
  let [code, map, lines] = this.visitAsset(resolved);
688
701
  depCode += code + '\n';
689
702
  if (sourceMap && map) {
703
+ // @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
690
704
  sourceMap.addSourceMap(map, lineCount);
691
705
  }
692
706
  lineCount += lines + 1;
@@ -842,6 +856,7 @@ export class ScopeHoistingPackager {
842
856
  }
843
857
 
844
858
  if (map) {
859
+ // @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
845
860
  sourceMap.addSourceMap(map, lineCount);
846
861
  }
847
862
  }
@@ -898,6 +913,7 @@ ${code}
898
913
  if (!depCode) continue;
899
914
  code += depCode + '\n';
900
915
  if (sourceMap && map) {
916
+ // @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
901
917
  sourceMap.addSourceMap(map, lineCount);
902
918
  }
903
919
  lineCount += lines + 1;
package/src/index.ts CHANGED
@@ -1,17 +1,21 @@
1
- import type {Async} from '@atlaspack/types';
2
- import type SourceMap from '@atlaspack/source-map';
1
+ import type {Async, BundleResult} from '@atlaspack/types';
2
+ import type SourceMap from '@parcel/source-map';
3
3
  import {Packager} from '@atlaspack/plugin';
4
4
  import {
5
5
  replaceInlineReferences,
6
6
  replaceURLReferences,
7
7
  validateSchema,
8
8
  SchemaEntity,
9
+ debugTools,
9
10
  } from '@atlaspack/utils';
10
11
  import {encodeJSONKeyComponent} from '@atlaspack/diagnostic';
11
12
  import {hashString} from '@atlaspack/rust';
12
13
  import nullthrows from 'nullthrows';
13
14
  import {DevPackager} from './DevPackager';
14
- import {ScopeHoistingPackager} from './ScopeHoistingPackager';
15
+ import {
16
+ type PackageResult as ScopeHoistingPackageResult,
17
+ ScopeHoistingPackager,
18
+ } from './ScopeHoistingPackager';
15
19
 
16
20
  type JSPackagerConfig = {
17
21
  parcelRequireName: string;
@@ -91,6 +95,8 @@ export default new Packager({
91
95
  // If this is a non-module script, and there is only one asset with no dependencies,
92
96
  // then we don't need to package at all and can pass through the original code un-wrapped.
93
97
  let contents, map;
98
+ let scopeHoistingStats: ScopeHoistingPackageResult['scopeHoistingStats'];
99
+
94
100
  if (bundle.env.sourceType === 'script') {
95
101
  let entries = bundle.getEntryAssets();
96
102
  if (
@@ -103,24 +109,31 @@ export default new Packager({
103
109
  }
104
110
 
105
111
  if (contents == null) {
106
- let packager = bundle.env.shouldScopeHoist
107
- ? new ScopeHoistingPackager(
108
- options,
109
- bundleGraph,
110
- bundle,
111
- nullthrows(config).parcelRequireName,
112
- nullthrows(config).unstable_asyncBundleRuntime,
113
- nullthrows(config).unstable_manualStaticBindingExports,
114
- logger,
115
- )
116
- : new DevPackager(
117
- options,
118
- bundleGraph,
119
- bundle,
120
- nullthrows(config).parcelRequireName,
121
- );
122
-
123
- ({contents, map} = await packager.package());
112
+ if (bundle.env.shouldScopeHoist) {
113
+ let packager = new ScopeHoistingPackager(
114
+ options,
115
+ bundleGraph,
116
+ bundle,
117
+ nullthrows(config).parcelRequireName,
118
+ nullthrows(config).unstable_asyncBundleRuntime,
119
+ nullthrows(config).unstable_manualStaticBindingExports,
120
+ logger,
121
+ );
122
+
123
+ let packageResult = await packager.package();
124
+ ({contents, map} = packageResult);
125
+ scopeHoistingStats = packageResult.scopeHoistingStats;
126
+ } else {
127
+ let packager = new DevPackager(
128
+ options,
129
+ bundleGraph,
130
+ bundle,
131
+ nullthrows(config).parcelRequireName,
132
+ );
133
+
134
+ let packageResult = await packager.package();
135
+ ({contents, map} = packageResult);
136
+ }
124
137
  }
125
138
 
126
139
  contents += '\n' + (await getSourceMapSuffix(getSourceMapReference, map));
@@ -137,7 +150,7 @@ export default new Packager({
137
150
  }));
138
151
  }
139
152
 
140
- return replaceInlineReferences({
153
+ let result = await replaceInlineReferences({
141
154
  bundle,
142
155
  bundleGraph,
143
156
  contents,
@@ -148,6 +161,12 @@ export default new Packager({
148
161
  getInlineBundleContents,
149
162
  map,
150
163
  });
164
+
165
+ if (debugTools['scope-hoisting-stats']) {
166
+ return {...result, scopeHoistingStats};
167
+ }
168
+
169
+ return result;
151
170
  },
152
171
  }) as Packager<unknown, unknown>;
153
172
 
package/src/utils.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type {BundleGraph, Dependency, NamedBundle} from '@atlaspack/types';
2
- import type SourceMap from '@atlaspack/source-map';
2
+ import type SourceMap from '@parcel/source-map';
3
3
  import nullthrows from 'nullthrows';
4
4
 
5
5
  // This replaces __parcel__require__ references left by the transformer with
package/tsconfig.json CHANGED
@@ -22,9 +22,6 @@
22
22
  },
23
23
  {
24
24
  "path": "../../core/utils/tsconfig.json"
25
- },
26
- {
27
- "path": "../../core/source-map/tsconfig.json"
28
25
  }
29
26
  ]
30
27
  }