( client: Client, name: string, args: string[], cwd: string )
| 18 | * error is thrown. |
| 19 | */ |
| 20 | export async function execExtension( |
| 21 | client: Client, |
| 22 | name: string, |
| 23 | args: string[], |
| 24 | cwd: string |
| 25 | ): Promise<number> { |
| 26 | const { debug, error } = output; |
| 27 | const extensionCommand = `vercel-${name}`; |
| 28 | |
| 29 | const { packageJsonPath, lockfilePath } = await scanParentDirs(cwd); |
| 30 | const baseFile = lockfilePath || packageJsonPath; |
| 31 | let extensionPath: string | null = null; |
| 32 | |
| 33 | if (baseFile) { |
| 34 | // Scan `node_modules/.bin` works for npm / pnpm / yarn v1 |
| 35 | // TOOD: add support for Yarn PnP |
| 36 | extensionPath = await walkParentDirs({ |
| 37 | base: dirname(baseFile), |
| 38 | start: cwd, |
| 39 | filename: `node_modules/.bin/${extensionCommand}`, |
| 40 | }); |
| 41 | } |
| 42 | |
| 43 | if (!extensionPath) { |
| 44 | // Attempt global `$PATH` lookup |
| 45 | extensionPath = which.sync(extensionCommand, { nothrow: true }); |
| 46 | } |
| 47 | |
| 48 | if (!extensionPath) { |
| 49 | debug(`failed to find extension command with name "${extensionCommand}"`); |
| 50 | throw new ENOENT(extensionCommand); |
| 51 | } |
| 52 | |
| 53 | debug(`invoking extension: ${extensionPath}`); |
| 54 | |
| 55 | const proxy = createProxy(client); |
| 56 | proxy.once('close', () => { |
| 57 | debug(`extension proxy server shut down`); |
| 58 | }); |
| 59 | |
| 60 | const proxyUrl = await listen(proxy, { port: 0, host: '127.0.0.1' }); |
| 61 | const VERCEL_API = proxyUrl.href.replace(/\/$/, ''); |
| 62 | debug(`extension proxy server listening at ${VERCEL_API}`); |
| 63 | let exitCode = 0; |
| 64 | |
| 65 | try { |
| 66 | const result = await execa(extensionPath, args, { |
| 67 | cwd, |
| 68 | stdio: 'inherit', |
| 69 | reject: false, |
| 70 | env: { |
| 71 | ...process.env, |
| 72 | VERCEL_API, |
| 73 | // TODO: |
| 74 | // VERCEL_SCOPE |
| 75 | // VERCEL_DEBUG |
| 76 | // VERCEL_HELP |
| 77 | }, |
no test coverage detected