package-build-stats 8.2.1 → 8.2.3
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/package.json +1 -1
- package/src/utils/installation.utils.ts +3 -1
- package/build/common.types.d.ts +0 -26
- package/build/common.types.js +0 -1
- package/build/config/config.d.ts +0 -4
- package/build/config/config.js +0 -5
- package/build/config/makeRspackConfig.d.ts +0 -11
- package/build/config/makeRspackConfig.js +0 -170
- package/build/errors/CustomError.d.ts +0 -42
- package/build/errors/CustomError.js +0 -69
- package/build/getDependencySizeTree.d.ts +0 -6
- package/build/getDependencySizeTree.js +0 -271
- package/build/getPackageExportSizes.d.ts +0 -18
- package/build/getPackageExportSizes.js +0 -95
- package/build/getPackageStats.d.ts +0 -26
- package/build/getPackageStats.js +0 -98
- package/build/index.d.ts +0 -4
- package/build/index.js +0 -4
- package/build/utils/build.utils.d.ts +0 -51
- package/build/utils/build.utils.js +0 -269
- package/build/utils/common.utils.d.ts +0 -20
- package/build/utils/common.utils.js +0 -112
- package/build/utils/exports.utils.d.ts +0 -26
- package/build/utils/exports.utils.js +0 -192
- package/build/utils/installation.utils.d.ts +0 -9
- package/build/utils/installation.utils.js +0 -203
- package/build/utils/telemetry.utils.d.ts +0 -17
- package/build/utils/telemetry.utils.js +0 -121
package/package.json
CHANGED
|
@@ -239,7 +239,9 @@ const InstallationUtils = {
|
|
|
239
239
|
|
|
240
240
|
command = `bun add ${packageString} ${additionalPackages.join(
|
|
241
241
|
' ',
|
|
242
|
-
)}
|
|
242
|
+
)} --cache-dir=${path.join(config.tmp, 'cache', 'bun')} --${flags.join(
|
|
243
|
+
' --',
|
|
244
|
+
)}`
|
|
243
245
|
} else {
|
|
244
246
|
console.error('No valid client specified')
|
|
245
247
|
process.exit(1)
|
package/build/common.types.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun';
|
|
2
|
-
type AllOptions = {
|
|
3
|
-
customImports?: Array<string>;
|
|
4
|
-
splitCustomImports?: boolean;
|
|
5
|
-
debug?: boolean;
|
|
6
|
-
minify?: boolean;
|
|
7
|
-
esm?: boolean;
|
|
8
|
-
entryFilename?: string;
|
|
9
|
-
client?: PackageManager | PackageManager[];
|
|
10
|
-
limitConcurrency?: boolean;
|
|
11
|
-
networkConcurrency?: number;
|
|
12
|
-
additionalPackages?: Array<string>;
|
|
13
|
-
isLocal?: boolean;
|
|
14
|
-
installTimeout?: number;
|
|
15
|
-
};
|
|
16
|
-
export type BuildPackageOptions = Pick<AllOptions, 'customImports' | 'splitCustomImports' | 'debug' | 'minify'> & {
|
|
17
|
-
includeDependencySizes: boolean;
|
|
18
|
-
};
|
|
19
|
-
export type CreateEntryPointOptions = Pick<AllOptions, 'esm' | 'customImports' | 'entryFilename'>;
|
|
20
|
-
export type InstallPackageOptions = Pick<AllOptions, 'client' | 'limitConcurrency' | 'networkConcurrency' | 'additionalPackages' | 'isLocal' | 'installTimeout' | 'debug'>;
|
|
21
|
-
export type GetPackageStatsOptions = Pick<AllOptions, 'client' | 'limitConcurrency' | 'networkConcurrency' | 'debug' | 'customImports' | 'installTimeout' | 'minify'>;
|
|
22
|
-
export type Externals = {
|
|
23
|
-
externalPackages: Array<string>;
|
|
24
|
-
externalBuiltIns: Array<string>;
|
|
25
|
-
};
|
|
26
|
-
export {};
|
package/build/common.types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/build/config/config.d.ts
DELETED
package/build/config/config.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Entry, Configuration } from '@rspack/core';
|
|
2
|
-
import { Externals } from '../common.types.js';
|
|
3
|
-
type MakeRspackConfigOptions = {
|
|
4
|
-
packageName: string;
|
|
5
|
-
externals: Externals;
|
|
6
|
-
debug?: boolean;
|
|
7
|
-
minify?: boolean;
|
|
8
|
-
entry: Entry;
|
|
9
|
-
};
|
|
10
|
-
export default function makeRspackConfig({ packageName: _packageName, entry, externals, debug: _debug, minify, }: MakeRspackConfigOptions): Configuration;
|
|
11
|
-
export {};
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import autoprefixer from 'autoprefixer';
|
|
2
|
-
import escapeRegex from 'escape-string-regexp';
|
|
3
|
-
import rspack from '@rspack/core';
|
|
4
|
-
import { createRequire } from 'module';
|
|
5
|
-
const require = createRequire(import.meta.url);
|
|
6
|
-
export default function makeRspackConfig({ packageName: _packageName, entry, externals, debug: _debug, minify = true, }) {
|
|
7
|
-
const externalsRegex = makeExternalsRegex(externals.externalPackages);
|
|
8
|
-
const isExternalRequest = (request) => {
|
|
9
|
-
const isPeerDep = externals.externalPackages.length
|
|
10
|
-
? externalsRegex.test(request)
|
|
11
|
-
: false;
|
|
12
|
-
const isBuiltIn = externals.externalBuiltIns.includes(request);
|
|
13
|
-
return isPeerDep || isBuiltIn;
|
|
14
|
-
};
|
|
15
|
-
const configuration = {
|
|
16
|
-
entry: entry,
|
|
17
|
-
mode: 'production',
|
|
18
|
-
devtool: _debug ? 'source-map' : false,
|
|
19
|
-
optimization: {
|
|
20
|
-
// Use 'multiple' to create a separate runtime chunk per entry point
|
|
21
|
-
// 'single' or { name: 'runtime' } shares one runtime across all entries,
|
|
22
|
-
// which breaks tree-shaking when building many exports simultaneously
|
|
23
|
-
runtimeChunk: 'multiple',
|
|
24
|
-
realContentHash: false,
|
|
25
|
-
minimize: minify,
|
|
26
|
-
// Enable tree-shaking optimizations
|
|
27
|
-
usedExports: true, // Mark unused exports for removal
|
|
28
|
-
sideEffects: true, // Respect package.json sideEffects field
|
|
29
|
-
// Rspack automatically uses its built-in default minifiers:
|
|
30
|
-
// - SwcJsMinimizerRspackPlugin for JS (SWC-based, very fast)
|
|
31
|
-
// - LightningCssMinimizerRspackPlugin for CSS (Lightning CSS-based)
|
|
32
|
-
// See: https://rspack.rs/guide/optimization/production
|
|
33
|
-
splitChunks: {
|
|
34
|
-
cacheGroups: {
|
|
35
|
-
styles: {
|
|
36
|
-
name: 'main',
|
|
37
|
-
test: /\.css$/,
|
|
38
|
-
chunks: 'all',
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
stats: {
|
|
44
|
-
source: true,
|
|
45
|
-
modules: true,
|
|
46
|
-
nestedModules: true,
|
|
47
|
-
reasons: true,
|
|
48
|
-
depth: true,
|
|
49
|
-
chunkModules: true,
|
|
50
|
-
},
|
|
51
|
-
resolve: {
|
|
52
|
-
modules: ['node_modules'],
|
|
53
|
-
extensions: [
|
|
54
|
-
'.web.mjs',
|
|
55
|
-
'.mjs',
|
|
56
|
-
'.web.js',
|
|
57
|
-
'.js',
|
|
58
|
-
'.mjs',
|
|
59
|
-
'.json',
|
|
60
|
-
'.css',
|
|
61
|
-
'.sass',
|
|
62
|
-
'.scss',
|
|
63
|
-
],
|
|
64
|
-
mainFields: ['browser', 'module', 'main', 'style'],
|
|
65
|
-
},
|
|
66
|
-
module: {
|
|
67
|
-
rules: [
|
|
68
|
-
{
|
|
69
|
-
type: 'javascript/auto',
|
|
70
|
-
test: /\.mjs$/,
|
|
71
|
-
use: [],
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
test: /\.css$/,
|
|
75
|
-
type: 'javascript/auto',
|
|
76
|
-
use: [
|
|
77
|
-
rspack.CssExtractRspackPlugin.loader,
|
|
78
|
-
require.resolve('css-loader'),
|
|
79
|
-
],
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
test: /\.(html|svelte)$/,
|
|
83
|
-
use: {
|
|
84
|
-
loader: require.resolve('svelte-loader'),
|
|
85
|
-
options: {
|
|
86
|
-
emitCss: true,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
// {
|
|
91
|
-
// test: /\.vue$/,
|
|
92
|
-
// loader: require.resolve('vue-loader'),
|
|
93
|
-
// },
|
|
94
|
-
{
|
|
95
|
-
test: /\.(scss|sass)$/,
|
|
96
|
-
type: 'javascript/auto',
|
|
97
|
-
use: [
|
|
98
|
-
rspack.CssExtractRspackPlugin.loader,
|
|
99
|
-
require.resolve('css-loader'),
|
|
100
|
-
{
|
|
101
|
-
loader: require.resolve('postcss-loader'),
|
|
102
|
-
options: {
|
|
103
|
-
postcssOptions: {
|
|
104
|
-
plugins: [autoprefixer()],
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
require.resolve('sass-loader'),
|
|
109
|
-
],
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
test: /\.less$/,
|
|
113
|
-
type: 'javascript/auto',
|
|
114
|
-
use: [
|
|
115
|
-
rspack.CssExtractRspackPlugin.loader,
|
|
116
|
-
require.resolve('css-loader'),
|
|
117
|
-
{
|
|
118
|
-
loader: require.resolve('postcss-loader'),
|
|
119
|
-
options: {
|
|
120
|
-
postcssOptions: {
|
|
121
|
-
plugins: [
|
|
122
|
-
autoprefixer({
|
|
123
|
-
overrideBrowserslist: [
|
|
124
|
-
'last 5 Chrome versions',
|
|
125
|
-
'last 5 Firefox versions',
|
|
126
|
-
'Safari >= 8',
|
|
127
|
-
'Explorer >= 10',
|
|
128
|
-
'edge >= 12',
|
|
129
|
-
],
|
|
130
|
-
}),
|
|
131
|
-
],
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
loader: require.resolve('less-loader'),
|
|
137
|
-
options: {
|
|
138
|
-
lessOptions: {
|
|
139
|
-
javascriptEnabled: true,
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
],
|
|
144
|
-
},
|
|
145
|
-
],
|
|
146
|
-
},
|
|
147
|
-
plugins: [
|
|
148
|
-
new rspack.CssExtractRspackPlugin({
|
|
149
|
-
filename: '[name].bundle.css',
|
|
150
|
-
}),
|
|
151
|
-
],
|
|
152
|
-
node: {
|
|
153
|
-
global: false,
|
|
154
|
-
},
|
|
155
|
-
output: {
|
|
156
|
-
filename: '[name].bundle.js',
|
|
157
|
-
},
|
|
158
|
-
externals: ({ request }, callback) => isExternalRequest(request || '')
|
|
159
|
-
? callback(undefined, 'commonjs ' + request)
|
|
160
|
-
: callback(undefined),
|
|
161
|
-
};
|
|
162
|
-
return configuration;
|
|
163
|
-
}
|
|
164
|
-
function makeExternalsRegex(externals) {
|
|
165
|
-
let externalsRegex = externals
|
|
166
|
-
.map(dep => `^${escapeRegex(dep)}$|^${escapeRegex(dep)}\\/`)
|
|
167
|
-
.join('|');
|
|
168
|
-
externalsRegex = `(${externalsRegex})`;
|
|
169
|
-
return new RegExp(externalsRegex);
|
|
170
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wraps the original error with a identifiable
|
|
3
|
-
* name.
|
|
4
|
-
*/
|
|
5
|
-
declare class CustomError extends Error {
|
|
6
|
-
originalError: any;
|
|
7
|
-
extra: any;
|
|
8
|
-
constructor(name: string, originalError: Error, extra?: any);
|
|
9
|
-
toJSON(): {
|
|
10
|
-
name: string;
|
|
11
|
-
originalError: any;
|
|
12
|
-
extra: any;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export declare class BuildError extends CustomError {
|
|
16
|
-
constructor(originalError: any, extra?: any);
|
|
17
|
-
}
|
|
18
|
-
export declare class EntryPointError extends CustomError {
|
|
19
|
-
constructor(originalError: any, extra?: any);
|
|
20
|
-
}
|
|
21
|
-
export declare class InstallError extends CustomError {
|
|
22
|
-
constructor(originalError: any, extra?: any);
|
|
23
|
-
}
|
|
24
|
-
export declare class PackageNotFoundError extends CustomError {
|
|
25
|
-
constructor(originalError: any, extra?: any);
|
|
26
|
-
}
|
|
27
|
-
export declare class CLIBuildError extends CustomError {
|
|
28
|
-
constructor(originalError: any, extra?: any);
|
|
29
|
-
}
|
|
30
|
-
export declare class MinifyError extends CustomError {
|
|
31
|
-
constructor(originalError: any, extra?: any);
|
|
32
|
-
}
|
|
33
|
-
export declare class MissingDependencyError extends CustomError {
|
|
34
|
-
missingModules: Array<string>;
|
|
35
|
-
constructor(originalError: any, extra: {
|
|
36
|
-
missingModules: Array<string>;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
export declare class UnexpectedBuildError extends CustomError {
|
|
40
|
-
constructor(originalError: any, extra?: any);
|
|
41
|
-
}
|
|
42
|
-
export {};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wraps the original error with a identifiable
|
|
3
|
-
* name.
|
|
4
|
-
*/
|
|
5
|
-
class CustomError extends Error {
|
|
6
|
-
constructor(name, originalError, extra) {
|
|
7
|
-
super(name);
|
|
8
|
-
this.name = name;
|
|
9
|
-
this.originalError = originalError;
|
|
10
|
-
this.extra = extra;
|
|
11
|
-
Object.setPrototypeOf(this, CustomError.prototype);
|
|
12
|
-
}
|
|
13
|
-
toJSON() {
|
|
14
|
-
return {
|
|
15
|
-
name: this.name,
|
|
16
|
-
originalError: this.originalError,
|
|
17
|
-
extra: this.extra,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export class BuildError extends CustomError {
|
|
22
|
-
constructor(originalError, extra) {
|
|
23
|
-
super('BuildError', originalError, extra);
|
|
24
|
-
Object.setPrototypeOf(this, BuildError.prototype);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export class EntryPointError extends CustomError {
|
|
28
|
-
constructor(originalError, extra) {
|
|
29
|
-
super('EntryPointError', originalError, extra);
|
|
30
|
-
Object.setPrototypeOf(this, EntryPointError.prototype);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export class InstallError extends CustomError {
|
|
34
|
-
constructor(originalError, extra) {
|
|
35
|
-
super('InstallError', originalError, extra);
|
|
36
|
-
Object.setPrototypeOf(this, InstallError.prototype);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export class PackageNotFoundError extends CustomError {
|
|
40
|
-
constructor(originalError, extra) {
|
|
41
|
-
super('PackageNotFoundError', originalError, extra);
|
|
42
|
-
Object.setPrototypeOf(this, PackageNotFoundError.prototype);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export class CLIBuildError extends CustomError {
|
|
46
|
-
constructor(originalError, extra) {
|
|
47
|
-
super('CLIBuildError', originalError, extra);
|
|
48
|
-
Object.setPrototypeOf(this, CLIBuildError.prototype);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export class MinifyError extends CustomError {
|
|
52
|
-
constructor(originalError, extra) {
|
|
53
|
-
super('MinifyError', originalError, extra);
|
|
54
|
-
Object.setPrototypeOf(this, MinifyError.prototype);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
export class MissingDependencyError extends CustomError {
|
|
58
|
-
constructor(originalError, extra) {
|
|
59
|
-
super('MissingDependencyError', originalError, extra);
|
|
60
|
-
this.missingModules = extra.missingModules;
|
|
61
|
-
Object.setPrototypeOf(this, MissingDependencyError.prototype);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
export class UnexpectedBuildError extends CustomError {
|
|
65
|
-
constructor(originalError, extra) {
|
|
66
|
-
super('UnexpectedBuildError', originalError, extra);
|
|
67
|
-
Object.setPrototypeOf(this, UnexpectedBuildError.prototype);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
type RspackStatsCompilation = NonNullable<ReturnType<NonNullable<import('@rspack/core').Stats['toJson']>>>;
|
|
2
|
-
declare function bundleSizeTree(packageName: string, stats: RspackStatsCompilation): Promise<{
|
|
3
|
-
name: string;
|
|
4
|
-
approximateSize: number;
|
|
5
|
-
}[]>;
|
|
6
|
-
export default bundleSizeTree;
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { minify } from '@swc/core';
|
|
3
|
-
import { MinifyError } from './errors/CustomError.js';
|
|
4
|
-
import Telemetry from './utils/telemetry.utils.js';
|
|
5
|
-
import { performance } from 'perf_hooks';
|
|
6
|
-
function modulePath(identifier) {
|
|
7
|
-
// the format of module paths is
|
|
8
|
-
// '(<loader expression>!)?/path/to/module.js'
|
|
9
|
-
// OR
|
|
10
|
-
// 'javascript/esm|/some/path'
|
|
11
|
-
let loaderRegex = /.*!/;
|
|
12
|
-
const withoutLoader = identifier.replace(loaderRegex, '');
|
|
13
|
-
if (withoutLoader.includes('|'))
|
|
14
|
-
return withoutLoader.split('|')[1];
|
|
15
|
-
return withoutLoader;
|
|
16
|
-
}
|
|
17
|
-
function getUtf8Size(value) {
|
|
18
|
-
const size = Buffer.byteLength(value, 'utf8');
|
|
19
|
-
if (process.env.DEBUG_SIZE && Math.random() < 0.01) {
|
|
20
|
-
// Only debug 1% to avoid spam
|
|
21
|
-
console.log(`Size: ${size} bytes`);
|
|
22
|
-
}
|
|
23
|
-
return size;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Extract all package names from a module path to build a dependency chain.
|
|
27
|
-
* For example: /node_modules/a/node_modules/b/index.js returns ['a', 'b']
|
|
28
|
-
* This preserves the old behavior of showing nested dependencies.
|
|
29
|
-
*/
|
|
30
|
-
function extractPackageNamesFromPath(moduleFilePath) {
|
|
31
|
-
// pnpm will serve packages from a global symlink (.pnpm/package@version/node_modules/package)
|
|
32
|
-
// needs to be stripped off
|
|
33
|
-
const pnpmPrefix = '.pnpm\\' + path.sep + '.+\\' + path.sep + 'node_modules\\' + path.sep;
|
|
34
|
-
const packages = moduleFilePath.split(new RegExp('\\' + path.sep + 'node_modules\\' + path.sep + `(?:${pnpmPrefix})?`));
|
|
35
|
-
if (packages.length <= 1)
|
|
36
|
-
return [];
|
|
37
|
-
const lastSegment = packages.pop();
|
|
38
|
-
if (!lastSegment)
|
|
39
|
-
return [];
|
|
40
|
-
// Extract the package name from the last segment
|
|
41
|
-
let lastPackageName;
|
|
42
|
-
if (lastSegment[0] === '@') {
|
|
43
|
-
// package is a scoped package
|
|
44
|
-
const offset = lastSegment.indexOf(path.sep) + 1;
|
|
45
|
-
lastPackageName = lastSegment.slice(0, offset + lastSegment.slice(offset).indexOf(path.sep));
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
lastPackageName = lastSegment.slice(0, lastSegment.indexOf(path.sep));
|
|
49
|
-
}
|
|
50
|
-
packages.push(lastPackageName);
|
|
51
|
-
packages.shift(); // Remove the first empty element
|
|
52
|
-
return packages;
|
|
53
|
-
}
|
|
54
|
-
async function minifyDependencyCode(source) {
|
|
55
|
-
if (process.env.DEBUG_SIZE) {
|
|
56
|
-
console.log('Minifying dependency code...');
|
|
57
|
-
}
|
|
58
|
-
try {
|
|
59
|
-
const startTime = Date.now();
|
|
60
|
-
const result = await minify(source, {
|
|
61
|
-
compress: true,
|
|
62
|
-
mangle: true,
|
|
63
|
-
module: true, // Treat as ES module to support import/export
|
|
64
|
-
});
|
|
65
|
-
const minifyTime = Date.now() - startTime;
|
|
66
|
-
if (process.env.DEBUG_SIZE) {
|
|
67
|
-
console.log(`Minify completed in ${minifyTime}ms`);
|
|
68
|
-
}
|
|
69
|
-
return { code: result.code };
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
if (process.env.DEBUG_SIZE) {
|
|
73
|
-
console.log('Minify error occurred');
|
|
74
|
-
}
|
|
75
|
-
console.error('SWC minify error:', error);
|
|
76
|
-
throw error;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function normaliseModuleSource(mod) {
|
|
80
|
-
const identifier = mod.identifier || '';
|
|
81
|
-
const isJSON = identifier.endsWith('.json');
|
|
82
|
-
const rawSource = mod.source;
|
|
83
|
-
if (process.env.DEBUG_SIZE) {
|
|
84
|
-
console.log(`Normalising module: ${identifier}`);
|
|
85
|
-
}
|
|
86
|
-
if (rawSource === undefined || rawSource === null) {
|
|
87
|
-
if (process.env.DEBUG_SIZE) {
|
|
88
|
-
console.log(`No source for module: ${identifier}`);
|
|
89
|
-
}
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
let source;
|
|
93
|
-
if (typeof rawSource === 'string') {
|
|
94
|
-
source = rawSource;
|
|
95
|
-
if (process.env.DEBUG_SIZE) {
|
|
96
|
-
console.log(`Source is string`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else if (Buffer.isBuffer(rawSource)) {
|
|
100
|
-
source = rawSource.toString('utf8');
|
|
101
|
-
if (process.env.DEBUG_SIZE) {
|
|
102
|
-
console.log(`Source is buffer`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
source = String(rawSource);
|
|
107
|
-
if (process.env.DEBUG_SIZE) {
|
|
108
|
-
console.log(`Source is other type`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const finalSource = isJSON ? `$a$=${source}` : source;
|
|
112
|
-
if (process.env.DEBUG_SIZE) {
|
|
113
|
-
console.log(`Module source normalised (length: ${finalSource.length})`);
|
|
114
|
-
}
|
|
115
|
-
return finalSource;
|
|
116
|
-
}
|
|
117
|
-
async function bundleSizeTree(packageName, stats) {
|
|
118
|
-
const startTime = performance.now();
|
|
119
|
-
const statsTree = {
|
|
120
|
-
packageName: '<root>',
|
|
121
|
-
sources: [],
|
|
122
|
-
children: [],
|
|
123
|
-
};
|
|
124
|
-
if (!stats.modules)
|
|
125
|
-
return [];
|
|
126
|
-
// Collect modules with their sources
|
|
127
|
-
const modules = [];
|
|
128
|
-
const makeModule = (mod) => {
|
|
129
|
-
const identifier = mod.identifier || '';
|
|
130
|
-
const resolvedPath = modulePath(identifier);
|
|
131
|
-
const source = normaliseModuleSource(mod);
|
|
132
|
-
if (!source)
|
|
133
|
-
return null;
|
|
134
|
-
return {
|
|
135
|
-
path: resolvedPath,
|
|
136
|
-
source,
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
const filteredModules = stats.modules.filter(mod => { var _a; return !(((_a = mod.name) === null || _a === void 0 ? void 0 : _a.startsWith('external')) || mod.moduleType === 'runtime'); });
|
|
140
|
-
if (process.env.DEBUG_SIZE) {
|
|
141
|
-
console.log(`\n[LOCAL] ==================== ${packageName} ====================`);
|
|
142
|
-
}
|
|
143
|
-
filteredModules.forEach(mod => {
|
|
144
|
-
if (mod.modules) {
|
|
145
|
-
if (process.env.DEBUG_SIZE) {
|
|
146
|
-
console.log(`Module has ${mod.modules.length} sub-modules`);
|
|
147
|
-
}
|
|
148
|
-
mod.modules.forEach(subMod => {
|
|
149
|
-
const made = makeModule(subMod);
|
|
150
|
-
if (made)
|
|
151
|
-
modules.push(made);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
const made = makeModule(mod);
|
|
156
|
-
if (made)
|
|
157
|
-
modules.push(made);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
if (process.env.DEBUG_SIZE) {
|
|
161
|
-
console.log(`Collected ${modules.length} total modules`);
|
|
162
|
-
}
|
|
163
|
-
modules.sort((a, b) => {
|
|
164
|
-
if (a === b) {
|
|
165
|
-
return 0;
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
return a < b ? -1 : 1;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
// Build tree structure from module paths
|
|
172
|
-
modules.forEach((mod, modIndex) => {
|
|
173
|
-
const packages = extractPackageNamesFromPath(mod.path);
|
|
174
|
-
if (process.env.DEBUG_SIZE && modIndex < 5) {
|
|
175
|
-
console.log(`[${modIndex}] Extracted packages: ${packages.join(' > ')}`);
|
|
176
|
-
}
|
|
177
|
-
if (packages.length === 0) {
|
|
178
|
-
if (process.env.DEBUG_SIZE && modIndex < 5) {
|
|
179
|
-
console.log(`[${modIndex}] No packages found in path`);
|
|
180
|
-
}
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
let parent = statsTree;
|
|
184
|
-
packages.forEach(pkg => {
|
|
185
|
-
const existing = parent.children.filter(child => child.packageName === pkg);
|
|
186
|
-
if (existing.length > 0) {
|
|
187
|
-
existing[0].sources.push(mod.source);
|
|
188
|
-
if (process.env.DEBUG_SIZE && modIndex < 5) {
|
|
189
|
-
console.log(`[${modIndex}] Added to existing package: ${pkg}`);
|
|
190
|
-
}
|
|
191
|
-
parent = existing[0];
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
const newChild = {
|
|
195
|
-
path: mod.path,
|
|
196
|
-
packageName: pkg,
|
|
197
|
-
sources: [mod.source],
|
|
198
|
-
children: [],
|
|
199
|
-
};
|
|
200
|
-
parent.children.push(newChild);
|
|
201
|
-
if (process.env.DEBUG_SIZE && modIndex < 5) {
|
|
202
|
-
console.log(`[${modIndex}] Created new package: ${pkg}`);
|
|
203
|
-
}
|
|
204
|
-
parent = newChild;
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
// The old webpack implementation returned only the first-level children
|
|
209
|
-
// We need to preserve that behavior
|
|
210
|
-
const flattenedItems = statsTree.children;
|
|
211
|
-
if (process.env.DEBUG_SIZE) {
|
|
212
|
-
console.log(`\n[LOCAL] Tree structure built with ${flattenedItems.length} top-level dependencies:`);
|
|
213
|
-
}
|
|
214
|
-
const resultPromises = flattenedItems
|
|
215
|
-
.map(treeItem => ({
|
|
216
|
-
...treeItem,
|
|
217
|
-
sources: treeItem.sources.filter(source => !!source),
|
|
218
|
-
}))
|
|
219
|
-
.filter(treeItem => treeItem.sources.length)
|
|
220
|
-
.map(async (treeItem) => {
|
|
221
|
-
if (process.env.DEBUG_SIZE) {
|
|
222
|
-
console.log(`\n[LOCAL] Processing dependency: ${treeItem.packageName}`);
|
|
223
|
-
}
|
|
224
|
-
const sourceMinifiedPromises = treeItem.sources.map(async (code, idx) => {
|
|
225
|
-
const originalSize = getUtf8Size(code);
|
|
226
|
-
if (process.env.DEBUG_SIZE) {
|
|
227
|
-
console.log(`Source ${idx}: ${originalSize} bytes (original)`);
|
|
228
|
-
}
|
|
229
|
-
const minified = await minifyDependencyCode(code);
|
|
230
|
-
const minifiedSize = getUtf8Size(minified.code || '');
|
|
231
|
-
if (process.env.DEBUG_SIZE) {
|
|
232
|
-
console.log(`Source ${idx}: ${minifiedSize} bytes (minified)`);
|
|
233
|
-
}
|
|
234
|
-
return minified;
|
|
235
|
-
});
|
|
236
|
-
try {
|
|
237
|
-
const sources = await Promise.all(sourceMinifiedPromises);
|
|
238
|
-
const size = sources.reduce((acc, source, idx) => {
|
|
239
|
-
const sourceSize = getUtf8Size(source.code || '');
|
|
240
|
-
if (process.env.DEBUG_SIZE) {
|
|
241
|
-
console.log(`Total accumulation at idx ${idx}: ${acc + sourceSize} bytes`);
|
|
242
|
-
}
|
|
243
|
-
return acc + sourceSize;
|
|
244
|
-
}, 0);
|
|
245
|
-
if (process.env.DEBUG_SIZE) {
|
|
246
|
-
console.log(`Final size for ${treeItem.packageName}: ${size} bytes`);
|
|
247
|
-
}
|
|
248
|
-
return {
|
|
249
|
-
name: treeItem.packageName,
|
|
250
|
-
approximateSize: size,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
catch (error) {
|
|
254
|
-
const { message, filename } = error;
|
|
255
|
-
throw new MinifyError(error, {
|
|
256
|
-
message: message,
|
|
257
|
-
filePath: filename,
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
try {
|
|
262
|
-
const results = await Promise.all(resultPromises);
|
|
263
|
-
Telemetry.dependencySizes(packageName, startTime, true, { minifier: 'swc' });
|
|
264
|
-
return results;
|
|
265
|
-
}
|
|
266
|
-
catch (e) {
|
|
267
|
-
Telemetry.dependencySizes(packageName, startTime, false, { minifier: 'swc' }, e);
|
|
268
|
-
throw e;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
export default bundleSizeTree;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { GetPackageStatsOptions, InstallPackageOptions } from './common.types.js';
|
|
2
|
-
export declare function getAllPackageExports(packageString: string, options?: InstallPackageOptions): Promise<{
|
|
3
|
-
[key: string]: string;
|
|
4
|
-
}>;
|
|
5
|
-
export declare function getPackageExportSizes(packageString: string, options?: GetPackageStatsOptions): Promise<{
|
|
6
|
-
assets: {
|
|
7
|
-
path: string;
|
|
8
|
-
name: string;
|
|
9
|
-
type: string;
|
|
10
|
-
size: number;
|
|
11
|
-
gzip: number;
|
|
12
|
-
}[];
|
|
13
|
-
dependencySizes?: Array<{
|
|
14
|
-
name: string;
|
|
15
|
-
approximateSize: number;
|
|
16
|
-
}>;
|
|
17
|
-
ignoredMissingDependencies?: Array<string>;
|
|
18
|
-
}>;
|