@atlaspack/core 2.25.2-dev-5779cd2e2.0 → 2.25.2-dev-9dac9ed3a.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/dist/Atlaspack.js CHANGED
@@ -373,7 +373,7 @@ class Atlaspack {
373
373
  requestedAssetIds: __classPrivateFieldGet(this, _Atlaspack_requestedAssetIds, "f"),
374
374
  signal,
375
375
  });
376
- let { bundleGraph, bundleInfo, changedAssets, assetRequests } = await __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").runRequest(request, { force: true });
376
+ let { bundleGraph, bundleInfo, changedAssets, assetRequests, scopeHoistingStats, } = await __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").runRequest(request, { force: true });
377
377
  __classPrivateFieldGet(this, _Atlaspack_requestedAssetIds, "f").clear();
378
378
  await (0, dumpGraphToGraphViz_1.default)(
379
379
  // @ts-expect-error TS2345
@@ -403,6 +403,7 @@ class Atlaspack {
403
403
  buildTime: 0,
404
404
  requestBundle: event.requestBundle,
405
405
  unstable_requestStats: {},
406
+ scopeHoistingStats: event.scopeHoistingStats,
406
407
  };
407
408
  }
408
409
  for (let assetId of bundleNode.value.entryAssetIds) {
@@ -424,6 +425,7 @@ class Atlaspack {
424
425
  return result;
425
426
  },
426
427
  unstable_requestStats: __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").flushStats(),
428
+ scopeHoistingStats,
427
429
  };
428
430
  // @ts-expect-error TS2345
429
431
  await __classPrivateFieldGet(this, _Atlaspack_reporterRunner, "f").report(event);
@@ -170,7 +170,7 @@ class PackagerRunner {
170
170
  return this.options.cache.get(infoKey);
171
171
  }
172
172
  async getBundleInfo(bundle, bundleGraph, configs, bundleConfigs) {
173
- let { type, contents, map } = await this.getBundleResult(bundle, bundleGraph, configs, bundleConfigs);
173
+ let { type, contents, map, scopeHoistingStats } = await this.getBundleResult(bundle, bundleGraph, configs, bundleConfigs);
174
174
  // Recompute cache keys as they may have changed due to dev dependencies.
175
175
  let cacheKey = await this.getCacheKey(bundle, bundleGraph, configs, bundleConfigs, [...this.invalidations.values()]);
176
176
  let cacheKeys = {
@@ -178,7 +178,11 @@ class PackagerRunner {
178
178
  map: PackagerRunner.getMapKey(cacheKey),
179
179
  info: PackagerRunner.getInfoKey(cacheKey),
180
180
  };
181
- return this.writeToCache(cacheKeys, type, contents, map);
181
+ let cachedResult = await this.writeToCache(cacheKeys, type, contents, map);
182
+ if (utils_1.debugTools['scope-hoisting-stats']) {
183
+ return { ...cachedResult, scopeHoistingStats };
184
+ }
185
+ return cachedResult;
182
186
  }
183
187
  async getBundleResult(bundle, bundleGraph, configs, bundleConfigs) {
184
188
  let packaged = await this.package(bundle, bundleGraph, configs, bundleConfigs);
@@ -189,6 +193,7 @@ class PackagerRunner {
189
193
  type: res.type ?? type,
190
194
  contents: res.contents,
191
195
  map,
196
+ scopeHoistingStats: packaged.scopeHoistingStats,
192
197
  };
193
198
  }
194
199
  getSourceMapReference(bundle, map) {
@@ -237,8 +242,8 @@ class PackagerRunner {
237
242
  bundle.bundleBehavior !== 'inlineIsolated') {
238
243
  throw new Error('Bundle is not inline and unable to retrieve contents');
239
244
  }
240
- let res = await this.getBundleResult((0, Bundle_1.bundleToInternalBundle)(bundle), (0, BundleGraph_1.bundleGraphToInternalBundleGraph)(bundleGraph), configs, bundleConfigs);
241
- return { contents: res.contents };
245
+ let { contents } = await this.getBundleResult((0, Bundle_1.bundleToInternalBundle)(bundle), (0, BundleGraph_1.bundleGraphToInternalBundleGraph)(bundleGraph), configs, bundleConfigs);
246
+ return { contents };
242
247
  },
243
248
  });
