Skip to content

Commit d69d8d1

Browse files
committed
limit concurrent command execution
1 parent dcabfc9 commit d69d8d1

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"terse": "ts-node scripts/terse.ts lib/"
1515
},
1616
"dependencies": {
17-
"env-cmd": "^10.1.0"
17+
"env-cmd": "^10.1.0",
18+
"p-limit": "^3.0.1"
1819
},
1920
"devDependencies": {
2021
"@types/node": "^14.0.19",

src/helpers/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { access } from 'fs/promises'
22
import { exec as execCallback } from 'child_process'
3+
import pLimit = require('p-limit')
34

45
export const exists = (path: string) => access(path).then(_ => true).catch(_ => false)
56

67
export const exec = (cmd: string): Promise<string> => new Promise( (res,rej) =>
78
execCallback( cmd, (_,stdout,stderr) => res(stdout + stderr) )
89
)
10+
11+
export const limit = pLimit(8)

src/utils/vercel-env.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { exec } from '../helpers/helpers'
1+
import { exec, limit } from '../helpers/helpers'
22
import { printStdout } from '../helpers/print'
33
import { getEnvVarMap } from './get-env'
44
import type { DeploymentEnv, EnvVarMap } from '../types/types'
@@ -7,7 +7,7 @@ const removeEnv = async (deploymentEnv: DeploymentEnv, envVarMap: EnvVarMap) =>
77
const stdoutList: Promise<void>[] = []
88
for (const varName in envVarMap) {
99
stdoutList.push(
10-
exec( `vercel env rm ${varName} ${deploymentEnv} -y` ).then(printStdout)
10+
limit(() => exec( `vercel env rm ${varName} ${deploymentEnv} -y` ).then(printStdout))
1111
)
1212
}
1313

@@ -19,7 +19,7 @@ const addEnv = async (deploymentEnv: DeploymentEnv, envVarMap: EnvVarMap) => {
1919
for (const varName in envVarMap) {
2020
const varValue = envVarMap[varName]
2121
stdoutList.push(
22-
exec( `echo -n ${varValue} | vercel env add ${varName} ${deploymentEnv}` ).then(printStdout)
22+
limit(() => exec( `echo -n ${varValue} | vercel env add ${varName} ${deploymentEnv}` ).then(printStdout))
2323
)
2424
}
2525

0 commit comments

Comments
 (0)