@manifesto-ai/compiler 1.9.1 → 3.1.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/README.md CHANGED
@@ -110,16 +110,34 @@ npx tsx --loader @manifesto-ai/compiler/node-loader main.ts
110
110
  ### Plugin Options
111
111
 
112
112
  ```typescript
113
+ import { createCompilerCodegen } from "@manifesto-ai/codegen";
114
+
113
115
  melPlugin({
114
116
  include: /\.mel$/, // File filter (default: /\.mel$/)
115
- codegen: { // Optional: auto-generate types
116
- outDir: "src/generated", // Output directory
117
- plugins: [/* custom */], // Defaults to TS + Zod plugins
117
+ codegen: {
118
+ emit: createCompilerCodegen(),
119
+ timing: "transform", // default: run during dev/build transforms
118
120
  },
119
121
  });
120
122
  ```
121
123
 
122
- The `codegen` option requires `@manifesto-ai/codegen` as a peer dependency. When enabled, TypeScript types and Zod schemas are generated automatically at build time.
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.
125
+
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:
127
+
128
+ ```typescript
129
+ import { createCompilerCodegen, createDomainPlugin } from "@manifesto-ai/codegen";
130
+
131
+ melPlugin({
132
+ codegen: {
133
+ emit: createCompilerCodegen({
134
+ outDir: "src/generated",
135
+ plugins: [createDomainPlugin({ interfaceName: "CounterDomain" })],
136
+ }),
137
+ timing: "build",
138
+ },
139
+ });
140
+ ```
123
141
 
124
142
  ### Subpath Exports
125
143
 
