Skip to content

Commit 2c95fd4

Browse files
committed
perf: only calculate minijsonBin once
1 parent 713cb5f commit 2c95fd4

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/node/lib.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { join } from "path"
44
/**
55
* Minify all the given JSON files in place. It minifies the files in parallel.
66
*
7-
* @param files The paths to the files
7+
* @param files an array of paths to the files
88
* @returns {Promise<void>} Returns a void promise that resolves when all the files are minified
99
* @throws {Promise<string | Error>} The promise is rejected with the reason for failure
1010
*/
@@ -36,18 +36,19 @@ export async function minifyString(jsonString: string): Promise<string> {
3636
return (await spawnMinijson(["--string", jsonString])).trim()
3737
}
3838

39+
const exeExtention = process.platform === "win32" ? ".exe" : ""
40+
const binName = `minijson${exeExtention}`
41+
42+
const minijsonBin = join(__dirname, `${process.platform}-${process.arch}`, binName)
43+
3944
/**
4045
* Spawn minijson with the given arguments
4146
*
47+
* @param args an array of arguments
4248
* @returns {Promise<string>} Returns a promise that resolves to stdout output string when the operation finishes
4349
* @throws {Promise<string | Error>} The promise is rejected with the reason for failure
4450
*/
4551
export function spawnMinijson(args: string[]): Promise<string> {
46-
const exeExtention = process.platform === "win32" ? ".exe" : ""
47-
const binName = `minijson${exeExtention}`
48-
49-
const minijsonBin = join(__dirname, `${process.platform}-${process.arch}`, binName)
50-
5152
return new Promise<string>((resolve, reject) => {
5253
execFile(minijsonBin, args, (err, stdout, stderr) => {
5354
if (err) {

0 commit comments

Comments
 (0)