package-build-stats 7.3.8 → 8.0.0-beta.1
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/.parcelrc +37 -0
- package/package.json +96 -68
- package/src/common.types.ts +3 -10
- package/src/config/{config.ts → index.ts} +1 -0
- package/{build → src}/errors/CustomError.d.ts +0 -0
- package/{build → src}/errors/CustomError.js +1 -0
- package/src/errors/CustomError.js.map +1 -0
- package/src/fixed/parseReference.js +762 -727
- package/src/getPackageExportSizes.ts +33 -14
- package/src/getPackageStats.ts +55 -16
- package/src/typings/is-valid-npm-name.d.ts +3 -0
- package/src/utils/build.utils.ts +258 -230
- package/src/utils/common.utils.ts +138 -0
- package/src/utils/exports.utils.ts +34 -21
- package/src/utils/installation.utils.ts +28 -5
- package/src/utils/telemetry.utils.ts +0 -21
- package/LICENSE +0 -21
- package/README.md +0 -67
- package/build/common.types.d.ts +0 -34
- package/build/common.types.js +0 -2
- package/build/config/config.d.ts +0 -4
- package/build/config/config.js +0 -10
- package/build/config/makeWebpackConfig.d.ts +0 -11
- package/build/config/makeWebpackConfig.js +0 -225
- package/build/fixed/parseReference.js +0 -5353
- package/build/getDependencySizeTree.d.ts +0 -6
- package/build/getDependencySizeTree.js +0 -238
- package/build/getPackageExportSizes.d.ts +0 -44
- package/build/getPackageExportSizes.js +0 -77
- package/build/getPackageStats.d.ts +0 -73
- package/build/getPackageStats.js +0 -90
- package/build/getParseTime.d.ts +0 -8
- package/build/getParseTime.js +0 -49
- package/build/index.d.ts +0 -5
- package/build/index.js +0 -24
- package/build/utils/build.utils.d.ts +0 -84
- package/build/utils/build.utils.js +0 -261
- package/build/utils/common.utils.d.ts +0 -19
- package/build/utils/common.utils.js +0 -118
- package/build/utils/exports.utils.d.ts +0 -17
- package/build/utils/exports.utils.js +0 -238
- package/build/utils/installation.utils.d.ts +0 -8
- package/build/utils/installation.utils.js +0 -122
- package/build/utils/telemetry.utils.d.ts +0 -15
- package/build/utils/telemetry.utils.js +0 -127
- package/src/config/makeWebpackConfig.ts +0 -251
- package/src/getDependencySizeTree.ts +0 -266
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const path_1 = __importDefault(require("path"));
|
|
26
|
-
const terser_1 = __importDefault(require("terser"));
|
|
27
|
-
const esbuild = __importStar(require("esbuild"));
|
|
28
|
-
const CustomError_1 = require("./errors/CustomError");
|
|
29
|
-
const telemetry_utils_1 = __importDefault(require("./utils/telemetry.utils"));
|
|
30
|
-
const perf_hooks_1 = require("perf_hooks");
|
|
31
|
-
/**
|
|
32
|
-
* A fork of `webpack-bundle-size-analyzer`.
|
|
33
|
-
* https://github.com/robertknight/webpack-bundle-size-analyzer
|
|
34
|
-
*/
|
|
35
|
-
function modulePath(identifier) {
|
|
36
|
-
// the format of module paths is
|
|
37
|
-
// '(<loader expression>!)?/path/to/module.js'
|
|
38
|
-
let loaderRegex = /.*!/;
|
|
39
|
-
return identifier.replace(loaderRegex, '');
|
|
40
|
-
}
|
|
41
|
-
function getByteLen(normal_val) {
|
|
42
|
-
// Force string type
|
|
43
|
-
normal_val = String(normal_val);
|
|
44
|
-
let byteLen = 0;
|
|
45
|
-
for (let i = 0; i < normal_val.length; i++) {
|
|
46
|
-
const c = normal_val.charCodeAt(i);
|
|
47
|
-
byteLen +=
|
|
48
|
-
c < 1 << 7
|
|
49
|
-
? 1
|
|
50
|
-
: c < 1 << 11
|
|
51
|
-
? 2
|
|
52
|
-
: c < 1 << 16
|
|
53
|
-
? 3
|
|
54
|
-
: c < 1 << 21
|
|
55
|
-
? 4
|
|
56
|
-
: c < 1 << 26
|
|
57
|
-
? 5
|
|
58
|
-
: c < 1 << 31
|
|
59
|
-
? 6
|
|
60
|
-
: Number.NaN;
|
|
61
|
-
}
|
|
62
|
-
return byteLen;
|
|
63
|
-
}
|
|
64
|
-
async function minifyDependencyCode(source, minifier = 'terser') {
|
|
65
|
-
if (minifier === 'terser') {
|
|
66
|
-
return terser_1.default.minify(source, {
|
|
67
|
-
mangle: false,
|
|
68
|
-
compress: {
|
|
69
|
-
arrows: true,
|
|
70
|
-
booleans: true,
|
|
71
|
-
collapse_vars: true,
|
|
72
|
-
comparisons: true,
|
|
73
|
-
conditionals: true,
|
|
74
|
-
dead_code: true,
|
|
75
|
-
drop_console: false,
|
|
76
|
-
drop_debugger: true,
|
|
77
|
-
ecma: 5,
|
|
78
|
-
evaluate: true,
|
|
79
|
-
expression: false,
|
|
80
|
-
global_defs: {},
|
|
81
|
-
hoist_vars: false,
|
|
82
|
-
ie8: false,
|
|
83
|
-
if_return: true,
|
|
84
|
-
inline: true,
|
|
85
|
-
join_vars: true,
|
|
86
|
-
keep_fargs: true,
|
|
87
|
-
keep_fnames: false,
|
|
88
|
-
keep_infinity: false,
|
|
89
|
-
loops: true,
|
|
90
|
-
negate_iife: true,
|
|
91
|
-
passes: 1,
|
|
92
|
-
properties: true,
|
|
93
|
-
pure_getters: 'strict',
|
|
94
|
-
reduce_vars: true,
|
|
95
|
-
sequences: true,
|
|
96
|
-
side_effects: true,
|
|
97
|
-
switches: true,
|
|
98
|
-
top_retain: null,
|
|
99
|
-
toplevel: false,
|
|
100
|
-
typeofs: true,
|
|
101
|
-
unsafe: false,
|
|
102
|
-
unused: true,
|
|
103
|
-
},
|
|
104
|
-
output: {
|
|
105
|
-
comments: false,
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
return esbuild.transform(
|
|
111
|
-
// ESBuild Minifier doesn't auto-remove license comments from code
|
|
112
|
-
// So, we break ESBuild's heuristic for license comments match. See github.com/privatenumber/esbuild-loader/issues/87
|
|
113
|
-
source
|
|
114
|
-
.replace(/@license/g, '@silence')
|
|
115
|
-
.replace(/\/\/!/g, '//')
|
|
116
|
-
.replace(/\/\*!/g, '//'), { minify: true });
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
async function bundleSizeTree(packageName, stats, minifier) {
|
|
120
|
-
let startTime = perf_hooks_1.performance.now();
|
|
121
|
-
let statsTree = {
|
|
122
|
-
packageName: '<root>',
|
|
123
|
-
sources: [],
|
|
124
|
-
children: [],
|
|
125
|
-
};
|
|
126
|
-
if (!stats.modules)
|
|
127
|
-
return [];
|
|
128
|
-
// extract source path for each module
|
|
129
|
-
let modules = [];
|
|
130
|
-
const makeModule = (mod) => {
|
|
131
|
-
// Uglifier cannot minify a json file, hence we need
|
|
132
|
-
// to make it valid javascript syntax
|
|
133
|
-
const isJSON = mod.identifier.endsWith('.json');
|
|
134
|
-
const source = isJSON ? `$a$=${mod.source}` : mod.source;
|
|
135
|
-
return {
|
|
136
|
-
path: modulePath(mod.identifier),
|
|
137
|
-
sources: [source || ''],
|
|
138
|
-
source: source || '',
|
|
139
|
-
};
|
|
140
|
-
};
|
|
141
|
-
stats.modules
|
|
142
|
-
.filter(mod => !mod.name.startsWith('external'))
|
|
143
|
-
.forEach(mod => {
|
|
144
|
-
if (mod.modules) {
|
|
145
|
-
mod.modules.forEach(subMod => {
|
|
146
|
-
modules.push(makeModule(subMod));
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
modules.push(makeModule(mod));
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
modules.sort((a, b) => {
|
|
154
|
-
if (a === b) {
|
|
155
|
-
return 0;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
return a < b ? -1 : 1;
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
modules.forEach(mod => {
|
|
162
|
-
// pnpm will serve packages from a global symlink (.pnpm/package@verison/node_modules/package)
|
|
163
|
-
// needs to be stripped off
|
|
164
|
-
const pnpmPrefix = '.pnpm\\' + path_1.default.sep + '.+\\' + path_1.default.sep + 'node_modules\\' + path_1.default.sep;
|
|
165
|
-
let packages = mod.path.split(new RegExp('\\' + path_1.default.sep + 'node_modules\\' + path_1.default.sep + `(?:${pnpmPrefix})?`));
|
|
166
|
-
if (packages.length > 1) {
|
|
167
|
-
let lastSegment = packages.pop();
|
|
168
|
-
if (!lastSegment)
|
|
169
|
-
return;
|
|
170
|
-
let lastPackageName;
|
|
171
|
-
if (lastSegment[0] === '@') {
|
|
172
|
-
// package is a scoped package
|
|
173
|
-
let offset = lastSegment.indexOf(path_1.default.sep) + 1;
|
|
174
|
-
lastPackageName = lastSegment.slice(0, offset + lastSegment.slice(offset).indexOf(path_1.default.sep));
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
lastPackageName = lastSegment.slice(0, lastSegment.indexOf(path_1.default.sep));
|
|
178
|
-
}
|
|
179
|
-
packages.push(lastPackageName);
|
|
180
|
-
}
|
|
181
|
-
packages.shift();
|
|
182
|
-
let parent = statsTree;
|
|
183
|
-
packages.forEach(pkg => {
|
|
184
|
-
let existing = parent.children.filter(child => child.packageName === pkg);
|
|
185
|
-
if (existing.length > 0) {
|
|
186
|
-
existing[0].sources.push(mod.source);
|
|
187
|
-
parent = existing[0];
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
let newChild = {
|
|
191
|
-
path: mod.path,
|
|
192
|
-
packageName: pkg,
|
|
193
|
-
sources: [mod.source],
|
|
194
|
-
children: [],
|
|
195
|
-
};
|
|
196
|
-
parent.children.push(newChild);
|
|
197
|
-
parent = newChild;
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
const resultPromises = statsTree.children
|
|
202
|
-
.map(treeItem => (Object.assign(Object.assign({}, treeItem), { sources: treeItem.sources.filter(source => !!source) })))
|
|
203
|
-
.filter(treeItem => treeItem.sources.length)
|
|
204
|
-
.map(async (treeItem) => {
|
|
205
|
-
const sourceMinifiedPromises = treeItem.sources.map(async (code) => {
|
|
206
|
-
const start = Date.now();
|
|
207
|
-
const minified = await minifyDependencyCode(code, minifier);
|
|
208
|
-
return minified;
|
|
209
|
-
});
|
|
210
|
-
try {
|
|
211
|
-
const sources = await Promise.all(sourceMinifiedPromises);
|
|
212
|
-
const size = sources.reduce((acc, source) => {
|
|
213
|
-
return acc + getByteLen(source.code || '');
|
|
214
|
-
}, 0);
|
|
215
|
-
return {
|
|
216
|
-
name: treeItem.packageName,
|
|
217
|
-
approximateSize: size,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
catch (error) {
|
|
221
|
-
const { message, filename } = error;
|
|
222
|
-
throw new CustomError_1.MinifyError(error, {
|
|
223
|
-
message: message,
|
|
224
|
-
filePath: filename,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
try {
|
|
229
|
-
const results = await Promise.all(resultPromises);
|
|
230
|
-
telemetry_utils_1.default.dependencySizes(packageName, startTime, true, { minifier });
|
|
231
|
-
return results;
|
|
232
|
-
}
|
|
233
|
-
catch (e) {
|
|
234
|
-
telemetry_utils_1.default.dependencySizes(packageName, startTime, false, { minifier }, e);
|
|
235
|
-
throw e;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
exports.default = bundleSizeTree;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { GetPackageStatsOptions, InstallPackageOptions } from './common.types';
|
|
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
|
-
parse: {
|
|
13
|
-
baseParseTime: number;
|
|
14
|
-
scriptParseTime: number;
|
|
15
|
-
} | {
|
|
16
|
-
baseParseTime?: undefined;
|
|
17
|
-
scriptParseTime?: undefined;
|
|
18
|
-
} | null;
|
|
19
|
-
}[];
|
|
20
|
-
dependencySizes?: {
|
|
21
|
-
name: string;
|
|
22
|
-
approximateSize: number;
|
|
23
|
-
}[] | undefined;
|
|
24
|
-
} | {
|
|
25
|
-
assets: {
|
|
26
|
-
path: string;
|
|
27
|
-
name: string;
|
|
28
|
-
type: string;
|
|
29
|
-
size: number;
|
|
30
|
-
gzip: number;
|
|
31
|
-
parse: {
|
|
32
|
-
baseParseTime: number;
|
|
33
|
-
scriptParseTime: number;
|
|
34
|
-
} | {
|
|
35
|
-
baseParseTime?: undefined;
|
|
36
|
-
scriptParseTime?: undefined;
|
|
37
|
-
} | null;
|
|
38
|
-
}[];
|
|
39
|
-
dependencySizes?: {
|
|
40
|
-
name: string;
|
|
41
|
-
approximateSize: number;
|
|
42
|
-
}[] | undefined;
|
|
43
|
-
ignoredMissingDependencies: any;
|
|
44
|
-
}>;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPackageExportSizes = exports.getAllPackageExports = void 0;
|
|
7
|
-
const telemetry_utils_1 = __importDefault(require("./utils/telemetry.utils"));
|
|
8
|
-
const perf_hooks_1 = require("perf_hooks");
|
|
9
|
-
const debug = require('debug')('bp:worker');
|
|
10
|
-
const common_utils_1 = require("./utils/common.utils");
|
|
11
|
-
const exports_utils_1 = require("./utils/exports.utils");
|
|
12
|
-
const installation_utils_1 = __importDefault(require("./utils/installation.utils"));
|
|
13
|
-
const build_utils_1 = __importDefault(require("./utils/build.utils"));
|
|
14
|
-
async function installPackage(packageString, installPath, options) {
|
|
15
|
-
const { isLocal } = common_utils_1.parsePackageString(packageString);
|
|
16
|
-
await installation_utils_1.default.installPackage(packageString, installPath, {
|
|
17
|
-
isLocal,
|
|
18
|
-
client: options.client,
|
|
19
|
-
limitConcurrency: options.limitConcurrency,
|
|
20
|
-
networkConcurrency: options.networkConcurrency,
|
|
21
|
-
installTimeout: options.installTimeout,
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
async function getAllPackageExports(packageString, options = {}) {
|
|
25
|
-
const startTime = perf_hooks_1.performance.now();
|
|
26
|
-
const { name: packageName, normalPath } = common_utils_1.parsePackageString(packageString);
|
|
27
|
-
const installPath = await installation_utils_1.default.preparePath(packageName);
|
|
28
|
-
try {
|
|
29
|
-
await installPackage(packageString, installPath, options);
|
|
30
|
-
const results = await exports_utils_1.getAllExports(packageString, normalPath || installPath, packageName);
|
|
31
|
-
telemetry_utils_1.default.packageExports(packageString, startTime, true);
|
|
32
|
-
return results;
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
telemetry_utils_1.default.packageExports(packageString, startTime, false, err);
|
|
36
|
-
throw err;
|
|
37
|
-
}
|
|
38
|
-
finally {
|
|
39
|
-
await installation_utils_1.default.cleanupPath(installPath);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.getAllPackageExports = getAllPackageExports;
|
|
43
|
-
async function getPackageExportSizes(packageString, options = {
|
|
44
|
-
minifier: 'terser',
|
|
45
|
-
}) {
|
|
46
|
-
const startTime = perf_hooks_1.performance.now();
|
|
47
|
-
const { name: packageName, normalPath } = common_utils_1.parsePackageString(packageString);
|
|
48
|
-
const installPath = await installation_utils_1.default.preparePath(packageName);
|
|
49
|
-
try {
|
|
50
|
-
await installPackage(packageString, installPath, options);
|
|
51
|
-
const exportMap = await exports_utils_1.getAllExports(packageString, normalPath || installPath, packageName);
|
|
52
|
-
const exports = Object.keys(exportMap).filter(exp => !(exp === 'default'));
|
|
53
|
-
debug('Got %d exports for %s', exports.length, packageString);
|
|
54
|
-
const externals = common_utils_1.getExternals(packageName, installPath);
|
|
55
|
-
const builtDetails = await build_utils_1.default.buildPackageIgnoringMissingDeps({
|
|
56
|
-
name: packageName,
|
|
57
|
-
installPath,
|
|
58
|
-
externals,
|
|
59
|
-
options: {
|
|
60
|
-
customImports: exports,
|
|
61
|
-
splitCustomImports: true,
|
|
62
|
-
includeDependencySizes: false,
|
|
63
|
-
minifier: options.minifier || 'terser',
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
telemetry_utils_1.default.packageExportsSizes(packageString, startTime, true, options);
|
|
67
|
-
return Object.assign(Object.assign({}, builtDetails), { assets: builtDetails.assets.map(asset => (Object.assign(Object.assign({}, asset), { path: exportMap[asset.name] }))) });
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
telemetry_utils_1.default.packageExportsSizes(packageString, startTime, false, options, err);
|
|
71
|
-
throw err;
|
|
72
|
-
}
|
|
73
|
-
finally {
|
|
74
|
-
await installation_utils_1.default.cleanupPath(installPath);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.getPackageExportSizes = getPackageExportSizes;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parts of the code are inspired from the `import-cost` project
|
|
3
|
-
* @see https://github.com/wix/import-cost/blob/master/packages/import-cost/src/webpack.js
|
|
4
|
-
*/
|
|
5
|
-
import { GetPackageStatsOptions } from './common.types';
|
|
6
|
-
export default function getPackageStats(packageString: string, optionsRaw: GetPackageStatsOptions): Promise<{
|
|
7
|
-
size: number;
|
|
8
|
-
gzip: number;
|
|
9
|
-
parse: {
|
|
10
|
-
baseParseTime: number;
|
|
11
|
-
scriptParseTime: number;
|
|
12
|
-
} | {
|
|
13
|
-
baseParseTime?: undefined;
|
|
14
|
-
scriptParseTime?: undefined;
|
|
15
|
-
} | null;
|
|
16
|
-
dependencySizes?: {
|
|
17
|
-
name: string;
|
|
18
|
-
approximateSize: number;
|
|
19
|
-
}[] | undefined;
|
|
20
|
-
assets: {
|
|
21
|
-
name: string;
|
|
22
|
-
type: string;
|
|
23
|
-
size: number;
|
|
24
|
-
gzip: number;
|
|
25
|
-
parse: {
|
|
26
|
-
baseParseTime: number;
|
|
27
|
-
scriptParseTime: number;
|
|
28
|
-
} | {
|
|
29
|
-
baseParseTime?: undefined;
|
|
30
|
-
scriptParseTime?: undefined;
|
|
31
|
-
} | null;
|
|
32
|
-
}[];
|
|
33
|
-
dependencyCount?: number | undefined;
|
|
34
|
-
hasJSNext?: any;
|
|
35
|
-
hasJSModule?: any;
|
|
36
|
-
isModuleType?: boolean | undefined;
|
|
37
|
-
hasSideEffects?: any;
|
|
38
|
-
peerDependencies?: string[] | undefined;
|
|
39
|
-
} | {
|
|
40
|
-
size: number;
|
|
41
|
-
gzip: number;
|
|
42
|
-
parse: {
|
|
43
|
-
baseParseTime: number;
|
|
44
|
-
scriptParseTime: number;
|
|
45
|
-
} | {
|
|
46
|
-
baseParseTime?: undefined;
|
|
47
|
-
scriptParseTime?: undefined;
|
|
48
|
-
} | null;
|
|
49
|
-
dependencySizes?: {
|
|
50
|
-
name: string;
|
|
51
|
-
approximateSize: number;
|
|
52
|
-
}[] | undefined;
|
|
53
|
-
assets: {
|
|
54
|
-
name: string;
|
|
55
|
-
type: string;
|
|
56
|
-
size: number;
|
|
57
|
-
gzip: number;
|
|
58
|
-
parse: {
|
|
59
|
-
baseParseTime: number;
|
|
60
|
-
scriptParseTime: number;
|
|
61
|
-
} | {
|
|
62
|
-
baseParseTime?: undefined;
|
|
63
|
-
scriptParseTime?: undefined;
|
|
64
|
-
} | null;
|
|
65
|
-
}[];
|
|
66
|
-
ignoredMissingDependencies: any;
|
|
67
|
-
dependencyCount?: number | undefined;
|
|
68
|
-
hasJSNext?: any;
|
|
69
|
-
hasJSModule?: any;
|
|
70
|
-
isModuleType?: boolean | undefined;
|
|
71
|
-
hasSideEffects?: any;
|
|
72
|
-
peerDependencies?: string[] | undefined;
|
|
73
|
-
}>;
|
package/build/getPackageStats.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Parts of the code are inspired from the `import-cost` project
|
|
4
|
-
* @see https://github.com/wix/import-cost/blob/master/packages/import-cost/src/webpack.js
|
|
5
|
-
*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
const fs_1 = require("fs");
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const common_utils_1 = require("./utils/common.utils");
|
|
13
|
-
const installation_utils_1 = __importDefault(require("./utils/installation.utils"));
|
|
14
|
-
const build_utils_1 = __importDefault(require("./utils/build.utils"));
|
|
15
|
-
const CustomError_1 = require("./errors/CustomError");
|
|
16
|
-
const telemetry_utils_1 = __importDefault(require("./utils/telemetry.utils"));
|
|
17
|
-
const perf_hooks_1 = require("perf_hooks");
|
|
18
|
-
function getPackageJSONDetails(packageName, installPath) {
|
|
19
|
-
const startTime = perf_hooks_1.performance.now();
|
|
20
|
-
const packageJSONPath = path_1.default.join(installPath, 'node_modules', packageName, 'package.json');
|
|
21
|
-
return fs_1.promises.readFile(packageJSONPath, 'utf8').then((contents) => {
|
|
22
|
-
const parsedJSON = JSON.parse(contents);
|
|
23
|
-
telemetry_utils_1.default.getPackageJSONDetails(packageName, true, startTime);
|
|
24
|
-
return {
|
|
25
|
-
dependencyCount: 'dependencies' in parsedJSON
|
|
26
|
-
? Object.keys(parsedJSON.dependencies).length
|
|
27
|
-
: 0,
|
|
28
|
-
hasJSNext: parsedJSON['jsnext:main'] || false,
|
|
29
|
-
hasJSModule: parsedJSON['module'] || false,
|
|
30
|
-
isModuleType: parsedJSON['type'] === 'module',
|
|
31
|
-
hasSideEffects: 'sideEffects' in parsedJSON ? parsedJSON['sideEffects'] : true,
|
|
32
|
-
peerDependencies: 'peerDependencies' in parsedJSON
|
|
33
|
-
? Object.keys(parsedJSON.peerDependencies)
|
|
34
|
-
: [],
|
|
35
|
-
};
|
|
36
|
-
}, err => {
|
|
37
|
-
telemetry_utils_1.default.getPackageJSONDetails(packageName, false, startTime, err);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
async function getPackageStats(packageString, optionsRaw) {
|
|
41
|
-
const startTime = perf_hooks_1.performance.now();
|
|
42
|
-
const defaultMinifier = 'terser';
|
|
43
|
-
const options = Object.assign({ minifier: defaultMinifier }, optionsRaw);
|
|
44
|
-
const { name: packageName, isLocal } = common_utils_1.parsePackageString(packageString);
|
|
45
|
-
const installPath = await installation_utils_1.default.preparePath(packageName);
|
|
46
|
-
if (options.debug) {
|
|
47
|
-
console.log('Install path:', installPath);
|
|
48
|
-
}
|
|
49
|
-
try {
|
|
50
|
-
await installation_utils_1.default.installPackage(packageString, installPath, {
|
|
51
|
-
isLocal,
|
|
52
|
-
client: options.client,
|
|
53
|
-
limitConcurrency: options.limitConcurrency,
|
|
54
|
-
networkConcurrency: options.networkConcurrency,
|
|
55
|
-
installTimeout: options.installTimeout,
|
|
56
|
-
});
|
|
57
|
-
const externals = common_utils_1.getExternals(packageName, installPath);
|
|
58
|
-
const [pacakgeJSONDetails, builtDetails] = await Promise.all([
|
|
59
|
-
getPackageJSONDetails(packageName, installPath),
|
|
60
|
-
build_utils_1.default.buildPackageIgnoringMissingDeps({
|
|
61
|
-
name: packageName,
|
|
62
|
-
installPath,
|
|
63
|
-
externals,
|
|
64
|
-
options: {
|
|
65
|
-
debug: options.debug,
|
|
66
|
-
customImports: options.customImports,
|
|
67
|
-
minifier: options.minifier,
|
|
68
|
-
includeDependencySizes: true,
|
|
69
|
-
},
|
|
70
|
-
}),
|
|
71
|
-
]);
|
|
72
|
-
const hasCSSAsset = builtDetails.assets.some(asset => asset.type === 'css');
|
|
73
|
-
const mainAsset = builtDetails.assets.find(asset => asset.name === 'main' && asset.type === (hasCSSAsset ? 'css' : 'js'));
|
|
74
|
-
if (!mainAsset) {
|
|
75
|
-
throw new CustomError_1.UnexpectedBuildError('Did not find a main asset in the built bundle');
|
|
76
|
-
}
|
|
77
|
-
telemetry_utils_1.default.packageStats(packageString, true, perf_hooks_1.performance.now() - startTime, options);
|
|
78
|
-
return Object.assign(Object.assign(Object.assign({}, pacakgeJSONDetails), builtDetails), { size: mainAsset.size, gzip: mainAsset.gzip, parse: mainAsset.parse });
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
telemetry_utils_1.default.packageStats(packageString, false, perf_hooks_1.performance.now() - startTime, options);
|
|
82
|
-
throw e;
|
|
83
|
-
}
|
|
84
|
-
finally {
|
|
85
|
-
if (!options.debug) {
|
|
86
|
-
await installation_utils_1.default.cleanupPath(installPath);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
exports.default = getPackageStats;
|
package/build/getParseTime.d.ts
DELETED
package/build/getParseTime.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const vm2_1 = require("vm2");
|
|
9
|
-
const performance_now_1 = __importDefault(require("performance-now"));
|
|
10
|
-
const stats_lite_1 = __importDefault(require("stats-lite"));
|
|
11
|
-
const debug = require('debug')('bp:worker');
|
|
12
|
-
function getParseTime(currentScript, trialCount = 5) {
|
|
13
|
-
let baseVMScript, currentVMScript;
|
|
14
|
-
let baseCounter = 0;
|
|
15
|
-
let baseResults = [];
|
|
16
|
-
let currentCounter = 0;
|
|
17
|
-
let currentResults = [];
|
|
18
|
-
const baseScript = fs_1.default.readFileSync(path_1.default.join(__dirname, 'fixed', 'parseReference.js'), 'utf8');
|
|
19
|
-
try {
|
|
20
|
-
while (baseCounter++ < trialCount) {
|
|
21
|
-
baseVMScript = new vm2_1.VMScript(`${Math.random()}; ${baseScript}`);
|
|
22
|
-
const start = performance_now_1.default();
|
|
23
|
-
baseVMScript.compile();
|
|
24
|
-
const end = performance_now_1.default();
|
|
25
|
-
baseResults.push(end - start);
|
|
26
|
-
}
|
|
27
|
-
while (currentCounter++ < trialCount) {
|
|
28
|
-
currentVMScript = new vm2_1.VMScript(`${Math.random()}; ${currentScript}`);
|
|
29
|
-
const start = performance_now_1.default();
|
|
30
|
-
currentVMScript.compile();
|
|
31
|
-
const end = performance_now_1.default();
|
|
32
|
-
currentResults.push(end - start);
|
|
33
|
-
}
|
|
34
|
-
const baseMedian = stats_lite_1.default.median(baseResults);
|
|
35
|
-
const currentMedian = stats_lite_1.default.median(currentResults);
|
|
36
|
-
debug('base parse time: %d | script parse time: %d', baseMedian, currentMedian);
|
|
37
|
-
debug('base deviation: %d | script deviation: %d', stats_lite_1.default.stdev(baseResults), stats_lite_1.default.stdev(currentResults));
|
|
38
|
-
debug('parse time ratio', currentMedian / baseMedian);
|
|
39
|
-
return {
|
|
40
|
-
baseParseTime: baseMedian,
|
|
41
|
-
scriptParseTime: currentMedian,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
console.error('Failed to get parsed times, is this a valid JS file?');
|
|
46
|
-
return {};
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.default = getParseTime;
|
package/build/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { default as getPackageStats } from './getPackageStats';
|
|
2
|
-
export * from './errors/CustomError';
|
|
3
|
-
export { default as getParseTime } from './getParseTime';
|
|
4
|
-
export * from './getPackageExportSizes';
|
|
5
|
-
export { emitter as eventQueue } from './utils/telemetry.utils';
|
package/build/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.eventQueue = exports.getParseTime = exports.getPackageStats = void 0;
|
|
17
|
-
var getPackageStats_1 = require("./getPackageStats");
|
|
18
|
-
Object.defineProperty(exports, "getPackageStats", { enumerable: true, get: function () { return __importDefault(getPackageStats_1).default; } });
|
|
19
|
-
__exportStar(require("./errors/CustomError"), exports);
|
|
20
|
-
var getParseTime_1 = require("./getParseTime");
|
|
21
|
-
Object.defineProperty(exports, "getParseTime", { enumerable: true, get: function () { return __importDefault(getParseTime_1).default; } });
|
|
22
|
-
__exportStar(require("./getPackageExportSizes"), exports);
|
|
23
|
-
var telemetry_utils_1 = require("./utils/telemetry.utils");
|
|
24
|
-
Object.defineProperty(exports, "eventQueue", { enumerable: true, get: function () { return telemetry_utils_1.emitter; } });
|