@@ -0,0 +1,117 @@
1
+ import {
2
+ formatDiagnostic
3
+ } from "./chunk-LI5HNMZV.js";
4
+ import {
5
+ compileMelDomain
6
+ } from "./chunk-7TT6Y5ZC.js";
7
+
8
+ // src/unplugin.ts
9
+ import { createHash } from "crypto";
10
+ import * as nodePath from "path";
11
+ import { createUnplugin } from "unplugin";
12
+ var VALID_CODEGEN_TIMINGS = /* @__PURE__ */ new Set(["transform", "build", "both"]);
13
+ function normalizeId(id) {
14
+ return id.split("?", 1)[0];
15
+ }
16
+ function testRegex(regex, value) {
17
+ regex.lastIndex = 0;
18
+ return regex.test(value);
19
+ }
20
+ function normalizeArtifactSourceId(sourceId) {
21
+ const normalized = normalizeId(sourceId).replace(/\\/g, "/");
22
+ if (!normalized) {
23
+ return "domain.mel";
24
+ }
25
+ if (!nodePath.isAbsolute(sourceId)) {
26
+ return normalized.replace(/^\.\//, "");
27
+ }
28
+ const relative2 = nodePath.relative(process.cwd(), sourceId);
29
+ if (!relative2 || relative2.startsWith("..") || nodePath.isAbsolute(relative2)) {
30
+ return createExternalArtifactSourceId(normalized);
31
+ }
32
+ return relative2.split(nodePath.sep).join("/");
33
+ }
34
+ function createExternalArtifactSourceId(sourceId) {
35
+ const basename = nodePath.posix.basename(sourceId) || "domain.mel";
36
+ const extension = nodePath.posix.extname(basename);
37
+ const stem = basename.slice(0, basename.length - extension.length) || "domain";
38
+ const hash = createHash("sha256").update(sourceId).digest("hex").slice(0, 12);
39
+ const safeStem = sanitizePathSegment(stem);
40
+ return `external/${safeStem}--${hash}${extension}`;
41
+ }
42
+ function sanitizePathSegment(value) {
43
+ const normalized = value.replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
44
+ return normalized || "domain";
45
+ }
46
+ function resolveCodegenOptions(codegen) {
47
+ if (!codegen) {
48
+ return null;
49
+ }
50
+ if (typeof codegen === "function") {
51
+ return { emit: codegen, timing: "transform" };
52
+ }
53
+ if (typeof codegen === "object" && typeof codegen.emit === "function") {
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
+ };
64
+ }
65
+ throw new TypeError(
66
+ "manifesto:mel codegen must be a function or an object with a callable emit field"
67
+ );
68
+ }
69
+ var unpluginMel = createUnplugin((options = {}) => {
70
+ const include = options.include ?? /\.mel$/;
71
+ const compiledSchemas = /* @__PURE__ */ new Map();
72
+ const codegen = resolveCodegenOptions(options.codegen);
73
+ return {
74
+ name: "manifesto:mel",
75
+ enforce: "pre",
76
+ transformInclude(id) {
77
+ return testRegex(include, normalizeId(id));
78
+ },
79
+ async transform(source, id) {
80
+ const sourceId = normalizeId(id);
81
+ const result = compileMelDomain(source, { mode: "domain" });
82
+ if (result.errors.length > 0) {
83
+ const details = result.errors.map(formatDiagnostic).join("\n");
84
+ throw new Error(`MEL compilation failed for ${sourceId}
85
+ ${details}`);
86
+ }
87
+ if (!result.schema) {
88
+ throw new Error(`MEL compilation produced no schema for ${sourceId}`);
89
+ }
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
+ }
98
+ }
99
+ const serializedSchema = JSON.stringify(result.schema, null, 2);
100
+ return `export default ${serializedSchema};
101
+ `;
102
+ },
103
+ async buildEnd() {
104
+ if (!codegen || compiledSchemas.size === 0) {
105
+ return;
106
+ }
107
+ for (const [sourceId, schema] of compiledSchemas) {
108
+ await codegen.emit({ schema, sourceId });
109
+ }
110
+ }
111
+ };
112
+ });
113
+
114
+ export {
115
+ unpluginMel
116
+ };
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,UAAS,MAAe,YAAG,EAAE,KAAK,GAAG;AAC9C;AAEA,SAAS,+BAA+B,UAA0B;AAChE,QAAM,WAAoB,eAAM,SAAS,QAAQ,KAAK;AACtD,QAAM,YAAqB,eAAM,QAAQ,QAAQ;AACjD,QAAM,OAAO,SAAS,MAAM,GAAG,SAAS,SAAS,UAAU,MAAM,KAAK;AACtE,QAAM,OAAO,WAAW,QAAQ,EAAE,OAAO,QAAQ,EAAE,OAAO,KAAK,EAAE,MAAM,GAAG,EAAE;AAC5E,QAAM,WAAW,oBAAoB,IAAI;AACzC,SAAO,YAAY,QAAQ,KAAK,IAAI,GAAG,SAAS;AAClD;A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AClB,cAAM,IAAI,MAAM,0CAA0C,QAAQ,EAAE;AAAA,MACtE;AAEA,YAAM,mBAAmB,0BAA0B,QAAQ;AAE3D,UAAI,SAAS;AACX,YAAI,QAAQ,WAAW,eAAe,QAAQ,WAAW,QAAQ;AAC/D,gBAAM,QAAQ,KAAK,EAAE,QAAQ,OAAO,QAAQ,UAAU,iBAAiB,CAAC;AAAA,QAC1E;AAEA,YAAI,QAAQ,WAAW,WAAW,QAAQ,WAAW,QAAQ;AAC3D,0BAAgB,IAAI,kBAAkB,OAAO,MAAM;AAAA,QACrD;AAAA,MACF;AAEA,YAAM,mBAAmB,KAAK,UAAU,OAAO,QAAQ,MAAM,CAAC;AAC9D,aAAO,kBAAkB,gBAAgB;AAAA;AAAA,IAC3C;AAAA,IAEA,MAAM,WAAW;AACf,UAAI,CAAC,WAAW,gBAAgB,SAAS,GAAG;AAC1C;AAAA,MACF;AAEA,iBAAW,CAAC,UAAU,MAAM,KAAK,iBAAiB;AAChD,cAAM,QAAQ,KAAK,EAAE,QAAQ,SAAS,CAAC;AAAA,MACzC;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":["relative"]}
package/dist/esbuild.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * esbuild plugin for MEL files.
3
3
  */
