@grayhaven/nerve-compiler 0.1.0 → 0.2.0
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/dist/index.d.ts +7 -2
- package/dist/index.js +42 -3
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as effect_Cause from 'effect/Cause';
|
|
2
2
|
import * as effect_Types from 'effect/Types';
|
|
3
|
-
import { Diagnostic, Rule, NerveConfig, HarnessDesign, Hir } from '@grayhaven/nerve';
|
|
3
|
+
import { Diagnostic, Rule, NerveConfig, HarnessDesign, Hir, NervePlugin } from '@grayhaven/nerve';
|
|
4
4
|
import { Effect } from 'effect';
|
|
5
5
|
|
|
6
6
|
declare const CompileError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
|
|
@@ -45,6 +45,11 @@ interface CompileFileResult {
|
|
|
45
45
|
declare const loadDesign: (file: string) => Effect.Effect<HarnessDesign, CompileError>;
|
|
46
46
|
/** Load `nerve.config.ts` (or legacy `interconnect.config.ts`) from a directory, walking up to the package root. */
|
|
47
47
|
declare const loadConfig: (fromDir: string) => Effect.Effect<NerveConfig, CompileError>;
|
|
48
|
+
/** Load plugin modules declared in config (PRD §40). */
|
|
49
|
+
declare const loadPlugins: (fromDir: string, specifiers: ReadonlyArray<string>) => Effect.Effect<{
|
|
50
|
+
plugins: ReadonlyArray<NervePlugin>;
|
|
51
|
+
diagnostics: ReadonlyArray<Diagnostic>;
|
|
52
|
+
}, CompileError>;
|
|
48
53
|
/** Compile a `.harness.ts` file to HIR with full diagnostics. */
|
|
49
54
|
declare const compileFile: (file: string, options?: CompileFileOptions) => Effect.Effect<CompileFileResult, CompileError>;
|
|
50
55
|
/** Fail with `ValidationError` when diagnostics contain errors (fail-closed gate, PRD §15). */
|
|
@@ -64,4 +69,4 @@ declare const CompilerService_base: Effect.Service.Class<CompilerService, "nerve
|
|
|
64
69
|
declare class CompilerService extends CompilerService_base {
|
|
65
70
|
}
|
|
66
71
|
|
|
67
|
-
export { CompileError, type CompileFileOptions, type CompileFileResult, CompilerService, ExportError, ValidationError, compileFile, failOnErrors, loadConfig, loadDesign };
|
|
72
|
+
export { CompileError, type CompileFileOptions, type CompileFileResult, CompilerService, ExportError, ValidationError, compileFile, failOnErrors, loadConfig, loadDesign, loadPlugins };
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,8 @@ import { createJiti } from "jiti";
|
|
|
14
14
|
import { Effect } from "effect";
|
|
15
15
|
import {
|
|
16
16
|
compileDesign,
|
|
17
|
+
HIR_SCHEMA_VERSION,
|
|
18
|
+
isNervePlugin,
|
|
17
19
|
runRules
|
|
18
20
|
} from "@grayhaven/nerve";
|
|
19
21
|
import { builtinRules } from "@grayhaven/nerve-rules";
|
|
@@ -60,16 +62,52 @@ var loadConfig = (fromDir) => Effect.tryPromise({
|
|
|
60
62
|
cause
|
|
61
63
|
})
|
|
62
64
|
});
|
|
65
|
+
var loadPlugins = (fromDir, specifiers) => Effect.tryPromise({
|
|
66
|
+
try: async () => {
|
|
67
|
+
const plugins = [];
|
|
68
|
+
const diagnostics = [];
|
|
69
|
+
for (const spec of specifiers) {
|
|
70
|
+
const path = spec.startsWith(".") ? resolve(fromDir, spec) : spec;
|
|
71
|
+
const mod = await jiti.import(path);
|
|
72
|
+
const plugin = mod.default ?? mod;
|
|
73
|
+
if (!isNervePlugin(plugin)) {
|
|
74
|
+
throw new CompileError({
|
|
75
|
+
message: `${spec} does not default-export a Nerve plugin (use definePlugin).`,
|
|
76
|
+
source: spec
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (!plugin.hirSchemaVersions.includes(HIR_SCHEMA_VERSION)) {
|
|
80
|
+
diagnostics.push({
|
|
81
|
+
code: "HK-PLUGIN-001",
|
|
82
|
+
severity: "error",
|
|
83
|
+
message: `Plugin ${plugin.name} supports HIR ${plugin.hirSchemaVersions.join(", ")}, but this compiler emits ${HIR_SCHEMA_VERSION}; its rules were not run.`
|
|
84
|
+
});
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
plugins.push(plugin);
|
|
88
|
+
}
|
|
89
|
+
return { plugins, diagnostics };
|
|
90
|
+
},
|
|
91
|
+
catch: (cause) => cause instanceof CompileError ? cause : new CompileError({
|
|
92
|
+
message: `Failed to load plugins: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
93
|
+
cause
|
|
94
|
+
})
|
|
95
|
+
});
|
|
63
96
|
var compileFile = (file, options = {}) => Effect.gen(function* () {
|
|
64
97
|
const design = yield* loadDesign(file);
|
|
65
98
|
const config = options.config ?? (yield* loadConfig(dirname(resolve(file))));
|
|
99
|
+
const { plugins, diagnostics: pluginDiagnostics } = config.plugins !== void 0 && config.plugins.length > 0 ? yield* loadPlugins(dirname(resolve(file)), config.plugins) : { plugins: [], diagnostics: [] };
|
|
66
100
|
const { hir, diagnostics: structural } = compileDesign(design);
|
|
67
101
|
const ruleDiagnostics = runRules(
|
|
68
102
|
hir,
|
|
69
|
-
[
|
|
103
|
+
[
|
|
104
|
+
...builtinRules,
|
|
105
|
+
...plugins.flatMap((p) => p.rules ?? []),
|
|
106
|
+
...options.rules ?? []
|
|
107
|
+
],
|
|
70
108
|
config.rules ?? {}
|
|
71
109
|
);
|
|
72
|
-
const diagnostics = [...structural, ...ruleDiagnostics];
|
|
110
|
+
const diagnostics = [...pluginDiagnostics, ...structural, ...ruleDiagnostics];
|
|
73
111
|
return {
|
|
74
112
|
design,
|
|
75
113
|
hir: { ...hir, diagnostics },
|
|
@@ -101,5 +139,6 @@ export {
|
|
|
101
139
|
compileFile,
|
|
102
140
|
failOnErrors,
|
|
103
141
|
loadConfig,
|
|
104
|
-
loadDesign
|
|
142
|
+
loadDesign,
|
|
143
|
+
loadPlugins
|
|
105
144
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grayhaven/nerve-compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Grayhaven Nerve compiler: TypeScript loading, normalization, HIR generation, validation orchestration.",
|
|
6
6
|
"exports": {
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"effect": "^3.16.0",
|
|
14
14
|
"jiti": "^2.4.2",
|
|
15
|
-
"@grayhaven/nerve": "0.
|
|
16
|
-
"@grayhaven/nerve-rules": "0.
|
|
15
|
+
"@grayhaven/nerve": "0.2.0",
|
|
16
|
+
"@grayhaven/nerve-rules": "0.2.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "^25.9.2",
|
|
20
20
|
"typescript": "^5.8.3",
|
|
21
21
|
"vitest": "^3.2.4",
|
|
22
|
-
"@grayhaven/nerve-connectors": "0.
|
|
22
|
+
"@grayhaven/nerve-connectors": "0.2.0"
|
|
23
23
|
},
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"files": [
|