244
249
  }
@@ -23,8 +23,7 @@ function createAtlaspackBuildRequest(input) {
23
23
  input,
24
24
  };
25
25
  }
26
- // @ts-expect-error TS7031
27
- async function run({ input, api, options, rustAtlaspack }) {
26
+ async function run({ input, api, options, rustAtlaspack, }) {
28
27
  let { optionsRef, requestedAssetIds, signal } = input;
29
28
  let bundleGraphRequest = (0, BundleGraphRequest_1.default)({
30
29
  optionsRef,
@@ -53,8 +52,14 @@ async function run({ input, api, options, rustAtlaspack }) {
53
52
  bundleGraph,
54
53
  optionsRef,
55
54
  });
56
- let bundleInfo = await api.runRequest(writeBundlesRequest);
55
+ let { bundleInfo, scopeHoistingStats } = await api.runRequest(writeBundlesRequest);
57
56
  packagingMeasurement && packagingMeasurement.end();
58
57
  (0, utils_1.assertSignalNotAborted)(signal);
59
- return { bundleGraph, bundleInfo, changedAssets, assetRequests };
58
+ return {
59
+ bundleGraph,
60
+ bundleInfo,
61
+ changedAssets,
62
+ assetRequests,
63
+ scopeHoistingStats,
64
+ };
60
65
  }
@@ -17,15 +17,12 @@ function createPackageRequest(input) {
17
17
  input,
18
18
  };
19
19
  }
20
- // @ts-expect-error TS7031
21
20
  async function run({ input, api, farm }) {
22
21
  let { bundleGraphReference, optionsRef, bundle, useMainThread } = input;
23
22
  let runPackage = farm.createHandle('runPackage', useMainThread);
24
23
  let start = Date.now();
25
24
  let { devDeps, invalidDevDeps } = await (0, DevDepRequest_1.getDevDepRequests)(api);
26
- let { cachePath } = (0, nullthrows_1.default)(
27
- // @ts-expect-error TS2347
28
- await api.runRequest((0, AtlaspackConfigRequest_1.default)()));
25
+ let { cachePath } = (0, nullthrows_1.default)(await api.runRequest((0, AtlaspackConfigRequest_1.default)()));
29
26
  let { devDepRequests, configRequests, bundleInfo, invalidations } = (await runPackage({
30
27
  bundle,
31
28
  bundleGraphReference,
@@ -887,6 +887,7 @@ class TargetResolver {
887
887
  : descriptor.optimize !== false),
888
888
  shouldScopeHoist: shouldScopeHoist && descriptor.scopeHoist !== false,
889
889
  sourceMap: normalizeSourceMap(this.options, descriptor.sourceMap),
890
+ customEnv: descriptor.env,
890
891
  }),
891
892
  loc: (0, utils_2.toInternalSourceLocation)(this.options.projectRoot, loc),
892
893
  });
@@ -14,6 +14,7 @@ const nullthrows_1 = __importDefault(require("nullthrows"));
14
14
  const rust_1 = require("@atlaspack/rust");
15
15
  const PackageRequest_1 = require("./PackageRequest");
16
16
  const WriteBundleRequest_1 = __importDefault(require("./WriteBundleRequest"));
17
+ const utils_1 = require("@atlaspack/utils");
17
18
  function reportPackagingProgress(completeBundles, totalBundles) {
18
19
  if (!(0, feature_flags_1.getFeatureFlag)('cliProgressReportingImprovements')) {
19
20
  return;
@@ -131,8 +132,26 @@ async function run({ input, api, farm, options, }) {
131
132
  }));
132
133
  return promise.then((r) => res.set(bundle.id, r));
133
134
  }));
