Skip to content

Commit 9492dff

Browse files
committed
perf(scripts): Add JSDoc annotations to build.js
1 parent 75d94f6 commit 9492dff

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

scripts/build.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,27 @@ async function run() {
6969
removeCache()
7070
}
7171
}
72-
72+
/**
73+
* Builds all the targets in parallel.
74+
* @param {Array<string>} targets - An array of targets to build.
75+
* @returns {Promise<void>} - A promise representing the build process.
76+
*/
7377
async function buildAll(targets) {
7478
await runParallel(cpus().length, targets, build)
7579
}
7680

81+
/**
82+
* Runs iterator function in parallel.
83+
* @template T - The type of items in the data source
84+
* @param {number} maxConcurrency - The maximum concurrency.
85+
* @param {Array<T>} source - The data source
86+
* @param {(item: T) => Promise<void>} iteratorFn - The iteratorFn
87+
* @returns {Promise<void[]>} - A Promise array containing all iteration results.
88+
*/
7789
async function runParallel(maxConcurrency, source, iteratorFn) {
90+
/**@type {Promise<void>[]} */
7891
const ret = []
92+
/**@type {Promise<void>[]} */
7993
const executing = []
8094
for (const item of source) {
8195
const p = Promise.resolve().then(() => iteratorFn(item))
@@ -91,7 +105,11 @@ async function runParallel(maxConcurrency, source, iteratorFn) {
91105
}
92106
return Promise.all(ret)
93107
}
94-
108+
/**
109+
* Builds the target.
110+
* @param {string} target - The target to build.
111+
* @returns {Promise<void>} - A promise representing the build process.
112+
*/
95113
async function build(target) {
96114
const pkgDir = path.resolve(`packages/${target}`)
97115
const pkg = require(`${pkgDir}/package.json`)
@@ -128,6 +146,11 @@ async function build(target) {
128146
{ stdio: 'inherit' }
129147
)
130148
}
149+
/**
150+
* Checks the sizes of all targets.
151+
* @param {string[]} targets - The targets to check sizes for.
152+
* @returns {void}
153+
*/
131154

132155
function checkAllSizes(targets) {
133156
if (devOnly || (formats && !formats.includes('global'))) {
@@ -140,6 +163,11 @@ function checkAllSizes(targets) {
140163
console.log()
141164
}
142165

166+
/**
167+
* Checks the size of a target.
168+
* @param {string} target - The target to check the size for.
169+
* @returns {void}
170+
*/
143171
function checkSize(target) {
144172
const pkgDir = path.resolve(`packages/${target}`)
145173
checkFileSize(`${pkgDir}/dist/${target}.global.prod.js`)
@@ -148,6 +176,11 @@ function checkSize(target) {
148176
}
149177
}
150178

179+
/**
180+
* Checks the file size.
181+
* @param {string} filePath - The path of the file to check the size for.
182+
* @returns {void}
183+
*/
151184
function checkFileSize(filePath) {
152185
if (!existsSync(filePath)) {
153186
return

0 commit comments

Comments
 (0)