@manifesto-ai/compiler 3.0.0 → 3.1.1
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 +13 -7
- package/dist/{chunk-VAFXIS7J.js → chunk-INVHMPXW.js} +26 -10
- package/dist/chunk-INVHMPXW.js.map +1 -0
- package/dist/esbuild.js +1 -1
- package/dist/rollup.js +1 -1
- package/dist/rspack.js +1 -1
- package/dist/unplugin.d.ts +2 -0
- package/dist/vite.js +1 -1
- package/dist/webpack.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-VAFXIS7J.js.map +0 -1
package/README.md
CHANGED
|
@@ -114,22 +114,28 @@ import { createCompilerCodegen } from "@manifesto-ai/codegen";
|
|
|
114
114
|
|
|
115
115
|
melPlugin({
|
|
116
116
|
include: /\.mel$/, // File filter (default: /\.mel$/)
|
|
117
|
-
codegen:
|
|
117
|
+
codegen: {
|
|
118
|
+
emit: createCompilerCodegen(),
|
|
119
|
+
timing: "transform", // default: run during dev/build transforms
|
|
120
|
+
},
|
|
118
121
|
});
|
|
119
122
|
```
|
|
120
123
|
|
|
121
|
-
`codegen` is an explicit emitter hook. `@manifesto-ai/compiler` does not import `@manifesto-ai/codegen` for you; install it only if you want
|
|
124
|
+
`codegen` is an explicit emitter hook. `@manifesto-ai/compiler` does not import `@manifesto-ai/codegen` for you; install it only if you want MEL artifacts written during dev or build and inject the emitter yourself.
|
|
122
125
|
|
|
123
|
-
`createCompilerCodegen()` can be called with no options. In that default mode it uses the canonical domain plugin and writes `<source>.
|
|
126
|
+
`createCompilerCodegen()` can be called with no options. In that default mode it uses the canonical domain plugin and writes `<source>.domain.ts` next to the compiled `.mel` file during transform. If you prefer build-end emission, set `timing: "build"` or `timing: "both"`. You can still customize the pipeline:
|
|
124
127
|
|
|
125
128
|
```typescript
|
|
126
129
|
import { createCompilerCodegen, createDomainPlugin } from "@manifesto-ai/codegen";
|
|
127
130
|
|
|
128
131
|
melPlugin({
|
|
129
|
-
codegen:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
codegen: {
|
|
133
|
+
emit: createCompilerCodegen({
|
|
134
|
+
outDir: "src/generated",
|
|
135
|
+
plugins: [createDomainPlugin({ interfaceName: "CounterDomain" })],
|
|
136
|
+
}),
|
|
137
|
+
timing: "build",
|
|
138
|
+
},
|
|
133
139
|
});
|
|
134
140
|
```
|
|
135
141
|
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import { createHash } from "crypto";
|
|
10
10
|
import * as nodePath from "path";
|
|
11
11
|
import { createUnplugin } from "unplugin";
|
|
12
|
+
var VALID_CODEGEN_TIMINGS = /* @__PURE__ */ new Set(["transform", "build", "both"]);
|
|
12
13
|
function normalizeId(id) {
|
|
13
14
|
return id.split("?", 1)[0];
|
|
14
15
|
}
|
|
@@ -42,15 +43,24 @@ function sanitizePathSegment(value) {
|
|
|
42
43
|
const normalized = value.replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
43
44
|
return normalized || "domain";
|
|
44
45
|
}
|
|
45
|
-
function
|
|
46
|
+
function resolveCodegenOptions(codegen) {
|
|
46
47
|
if (!codegen) {
|
|
47
48
|
return null;
|
|
48
49
|
}
|
|
49
50
|
if (typeof codegen === "function") {
|
|
50
|
-
return codegen;
|
|
51
|
+
return { emit: codegen, timing: "transform" };
|
|
51
52
|
}
|
|
52
53
|
if (typeof codegen === "object" && typeof codegen.emit === "function") {
|
|
53
|
-
|
|
54
|
+
const timing = codegen.timing ?? "transform";
|
|
55
|
+
if (!VALID_CODEGEN_TIMINGS.has(timing)) {
|
|
56
|
+
throw new TypeError(
|
|
57
|
+
`manifesto:mel codegen timing must be one of "transform", "build", or "both" (received ${JSON.stringify(timing)})`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
emit: codegen.emit,
|
|
62
|
+
timing
|
|
63
|
+
};
|
|
54
64
|
}
|
|
55
65
|
throw new TypeError(
|
|
56
66
|
"manifesto:mel codegen must be a function or an object with a callable emit field"
|
|
@@ -59,14 +69,14 @@ function resolveCodegenEmitter(codegen) {
|
|
|
59
69
|
var unpluginMel = createUnplugin((options = {}) => {
|
|
60
70
|
const include = options.include ?? /\.mel$/;
|
|
61
71
|
const compiledSchemas = /* @__PURE__ */ new Map();
|
|
62
|
-
const
|
|
72
|
+
const codegen = resolveCodegenOptions(options.codegen);
|
|
63
73
|
return {
|
|
64
74
|
name: "manifesto:mel",
|
|
65
75
|
enforce: "pre",
|
|
66
76
|
transformInclude(id) {
|
|
67
77
|
return testRegex(include, normalizeId(id));
|
|
68
78
|
},
|
|
69
|
-
transform(source, id) {
|
|
79
|
+
async transform(source, id) {
|
|
70
80
|
const sourceId = normalizeId(id);
|
|
71
81
|
const result = compileMelDomain(source, { mode: "domain" });
|
|
72
82
|
if (result.errors.length > 0) {
|
|
@@ -77,19 +87,25 @@ ${details}`);
|
|
|
77
87
|
if (!result.schema) {
|
|
78
88
|
throw new Error(`MEL compilation produced no schema for ${sourceId}`);
|
|
79
89
|
}
|
|
80
|
-
|
|
81
|
-
|
|
90
|
+
const artifactSourceId = normalizeArtifactSourceId(sourceId);
|
|
91
|
+
if (codegen) {
|
|
92
|
+
if (codegen.timing === "transform" || codegen.timing === "both") {
|
|
93
|
+
await codegen.emit({ schema: result.schema, sourceId: artifactSourceId });
|
|
94
|
+
}
|
|
95
|
+
if (codegen.timing === "build" || codegen.timing === "both") {
|
|
96
|
+
compiledSchemas.set(artifactSourceId, result.schema);
|
|
97
|
+
}
|
|
82
98
|
}
|
|
83
99
|
const serializedSchema = JSON.stringify(result.schema, null, 2);
|
|
84
100
|
return `export default ${serializedSchema};
|
|
85
101
|
`;
|
|
86
102
|
},
|
|
87
103
|
async buildEnd() {
|
|
88
|
-
if (!
|
|
104
|
+
if (!codegen || compiledSchemas.size === 0) {
|
|
89
105
|
return;
|
|
90
106
|
}
|
|
91
107
|
for (const [sourceId, schema] of compiledSchemas) {
|
|
92
|
-
await
|
|
108
|
+
await codegen.emit({ schema, sourceId });
|
|
93
109
|
}
|
|
94
110
|
}
|
|
95
111
|
};
|
|
@@ -98,4 +114,4 @@ ${details}`);
|
|
|
98
114
|
export {
|
|
99
115
|
unpluginMel
|
|
100
116
|
};
|
|
101
|
-
//# sourceMappingURL=chunk-
|
|
117
|
+
//# sourceMappingURL=chunk-INVHMPXW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/unplugin.ts"],"sourcesContent":["/**\n * Unified MEL plugin via unplugin.\n *\n * Single implementation that targets Vite, Webpack, Rollup, esbuild, and Rspack.\n */\n\nimport { createHash } from \"node:crypto\";\nimport * as nodePath from \"node:path\";\nimport { createUnplugin } from \"unplugin\";\nimport type { DomainSchema } from \"@manifesto-ai/core\";\nimport { compileMelDomain } from \"./api/index.js\";\nimport { formatDiagnostic } from \"./mel-module.js\";\n\nexport type MelCodegenArtifact = {\n readonly schema: DomainSchema;\n readonly sourceId: string;\n};\n\nexport type MelCodegenEmitter = (\n artifact: MelCodegenArtifact\n) => unknown | Promise<unknown>;\n\nexport type MelCodegenTiming = \"transform\" | \"build\" | \"both\";\n\nexport type MelCodegenOptions = {\n readonly emit: MelCodegenEmitter;\n readonly timing?: MelCodegenTiming;\n};\n\nexport type MelPluginOptions = {\n readonly include?: RegExp;\n readonly codegen?: MelCodegenEmitter | MelCodegenOptions | false;\n};\n\nconst VALID_CODEGEN_TIMINGS = new Set<MelCodegenTiming>([\"transform\", \"build\", \"both\"]);\n\nfunction normalizeId(id: string): string {\n return id.split(\"?\", 1)[0];\n}\n\nfunction testRegex(regex: RegExp, value: string): boolean {\n regex.lastIndex = 0;\n return regex.test(value);\n}\n\nfunction normalizeArtifactSourceId(sourceId: string): string {\n const normalized = normalizeId(sourceId).replace(/\\\\/g, \"/\");\n if (!normalized) {\n return \"domain.mel\";\n }\n\n if (!nodePath.isAbsolute(sourceId)) {\n return normalized.replace(/^\\.\\//, \"\");\n }\n\n const relative = nodePath.relative(process.cwd(), sourceId);\n if (!relative || relative.startsWith(\"..\") || nodePath.isAbsolute(relative)) {\n return createExternalArtifactSourceId(normalized);\n }\n\n return relative.split(nodePath.sep).join(\"/\");\n}\n\nfunction createExternalArtifactSourceId(sourceId: string): string {\n const basename = nodePath.posix.basename(sourceId) || \"domain.mel\";\n const extension = nodePath.posix.extname(basename);\n const stem = basename.slice(0, basename.length - extension.length) || \"domain\";\n const hash = createHash(\"sha256\").update(sourceId).digest(\"hex\").slice(0, 12);\n const safeStem = sanitizePathSegment(stem);\n return `external/${safeStem}--${hash}${extension}`;\n}\n\nfunction sanitizePathSegment(value: string): string {\n const normalized = value.replace(/[^a-zA-Z0-9._-]+/g, \"-\").replace(/^-+|-+$/g, \"\");\n return normalized || \"domain\";\n}\n\nfunction resolveCodegenOptions(\n codegen: MelPluginOptions[\"codegen\"]\n): MelCodegenOptions | null {\n if (!codegen) {\n return null;\n }\n\n if (typeof codegen === \"function\") {\n return { emit: codegen, timing: \"transform\" };\n }\n\n if (typeof codegen === \"object\" && typeof codegen.emit === \"function\") {\n const timing = codegen.timing ?? \"transform\";\n if (!VALID_CODEGEN_TIMINGS.has(timing)) {\n throw new TypeError(\n `manifesto:mel codegen timing must be one of \"transform\", \"build\", or \"both\" (received ${JSON.stringify(timing)})`\n );\n }\n\n return {\n emit: codegen.emit,\n timing,\n };\n }\n\n throw new TypeError(\n \"manifesto:mel codegen must be a function or an object with a callable emit field\"\n );\n}\n\nexport const unpluginMel = createUnplugin((options: MelPluginOptions = {}) => {\n const include = options.include ?? /\\.mel$/;\n const compiledSchemas = new Map<string, DomainSchema>();\n const codegen = resolveCodegenOptions(options.codegen);\n\n return {\n name: \"manifesto:mel\",\n enforce: \"pre\" as const,\n\n transformInclude(id: string) {\n return testRegex(include, normalizeId(id));\n },\n\n async transform(source: string, id: string) {\n const sourceId = normalizeId(id);\n const result = compileMelDomain(source, { mode: \"domain\" });\n\n if (result.errors.length > 0) {\n const details = result.errors.map(formatDiagnostic).join(\"\\n\");\n throw new Error(`MEL compilation failed for ${sourceId}\\n${details}`);\n }\n\n if (!result.schema) {\n throw new Error(`MEL compilation produced no schema for ${sourceId}`);\n }\n\n const artifactSourceId = normalizeArtifactSourceId(sourceId);\n\n if (codegen) {\n if (codegen.timing === \"transform\" || codegen.timing === \"both\") {\n await codegen.emit({ schema: result.schema, sourceId: artifactSourceId });\n }\n\n if (codegen.timing === \"build\" || codegen.timing === \"both\") {\n compiledSchemas.set(artifactSourceId, result.schema);\n }\n }\n\n const serializedSchema = JSON.stringify(result.schema, null, 2);\n return `export default ${serializedSchema};\\n`;\n },\n\n async buildEnd() {\n if (!codegen || compiledSchemas.size === 0) {\n return;\n }\n\n for (const [sourceId, schema] of compiledSchemas) {\n await codegen.emit({ schema, sourceId });\n }\n },\n };\n});\n"],"mappings":";;;;;;;;AAMA,SAAS,kBAAkB;AAC3B,YAAY,cAAc;AAC1B,SAAS,sBAAsB;AA0B/B,IAAM,wBAAwB,oBAAI,IAAsB,CAAC,aAAa,SAAS,MAAM,CAAC;AAEtF,SAAS,YAAY,IAAoB;AACvC,SAAO,GAAG,MAAM,KAAK,CAAC,EAAE,CAAC;AAC3B;AAEA,SAAS,UAAU,OAAe,OAAwB;AACxD,QAAM,YAAY;AAClB,SAAO,MAAM,KAAK,KAAK;AACzB;AAEA,SAAS,0BAA0B,UAA0B;AAC3D,QAAM,aAAa,YAAY,QAAQ,EAAE,QAAQ,OAAO,GAAG;AAC3D,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AAEA,MAAI,CAAU,oBAAW,QAAQ,GAAG;AAClC,WAAO,WAAW,QAAQ,SAAS,EAAE;AAAA,EACvC;AAEA,QAAMA,YAAoB,kBAAS,QAAQ,IAAI,GAAG,QAAQ;AAC1D,MAAI,CAACA,aAAYA,UAAS,WAAW,IAAI,KAAc,oBAAWA,SAAQ,GAAG;AAC3E,WAAO,+BAA+B,UAAU;AAAA,EAClD;AAEA,SAAOA,UAA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egenArtifact = {
|
|
|
9
9
|
readonly sourceId: string;
|
|
10
10
|
};
|
|
11
11
|
export type MelCodegenEmitter = (artifact: MelCodegenArtifact) => unknown | Promise<unknown>;
|
|
12
|
+
export type MelCodegenTiming = "transform" | "build" | "both";
|
|
12
13
|
export type MelCodegenOptions = {
|
|
13
14
|
readonly emit: MelCodegenEmitter;
|
|
15
|
+
readonly timing?: MelCodegenTiming;
|
|
14
16
|
};
|
|
15
17
|
export type MelPluginOptions = {
|
|
16
18
|
readonly include?: RegExp;
|
package/dist/vite.js
CHANGED
package/dist/webpack.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manifesto-ai/compiler",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Manifesto Compiler - MEL (Manifesto Expression Language) to DomainSchema compiler",
|
|
5
5
|
"author": "eggplantiny <eggplantiny@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@anthropic-ai/sdk": "^0.26.0",
|
|
64
|
-
"@manifesto-ai/core": "^2.
|
|
64
|
+
"@manifesto-ai/core": "^2.9.0",
|
|
65
65
|
"openai": "^4.0.0",
|
|
66
66
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
67
67
|
"zod": "^4.3.6"
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"vitest": "^4.1.2",
|
|
98
98
|
"webpack": "^5.105.4",
|
|
99
99
|
"zod": "^4.3.6",
|
|
100
|
-
"@manifesto-ai/core": "2.
|
|
100
|
+
"@manifesto-ai/core": "2.9.0"
|
|
101
101
|
},
|
|
102
102
|
"files": [
|
|
103
103
|
"dist"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/unplugin.ts"],"sourcesContent":["/**\n * Unified MEL plugin via unplugin.\n *\n * Single implementation that targets Vite, Webpack, Rollup, esbuild, and Rspack.\n */\n\nimport { createHash } from \"node:crypto\";\nimport * as nodePath from \"node:path\";\nimport { createUnplugin } from \"unplugin\";\nimport type { DomainSchema } from \"@manifesto-ai/core\";\nimport { compileMelDomain } from \"./api/index.js\";\nimport { formatDiagnostic } from \"./mel-module.js\";\n\nexport type MelCodegenArtifact = {\n readonly schema: DomainSchema;\n readonly sourceId: string;\n};\n\nexport type MelCodegenEmitter = (\n artifact: MelCodegenArtifact\n) => unknown | Promise<unknown>;\n\nexport type MelCodegenOptions = {\n readonly emit: MelCodegenEmitter;\n};\n\nexport type MelPluginOptions = {\n readonly include?: RegExp;\n readonly codegen?: MelCodegenEmitter | MelCodegenOptions | false;\n};\n\nfunction normalizeId(id: string): string {\n return id.split(\"?\", 1)[0];\n}\n\nfunction testRegex(regex: RegExp, value: string): boolean {\n regex.lastIndex = 0;\n return regex.test(value);\n}\n\nfunction normalizeArtifactSourceId(sourceId: string): string {\n const normalized = normalizeId(sourceId).replace(/\\\\/g, \"/\");\n if (!normalized) {\n return \"domain.mel\";\n }\n\n if (!nodePath.isAbsolute(sourceId)) {\n return normalized.replace(/^\\.\\//, \"\");\n }\n\n const relative = nodePath.relative(process.cwd(), sourceId);\n if (!relative || relative.startsWith(\"..\") || nodePath.isAbsolute(relative)) {\n return createExternalArtifactSourceId(normalized);\n }\n\n return relative.split(nodePath.sep).join(\"/\");\n}\n\nfunction createExternalArtifactSourceId(sourceId: string): string {\n const basename = nodePath.posix.basename(sourceId) || \"domain.mel\";\n const extension = nodePath.posix.extname(basename);\n const stem = basename.slice(0, basename.length - extension.length) || \"domain\";\n const hash = createHash(\"sha256\").update(sourceId).digest(\"hex\").slice(0, 12);\n const safeStem = sanitizePathSegment(stem);\n return `external/${safeStem}--${hash}${extension}`;\n}\n\nfunction sanitizePathSegment(value: string): string {\n const normalized = value.replace(/[^a-zA-Z0-9._-]+/g, \"-\").replace(/^-+|-+$/g, \"\");\n return normalized || \"domain\";\n}\n\nfunction resolveCodegenEmitter(\n codegen: MelPluginOptions[\"codegen\"]\n): MelCodegenEmitter | null {\n if (!codegen) {\n return null;\n }\n\n if (typeof codegen === \"function\") {\n return codegen;\n }\n\n if (typeof codegen === \"object\" && typeof codegen.emit === \"function\") {\n return codegen.emit;\n }\n\n throw new TypeError(\n \"manifesto:mel codegen must be a function or an object with a callable emit field\"\n );\n}\n\nexport const unpluginMel = createUnplugin((options: MelPluginOptions = {}) => {\n const include = options.include ?? /\\.mel$/;\n const compiledSchemas = new Map<string, DomainSchema>();\n const codegenEmitter = resolveCodegenEmitter(options.codegen);\n\n return {\n name: \"manifesto:mel\",\n enforce: \"pre\" as const,\n\n transformInclude(id: string) {\n return testRegex(include, normalizeId(id));\n },\n\n transform(source: string, id: string) {\n const sourceId = normalizeId(id);\n const result = compileMelDomain(source, { mode: \"domain\" });\n\n if (result.errors.length > 0) {\n const details = result.errors.map(formatDiagnostic).join(\"\\n\");\n throw new Error(`MEL compilation failed for ${sourceId}\\n${details}`);\n }\n\n if (!result.schema) {\n throw new Error(`MEL compilation produced no schema for ${sourceId}`);\n }\n\n if (codegenEmitter) {\n compiledSchemas.set(normalizeArtifactSourceId(sourceId), result.schema);\n }\n\n const serializedSchema = JSON.stringify(result.schema, null, 2);\n return `export default ${serializedSchema};\\n`;\n },\n\n async buildEnd() {\n if (!codegenEmitter || compiledSchemas.size === 0) {\n return;\n }\n\n for (const [sourceId, schema] of compiledSchemas) {\n await codegenEmitter({ schema, sourceId });\n }\n },\n };\n});\n"],"mappings":";;;;;;;;AAMA,SAAS,kBAAkB;AAC3B,YAAY,cAAc;AAC1B,SAAS,sBAAsB;AAuB/B,SAAS,YAAY,IAAoB;AACvC,SAAO,GAAG,MAAM,KAAK,CAAC,EAAE,CAAC;AAC3B;AAEA,SAAS,UAAU,OAAe,OAAwB;AACxD,QAAM,YAAY;AAClB,SAAO,MAAM,KAAK,KAAK;AACzB;AAEA,SAAS,0BAA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