134
- api.storeResult(res);
135
- return res;
135
+ let result = { bundleInfo: res };
136
+ if (utils_1.debugTools['scope-hoisting-stats']) {
137
+ // Aggregate scope hoisting stats from all bundles
138
+ let aggregatedScopeHoistingStats = {
139
+ totalAssets: 0,
140
+ wrappedAssets: 0,
141
+ };
142
+ for (let bundle of bundles) {
143
+ let bundleInfo = bundleInfoMap[bundle.id];
144
+ if (bundleInfo?.scopeHoistingStats) {
145
+ aggregatedScopeHoistingStats.totalAssets +=
146
+ bundleInfo.scopeHoistingStats.totalAssets;
147
+ aggregatedScopeHoistingStats.wrappedAssets +=
148
+ bundleInfo.scopeHoistingStats.wrappedAssets;
149
+ }
150
+ }
151
+ result.scopeHoistingStats = aggregatedScopeHoistingStats;
152
+ }
153
+ api.storeResult(result);
154
+ return result;
136
155
  }
137
156
  finally {
138
157
  await dispose();
package/lib/Atlaspack.js CHANGED
@@ -431,7 +431,8 @@ class Atlaspack {
431
431
  bundleGraph,
432
432
  bundleInfo,
433
433
  changedAssets,
434
- assetRequests
434
+ assetRequests,
435
+ scopeHoistingStats
435
436
  } = await this.#requestTracker.runRequest(request, {
436
437
  force: true
437
438
  });
@@ -456,7 +457,8 @@ class Atlaspack {
456
457
  bundleGraph: event.bundleGraph,
457
458
  buildTime: 0,
458
459
  requestBundle: event.requestBundle,
459
- unstable_requestStats: {}
460
+ unstable_requestStats: {},
461
+ scopeHoistingStats: event.scopeHoistingStats
460
462
  };
461
463
  }
462
464
  for (let assetId of bundleNode.value.entryAssetIds) {
@@ -477,7 +479,8 @@ class Atlaspack {
477
479
  }
478
480
  return result;
479
481
  },
480
- unstable_requestStats: this.#requestTracker.flushStats()
482
+ unstable_requestStats: this.#requestTracker.flushStats(),
483
+ scopeHoistingStats
481
484
  };
482
485
 
483
486
  // @ts-expect-error TS2345
@@ -230,7 +230,8 @@ class PackagerRunner {
230
230
  let {
231
231
  type,
232
232
  contents,
233
- map
233
+ map,
234
+ scopeHoistingStats
234
235
  } = await this.getBundleResult(bundle, bundleGraph, configs, bundleConfigs);
235
236
 
236
237
  // Recompute cache keys as they may have changed due to dev dependencies.
@@ -240,7 +241,14 @@ class PackagerRunner {
240
241
  map: PackagerRunner.getMapKey(cacheKey),
241
242
  info: PackagerRunner.getInfoKey(cacheKey)
242
243
  };
243
- return this.writeToCache(cacheKeys, type, contents, map);
244
+ let cachedResult = await this.writeToCache(cacheKeys, type, contents, map);
245
+ if (_utils().debugTools['scope-hoisting-stats']) {
246
+ return {
247
+ ...cachedResult,
248
+ scopeHoistingStats
249
+ };
250
+ }
251
+ return cachedResult;
244
252
  }
245
253
  async getBundleResult(bundle, bundleGraph, configs, bundleConfigs) {
246
254
  let packaged = await this.package(bundle, bundleGraph, configs, bundleConfigs);
@@ -250,7 +258,8 @@ class PackagerRunner {
250
258
  return {
251
259
  type: res.type ?? type,
252
260
  contents: res.contents,
253
- map
261
+ map,
262
+ scopeHoistingStats: packaged.scopeHoistingStats
254
263
  };
255
264
  }
256
265
  getSourceMapReference(bundle, map) {
@@ -303,9 +312,11 @@ class PackagerRunner {
303
312
  if (bundle.bundleBehavior !== 'inline' && bundle.bundleBehavior !== 'inlineIsolated') {
304
313
  throw new Error('Bundle is not inline and unable to retrieve contents');
305
314
  }
306
- let res = await this.getBundleResult((0, _Bundle.bundleToInternalBundle)(bundle), (0, _BundleGraph.bundleGraphToInternalBundleGraph)(bundleGraph), configs, bundleConfigs);
315
+ let {
316
+ contents
317
+ } = await this.getBundleResult((0, _Bundle.bundleToInternalBundle)(bundle), (0, _BundleGraph.bundleGraphToInternalBundleGraph)(bundleGraph), configs, bundleConfigs);
307
318
  return {
308
- contents: res.contents
319
+ contents
309
320
  };
310
321
  }
311
322
  });
