Skip to content

Commit 3b3bcd4

Browse files
authored
chore(scripts): delete an unnecessary parameter + add jsdoc to build script (#8527)
1 parent 7c44800 commit 3b3bcd4

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

scripts/build.js

+36-2
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,30 @@ async function run() {
7575
}
7676
}
7777

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+
*/
7883
async function buildAll(targets) {
7984
await runParallel(cpus().length, targets, build)
8085
}
8186

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+
*/
8295
async function runParallel(maxConcurrency, source, iteratorFn) {
96+
/**@type {Promise<void>[]} */
8397
const ret = []
98+
/**@type {Promise<void>[]} */
8499
const executing = []
85100
for (const item of source) {
86-
const p = Promise.resolve().then(() => iteratorFn(item, source))
101+
const p = Promise.resolve().then(() => iteratorFn(item))
87102
ret.push(p)
88103

89104
if (maxConcurrency <= source.length) {
@@ -96,7 +111,11 @@ async function runParallel(maxConcurrency, source, iteratorFn) {
96111
}
97112
return Promise.all(ret)
98113
}
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+
*/
100119
async function build(target) {
101120
const pkgDir = path.resolve(`packages/${target}`)
102121
const pkg = require(`${pkgDir}/package.json`)
@@ -134,6 +153,11 @@ async function build(target) {
134153
)
135154
}
136155

156+
/**
157+
* Checks the sizes of all targets.
158+
* @param {string[]} targets - The targets to check sizes for.
159+
* @returns {Promise<void>}
160+
*/
137161
async function checkAllSizes(targets) {
138162
if (devOnly || (formats && !formats.includes('global'))) {
139163
return
@@ -145,6 +169,11 @@ async function checkAllSizes(targets) {
145169
console.log()
146170
}
147171

172+
/**
173+
* Checks the size of a target.
174+
* @param {string} target - The target to check the size for.
175+
* @returns {Promise<void>}
176+
*/
148177
async function checkSize(target) {
149178
const pkgDir = path.resolve(`packages/${target}`)
150179
await checkFileSize(`${pkgDir}/dist/${target}.global.prod.js`)
@@ -153,6 +182,11 @@ async function checkSize(target) {
153182
}
154183
}
155184

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+
*/
156190
async function checkFileSize(filePath) {
157191
if (!existsSync(filePath)) {
158192
return

0 commit comments

Comments
 (0)