package-build-stats 7.3.8 → 8.0.0-beta.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.
Files changed (74) hide show
  1. package/.parcelrc +37 -0
  2. package/build/common.types.d.ts +3 -8
  3. package/build/common.types.d.ts.map +1 -0
  4. package/build/common.types.js +1 -0
  5. package/build/common.types.js.map +1 -0
  6. package/build/config/{config.d.ts → index.d.ts} +2 -0
  7. package/build/config/index.d.ts.map +1 -0
  8. package/build/config/{config.js → index.js} +2 -0
  9. package/build/config/index.js.map +1 -0
  10. package/build/errors/CustomError.d.ts +1 -0
  11. package/build/errors/CustomError.d.ts.map +1 -0
  12. package/build/errors/CustomError.js +1 -0
  13. package/build/errors/CustomError.js.map +1 -0
  14. package/build/fixed/fixed/parseReference.js +5388 -0
  15. package/build/fixed/parseReference.js +762 -727
  16. package/build/getPackageExportSizes.d.ts +5 -29
  17. package/build/getPackageExportSizes.d.ts.map +1 -0
  18. package/build/getPackageExportSizes.js +18 -10
  19. package/build/getPackageExportSizes.js.map +1 -0
  20. package/build/getPackageStats.d.ts +13 -54
  21. package/build/getPackageStats.d.ts.map +1 -0
  22. package/build/getPackageStats.js +30 -7
  23. package/build/getPackageStats.js.map +1 -0
  24. package/build/getParseTime.d.ts +1 -0
  25. package/build/getParseTime.d.ts.map +1 -0
  26. package/build/getParseTime.js +5 -4
  27. package/build/getParseTime.js.map +1 -0
  28. package/build/index.d.ts +1 -0
  29. package/build/index.d.ts.map +1 -0
  30. package/build/index.js +1 -0
  31. package/build/index.js.map +1 -0
  32. package/build/utils/build.utils.d.ts +39 -69
  33. package/build/utils/build.utils.d.ts.map +1 -0
  34. package/build/utils/build.utils.js +177 -159
  35. package/build/utils/build.utils.js.map +1 -0
  36. package/build/utils/common.utils.d.ts +22 -0
  37. package/build/utils/common.utils.d.ts.map +1 -0
  38. package/build/utils/common.utils.js +94 -1
  39. package/build/utils/common.utils.js.map +1 -0
  40. package/build/utils/exports.utils.d.ts +1 -0
  41. package/build/utils/exports.utils.d.ts.map +1 -0
  42. package/build/utils/exports.utils.js +35 -23
  43. package/build/utils/exports.utils.js.map +1 -0
  44. package/build/utils/installation.utils.d.ts +1 -0
  45. package/build/utils/installation.utils.d.ts.map +1 -0
  46. package/build/utils/installation.utils.js +25 -7
  47. package/build/utils/installation.utils.js.map +1 -0
  48. package/build/utils/telemetry.utils.d.ts +1 -2
  49. package/build/utils/telemetry.utils.d.ts.map +1 -0
  50. package/build/utils/telemetry.utils.js +7 -20
  51. package/build/utils/telemetry.utils.js.map +1 -0
  52. package/package.json +75 -73
  53. package/src/common.types.ts +3 -10
  54. package/src/config/{config.ts → index.ts} +1 -0
  55. package/src/errors/CustomError.d.ts +42 -0
  56. package/src/errors/CustomError.js +81 -0
  57. package/src/errors/CustomError.js.map +1 -0
  58. package/src/fixed/parseReference.js +762 -727
  59. package/src/getPackageExportSizes.ts +33 -14
  60. package/src/getPackageStats.ts +55 -16
  61. package/src/typings/is-valid-npm-name.d.ts +3 -0
  62. package/src/utils/build.utils.ts +258 -230
  63. package/src/utils/common.utils.ts +138 -0
  64. package/src/utils/exports.utils.ts +34 -21
  65. package/src/utils/installation.utils.ts +28 -5
  66. package/src/utils/telemetry.utils.ts +0 -21
  67. package/LICENSE +0 -21
  68. package/README.md +0 -67
  69. package/build/config/makeWebpackConfig.d.ts +0 -11
  70. package/build/config/makeWebpackConfig.js +0 -225
  71. package/build/getDependencySizeTree.d.ts +0 -6
  72. package/build/getDependencySizeTree.js +0 -238
  73. package/src/config/makeWebpackConfig.ts +0 -251
  74. package/src/getDependencySizeTree.ts +0 -266