@@ -420,7 +431,7 @@ class PackagerRunner {
420
431
  let isInlineMap = bundleEnv.sourceMap && bundleEnv.sourceMap.inline;
421
432
  if ((0, _featureFlags().getFeatureFlag)('omitSourcesContentInMemory') && !isInlineMap) {
422
433
  if (!(bundleEnv.sourceMap && bundleEnv.sourceMap.inlineSources === false)) {
423
- /*
434
+ /*
424
435
  We're omitting sourcesContent during transformation to allow GC to run.
425
436
  Ensure sources are still inlined into the final source maps written to disk. UNLESS the user explicitly disabled inlineSources.
426
437
  */
@@ -30,8 +30,6 @@ function createAtlaspackBuildRequest(input) {
30
30
  input
31
31
  };
32
32
  }
33
-
34
- // @ts-expect-error TS7031
35
33
  async function run({
36
34
  input,
37
35
  api,
@@ -71,13 +69,17 @@ async function run({
71
69
  bundleGraph,
72
70
  optionsRef
73
71
  });
74
- let bundleInfo = await api.runRequest(writeBundlesRequest);
72
+ let {
73
+ bundleInfo,
74
+ scopeHoistingStats
75
+ } = await api.runRequest(writeBundlesRequest);
75
76
  packagingMeasurement && packagingMeasurement.end();
76
77
  (0, _utils.assertSignalNotAborted)(signal);
77
78
  return {
78
79
  bundleGraph,
79
80
  bundleInfo,
80
81
  changedAssets,
81
- assetRequests
82
+ assetRequests,
83
+ scopeHoistingStats
82
84
  };
83
85
  }
@@ -24,8 +24,6 @@ function createPackageRequest(input) {
24
24
  input
25
25
  };
26
26
  }
27
-
28
- // @ts-expect-error TS7031
29
27
  async function run({
30
28
  input,
31
29
  api,
@@ -45,9 +43,7 @@ async function run({
45
43
  } = await (0, _DevDepRequest.getDevDepRequests)(api);
46
44
  let {
47
45
  cachePath
48
- } = (0, _nullthrows().default)(
49
- // @ts-expect-error TS2347
50
- await api.runRequest((0, _AtlaspackConfigRequest.default)()));
46
+ } = (0, _nullthrows().default)(await api.runRequest((0, _AtlaspackConfigRequest.default)()));
51
47
  let {
52
48
  devDepRequests,
53
49
  configRequests,
@@ -830,7 +830,8 @@ class TargetResolver {
830
830
  // Libraries are not optimized by default, users must explicitly configure this.
831
831
  isLibrary ? descriptor.optimize === true : descriptor.optimize !== false),
832
832
  shouldScopeHoist: shouldScopeHoist && descriptor.scopeHoist !== false,
833
- sourceMap: normalizeSourceMap(this.options, descriptor.sourceMap)
833
+ sourceMap: normalizeSourceMap(this.options, descriptor.sourceMap),
834
+ customEnv: descriptor.env
834
835
  }),
835
836
  loc: (0, _utils2.toInternalSourceLocation)(this.options.projectRoot, loc)
836
837
  });
@@ -32,6 +32,13 @@ function _rust() {
32
32
  }
33
33
  var _PackageRequest = require("./PackageRequest");
34
34
  var _WriteBundleRequest = _interopRequireDefault(require("./WriteBundleRequest"));
35
+ function _utils() {
36
+ const data = require("@atlaspack/utils");
37
+ _utils = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
35
42
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
43
  function reportPackagingProgress(completeBundles, totalBundles) {
37
44
  if (!(0, _featureFlags().getFeatureFlag)('cliProgressReportingImprovements')) {
@@ -159,8 +166,26 @@ async function run({
159
166
  }));
160
167
  return promise.then(r => res.set(bundle.id, r));
161
168
  }));
