@atlaspack/packager-js 2.23.5-dev-9bc89ddee.0 → 2.23.5-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.
@@ -235,10 +235,14 @@ class ScopeHoistingPackager {
235
235
  sourceMap.addSourceMap(map, lineCount);
236
236
  }
237
237
  }
238
- return {
239
- contents: res,
240
- map: sourceMap,
241
- };
238
+ const result = { contents: res, map: sourceMap };
239
+ if (utils_1.debugTools['scope-hoisting-stats']) {
240
+ result.scopeHoistingStats = {
241
+ totalAssets: this.assetOutputs.size,
242
+ wrappedAssets: this.wrappedAssets.size,
243
+ };
244
+ }
245
+ return result;
242
246
  }
243
247
  shouldBundleQueue(bundle) {
244
248
  let referencingBundles = this.bundleGraph.getReferencingBundles(bundle);
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) {
@@ -253,10 +253,17 @@ class ScopeHoistingPackager {
253
253
  sourceMap.addSourceMap(map, lineCount);
254
254
  }
255
255
  }
256
- return {
256
+ const result = {
257
257
  contents: res,
258
258
  map: sourceMap
259
259
  };
260
+ if (_utils().debugTools['scope-hoisting-stats']) {
261
+ result.scopeHoistingStats = {
262
+ totalAssets: this.assetOutputs.size,
263
+ wrappedAssets: this.wrappedAssets.size
264
+ };
265
+ }
266
+ return result;
260
267
  }
261
268
  shouldBundleQueue(bundle) {
262
269
  let referencingBundles = this.bundleGraph.getReferencingBundles(bundle);
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) {
@@ -4,6 +4,14 @@ 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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/packager-js",
3
- "version": "2.23.5-dev-9bc89ddee.0",
3
+ "version": "2.23.5-dev-9dac9ed3a.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-9bc89ddee.0",
20
- "@atlaspack/feature-flags": "2.25.5-dev-9bc89ddee.0",
21
- "@atlaspack/plugin": "2.14.35-dev-9bc89ddee.0",
22
- "@atlaspack/rust": "3.8.3-dev-9bc89ddee.0",
23
- "@atlaspack/source-map": "3.0.1-dev-9bc89ddee.0",
24
- "@atlaspack/types": "2.15.25-dev-9bc89ddee.0",
25
- "@atlaspack/utils": "3.0.3-dev-9bc89ddee.0",
19
+ "@atlaspack/diagnostic": "2.14.5-dev-9dac9ed3a.0",
20
+ "@atlaspack/feature-flags": "2.25.5-dev-9dac9ed3a.0",
21
+ "@atlaspack/plugin": "2.14.35-dev-9dac9ed3a.0",
22
+ "@atlaspack/rust": "3.8.3-dev-9dac9ed3a.0",
23
+ "@atlaspack/source-map": "3.0.1-dev-9dac9ed3a.0",
24
+ "@atlaspack/types": "2.15.25-dev-9dac9ed3a.0",
25
+ "@atlaspack/utils": "3.0.3-dev-9dac9ed3a.0",
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": "9bc89ddeed68b29ffa09a0e3a0525923572853e6"
34
+ "gitHead": "9dac9ed3ab18934ba96e184638b45e9f171ecfc7"
35
35
  }
@@ -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
 
@@ -319,10 +325,16 @@ export class ScopeHoistingPackager {
319
325
  }
320
326
  }
321
327
 
322
- return {
323
- contents: res,
324
- map: sourceMap,
325
- };
328
+ const result: PackageResult = {contents: res, map: sourceMap};
329
+
330
+ if (debugTools['scope-hoisting-stats']) {
331
+ result.scopeHoistingStats = {
332
+ totalAssets: this.assetOutputs.size,
333
+ wrappedAssets: this.wrappedAssets.size,
334
+ };
335
+ }
336
+
337
+ return result;
326
338
  }
327
339
 
328
340
  shouldBundleQueue(bundle: NamedBundle): boolean {
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type {Async} from '@atlaspack/types';
1
+ import type {Async, BundleResult} from '@atlaspack/types';
2
2
  import type SourceMap from '@atlaspack/source-map';
3
3
  import {Packager} from '@atlaspack/plugin';
4
4
  import {
@@ -6,12 +6,16 @@ import {
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