Skip to content

Commit e37e3db

Browse files
committed
feat(cli): delegate commands to gnd by default
`graph <cmd>` now execs the matching `gnd <cmd>` (the Rust `@graphprotocol/gnd` binary). Two exceptions stay on the oclif/TS path: `local`, which has no gnd equivalent, and `dev`, which is a thin oclif shim that spawns `gnd dev` so the command is discoverable from `graph --help`. Set `GRAPH_CLI_IGNORE_GND=1` to force the TS implementation everywhere; the test suite does this automatically.
1 parent 4bfb55f commit e37e3db

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

packages/cli/bin/run.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import process from 'node:process';
33
import semver from 'semver';
44
import { execute } from '@oclif/core';
5+
import { runGnd } from '../dist/command-helpers/gnd.js';
56
import { nodeVersion } from '../dist/version.js';
67

78
if (!semver.satisfies(process.version, nodeVersion)) {
@@ -11,4 +12,11 @@ if (!semver.satisfies(process.version, nodeVersion)) {
1112
process.exit(1);
1213
}
1314

14-
await execute({ dir: import.meta.url });
15+
const args = process.argv.slice(2);
16+
const useGnd = !process.env.GRAPH_CLI_IGNORE_GND && args[0] !== 'local';
17+
18+
if (useGnd) {
19+
runGnd(args);
20+
} else {
21+
await execute({ dir: import.meta.url });
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { spawnSync } from 'node:child_process';
2+
import { createRequire } from 'node:module';
3+
import process from 'node:process';
4+
5+
const require = createRequire(import.meta.url);
6+
7+
export function runGnd(args: string[]): never {
8+
const gndEntry = require.resolve('@graphprotocol/gnd/bin/gnd.js');
9+
const result = spawnSync(process.execPath, [gndEntry, ...args], { stdio: 'inherit' });
10+
if (result.error) {
11+
process.stderr.write(`Failed to launch gnd: ${result.error.message}\n`);
12+
process.exit(1);
13+
}
14+
if (result.signal) {
15+
process.kill(process.pid, result.signal);
16+
}
17+
process.exit(result.status ?? 1);
18+
}

packages/cli/src/commands/dev.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Command } from '@oclif/core';
2+
import { runGnd } from '../command-helpers/gnd.js';
3+
4+
export default class DevCommand extends Command {
5+
static description =
6+
'Run graph-node in dev mode. Delegates to `gnd dev`; run `graph dev --help` (without GRAPH_CLI_IGNORE_GND set) for the full list of supported flags.';
7+
8+
static strict = false;
9+
10+
static args = {};
11+
12+
async run() {
13+
runGnd(['dev', ...this.argv]);
14+
}
15+
}

packages/cli/tests/cli/globalSetup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ import { linkCli } from './link';
44

55
export default async () => {
66
process.env.GRAPH_CLI_TESTS = '1';
7+
process.env.GRAPH_CLI_IGNORE_GND = '1';
78
await linkCli();
89
};

0 commit comments

Comments
 (0)