4
- export type { MelPluginOptions, MelCodegenOptions } from "./unplugin.js";
4
+ export type { MelPluginOptions, MelCodegenOptions, MelCodegenEmitter, MelCodegenArtifact, } from "./unplugin.js";
5
5
  export declare const melPlugin: (options: import("./unplugin.js").MelPluginOptions) => import("unplugin").EsbuildPlugin;
6
6
  export default melPlugin;
package/dist/esbuild.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginMel
3
- } from "./chunk-WZRGVNJK.js";
3
+ } from "./chunk-INVHMPXW.js";
4
4
  import "./chunk-LI5HNMZV.js";
5
5
  import "./chunk-7TT6Y5ZC.js";
6
6
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/esbuild.ts"],"sourcesContent":["/**\n * esbuild plugin for MEL files.\n */\n\nimport { unpluginMel } from \"./unplugin.js\";\n\nexport type { MelPluginOptions, MelCodegenOptions } from \"./unplugin.js\";\nexport const melPlugin = unpluginMel.esbuild;\nexport default melPlugin;\n"],"mappings":";;;;;;;AAOO,IAAM,YAAY,YAAY;AACrC,IAAO,kBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/esbuild.ts"],"sourcesContent":["/**\n * esbuild plugin for MEL files.\n */\n\nimport { unpluginMel } from \"./unplugin.js\";\n\nexport type {\n MelPluginOptions,\n MelCodegenOptions,\n MelCodegenEmitter,\n MelCodegenArtifact,\n} from \"./unplugin.js\";\nexport const melPlugin = unpluginMel.esbuild;\nexport default melPlugin;\n"],"mappings":";;;;;;;AAYO,IAAM,YAAY,YAAY;AACrC,IAAO,kBAAQ;","names":[]}
package/dist/rollup.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Rollup plugin for MEL files.
3
3
  */
4
- export type { MelPluginOptions, MelCodegenOptions } from "./unplugin.js";
4
+ export type { MelPluginOptions, MelCodegenOptions, MelCodegenEmitter, MelCodegenArtifact, } from "./unplugin.js";
5
5
  export declare const melPlugin: (options: import("./unplugin.js").MelPluginOptions) => import("unplugin").RollupPlugin<any> | import("unplugin").RollupPlugin<any>[];
6
6
  export default melPlugin;
package/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginMel
3
- } from "./chunk-WZRGVNJK.js";
3
+ } from "./chunk-INVHMPXW.js";
4
4
  import "./chunk-LI5HNMZV.js";
5
5
  import "./chunk-7TT6Y5ZC.js";
6
6
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/rollup.ts"],"sourcesContent":["/**\n * Rollup plugin for MEL files.\n */\n\nimport { unpluginMel } from \"./unplugin.js\";\n\nexport type { MelPluginOptions, MelCodegenOptions } from \"./unplugin.js\";\nexport const melPlugin = unpluginMel.rollup;\nexport default melPlugin;\n"],"mappings":";;;;;;;AAOO,IAAM,YAAY,YAAY;AACrC,IAAO,iBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/rollup.ts"],"sourcesContent":["/**\n * Rollup plugin for MEL files.\n */\n\nimport { unpluginMel } from \"./unplugin.js\";\n\nexport type {\n MelPluginOptions,\n MelCodegenOptions,\n MelCodegenEmitter,\n MelCodegenArtifact,\n} from \"./unplugin.js\";\nexport const melPlugin = unpluginMel.rollup;\nexport default melPlugin;\n"],"mappings":";;;;;;;AAYO,IAAM,YAAY,YAAY;AACrC,IAAO,iBAAQ;","names":[]}
package/dist/rspack.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Rspack plugin for MEL files.
3
3
  */
