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.
- package/.parcelrc +37 -0
- package/build/common.types.d.ts +3 -8
- package/build/common.types.d.ts.map +1 -0
- package/build/common.types.js +1 -0
- package/build/common.types.js.map +1 -0
- package/build/config/{config.d.ts → index.d.ts} +2 -0
- package/build/config/index.d.ts.map +1 -0
- package/build/config/{config.js → index.js} +2 -0
- package/build/config/index.js.map +1 -0
- package/build/errors/CustomError.d.ts +1 -0
- package/build/errors/CustomError.d.ts.map +1 -0
- package/build/errors/CustomError.js +1 -0
- package/build/errors/CustomError.js.map +1 -0
- package/build/fixed/fixed/parseReference.js +5388 -0
- package/build/fixed/parseReference.js +762 -727
- package/build/getPackageExportSizes.d.ts +5 -29
- package/build/getPackageExportSizes.d.ts.map +1 -0
- package/build/getPackageExportSizes.js +18 -10
- package/build/getPackageExportSizes.js.map +1 -0
- package/build/getPackageStats.d.ts +13 -54
- package/build/getPackageStats.d.ts.map +1 -0
- package/build/getPackageStats.js +30 -7
- package/build/getPackageStats.js.map +1 -0
- package/build/getParseTime.d.ts +1 -0
- package/build/getParseTime.d.ts.map +1 -0
- package/build/getParseTime.js +5 -4
- package/build/getParseTime.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +1 -0
- package/build/index.js.map +1 -0
- package/build/utils/build.utils.d.ts +39 -69
- package/build/utils/build.utils.d.ts.map +1 -0
- package/build/utils/build.utils.js +177 -159
- package/build/utils/build.utils.js.map +1 -0
- package/build/utils/common.utils.d.ts +22 -0
- package/build/utils/common.utils.d.ts.map +1 -0
- package/build/utils/common.utils.js +94 -1
- package/build/utils/common.utils.js.map +1 -0
- package/build/utils/exports.utils.d.ts +1 -0
- package/build/utils/exports.utils.d.ts.map +1 -0
- package/build/utils/exports.utils.js +35 -23
- package/build/utils/exports.utils.js.map +1 -0
- package/build/utils/installation.utils.d.ts +1 -0
- package/build/utils/installation.utils.d.ts.map +1 -0
- package/build/utils/installation.utils.js +25 -7
- package/build/utils/installation.utils.js.map +1 -0
- package/build/utils/telemetry.utils.d.ts +1 -2
- package/build/utils/telemetry.utils.d.ts.map +1 -0
- package/build/utils/telemetry.utils.js +7 -20
- package/build/utils/telemetry.utils.js.map +1 -0
- package/package.json +75 -73
- package/src/common.types.ts +3 -10
- package/src/config/{config.ts → index.ts} +1 -0
- package/src/errors/CustomError.d.ts +42 -0
- package/src/errors/CustomError.js +81 -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/config/makeWebpackConfig.d.ts +0 -11
- package/build/config/makeWebpackConfig.js +0 -225
- package/build/getDependencySizeTree.d.ts +0 -6
- package/build/getDependencySizeTree.js +0 -238
- package/src/config/makeWebpackConfig.ts +0 -251
- 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 {
|
|
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
|
|
86
|
+
debug('Got %d exports for %s', exports.length, packageString)
|
|
74
87
|
|
|
75
88
|
const externals = getExternals(packageName, installPath)
|
|
76
89
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
110
|
+
buildVersion: require('../package.json').version,
|
|
111
|
+
assets: builtDetails?.assets?.map(asset => ({
|
|
93
112
|
...asset,
|
|
94
|
-
path: exportMap[asset
|
|
113
|
+
path: exportMap[asset?.name],
|
|
95
114
|
})),
|
|
96
115
|
}
|
|
97
116
|
} catch (err) {
|
package/src/getPackageStats.ts
CHANGED
|
@@ -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 [
|
|
86
|
+
const [packageJSONDetails, builtDetails] = await Promise.all([
|
|
80
87
|
getPackageJSONDetails(packageName, installPath),
|
|
81
|
-
BuildUtils.buildPackageIgnoringMissingDeps(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
95
|
-
|
|
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
|
|
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
|
-
...
|
|
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,
|