package-build-stats 8.1.0 → 8.2.0

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.
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,10 +1,5 @@
1
- "use strict";
2
1
  // Use ES6 supported by Node v6.10 only!
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const path_1 = __importDefault(require("path"));
8
- exports.default = {
9
- tmp: path_1.default.join('/tmp', 'tmp-build'),
2
+ import path from 'path';
3
+ export default {
4
+ tmp: path.join('/tmp', 'tmp-build'),
10
5
  };
@@ -1,5 +1,5 @@
1
1
  import type { Entry, Configuration } from '@rspack/core';
2
- import { Externals } from '../common.types';
2
+ import { Externals } from '../common.types.js';
3
3
  type MakeRspackConfigOptions = {
4
4
  packageName: string;
5
5
  externals: Externals;
@@ -1,13 +1,7 @@
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.default = makeRspackConfig;
7
- const autoprefixer_1 = __importDefault(require("autoprefixer"));
8
- const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
9
- const core_1 = __importDefault(require("@rspack/core"));
10
- function makeRspackConfig({ packageName: _packageName, entry, externals, debug: _debug, minify = true, }) {
1
+ import autoprefixer from 'autoprefixer';
2
+ import escapeRegex from 'escape-string-regexp';
3
+ import rspack from '@rspack/core';
4
+ export default function makeRspackConfig({ packageName: _packageName, entry, externals, debug: _debug, minify = true, }) {
11
5
  const externalsRegex = makeExternalsRegex(externals.externalPackages);
12
6
  const isExternalRequest = (request) => {
13
7
  const isPeerDep = externals.externalPackages.length
@@ -78,7 +72,7 @@ function makeRspackConfig({ packageName: _packageName, entry, externals, debug:
78
72
  test: /\.css$/,
79
73
  type: 'javascript/auto',
80
74
  use: [
81
- core_1.default.CssExtractRspackPlugin.loader,
75
+ rspack.CssExtractRspackPlugin.loader,
82
76
  require.resolve('css-loader'),
83
77
  ],
84
78
  },
@@ -99,13 +93,13 @@ function makeRspackConfig({ packageName: _packageName, entry, externals, debug:
99
93
  test: /\.(scss|sass)$/,
100
94
  type: 'javascript/auto',
101
95
  use: [
102
- core_1.default.CssExtractRspackPlugin.loader,
96
+ rspack.CssExtractRspackPlugin.loader,
103
97
  require.resolve('css-loader'),
104
98
  {
105
99
  loader: require.resolve('postcss-loader'),
106
100
  options: {
107
101
  postcssOptions: {
108
- plugins: [(0, autoprefixer_1.default)()],
102
+ plugins: [autoprefixer()],
109
103
  },
110
104
  },
111
105
  },
@@ -116,14 +110,14 @@ function makeRspackConfig({ packageName: _packageName, entry, externals, debug:
116
110
  test: /\.less$/,
117
111
  type: 'javascript/auto',
118
112
  use: [
119
- core_1.default.CssExtractRspackPlugin.loader,
113
+ rspack.CssExtractRspackPlugin.loader,
120
114
  require.resolve('css-loader'),
121
115
  {
122
116
  loader: require.resolve('postcss-loader'),
123
117
  options: {
124
118
  postcssOptions: {
125
119
  plugins: [
126
- (0, autoprefixer_1.default)({
120
+ autoprefixer({
127
121
  overrideBrowserslist: [
128
122
  'last 5 Chrome versions',
129
123
  'last 5 Firefox versions',
@@ -149,7 +143,7 @@ function makeRspackConfig({ packageName: _packageName, entry, externals, debug:
149
143
  ],
150
144
  },
151
145
  plugins: [
152
- new core_1.default.CssExtractRspackPlugin({
146
+ new rspack.CssExtractRspackPlugin({
153
147
  filename: '[name].bundle.css',
154
148
  }),
155
149
  ],
@@ -167,7 +161,7 @@ function makeRspackConfig({ packageName: _packageName, entry, externals, debug:
167
161
  }
168
162
  function makeExternalsRegex(externals) {
169
163
  let externalsRegex = externals
170
- .map(dep => `^${(0, escape_string_regexp_1.default)(dep)}$|^${(0, escape_string_regexp_1.default)(dep)}\\/`)
164
+ .map(dep => `^${escapeRegex(dep)}$|^${escapeRegex(dep)}\\/`)
171
165
  .join('|');
172
166
  externalsRegex = `(${externalsRegex})`;
173
167
  return new RegExp(externalsRegex);
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnexpectedBuildError = exports.MissingDependencyError = exports.MinifyError = exports.CLIBuildError = exports.PackageNotFoundError = exports.InstallError = exports.EntryPointError = exports.BuildError = void 0;
4
1
  /**
5
2
  * Wraps the original error with a identifiable
6
3
  * name.
@@ -21,60 +18,52 @@ class CustomError extends Error {
21
18
  };
22
19
  }
23
20
  }
24
- class BuildError extends CustomError {
21
+ export class BuildError extends CustomError {
25
22
  constructor(originalError, extra) {
26
23
  super('BuildError', originalError, extra);
27
24
  Object.setPrototypeOf(this, BuildError.prototype);
28
25
  }
29
26
  }
30
- exports.BuildError = BuildError;
31
- class EntryPointError extends CustomError {
27
+ export class EntryPointError extends CustomError {
32
28
  constructor(originalError, extra) {
33
29
  super('EntryPointError', originalError, extra);
34
30
  Object.setPrototypeOf(this, EntryPointError.prototype);
35
31
  }
36
32
  }
37
- exports.EntryPointError = EntryPointError;
38
- class InstallError extends CustomError {
33
+ export class InstallError extends CustomError {
39
34
  constructor(originalError, extra) {
40
35
  super('InstallError', originalError, extra);
41
36
  Object.setPrototypeOf(this, InstallError.prototype);
42
37
  }
43
38
  }
44
- exports.InstallError = InstallError;
45
- class PackageNotFoundError extends CustomError {
39
+ export class PackageNotFoundError extends CustomError {
46
40
  constructor(originalError, extra) {
47
41
  super('PackageNotFoundError', originalError, extra);
48
42
  Object.setPrototypeOf(this, PackageNotFoundError.prototype);
49
43
  }
50
44
  }
51
- exports.PackageNotFoundError = PackageNotFoundError;
52
- class CLIBuildError extends CustomError {
45
+ export class CLIBuildError extends CustomError {
53
46
  constructor(originalError, extra) {
54
47
  super('CLIBuildError', originalError, extra);
55
48
  Object.setPrototypeOf(this, CLIBuildError.prototype);
56
49
  }
57
50
  }
58
- exports.CLIBuildError = CLIBuildError;
59
- class MinifyError extends CustomError {
51
+ export class MinifyError extends CustomError {
60
52
  constructor(originalError, extra) {
61
53
  super('MinifyError', originalError, extra);
62
54
  Object.setPrototypeOf(this, MinifyError.prototype);
63
55
  }
64
56
  }
65
- exports.MinifyError = MinifyError;
66
- class MissingDependencyError extends CustomError {
57
+ export class MissingDependencyError extends CustomError {
67
58
  constructor(originalError, extra) {
68
59
  super('MissingDependencyError', originalError, extra);
69
60
  this.missingModules = extra.missingModules;
70
61
  Object.setPrototypeOf(this, MissingDependencyError.prototype);
71
62
  }
72
63
  }
73
- exports.MissingDependencyError = MissingDependencyError;
74
- class UnexpectedBuildError extends CustomError {
64
+ export class UnexpectedBuildError extends CustomError {
75
65
  constructor(originalError, extra) {
76
66
  super('UnexpectedBuildError', originalError, extra);
77
67
  Object.setPrototypeOf(this, UnexpectedBuildError.prototype);
78
68
  }
79
69
  }
80
- exports.UnexpectedBuildError = UnexpectedBuildError;
@@ -1,13 +1,8 @@
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 path_1 = __importDefault(require("path"));
7
- const core_1 = require("@swc/core");
8
- const CustomError_1 = require("./errors/CustomError");
9
- const telemetry_utils_1 = __importDefault(require("./utils/telemetry.utils"));
10
- const perf_hooks_1 = require("perf_hooks");
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';
11
6
  function modulePath(identifier) {
12
7
  // the format of module paths is
13
8
  // '(<loader expression>!)?/path/to/module.js'
@@ -35,8 +30,8 @@ function getUtf8Size(value) {
35
30
  function extractPackageNamesFromPath(moduleFilePath) {
36
31
  // pnpm will serve packages from a global symlink (.pnpm/package@version/node_modules/package)
37
32
  // needs to be stripped off
38
- const pnpmPrefix = '.pnpm\\' + path_1.default.sep + '.+\\' + path_1.default.sep + 'node_modules\\' + path_1.default.sep;
39
- const packages = moduleFilePath.split(new RegExp('\\' + path_1.default.sep + 'node_modules\\' + path_1.default.sep + `(?:${pnpmPrefix})?`));
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})?`));
40
35
  if (packages.length <= 1)
41
36
  return [];
42
37
  const lastSegment = packages.pop();
@@ -46,11 +41,11 @@ function extractPackageNamesFromPath(moduleFilePath) {
46
41
  let lastPackageName;
47
42
  if (lastSegment[0] === '@') {
48
43
  // package is a scoped package
49
- const offset = lastSegment.indexOf(path_1.default.sep) + 1;
50
- lastPackageName = lastSegment.slice(0, offset + lastSegment.slice(offset).indexOf(path_1.default.sep));
44
+ const offset = lastSegment.indexOf(path.sep) + 1;
45
+ lastPackageName = lastSegment.slice(0, offset + lastSegment.slice(offset).indexOf(path.sep));
51
46
  }
52
47
  else {
53
- lastPackageName = lastSegment.slice(0, lastSegment.indexOf(path_1.default.sep));
48
+ lastPackageName = lastSegment.slice(0, lastSegment.indexOf(path.sep));
54
49
  }
55
50
  packages.push(lastPackageName);
56
51
  packages.shift(); // Remove the first empty element
@@ -62,7 +57,7 @@ async function minifyDependencyCode(source) {
62
57
  }
63
58
  try {
64
59
  const startTime = Date.now();
65
- const result = await (0, core_1.minify)(source, {
60
+ const result = await minify(source, {
66
61
  compress: true,
67
62
  mangle: true,
68
63
  module: true, // Treat as ES module to support import/export
@@ -120,7 +115,7 @@ function normaliseModuleSource(mod) {
120
115
  return finalSource;
121
116
  }
122
117
  async function bundleSizeTree(packageName, stats) {
123
- const startTime = perf_hooks_1.performance.now();
118
+ const startTime = performance.now();
124
119
  const statsTree = {
125
120
  packageName: '<root>',
126
121
  sources: [],
@@ -186,7 +181,7 @@ async function bundleSizeTree(packageName, stats) {
186
181
  return;
187
182
  }
188
183
  let parent = statsTree;
189
- packages.forEach((pkg, pkgIndex) => {
184
+ packages.forEach(pkg => {
190
185
  const existing = parent.children.filter(child => child.packageName === pkg);
191
186
  if (existing.length > 0) {
192
187
  existing[0].sources.push(mod.source);
@@ -233,7 +228,6 @@ async function bundleSizeTree(packageName, stats) {
233
228
  }
234
229
  const minified = await minifyDependencyCode(code);
235
230
  const minifiedSize = getUtf8Size(minified.code || '');
236
- const minifiedCode = minified.code || '';
237
231
  if (process.env.DEBUG_SIZE) {
238
232
  console.log(`Source ${idx}: ${minifiedSize} bytes (minified)`);
239
233
  }
@@ -258,7 +252,7 @@ async function bundleSizeTree(packageName, stats) {
258
252
  }
259
253
  catch (error) {
260
254
  const { message, filename } = error;
261
- throw new CustomError_1.MinifyError(error, {
255
+ throw new MinifyError(error, {
262
256
  message: message,
263
257
  filePath: filename,
264
258
  });
@@ -266,12 +260,12 @@ async function bundleSizeTree(packageName, stats) {
266
260
  });
267
261
  try {
268
262
  const results = await Promise.all(resultPromises);
269
- telemetry_utils_1.default.dependencySizes(packageName, startTime, true, { minifier: 'swc' });
263
+ Telemetry.dependencySizes(packageName, startTime, true, { minifier: 'swc' });
270
264
  return results;
271
265
  }
272
266
  catch (e) {
273
- telemetry_utils_1.default.dependencySizes(packageName, startTime, false, { minifier: 'swc' }, e);
267
+ Telemetry.dependencySizes(packageName, startTime, false, { minifier: 'swc' }, e);
274
268
  throw e;
275
269
  }
276
270
  }
277
- exports.default = bundleSizeTree;
271
+ export default bundleSizeTree;
@@ -1,4 +1,4 @@
1
- import { GetPackageStatsOptions, InstallPackageOptions } from './common.types';
1
+ import { GetPackageStatsOptions, InstallPackageOptions } from './common.types.js';
2
2
  export declare function getAllPackageExports(packageString: string, options?: InstallPackageOptions): Promise<{
3
3
  [key: string]: string;
4
4
  }>;
@@ -1,22 +1,15 @@
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.getAllPackageExports = getAllPackageExports;
7
- exports.getPackageExportSizes = getPackageExportSizes;
8
- const telemetry_utils_1 = __importDefault(require("./utils/telemetry.utils"));
9
- const perf_hooks_1 = require("perf_hooks");
10
- const path_1 = __importDefault(require("path"));
11
- const debug_1 = __importDefault(require("debug"));
12
- const debug = (0, debug_1.default)('bp:worker');
13
- const common_utils_1 = require("./utils/common.utils");
14
- const exports_utils_1 = require("./utils/exports.utils");
15
- const installation_utils_1 = __importDefault(require("./utils/installation.utils"));
16
- const build_utils_1 = __importDefault(require("./utils/build.utils"));
1
+ import Telemetry from './utils/telemetry.utils.js';
2
+ import { performance } from 'perf_hooks';
3
+ import path from 'path';
4
+ import createDebug from 'debug';
5
+ const debug = createDebug('bp:worker');
6
+ import { getExternals, parsePackageString } from './utils/common.utils.js';
7
+ import { getAllExports } from './utils/exports.utils.js';
8
+ import InstallationUtils from './utils/installation.utils.js';
9
+ import BuildUtils from './utils/build.utils.js';
17
10
  async function installPackage(packageString, installPath, options) {
18
- const { isLocal } = (0, common_utils_1.parsePackageString)(packageString);
19
- await installation_utils_1.default.installPackage(packageString, installPath, {
11
+ const { isLocal } = parsePackageString(packageString);
12
+ await InstallationUtils.installPackage(packageString, installPath, {
20
13
  isLocal,
21
14
  client: options.client,
22
15
  limitConcurrency: options.limitConcurrency,
@@ -24,54 +17,54 @@ async function installPackage(packageString, installPath, options) {
24
17
  installTimeout: options.installTimeout,
25
18
  });
26
19
  }
27
- async function getAllPackageExports(packageString, options = {}) {
28
- const startTime = perf_hooks_1.performance.now();
29
- const { name: packageName, normalPath } = (0, common_utils_1.parsePackageString)(packageString);
30
- const installPath = await installation_utils_1.default.preparePath(packageName);
20
+ export async function getAllPackageExports(packageString, options = {}) {
21
+ const startTime = performance.now();
22
+ const { name: packageName, normalPath } = parsePackageString(packageString);
23
+ const installPath = await InstallationUtils.preparePath(packageName);
31
24
  try {
32
25
  await installPackage(packageString, installPath, options);
33
26
  // The package is installed in node_modules subdirectory
34
- const packagePath = normalPath || path_1.default.join(installPath, 'node_modules', packageName);
35
- const results = await (0, exports_utils_1.getAllExports)(packageString, packagePath, packageName, installPath);
36
- telemetry_utils_1.default.packageExports(packageString, startTime, true);
27
+ const packagePath = normalPath || path.join(installPath, 'node_modules', packageName);
28
+ const results = await getAllExports(packageString, packagePath, packageName, installPath);
29
+ Telemetry.packageExports(packageString, startTime, true);
37
30
  return results;
38
31
  }
39
32
  catch (err) {
40
- telemetry_utils_1.default.packageExports(packageString, startTime, false, err);
33
+ Telemetry.packageExports(packageString, startTime, false, err);
41
34
  throw err;
42
35
  }
43
36
  finally {
44
- await installation_utils_1.default.cleanupPath(installPath);
37
+ await InstallationUtils.cleanupPath(installPath);
45
38
  }
46
39
  }
47
- async function getPackageExportSizes(packageString, options = {}) {
48
- const startTime = perf_hooks_1.performance.now();
40
+ export async function getPackageExportSizes(packageString, options = {}) {
41
+ const startTime = performance.now();
49
42
  const timings = {};
50
- const { name: packageName, normalPath } = (0, common_utils_1.parsePackageString)(packageString);
51
- const preparePathStart = perf_hooks_1.performance.now();
52
- const installPath = await installation_utils_1.default.preparePath(packageName);
53
- timings.preparePath = perf_hooks_1.performance.now() - preparePathStart;
43
+ const { name: packageName, normalPath } = parsePackageString(packageString);
44
+ const preparePathStart = performance.now();
45
+ const installPath = await InstallationUtils.preparePath(packageName);
46
+ timings.preparePath = performance.now() - preparePathStart;
54
47
  console.log(`[PERF] [ExportSizes] preparePath: ${timings.preparePath.toFixed(2)}ms`);
55
48
  try {
56
- const installStart = perf_hooks_1.performance.now();
49
+ const installStart = performance.now();
57
50
  await installPackage(packageString, installPath, options);
58
- timings.install = perf_hooks_1.performance.now() - installStart;
51
+ timings.install = performance.now() - installStart;
59
52
  console.log(`[PERF] [ExportSizes] installPackage: ${timings.install.toFixed(2)}ms`);
60
53
  // The package is installed in node_modules subdirectory
61
- const packagePath = normalPath || path_1.default.join(installPath, 'node_modules', packageName);
62
- const getAllExportsStart = perf_hooks_1.performance.now();
63
- const exportMap = await (0, exports_utils_1.getAllExports)(packageString, packagePath, packageName, installPath);
64
- timings.getAllExports = perf_hooks_1.performance.now() - getAllExportsStart;
54
+ const packagePath = normalPath || path.join(installPath, 'node_modules', packageName);
55
+ const getAllExportsStart = performance.now();
56
+ const exportMap = await getAllExports(packageString, packagePath, packageName, installPath);
57
+ timings.getAllExports = performance.now() - getAllExportsStart;
65
58
  console.log(`[PERF] [ExportSizes] getAllExports: ${timings.getAllExports.toFixed(2)}ms`);
66
59
  const exports = Object.keys(exportMap).filter(exp => !(exp === 'default'));
67
60
  debug('Got %d exports for %s', exports.length, packageString);
68
61
  console.log(`[PERF] [ExportSizes] Found ${exports.length} exports`);
69
- const externalsStart = perf_hooks_1.performance.now();
70
- const externals = (0, common_utils_1.getExternals)(packageName, installPath);
71
- timings.getExternals = perf_hooks_1.performance.now() - externalsStart;
62
+ const externalsStart = performance.now();
63
+ const externals = getExternals(packageName, installPath);
64
+ timings.getExternals = performance.now() - externalsStart;
72
65
  console.log(`[PERF] [ExportSizes] getExternals: ${timings.getExternals.toFixed(2)}ms`);
73
- const buildStart = perf_hooks_1.performance.now();
74
- const builtDetails = await build_utils_1.default.buildPackageIgnoringMissingDeps({
66
+ const buildStart = performance.now();
67
+ const builtDetails = await BuildUtils.buildPackageIgnoringMissingDeps({
75
68
  name: packageName,
76
69
  installPath,
77
70
  externals,
@@ -81,9 +74,9 @@ async function getPackageExportSizes(packageString, options = {}) {
81
74
  includeDependencySizes: false,
82
75
  },
83
76
  });
84
- timings.build = perf_hooks_1.performance.now() - buildStart;
77
+ timings.build = performance.now() - buildStart;
85
78
  console.log(`[PERF] [ExportSizes] buildPackage: ${timings.build.toFixed(2)}ms`);
86
- telemetry_utils_1.default.packageExportsSizes(packageString, startTime, true, options);
79
+ Telemetry.packageExportsSizes(packageString, startTime, true, options);
87
80
  return {
88
81
  ...builtDetails,
89
82
  assets: builtDetails.assets.map(asset => ({
@@ -93,10 +86,10 @@ async function getPackageExportSizes(packageString, options = {}) {
93
86
  };
94
87
  }
95
88
  catch (err) {
96
- telemetry_utils_1.default.packageExportsSizes(packageString, startTime, false, options, err);
89
+ Telemetry.packageExportsSizes(packageString, startTime, false, options, err);
97
90
  throw err;
98
91
  }
99
92
  finally {
100
- await installation_utils_1.default.cleanupPath(installPath);
93
+ await InstallationUtils.cleanupPath(installPath);
101
94
  }
102
95
  }
@@ -2,7 +2,7 @@
2
2
  * Parts of the code are inspired from the `import-cost` project
3
3
  * @see https://github.com/wix/import-cost/blob/master/packages/import-cost/src/webpack.js
4
4
  */
5
- import { GetPackageStatsOptions } from './common.types';
5
+ import { GetPackageStatsOptions } from './common.types.js';
6
6
  export default function getPackageStats(packageString: string, options?: GetPackageStatsOptions): Promise<{
7
7
  size: number;
8
8
  gzip: number;
@@ -1,27 +1,21 @@
1
- "use strict";
2
1
  /**
3
2
  * Parts of the code are inspired from the `import-cost` project
4
3
  * @see https://github.com/wix/import-cost/blob/master/packages/import-cost/src/webpack.js
5
4
  */
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
- exports.default = getPackageStats;
11
- const promises_1 = __importDefault(require("fs/promises"));
12
- const path_1 = __importDefault(require("path"));
13
- const common_utils_1 = require("./utils/common.utils");
14
- const installation_utils_1 = __importDefault(require("./utils/installation.utils"));
15
- const build_utils_1 = __importDefault(require("./utils/build.utils"));
16
- const CustomError_1 = require("./errors/CustomError");
17
- const telemetry_utils_1 = __importDefault(require("./utils/telemetry.utils"));
18
- const perf_hooks_1 = require("perf_hooks");
5
+ import fs from 'fs/promises';
6
+ import path from 'path';
7
+ import { getExternals, parsePackageString } from './utils/common.utils.js';
8
+ import InstallationUtils from './utils/installation.utils.js';
9
+ import BuildUtils from './utils/build.utils.js';
10
+ import { UnexpectedBuildError } from './errors/CustomError.js';
11
+ import Telemetry from './utils/telemetry.utils.js';
12
+ import { performance } from 'perf_hooks';
19
13
  function getPackageJSONDetails(packageName, installPath) {
20
- const startTime = perf_hooks_1.performance.now();
21
- const packageJSONPath = path_1.default.join(installPath, 'node_modules', packageName, 'package.json');
22
- return promises_1.default.readFile(packageJSONPath, 'utf8').then((contents) => {
14
+ const startTime = performance.now();
15
+ const packageJSONPath = path.join(installPath, 'node_modules', packageName, 'package.json');
16
+ return fs.readFile(packageJSONPath, 'utf8').then((contents) => {
23
17
  const parsedJSON = JSON.parse(contents);
24
- telemetry_utils_1.default.getPackageJSONDetails(packageName, true, startTime);
18
+ Telemetry.getPackageJSONDetails(packageName, true, startTime);
25
19
  return {
26
20
  dependencyCount: 'dependencies' in parsedJSON
27
21
  ? Object.keys(parsedJSON.dependencies).length
@@ -35,36 +29,36 @@ function getPackageJSONDetails(packageName, installPath) {
35
29
  : [],
36
30
  };
37
31
  }, err => {
38
- telemetry_utils_1.default.getPackageJSONDetails(packageName, false, startTime, err);
32
+ Telemetry.getPackageJSONDetails(packageName, false, startTime, err);
39
33
  });
40
34
  }
41
- async function getPackageStats(packageString, options = {}) {
42
- const startTime = perf_hooks_1.performance.now();
35
+ export default async function getPackageStats(packageString, options = {}) {
36
+ const startTime = performance.now();
43
37
  const timings = {};
44
- const { name: packageName, isLocal } = (0, common_utils_1.parsePackageString)(packageString);
45
- const preparePathStart = perf_hooks_1.performance.now();
46
- const installPath = await installation_utils_1.default.preparePath(packageName, options.client);
47
- timings.preparePath = perf_hooks_1.performance.now() - preparePathStart;
38
+ const { name: packageName, isLocal } = parsePackageString(packageString);
39
+ const preparePathStart = performance.now();
40
+ const installPath = await InstallationUtils.preparePath(packageName, options.client);
41
+ timings.preparePath = performance.now() - preparePathStart;
48
42
  console.log(`[PERF] preparePath: ${timings.preparePath.toFixed(2)}ms`);
49
43
  try {
50
- const installStart = perf_hooks_1.performance.now();
51
- await installation_utils_1.default.installPackage(packageString, installPath, {
44
+ const installStart = performance.now();
45
+ await InstallationUtils.installPackage(packageString, installPath, {
52
46
  isLocal,
53
47
  client: options.client,
54
48
  limitConcurrency: options.limitConcurrency,
55
49
  networkConcurrency: options.networkConcurrency,
56
50
  installTimeout: options.installTimeout,
57
51
  });
58
- timings.install = perf_hooks_1.performance.now() - installStart;
52
+ timings.install = performance.now() - installStart;
59
53
  console.log(`[PERF] installPackage: ${timings.install.toFixed(2)}ms`);
60
- const externalsStart = perf_hooks_1.performance.now();
61
- const externals = (0, common_utils_1.getExternals)(packageName, installPath);
62
- timings.getExternals = perf_hooks_1.performance.now() - externalsStart;
54
+ const externalsStart = performance.now();
55
+ const externals = getExternals(packageName, installPath);
56
+ timings.getExternals = performance.now() - externalsStart;
63
57
  console.log(`[PERF] getExternals: ${timings.getExternals.toFixed(2)}ms`);
64
- const parallelStart = perf_hooks_1.performance.now();
58
+ const parallelStart = performance.now();
65
59
  const [pacakgeJSONDetails, builtDetails] = await Promise.all([
66
60
  getPackageJSONDetails(packageName, installPath),
67
- build_utils_1.default.buildPackageIgnoringMissingDeps({
61
+ BuildUtils.buildPackageIgnoringMissingDeps({
68
62
  name: packageName,
69
63
  installPath,
70
64
  externals,
@@ -76,15 +70,15 @@ async function getPackageStats(packageString, options = {}) {
76
70
  },
77
71
  }),
78
72
  ]);
79
- timings.parallelBuild = perf_hooks_1.performance.now() - parallelStart;
73
+ timings.parallelBuild = performance.now() - parallelStart;
80
74
  console.log(`[PERF] parallel (packageJSON + build): ${timings.parallelBuild.toFixed(2)}ms`);
81
75
  const hasCSSAsset = builtDetails.assets.some(asset => asset.type === 'css');
82
76
  const mainAsset = builtDetails.assets.find(asset => asset.name === 'main' && asset.type === (hasCSSAsset ? 'css' : 'js'));
83
77
  if (!mainAsset) {
84
- throw new CustomError_1.UnexpectedBuildError('Did not find a main asset in the built bundle');
78
+ throw new UnexpectedBuildError('Did not find a main asset in the built bundle');
85
79
  }
86
- const totalTime = perf_hooks_1.performance.now() - startTime;
87
- telemetry_utils_1.default.packageStats(packageString, true, totalTime, options);
80
+ const totalTime = performance.now() - startTime;
81
+ Telemetry.packageStats(packageString, true, totalTime, options);
88
82
  return {
89
83
  ...pacakgeJSONDetails,
90
84
  ...builtDetails,
@@ -93,12 +87,12 @@ async function getPackageStats(packageString, options = {}) {
93
87
  };
94
88
  }
95
89
  catch (e) {
96
- telemetry_utils_1.default.packageStats(packageString, false, perf_hooks_1.performance.now() - startTime, options);
90
+ Telemetry.packageStats(packageString, false, performance.now() - startTime, options);
97
91
  throw e;
98
92
  }
99
93
  finally {
100
94
  if (!options.debug) {
101
- await installation_utils_1.default.cleanupPath(installPath);
95
+ await InstallationUtils.cleanupPath(installPath);
102
96
  }
103
97
  }
104
98
  }
package/build/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { default as getPackageStats } from './getPackageStats';
2
- export * from './errors/CustomError';
3
- export * from './getPackageExportSizes';
4
- export { emitter as eventQueue } from './utils/telemetry.utils';
1
+ export { default as getPackageStats } from './getPackageStats.js';
2
+ export * from './errors/CustomError.js';
3
+ export * from './getPackageExportSizes.js';
4
+ export { emitter as eventQueue } from './utils/telemetry.utils.js';
package/build/index.js CHANGED
@@ -1,26 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.eventQueue = exports.getPackageStats = void 0;
21
- var getPackageStats_1 = require("./getPackageStats");
22
- Object.defineProperty(exports, "getPackageStats", { enumerable: true, get: function () { return __importDefault(getPackageStats_1).default; } });
23
- __exportStar(require("./errors/CustomError"), exports);
24
- __exportStar(require("./getPackageExportSizes"), exports);
25
- var telemetry_utils_1 = require("./utils/telemetry.utils");
26
- Object.defineProperty(exports, "eventQueue", { enumerable: true, get: function () { return telemetry_utils_1.emitter; } });
1
+ export { default as getPackageStats } from './getPackageStats.js';
2
+ export * from './errors/CustomError.js';
3
+ export * from './getPackageExportSizes.js';
4
+ export { emitter as eventQueue } from './utils/telemetry.utils.js';
@@ -1,6 +1,6 @@
1
1
  import { Entry } from '@rspack/core';
2
2
  import type { Stats } from '@rspack/core';
3
- import { Externals, BuildPackageOptions, CreateEntryPointOptions } from '../common.types';
3
+ import { Externals, BuildPackageOptions, CreateEntryPointOptions } from '../common.types.js';
4
4
  type CompilePackageArgs = {
5
5
  name: string;
6
6
  externals: Externals;