4
- export type { MelPluginOptions, MelCodegenOptions } from "./unplugin.js";
4
+ export type { MelPluginOptions, MelCodegenOptions, MelCodegenEmitter, MelCodegenArtifact, } from "./unplugin.js";
5
5
  export declare const melPlugin: (options: import("./unplugin.js").MelPluginOptions) => RspackPluginInstance;
6
6
  export default melPlugin;
package/dist/rspack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginMel
3
- } from "./chunk-WZRGVNJK.js";
3
+ } from "./chunk-INVHMPXW.js";
4
4
  import "./chunk-LI5HNMZV.js";
5
5
  import "./chunk-7TT6Y5ZC.js";
6
6
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/rspack.ts"],"sourcesContent":["/**\n * Rspack plugin for MEL files.\n */\n\nimport { unpluginMel } from \"./unplugin.js\";\n\nexport type { MelPluginOptions, MelCodegenOptions } from \"./unplugin.js\";\nexport const melPlugin = unpluginMel.rspack;\nexport default melPlugin;\n"],"mappings":";;;;;;;AAOO,IAAM,YAAY,YAAY;AACrC,IAAO,iBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/rspack.ts"],"sourcesContent":["/**\n * Rspack plugin for MEL files.\n */\n\nimport { unpluginMel } from \"./unplugin.js\";\n\nexport type {\n MelPluginOptions,\n MelCodegenOptions,\n MelCodegenEmitter,\n MelCodegenArtifact,\n} from \"./unplugin.js\";\nexport const melPlugin = unpluginMel.rspack;\nexport default melPlugin;\n"],"mappings":";;;;;;;AAYO,IAAM,YAAY,YAAY;AACrC,IAAO,iBAAQ;","names":[]}
@@ -3,12 +3,19 @@
3
3
  *
4
4
  * Single implementation that targets Vite, Webpack, Rollup, esbuild, and Rspack.
5
5
  */
6
+ import type { DomainSchema } from "@manifesto-ai/core";
7
+ export type MelCodegenArtifact = {
8
+ readonly schema: DomainSchema;
9
+ readonly sourceId: string;
10
+ };
11
+ export type MelCodegenEmitter = (artifact: MelCodegenArtifact) => unknown | Promise<unknown>;
12
+ export type MelCodegenTiming = "transform" | "build" | "both";
6
13
  export type MelCodegenOptions = {
7
- readonly outDir: string;
8
- readonly plugins?: readonly import("@manifesto-ai/codegen").CodegenPlugin[];
14
+ readonly emit: MelCodegenEmitter;
15
+ readonly timing?: MelCodegenTiming;
9
16
  };
10
17
  export type MelPluginOptions = {
11
18
  readonly include?: RegExp;
12
- readonly codegen?: MelCodegenOptions | false;
19
+ readonly codegen?: MelCodegenEmitter | MelCodegenOptions | false;
13
20
  };
14
21
  export declare const unpluginMel: import("unplugin").UnpluginInstance<MelPluginOptions, boolean>;
package/dist/vite.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Vite plugin for MEL files.
3
3
  */
4
- export type { MelPluginOptions, MelCodegenOptions } from "./unplugin.js";
4
+ export type { MelPluginOptions, MelCodegenOptions, MelCodegenEmitter, MelCodegenArtifact, } from "./unplugin.js";
5
5
  export declare const melPlugin: (options: import("./unplugin.js").MelPluginOptions) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
6
6
  export default melPlugin;
package/dist/vite.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginMel
3
- } from "./chunk-WZRGVNJK.js";
3
+ } from "./chunk-INVHMPXW.js";
4
4
  import "./chunk-LI5HNMZV.js";
