@hydranium/cli 1.0.0-next.42 → 1.0.0-next.421
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 +125 -204
- package/bin/hydranium-cli.js +13 -0
- package/heap-analysis/heap/core/load.mjs +2 -2
- package/heap-analysis/heap/langium/langium.classifier.mjs +22 -11
- package/lib/cli-version.js.map +1 -1
- package/lib/cli.js +11 -2
- package/lib/cli.js.map +1 -1
- package/lib/commands/analyze-heap-args.d.ts.map +1 -1
- package/lib/commands/analyze-heap-args.js +1 -2
- 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 +12 -10
- package/lib/commands/ast-ground-truth-args.js.map +1 -1
- package/lib/commands/ast-ground-truth-driver.js +4 -2
- 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/check-skills-args.d.ts +11 -0
- package/lib/commands/check-skills-args.d.ts.map +1 -0
- package/lib/commands/check-skills-args.js +71 -0
- package/lib/commands/check-skills-args.js.map +1 -0
- package/lib/commands/client-session.d.ts +17 -0
- package/lib/commands/client-session.d.ts.map +1 -0
- package/lib/commands/client-session.js +27 -0
- package/lib/commands/client-session.js.map +1 -0
- package/lib/commands/create-args.d.ts +17 -0
- package/lib/commands/create-args.d.ts.map +1 -0
- package/lib/commands/create-args.js +53 -0
- package/lib/commands/create-args.js.map +1 -0
- package/lib/commands/create.d.ts +38 -0
- package/lib/commands/create.d.ts.map +1 -0
- package/lib/commands/create.js +43 -0
- package/lib/commands/create.js.map +1 -0
- package/lib/commands/delete-args.d.ts +17 -0
- package/lib/commands/delete-args.d.ts.map +1 -0
- package/lib/commands/delete-args.js +49 -0
- package/lib/commands/delete-args.js.map +1 -0
- package/lib/commands/delete.d.ts +30 -0
- package/lib/commands/delete.d.ts.map +1 -0
- package/lib/commands/delete.js +32 -0
- package/lib/commands/delete.js.map +1 -0
- package/lib/commands/generate-ast-builder.d.ts +1 -1
- package/lib/commands/generate-ast-builder.d.ts.map +1 -1
- package/lib/commands/generate-ast-builder.js +2 -11
- package/lib/commands/generate-ast-builder.js.map +1 -1
- package/lib/commands/generate-languages.d.ts +35 -0
- package/lib/commands/generate-languages.d.ts.map +1 -0
- package/lib/commands/generate-languages.js +105 -0
- package/lib/commands/generate-languages.js.map +1 -0
- package/lib/commands/generate-transfer-builder.d.ts +33 -0
- package/lib/commands/generate-transfer-builder.d.ts.map +1 -0
- package/lib/commands/generate-transfer-builder.js +86 -0
- package/lib/commands/generate-transfer-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 +20 -5
- 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 +8 -3
- package/lib/commands/generate-transfer-model-config.js.map +1 -1
- package/lib/commands/generate-transfer-model.d.ts +41 -9
- package/lib/commands/generate-transfer-model.d.ts.map +1 -1
- package/lib/commands/generate-transfer-model.js +225 -68
- package/lib/commands/generate-transfer-model.js.map +1 -1
- package/lib/commands/generated-module-path.d.ts +16 -0
- package/lib/commands/generated-module-path.d.ts.map +1 -0
- package/lib/commands/generated-module-path.js +21 -0
- package/lib/commands/generated-module-path.js.map +1 -0
- package/lib/commands/harness-args.d.ts +46 -43
- package/lib/commands/harness-args.d.ts.map +1 -1
- package/lib/commands/harness-args.js +170 -29
- 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 +71 -19
- package/lib/commands/headless-harness.js.map +1 -1
- package/lib/commands/init-args.d.ts +5 -18
- package/lib/commands/init-args.d.ts.map +1 -1
- package/lib/commands/init-args.js +131 -35
- package/lib/commands/init-args.js.map +1 -1
- package/lib/commands/init-hosts.d.ts +24 -0
- package/lib/commands/init-hosts.d.ts.map +1 -0
- package/lib/commands/init-hosts.js +37 -0
- package/lib/commands/init-hosts.js.map +1 -0
- package/lib/commands/init-prompt.d.ts +3 -3
- package/lib/commands/init-prompt.d.ts.map +1 -1
- package/lib/commands/init-prompt.js +4 -5
- package/lib/commands/init-prompt.js.map +1 -1
- package/lib/commands/init-skills.d.ts +41 -0
- package/lib/commands/init-skills.d.ts.map +1 -0
- package/lib/commands/init-skills.js +110 -0
- package/lib/commands/init-skills.js.map +1 -0
- package/lib/commands/init-templates.d.ts +20 -14
- package/lib/commands/init-templates.d.ts.map +1 -1
- package/lib/commands/init-templates.js +3134 -763
- package/lib/commands/init-templates.js.map +1 -1
- package/lib/commands/init-wizard.d.ts +10 -0
- package/lib/commands/init-wizard.d.ts.map +1 -1
- package/lib/commands/init-wizard.js +76 -31
- package/lib/commands/init-wizard.js.map +1 -1
- package/lib/commands/init-workspace.d.ts +13 -11
- package/lib/commands/init-workspace.d.ts.map +1 -1
- package/lib/commands/init-workspace.js +21 -7
- package/lib/commands/init-workspace.js.map +1 -1
- package/lib/commands/init.d.ts +61 -24
- package/lib/commands/init.d.ts.map +1 -1
- package/lib/commands/init.js +244 -50
- package/lib/commands/init.js.map +1 -1
- package/lib/commands/kebab.d.ts +15 -0
- package/lib/commands/kebab.d.ts.map +1 -0
- package/lib/commands/kebab.js +17 -0
- package/lib/commands/kebab.js.map +1 -0
- 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 +14 -11
- 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 +26 -14
- 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.d.ts +1 -1
- package/lib/commands/measure-memory.d.ts.map +1 -1
- package/lib/commands/measure-memory.js +6 -3
- package/lib/commands/measure-memory.js.map +1 -1
- package/lib/commands/message-catalogue-args.d.ts +16 -0
- package/lib/commands/message-catalogue-args.d.ts.map +1 -0
- package/lib/commands/message-catalogue-args.js +53 -0
- package/lib/commands/message-catalogue-args.js.map +1 -0
- package/lib/commands/message-catalogue.d.ts +21 -0
- package/lib/commands/message-catalogue.d.ts.map +1 -0
- package/lib/commands/message-catalogue.js +48 -0
- package/lib/commands/message-catalogue.js.map +1 -0
- 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 +13 -11
- 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 +6 -5
- package/lib/commands/query-args.js.map +1 -1
- package/lib/commands/query.d.ts +6 -5
- package/lib/commands/query.d.ts.map +1 -1
- package/lib/commands/query.js +5 -4
- 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 +14 -11
- 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 +7 -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 +12 -23
- package/lib/commands/save.js.map +1 -1
- package/lib/commands/skills.d.ts +22 -0
- package/lib/commands/skills.d.ts.map +1 -0
- package/lib/commands/skills.js +129 -0
- package/lib/commands/skills.js.map +1 -0
- 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 +14 -11
- 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 +5 -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 +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -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 +9 -4
- package/lib/spawn-data-server.d.ts.map +1 -1
- package/lib/spawn-data-server.js +5 -4
- 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 +99 -41
- package/src/cli.ts +11 -2
- package/src/commands/analyze-heap-args.ts +1 -2
- package/src/commands/analyze-heap.ts +4 -1
- package/src/commands/ast-ground-truth-args.ts +16 -13
- package/src/commands/ast-ground-truth-driver.ts +4 -2
- package/src/commands/ast-ground-truth.ts +1 -1
- package/src/commands/check-skills-args.ts +70 -0
- package/src/commands/client-session.ts +33 -0
- package/src/commands/create-args.ts +68 -0
- package/src/commands/create.ts +83 -0
- package/src/commands/delete-args.ts +64 -0
- package/src/commands/delete.ts +61 -0
- package/src/commands/generate-ast-builder.ts +2 -12
- package/src/commands/generate-languages.ts +132 -0
- package/src/commands/generate-transfer-builder.ts +101 -0
- package/src/commands/generate-transfer-model-args.ts +20 -5
- package/src/commands/generate-transfer-model-config.ts +8 -3
- package/src/commands/generate-transfer-model.ts +297 -66
- package/src/commands/generated-module-path.ts +22 -0
- package/src/commands/harness-args.ts +163 -33
- package/src/commands/headless-harness.ts +89 -28
- package/src/commands/init-args.ts +135 -35
- package/src/commands/init-hosts.ts +51 -0
- package/src/commands/init-prompt.ts +5 -6
- package/src/commands/init-skills.ts +129 -0
- package/src/commands/init-templates.ts +3326 -785
- package/src/commands/init-wizard.ts +97 -32
- package/src/commands/init-workspace.ts +31 -16
- package/src/commands/init.ts +311 -65
- package/src/commands/kebab.ts +17 -0
- package/src/commands/lint-grammar-args.ts +18 -14
- package/src/commands/lint-grammar-driver.ts +2 -1
- package/src/commands/lint-grammar.ts +1 -1
- package/src/commands/measure-memory-args.ts +31 -17
- package/src/commands/measure-memory-driver.ts +5 -3
- package/src/commands/measure-memory.ts +6 -3
- package/src/commands/message-catalogue-args.ts +55 -0
- package/src/commands/message-catalogue.ts +56 -0
- package/src/commands/model-docs-args.ts +17 -14
- 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 +6 -4
- package/src/commands/query.ts +9 -9
- package/src/commands/reflect-args.ts +18 -14
- package/src/commands/reflect-driver.ts +2 -1
- package/src/commands/reflect.ts +1 -1
- package/src/commands/save-args.ts +7 -3
- package/src/commands/save.ts +24 -27
- package/src/commands/skills.ts +146 -0
- package/src/commands/validate-args.ts +18 -14
- 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 +7 -6
- package/src/driver-heap.ts +65 -0
- package/src/index.ts +3 -0
- package/src/log-level.ts +42 -14
- package/src/spawn-data-server.ts +17 -5
- package/src/stderr-connection-logger.ts +18 -0
- package/src/testing/echo-server.ts +11 -2
- package/templates/client/gitignore +3 -0
- package/templates/client/src/__GRAMMAR_ID__-diagram-module.ts +82 -0
- package/templates/editorconfig +15 -0
- package/templates/gitignore +1 -0
- package/templates/host-browser/esbuild.mjs +82 -0
- package/templates/host-browser/gitignore +4 -0
- package/templates/host-browser/hydranium-mark.svg +40 -0
- package/templates/host-browser/index.html +287 -0
- package/templates/host-browser/playwright.config.mts +24 -0
- package/templates/host-browser/src/data-status.ts +15 -0
- package/templates/host-browser/src/diagram-save.ts +60 -0
- package/templates/host-browser/src/diagram.ts +121 -0
- package/templates/host-browser/src/editor.ts +116 -0
- package/templates/host-browser/src/log.ts +14 -0
- package/templates/host-browser/src/monaco-editor-core-worker.d.ts +7 -0
- package/templates/host-browser/src/monaco-editor-worker.ts +10 -0
- package/templates/host-browser/src/posix-path-shim.ts +23 -0
- package/templates/host-browser/src/shown-file.ts +61 -0
- package/templates/host-browser/src/workspace.ts +5 -0
- package/templates/host-browser/tsconfig.e2e.json +16 -0
- package/templates/host-browser/tsconfig.page.json +16 -0
- package/templates/host-browser/tsconfig.worker.json +16 -0
- package/templates/host-theia-browser/esbuild.mjs +24 -0
- package/templates/host-theia-browser/gitignore +9 -0
- package/templates/host-theia-browser/playwright.config.mts +42 -0
- package/templates/host-theia-browser/start.mjs +50 -0
- package/templates/host-theia-browser/tsconfig.e2e.json +16 -0
- package/templates/host-theia-electron/esbuild.mjs +27 -0
- package/templates/host-theia-electron/gitignore +8 -0
- package/templates/host-theia-electron/playwright.config.mts +12 -0
- package/templates/host-theia-electron/start.mjs +47 -0
- package/templates/host-theia-electron/tsconfig.e2e.json +16 -0
- package/templates/host-vscode/esbuild.mjs +38 -0
- package/templates/host-vscode/gitignore +7 -0
- package/templates/host-vscode/playwright.config.mts +14 -0
- package/templates/host-vscode/src/__GRAMMAR_ID__-diagram-editor.ts +19 -0
- package/templates/host-vscode/src/show-model-command.ts +24 -0
- package/templates/host-vscode/src/webview/__GRAMMAR_ID__-diagram.ts +18 -0
- package/templates/host-vscode/src/webview/diagram.css +40 -0
- package/templates/host-vscode/start.mjs +22 -0
- package/templates/host-vscode/test/content-server.cjs +40 -0
- package/templates/host-vscode/test/install-vscode.mts +21 -0
- package/templates/host-vscode/test/virtual-documents.spec.mts +28 -0
- package/templates/host-vscode/test/vscode-version.mts +10 -0
- package/templates/host-vscode/tsconfig.e2e.json +17 -0
- package/templates/host-vscode/tsconfig.json +19 -0
- package/templates/host-vscode/tsconfig.webview.json +17 -0
- package/templates/oxlintrc.json +4 -0
- package/templates/protocol/gitignore +3 -0
- package/templates/protocol/src/__GRAMMAR_ID__-diagram-types.ts +47 -0
- package/templates/server/gitignore +6 -0
- package/templates/server/src/glsp/__GRAMMAR_ID__/create-node-operation-handler.ts +62 -0
- package/templates/server/src/glsp/__GRAMMAR_ID__/delete-operation-handler.ts +63 -0
- package/templates/server/src/glsp/__GRAMMAR_ID__/gmodel-factory.ts +144 -0
- package/templates/server/src/glsp/__GRAMMAR_ID__/state.ts +18 -0
- package/templates/server/src/glsp/__GRAMMAR_ID__/storage.ts +16 -0
- package/templates/server/src/glsp/__GRAMMAR_ID__/submission-handler.ts +24 -0
- package/templates/server/src/grammar/common.langium +12 -0
- package/templates/server/src/language-server/__GRAMMAR_ID__-semantic-tokens.ts +10 -0
- package/templates/server/src/language-server/__GRAMMAR_ID__-serializer.ts +53 -0
- package/templates/server/src/language-server/__GRAMMAR_ID__-validation.ts +30 -0
- package/templates/server/src/language-server/ast.ts +23 -0
- package/templates/server/src/node/services.ts +16 -0
- package/templates/server/test/__GRAMMAR_ID__-diagram.test.ts +403 -0
- package/templates/server/test/__GRAMMAR_ID__-semantic-tokens.test.ts +34 -0
- package/templates/server/test/tsconfig.json +4 -0
- package/templates/server/tsconfig.test.json +10 -0
- package/templates/server/vitest.config.ts +14 -0
- package/templates/theia/gitignore +3 -0
- package/templates/theia/src/browser/__GRAMMAR_ID__-diagram-frontend-module.ts +65 -0
- package/templates/theia/src/browser/__PROJECT_ID__-connection-preload-module.ts +15 -0
- package/templates/theia/src/browser/__PROJECT_ID__-data-connection.ts +15 -0
- package/templates/theia/src/browser/__PROJECT_ID__-data-port.ts +11 -0
- package/templates/theia/src/browser/__PROJECT_ID__-glsp-client-contribution.ts +13 -0
- package/templates/theia/src/browser/__PROJECT_ID__-show-model-command.ts +51 -0
- package/templates/theia/src/common/__PROJECT_ID__-glsp-contribution.ts +3 -0
- package/templates/theia/src/node/__PROJECT_ID__-connection-backend-module.ts +12 -0
- package/templates/theia/src/node/__PROJECT_ID__-data-backend-module.ts +15 -0
- package/templates/theia/src/node/__PROJECT_ID__-glsp-backend-module.ts +16 -0
- package/templates/theia/style/diagram.css +20 -0
- package/templates/theia/tsconfig.json +24 -0
- package/templates/vscode-servers/gitignore +4 -0
- package/templates/vscode-servers/tsconfig.json +19 -0
- package/templates/workspace/nodes.__EXTENSION__ +5 -0
- package/templates/workspace/references.__EXTENSION__ +2 -0
|
@@ -31,11 +31,12 @@
|
|
|
31
31
|
* parser rejects is an invocation that fails for no visible reason.
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
-
import type
|
|
35
|
-
import { statSync } from 'node:fs';
|
|
34
|
+
import { describeError, type LogThreshold } from '@hydranium/protocol';
|
|
35
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
36
|
+
import * as fs from 'node:fs/promises';
|
|
36
37
|
import * as path from 'node:path';
|
|
37
38
|
import { fileURLToPath } from 'node:url';
|
|
38
|
-
import { parseLogLevelOption } from '../log-level.js';
|
|
39
|
+
import { type LogOptions, parseLogLevelOption } from '../log-level.js';
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* How a parser reports a usage problem. It never returns, so a parser can treat
|
|
@@ -56,9 +57,18 @@ export function exitWithUsage(message: string): never {
|
|
|
56
57
|
process.exit(2);
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
/**
|
|
60
|
+
/** Overrides the services module configured by the project. */
|
|
60
61
|
export const SERVICES_FLAG = '--services';
|
|
61
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Registers a loader in the driver child that imports the head. The child is a
|
|
65
|
+
* fresh `node`, so a loader registered on the CLI's own process never reaches it.
|
|
66
|
+
*/
|
|
67
|
+
export const IMPORT_FLAG = '--import';
|
|
68
|
+
|
|
69
|
+
/** The value flags {@link parseHarnessArgs} consumes itself, before any the subcommand declares. */
|
|
70
|
+
export const HARNESS_VALUE_FLAGS = [SERVICES_FLAG, IMPORT_FLAG] as const;
|
|
71
|
+
|
|
62
72
|
/**
|
|
63
73
|
* The one spelling of the log threshold, shared by both subcommand families.
|
|
64
74
|
*
|
|
@@ -68,33 +78,68 @@ export const SERVICES_FLAG = '--services';
|
|
|
68
78
|
* on which command a caller happened to reach for.
|
|
69
79
|
*/
|
|
70
80
|
export const LOG_LEVEL_FLAG = '--log-level';
|
|
81
|
+
export const LOG_FILE_FLAG = '--log-file';
|
|
82
|
+
export const LOG_FILE_LEVEL_FLAG = '--log-file-level';
|
|
83
|
+
|
|
84
|
+
/** The log flags every subcommand takes, read by {@link logOptions}. */
|
|
85
|
+
export const LOG_VALUE_FLAGS = [LOG_LEVEL_FLAG, LOG_FILE_FLAG, LOG_FILE_LEVEL_FLAG] as const;
|
|
71
86
|
|
|
72
87
|
/** The value flags {@link parseServerSpawnOptions} consumes itself. */
|
|
73
|
-
export const SERVER_SPAWN_VALUE_FLAGS: readonly string[] = ['--server', '--cwd',
|
|
88
|
+
export const SERVER_SPAWN_VALUE_FLAGS: readonly string[] = ['--server', '--cwd', ...LOG_VALUE_FLAGS];
|
|
74
89
|
|
|
75
90
|
/**
|
|
76
|
-
* The `--help`
|
|
91
|
+
* The `--help` lines every subcommand describes {@link LOG_VALUE_FLAGS} with.
|
|
77
92
|
*
|
|
78
93
|
* Shared text, per-command padding: `command-args.test.ts` compares the flags a
|
|
79
94
|
* help block DESCRIBES against the flags the parser accepts, and it recognises a
|
|
80
|
-
* description by the two-space indent — so
|
|
95
|
+
* description by the two-space indent — so each line has to be a real option entry
|
|
81
96
|
* in each block, and the column each block aligns its descriptions at is the
|
|
82
|
-
* block's own.
|
|
97
|
+
* block's own. A flag too wide for that column takes its description on the
|
|
98
|
+
* next line, at the column.
|
|
83
99
|
*/
|
|
84
|
-
export function
|
|
85
|
-
return
|
|
100
|
+
export function logHelpLines(padTo: number, head = 'the head this boots'): string[] {
|
|
101
|
+
return [
|
|
102
|
+
helpLine(`${LOG_LEVEL_FLAG} <lvl>`, `Log threshold for ${head} (off|error|warn|info|debug|trace).`, padTo),
|
|
103
|
+
helpLine(
|
|
104
|
+
`${LOG_FILE_FLAG} <file>`,
|
|
105
|
+
`Also write ${head}'s log to <file>; {workspace} expands to the workspace, {pid} to the process id.`,
|
|
106
|
+
padTo
|
|
107
|
+
),
|
|
108
|
+
helpLine(`${LOG_FILE_LEVEL_FLAG} <lvl>`, `Threshold for that file, which the log-level setting does not change.`, padTo)
|
|
109
|
+
].flat();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The `--help` lines every `--services` subcommand describes {@link IMPORT_FLAG} with, aligned as {@link logHelpLines}. */
|
|
113
|
+
export function importHelpLines(padTo: number): string[] {
|
|
114
|
+
return helpLine(`${IMPORT_FLAG} <specifier>`, 'Loader to register before importing <module>, e.g. tsx (repeatable).', padTo);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function helpLine(flag: string, text: string, padTo: number): string[] {
|
|
118
|
+
return flag.length < padTo - 1 ? [` ${flag.padEnd(padTo)}${text}`] : [` ${flag}`, `${' '.repeat(padTo + 2)}${text}`];
|
|
86
119
|
}
|
|
87
120
|
|
|
88
121
|
/**
|
|
89
|
-
* Narrow
|
|
90
|
-
*
|
|
122
|
+
* Narrow the raw {@link LOG_VALUE_FLAGS} values a parser collected, leaving
|
|
123
|
+
* absent flags absent.
|
|
124
|
+
*
|
|
125
|
+
* `--log-file` resolves against the caller's directory: the child may run
|
|
126
|
+
* elsewhere (`--cwd`), and a relative path would land the log there.
|
|
91
127
|
*
|
|
92
128
|
* Throws rather than reaching `onError`, matching {@link parseServerSpawnOptions}:
|
|
93
129
|
* the level vocabulary belongs to the protocol package, which reports it, and the
|
|
94
130
|
* entry point's catch turns that into the same message-and-exit.
|
|
95
131
|
*/
|
|
96
|
-
export function
|
|
97
|
-
|
|
132
|
+
export function logOptions(options: Readonly<Record<string, string | undefined>>): LogOptions {
|
|
133
|
+
const level = (flag: string): LogThreshold | undefined => {
|
|
134
|
+
const value = options[flag];
|
|
135
|
+
return value === undefined ? undefined : parseLogLevelOption(value, flag);
|
|
136
|
+
};
|
|
137
|
+
const logFile = options[LOG_FILE_FLAG];
|
|
138
|
+
return {
|
|
139
|
+
logLevel: level(LOG_LEVEL_FLAG),
|
|
140
|
+
logFile: logFile === undefined ? undefined : path.resolve(logFile),
|
|
141
|
+
logFileLevel: level(LOG_FILE_LEVEL_FLAG)
|
|
142
|
+
};
|
|
98
143
|
}
|
|
99
144
|
|
|
100
145
|
/**
|
|
@@ -134,6 +179,8 @@ export function printHelp(lines: readonly string[]): void {
|
|
|
134
179
|
/** What {@link parseHarnessArgs} recovered from an argv. */
|
|
135
180
|
export interface ParsedHarnessArgs {
|
|
136
181
|
servicesModule: string;
|
|
182
|
+
/** The {@link IMPORT_FLAG} values in the order given, absent when there were none. */
|
|
183
|
+
imports?: string[];
|
|
137
184
|
/**
|
|
138
185
|
* An absolute directory path, resolved by {@link resolveWorkspaceArgument} and
|
|
139
186
|
* checked to exist. `''` when the subcommand declared `requireWorkspace: false`.
|
|
@@ -162,13 +209,14 @@ export interface HarnessArgsConfig {
|
|
|
162
209
|
}
|
|
163
210
|
|
|
164
211
|
/**
|
|
165
|
-
* Shared parser for the headless-harness subcommands. Consumes the
|
|
166
|
-
* `--services <module>`
|
|
167
|
-
* the `valueFlags` (each takes a value)
|
|
168
|
-
* as `'true'`) the subcommand
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
212
|
+
* Shared parser for the headless-harness subcommands. Consumes the
|
|
213
|
+
* `--services <module>` override, the repeatable `--import <specifier>` and a
|
|
214
|
+
* single positional `<workspace>`, plus the `valueFlags` (each takes a value)
|
|
215
|
+
* and `boolFlags` (presence-only, recorded as `'true'`) the subcommand
|
|
216
|
+
* recognises. Services default to the nearest package manifest. Unknown flags,
|
|
217
|
+
* missing services or a missing `<workspace>` are usage errors, and so is a
|
|
218
|
+
* `<workspace>` that reaches no directory — see
|
|
219
|
+
* {@link resolveWorkspaceArgument} for why that cannot be left to the run.
|
|
172
220
|
*/
|
|
173
221
|
export function parseHarnessArgs(
|
|
174
222
|
args: string[],
|
|
@@ -185,6 +233,7 @@ export function parseHarnessArgs(
|
|
|
185
233
|
const options: Record<string, string | undefined> = {};
|
|
186
234
|
const values: Record<string, string[]> = {};
|
|
187
235
|
let servicesModule: string | undefined;
|
|
236
|
+
let imports: string[] | undefined;
|
|
188
237
|
let workspace: string | undefined;
|
|
189
238
|
for (let index = 0; index < args.length; index += 1) {
|
|
190
239
|
const flag = args[index];
|
|
@@ -196,8 +245,10 @@ export function parseHarnessArgs(
|
|
|
196
245
|
index += 1;
|
|
197
246
|
return value;
|
|
198
247
|
};
|
|
199
|
-
if (flag ===
|
|
248
|
+
if (flag === SERVICES_FLAG) {
|
|
200
249
|
servicesModule = next();
|
|
250
|
+
} else if (flag === IMPORT_FLAG) {
|
|
251
|
+
(imports ??= []).push(next());
|
|
201
252
|
} else if (boolSet.has(flag)) {
|
|
202
253
|
options[flag] = 'true';
|
|
203
254
|
} else if (repeatableSet.has(flag)) {
|
|
@@ -212,8 +263,15 @@ export function parseHarnessArgs(
|
|
|
212
263
|
onError(`Unexpected argument: ${flag} (hydranium-cli ${commandName} --help)`);
|
|
213
264
|
}
|
|
214
265
|
}
|
|
266
|
+
servicesModule ??= configuredServicesModule(onError);
|
|
267
|
+
if (servicesModule === undefined) {
|
|
268
|
+
return onError(
|
|
269
|
+
`Missing required option: ${SERVICES_FLAG} (hydranium-cli ${commandName} --help). Pass --services or set hydranium.services in package.json.`
|
|
270
|
+
);
|
|
271
|
+
}
|
|
215
272
|
return {
|
|
216
|
-
servicesModule
|
|
273
|
+
servicesModule,
|
|
274
|
+
imports,
|
|
217
275
|
workspace: requireWorkspace
|
|
218
276
|
? resolveWorkspaceArgument(assertRequired(workspace, '<workspace>', commandName, onError), commandName, onError)
|
|
219
277
|
: (workspace ?? ''),
|
|
@@ -222,6 +280,61 @@ export function parseHarnessArgs(
|
|
|
222
280
|
};
|
|
223
281
|
}
|
|
224
282
|
|
|
283
|
+
/**
|
|
284
|
+
* Stop at the nearest manifest even when it has no setting: inheriting through
|
|
285
|
+
* a workspace member would silently select another package's composition.
|
|
286
|
+
* Read only after argv, so an explicit override needs no valid project config.
|
|
287
|
+
*/
|
|
288
|
+
function configuredServicesModule(onError: UsageError): string | undefined {
|
|
289
|
+
let directory = process.cwd();
|
|
290
|
+
for (;;) {
|
|
291
|
+
const manifestPath = path.join(directory, 'package.json');
|
|
292
|
+
if (statSync(manifestPath, { throwIfNoEntry: false }) !== undefined) {
|
|
293
|
+
let manifest: unknown;
|
|
294
|
+
try {
|
|
295
|
+
manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
296
|
+
} catch (error: unknown) {
|
|
297
|
+
return onError(`Cannot read ${manifestPath}: ${describeError(error)}`);
|
|
298
|
+
}
|
|
299
|
+
if (typeof manifest !== 'object' || manifest === null || Array.isArray(manifest)) {
|
|
300
|
+
return onError(`${manifestPath} must contain a JSON object.`);
|
|
301
|
+
}
|
|
302
|
+
if (!('hydranium' in manifest)) {
|
|
303
|
+
return undefined;
|
|
304
|
+
}
|
|
305
|
+
const configuration = manifest.hydranium;
|
|
306
|
+
if (typeof configuration !== 'object' || configuration === null || Array.isArray(configuration)) {
|
|
307
|
+
return onError(`hydranium in ${manifestPath} must be an object.`);
|
|
308
|
+
}
|
|
309
|
+
if (!('services' in configuration)) {
|
|
310
|
+
return undefined;
|
|
311
|
+
}
|
|
312
|
+
const services = configuration.services;
|
|
313
|
+
if (typeof services !== 'string' || services.trim() === '') {
|
|
314
|
+
return onError(`hydranium.services in ${manifestPath} must be a non-empty file path.`);
|
|
315
|
+
}
|
|
316
|
+
const modulePath = path.resolve(directory, services);
|
|
317
|
+
let stats;
|
|
318
|
+
try {
|
|
319
|
+
stats = statSync(modulePath, { throwIfNoEntry: false });
|
|
320
|
+
} catch (error: unknown) {
|
|
321
|
+
return onError(`Cannot read hydranium.services in ${manifestPath}: ${describeError(error)}`);
|
|
322
|
+
}
|
|
323
|
+
if (stats === undefined || !stats.isFile()) {
|
|
324
|
+
return onError(
|
|
325
|
+
`hydranium.services in ${manifestPath} points to '${services}' (${modulePath}), which is not an existing file. Build the project or correct the setting.`
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
return modulePath;
|
|
329
|
+
}
|
|
330
|
+
const parent = path.dirname(directory);
|
|
331
|
+
if (parent === directory) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
directory = parent;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
225
338
|
/**
|
|
226
339
|
* Resolve the `<workspace>` positional to an absolute directory path, reporting
|
|
227
340
|
* a usage error when it reaches anything else.
|
|
@@ -257,7 +370,7 @@ export function resolveWorkspaceArgument(workspace: string, commandName: string,
|
|
|
257
370
|
try {
|
|
258
371
|
stats = statSync(resolved, { throwIfNoEntry: false });
|
|
259
372
|
} catch (err: unknown) {
|
|
260
|
-
const detail =
|
|
373
|
+
const detail = describeError(err);
|
|
261
374
|
onError(`<workspace> is not reachable: '${workspace}' resolved to ${resolved} (${detail}) ${help}`);
|
|
262
375
|
}
|
|
263
376
|
if (stats === undefined) {
|
|
@@ -276,7 +389,7 @@ function toWorkspacePath(workspace: string, commandName: string, onError: UsageE
|
|
|
276
389
|
try {
|
|
277
390
|
return fileURLToPath(workspace);
|
|
278
391
|
} catch (err: unknown) {
|
|
279
|
-
const detail =
|
|
392
|
+
const detail = describeError(err);
|
|
280
393
|
onError(`<workspace> is not a usable file URI: '${workspace}' (${detail}) (hydranium-cli ${commandName} --help)`);
|
|
281
394
|
}
|
|
282
395
|
}
|
|
@@ -336,11 +449,10 @@ function kebabToCamel(name: string): string {
|
|
|
336
449
|
}
|
|
337
450
|
|
|
338
451
|
/** What {@link parseServerSpawnOptions} recovered from an argv. */
|
|
339
|
-
export interface SpawnOptions {
|
|
452
|
+
export interface SpawnOptions extends LogOptions {
|
|
340
453
|
serverCommand: string;
|
|
341
454
|
serverArgs: string[];
|
|
342
455
|
cwd?: string;
|
|
343
|
-
logLevel?: LogThreshold;
|
|
344
456
|
/** The tokens this parser did not claim, for the subcommand's own options. */
|
|
345
457
|
extra: string[];
|
|
346
458
|
}
|
|
@@ -363,10 +475,10 @@ function isRelativePathToken(token: string, isCommand: boolean): boolean {
|
|
|
363
475
|
|
|
364
476
|
/**
|
|
365
477
|
* Shared option parser for subcommands that spawn a data-server child. Consumes
|
|
366
|
-
* `--server` / `--cwd` /
|
|
478
|
+
* `--server` / `--cwd` / the {@link LOG_VALUE_FLAGS} and returns the surviving tokens as
|
|
367
479
|
* `extra` for {@link parseFlagOptions} to finish.
|
|
368
480
|
*
|
|
369
|
-
* An unrecognised
|
|
481
|
+
* An unrecognised log level value throws rather than reaching `onError`: the
|
|
370
482
|
* level vocabulary belongs to the protocol package, which reports it, and the
|
|
371
483
|
* entry point's catch turns that into the same message-and-exit.
|
|
372
484
|
*
|
|
@@ -383,7 +495,7 @@ function isRelativePathToken(token: string, isCommand: boolean): boolean {
|
|
|
383
495
|
export function parseServerSpawnOptions(args: string[], commandName: string, onError: UsageError = exitWithUsage): SpawnOptions {
|
|
384
496
|
let serverSpec: string | undefined;
|
|
385
497
|
let cwd: string | undefined;
|
|
386
|
-
|
|
498
|
+
const logFlags: Record<string, string> = {};
|
|
387
499
|
const extra: string[] = [];
|
|
388
500
|
for (let index = 0; index < args.length; index += 1) {
|
|
389
501
|
const flag = args[index];
|
|
@@ -399,8 +511,8 @@ export function parseServerSpawnOptions(args: string[], commandName: string, onE
|
|
|
399
511
|
serverSpec = claim();
|
|
400
512
|
} else if (flag === '--cwd') {
|
|
401
513
|
cwd = claim();
|
|
402
|
-
} else if (
|
|
403
|
-
|
|
514
|
+
} else if ((LOG_VALUE_FLAGS as readonly string[]).includes(flag)) {
|
|
515
|
+
logFlags[flag] = claim();
|
|
404
516
|
} else {
|
|
405
517
|
extra.push(flag);
|
|
406
518
|
}
|
|
@@ -425,5 +537,23 @@ export function parseServerSpawnOptions(args: string[], commandName: string, onE
|
|
|
425
537
|
);
|
|
426
538
|
}
|
|
427
539
|
}
|
|
428
|
-
return { serverCommand, serverArgs, cwd,
|
|
540
|
+
return { serverCommand, serverArgs, cwd, ...logOptions(logFlags), extra };
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Resolve the `--content` argument to its textual form. The `@<path>`
|
|
545
|
+
* prefix reads from a file (parses as UTF-8); anything else is taken
|
|
546
|
+
* literally. The leading `@` can be escaped as `\@` for content that
|
|
547
|
+
* legitimately starts with `@`.
|
|
548
|
+
*/
|
|
549
|
+
export async function resolveContent(content: string, readFile?: (path: string) => Promise<string>): Promise<string> {
|
|
550
|
+
if (content.startsWith('@')) {
|
|
551
|
+
const file = content.slice(1);
|
|
552
|
+
const reader = readFile ?? ((target: string) => fs.readFile(target, 'utf8'));
|
|
553
|
+
return reader(file);
|
|
554
|
+
}
|
|
555
|
+
if (content.startsWith('\\@')) {
|
|
556
|
+
return content.slice(1);
|
|
557
|
+
}
|
|
558
|
+
return content;
|
|
429
559
|
}
|
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
import type * as HydraniumCoreNode from '@hydranium/core/node';
|
|
11
|
-
import type { LogThreshold } from '@hydranium/protocol';
|
|
12
11
|
import { spawn } from 'node:child_process';
|
|
13
12
|
import { statSync, writeFileSync } from 'node:fs';
|
|
14
13
|
import { createRequire } from 'node:module';
|
|
15
14
|
import * as path from 'node:path';
|
|
16
15
|
import { pathToFileURL } from 'node:url';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
16
|
+
import { driverHeapArgs, type HeapReading } from '../driver-heap.js';
|
|
17
|
+
import { logEnv, type LogOptions } from '../log-level.js';
|
|
18
|
+
import { IMPORT_FLAG, SERVICES_FLAG } from './harness-args.js';
|
|
19
19
|
|
|
20
20
|
/** The flag every report-producing subcommand names its destination file with. */
|
|
21
21
|
export const OUT_FILE_FLAG = '--out-file';
|
|
@@ -43,13 +43,15 @@ export interface HeadlessContext {
|
|
|
43
43
|
* its `createServices` thunk AND the `@hydranium/core/node` harness, both
|
|
44
44
|
* resolved from the HEAD's location rather than the CLI's.
|
|
45
45
|
*
|
|
46
|
-
* The module is an ESM file
|
|
47
|
-
*
|
|
46
|
+
* The module is an ESM file exporting a ZERO-ARG `createServices(): { shared }`:
|
|
47
|
+
* a compiled `lib/*.js`, or the TypeScript source when the child was started
|
|
48
|
+
* with a loader through {@link IMPORT_FLAG}. `hydranium-cli` is language-agnostic
|
|
48
49
|
* and cannot statically import a head's `create<Lang>Services`, so the dynamic
|
|
49
50
|
* import is the seam that keeps the binary head-neutral. Resolving the harness
|
|
50
|
-
* from the head's graph (via `createRequire` rooted at the head module)
|
|
51
|
-
*
|
|
52
|
-
*
|
|
51
|
+
* from the head's graph (via `createRequire` rooted at the head module) rather
|
|
52
|
+
* than from the CLI's guarantees it runs against the SAME core copy as
|
|
53
|
+
* `createServices`, which a second copy of the module would break even where
|
|
54
|
+
* both resolve.
|
|
53
55
|
*
|
|
54
56
|
* Throws a clear error when the path names no file, and when the export is
|
|
55
57
|
* missing or not a function.
|
|
@@ -64,12 +66,17 @@ export async function loadHeadlessContext(servicesModule: string): Promise<Headl
|
|
|
64
66
|
if (stats === undefined || !stats.isFile()) {
|
|
65
67
|
throw new Error(
|
|
66
68
|
`${SERVICES_FLAG} must name an existing ESM file; '${servicesModule}' resolved to ${modulePath}, ` +
|
|
67
|
-
|
|
68
|
-
'not
|
|
69
|
+
"which is not one. Pass the path of the server package's built `lib/node/services.js` from where you run this — " +
|
|
70
|
+
'not a package name.'
|
|
69
71
|
);
|
|
70
72
|
}
|
|
71
73
|
const moduleUrl = pathToFileURL(modulePath).href;
|
|
72
|
-
|
|
74
|
+
let imported: Record<string, unknown>;
|
|
75
|
+
try {
|
|
76
|
+
imported = (await import(moduleUrl)) as Record<string, unknown>;
|
|
77
|
+
} catch (err: unknown) {
|
|
78
|
+
throw withLoaderHint(err, modulePath);
|
|
79
|
+
}
|
|
73
80
|
const createServices = imported.createServices;
|
|
74
81
|
if (typeof createServices !== 'function') {
|
|
75
82
|
throw new Error(
|
|
@@ -84,6 +91,32 @@ export async function loadHeadlessContext(servicesModule: string): Promise<Headl
|
|
|
84
91
|
return { createServices: createServices as ServicesFactory, coreNode };
|
|
85
92
|
}
|
|
86
93
|
|
|
94
|
+
/** The codes Node fails a TypeScript entry with when no loader handled it, depending on its version. */
|
|
95
|
+
const UNLOADED_TYPESCRIPT_CODES: ReadonlySet<string> = new Set([
|
|
96
|
+
'ERR_UNKNOWN_FILE_EXTENSION',
|
|
97
|
+
'ERR_MODULE_NOT_FOUND',
|
|
98
|
+
'ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX'
|
|
99
|
+
]);
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Append a loader hint to a TypeScript entry's import failure, unless the child
|
|
103
|
+
* was started with {@link IMPORT_FLAG}, where the hint would only repeat the
|
|
104
|
+
* caller's own command. Appended rather than substituted: a loader set through
|
|
105
|
+
* `NODE_OPTIONS` does not show in `execArgv`, and under it the failure can be a
|
|
106
|
+
* missing module that only Node's own message names.
|
|
107
|
+
*/
|
|
108
|
+
function withLoaderHint(err: unknown, modulePath: string): unknown {
|
|
109
|
+
if (!(err instanceof Error) || !/\.[cm]?ts$/.test(modulePath) || !('code' in err) || typeof err.code !== 'string') {
|
|
110
|
+
return err;
|
|
111
|
+
}
|
|
112
|
+
if (!UNLOADED_TYPESCRIPT_CODES.has(err.code) || process.execArgv.some(arg => arg.startsWith(IMPORT_FLAG))) {
|
|
113
|
+
return err;
|
|
114
|
+
}
|
|
115
|
+
return new Error(`${err.message}\nA TypeScript head needs a loader registered with \`${IMPORT_FLAG}\`, e.g. \`${IMPORT_FLAG} tsx\`.`, {
|
|
116
|
+
cause: err
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
87
120
|
/**
|
|
88
121
|
* Child-side: deliver a finished report — to `outFile` when one was named, else
|
|
89
122
|
* to stdout.
|
|
@@ -101,8 +134,9 @@ export function emitReport(report: string, outFile: string | undefined): void {
|
|
|
101
134
|
}
|
|
102
135
|
writeFileSync(outFile, report.endsWith('\n') ? report : `${report}\n`);
|
|
103
136
|
// Progress on stderr, so a caller that also captures stdout gets a clean
|
|
104
|
-
// stream rather than a note where the report used to be.
|
|
105
|
-
|
|
137
|
+
// stream rather than a note where the report used to be. Not `console.error`,
|
|
138
|
+
// which a configured log file records as an error line.
|
|
139
|
+
process.stderr.write(`Wrote ${outFile}\n`);
|
|
106
140
|
}
|
|
107
141
|
|
|
108
142
|
/**
|
|
@@ -129,37 +163,64 @@ export function spawnNodeChild(execArgs: string[], env?: Record<string, string>)
|
|
|
129
163
|
/** How a subcommand parent reaches its driver child; the seam `__spawnForTest` replaces. */
|
|
130
164
|
export type SpawnDriverChild = (execArgs: string[], env?: Record<string, string>) => Promise<number>;
|
|
131
165
|
|
|
132
|
-
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
166
|
+
/**
|
|
167
|
+
* What every `--services` subcommand carries for the child it spawns, on top of
|
|
168
|
+
* its own options. The log options apply to the head the driver boots; an
|
|
169
|
+
* absent one leaves the child's inherited environment alone, so an ambient
|
|
170
|
+
* variable still wins where a caller set one.
|
|
171
|
+
*/
|
|
172
|
+
export interface DriverSpawnOptions extends LogOptions {
|
|
173
|
+
/** Specifiers the driver child registers with Node's `--import`, in order, before it imports the head. */
|
|
174
|
+
readonly imports?: readonly string[];
|
|
140
175
|
/** Test-only: capture the node argv and env instead of spawning the real child. */
|
|
141
176
|
readonly __spawnForTest?: SpawnDriverChild;
|
|
177
|
+
/**
|
|
178
|
+
* Test-only: decide the heap ceiling from a stated cgroup reading rather
|
|
179
|
+
* than the machine's. Without it an argv assertion means one thing on a
|
|
180
|
+
* workstation and nothing at all under a memory limit, so a suite that
|
|
181
|
+
* asserts the ceiling is present passes vacuously in a container.
|
|
182
|
+
*/
|
|
183
|
+
readonly __heapReadingForTest?: HeapReading;
|
|
142
184
|
}
|
|
143
185
|
|
|
144
186
|
/**
|
|
145
187
|
* Parent-side: run a subcommand's driver child and propagate its exit code, so a
|
|
146
188
|
* shell or CI step sees the gate.
|
|
147
189
|
*
|
|
148
|
-
* **The log
|
|
149
|
-
* head's logger reads `
|
|
150
|
-
* which is inside the driver's dynamic import — a flag the driver
|
|
151
|
-
* arrive after the only moment it can be read. Setting
|
|
152
|
-
* exporting
|
|
153
|
-
*
|
|
190
|
+
* **The log options travel in the child's ENVIRONMENT, not its argv.** The
|
|
191
|
+
* head's logger reads its `HYDRANIUM_LOG_*` variables while `createServices`
|
|
192
|
+
* constructs it, which is inside the driver's dynamic import — a flag the driver
|
|
193
|
+
* parsed would arrive after the only moment it can be read. Setting them here
|
|
194
|
+
* rather than exporting them also leaves the CLI's own output alone, unlike
|
|
195
|
+
* ambient variables the parent would carry too.
|
|
154
196
|
*
|
|
155
197
|
* A head that binds a logger of its own decides for itself whether the flag means
|
|
156
198
|
* anything, which is the intended seam: the CLI is language-agnostic and cannot
|
|
157
199
|
* reach past `createServices`.
|
|
200
|
+
*
|
|
201
|
+
* **The heap ceiling is prepended HERE rather than passed by each subcommand.**
|
|
202
|
+
* Every caller wants the same answer to the same question, and the answer is not
|
|
203
|
+
* a constant — see {@link driverHeapArgs}. A literal at the call site is a place
|
|
204
|
+
* the container case can be missed, and the caller that misses it takes the whole
|
|
205
|
+
* cgroup down with it rather than failing on its own.
|
|
158
206
|
*/
|
|
159
207
|
export async function runDriverChild(execArgs: string[], options: DriverSpawnOptions): Promise<void> {
|
|
160
208
|
const spawnChild = options.__spawnForTest ?? spawnNodeChild;
|
|
161
|
-
const
|
|
209
|
+
const importArgs = (options.imports ?? []).map(specifier => `${IMPORT_FLAG}=${loaderSpecifier(specifier)}`);
|
|
210
|
+
const code = await spawnChild([...driverHeapArgs(options.__heapReadingForTest), ...importArgs, ...execArgs], logEnv(options));
|
|
162
211
|
if (code) {
|
|
163
212
|
process.exitCode = code;
|
|
164
213
|
}
|
|
165
214
|
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* A path, absolute or `./`/`../` relative with either separator, becomes a file
|
|
218
|
+
* URL resolved against the caller's directory. Node reads `--import` as a URL or
|
|
219
|
+
* package specifier, so it would take a Windows `C:\…` for the URL scheme `c:`
|
|
220
|
+
* and a `.\…` for a package name. Any other specifier passes through as Node
|
|
221
|
+
* reads it.
|
|
222
|
+
*/
|
|
223
|
+
function loaderSpecifier(specifier: string): string {
|
|
224
|
+
const isPath = path.isAbsolute(specifier) || /^\.\.?[\\/]/.test(specifier);
|
|
225
|
+
return isPath ? pathToFileURL(path.resolve(specifier)).href : specifier;
|
|
226
|
+
}
|