| 122 | } |
| 123 | |
| 124 | function resolveNgCommand( |
| 125 | args: readonly string[], |
| 126 | cwd?: string, |
| 127 | ): { command: string; args: readonly string[] } { |
| 128 | const defaultCommand = { command: 'ng', args }; |
| 129 | if (!cwd) { |
| 130 | return defaultCommand; |
| 131 | } |
| 132 | |
| 133 | try { |
| 134 | const workspaceRequire = createRequire(join(cwd, 'package.json')); |
| 135 | const pkgJsonPath = workspaceRequire.resolve('@angular/cli/package.json'); |
| 136 | const pkgJson = workspaceRequire(pkgJsonPath) as { bin?: string | Record<string, string> }; |
| 137 | const binPath = typeof pkgJson.bin === 'string' ? pkgJson.bin : pkgJson.bin?.['ng']; |
| 138 | |
| 139 | if (binPath) { |
| 140 | const ngJsPath = resolve(dirname(pkgJsonPath), binPath); |
| 141 | |
| 142 | return { |
| 143 | command: process.execPath, |
| 144 | args: [ngJsPath, ...args], |
| 145 | }; |
| 146 | } |
| 147 | } catch { |
| 148 | // Failed to resolve the CLI binary, fall back to assuming `ng` is on PATH. |
| 149 | } |
| 150 | |
| 151 | return defaultCommand; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * A concrete implementation of the `Host` interface that runs on a local workspace. |