@hydranium/cli 1.0.0-next.27 → 1.0.0-next.270
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -204
- package/bin/hydranium-cli.js +13 -0
- package/lib/cli-version.js.map +1 -1
- package/lib/cli.js +2 -1
- package/lib/cli.js.map +1 -1
- package/lib/commands/analyze-heap-args.js.map +1 -1
- package/lib/commands/analyze-heap.d.ts +3 -0
- package/lib/commands/analyze-heap.d.ts.map +1 -1
- package/lib/commands/analyze-heap.js +2 -1
- package/lib/commands/analyze-heap.js.map +1 -1
- package/lib/commands/ast-ground-truth-args.d.ts +3 -2
- package/lib/commands/ast-ground-truth-args.d.ts.map +1 -1
- package/lib/commands/ast-ground-truth-args.js +11 -9
- package/lib/commands/ast-ground-truth-args.js.map +1 -1
- package/lib/commands/ast-ground-truth-driver.js +2 -1
- package/lib/commands/ast-ground-truth-driver.js.map +1 -1
- package/lib/commands/ast-ground-truth.js +1 -1
- package/lib/commands/ast-ground-truth.js.map +1 -1
- package/lib/commands/generate-ast-builder.d.ts +49 -0
- package/lib/commands/generate-ast-builder.d.ts.map +1 -0
- package/lib/commands/generate-ast-builder.js +200 -0
- package/lib/commands/generate-ast-builder.js.map +1 -0
- package/lib/commands/generate-transfer-model-args.d.ts.map +1 -1
- package/lib/commands/generate-transfer-model-args.js +11 -1
- package/lib/commands/generate-transfer-model-args.js.map +1 -1
- package/lib/commands/generate-transfer-model-config.d.ts.map +1 -1
- package/lib/commands/generate-transfer-model-config.js +6 -3
- package/lib/commands/generate-transfer-model-config.js.map +1 -1
- package/lib/commands/generate-transfer-model.d.ts +9 -0
- package/lib/commands/generate-transfer-model.d.ts.map +1 -1
- package/lib/commands/generate-transfer-model.js +18 -4
- package/lib/commands/generate-transfer-model.js.map +1 -1
- package/lib/commands/harness-args.d.ts +37 -42
- package/lib/commands/harness-args.d.ts.map +1 -1
- package/lib/commands/harness-args.js +91 -27
- package/lib/commands/harness-args.js.map +1 -1
- package/lib/commands/headless-harness.d.ts +37 -20
- package/lib/commands/headless-harness.d.ts.map +1 -1
- package/lib/commands/headless-harness.js +68 -17
- package/lib/commands/headless-harness.js.map +1 -1
- package/lib/commands/init-args.js +6 -6
- package/lib/commands/init-args.js.map +1 -1
- package/lib/commands/init-prompt.d.ts.map +1 -1
- package/lib/commands/init-templates.d.ts +8 -10
- package/lib/commands/init-templates.d.ts.map +1 -1
- package/lib/commands/init-templates.js +260 -152
- package/lib/commands/init-templates.js.map +1 -1
- package/lib/commands/init-wizard.js +4 -4
- package/lib/commands/init-wizard.js.map +1 -1
- package/lib/commands/init-workspace.d.ts +13 -3
- package/lib/commands/init-workspace.d.ts.map +1 -1
- package/lib/commands/init-workspace.js +21 -6
- package/lib/commands/init-workspace.js.map +1 -1
- package/lib/commands/init.d.ts +16 -10
- package/lib/commands/init.d.ts.map +1 -1
- package/lib/commands/init.js +17 -15
- package/lib/commands/init.js.map +1 -1
- package/lib/commands/lint-grammar-args.d.ts +3 -2
- package/lib/commands/lint-grammar-args.d.ts.map +1 -1
- package/lib/commands/lint-grammar-args.js +13 -10
- package/lib/commands/lint-grammar-args.js.map +1 -1
- package/lib/commands/lint-grammar-driver.js +2 -1
- package/lib/commands/lint-grammar-driver.js.map +1 -1
- package/lib/commands/lint-grammar-report.js.map +1 -1
- package/lib/commands/lint-grammar.js +1 -1
- package/lib/commands/lint-grammar.js.map +1 -1
- package/lib/commands/measure-memory-args.d.ts +3 -2
- package/lib/commands/measure-memory-args.d.ts.map +1 -1
- package/lib/commands/measure-memory-args.js +22 -11
- package/lib/commands/measure-memory-args.js.map +1 -1
- package/lib/commands/measure-memory-driver.js +5 -3
- package/lib/commands/measure-memory-driver.js.map +1 -1
- package/lib/commands/measure-memory.js +1 -1
- package/lib/commands/measure-memory.js.map +1 -1
- package/lib/commands/model-docs-args.d.ts +4 -3
- package/lib/commands/model-docs-args.d.ts.map +1 -1
- package/lib/commands/model-docs-args.js +12 -10
- package/lib/commands/model-docs-args.js.map +1 -1
- package/lib/commands/model-docs-driver.js +2 -1
- package/lib/commands/model-docs-driver.js.map +1 -1
- package/lib/commands/model-docs.js +1 -1
- package/lib/commands/model-docs.js.map +1 -1
- package/lib/commands/projects-args.d.ts.map +1 -1
- package/lib/commands/projects-args.js +5 -5
- package/lib/commands/projects-args.js.map +1 -1
- package/lib/commands/projects.d.ts +3 -4
- package/lib/commands/projects.d.ts.map +1 -1
- package/lib/commands/projects.js +2 -2
- package/lib/commands/projects.js.map +1 -1
- package/lib/commands/query-args.d.ts.map +1 -1
- package/lib/commands/query-args.js +5 -5
- package/lib/commands/query-args.js.map +1 -1
- package/lib/commands/query.d.ts +3 -4
- package/lib/commands/query.d.ts.map +1 -1
- package/lib/commands/query.js +2 -2
- package/lib/commands/query.js.map +1 -1
- package/lib/commands/reflect-args.d.ts +3 -2
- package/lib/commands/reflect-args.d.ts.map +1 -1
- package/lib/commands/reflect-args.js +13 -10
- package/lib/commands/reflect-args.js.map +1 -1
- package/lib/commands/reflect-driver.js +2 -1
- package/lib/commands/reflect-driver.js.map +1 -1
- package/lib/commands/reflect-report.js.map +1 -1
- package/lib/commands/reflect.js +1 -1
- package/lib/commands/reflect.js.map +1 -1
- package/lib/commands/save-args.d.ts.map +1 -1
- package/lib/commands/save-args.js +6 -4
- package/lib/commands/save-args.js.map +1 -1
- package/lib/commands/save.d.ts +8 -4
- package/lib/commands/save.d.ts.map +1 -1
- package/lib/commands/save.js +31 -6
- package/lib/commands/save.js.map +1 -1
- package/lib/commands/validate-args.d.ts +3 -2
- package/lib/commands/validate-args.d.ts.map +1 -1
- package/lib/commands/validate-args.js +13 -10
- package/lib/commands/validate-args.js.map +1 -1
- package/lib/commands/validate-driver.js +2 -1
- package/lib/commands/validate-driver.js.map +1 -1
- package/lib/commands/validate-report.js.map +1 -1
- package/lib/commands/validate.js +1 -1
- package/lib/commands/validate.js.map +1 -1
- package/lib/commands/watch-args.d.ts.map +1 -1
- package/lib/commands/watch-args.js +6 -4
- package/lib/commands/watch-args.js.map +1 -1
- package/lib/commands/watch.d.ts +3 -4
- package/lib/commands/watch.d.ts.map +1 -1
- package/lib/commands/watch.js +20 -2
- package/lib/commands/watch.js.map +1 -1
- package/lib/driver-heap.d.ts +52 -0
- package/lib/driver-heap.d.ts.map +1 -0
- package/lib/driver-heap.js +51 -0
- package/lib/driver-heap.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/log-level.d.ts +21 -11
- package/lib/log-level.d.ts.map +1 -1
- package/lib/log-level.js +25 -14
- package/lib/log-level.js.map +1 -1
- package/lib/spawn-data-server.d.ts +6 -1
- package/lib/spawn-data-server.d.ts.map +1 -1
- package/lib/spawn-data-server.js +2 -1
- package/lib/spawn-data-server.js.map +1 -1
- package/lib/stderr-connection-logger.d.ts +12 -0
- package/lib/stderr-connection-logger.d.ts.map +1 -0
- package/lib/stderr-connection-logger.js +16 -0
- package/lib/stderr-connection-logger.js.map +1 -0
- package/lib/testing/echo-server.js +9 -1
- package/lib/testing/echo-server.js.map +1 -1
- package/package.json +50 -39
- package/src/cli.ts +2 -1
- package/src/commands/analyze-heap.ts +4 -1
- package/src/commands/ast-ground-truth-args.ts +15 -12
- package/src/commands/ast-ground-truth-driver.ts +2 -1
- package/src/commands/ast-ground-truth.ts +1 -1
- package/src/commands/generate-ast-builder.ts +246 -0
- package/src/commands/generate-transfer-model-args.ts +11 -1
- package/src/commands/generate-transfer-model-config.ts +6 -3
- package/src/commands/generate-transfer-model.ts +27 -4
- package/src/commands/harness-args.ts +76 -31
- package/src/commands/headless-harness.ts +86 -26
- package/src/commands/init-args.ts +6 -6
- package/src/commands/init-templates.ts +270 -154
- package/src/commands/init-wizard.ts +4 -4
- package/src/commands/init-workspace.ts +31 -7
- package/src/commands/init.ts +36 -26
- package/src/commands/lint-grammar-args.ts +17 -13
- package/src/commands/lint-grammar-driver.ts +2 -1
- package/src/commands/lint-grammar.ts +1 -1
- package/src/commands/measure-memory-args.ts +27 -14
- package/src/commands/measure-memory-driver.ts +5 -3
- package/src/commands/measure-memory.ts +1 -1
- package/src/commands/model-docs-args.ts +16 -13
- package/src/commands/model-docs-driver.ts +2 -1
- package/src/commands/model-docs.ts +1 -1
- package/src/commands/projects-args.ts +5 -4
- package/src/commands/projects.ts +4 -6
- package/src/commands/query-args.ts +5 -4
- package/src/commands/query.ts +4 -6
- package/src/commands/reflect-args.ts +17 -13
- package/src/commands/reflect-driver.ts +2 -1
- package/src/commands/reflect.ts +1 -1
- package/src/commands/save-args.ts +6 -3
- package/src/commands/save.ts +47 -10
- package/src/commands/validate-args.ts +17 -13
- package/src/commands/validate-driver.ts +2 -1
- package/src/commands/validate.ts +1 -1
- package/src/commands/watch-args.ts +6 -3
- package/src/commands/watch.ts +28 -7
- package/src/driver-heap.ts +65 -0
- package/src/index.ts +1 -0
- package/src/log-level.ts +42 -14
- package/src/spawn-data-server.ts +14 -2
- package/src/stderr-connection-logger.ts +18 -0
- package/src/testing/echo-server.ts +11 -2
package/package.json
CHANGED
|
@@ -1,34 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hydranium/cli",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.270",
|
|
4
4
|
"description": "Build-time codegen tools + data-server subcommands for the hydranium framework.",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"cli",
|
|
7
|
+
"codegen",
|
|
6
8
|
"hydranium",
|
|
7
9
|
"langium",
|
|
8
10
|
"language-server",
|
|
9
|
-
"lsp"
|
|
10
|
-
"cli",
|
|
11
|
-
"codegen"
|
|
11
|
+
"lsp"
|
|
12
12
|
],
|
|
13
13
|
"homepage": "https://github.com/eclipse-emfcloud/hydranium/tree/main/packages/cli",
|
|
14
14
|
"bugs": {
|
|
15
15
|
"url": "https://github.com/eclipse-emfcloud/hydranium/issues"
|
|
16
16
|
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Hydranium Team"
|
|
20
|
+
},
|
|
17
21
|
"repository": {
|
|
18
22
|
"type": "git",
|
|
19
23
|
"url": "https://github.com/eclipse-emfcloud/hydranium.git",
|
|
20
24
|
"directory": "packages/cli"
|
|
21
25
|
},
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
"name": "Hydranium Team"
|
|
26
|
+
"bin": {
|
|
27
|
+
"hydranium-cli": "bin/hydranium-cli.js"
|
|
25
28
|
},
|
|
29
|
+
"files": [
|
|
30
|
+
"bin",
|
|
31
|
+
"lib",
|
|
32
|
+
"src",
|
|
33
|
+
"heap-analysis",
|
|
34
|
+
"!lib/**/*.tsbuildinfo"
|
|
35
|
+
],
|
|
36
|
+
"type": "module",
|
|
26
37
|
"sideEffects": [
|
|
27
38
|
"./lib/cli.js",
|
|
28
39
|
"./lib/commands/*-driver.js",
|
|
29
40
|
"./lib/testing/echo-server.js"
|
|
30
41
|
],
|
|
31
|
-
"
|
|
42
|
+
"main": "lib/index.js",
|
|
43
|
+
"types": "lib/index.d.ts",
|
|
32
44
|
"exports": {
|
|
33
45
|
".": {
|
|
34
46
|
"types": "./lib/index.d.ts",
|
|
@@ -39,21 +51,13 @@
|
|
|
39
51
|
"default": "./lib/cli.js"
|
|
40
52
|
}
|
|
41
53
|
},
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
"bin": {
|
|
45
|
-
"hydranium-cli": "lib/cli.js"
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
46
56
|
},
|
|
47
|
-
"files": [
|
|
48
|
-
"lib",
|
|
49
|
-
"src",
|
|
50
|
-
"heap-analysis",
|
|
51
|
-
"!lib/**/*.tsbuildinfo"
|
|
52
|
-
],
|
|
53
57
|
"scripts": {
|
|
54
|
-
"build": "tsc -b
|
|
58
|
+
"build": "tsc -b",
|
|
55
59
|
"clean": "rimraf lib tsconfig.tsbuildinfo",
|
|
56
|
-
"lint": "
|
|
60
|
+
"lint": "oxlint --format stylish --config ../../oxlint.config.cjs src test --max-warnings 0",
|
|
57
61
|
"prepack": "node -e \"const m=require('./package.json'),fs=require('node:fs');const missing=[m.main,...Object.values(m.bin||{})].filter(entry=>entry&&!fs.existsSync(entry));if(missing.length){console.error('prepack '+m.name+': not built ('+missing.join(', ')+' missing). Run the build before packing: a files entry that matches nothing is skipped silently, so the tarball would ship src only.');process.exit(1);}\"",
|
|
58
62
|
"test": "npm run typecheck:test && vitest run",
|
|
59
63
|
"typecheck:test": "tsc --noEmit -p tsconfig.test.json",
|
|
@@ -65,23 +69,33 @@
|
|
|
65
69
|
"ts-morph": "^25.0.0"
|
|
66
70
|
},
|
|
67
71
|
"devDependencies": {
|
|
68
|
-
"@
|
|
69
|
-
"@
|
|
70
|
-
"@hydranium/
|
|
71
|
-
"@hydranium/
|
|
72
|
+
"@eclipse-glsp/graph": "2.7.0",
|
|
73
|
+
"@eclipse-glsp/server": "2.7.0",
|
|
74
|
+
"@hydranium/core": "1.0.0-next.270",
|
|
75
|
+
"@hydranium/data-server": "1.0.0-next.270",
|
|
76
|
+
"@hydranium/glsp-server": "1.0.0-next.270",
|
|
77
|
+
"@hydranium/langium": "1.0.0-next.270",
|
|
78
|
+
"@hydranium/protocol": "1.0.0-next.270",
|
|
79
|
+
"@types/node": "^22.0.0",
|
|
80
|
+
"inversify": "6.2.2",
|
|
81
|
+
"langium": "4.3.1",
|
|
82
|
+
"langium-cli": "4.3.0",
|
|
83
|
+
"reflect-metadata": "0.2.2",
|
|
72
84
|
"rimraf": "^5.0.0",
|
|
73
|
-
"typescript": "^
|
|
74
|
-
"
|
|
75
|
-
"vscode-
|
|
85
|
+
"typescript": "^7.0.2",
|
|
86
|
+
"vitest": "^4.0.0",
|
|
87
|
+
"vscode-jsonrpc": "9.0.0",
|
|
88
|
+
"vscode-languageserver": "10.0.1",
|
|
89
|
+
"vscode-languageserver-protocol": "3.18.1"
|
|
76
90
|
},
|
|
77
91
|
"peerDependencies": {
|
|
78
|
-
"@hydranium/core": "1.0.0-next.
|
|
79
|
-
"@hydranium/data-server": "1.0.0-next.
|
|
80
|
-
"@hydranium/langium": "1.0.0-next.
|
|
81
|
-
"@hydranium/protocol": "1.0.0-next.
|
|
92
|
+
"@hydranium/core": "1.0.0-next.270",
|
|
93
|
+
"@hydranium/data-server": "1.0.0-next.270",
|
|
94
|
+
"@hydranium/langium": "1.0.0-next.270",
|
|
95
|
+
"@hydranium/protocol": "1.0.0-next.270",
|
|
82
96
|
"@memlab/core": "^2.0.3",
|
|
83
97
|
"@memlab/heap-analysis": "^2.0.3",
|
|
84
|
-
"vscode-jsonrpc": "9.0.
|
|
98
|
+
"vscode-jsonrpc": "^9.0.0"
|
|
85
99
|
},
|
|
86
100
|
"peerDependenciesMeta": {
|
|
87
101
|
"@memlab/core": {
|
|
@@ -94,13 +108,10 @@
|
|
|
94
108
|
"engines": {
|
|
95
109
|
"node": ">=22.13"
|
|
96
110
|
},
|
|
97
|
-
"
|
|
98
|
-
|
|
99
|
-
},
|
|
100
|
-
"//build": "The chmod is load-bearing, not cruft. npm sets a bin's executable bit through bin-links' fixBin, but ONLY when it first creates the link — and `tsc` never sets it, so after `npm run clean` (which deletes lib/) a rebuild leaves lib/cli.js at 0644 and the node_modules/.bin/hydranium-cli symlink resolves to a non-executable target. Every example's `generate` step then dies with `sh: hydranium-cli: Permission denied`, surfacing as an opaque npm error code 127 during `turbo run build`. npm rebuild, npm rebuild @hydranium/cli AND a full npm install all fail to restore it, because npm will not revisit an existing workspace symlink; only a from-scratch `rm -rf node_modules` install does. Written as `node -e` rather than `chmod +x` so it stays portable — on Windows npm generates .cmd/.ps1 shims where the bit is irrelevant and chmodSync is harmless. The example packages' bins need no such step: their tests spawn them via process.execPath, never through the shim.",
|
|
101
|
-
"//exports": "Two keys, and the SHORT list is the point: `files` ships the whole compiled tree, so without a map every `lib/commands/*.js`, every internal helper and `lib/testing/echo-server.js` is deep-importable the moment this publishes, and semver then applies to all of it. `.` is the library barrel (the data-server subcommands an adopter calls as functions). `./lib/cli.js` is the BINARY ARTEFACT, and it is declared because a consumer that spawns the CLI resolves it BY SPECIFIER — `createRequire(import.meta.url).resolve('@hydranium/cli/lib/cli.js')` — to get the path npx would run; `bin` gives a shim on PATH, not a path, so dropping this key breaks that resolution and the failure surfaces as \"hydranium-cli is not built\", naming the wrong cause. It is declared in the `/lib/` spelling ONLY: that spelling already resolves under both of this repo's module resolvers, so the twin rule (which exists so a BARE subpath is reachable from node10) has nothing to add here and a bare twin would only be a second name for one artefact. `heap-analysis/` needs no key even though `files` ships it — `analyze-heap` reaches the analyzer through a `new URL(..., import.meta.url)` file URL, which `exports` does not gate, and the package's own tests reach it relatively. `./testing` is deliberately absent: `echo-server` is a spawnable stdio fixture, not a reusable export.",
|
|
111
|
+
"//devDependencies": "Every package an `init` scaffold declares, other than this one, is declared here, whether or not `src` uses it: the scaffold-compiles test compiles and runs scaffolds inside this package, so their imports and tools resolve through these declarations. `check:init-provenance` holds this list and its versions to the scaffold's manifest.",
|
|
112
|
+
"//exports": "Two keys, and the SHORT list is the point: `files` ships the whole compiled tree, so without a map every `lib/commands/*.js`, every internal helper and `lib/testing/echo-server.js` is deep-importable the moment this publishes, and semver then applies to all of it. `.` is the library barrel (the data-server subcommands an adopter calls as functions). `./lib/cli.js` is the BINARY ARTEFACT, and it is declared because a consumer that spawns the CLI resolves it BY SPECIFIER — `createRequire(import.meta.url).resolve('@hydranium/cli/lib/cli.js')` — to get the path npx would run; `bin` gives a shim on PATH, not a path, so dropping this key breaks that resolution and the failure surfaces as \"hydranium-cli is not built\", naming the wrong cause. `heap-analysis/` needs no key even though `files` ships it — `analyze-heap` reaches the analyzer through a `new URL(..., import.meta.url)` file URL, which `exports` does not gate, and the package's own tests reach it relatively. `./testing` is deliberately absent: `echo-server` is a spawnable stdio fixture, not a reusable export.",
|
|
102
113
|
"//memlab": "@memlab/core and @memlab/heap-analysis are OPTIONAL PEER dependencies, not optionalDependencies, and the distinction is the whole point: npm installs optionalDependencies BY DEFAULT, both memlab packages pin puppeteer exactly, and puppeteer's postinstall downloads a Chrome binary — so every adopter of this CLI paid ~86 MB and a browser download for the one subcommand almost none of them run, and the download can fail and be walked past as a warning. An optional peer is not auto-installed, so `analyze-heap` documents `npm install @memlab/core @memlab/heap-analysis` as the opt-in and every other subcommand is unaffected. Taken pre-publish deliberately: after publish the install shape is what adopters already have.",
|
|
103
|
-
"//peerDependencies": "`vscode-jsonrpc`
|
|
104
|
-
"//prepack": "The publish guard,
|
|
114
|
+
"//peerDependencies": "`vscode-jsonrpc` takes a caret, so the framework shares the transport the LSP connection resolves, which an `init` scaffold pins: each `vscode-languageserver-protocol` release pins its transport exactly, so an exact peer would name a copy a fresh install rarely holds. The caret excludes 8.x, so a tree whose top holds GLSP's copy fails the peer with a named ERESOLVE warning, an error under `--strict-peer-deps`, rather than resolving silently. No peer reaches a NESTED copy, such as GLSP's or one the LSP packages nest. The wire compares message types and `ResponseError`s by copy identity, so the framework sends typed messages by method name and recognises errors with `isResponseError` rather than `instanceof`.",
|
|
115
|
+
"//prepack": "The publish guard, a `prepack` rather than a `prepare`: `prepack` runs only when a tarball is made (`npm pack`, `npm publish`) and never on install, so it cannot break the install it has no business touching. What it defends against: `files` lists `lib`, `lib` is gitignored, and a `files` entry matching nothing is skipped SILENTLY — so `npm publish` from an unbuilt tree emits a tarball of `src` and nothing else, with no error.",
|
|
105
116
|
"//sideEffects": "The listed modules RUN on load rather than exporting anything: `cli.js` is the `bin`, each `*-driver.js` is spawned as its own process and calls `main(process.argv)` at top level, and `echo-server.js` starts a server. Their whole purpose is the effect, so a bundler must never treat them as prunable. Everything else here is library code with no module-level state beyond `new URL(..., import.meta.url)` constants."
|
|
106
117
|
}
|
package/src/cli.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
********************************************************************************/
|
|
10
10
|
|
|
11
11
|
import { Command } from 'commander';
|
|
12
|
+
import { describeError } from '@hydranium/protocol';
|
|
12
13
|
import { readCliVersion } from './cli-version.js';
|
|
13
14
|
import { runAnalyzeHeapCommand } from './commands/analyze-heap-args.js';
|
|
14
15
|
import { runAstGroundTruthCommand } from './commands/ast-ground-truth-args.js';
|
|
@@ -134,6 +135,6 @@ main(process.argv.slice(2)).catch(err => {
|
|
|
134
135
|
if (err instanceof InitWizardCancelled) {
|
|
135
136
|
process.exit(130);
|
|
136
137
|
}
|
|
137
|
-
console.error(
|
|
138
|
+
console.error(describeError(err));
|
|
138
139
|
process.exit(1);
|
|
139
140
|
});
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { driverHeapArgs, type HeapReading } from '../driver-heap.js';
|
|
11
12
|
import { spawnNodeChild } from './headless-harness.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -41,6 +42,8 @@ export interface AnalyzeHeapDeps {
|
|
|
41
42
|
readonly __spawnForTest?: (execArgs: string[]) => Promise<number>;
|
|
42
43
|
/** Override the memlab-availability check. */
|
|
43
44
|
readonly __memlabInstalledForTest?: () => boolean;
|
|
45
|
+
/** Decide the heap ceiling from a stated cgroup reading rather than the machine's. */
|
|
46
|
+
readonly __heapReadingForTest?: HeapReading;
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
/**
|
|
@@ -69,7 +72,7 @@ export async function runAnalyzeHeap(args: string[], deps: AnalyzeHeapDeps = {})
|
|
|
69
72
|
return;
|
|
70
73
|
}
|
|
71
74
|
const spawnChild = deps.__spawnForTest ?? spawnNodeChild;
|
|
72
|
-
const code = await spawnChild([
|
|
75
|
+
const code = await spawnChild([...driverHeapArgs(deps.__heapReadingForTest), ANALYZER, ...args]);
|
|
73
76
|
if (code) {
|
|
74
77
|
process.exitCode = code;
|
|
75
78
|
}
|
|
@@ -10,32 +10,34 @@
|
|
|
10
10
|
import { runAstGroundTruth, type AstGroundTruthCommandOptions } from './ast-ground-truth.js';
|
|
11
11
|
import {
|
|
12
12
|
exitWithUsage,
|
|
13
|
+
HARNESS_VALUE_FLAGS,
|
|
13
14
|
helpRequested,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
importHelpLines,
|
|
16
|
+
LOG_VALUE_FLAGS,
|
|
17
|
+
logHelpLines,
|
|
18
|
+
logOptions,
|
|
17
19
|
parseHarnessArgs,
|
|
18
20
|
printHelp,
|
|
19
|
-
SERVICES_FLAG,
|
|
20
21
|
type UsageError
|
|
21
22
|
} from './harness-args.js';
|
|
22
23
|
import { OUT_FILE_FLAG } from './headless-harness.js';
|
|
23
24
|
|
|
24
|
-
const VALUE_FLAGS = [OUT_FILE_FLAG,
|
|
25
|
+
const VALUE_FLAGS = [OUT_FILE_FLAG, ...LOG_VALUE_FLAGS] as const;
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Every flag `ast-ground-truth` accepts, derived from the sets the parser is
|
|
28
|
-
* handed so the list cannot claim a flag the parser would reject.
|
|
29
|
-
*
|
|
29
|
+
* handed so the list cannot claim a flag the parser would reject.
|
|
30
|
+
* {@link HARNESS_VALUE_FLAGS} are consumed by the shared harness parser itself,
|
|
31
|
+
* so they are in neither set.
|
|
30
32
|
*/
|
|
31
|
-
export const AST_GROUND_TRUTH_FLAGS: readonly string[] = [
|
|
33
|
+
export const AST_GROUND_TRUTH_FLAGS: readonly string[] = [...HARNESS_VALUE_FLAGS, ...VALUE_FLAGS];
|
|
32
34
|
|
|
33
35
|
/** The subset that takes a value, so `--help` in a value position reads as data. */
|
|
34
36
|
export const AST_GROUND_TRUTH_VALUE_FLAGS: readonly string[] = AST_GROUND_TRUTH_FLAGS;
|
|
35
37
|
|
|
36
38
|
/** The `--help` text, as data, held to {@link AST_GROUND_TRUTH_FLAGS} by a test. */
|
|
37
39
|
export const AST_GROUND_TRUTH_HELP: readonly string[] = [
|
|
38
|
-
'Usage: hydranium-cli ast-ground-truth --services <module> <workspace> [--out-file <file>] [--log-level <lvl>]',
|
|
40
|
+
'Usage: hydranium-cli ast-ground-truth --services <module> [--import <specifier>]... <workspace> [--out-file <file>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
|
|
39
41
|
'',
|
|
40
42
|
"Tally a workspace's live-model AST nodes by `$type` — the ground truth that",
|
|
41
43
|
'`analyze-heap --validate <gt.json>` checks a heap snapshot against. `<module>`',
|
|
@@ -44,14 +46,15 @@ export const AST_GROUND_TRUTH_HELP: readonly string[] = [
|
|
|
44
46
|
'',
|
|
45
47
|
'Options:',
|
|
46
48
|
' --services <module> ESM module exporting `createServices(): { shared }` (required).',
|
|
49
|
+
...importHelpLines(22),
|
|
47
50
|
' <workspace> Workspace root (path or file URI) to build (required).',
|
|
48
51
|
' --out-file <file> Write the JSON to this file instead of stdout.',
|
|
49
|
-
|
|
52
|
+
...logHelpLines(22)
|
|
50
53
|
];
|
|
51
54
|
|
|
52
55
|
export function parseAstGroundTruthArgs(args: string[], onError: UsageError = exitWithUsage): AstGroundTruthCommandOptions {
|
|
53
|
-
const { servicesModule, workspace, options } = parseHarnessArgs(args, 'ast-ground-truth', VALUE_FLAGS, [], { onError });
|
|
54
|
-
return { servicesModule, workspace, outFile: options[OUT_FILE_FLAG],
|
|
56
|
+
const { servicesModule, imports, workspace, options } = parseHarnessArgs(args, 'ast-ground-truth', VALUE_FLAGS, [], { onError });
|
|
57
|
+
return { servicesModule, imports, workspace, outFile: options[OUT_FILE_FLAG], ...logOptions(options) };
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
export function runAstGroundTruthCommand(args: string[]): Promise<void> {
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import * as fs from 'node:fs';
|
|
19
|
+
import { describeError } from '@hydranium/protocol';
|
|
19
20
|
import { loadHeadlessContext, OUT_FILE_FLAG } from './headless-harness.js';
|
|
20
21
|
|
|
21
22
|
interface DriverArgs {
|
|
@@ -76,6 +77,6 @@ async function main(argv: string[]): Promise<void> {
|
|
|
76
77
|
main(process.argv.slice(2))
|
|
77
78
|
.then(() => process.exit(0))
|
|
78
79
|
.catch((error: unknown) => {
|
|
79
|
-
console.error(
|
|
80
|
+
console.error(describeError(error));
|
|
80
81
|
process.exit(1);
|
|
81
82
|
});
|
|
@@ -45,5 +45,5 @@ export function buildGroundTruthDriverArgs(options: AstGroundTruthCommandOptions
|
|
|
45
45
|
* `--out-file`). No `--expose-gc` needed — this walks the AST, it does not weigh it.
|
|
46
46
|
*/
|
|
47
47
|
export function runAstGroundTruth(options: AstGroundTruthCommandOptions): Promise<void> {
|
|
48
|
-
return runDriverChild([
|
|
48
|
+
return runDriverChild([DRIVER, ...buildGroundTruthDriverArgs(options)], options);
|
|
49
49
|
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
import * as fs from 'fs';
|
|
11
|
+
import * as path from 'path';
|
|
12
|
+
import type { SourceFile } from 'ts-morph';
|
|
13
|
+
|
|
14
|
+
/** Inputs for {@link emitAstBuilder}, resolved by the transfer-model command. */
|
|
15
|
+
export interface EmitAstBuilderOptions {
|
|
16
|
+
/** Destination path for the generated builder module. */
|
|
17
|
+
outFile: string;
|
|
18
|
+
/** Path to the Langium-generated AST file the builder imports from. */
|
|
19
|
+
astFile: string;
|
|
20
|
+
/** Language id derived from the `<LanguageId>AstReflection` class name. */
|
|
21
|
+
languageId: string;
|
|
22
|
+
/** Header line naming the command that regenerates the file. */
|
|
23
|
+
regenCommand: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A single `makeAstNodeBuilder` binding the generator emits.
|
|
28
|
+
*
|
|
29
|
+
* `typeMap` is the type expression handed to the generic — the whole-project
|
|
30
|
+
* alias for the merged binding, `<Namespace>.AstType` for a narrowed one.
|
|
31
|
+
*/
|
|
32
|
+
interface BuilderBinding {
|
|
33
|
+
exportName: string;
|
|
34
|
+
typeMap: string;
|
|
35
|
+
/** Grammar this binding is narrowed to; absent on the merged binding. */
|
|
36
|
+
namespace?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Langium declares this type alias inside each language's namespace in a
|
|
41
|
+
* multi-language project. Its presence is what marks a namespace as a grammar's
|
|
42
|
+
* type registry rather than an incidental one.
|
|
43
|
+
*/
|
|
44
|
+
const NAMESPACED_AST_TYPE_NAME = 'AstType';
|
|
45
|
+
|
|
46
|
+
/** Export name of the merged, whole-project binding. */
|
|
47
|
+
const MERGED_EXPORT_NAME = 'astNode';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Emit a module binding {@link makeAstNodeBuilder} to a project's reflection,
|
|
51
|
+
* once per grammar plus once across all of them.
|
|
52
|
+
*
|
|
53
|
+
* **The binding is boilerplate with exactly one degree of freedom** — the type
|
|
54
|
+
* map — so hand-writing it buys nothing and goes stale the moment a grammar is
|
|
55
|
+
* added. Generating it is also the only way a narrowed binding can exist at all:
|
|
56
|
+
* the per-grammar type maps live in namespaces Langium emits only on its
|
|
57
|
+
* multi-language path, so a single-grammar project gets the merged binding alone
|
|
58
|
+
* and there is nothing to narrow.
|
|
59
|
+
*
|
|
60
|
+
* **A narrowed binding is only as narrow as its grammar's import closure.**
|
|
61
|
+
* Langium's per-grammar `AstType` lists everything REACHABLE from that grammar,
|
|
62
|
+
* so where one grammar imports all the others its map equals the project's and
|
|
63
|
+
* its binding checks nothing the merged one does not. The emitted doc says so at
|
|
64
|
+
* each declaration rather than promising a guarantee the type map cannot give.
|
|
65
|
+
*
|
|
66
|
+
* Answers `false` when the AST source declares no whole-project type alias,
|
|
67
|
+
* which means the file did not come from `langium generate` and the caller
|
|
68
|
+
* should report rather than write a module that cannot compile.
|
|
69
|
+
*/
|
|
70
|
+
export function emitAstBuilder(astSource: SourceFile, options: EmitAstBuilderOptions): boolean {
|
|
71
|
+
const content = buildAstBuilderSource(astSource, options);
|
|
72
|
+
if (content === undefined) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
fs.mkdirSync(path.dirname(options.outFile), { recursive: true });
|
|
77
|
+
if (fs.existsSync(options.outFile) && fs.readFileSync(options.outFile, 'utf-8') === content) {
|
|
78
|
+
console.log('AST builder is up to date.');
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
fs.writeFileSync(options.outFile, content, 'utf-8');
|
|
82
|
+
console.log(`Generated: ${options.outFile}`);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The module text {@link emitAstBuilder} would write, or `undefined` when the
|
|
88
|
+
* AST source declares no whole-project type alias. Pure over its inputs, so the
|
|
89
|
+
* emitted shape is testable without touching a filesystem.
|
|
90
|
+
*/
|
|
91
|
+
export function buildAstBuilderSource(astSource: SourceFile, options: EmitAstBuilderOptions): string | undefined {
|
|
92
|
+
const mergedTypeMap = `${options.languageId}AstType`;
|
|
93
|
+
if (!astSource.getTypeAlias(mergedTypeMap)) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const bindings: BuilderBinding[] = [{ exportName: MERGED_EXPORT_NAME, typeMap: mergedTypeMap }];
|
|
98
|
+
for (const namespace of findGrammarNamespaces(astSource)) {
|
|
99
|
+
bindings.push({
|
|
100
|
+
exportName: builderExportName(namespace),
|
|
101
|
+
typeMap: `${namespace}.${NAMESPACED_AST_TYPE_NAME}`,
|
|
102
|
+
namespace
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
assertDistinctExportNames(bindings);
|
|
106
|
+
|
|
107
|
+
return renderAstBuilder(bindings, {
|
|
108
|
+
reflectionName: findReflectionConstName(astSource, options.languageId),
|
|
109
|
+
importPath: relativeImportPath(options.outFile, options.astFile),
|
|
110
|
+
regenCommand: options.regenCommand
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Namespaces that carry a grammar's type registry, in declaration order.
|
|
116
|
+
*
|
|
117
|
+
* Keyed on the nested `AstType` alias rather than on the namespace being
|
|
118
|
+
* exported, because an adopter's augmentation can add namespaces to the same
|
|
119
|
+
* file for unrelated reasons and only the ones Langium emits per grammar have
|
|
120
|
+
* a type map to bind.
|
|
121
|
+
*/
|
|
122
|
+
function findGrammarNamespaces(astSource: SourceFile): string[] {
|
|
123
|
+
const names: string[] = [];
|
|
124
|
+
for (const module of astSource.getModules()) {
|
|
125
|
+
const name = module.getName();
|
|
126
|
+
if (name && module.getTypeAlias(NAMESPACED_AST_TYPE_NAME)) {
|
|
127
|
+
names.push(name);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return names;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* `Domain` → `domainNode`. Lower-cases the leading character only, so a grammar
|
|
135
|
+
* named `OrderFlow` reads as `orderFlowNode` rather than losing its word break.
|
|
136
|
+
*/
|
|
137
|
+
function builderExportName(namespace: string): string {
|
|
138
|
+
return `${namespace.charAt(0).toLowerCase()}${namespace.slice(1)}Node`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Two grammars whose names differ only in their leading character collapse to
|
|
143
|
+
* one export. Emitting anyway would silently drop a binding, so fail with both
|
|
144
|
+
* names rather than leave the caller to discover it at compile time.
|
|
145
|
+
*/
|
|
146
|
+
function assertDistinctExportNames(bindings: readonly BuilderBinding[]): void {
|
|
147
|
+
const seen = new Map<string, string>();
|
|
148
|
+
for (const binding of bindings) {
|
|
149
|
+
const previous = seen.get(binding.exportName);
|
|
150
|
+
if (previous !== undefined) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`Cannot emit the AST builder: grammars '${previous}' and '${binding.namespace}' both map to the export ` +
|
|
153
|
+
`'${binding.exportName}'. Rename one grammar so the generated bindings stay distinct.`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
seen.set(binding.exportName, binding.namespace ?? MERGED_EXPORT_NAME);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Name of the const holding the project's reflection instance.
|
|
162
|
+
*
|
|
163
|
+
* Langium emits `export const reflection = new <LanguageId>AstReflection()`, but
|
|
164
|
+
* the const is located by its initializer rather than by that name so a renamed
|
|
165
|
+
* export still resolves. Falls back to the emitted default when no declaration
|
|
166
|
+
* matches, which keeps the output compiling against a stock Langium file.
|
|
167
|
+
*/
|
|
168
|
+
function findReflectionConstName(astSource: SourceFile, languageId: string): string {
|
|
169
|
+
const reflectionClass = `${languageId}AstReflection`;
|
|
170
|
+
for (const declaration of astSource.getVariableDeclarations()) {
|
|
171
|
+
if (declaration.getInitializer()?.getText().replace(/\s/g, '') === `new${reflectionClass}()`) {
|
|
172
|
+
return declaration.getName();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return 'reflection';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Module specifier for the AST file as seen from the generated module's own
|
|
180
|
+
* directory. Emitted with a `.js` extension and posix separators because the
|
|
181
|
+
* output is ESM TypeScript, where the specifier names the compiled sibling.
|
|
182
|
+
*/
|
|
183
|
+
function relativeImportPath(outFile: string, astFile: string): string {
|
|
184
|
+
const relative = path.relative(path.dirname(path.resolve(outFile)), path.resolve(astFile));
|
|
185
|
+
const posix = relative.split(path.sep).join('/').replace(/\.ts$/, '.js');
|
|
186
|
+
return posix.startsWith('.') ? posix : `./${posix}`;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function renderAstBuilder(
|
|
190
|
+
bindings: readonly BuilderBinding[],
|
|
191
|
+
context: { reflectionName: string; importPath: string; regenCommand: string }
|
|
192
|
+
): string {
|
|
193
|
+
const imported = [context.reflectionName, ...bindings.map(binding => `type ${binding.namespace ?? binding.typeMap}`)];
|
|
194
|
+
const out: string[] = [];
|
|
195
|
+
|
|
196
|
+
out.push('/******************************************************************************');
|
|
197
|
+
out.push(' * Generated from the Langium AST — DO NOT EDIT MANUALLY!');
|
|
198
|
+
out.push(` * ${context.regenCommand}`);
|
|
199
|
+
out.push(' ******************************************************************************/');
|
|
200
|
+
out.push('');
|
|
201
|
+
out.push('/* eslint-disable */');
|
|
202
|
+
out.push('');
|
|
203
|
+
out.push("import { makeAstNodeBuilder } from '@hydranium/core';");
|
|
204
|
+
out.push(`import { ${imported.join(', ')} } from '${context.importPath}';`);
|
|
205
|
+
out.push('');
|
|
206
|
+
|
|
207
|
+
// A single-grammar project has nothing to narrow to, so the merged binding is
|
|
208
|
+
// simply THE binding there and must not point at a sibling that was not emitted.
|
|
209
|
+
const narrowed = bindings.some(binding => binding.namespace !== undefined);
|
|
210
|
+
const guarantee = [
|
|
211
|
+
' * Mandatory fields are a type error at the call site, and grammar-declared',
|
|
212
|
+
' * containment arrays are materialised from reflection metadata, so a built',
|
|
213
|
+
' * node carries `[]` where a cast literal would leave `undefined`.'
|
|
214
|
+
];
|
|
215
|
+
|
|
216
|
+
for (const binding of bindings) {
|
|
217
|
+
out.push('/**');
|
|
218
|
+
if (binding.namespace !== undefined) {
|
|
219
|
+
out.push(` * AST-node factory narrowed to the '${binding.namespace}' grammar.`);
|
|
220
|
+
out.push(' *');
|
|
221
|
+
out.push(' * Narrowed by grammar REACHABILITY, not by ownership: a grammar that');
|
|
222
|
+
out.push(" * imports another sees that one's types too, so this binding is only as");
|
|
223
|
+
out.push(` * narrow as '${binding.namespace}'s import closure. Where that closure is the`);
|
|
224
|
+
out.push(' * whole project, it accepts exactly what the merged binding does and the');
|
|
225
|
+
out.push(' * choice is documentation rather than a check.');
|
|
226
|
+
out.push(' *');
|
|
227
|
+
out.push(...guarantee);
|
|
228
|
+
} else if (narrowed) {
|
|
229
|
+
out.push(' * AST-node factory spanning every grammar in this project.');
|
|
230
|
+
out.push(' *');
|
|
231
|
+
out.push(' * Prefer the narrowed binding matching the grammar the call site works in:');
|
|
232
|
+
out.push(" * it rejects a type outside that grammar's import closure, which this one");
|
|
233
|
+
out.push(' * accepts from anywhere. Reach for this one where a call site genuinely');
|
|
234
|
+
out.push(' * spans grammars.');
|
|
235
|
+
} else {
|
|
236
|
+
out.push(" * AST-node factory for this project's grammar.");
|
|
237
|
+
out.push(' *');
|
|
238
|
+
out.push(...guarantee);
|
|
239
|
+
}
|
|
240
|
+
out.push(' */');
|
|
241
|
+
out.push(`export const ${binding.exportName} = makeAstNodeBuilder<${binding.typeMap}>(${context.reflectionName});`);
|
|
242
|
+
out.push('');
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return out.join('\n');
|
|
246
|
+
}
|
|
@@ -29,6 +29,7 @@ export const GENERATE_TRANSFER_MODEL_FLAGS: readonly string[] = [
|
|
|
29
29
|
'--ast-file',
|
|
30
30
|
'--augmentation-file',
|
|
31
31
|
'--out-file',
|
|
32
|
+
'--ast-builder-file',
|
|
32
33
|
'--element-type-name',
|
|
33
34
|
'--terminals-name',
|
|
34
35
|
'--terminals-source-name',
|
|
@@ -48,7 +49,8 @@ export const GENERATE_TRANSFER_MODEL_VALUE_FLAGS: readonly string[] = GENERATE_T
|
|
|
48
49
|
export const GENERATE_TRANSFER_MODEL_HELP: readonly string[] = [
|
|
49
50
|
'Usage: hydranium-cli generate-transfer-model [options]',
|
|
50
51
|
'',
|
|
51
|
-
'Generate a serializable transfer-model TypeScript file from a Langium AST
|
|
52
|
+
'Generate a serializable transfer-model TypeScript file from a Langium AST, and',
|
|
53
|
+
'optionally an AST-node builder module bound to the same reflection. The',
|
|
52
54
|
'required inputs (--ast-file / --augmentation-file / --out-file) may instead come',
|
|
53
55
|
'from a --config JSON file, and --ast-file can be auto-discovered from a Langium',
|
|
54
56
|
"config's `out` directory. Precedence, highest first: explicit flags, then the",
|
|
@@ -67,6 +69,11 @@ export const GENERATE_TRANSFER_MODEL_HELP: readonly string[] = [
|
|
|
67
69
|
' directory: it treats that directory as exclusively',
|
|
68
70
|
' its own, so every `langium generate` reports this',
|
|
69
71
|
' file as unexpected and offers to delete it.',
|
|
72
|
+
' --ast-builder-file <path> Also emit an AST-node builder module here: one',
|
|
73
|
+
' makeAstNodeBuilder binding per grammar, plus one',
|
|
74
|
+
' spanning all of them. Omit if nothing constructs',
|
|
75
|
+
' AST nodes. Same restriction as --out-file: keep it',
|
|
76
|
+
" out of langium-cli's own `out` directory.",
|
|
70
77
|
' --element-type-name <name> Base element type name in output. Default: TransferElement.',
|
|
71
78
|
' --terminals-name <name> Terminals const name in output. Default: ModelTerminals.',
|
|
72
79
|
' --terminals-source-name <n> Source-side terminals variable name. Default: <LanguageId>Terminals.',
|
|
@@ -120,6 +127,9 @@ export function parseGenerateOptions(args: string[], onError: UsageError = exitW
|
|
|
120
127
|
case '--out-file':
|
|
121
128
|
flags.outFile = next();
|
|
122
129
|
break;
|
|
130
|
+
case '--ast-builder-file':
|
|
131
|
+
flags.astBuilderFile = next();
|
|
132
|
+
break;
|
|
123
133
|
case '--element-type-name':
|
|
124
134
|
flags.elementTypeName = next();
|
|
125
135
|
break;
|
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
|
|
10
10
|
import * as fs from 'node:fs';
|
|
11
11
|
import * as path from 'node:path';
|
|
12
|
+
import { describeError } from '@hydranium/protocol';
|
|
12
13
|
import type { GenerateTransferModelOptions } from './generate-transfer-model.js';
|
|
13
14
|
|
|
14
15
|
/** Path-valued option keys — resolved relative to a config/langium-config file's directory. */
|
|
15
|
-
const PATH_KEYS = ['astFile', 'augmentationFile', 'outFile'] as const;
|
|
16
|
+
const PATH_KEYS = ['astFile', 'augmentationFile', 'outFile', 'astBuilderFile'] as const;
|
|
16
17
|
|
|
17
18
|
/** Resolve `value` against `baseDir` when it is relative; absolute paths pass through. */
|
|
18
19
|
function resolveAgainst(baseDir: string, value: string): string {
|
|
@@ -31,7 +32,7 @@ export function loadTransferModelConfig(configPath: string): Partial<GenerateTra
|
|
|
31
32
|
try {
|
|
32
33
|
raw = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
33
34
|
} catch (error: unknown) {
|
|
34
|
-
throw new Error(`Cannot read transfer-model config '${configPath}': ${
|
|
35
|
+
throw new Error(`Cannot read transfer-model config '${configPath}': ${describeError(error)}`);
|
|
35
36
|
}
|
|
36
37
|
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
37
38
|
throw new Error(`Transfer-model config '${configPath}' must be a JSON object.`);
|
|
@@ -43,6 +44,7 @@ export function loadTransferModelConfig(configPath: string): Partial<GenerateTra
|
|
|
43
44
|
'astFile',
|
|
44
45
|
'augmentationFile',
|
|
45
46
|
'outFile',
|
|
47
|
+
'astBuilderFile',
|
|
46
48
|
'elementTypeName',
|
|
47
49
|
'terminalsName',
|
|
48
50
|
'terminalsSourceName',
|
|
@@ -74,7 +76,7 @@ export function deriveAstFileFromLangiumConfig(langiumConfigPath: string): strin
|
|
|
74
76
|
try {
|
|
75
77
|
raw = JSON.parse(fs.readFileSync(langiumConfigPath, 'utf-8'));
|
|
76
78
|
} catch (error: unknown) {
|
|
77
|
-
throw new Error(`Cannot read langium-config '${langiumConfigPath}': ${
|
|
79
|
+
throw new Error(`Cannot read langium-config '${langiumConfigPath}': ${describeError(error)}`);
|
|
78
80
|
}
|
|
79
81
|
const out = (raw as { out?: unknown })?.out;
|
|
80
82
|
if (typeof out !== 'string') {
|
|
@@ -118,6 +120,7 @@ export function mergeTransferModelOptions(...sources: Array<Partial<GenerateTran
|
|
|
118
120
|
astFile: astFile!,
|
|
119
121
|
augmentationFile: augmentationFile!,
|
|
120
122
|
outFile: outFile!,
|
|
123
|
+
astBuilderFile: pick('astBuilderFile'),
|
|
121
124
|
elementTypeName: pick('elementTypeName'),
|
|
122
125
|
terminalsName: pick('terminalsName'),
|
|
123
126
|
terminalsSourceName: pick('terminalsSourceName'),
|