162
- api.storeResult(res);
163
- return res;
169
+ let result = {
170
+ bundleInfo: res
171
+ };
172
+ if (_utils().debugTools['scope-hoisting-stats']) {
173
+ // Aggregate scope hoisting stats from all bundles
174
+ let aggregatedScopeHoistingStats = {
175
+ totalAssets: 0,
176
+ wrappedAssets: 0
177
+ };
178
+ for (let bundle of bundles) {
179
+ let bundleInfo = bundleInfoMap[bundle.id];
180
+ if (bundleInfo !== null && bundleInfo !== void 0 && bundleInfo.scopeHoistingStats) {
181
+ aggregatedScopeHoistingStats.totalAssets += bundleInfo.scopeHoistingStats.totalAssets;
182
+ aggregatedScopeHoistingStats.wrappedAssets += bundleInfo.scopeHoistingStats.wrappedAssets;
183
+ }
184
+ }
185
+ result.scopeHoistingStats = aggregatedScopeHoistingStats;
186
+ }
187
+ api.storeResult(result);
188
+ return result;
164
189
  } finally {
165
190
  await dispose();
166
191
  }
@@ -30,6 +30,10 @@ export type BundleInfo = {
30
30
  readonly time?: number;
31
31
  readonly cacheKeys: CacheKeyMap;
32
32
  readonly isLargeBlob: boolean;
33
+ readonly scopeHoistingStats?: {
34
+ totalAssets: number;
35
+ wrappedAssets: number;
36
+ };
33
37
  };
