@@ -75,15 +75,30 @@ async function run() {
75
75
}
76
76
}
77
77
78
+ /**
79
+ * Builds all the targets in parallel.
80
+ * @param {Array<string> } targets - An array of targets to build.
81
+ * @returns {Promise<void> } - A promise representing the build process.
82
+ */
78
83
async function buildAll ( targets ) {
79
84
await runParallel ( cpus ( ) . length , targets , build )
80
85
}
81
86
87
+ /**
88
+ * Runs iterator function in parallel.
89
+ * @template T - The type of items in the data source
90
+ * @param {number } maxConcurrency - The maximum concurrency.
91
+ * @param {Array<T> } source - The data source
92
+ * @param {(item: T) => Promise<void> } iteratorFn - The iteratorFn
93
+ * @returns {Promise<void[]> } - A Promise array containing all iteration results.
94
+ */
82
95
async function runParallel ( maxConcurrency , source , iteratorFn ) {
96
+ /**@type {Promise<void>[] } */
83
97
const ret = [ ]
98
+ /**@type {Promise<void>[] } */
84
99
const executing = [ ]
85
100
for ( const item of source ) {
86
- const p = Promise . resolve ( ) . then ( ( ) => iteratorFn ( item , source ) )
101
+ const p = Promise . resolve ( ) . then ( ( ) => iteratorFn ( item ) )
87
102
ret . push ( p )
88
103
89
104
if ( maxConcurrency <= source . length ) {
@@ -96,7 +111,11 @@ async function runParallel(maxConcurrency, source, iteratorFn) {
96
111
}
97
112
return Promise . all ( ret )
98
113
}
99
-
114
+ /**
115
+ * Builds the target.
116
+ * @param {string } target - The target to build.
117
+ * @returns {Promise<void> } - A promise representing the build process.
118
+ */
100
119
async function build ( target ) {
101
120
const pkgDir = path . resolve ( `packages/${ target } ` )
102
121
const pkg = require ( `${ pkgDir } /package.json` )
@@ -134,6 +153,11 @@ async function build(target) {
134
153
)
135
154
}
136
155
156
+ /**
157
+ * Checks the sizes of all targets.
158
+ * @param {string[] } targets - The targets to check sizes for.
159
+ * @returns {Promise<void> }
160
+ */
137
161
async function checkAllSizes ( targets ) {
138
162
if ( devOnly || ( formats && ! formats . includes ( 'global' ) ) ) {
139
163
return
@@ -145,6 +169,11 @@ async function checkAllSizes(targets) {
145
169
console . log ( )
146
170
}
147
171
172
+ /**
173
+ * Checks the size of a target.
174
+ * @param {string } target - The target to check the size for.
175
+ * @returns {Promise<void> }
176
+ */
148
177
async function checkSize ( target ) {
149
178
const pkgDir = path . resolve ( `packages/${ target } ` )
150
179
await checkFileSize ( `${ pkgDir } /dist/${ target } .global.prod.js` )
@@ -153,6 +182,11 @@ async function checkSize(target) {
153
182
}
154
183
}
155
184
185
+ /**
186
+ * Checks the file size.
187
+ * @param {string } filePath - The path of the file to check the size for.
188
+ * @returns {Promise<void> }
189
+ */
156
190
async function checkFileSize ( filePath ) {
157
191
if ( ! existsSync ( filePath ) ) {
158
192
return
0 commit comments