5
5
  import "./chunk-7TT6Y5ZC.js";
6
6
 
package/dist/vite.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/vite.ts"],"sourcesContent":["/**\n * Vite plugin for MEL files.\n */\n\nimport { unpluginMel } from \"./unplugin.js\";\n\nexport type { MelPluginOptions, MelCodegenOptions } from \"./unplugin.js\";\nexport const melPlugin = unpluginMel.vite;\nexport default melPlugin;\n"],"mappings":";;;;;;;AAOO,IAAM,YAAY,YAAY;AACrC,IAAO,eAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/vite.ts"],"sourcesContent":["/**\n * Vite plugin for MEL files.\n */\n\nimport { unpluginMel } from \"./unplugin.js\";\n\nexport type {\n MelPluginOptions,\n MelCodegenOptions,\n MelCodegenEmitter,\n MelCodegenArtifact,\n} from \"./unplugin.js\";\nexport const melPlugin = unpluginMel.vite;\nexport default melPlugin;\n"],"mappings":";;;;;;;AAYO,IAAM,YAAY,YAAY;AACrC,IAAO,eAAQ;","names":[]}
package/dist/webpack.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Webpack plugin for MEL files.
3
3
  */
4
- export type { MelPluginOptions, MelCodegenOptions } from "./unplugin.js";
4
+ export type { MelPluginOptions, MelCodegenOptions, MelCodegenEmitter, MelCodegenArtifact, } from "./unplugin.js";
5
5
  export declare const melPlugin: (options: import("./unplugin.js").MelPluginOptions) => import("unplugin").WebpackPluginInstance;
6
6
  export default melPlugin;
package/dist/webpack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginMel
3
- } from "./chunk-WZRGVNJK.js";
3
+ } from "./chunk-INVHMPXW.js";
4
4
  import "./chunk-LI5HNMZV.js";
5
5
  import "./chunk-7TT6Y5ZC.js";
6
6
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/webpack.ts"],"sourcesContent":["/**\n * Webpack plugin for MEL files.\n */\n\nimport { unpluginMel } from \"./unplugin.js\";\n\nexport type { MelPluginOptions, MelCodegenOptions } from \"./unplugin.js\";\nexport const melPlugin = unpluginMel.webpack;\nexport default melPlugin;\n"],"mappings":";;;;;;;AAOO,IAAM,YAAY,YAAY;AACrC,IAAO,kBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/webpack.ts"],"sourcesContent":["/**\n * Webpack plugin for MEL files.\n */\n\nimport { unpluginMel } from \"./unplugin.js\";\n\nexport type {\n MelPluginOptions,\n MelCodegenOptions,\n MelCodegenEmitter,\n MelCodegenArtifact,\n} from \"./unplugin.js\";\nexport const melPlugin = unpluginMel.webpack;\nexport default melPlugin;\n"],"mappings":";;;;;;;AAYO,IAAM,YAAY,YAAY;AACrC,IAAO,kBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manifesto-ai/compiler",
3
- "version": "1.9.1",
3
+ "version": "3.1.0",
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,6 @@
61
61
  },
62
62
  "peerDependencies": {
63
63
  "@anthropic-ai/sdk": "^0.26.0",
64
- "@manifesto-ai/codegen": "^0.1.5",
65
64
  "@manifesto-ai/core": "^2.0.0",
66
65
  "openai": "^4.0.0",
67
66
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0",
@@ -71,9 +70,6 @@
71
70
  "@anthropic-ai/sdk": {
72
71
  "optional": true
73
72
  },
74
- "@manifesto-ai/codegen": {
75
- "optional": true
76
- },
77
73
  "openai": {
78
74
  "optional": true
79
75
  },
@@ -101,7 +97,6 @@
101
97
  "vitest": "^4.1.2",
102
98
  "webpack": "^5.105.4",
103
99
  "zod": "^4.3.6",
104
- "@manifesto-ai/codegen": "0.1.5",
105
100
  "@manifesto-ai/core": "2.8.0"
106
101
  },