34
38
  type CacheKeyMap = {
35
39
  content: string;
@@ -61,6 +65,7 @@ export default class PackagerRunner {
61
65
  type: string;
62
66
  contents: Blob;
63
67
  map: string | null | undefined;
68
+ scopeHoistingStats?: BundleResult['scopeHoistingStats'];
64
69
  }>;
65
70
  getSourceMapReference(bundle: NamedBundle, map?: SourceMap | null): Async<string | null | undefined>;
66
71
  package(internalBundle: InternalBundle, bundleGraph: InternalBundleGraph, configs: Map<string, Config>, bundleConfigs: Map<string, Config>): Promise<BundleResult>;
@@ -15,6 +15,10 @@ export type AtlaspackBuildRequestResult = {
15
15
  bundleInfo: Map<string, PackagedBundleInfo>;
16
16
  changedAssets: Map<string, Asset>;
17
17
  assetRequests: Array<AssetGroup>;
18
+ scopeHoistingStats?: {
19
+ totalAssets: number;
20
+ wrappedAssets: number;
21
+ };
18
22
  };
19
23
  type RunInput<TResult> = {
20
24
  input: AtlaspackBuildRequestInput;
@@ -9,7 +9,13 @@ type WriteBundlesRequestInput = {
9
9
  bundleGraph: BundleGraph;
10
10
  optionsRef: SharedReference;
11
11
  };
12
- export type WriteBundlesRequestResult = Map<string, PackagedBundleInfo>;
12
+ export type WriteBundlesRequestResult = {
13
+ bundleInfo: Map<string, PackagedBundleInfo>;
14
+ scopeHoistingStats?: {
15
+ totalAssets: number;
16
+ wrappedAssets: number;
17
+ };
18
+ };
13
19
  type RunInput<TResult> = {
14
20
  input: WriteBundlesRequestInput;
15
21
  } & StaticRunOpts<TResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.25.2-dev-5779cd2e2.0",
3
+ "version": "2.25.2-dev-9dac9ed3a.0",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -22,22 +22,22 @@
22
22
  "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
23
23
  },
24
24
  "dependencies": {
25
- "@atlaspack/build-cache": "2.13.7-dev-5779cd2e2.0",
26
- "@atlaspack/cache": "3.2.30-dev-5779cd2e2.0",
27
- "@atlaspack/diagnostic": "2.14.5-dev-5779cd2e2.0",
28
- "@atlaspack/events": "2.14.5-dev-5779cd2e2.0",
29
- "@atlaspack/feature-flags": "2.25.5-dev-5779cd2e2.0",
30
- "@atlaspack/fs": "2.15.30-dev-5779cd2e2.0",
31
- "@atlaspack/graph": "3.5.24-dev-5779cd2e2.0",
32
- "@atlaspack/logger": "2.14.27-dev-5779cd2e2.0",
33
- "@atlaspack/package-manager": "2.14.35-dev-5779cd2e2.0",
34
- "@atlaspack/plugin": "2.14.35-dev-5779cd2e2.0",
35
- "@atlaspack/profiler": "2.14.32-dev-5779cd2e2.0",
36
- "@atlaspack/rust": "3.8.3-dev-5779cd2e2.0",
37
- "@atlaspack/source-map": "3.0.1-dev-5779cd2e2.0",
38
- "@atlaspack/types": "2.15.25-dev-5779cd2e2.0",
39
- "@atlaspack/utils": "3.0.3-dev-5779cd2e2.0",
40
- "@atlaspack/workers": "2.14.35-dev-5779cd2e2.0",
25
+ "@atlaspack/build-cache": "2.13.7-dev-9dac9ed3a.0",
26
+ "@atlaspack/cache": "3.2.30-dev-9dac9ed3a.0",
27
+ "@atlaspack/diagnostic": "2.14.5-dev-9dac9ed3a.0",
28
+ "@atlaspack/events": "2.14.5-dev-9dac9ed3a.0",
29
+ "@atlaspack/feature-flags": "2.25.5-dev-9dac9ed3a.0",
30
+ "@atlaspack/fs": "2.15.30-dev-9dac9ed3a.0",
31
+ "@atlaspack/graph": "3.5.24-dev-9dac9ed3a.0",
32
+ "@atlaspack/logger": "2.14.27-dev-9dac9ed3a.0",
33
+ "@atlaspack/package-manager": "2.14.35-dev-9dac9ed3a.0",
34
+ "@atlaspack/plugin": "2.14.35-dev-9dac9ed3a.0",
35
+ "@atlaspack/profiler": "2.14.32-dev-9dac9ed3a.0",
36
+ "@atlaspack/rust": "3.8.3-dev-9dac9ed3a.0",
37
+ "@atlaspack/source-map": "3.0.1-dev-9dac9ed3a.0",
38
+ "@atlaspack/types": "2.15.25-dev-9dac9ed3a.0",
39
+ "@atlaspack/utils": "3.0.3-dev-9dac9ed3a.0",
40
+ "@atlaspack/workers": "2.14.35-dev-9dac9ed3a.0",
41
41
  "@mischnic/json-sourcemap": "^0.1.0",
42
42
  "base-x": "^3.0.8",
43
43
  "browserslist": "^4.6.6",
@@ -50,7 +50,7 @@
50
50
  "semver": "^7.5.2"
51
51
  },
52
52
  "devDependencies": {
53
- "@atlaspack/babel-register": "2.14.5-dev-5779cd2e2.0",
53
+ "@atlaspack/babel-register": "2.14.5-dev-9dac9ed3a.0",
54
54
  "@types/node": ">= 18",
55
55
  "graphviz": "^0.0.9",
56
56
  "jest-diff": "*",
@@ -61,5 +61,5 @@
61
61
  "./src/serializerCore.js": "./src/serializerCore.browser.js"
62
62
  },
63
63
  "type": "commonjs",
64
- "gitHead": "5779cd2e2d554546c84fe2b7e4c57611975a15b2"
64
+ "gitHead": "9dac9ed3ab18934ba96e184638b45e9f171ecfc7"
65
65
  }
package/src/Atlaspack.ts CHANGED
@@ -427,8 +427,13 @@ export default class Atlaspack {
427
427
  signal,
428
428
  });
