MCPcopy Index your code
hub / github.com/angular/angular-cli / resolveNgCommand

Function resolveNgCommand

packages/angular/cli/src/commands/mcp/host.ts:124–152  ·  view source on GitHub ↗
(
  args: readonly string[],
  cwd?: string,
)

Source from the content-addressed store, hash-verified

122}
123
124function 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.

Callers 2

host.tsFile · 0.85
startNgProcessFunction · 0.85

Calls 4

joinFunction · 0.85
resolveMethod · 0.80
resolveFunction · 0.50
dirnameFunction · 0.50

Tested by

no test coverage detected