107
102
  "files": [
@@ -1,74 +0,0 @@
1
- import {
2
- formatDiagnostic
3
- } from "./chunk-LI5HNMZV.js";
4
- import {
5
- compileMelDomain
6
- } from "./chunk-7TT6Y5ZC.js";
7
-
8
- // src/unplugin.ts
9
- import { createUnplugin } from "unplugin";
10
- function normalizeId(id) {
11
- return id.split("?", 1)[0];
12
- }
13
- function testRegex(regex, value) {
14
- regex.lastIndex = 0;
15
- return regex.test(value);
16
- }
17
- var unpluginMel = createUnplugin((options = {}) => {
18
- const include = options.include ?? /\.mel$/;
19
- const compiledSchemas = /* @__PURE__ */ new Map();
20
- return {
21
- name: "manifesto:mel",
22
- enforce: "pre",
23
- transformInclude(id) {
24
- return testRegex(include, normalizeId(id));
25
- },
26
- transform(source, id) {
27
- const sourceId = normalizeId(id);
28
- const result = compileMelDomain(source, { mode: "domain" });
29
- if (result.errors.length > 0) {
30
- const details = result.errors.map(formatDiagnostic).join("\n");
31
- throw new Error(`MEL compilation failed for ${sourceId}
32
- ${details}`);
33
- }
34
- if (!result.schema) {
35
- throw new Error(`MEL compilation produced no schema for ${sourceId}`);
36
- }
37
- if (options.codegen) {
38
- compiledSchemas.set(sourceId, result.schema);
39
- }
40
- const serializedSchema = JSON.stringify(result.schema, null, 2);
41
- return `export default ${serializedSchema};
42
- `;
43
- },
44
- async buildEnd() {
45
- if (!options.codegen || compiledSchemas.size === 0) return;
46
- let codegen;
47
- try {
48
- codegen = await import("@manifesto-ai/codegen");
49
- } catch {
50
- console.warn(
51
- "[manifesto:mel] codegen option is enabled but @manifesto-ai/codegen is not installed. Skipping."
52
- );
53
- return;
54
- }
55
- const plugins = options.codegen.plugins ?? [
56
- codegen.createTsPlugin(),
57
- codegen.createZodPlugin()
58
- ];
59
- for (const [sourceId, schema] of compiledSchemas) {
60
- await codegen.generate({
61
- schema,
62
- outDir: options.codegen.outDir,
63
- plugins,
64
- sourceId
65
- });
66
- }
67
- }
68
- };
69
- });
70
-
71
- export {
72
- unpluginMel
73
- };
74
- //# sourceMappingURL=chunk-WZRGVNJK.js.map
@@ -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 { 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 MelCodegenOptions = {\n readonly outDir: string;\n readonly plugins?: readonly import(\"@manifesto-ai/codegen\").CodegenPlugin[];\n};\n\nexport type MelPluginOptions = {\n readonly include?: RegExp;\n readonly codegen?: 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\nexport const unpluginMel = createUnplugin((options: MelPluginOptions = {}) => {\n const include = options.include ?? /\\.mel$/;\n const compiledSchemas = new Map<string, DomainSchema>();\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 (options.codegen) {\n compiledSchemas.set(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 (!options.codegen || compiledSchemas.size === 0) return;\n\n let codegen: typeof import(\"@manifesto-ai/codegen\");\n try {\n codegen = await import(\"@manifesto-ai/codegen\");\n } catch {\n console.warn(\n \"[manifesto:mel] codegen option is enabled but @manifesto-ai/codegen is not installed. Skipping.\"\n );\n return;\n }\n\n const plugins = options.codegen.plugins ?? [\n codegen.createTsPlugin(),\n codegen.createZodPlugin(),\n ];\n\n for (const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