@@ -1,225 +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 autoprefixer_1 = __importDefault(require("autoprefixer"));
7
- const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
8
- const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
9
- const csso_webpack_plugin_1 = __importDefault(require("csso-webpack-plugin"));
10
- const write_file_webpack_plugin_1 = __importDefault(require("write-file-webpack-plugin"));
11
- const log = require('debug')('bp:webpack');
12
- const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
13
- const builtin_modules_1 = __importDefault(require("builtin-modules"));
14
- const webpack_1 = __importDefault(require("webpack"));
15
- const esbuild_loader_1 = require("esbuild-loader");
16
- // @ts-ignore
17
- const plugin_1 = __importDefault(require("vue-loader/lib/plugin"));
18
- function makeWebpackConfig({ packageName, entry, externals, debug, minifier, }) {
19
- const externalsRegex = makeExternalsRegex(externals.externalPackages);
20
- const isExternalRequest = (request) => {
21
- const isPeerDep = externals.externalPackages.length
22
- ? externalsRegex.test(request)
23
- : false;
24
- const isBuiltIn = externals.externalBuiltIns.includes(request);
25
- return isPeerDep || isBuiltIn;
26
- };
27
- log('external packages %o', externalsRegex);
28
- const builtInNode = {};
29
- builtin_modules_1.default.forEach(mod => {
30
- builtInNode[mod] = 'empty';
31
- });
32
- builtInNode['setImmediate'] = false;
33
- builtInNode['console'] = false;
34
- builtInNode['process'] = false;
35
- builtInNode['Buffer'] = false;
36
- // Don't mark an import as built in if it is the name of the package itself
37
- // eg. `events`
38
- if (builtInNode[packageName]) {
39
- builtInNode[packageName] = false;
40
- }
41
- // @ts-ignore
42
- // @ts-ignore
43
- // @ts-ignore
44
- return {
45
- entry: entry,
46
- mode: 'production',
47
- // bail: true,
48
- optimization: {
49
- namedChunks: true,
50
- runtimeChunk: { name: 'runtime' },
51
- minimize: true,
52
- splitChunks: {
53
- cacheGroups: {
54
- styles: {
55
- name: 'main',
56
- test: /\.css$/,
57
- chunks: 'all',
58
- enforce: true,
59
- },
60
- },
61
- },
62
- // @ts-ignore: Appears that the library CssoWebpackPlugin might have incorrect definitions
63
- minimizer: [
64
- ...(minifier === 'terser'
65
- ? [
66
- new terser_webpack_plugin_1.default({
67
- parallel: true,
68
- terserOptions: {
69
- ie8: false,
70
- output: {
71
- comments: false,
72
- },
73
- },
74
- }),
75
- ]
76
- : [
77
- new esbuild_loader_1.ESBuildMinifyPlugin({
78
- target: 'esnext',
79
- }),
80
- ]),
81
- new csso_webpack_plugin_1.default({ restructure: false }),
82
- ],
83
- },
84
- plugins: [
85
- new webpack_1.default.IgnorePlugin(/^electron$/),
86
- new plugin_1.default(),
87
- new mini_css_extract_plugin_1.default({
88
- // Options similar to the same options in webpackOptions.output
89
- // both options are optional
90
- filename: '[name].bundle.css',
91
- chunkFilename: '[id].bundle.css',
92
- }),
93
- ...(debug ? [new write_file_webpack_plugin_1.default()] : []),
94
- ],
95
- resolve: {
96
- modules: ['node_modules'],
97
- cacheWithContext: false,
98
- extensions: [
99
- '.web.mjs',
100
- '.mjs',
101
- '.web.js',
102
- '.js',
103
- '.mjs',
104
- '.json',
105
- '.css',
106
- '.sass',
107
- '.scss',
108
- ],
109
- mainFields: ['browser', 'module', 'main', 'style'],
110
- },
111
- module: {
112
- rules: [
113
- {
114
- test: /\.css$/,
115
- use: [mini_css_extract_plugin_1.default.loader, require.resolve('css-loader')],
116
- },
117
- // see https://github.com/apollographql/react-apollo/issues/1737
118
- {
119
- type: 'javascript/auto',
120
- test: /\.mjs$/,
121
- use: [],
122
- },
123
- {
124
- test: /\.js$/,
125
- loader: [
126
- // support CLI tools that start with a #!/usr/bin/node
127
- require.resolve('shebang-loader'),
128
- // ESBuild Minifier doesn't auto-remove license comments from code
129
- // So, we break ESBuild's heuristic for license comments match. See github.com/privatenumber/esbuild-loader/issues/87
130
- {
131
- loader: require.resolve('string-replace-loader'),
132
- options: {
133
- multiple: [
134
- { search: '@license', replace: '@silence' },
135
- { search: /\/\/!/g, replace: '//' },
136
- { search: /\/\*!/g, replace: '/*' },
137
- ],
138
- },
139
- },
140
- ],
141
- },
142
- {
143
- test: /\.(html|svelte)$/,
144
- use: {
145
- loader: require.resolve('svelte-loader'),
146
- options: {
147
- emitCss: true,
148
- },
149
- },
150
- },
151
- {
152
- test: /\.vue$/,
153
- loader: require.resolve('vue-loader'),
154
- },
155
- {
156
- test: /\.(scss|sass)$/,
157
- loader: [
158
- mini_css_extract_plugin_1.default.loader,
159
- require.resolve('css-loader'),
160
- {
161
- loader: require.resolve('postcss-loader'),
162
- options: {
163
- plugins: () => [autoprefixer_1.default()],
164
- },
165
- },
166
- require.resolve('sass-loader'),
167
- ],
168
- },
169
- {
170
- test: /\.less$/,
171
- loader: [
172
- mini_css_extract_plugin_1.default.loader,
173
- require.resolve('css-loader'),
174
- {
175
- loader: require.resolve('postcss-loader'),
176
- options: {
177
- plugins: () => [
178
- autoprefixer_1.default({
179
- browsers: [
180
- 'last 5 Chrome versions',
181
- 'last 5 Firefox versions',
182
- 'Safari >= 8',
183
- 'Explorer >= 10',
184
- 'edge >= 12',
185
- ],
186
- }),
187
- ],
188
- },
189
- },
190
- {
191
- loader: require.resolve('less-loader'),
192
- options: {
193
- webpackImporter: true,
194
- },
195
- },
196
- ],
197
- },
198
- {
199
- test: /\.(woff|woff2|eot|ttf|svg|png|jpeg|jpg|gif|webp)$/,
200
- loader: require.resolve('file-loader'),
201
- options: {
202
- name: '[name].bundle.[ext]',
203
- emitFile: true,
204
- },
205
- },
206
- ],
207
- },
208
- node: builtInNode,
209
- output: {
210
- filename: 'bundle.js',
211
- pathinfo: false,
212
- },
213
- externals: (context, request, callback) => isExternalRequest(request)
214
- ? callback(null, 'commonjs ' + request)
215
- : callback(),
216
- };
217
- }
218
- exports.default = makeWebpackConfig;
219
- function makeExternalsRegex(externals) {
220
- let externalsRegex = externals
221
- .map(dep => `^${escape_string_regexp_1.default(dep)}$|^${escape_string_regexp_1.default(dep)}\\/`)
222
- .join('|');
223
- externalsRegex = `(${externalsRegex})`;
224
- return new RegExp(externalsRegex);
225
- }
@@ -1,6 +0,0 @@
1
- import webpack from 'webpack';
2
- declare function bundleSizeTree(packageName: string, stats: webpack.Stats.ToJsonOutput, minifier: 'terser' | 'esbuild'): Promise<{
3
- name: string;
4
- approximateSize: number;
5
- }[]>;
6
- export default bundleSizeTree;
@@ -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;