429
429
 
430
- let {bundleGraph, bundleInfo, changedAssets, assetRequests} =
431
- await this.#requestTracker.runRequest(request, {force: true});
430
+ let {
431
+ bundleGraph,
432
+ bundleInfo,
433
+ changedAssets,
434
+ assetRequests,
435
+ scopeHoistingStats,
436
+ } = await this.#requestTracker.runRequest(request, {force: true});
432
437
 
433
438
  this.#requestedAssetIds.clear();
434
439
 
@@ -479,6 +484,7 @@ export default class Atlaspack {
479
484
  buildTime: 0,
480
485
  requestBundle: event.requestBundle,
481
486
  unstable_requestStats: {},
487
+ scopeHoistingStats: event.scopeHoistingStats,
482
488
  };
483
489
  }
484
490
 
@@ -505,6 +511,7 @@ export default class Atlaspack {
505
511
  return result;
506
512
  },
507
513
  unstable_requestStats: this.#requestTracker.flushStats(),
514
+ scopeHoistingStats,
508
515
  };
509
516
 
510
517
  // @ts-expect-error TS2345
@@ -24,7 +24,7 @@ import type {DevDepSpecifier} from './requests/DevDepRequest';
24
24
 
25
25
  import invariant from 'assert';
26
26
  import {createBuildCache} from '@atlaspack/build-cache';
27
- import {blobToStream, TapStream} from '@atlaspack/utils';
27
+ import {blobToStream, debugTools, TapStream} from '@atlaspack/utils';
28
28
  import {PluginLogger} from '@atlaspack/logger';
29
29
  import ThrowableDiagnostic, {errorToDiagnostic} from '@atlaspack/diagnostic';
30
30
  import {Readable} from 'stream';
@@ -87,6 +87,10 @@ export type BundleInfo = {
87
87
  readonly time?: number;
88
88
  readonly cacheKeys: CacheKeyMap;
89
89
  readonly isLargeBlob: boolean;
90
+ readonly scopeHoistingStats?: {
91
+ totalAssets: number;
92
+ wrappedAssets: number;
93
+ };
90
94
  };
91
95
 
