@mmapp/react-compiler 0.1.0-alpha.20 → 0.1.0-alpha.21
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/babel/index.js +29 -5
- package/dist/babel/index.mjs +1 -1
- package/dist/chunk-5PM7CGFQ.mjs +550 -0
- package/dist/chunk-AIM5FKMV.mjs +186 -0
- package/dist/chunk-MRCNUYFA.mjs +2921 -0
- package/dist/chunk-NJNAQF5I.mjs +7533 -0
- package/dist/chunk-RTAUTGHB.mjs +248 -0
- package/dist/chunk-YOVAADAD.mjs +175 -0
- package/dist/cli/index.js +29 -5
- package/dist/cli/index.mjs +5 -5
- package/dist/dev-server.js +29 -5
- package/dist/dev-server.mjs +4 -4
- package/dist/envelope.js +29 -5
- package/dist/envelope.mjs +2 -2
- package/dist/index.js +29 -5
- package/dist/index.mjs +6 -6
- package/dist/project-compiler-HNDWIX4J.mjs +10 -0
- package/dist/testing/index.js +29 -5
- package/dist/testing/index.mjs +1 -1
- package/dist/verify-LZXUHOX6.mjs +1833 -0
- package/dist/vite/index.js +29 -5
- package/dist/vite/index.mjs +2 -2
- package/package.json +15 -5
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSourceEnvelope,
|
|
3
|
+
generateFsTree
|
|
4
|
+
} from "./chunk-5M7DKKBC.mjs";
|
|
5
|
+
import {
|
|
6
|
+
babelPlugin
|
|
7
|
+
} from "./chunk-NJNAQF5I.mjs";
|
|
8
|
+
|
|
9
|
+
// src/cli/build.ts
|
|
10
|
+
import { glob } from "glob";
|
|
11
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
|
|
12
|
+
import { transformSync } from "@babel/core";
|
|
13
|
+
import { join, basename, dirname, resolve } from "path";
|
|
14
|
+
import { execSync } from "child_process";
|
|
15
|
+
async function build(options = {}) {
|
|
16
|
+
const srcDir = options.src ?? "src/workflows";
|
|
17
|
+
const outDir = options.outDir ?? "dist/workflows";
|
|
18
|
+
const mode = options.mode ?? "infer";
|
|
19
|
+
if (!options.skipTypeCheck) {
|
|
20
|
+
const tsconfigPath = resolve(srcDir, "tsconfig.json");
|
|
21
|
+
const hasTsconfig = existsSync(tsconfigPath);
|
|
22
|
+
if (hasTsconfig) {
|
|
23
|
+
console.log(`[mindmatrix-react] Type checking (tsc --noEmit)...`);
|
|
24
|
+
try {
|
|
25
|
+
execSync(`npx tsc --noEmit --project ${tsconfigPath}`, {
|
|
26
|
+
cwd: resolve(srcDir),
|
|
27
|
+
stdio: "pipe",
|
|
28
|
+
encoding: "utf-8"
|
|
29
|
+
});
|
|
30
|
+
console.log(`[mindmatrix-react] Type check passed.`);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
const tscError = err;
|
|
33
|
+
const output = tscError.stdout || tscError.stderr || "";
|
|
34
|
+
const lines = output.split("\n").filter((l) => l.trim());
|
|
35
|
+
const typeErrors = [];
|
|
36
|
+
for (const line of lines) {
|
|
37
|
+
const match = line.match(/^(.+?)\((\d+),\d+\):\s*error\s+(TS\d+):\s*(.+)$/);
|
|
38
|
+
if (match) {
|
|
39
|
+
typeErrors.push({
|
|
40
|
+
file: match[1],
|
|
41
|
+
message: `${match[3]}: ${match[4]}`,
|
|
42
|
+
line: parseInt(match[2], 10)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (typeErrors.length > 0) {
|
|
47
|
+
console.error(`
|
|
48
|
+
[mindmatrix-react] Type check failed with ${typeErrors.length} error(s):
|
|
49
|
+
`);
|
|
50
|
+
for (const te of typeErrors) {
|
|
51
|
+
console.error(` \u2717 ${te.file}:${te.line || "?"} ${te.message}`);
|
|
52
|
+
}
|
|
53
|
+
console.error(`
|
|
54
|
+
[mindmatrix-react] Fix type errors or use --skip-type-check to bypass.
|
|
55
|
+
`);
|
|
56
|
+
return {
|
|
57
|
+
compiled: 0,
|
|
58
|
+
errors: typeErrors.length,
|
|
59
|
+
warnings: 0,
|
|
60
|
+
definitions: [],
|
|
61
|
+
errorDetails: typeErrors
|
|
62
|
+
};
|
|
63
|
+
} else if (output.includes("not the tsc command") || output.includes("Cannot find module") || output.includes("ERR_MODULE_NOT_FOUND") || output.includes("command not found")) {
|
|
64
|
+
console.warn(`[mindmatrix-react] TypeScript not installed \u2014 skipping type check.`);
|
|
65
|
+
console.warn(` Run \`npm install\` to enable type checking, or use --skip-type-check.
|
|
66
|
+
`);
|
|
67
|
+
} else {
|
|
68
|
+
console.error(`
|
|
69
|
+
[mindmatrix-react] Type check failed:
|
|
70
|
+
${output}`);
|
|
71
|
+
return {
|
|
72
|
+
compiled: 0,
|
|
73
|
+
errors: 1,
|
|
74
|
+
warnings: 0,
|
|
75
|
+
definitions: [],
|
|
76
|
+
errorDetails: [{ file: "tsconfig.json", message: output.slice(0, 500) }]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const configPath = resolve(srcDir, "mm.config.ts");
|
|
83
|
+
if (existsSync(configPath)) {
|
|
84
|
+
console.log(`[mindmatrix-react] Detected mm.config.ts \u2014 using project compiler...`);
|
|
85
|
+
const { compileProject } = await import("./project-compiler-HNDWIX4J.mjs");
|
|
86
|
+
const allProjectFiles = await glob(`${srcDir}/**/*.{ts,tsx}`, {
|
|
87
|
+
ignore: ["**/node_modules/**", "**/dist/**", "**/__tests__/**", "**/*.test.*"]
|
|
88
|
+
});
|
|
89
|
+
const fileMap = {};
|
|
90
|
+
for (const f of allProjectFiles) {
|
|
91
|
+
const rel = f.startsWith(srcDir + "/") ? f.slice(srcDir.length + 1) : f;
|
|
92
|
+
fileMap[rel] = readFileSync(f, "utf-8");
|
|
93
|
+
}
|
|
94
|
+
mkdirSync(outDir, { recursive: true });
|
|
95
|
+
const result2 = compileProject(fileMap, { mode });
|
|
96
|
+
const errors = result2.errors.filter((e) => e.severity === "error");
|
|
97
|
+
const warnings = result2.errors.filter((e) => e.severity === "warning");
|
|
98
|
+
const definitions2 = [result2.ir];
|
|
99
|
+
const errorDetails2 = [];
|
|
100
|
+
for (const err of errors) {
|
|
101
|
+
errorDetails2.push({ file: err.file, message: err.message, line: err.line });
|
|
102
|
+
console.error(` x ${err.file}${err.line ? `:${err.line}` : ""} ${err.message}`);
|
|
103
|
+
}
|
|
104
|
+
for (const warn of warnings) {
|
|
105
|
+
console.warn(` ! ${warn.file}${warn.line ? `:${warn.line}` : ""} ${warn.message}`);
|
|
106
|
+
}
|
|
107
|
+
const irPath = join(outDir, `${result2.ir.slug}.workflow.json`);
|
|
108
|
+
writeFileSync(irPath, JSON.stringify(result2.ir, null, 2), "utf-8");
|
|
109
|
+
console.log(` + ${basename(irPath)}`);
|
|
110
|
+
const seenSlugs = /* @__PURE__ */ new Set([result2.ir.slug]);
|
|
111
|
+
for (const child of result2.childDefinitions) {
|
|
112
|
+
if (seenSlugs.has(child.slug)) continue;
|
|
113
|
+
seenSlugs.add(child.slug);
|
|
114
|
+
definitions2.push(child);
|
|
115
|
+
const childPath = join(outDir, `${child.slug}.workflow.json`);
|
|
116
|
+
writeFileSync(childPath, JSON.stringify(child, null, 2), "utf-8");
|
|
117
|
+
console.log(` + ${basename(childPath)}`);
|
|
118
|
+
}
|
|
119
|
+
console.log(`
|
|
120
|
+
[mindmatrix-react] Compiled ${definitions2.length} definitions, ${errors.length} errors, ${warnings.length} warnings`);
|
|
121
|
+
return { compiled: definitions2.length, errors: errors.length, warnings: warnings.length, definitions: definitions2, errorDetails: errorDetails2 };
|
|
122
|
+
}
|
|
123
|
+
console.log(`[mindmatrix-react] Building workflows from ${srcDir}...`);
|
|
124
|
+
mkdirSync(outDir, { recursive: true });
|
|
125
|
+
const workflowFiles = await glob(`${srcDir}/**/*.workflow.{tsx,ts,jsx,js}`);
|
|
126
|
+
const modelFiles = await glob(`${srcDir}/**/models/**/*.{ts,tsx}`);
|
|
127
|
+
const serverFiles = await glob(`${srcDir}/**/*.server.{ts,tsx,js,jsx}`);
|
|
128
|
+
const allFiles = [.../* @__PURE__ */ new Set([...workflowFiles, ...modelFiles, ...serverFiles])];
|
|
129
|
+
if (allFiles.length === 0) {
|
|
130
|
+
console.log(`[mindmatrix-react] No workflow files found in ${srcDir}`);
|
|
131
|
+
return { compiled: 0, errors: 0, warnings: 0, definitions: [], errorDetails: [] };
|
|
132
|
+
}
|
|
133
|
+
let compiled = 0;
|
|
134
|
+
let errorCount = 0;
|
|
135
|
+
let warningCount = 0;
|
|
136
|
+
const definitions = [];
|
|
137
|
+
const errorDetails = [];
|
|
138
|
+
for (const file of allFiles) {
|
|
139
|
+
try {
|
|
140
|
+
const code = readFileSync(file, "utf-8");
|
|
141
|
+
const result2 = transformSync(code, {
|
|
142
|
+
filename: file,
|
|
143
|
+
plugins: [[babelPlugin, { mode }]],
|
|
144
|
+
parserOpts: { plugins: ["jsx", "typescript"], attachComment: true }
|
|
145
|
+
});
|
|
146
|
+
const ir = result2?.metadata?.mindmatrixIR;
|
|
147
|
+
const definition = result2?.metadata?.mindmatrixDefinition;
|
|
148
|
+
const canonical = result2?.metadata?.mindmatrixCanonical;
|
|
149
|
+
if (ir) {
|
|
150
|
+
definitions.push(ir);
|
|
151
|
+
const irErrors = ir.metadata?.errors;
|
|
152
|
+
const irWarnings = ir.metadata?.warnings;
|
|
153
|
+
if (irErrors && irErrors.length > 0) {
|
|
154
|
+
for (const err of irErrors) {
|
|
155
|
+
errorDetails.push({
|
|
156
|
+
file: basename(file),
|
|
157
|
+
message: err.message,
|
|
158
|
+
line: err.line
|
|
159
|
+
});
|
|
160
|
+
console.error(` \u2717 ${basename(file)}:${err.line || "?"} ${err.message}`);
|
|
161
|
+
}
|
|
162
|
+
errorCount += irErrors.length;
|
|
163
|
+
}
|
|
164
|
+
if (irWarnings && irWarnings.length > 0) {
|
|
165
|
+
for (const warn of irWarnings) {
|
|
166
|
+
console.warn(` \u26A0 ${basename(file)}:${warn.line || "?"} ${warn.message}`);
|
|
167
|
+
}
|
|
168
|
+
warningCount += irWarnings.length;
|
|
169
|
+
}
|
|
170
|
+
const compiledFileName = basename(file).replace(/\.workflow\.(tsx?|jsx?)$/, ".json").replace(/\.(tsx?|jsx?)$/, ".json");
|
|
171
|
+
const compiledFile = join(outDir, compiledFileName);
|
|
172
|
+
mkdirSync(dirname(compiledFile), { recursive: true });
|
|
173
|
+
writeFileSync(compiledFile, JSON.stringify({ canonical, ir }, null, 2), "utf-8");
|
|
174
|
+
const irFileName = basename(file).replace(/\.workflow\.(tsx?|jsx?)$/, ".workflow.json").replace(/\.(tsx?|jsx?)$/, ".json");
|
|
175
|
+
const irFile = join(outDir, irFileName);
|
|
176
|
+
writeFileSync(irFile, JSON.stringify(ir, null, 2), "utf-8");
|
|
177
|
+
if (definition) {
|
|
178
|
+
const defFileName = basename(file).replace(/\.workflow\.(tsx?|jsx?)$/, ".def.json").replace(/\.(tsx?|jsx?)$/, ".def.json");
|
|
179
|
+
const defFile = join(outDir, defFileName);
|
|
180
|
+
writeFileSync(defFile, JSON.stringify(definition, null, 2), "utf-8");
|
|
181
|
+
}
|
|
182
|
+
console.log(` \u2713 ${basename(file)} \u2192 ${compiledFileName}`);
|
|
183
|
+
compiled++;
|
|
184
|
+
} else {
|
|
185
|
+
console.error(` \u2717 ${basename(file)}: No IR generated`);
|
|
186
|
+
errorDetails.push({ file: basename(file), message: "No IR generated" });
|
|
187
|
+
errorCount++;
|
|
188
|
+
}
|
|
189
|
+
} catch (error) {
|
|
190
|
+
const msg = error.message;
|
|
191
|
+
console.error(` \u2717 ${basename(file)}: ${msg}`);
|
|
192
|
+
errorDetails.push({ file: basename(file), message: msg });
|
|
193
|
+
errorCount++;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (options.envelope) {
|
|
197
|
+
const allSourceFiles = await glob(`${srcDir}/**/*.{ts,tsx,js,jsx}`);
|
|
198
|
+
const fsTree = generateFsTree(allSourceFiles, resolve(srcDir));
|
|
199
|
+
const envelope = createSourceEnvelope({
|
|
200
|
+
blueprintSlug: options.slug || "project",
|
|
201
|
+
blueprintVersion: options.version || "0.1.0",
|
|
202
|
+
definitions,
|
|
203
|
+
fsTree,
|
|
204
|
+
mode
|
|
205
|
+
});
|
|
206
|
+
const envelopePath = join(outDir, "envelope.json");
|
|
207
|
+
writeFileSync(envelopePath, JSON.stringify(envelope, null, 2), "utf-8");
|
|
208
|
+
console.log(`
|
|
209
|
+
\u2713 Source envelope \u2192 envelope.json (${envelope.envelopeId.substring(0, 8)})`);
|
|
210
|
+
}
|
|
211
|
+
console.log(`
|
|
212
|
+
[mindmatrix-react] Compiled ${compiled} workflows, ${errorCount} errors, ${warningCount} warnings`);
|
|
213
|
+
const result = { compiled, errors: errorCount, warnings: warningCount, definitions, errorDetails };
|
|
214
|
+
if (options.watch) {
|
|
215
|
+
await startWatchMode(options);
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
async function startWatchMode(options) {
|
|
220
|
+
const { watch: fsWatch } = await import("fs");
|
|
221
|
+
const srcDir = options.src ?? "src/workflows";
|
|
222
|
+
let debounce = null;
|
|
223
|
+
console.log(`
|
|
224
|
+
[mindmatrix-react] Watching ${srcDir} for changes... (Ctrl+C to stop)
|
|
225
|
+
`);
|
|
226
|
+
fsWatch(srcDir, { recursive: true }, (_event, filename) => {
|
|
227
|
+
if (!filename) return;
|
|
228
|
+
if (!filename.match(/\.(tsx?|jsx?)$/)) return;
|
|
229
|
+
if (filename.includes("node_modules") || filename.includes("dist")) return;
|
|
230
|
+
if (debounce) clearTimeout(debounce);
|
|
231
|
+
debounce = setTimeout(async () => {
|
|
232
|
+
const ts = (/* @__PURE__ */ new Date()).toLocaleTimeString();
|
|
233
|
+
console.log(`
|
|
234
|
+
[${ts}] Change detected: ${filename} \u2014 recompiling...`);
|
|
235
|
+
try {
|
|
236
|
+
await build({ ...options, watch: false, skipTypeCheck: true });
|
|
237
|
+
} catch (e) {
|
|
238
|
+
console.error(`[mindmatrix-react] Rebuild failed:`, e.message);
|
|
239
|
+
}
|
|
240
|
+
}, 300);
|
|
241
|
+
});
|
|
242
|
+
return new Promise(() => {
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export {
|
|
247
|
+
build
|
|
248
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
babelPlugin
|
|
3
|
+
} from "./chunk-NJNAQF5I.mjs";
|
|
4
|
+
|
|
5
|
+
// src/vite/index.ts
|
|
6
|
+
import { transformSync } from "@babel/core";
|
|
7
|
+
import { writeFileSync, mkdirSync } from "fs";
|
|
8
|
+
import { dirname, join, relative, basename } from "path";
|
|
9
|
+
function mindmatrixReact(options) {
|
|
10
|
+
const include = options?.include ?? ["**/*.workflow.tsx"];
|
|
11
|
+
const mode = options?.mode ?? "infer";
|
|
12
|
+
const outDir = options?.outDir ?? "dist/workflows";
|
|
13
|
+
const seedOnCompile = options?.seedOnCompile ?? false;
|
|
14
|
+
const apiUrl = options?.apiUrl ?? "http://localhost:4200/api/v1";
|
|
15
|
+
const authToken = options?.authToken ?? process.env.MINDMATRIX_TOKEN;
|
|
16
|
+
let enableSourceMaps = options?.sourceMaps;
|
|
17
|
+
let enableSourceAnnotations = options?.sourceAnnotations;
|
|
18
|
+
let isDev = true;
|
|
19
|
+
const compiledFiles = /* @__PURE__ */ new Map();
|
|
20
|
+
function shouldTransform(id) {
|
|
21
|
+
return include.some((pattern) => {
|
|
22
|
+
const regex = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "<<GLOBSTAR>>").replace(/\*/g, "[^/]*").replace(/<<GLOBSTAR>>/g, ".*").replace(/\?/g, ".");
|
|
23
|
+
return new RegExp(regex).test(id);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async function seedToApi(ir, filePath) {
|
|
27
|
+
if (!seedOnCompile || !authToken) return;
|
|
28
|
+
try {
|
|
29
|
+
const body = {
|
|
30
|
+
slug: ir.slug,
|
|
31
|
+
name: ir.name,
|
|
32
|
+
version: ir.version,
|
|
33
|
+
category: ir.category || ["workflow"],
|
|
34
|
+
fields: ir.fields || [],
|
|
35
|
+
states: ir.states || [],
|
|
36
|
+
transitions: ir.transitions || [],
|
|
37
|
+
experience: ir.experience || {},
|
|
38
|
+
metadata: {
|
|
39
|
+
...ir.metadata || {},
|
|
40
|
+
source_file: relative(process.cwd(), filePath),
|
|
41
|
+
compiled_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const resp = await fetch(`${apiUrl}/workflow/definitions`, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: {
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
"Authorization": `Bearer ${authToken}`
|
|
49
|
+
},
|
|
50
|
+
body: JSON.stringify(body)
|
|
51
|
+
});
|
|
52
|
+
if (resp.ok) {
|
|
53
|
+
console.log(`[mindmatrix-react] Seeded ${ir.slug} to ${apiUrl}`);
|
|
54
|
+
} else if (resp.status === 409) {
|
|
55
|
+
const existing = await fetch(
|
|
56
|
+
`${apiUrl}/workflow/definitions?slug=${encodeURIComponent(ir.slug)}&version=${encodeURIComponent(ir.version)}`,
|
|
57
|
+
{ headers: { "Authorization": `Bearer ${authToken}` } }
|
|
58
|
+
);
|
|
59
|
+
if (existing.ok) {
|
|
60
|
+
const data = await existing.json();
|
|
61
|
+
const defId = Array.isArray(data) ? data[0]?.id : data?.id;
|
|
62
|
+
if (defId) {
|
|
63
|
+
await fetch(`${apiUrl}/workflow/definitions/${defId}`, {
|
|
64
|
+
method: "PATCH",
|
|
65
|
+
headers: {
|
|
66
|
+
"Content-Type": "application/json",
|
|
67
|
+
"Authorization": `Bearer ${authToken}`
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify(body)
|
|
70
|
+
});
|
|
71
|
+
console.log(`[mindmatrix-react] Updated ${ir.slug} (PATCH)`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
const text = await resp.text().catch(() => "");
|
|
76
|
+
console.warn(`[mindmatrix-react] Seed failed (${resp.status}): ${text.slice(0, 200)}`);
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
console.warn(`[mindmatrix-react] Seed failed:`, e instanceof Error ? e.message : e);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
name: "mindmatrix-react",
|
|
84
|
+
enforce: "pre",
|
|
85
|
+
configResolved(config) {
|
|
86
|
+
isDev = config.command === "serve";
|
|
87
|
+
if (enableSourceMaps === void 0) enableSourceMaps = isDev;
|
|
88
|
+
if (enableSourceAnnotations === void 0) enableSourceAnnotations = isDev;
|
|
89
|
+
},
|
|
90
|
+
transform(code, id) {
|
|
91
|
+
if (!shouldTransform(id)) return null;
|
|
92
|
+
try {
|
|
93
|
+
const wantMaps = enableSourceMaps !== false;
|
|
94
|
+
const result = transformSync(code, {
|
|
95
|
+
filename: id,
|
|
96
|
+
plugins: [[babelPlugin, { mode, filename: id, sourceAnnotations: enableSourceAnnotations }]],
|
|
97
|
+
parserOpts: { plugins: ["jsx", "typescript"] },
|
|
98
|
+
sourceMaps: wantMaps,
|
|
99
|
+
// Embed original source in the source map so debuggers can show .workflow.tsx
|
|
100
|
+
...wantMaps ? { sourceFileName: basename(id) } : {}
|
|
101
|
+
});
|
|
102
|
+
if (!result?.code) return null;
|
|
103
|
+
const metadata = result.metadata || {};
|
|
104
|
+
const ir = metadata.mindmatrixIR;
|
|
105
|
+
const warnings = metadata.mindmatrixWarnings;
|
|
106
|
+
const errors = metadata.mindmatrixErrors;
|
|
107
|
+
if (warnings?.length) {
|
|
108
|
+
for (const w of warnings) {
|
|
109
|
+
console.warn(`[mindmatrix-react] ${basename(id)}: ${w.message}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (errors?.length) {
|
|
113
|
+
for (const e of errors) {
|
|
114
|
+
if (mode === "strict") {
|
|
115
|
+
this.error(`${basename(id)}: ${e.message}`);
|
|
116
|
+
} else {
|
|
117
|
+
this.warn(`${basename(id)}: ${e.message}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (ir) {
|
|
122
|
+
compiledFiles.set(id, ir);
|
|
123
|
+
const outputFileName = basename(id).replace(/\.tsx?$/, ".workflow.json");
|
|
124
|
+
const outputPath = join(process.cwd(), outDir, outputFileName);
|
|
125
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
126
|
+
writeFileSync(outputPath, JSON.stringify(ir, null, 2), "utf-8");
|
|
127
|
+
console.log(`[mindmatrix-react] Compiled ${basename(id)} \u2192 ${outputFileName}`);
|
|
128
|
+
seedToApi(ir, id);
|
|
129
|
+
}
|
|
130
|
+
if (!enableSourceAnnotations && ir) {
|
|
131
|
+
stripSourceAnnotations(ir);
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
code: result.code,
|
|
135
|
+
map: wantMaps ? result.map : void 0
|
|
136
|
+
};
|
|
137
|
+
} catch (error) {
|
|
138
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
139
|
+
if (mode === "strict") {
|
|
140
|
+
this.error(`Failed to compile ${basename(id)}: ${msg}`);
|
|
141
|
+
} else {
|
|
142
|
+
console.error(`[mindmatrix-react] Error compiling ${basename(id)}:`, msg);
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
handleHotUpdate(ctx) {
|
|
148
|
+
if (!shouldTransform(ctx.file)) return;
|
|
149
|
+
console.log(`[mindmatrix-react] HMR: ${basename(ctx.file)} changed`);
|
|
150
|
+
return void 0;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function stripSourceAnnotations(ir) {
|
|
155
|
+
const strip = (obj) => {
|
|
156
|
+
if (!obj || typeof obj !== "object") return;
|
|
157
|
+
if (Array.isArray(obj)) {
|
|
158
|
+
for (const item of obj) strip(item);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const rec = obj;
|
|
162
|
+
delete rec.__source;
|
|
163
|
+
for (const val of Object.values(rec)) {
|
|
164
|
+
if (val && typeof val === "object") strip(val);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
strip(ir.fields);
|
|
168
|
+
strip(ir.states);
|
|
169
|
+
strip(ir.transitions);
|
|
170
|
+
strip(ir.experience);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export {
|
|
174
|
+
mindmatrixReact
|
|
175
|
+
};
|
package/dist/cli/index.js
CHANGED
|
@@ -1387,7 +1387,14 @@ function jsxToExperienceNode(node) {
|
|
|
1387
1387
|
}
|
|
1388
1388
|
} else if (t6.isIdentifier(expr)) {
|
|
1389
1389
|
const snakeName = localFieldMap.get(expr.name);
|
|
1390
|
-
|
|
1390
|
+
const setterField = setterToFieldMap.get(expr.name);
|
|
1391
|
+
if (snakeName) {
|
|
1392
|
+
bindings[attrName] = `$local.${snakeName}`;
|
|
1393
|
+
} else if (setterField) {
|
|
1394
|
+
bindings[attrName] = `$action.setLocal("${setterField}")`;
|
|
1395
|
+
} else {
|
|
1396
|
+
bindings[attrName] = `$instance.${expr.name}`;
|
|
1397
|
+
}
|
|
1391
1398
|
} else if (isEventHandlerProp(attrName) && (t6.isArrowFunctionExpression(expr) || t6.isFunctionExpression(expr))) {
|
|
1392
1399
|
const decomposed = decomposeHandlerToSeq(expr);
|
|
1393
1400
|
if (decomposed) {
|
|
@@ -7530,6 +7537,26 @@ function createVisitor(options = {}) {
|
|
|
7530
7537
|
const id = path.node.id;
|
|
7531
7538
|
const init2 = path.node.init;
|
|
7532
7539
|
if (t21.isArrayPattern(id)) return;
|
|
7540
|
+
if (t21.isObjectPattern(id) && init2 && t21.isCallExpression(init2) && t21.isIdentifier(init2.callee) && init2.callee.name === "useQuery") {
|
|
7541
|
+
const slug = resolveSlugArg(init2.arguments, state);
|
|
7542
|
+
if (slug) {
|
|
7543
|
+
for (const prop2 of id.properties) {
|
|
7544
|
+
if (t21.isObjectProperty(prop2) && t21.isIdentifier(prop2.key) && prop2.key.name === "data") {
|
|
7545
|
+
const alias = t21.isIdentifier(prop2.value) ? prop2.value.name : null;
|
|
7546
|
+
if (alias) {
|
|
7547
|
+
const meta = compilerState.metadata;
|
|
7548
|
+
const dataSources = meta.dataSources;
|
|
7549
|
+
if (dataSources) {
|
|
7550
|
+
const ds = dataSources.find((d) => d.name === slug);
|
|
7551
|
+
if (ds) ds.name = alias;
|
|
7552
|
+
}
|
|
7553
|
+
}
|
|
7554
|
+
break;
|
|
7555
|
+
}
|
|
7556
|
+
}
|
|
7557
|
+
}
|
|
7558
|
+
return;
|
|
7559
|
+
}
|
|
7533
7560
|
if (!t21.isIdentifier(id) || !init2 || !t21.isExpression(init2)) return;
|
|
7534
7561
|
const parentFn = path.getFunctionParent();
|
|
7535
7562
|
if (!parentFn) return;
|
|
@@ -7557,10 +7584,7 @@ function createVisitor(options = {}) {
|
|
|
7557
7584
|
return;
|
|
7558
7585
|
}
|
|
7559
7586
|
if (callee === "useMutation") {
|
|
7560
|
-
registerDerivedVar(id.name, t21.
|
|
7561
|
-
t21.identifier("$action"),
|
|
7562
|
-
t21.identifier("transition")
|
|
7563
|
-
));
|
|
7587
|
+
registerDerivedVar(id.name, t21.identifier("$action"));
|
|
7564
7588
|
return;
|
|
7565
7589
|
}
|
|
7566
7590
|
if (callee === "useServerAction") {
|
package/dist/cli/index.mjs
CHANGED
|
@@ -10,9 +10,9 @@ import {
|
|
|
10
10
|
} from "../chunk-XUQ5R6F3.mjs";
|
|
11
11
|
import {
|
|
12
12
|
build
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-RTAUTGHB.mjs";
|
|
14
14
|
import "../chunk-5M7DKKBC.mjs";
|
|
15
|
-
import "../chunk-
|
|
15
|
+
import "../chunk-NJNAQF5I.mjs";
|
|
16
16
|
import {
|
|
17
17
|
__require
|
|
18
18
|
} from "../chunk-CIESM3BP.mjs";
|
|
@@ -45,7 +45,7 @@ async function test(options = {}) {
|
|
|
45
45
|
const rel = f.startsWith(srcDir + "/") ? f.slice(srcDir.length + 1) : f;
|
|
46
46
|
fileMap[rel] = readFileSync(f, "utf-8");
|
|
47
47
|
}
|
|
48
|
-
const { compileProject } = await import("../project-compiler-
|
|
48
|
+
const { compileProject } = await import("../project-compiler-HNDWIX4J.mjs");
|
|
49
49
|
const { decompileProjectEnhanced } = await import("../project-decompiler-QCZYY4TW.mjs");
|
|
50
50
|
process.stdout.write(` Compiling project...`);
|
|
51
51
|
const t0 = performance.now();
|
|
@@ -548,7 +548,7 @@ async function main() {
|
|
|
548
548
|
const { glob: glob2 } = await import("glob");
|
|
549
549
|
const configPath = resolve2(srcDir, "mm.config.ts");
|
|
550
550
|
if (existsSync2(configPath)) {
|
|
551
|
-
const { compileProject } = await import("../project-compiler-
|
|
551
|
+
const { compileProject } = await import("../project-compiler-HNDWIX4J.mjs");
|
|
552
552
|
const allFiles = await glob2(`${srcDir}/**/*.{ts,tsx}`, {
|
|
553
553
|
ignore: ["**/node_modules/**", "**/dist/**", "**/__tests__/**", "**/*.test.*"]
|
|
554
554
|
});
|
|
@@ -624,7 +624,7 @@ async function main() {
|
|
|
624
624
|
console.error("[mmrc] Error: target path is required\n Usage: mmrc verify <file-or-dir> [options]");
|
|
625
625
|
process.exit(1);
|
|
626
626
|
}
|
|
627
|
-
const { verifyCommand } = await import("../verify-
|
|
627
|
+
const { verifyCommand } = await import("../verify-LZXUHOX6.mjs");
|
|
628
628
|
const result = await verifyCommand({
|
|
629
629
|
target,
|
|
630
630
|
static: hasFlag("--static"),
|
package/dist/dev-server.js
CHANGED
|
@@ -1386,7 +1386,14 @@ function jsxToExperienceNode(node) {
|
|
|
1386
1386
|
}
|
|
1387
1387
|
} else if (t6.isIdentifier(expr)) {
|
|
1388
1388
|
const snakeName = localFieldMap.get(expr.name);
|
|
1389
|
-
|
|
1389
|
+
const setterField = setterToFieldMap.get(expr.name);
|
|
1390
|
+
if (snakeName) {
|
|
1391
|
+
bindings[attrName] = `$local.${snakeName}`;
|
|
1392
|
+
} else if (setterField) {
|
|
1393
|
+
bindings[attrName] = `$action.setLocal("${setterField}")`;
|
|
1394
|
+
} else {
|
|
1395
|
+
bindings[attrName] = `$instance.${expr.name}`;
|
|
1396
|
+
}
|
|
1390
1397
|
} else if (isEventHandlerProp(attrName) && (t6.isArrowFunctionExpression(expr) || t6.isFunctionExpression(expr))) {
|
|
1391
1398
|
const decomposed = decomposeHandlerToSeq(expr);
|
|
1392
1399
|
if (decomposed) {
|
|
@@ -7529,6 +7536,26 @@ function createVisitor(options = {}) {
|
|
|
7529
7536
|
const id = path.node.id;
|
|
7530
7537
|
const init = path.node.init;
|
|
7531
7538
|
if (t21.isArrayPattern(id)) return;
|
|
7539
|
+
if (t21.isObjectPattern(id) && init && t21.isCallExpression(init) && t21.isIdentifier(init.callee) && init.callee.name === "useQuery") {
|
|
7540
|
+
const slug = resolveSlugArg(init.arguments, state);
|
|
7541
|
+
if (slug) {
|
|
7542
|
+
for (const prop of id.properties) {
|
|
7543
|
+
if (t21.isObjectProperty(prop) && t21.isIdentifier(prop.key) && prop.key.name === "data") {
|
|
7544
|
+
const alias = t21.isIdentifier(prop.value) ? prop.value.name : null;
|
|
7545
|
+
if (alias) {
|
|
7546
|
+
const meta = compilerState.metadata;
|
|
7547
|
+
const dataSources = meta.dataSources;
|
|
7548
|
+
if (dataSources) {
|
|
7549
|
+
const ds = dataSources.find((d) => d.name === slug);
|
|
7550
|
+
if (ds) ds.name = alias;
|
|
7551
|
+
}
|
|
7552
|
+
}
|
|
7553
|
+
break;
|
|
7554
|
+
}
|
|
7555
|
+
}
|
|
7556
|
+
}
|
|
7557
|
+
return;
|
|
7558
|
+
}
|
|
7532
7559
|
if (!t21.isIdentifier(id) || !init || !t21.isExpression(init)) return;
|
|
7533
7560
|
const parentFn = path.getFunctionParent();
|
|
7534
7561
|
if (!parentFn) return;
|
|
@@ -7556,10 +7583,7 @@ function createVisitor(options = {}) {
|
|
|
7556
7583
|
return;
|
|
7557
7584
|
}
|
|
7558
7585
|
if (callee === "useMutation") {
|
|
7559
|
-
registerDerivedVar(id.name, t21.
|
|
7560
|
-
t21.identifier("$action"),
|
|
7561
|
-
t21.identifier("transition")
|
|
7562
|
-
));
|
|
7586
|
+
registerDerivedVar(id.name, t21.identifier("$action"));
|
|
7563
7587
|
return;
|
|
7564
7588
|
}
|
|
7565
7589
|
if (callee === "useServerAction") {
|
package/dist/dev-server.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createDevServer
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-TRR2NPAV.mjs";
|
|
3
|
+
} from "./chunk-5PM7CGFQ.mjs";
|
|
4
|
+
import "./chunk-RTAUTGHB.mjs";
|
|
6
5
|
import "./chunk-5M7DKKBC.mjs";
|
|
7
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-YOVAADAD.mjs";
|
|
7
|
+
import "./chunk-NJNAQF5I.mjs";
|
|
8
8
|
import "./chunk-CIESM3BP.mjs";
|
|
9
9
|
export {
|
|
10
10
|
createDevServer
|
package/dist/envelope.js
CHANGED
|
@@ -1259,7 +1259,14 @@ function jsxToExperienceNode(node) {
|
|
|
1259
1259
|
}
|
|
1260
1260
|
} else if (t6.isIdentifier(expr)) {
|
|
1261
1261
|
const snakeName = localFieldMap.get(expr.name);
|
|
1262
|
-
|
|
1262
|
+
const setterField = setterToFieldMap.get(expr.name);
|
|
1263
|
+
if (snakeName) {
|
|
1264
|
+
bindings[attrName] = `$local.${snakeName}`;
|
|
1265
|
+
} else if (setterField) {
|
|
1266
|
+
bindings[attrName] = `$action.setLocal("${setterField}")`;
|
|
1267
|
+
} else {
|
|
1268
|
+
bindings[attrName] = `$instance.${expr.name}`;
|
|
1269
|
+
}
|
|
1263
1270
|
} else if (isEventHandlerProp(attrName) && (t6.isArrowFunctionExpression(expr) || t6.isFunctionExpression(expr))) {
|
|
1264
1271
|
const decomposed = decomposeHandlerToSeq(expr);
|
|
1265
1272
|
if (decomposed) {
|
|
@@ -7296,6 +7303,26 @@ function createVisitor(options = {}) {
|
|
|
7296
7303
|
const id = path.node.id;
|
|
7297
7304
|
const init = path.node.init;
|
|
7298
7305
|
if (t21.isArrayPattern(id)) return;
|
|
7306
|
+
if (t21.isObjectPattern(id) && init && t21.isCallExpression(init) && t21.isIdentifier(init.callee) && init.callee.name === "useQuery") {
|
|
7307
|
+
const slug = resolveSlugArg(init.arguments, state);
|
|
7308
|
+
if (slug) {
|
|
7309
|
+
for (const prop of id.properties) {
|
|
7310
|
+
if (t21.isObjectProperty(prop) && t21.isIdentifier(prop.key) && prop.key.name === "data") {
|
|
7311
|
+
const alias = t21.isIdentifier(prop.value) ? prop.value.name : null;
|
|
7312
|
+
if (alias) {
|
|
7313
|
+
const meta = compilerState.metadata;
|
|
7314
|
+
const dataSources = meta.dataSources;
|
|
7315
|
+
if (dataSources) {
|
|
7316
|
+
const ds = dataSources.find((d) => d.name === slug);
|
|
7317
|
+
if (ds) ds.name = alias;
|
|
7318
|
+
}
|
|
7319
|
+
}
|
|
7320
|
+
break;
|
|
7321
|
+
}
|
|
7322
|
+
}
|
|
7323
|
+
}
|
|
7324
|
+
return;
|
|
7325
|
+
}
|
|
7299
7326
|
if (!t21.isIdentifier(id) || !init || !t21.isExpression(init)) return;
|
|
7300
7327
|
const parentFn = path.getFunctionParent();
|
|
7301
7328
|
if (!parentFn) return;
|
|
@@ -7323,10 +7350,7 @@ function createVisitor(options = {}) {
|
|
|
7323
7350
|
return;
|
|
7324
7351
|
}
|
|
7325
7352
|
if (callee === "useMutation") {
|
|
7326
|
-
registerDerivedVar(id.name, t21.
|
|
7327
|
-
t21.identifier("$action"),
|
|
7328
|
-
t21.identifier("transition")
|
|
7329
|
-
));
|
|
7353
|
+
registerDerivedVar(id.name, t21.identifier("$action"));
|
|
7330
7354
|
return;
|
|
7331
7355
|
}
|
|
7332
7356
|
if (callee === "useServerAction") {
|
package/dist/envelope.mjs
CHANGED