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
@@ -3,7 +3,11 @@ import { performance } from 'perf_hooks'
3
3
 
4
4
  const debug = require('debug')('bp:worker')
5
5
 
6
- import { getExternals, parsePackageString } from './utils/common.utils'
6
+ import {
7
+ getExternals,
8
+ parsePackageString,
9
+ updateProjectEntries,
10
+ } from './utils/common.utils'
7
11
  import { getAllExports } from './utils/exports.utils'
8
12
  import InstallationUtils from './utils/installation.utils'
9
13
  import BuildUtils from './utils/build.utils'
@@ -50,6 +54,11 @@ export async function getAllPackageExports(
50
54
  }
51
55
  }
52
56
 
57
+ export async function getExportSize(
58
+ packageString: string,
59
+ exportName: string
60
+ ) {}
61
+
53
62
  export async function getPackageExportSizes(
54
63
  packageString: string,
55
64
  options: GetPackageStatsOptions = {
@@ -60,6 +69,10 @@ export async function getPackageExportSizes(
60
69
  const { name: packageName, normalPath } = parsePackageString(packageString)
61
70
  const installPath = await InstallationUtils.preparePath(packageName)
62
71
 
72
+ if (options.debug) {
73
+ console.log('Install path:', installPath)
74
+ }
75
+
63
76
  try {
64
77
  await installPackage(packageString, installPath, options)
65
78
 
@@ -70,28 +83,34 @@ export async function getPackageExportSizes(
70
83
  )
71
84
 
72
85
  const exports = Object.keys(exportMap).filter(exp => !(exp === 'default'))
73
- debug('Got %d exports for %s', exports.length, packageString)
86
+ debug('Got %d exports for %s', exports.length, packageString)
74
87
 
75
88
  const externals = getExternals(packageName, installPath)
76
89
 
77
- const builtDetails = await BuildUtils.buildPackageIgnoringMissingDeps({
78
- name: packageName,
79
- installPath,
80
- externals,
81
- options: {
82
- customImports: exports,
83
- splitCustomImports: true,
84
- includeDependencySizes: false,
85
- minifier: options.minifier || 'terser',
90
+ await updateProjectEntries(installPath, exportMap)
91
+
92
+ const builtDetails = await BuildUtils.buildPackageIgnoringMissingDeps(
93
+ {
94
+ name: packageName,
95
+ installPath,
96
+ externals,
97
+ options: {
98
+ customImports: exports,
99
+ splitCustomImports: true,
100
+ includeDependencySizes: false,
101
+ minifier: options.minifier || 'terser',
102
+ },
86
103
  },
87
- })
104
+ 0
105
+ )
88
106
 
89
107
  Telemetry.packageExportsSizes(packageString, startTime, true, options)
90
108
  return {
91
109
  ...builtDetails,
92
- assets: builtDetails.assets.map(asset => ({
110
+ buildVersion: require('../package.json').version,
111
+ assets: builtDetails?.assets?.map(asset => ({
93
112
  ...asset,
94
- path: exportMap[asset.name],
113
+ path: exportMap[asset?.name],
95
114
  })),
96
115
  }
97
116
  } catch (err) {
@@ -3,12 +3,13 @@
3
3
  * @see https://github.com/wix/import-cost/blob/master/packages/import-cost/src/webpack.js
4
4
  */
5
5
 
6
+ const log = require('debug')('bp:package-stats')
6
7
  import { promises as fs } from 'fs'
7
8
  import path from 'path'
8
9
  import { getExternals, parsePackageString } from './utils/common.utils'
9
10
  import InstallationUtils from './utils/installation.utils'
10
11
  import BuildUtils from './utils/build.utils'
11
- import { UnexpectedBuildError } from './errors/CustomError'
12
+ import { BuildError, UnexpectedBuildError } from './errors/CustomError'
12
13
  import { GetPackageStatsOptions } from './common.types'
13
14
  import Telemetry from './utils/telemetry.utils'
14
15
  import { performance } from 'perf_hooks'
@@ -31,6 +32,12 @@ function getPackageJSONDetails(packageName: string, installPath: string) {
31
32
  'dependencies' in parsedJSON
32
33
  ? Object.keys(parsedJSON.dependencies).length
33
34
  : 0,
35
+ mainFields: [
36
+ parsedJSON['module'] && 'module',
37
+ parsedJSON['jsnext:main'] && 'jsnext:main',
38
+ parsedJSON['main'] && 'main',
39
+ parsedJSON['style'] && 'style',
40
+ ].filter(Boolean),
34
41
  hasJSNext: parsedJSON['jsnext:main'] || false,
35
42
  hasJSModule: parsedJSON['module'] || false,
36
43
  isModuleType: parsedJSON['type'] === 'module',
@@ -76,25 +83,56 @@ export default async function getPackageStats(
76
83
  })
77
84
 
78
85
  const externals = getExternals(packageName, installPath)
79
- const [pacakgeJSONDetails, builtDetails] = await Promise.all([
86
+ const [packageJSONDetails, builtDetails] = await Promise.all([
80
87
  getPackageJSONDetails(packageName, installPath),
81
- BuildUtils.buildPackageIgnoringMissingDeps({
82
- name: packageName,
83
- installPath,
84
- externals,
85
- options: {
86
- debug: options.debug,
87
- customImports: options.customImports,
88
- minifier: options.minifier,
89
- includeDependencySizes: true,
88
+ BuildUtils.buildPackageIgnoringMissingDeps(
89
+ {
90
+ name: packageName,
91
+ installPath,
92
+ externals,
93
+ options: {
94
+ debug: options.debug,
95
+ customImports: options.customImports,
96
+ minifier: options.minifier,
97
+ includeDependencySizes: true,
98
+ },
90
99
  },
91
- }),
100
+ 0
101
+ ),
92
102
  ])
93
103
 
94
- const hasCSSAsset = builtDetails.assets.some(asset => asset.type === 'css')
95
- const mainAsset = builtDetails.assets.find(
104
+ if (!packageJSONDetails) {
105
+ throw new UnexpectedBuildError(
106
+ `Could not get package.json details for ${packageName}`
107
+ )
108
+ }
109
+
110
+ if (!builtDetails) {
111
+ throw new BuildError(`Could not get built details for ${packageName}`)
112
+ }
113
+
114
+ const isStylePackageOnly =
115
+ packageJSONDetails.mainFields.length === 1 &&
116
+ packageJSONDetails.mainFields[0] === 'style'
117
+ if (isStylePackageOnly) {
118
+ builtDetails.assets = builtDetails.assets?.filter(
119
+ asset => asset?.type !== 'js'
120
+ )
121
+ }
122
+
123
+ log(
124
+ 'builtDetails are %o %o',
125
+ builtDetails.assets,
126
+ // @ts-ignore
127
+ builtDetails.dependencySizes
128
+ )
129
+ const hasCSSAsset = builtDetails.assets?.some(
130
+ asset => asset?.type === 'css'
131
+ )
132
+
133
+ const mainAsset = builtDetails.assets?.find(
96
134
  asset =>
97
- asset.name === 'main' && asset.type === (hasCSSAsset ? 'css' : 'js')
135
+ asset?.name === 'index' && asset?.type === (hasCSSAsset ? 'css' : 'js')
98
136
  )
99
137
 
100
138
  if (!mainAsset) {
@@ -110,8 +148,9 @@ export default async function getPackageStats(
110
148
  options
111
149
  )
112
150
  return {
113
- ...pacakgeJSONDetails,
151
+ ...packageJSONDetails,
114
152
  ...builtDetails,
153
+ buildVersion: require('../package.json').version,
115
154
  size: mainAsset.size,
116
155
  gzip: mainAsset.gzip,
117
156
  parse: mainAsset.parse,
@@ -0,0 +1,3 @@
1
+ declare module 'is-valid-npm-name' {
2
+ export default function (str: string): boolean
3
+ }