92
96
  type CacheKeyMap = {
@@ -313,7 +317,7 @@ export default class PackagerRunner {
313
317
  configs: Map<string, Config>,
314
318
  bundleConfigs: Map<string, Config>,
315
319
  ): Promise<BundleInfo> {
316
- let {type, contents, map} = await this.getBundleResult(
320
+ let {type, contents, map, scopeHoistingStats} = await this.getBundleResult(
317
321
  bundle,
318
322
  bundleGraph,
319
323
  configs,
@@ -334,7 +338,13 @@ export default class PackagerRunner {
334
338
  info: PackagerRunner.getInfoKey(cacheKey),
335
339
  };
336
340
 
337
- return this.writeToCache(cacheKeys, type, contents, map);
341
+ let cachedResult = await this.writeToCache(cacheKeys, type, contents, map);
342
+
343
+ if (debugTools['scope-hoisting-stats']) {
344
+ return {...cachedResult, scopeHoistingStats};
345
+ }
346
+
347
+ return cachedResult;
338
348
  }
339
349
 
340
350
  async getBundleResult(
@@ -346,6 +356,7 @@ export default class PackagerRunner {
346
356
  type: string;
347
357
  contents: Blob;
348
358
  map: string | null | undefined;
359
+ scopeHoistingStats?: BundleResult['scopeHoistingStats'];
349
360
  }> {
350
361
  let packaged = await this.package(
351
362
  bundle,
@@ -370,6 +381,7 @@ export default class PackagerRunner {
370
381
  type: res.type ?? type,
371
382
  contents: res.contents,
372
383
  map,
384
+ scopeHoistingStats: packaged.scopeHoistingStats,
373
385
  };
374
386
  }
375
387
 
@@ -441,14 +453,14 @@ export default class PackagerRunner {
441
453
  );
442
454
  }
443
455
 
444
- let res = await this.getBundleResult(
456
+ let {contents} = await this.getBundleResult(
445
457
  bundleToInternalBundle(bundle),
446
458
  bundleGraphToInternalBundleGraph(bundleGraph),
447
459
  configs,
448
460
  bundleConfigs,
449
461
  );
450
462
 
451
- return {contents: res.contents};
463
+ return {contents};
452
464
  },
453
465
  });
454
466
  } catch (e: any) {
@@ -621,7 +633,7 @@ export default class PackagerRunner {
621
633
  if (
622
634
  !(bundleEnv.sourceMap && bundleEnv.sourceMap.inlineSources === false)
623
635
  ) {
624
- /*
636
+ /*
625
637
  We're omitting sourcesContent during transformation to allow GC to run.
626
638
  Ensure sources are still inlined into the final source maps written to disk. UNLESS the user explicitly disabled inlineSources.
627
639
  */
@@ -32,6 +32,10 @@ export type AtlaspackBuildRequestResult = {
32
32
  bundleInfo: Map<string, PackagedBundleInfo>;
33
33
  changedAssets: Map<string, Asset>;
34
34
  assetRequests: Array<AssetGroup>;
35
+ scopeHoistingStats?: {
36
+ totalAssets: number;
37
+ wrappedAssets: number;
38
+ };
35
39
  };
36
40
 
37
41
  type RunInput<TResult> = {
@@ -58,8 +62,12 @@ export default function createAtlaspackBuildRequest(
58
62
  };
59
63
  }
60
64
 
61
- // @ts-expect-error TS7031
62
- async function run({input, api, options, rustAtlaspack}) {
65
+ async function run({
66
+ input,
67
+ api,
68
+ options,
69
+ rustAtlaspack,
70
+ }: RunInput<AtlaspackBuildRequestResult>) {
63
71
  let {optionsRef, requestedAssetIds, signal} = input;
64
72
 
65
73
  let bundleGraphRequest = createBundleGraphRequest({
@@ -102,9 +110,16 @@ async function run({input, api, options, rustAtlaspack}) {
102
110
  optionsRef,
103
111
  });
104
112
 
105
- let bundleInfo = await api.runRequest(writeBundlesRequest);
113
+ let {bundleInfo, scopeHoistingStats} =
114
+ await api.runRequest(writeBundlesRequest);
106
115
  packagingMeasurement && packagingMeasurement.end();
107
116
  assertSignalNotAborted(signal);
108
117
 
109
- return {bundleGraph, bundleInfo, changedAssets, assetRequests};
118
+ return {
119
+ bundleGraph,
120
+ bundleInfo,
121
+ changedAssets,
122
+ assetRequests,
123
+ scopeHoistingStats,
124
+ };
110
125
  }
@@ -46,15 +46,13 @@ export function createPackageRequest(
46
46
  };
47
47
  }
48
48
 
49
- // @ts-expect-error TS7031
50
- async function run({input, api, farm}) {
49
+ async function run({input, api, farm}: RunInput<BundleInfo>) {
51
50
  let {bundleGraphReference, optionsRef, bundle, useMainThread} = input;
52
51
  let runPackage = farm.createHandle('runPackage', useMainThread);
53
52
 
54
53
  let start = Date.now();
55
54
  let {devDeps, invalidDevDeps} = await getDevDepRequests(api);
56
55
  let {cachePath} = nullthrows(
57
- // @ts-expect-error TS2347
58
56
  await api.runRequest<null, ConfigAndCachePath>(
59
57
  createAtlaspackConfigRequest(),
60
58
  ),
@@ -1151,6 +1151,7 @@ export class TargetResolver {
1151
1151
  shouldScopeHoist:
1152
1152
  shouldScopeHoist && descriptor.scopeHoist !== false,
1153
1153
  sourceMap: normalizeSourceMap(this.options, descriptor.sourceMap),
1154
+ customEnv: descriptor.env,
1154
1155
  }),
1155
1156
  loc: toInternalSourceLocation(this.options.projectRoot, loc),
1156
1157
  });