package-build-stats 8.2.4 → 8.2.5

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.
@@ -14,6 +14,18 @@ function notEmpty(value) {
14
14
  function getCompilationErrors(stats) {
15
15
  return [...stats.compilation.errors].filter(notEmpty).flat();
16
16
  }
17
+ function closeCompiler(compiler) {
18
+ return new Promise((resolve, reject) => {
19
+ compiler.close(error => {
20
+ if (error) {
21
+ reject(error);
22
+ }
23
+ else {
24
+ resolve();
25
+ }
26
+ });
27
+ });
28
+ }
17
29
  const BuildUtils = {
18
30
  createEntryPoint(packageName, installPath, options) {
19
31
  const entryPath = path.join(installPath, options.entryFilename || 'index.js');
@@ -58,18 +70,24 @@ const BuildUtils = {
58
70
  minify,
59
71
  });
60
72
  const compiler = rspack(options);
61
- return new Promise(resolve => {
62
- compiler.run((error, stats) => {
63
- if (!stats) {
64
- throw new Error('stats is null');
65
- }
66
- resolve({ stats, error });
67
- if (error) {
68
- console.error(error);
69
- Telemetry.compilePackage(name, false, startTime, {}, error);
73
+ return new Promise((resolve, reject) => {
74
+ compiler.run(async (error, stats) => {
75
+ try {
76
+ if (!stats) {
77
+ throw new Error('stats is null');
78
+ }
79
+ await closeCompiler(compiler);
80
+ if (error) {
81
+ console.error(error);
82
+ Telemetry.compilePackage(name, false, startTime, {}, error);
83
+ }
84
+ else {
85
+ Telemetry.compilePackage(name, true, startTime, {});
86
+ }
87
+ resolve({ stats, error });
70
88
  }
71
- else {
72
- Telemetry.compilePackage(name, true, startTime, {});
89
+ catch (closeError) {
90
+ reject(closeError);
73
91
  }
74
92
  });
75
93
  });
@@ -198,7 +216,8 @@ const BuildUtils = {
198
216
  var _a;
199
217
  return !((_a = asset.chunkNames) === null || _a === void 0 ? void 0 : _a.some(name => name === 'runtime' ||
200
218
  (typeof name === 'string' && name.startsWith('runtime~'))));
201
- }).filter(asset => !asset.name.endsWith('LICENSE.txt')).map(getAssetStats)) || [];
219
+ }).filter(asset => typeof asset.name === 'string' &&
220
+ !asset.name.endsWith('LICENSE.txt')).map(getAssetStats)) || [];
202
221
  const assetStats = await Promise.all(assetStatsPromises);
203
222
  Telemetry.assetsGZIPParseTime(name, performance.now());
204
223
  let dependencySizeResults = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "package-build-stats",
3
- "version": "8.2.4",
3
+ "version": "8.2.5",
4
4
  "type": "module",
5
5
  "author": "Shubham Kanodia <shubham.kanodia10@gmail.com>",
6
6
  "repository": "https://github.com/pastelsky/package-build-stats",
@@ -61,6 +61,7 @@
61
61
  "@types/rimraf": "^4.0.5",
62
62
  "@types/sanitize-filename": "^1.6.3",
63
63
  "@types/semver": "^7",
64
+ "@types/server": "^1",
64
65
  "@types/yargs": "^17.0.34",
65
66
  "@vitest/coverage-v8": "^4.0.6",
66
67
  "@vitest/ui": "4.0.6",
@@ -105,6 +106,7 @@
105
106
  "sanitize-filename": "^1.6.3",
106
107
  "sass": "^1.69.0",
107
108
  "sass-loader": "^14.0.0",
109
+ "server": "^1.0.42",
108
110
  "svelte": "^4.0.0",
109
111
  "svelte-loader": "^3.1.0",
110
112
  "terser": "^5.44.0",
@@ -35,6 +35,8 @@ type CompilePackageReturn = {
35
35
  error: Error | null
36
36
  }
37
37
 
38
+ type Compiler = NonNullable<ReturnType<typeof rspack>>
39
+
38
40
  type BuildPackageArgs = {
39
41
  name: string
40
42
  installPath: string
@@ -70,6 +72,18 @@ function getCompilationErrors(stats: Stats) {
70
72
  return [...stats.compilation.errors].filter(notEmpty).flat()
71
73
  }
72
74
 
75
+ function closeCompiler(compiler: Compiler) {
76
+ return new Promise<void>((resolve, reject) => {
77
+ compiler.close(error => {
78
+ if (error) {
79
+ reject(error)
80
+ } else {
81
+ resolve()
82
+ }
83
+ })
84
+ })
85
+ }
86
+
73
87
  const BuildUtils = {
74
88
  createEntryPoint(
75
89
  packageName: string,
@@ -132,18 +146,25 @@ const BuildUtils = {
132
146
 
133
147
  const compiler = rspack(options)
134
148
 
135
- return new Promise<CompilePackageReturn>(resolve => {
136
- compiler.run((error, stats) => {
137
- if (!stats) {
138
- throw new Error('stats is null')
139
- }
140
- resolve({ stats, error })
141
-
142
- if (error) {
143
- console.error(error)
144
- Telemetry.compilePackage(name, false, startTime, {}, error)
145
- } else {
146
- Telemetry.compilePackage(name, true, startTime, {})
149
+ return new Promise<CompilePackageReturn>((resolve, reject) => {
150
+ compiler.run(async (error, stats) => {
151
+ try {
152
+ if (!stats) {
153
+ throw new Error('stats is null')
154
+ }
155
+
156
+ await closeCompiler(compiler)
157
+
158
+ if (error) {
159
+ console.error(error)
160
+ Telemetry.compilePackage(name, false, startTime, {}, error)
161
+ } else {
162
+ Telemetry.compilePackage(name, true, startTime, {})
163
+ }
164
+
165
+ resolve({ stats, error })
166
+ } catch (closeError) {
167
+ reject(closeError)
147
168
  }
148
169
  })
149
170
  })
@@ -313,7 +334,11 @@ const BuildUtils = {
313
334
  (typeof name === 'string' && name.startsWith('runtime~')),
314
335
  ),
315
336
  )
316
- .filter(asset => !asset.name.endsWith('LICENSE.txt'))
337
+ .filter(
338
+ asset =>
339
+ typeof asset.name === 'string' &&
340
+ !asset.name.endsWith('LICENSE.txt'),
341
+ )
317
342
  .map(getAssetStats) || []
318
343
  const assetStats = await Promise.all(assetStatsPromises)
319
344
  Telemetry.assetsGZIPParseTime(name, performance.now())