package-build-stats 8.2.6 → 8.2.7
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/build/utils/build.utils.js +86 -77
- package/package.json +1 -1
- package/src/utils/build.utils.ts +107 -98
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import { randomUUID } from 'crypto';
|
|
2
3
|
import config from '../config/config.js';
|
|
3
4
|
import { rspack } from '@rspack/core';
|
|
4
5
|
import isValidNPMName from 'is-valid-npm-name';
|
|
@@ -121,10 +122,13 @@ const BuildUtils = {
|
|
|
121
122
|
},
|
|
122
123
|
async buildPackage({ name, installPath, externals, options, }) {
|
|
123
124
|
var _a;
|
|
124
|
-
const
|
|
125
|
+
const id = randomUUID().slice(0, 8);
|
|
126
|
+
const outputPath = path.join(config.tmp, 'dist', `build-${name}-${id}`);
|
|
127
|
+
fs.mkdirSync(outputPath, { recursive: true });
|
|
125
128
|
let entry = {};
|
|
126
129
|
if (options.splitCustomImports) {
|
|
127
130
|
if (!options.customImports || !options.customImports.length) {
|
|
131
|
+
fs.rmSync(outputPath, { recursive: true, force: true });
|
|
128
132
|
return { assets: [] };
|
|
129
133
|
}
|
|
130
134
|
options.customImports.forEach(importt => {
|
|
@@ -149,92 +153,97 @@ const BuildUtils = {
|
|
|
149
153
|
minify: options.minify,
|
|
150
154
|
outputPath,
|
|
151
155
|
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
else {
|
|
172
|
-
Telemetry.parseWebpackStats(name, true, jsonStatsStartTime);
|
|
173
|
-
}
|
|
174
|
-
const compilationErrors = getCompilationErrors(stats);
|
|
175
|
-
if (error && !stats) {
|
|
176
|
-
throw new BuildError(error);
|
|
177
|
-
}
|
|
178
|
-
else if (compilationErrors.length) {
|
|
179
|
-
const missingModules = BuildUtils._parseMissingModules(compilationErrors);
|
|
180
|
-
if (missingModules.length) {
|
|
181
|
-
if (missingModules.length === 1 && missingModules[0] === name) {
|
|
182
|
-
throw new EntryPointError(compilationErrors.map(err => err.message));
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
throw new MissingDependencyError(compilationErrors.map(err => err.toString()), { missingModules });
|
|
186
|
-
}
|
|
156
|
+
try {
|
|
157
|
+
const jsonStatsStartTime = performance.now();
|
|
158
|
+
let jsonStats = stats.toJson({
|
|
159
|
+
assets: true,
|
|
160
|
+
source: true,
|
|
161
|
+
chunks: false,
|
|
162
|
+
chunkGroups: false,
|
|
163
|
+
chunkModules: true,
|
|
164
|
+
modules: true,
|
|
165
|
+
nestedModules: true,
|
|
166
|
+
reasons: true,
|
|
167
|
+
depth: true,
|
|
168
|
+
errors: true,
|
|
169
|
+
entrypoints: false,
|
|
170
|
+
warnings: false,
|
|
171
|
+
});
|
|
172
|
+
if (!jsonStats) {
|
|
173
|
+
Telemetry.parseWebpackStats(name, false, jsonStatsStartTime);
|
|
174
|
+
throw new UnexpectedBuildError('Expected webpack json stats to be non-null, but was null');
|
|
187
175
|
}
|
|
188
|
-
else
|
|
189
|
-
|
|
190
|
-
|
|
176
|
+
else {
|
|
177
|
+
Telemetry.parseWebpackStats(name, true, jsonStatsStartTime);
|
|
178
|
+
}
|
|
179
|
+
const compilationErrors = getCompilationErrors(stats);
|
|
180
|
+
if (error && !stats) {
|
|
181
|
+
throw new BuildError(error);
|
|
182
|
+
}
|
|
183
|
+
else if (compilationErrors.length) {
|
|
184
|
+
const missingModules = BuildUtils._parseMissingModules(compilationErrors);
|
|
185
|
+
if (missingModules.length) {
|
|
186
|
+
if (missingModules.length === 1 && missingModules[0] === name) {
|
|
187
|
+
throw new EntryPointError(compilationErrors.map(err => err.message));
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
throw new MissingDependencyError(compilationErrors.map(err => err.toString()), { missingModules });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else if (jsonStats.errors && jsonStats.errors.length > 0) {
|
|
194
|
+
if (jsonStats.errors.some(error => error.message.includes("Unexpected character '#'"))) {
|
|
195
|
+
throw new CLIBuildError(jsonStats.errors);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
throw new BuildError(jsonStats.errors);
|
|
199
|
+
}
|
|
191
200
|
}
|
|
192
201
|
else {
|
|
193
|
-
throw new
|
|
202
|
+
throw new UnexpectedBuildError('The webpack stats object was unexpectedly empty');
|
|
194
203
|
}
|
|
195
204
|
}
|
|
196
205
|
else {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
const getAssetStats = async (asset) => {
|
|
207
|
+
const bundle = path.join(outputPath, asset.name);
|
|
208
|
+
const bundleContents = await fs.promises.readFile(bundle);
|
|
209
|
+
const gzip = gzipSync(bundleContents, {}).length;
|
|
210
|
+
const matches = asset.name.match(/(.+?)\.bundle\.(.+)$/);
|
|
211
|
+
if (!matches) {
|
|
212
|
+
throw new UnexpectedBuildError('Found an asset without the `.bundle` suffix. ' +
|
|
213
|
+
'A loader customization might be needed to recognize this asset type' +
|
|
214
|
+
asset.name);
|
|
215
|
+
}
|
|
216
|
+
const [, entryName, extension] = matches;
|
|
217
|
+
return {
|
|
218
|
+
name: entryName,
|
|
219
|
+
type: extension,
|
|
220
|
+
size: asset.size,
|
|
221
|
+
gzip,
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
const assetStatsPromises = ((_a = jsonStats === null || jsonStats === void 0 ? void 0 : jsonStats.assets) === null || _a === void 0 ? void 0 : _a.filter(asset => {
|
|
225
|
+
var _a;
|
|
226
|
+
return !((_a = asset.chunkNames) === null || _a === void 0 ? void 0 : _a.some(name => name === 'runtime' ||
|
|
227
|
+
(typeof name === 'string' && name.startsWith('runtime~'))));
|
|
228
|
+
}).filter(asset => typeof asset.name === 'string' &&
|
|
229
|
+
!asset.name.endsWith('LICENSE.txt')).map(getAssetStats)) || [];
|
|
230
|
+
const assetStats = await Promise.all(assetStatsPromises);
|
|
231
|
+
Telemetry.assetsGZIPParseTime(name, performance.now());
|
|
232
|
+
let dependencySizeResults = {};
|
|
233
|
+
if (options.includeDependencySizes) {
|
|
234
|
+
const dependencySizes = await getDependencySizes(name, jsonStats);
|
|
235
|
+
dependencySizeResults = {
|
|
236
|
+
dependencySizes,
|
|
237
|
+
};
|
|
210
238
|
}
|
|
211
|
-
const [, entryName, extension] = matches;
|
|
212
239
|
return {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
size: asset.size,
|
|
216
|
-
gzip,
|
|
217
|
-
};
|
|
218
|
-
};
|
|
219
|
-
const assetStatsPromises = ((_a = jsonStats === null || jsonStats === void 0 ? void 0 : jsonStats.assets) === null || _a === void 0 ? void 0 : _a.filter(asset => {
|
|
220
|
-
var _a;
|
|
221
|
-
return !((_a = asset.chunkNames) === null || _a === void 0 ? void 0 : _a.some(name => name === 'runtime' ||
|
|
222
|
-
(typeof name === 'string' && name.startsWith('runtime~'))));
|
|
223
|
-
}).filter(asset => typeof asset.name === 'string' &&
|
|
224
|
-
!asset.name.endsWith('LICENSE.txt')).map(getAssetStats)) || [];
|
|
225
|
-
const assetStats = await Promise.all(assetStatsPromises);
|
|
226
|
-
Telemetry.assetsGZIPParseTime(name, performance.now());
|
|
227
|
-
let dependencySizeResults = {};
|
|
228
|
-
if (options.includeDependencySizes) {
|
|
229
|
-
const dependencySizes = await getDependencySizes(name, jsonStats);
|
|
230
|
-
dependencySizeResults = {
|
|
231
|
-
dependencySizes,
|
|
240
|
+
assets: assetStats || [],
|
|
241
|
+
...dependencySizeResults,
|
|
232
242
|
};
|
|
233
243
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
};
|
|
244
|
+
}
|
|
245
|
+
finally {
|
|
246
|
+
fs.rmSync(outputPath, { recursive: true, force: true });
|
|
238
247
|
}
|
|
239
248
|
},
|
|
240
249
|
async buildPackageIgnoringMissingDeps({ name, externals, installPath, options, }) {
|
package/package.json
CHANGED
package/src/utils/build.utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
|
+
import { randomUUID } from 'crypto'
|
|
2
3
|
import config from '../config/config.js'
|
|
3
4
|
import { Entry, rspack } from '@rspack/core'
|
|
4
5
|
import isValidNPMName from 'is-valid-npm-name'
|
|
@@ -218,11 +219,14 @@ const BuildUtils = {
|
|
|
218
219
|
externals,
|
|
219
220
|
options,
|
|
220
221
|
}: BuildPackageArgs) {
|
|
221
|
-
const
|
|
222
|
+
const id = randomUUID().slice(0, 8)
|
|
223
|
+
const outputPath = path.join(config.tmp, 'dist', `build-${name}-${id}`)
|
|
224
|
+
fs.mkdirSync(outputPath, { recursive: true })
|
|
222
225
|
let entry: any = {}
|
|
223
226
|
|
|
224
227
|
if (options.splitCustomImports) {
|
|
225
228
|
if (!options.customImports || !options.customImports.length) {
|
|
229
|
+
fs.rmSync(outputPath, { recursive: true, force: true })
|
|
226
230
|
return { assets: [] }
|
|
227
231
|
}
|
|
228
232
|
options.customImports.forEach(importt => {
|
|
@@ -248,119 +252,124 @@ const BuildUtils = {
|
|
|
248
252
|
outputPath,
|
|
249
253
|
})
|
|
250
254
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (!jsonStats) {
|
|
268
|
-
Telemetry.parseWebpackStats(name, false, jsonStatsStartTime)
|
|
269
|
-
throw new UnexpectedBuildError(
|
|
270
|
-
'Expected webpack json stats to be non-null, but was null',
|
|
271
|
-
)
|
|
272
|
-
} else {
|
|
273
|
-
Telemetry.parseWebpackStats(name, true, jsonStatsStartTime)
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const compilationErrors = getCompilationErrors(stats)
|
|
277
|
-
|
|
278
|
-
if (error && !stats) {
|
|
279
|
-
throw new BuildError(error)
|
|
280
|
-
} else if (compilationErrors.length) {
|
|
281
|
-
const missingModules = BuildUtils._parseMissingModules(compilationErrors)
|
|
255
|
+
try {
|
|
256
|
+
const jsonStatsStartTime = performance.now()
|
|
257
|
+
let jsonStats = stats.toJson({
|
|
258
|
+
assets: true,
|
|
259
|
+
source: true,
|
|
260
|
+
chunks: false,
|
|
261
|
+
chunkGroups: false,
|
|
262
|
+
chunkModules: true,
|
|
263
|
+
modules: true,
|
|
264
|
+
nestedModules: true,
|
|
265
|
+
reasons: true,
|
|
266
|
+
depth: true,
|
|
267
|
+
errors: true,
|
|
268
|
+
entrypoints: false,
|
|
269
|
+
warnings: false,
|
|
270
|
+
})
|
|
282
271
|
|
|
283
|
-
if (
|
|
284
|
-
|
|
285
|
-
throw new EntryPointError(compilationErrors.map(err => err.message))
|
|
286
|
-
} else {
|
|
287
|
-
throw new MissingDependencyError(
|
|
288
|
-
compilationErrors.map(err => err.toString()),
|
|
289
|
-
{ missingModules },
|
|
290
|
-
)
|
|
291
|
-
}
|
|
292
|
-
} else if (jsonStats.errors && jsonStats.errors.length > 0) {
|
|
293
|
-
if (
|
|
294
|
-
jsonStats.errors.some(error =>
|
|
295
|
-
error.message.includes("Unexpected character '#'"),
|
|
296
|
-
)
|
|
297
|
-
) {
|
|
298
|
-
throw new CLIBuildError(jsonStats.errors)
|
|
299
|
-
} else {
|
|
300
|
-
throw new BuildError(jsonStats.errors)
|
|
301
|
-
}
|
|
302
|
-
} else {
|
|
272
|
+
if (!jsonStats) {
|
|
273
|
+
Telemetry.parseWebpackStats(name, false, jsonStatsStartTime)
|
|
303
274
|
throw new UnexpectedBuildError(
|
|
304
|
-
'
|
|
275
|
+
'Expected webpack json stats to be non-null, but was null',
|
|
305
276
|
)
|
|
277
|
+
} else {
|
|
278
|
+
Telemetry.parseWebpackStats(name, true, jsonStatsStartTime)
|
|
306
279
|
}
|
|
307
|
-
} else {
|
|
308
|
-
const getAssetStats = async (asset: RspackStatsAsset) => {
|
|
309
|
-
const bundle = path.join(outputPath, asset.name)
|
|
310
|
-
const bundleContents = await fs.promises.readFile(bundle)
|
|
311
280
|
|
|
312
|
-
|
|
313
|
-
const matches = asset.name.match(/(.+?)\.bundle\.(.+)$/)
|
|
281
|
+
const compilationErrors = getCompilationErrors(stats)
|
|
314
282
|
|
|
315
|
-
|
|
283
|
+
if (error && !stats) {
|
|
284
|
+
throw new BuildError(error)
|
|
285
|
+
} else if (compilationErrors.length) {
|
|
286
|
+
const missingModules =
|
|
287
|
+
BuildUtils._parseMissingModules(compilationErrors)
|
|
288
|
+
|
|
289
|
+
if (missingModules.length) {
|
|
290
|
+
if (missingModules.length === 1 && missingModules[0] === name) {
|
|
291
|
+
throw new EntryPointError(compilationErrors.map(err => err.message))
|
|
292
|
+
} else {
|
|
293
|
+
throw new MissingDependencyError(
|
|
294
|
+
compilationErrors.map(err => err.toString()),
|
|
295
|
+
{ missingModules },
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
} else if (jsonStats.errors && jsonStats.errors.length > 0) {
|
|
299
|
+
if (
|
|
300
|
+
jsonStats.errors.some(error =>
|
|
301
|
+
error.message.includes("Unexpected character '#'"),
|
|
302
|
+
)
|
|
303
|
+
) {
|
|
304
|
+
throw new CLIBuildError(jsonStats.errors)
|
|
305
|
+
} else {
|
|
306
|
+
throw new BuildError(jsonStats.errors)
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
316
309
|
throw new UnexpectedBuildError(
|
|
317
|
-
'
|
|
318
|
-
'A loader customization might be needed to recognize this asset type' +
|
|
319
|
-
asset.name,
|
|
310
|
+
'The webpack stats object was unexpectedly empty',
|
|
320
311
|
)
|
|
321
312
|
}
|
|
313
|
+
} else {
|
|
314
|
+
const getAssetStats = async (asset: RspackStatsAsset) => {
|
|
315
|
+
const bundle = path.join(outputPath, asset.name)
|
|
316
|
+
const bundleContents = await fs.promises.readFile(bundle)
|
|
317
|
+
|
|
318
|
+
const gzip = gzipSync(bundleContents, {}).length
|
|
319
|
+
const matches = asset.name.match(/(.+?)\.bundle\.(.+)$/)
|
|
320
|
+
|
|
321
|
+
if (!matches) {
|
|
322
|
+
throw new UnexpectedBuildError(
|
|
323
|
+
'Found an asset without the `.bundle` suffix. ' +
|
|
324
|
+
'A loader customization might be needed to recognize this asset type' +
|
|
325
|
+
asset.name,
|
|
326
|
+
)
|
|
327
|
+
}
|
|
322
328
|
|
|
323
|
-
|
|
329
|
+
const [, entryName, extension] = matches
|
|
324
330
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
331
|
+
return {
|
|
332
|
+
name: entryName,
|
|
333
|
+
type: extension,
|
|
334
|
+
size: asset.size,
|
|
335
|
+
gzip,
|
|
336
|
+
}
|
|
330
337
|
}
|
|
331
|
-
}
|
|
332
338
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
339
|
+
const assetStatsPromises =
|
|
340
|
+
jsonStats?.assets
|
|
341
|
+
?.filter(
|
|
342
|
+
asset =>
|
|
343
|
+
!asset.chunkNames?.some(
|
|
344
|
+
name =>
|
|
345
|
+
name === 'runtime' ||
|
|
346
|
+
(typeof name === 'string' && name.startsWith('runtime~')),
|
|
347
|
+
),
|
|
348
|
+
)
|
|
349
|
+
.filter(
|
|
350
|
+
asset =>
|
|
351
|
+
typeof asset.name === 'string' &&
|
|
352
|
+
!asset.name.endsWith('LICENSE.txt'),
|
|
353
|
+
)
|
|
354
|
+
.map(getAssetStats) || []
|
|
355
|
+
const assetStats = await Promise.all(assetStatsPromises)
|
|
356
|
+
Telemetry.assetsGZIPParseTime(name, performance.now())
|
|
357
|
+
|
|
358
|
+
let dependencySizeResults = {}
|
|
359
|
+
if (options.includeDependencySizes) {
|
|
360
|
+
const dependencySizes = await getDependencySizes(name, jsonStats)
|
|
361
|
+
dependencySizeResults = {
|
|
362
|
+
dependencySizes,
|
|
363
|
+
}
|
|
357
364
|
}
|
|
358
|
-
}
|
|
359
365
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
366
|
+
return {
|
|
367
|
+
assets: assetStats || [],
|
|
368
|
+
...dependencySizeResults,
|
|
369
|
+
}
|
|
363
370
|
}
|
|
371
|
+
} finally {
|
|
372
|
+
fs.rmSync(outputPath, { recursive: true, force: true })
|
|
364
373
|
}
|
|
365
374
|
},
|
|
366
375
|
async buildPackageIgnoringMissingDeps({
|