@magmonium/cli 0.10.1 → 0.10.3
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/bin/commands/gesture.js +3 -1
- package/bin/commands/validate.js +50 -8
- package/codegen/gesture-catalog.js +108 -3
- package/codegen/index.js +7 -2
- package/codegen/invariant-catalog.js +228 -193
- package/codegen/message-text.json +1 -0
- package/package.json +1 -1
package/bin/commands/gesture.js
CHANGED
|
@@ -48,9 +48,11 @@ async function gesture({ root = process.cwd(), name, args, batch, write = false
|
|
|
48
48
|
if (!read.ok || !read.source) return invalid('design-unreadable', read.refusal);
|
|
49
49
|
const source = read.source;
|
|
50
50
|
|
|
51
|
-
// `function-save` compiles the body the way the function editor does
|
|
51
|
+
// `function-save` compiles the body the way the function editor does, then
|
|
52
|
+
// runs its cases the way Run cases does (0132_01).
|
|
52
53
|
const ts = appTypeScript(root);
|
|
53
54
|
gestures.setFunctionBodyCheck(ts ? gestures.functionBodyCheckFor(ts) : undefined);
|
|
55
|
+
gestures.setFunctionCaseRun(ts ? gestures.functionCaseRunFor(ts) : undefined);
|
|
54
56
|
|
|
55
57
|
const run = gestures.runBatch(source, resolved);
|
|
56
58
|
report.notes = run.notes;
|
package/bin/commands/validate.js
CHANGED
|
@@ -468,6 +468,51 @@ function messageText(key) {
|
|
|
468
468
|
return messageTexts[key] ?? key;
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
+
// The packages whose version a design is stamped with on `--write`, by the
|
|
472
|
+
// `index.json` field that records it.
|
|
473
|
+
const PIN_STAMPS = { codegen: '@magmonium/cli', one: '@magmonium/one' };
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* A package the AppRepo's `package.json` pins below the version the design is
|
|
477
|
+
* stamped with (0132_03): the AppRepo's `gen-code` then refuses the design, or
|
|
478
|
+
* the emitted code compiles against an older `@magmonium/one` than it was
|
|
479
|
+
* written for — `ScreenOverlayTrigger` has no `screen` in 0.4.55. Advisory: the
|
|
480
|
+
* design is sound, the shell around it is behind. Ranges read as their floor.
|
|
481
|
+
*/
|
|
482
|
+
function pinsBehindStamp(packageJson, indexText) {
|
|
483
|
+
let index;
|
|
484
|
+
try {
|
|
485
|
+
index = JSON.parse(indexText || '{}');
|
|
486
|
+
} catch {
|
|
487
|
+
return [];
|
|
488
|
+
}
|
|
489
|
+
const pins = { ...(packageJson?.dependencies || {}), ...(packageJson?.devDependencies || {}) };
|
|
490
|
+
return Object.entries(PIN_STAMPS).flatMap(([field, name]) => {
|
|
491
|
+
const stamp = index[field];
|
|
492
|
+
const pin = typeof pins[name] === 'string' ? pins[name].replace(/^[^\d]*/, '') : '';
|
|
493
|
+
if (!stamp || !pin || !isNewer(stamp, pin)) return [];
|
|
494
|
+
return [
|
|
495
|
+
{
|
|
496
|
+
id: `pins-behind-stamp::${name}`,
|
|
497
|
+
invariant: 'pins-behind-stamp',
|
|
498
|
+
message: 'pins-behind-stamp',
|
|
499
|
+
text: `package.json pins ${name} ${pin}, below the ${stamp} this design is stamped with — run npm install --save-exact ${name}@${stamp}`,
|
|
500
|
+
subject: `${name} ${pin} < ${stamp}`,
|
|
501
|
+
severity: 'advisory',
|
|
502
|
+
target: { kind: 'panel', panel: 'config' },
|
|
503
|
+
},
|
|
504
|
+
];
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function readPackageJson(root) {
|
|
509
|
+
try {
|
|
510
|
+
return JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
511
|
+
} catch {
|
|
512
|
+
return undefined;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
471
516
|
function controlConfigsCatalog() {
|
|
472
517
|
const file = path.join(__dirname, '..', '..', 'codegen', 'control-configs.json');
|
|
473
518
|
return fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : undefined;
|
|
@@ -619,14 +664,10 @@ async function validate({
|
|
|
619
664
|
...source,
|
|
620
665
|
operationOf: codegen.operationResolverOf(operations),
|
|
621
666
|
};
|
|
622
|
-
report.violations =
|
|
623
|
-
bundles,
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
ws.operationOf,
|
|
627
|
-
files,
|
|
628
|
-
ts
|
|
629
|
-
);
|
|
667
|
+
report.violations = [
|
|
668
|
+
...findViolations(bundles, source, catalog, ws.operationOf, files, ts),
|
|
669
|
+
...pinsBehindStamp(readPackageJson(root), files[`${DESIGN_ROOT}/index.json`]),
|
|
670
|
+
];
|
|
630
671
|
|
|
631
672
|
// What the design already held at the baseline is not this change's to fix:
|
|
632
673
|
// marked, listed, and left out of the status.
|
|
@@ -777,4 +818,5 @@ module.exports.themeCatalogOf = themeCatalogOf;
|
|
|
777
818
|
module.exports.appTypeScript = appTypeScript;
|
|
778
819
|
module.exports.readDesignFilesAt = readDesignFilesAt;
|
|
779
820
|
module.exports.messageText = messageText;
|
|
821
|
+
module.exports.pinsBehindStamp = pinsBehindStamp;
|
|
780
822
|
module.exports.DESIGN_ROOT = DESIGN_ROOT;
|
|
@@ -23,10 +23,12 @@ __export(gesture_catalog_exports, {
|
|
|
23
23
|
GESTURES: () => GESTURES,
|
|
24
24
|
applyGesture: () => applyGesture,
|
|
25
25
|
functionBodyCheckFor: () => functionBodyCheckFor,
|
|
26
|
+
functionCaseRunFor: () => functionCaseRunFor,
|
|
26
27
|
gestureByName: () => gestureByName,
|
|
27
28
|
runBatch: () => runBatch,
|
|
28
29
|
runGesture: () => runGesture,
|
|
29
|
-
setFunctionBodyCheck: () => setFunctionBodyCheck
|
|
30
|
+
setFunctionBodyCheck: () => setFunctionBodyCheck,
|
|
31
|
+
setFunctionCaseRun: () => setFunctionCaseRun
|
|
30
32
|
});
|
|
31
33
|
module.exports = __toCommonJS(gesture_catalog_exports);
|
|
32
34
|
|
|
@@ -1481,6 +1483,12 @@ function planFunctionReplace(homes, fromId, toId, holders) {
|
|
|
1481
1483
|
return { rebind, homes: { functions, features } };
|
|
1482
1484
|
}
|
|
1483
1485
|
var bodyCheck;
|
|
1486
|
+
var caseRun;
|
|
1487
|
+
var setFunctionCaseRun = (run) => {
|
|
1488
|
+
const previous = caseRun;
|
|
1489
|
+
caseRun = run;
|
|
1490
|
+
return previous;
|
|
1491
|
+
};
|
|
1484
1492
|
var setFunctionBodyCheck = (check) => {
|
|
1485
1493
|
const previous = bodyCheck;
|
|
1486
1494
|
bodyCheck = check;
|
|
@@ -1520,6 +1528,18 @@ var functionSave = {
|
|
|
1520
1528
|
if (clash) return refuse4(clash);
|
|
1521
1529
|
const problems = bodyCheck?.(ctx.source, fn, home);
|
|
1522
1530
|
if (problems?.length) return refuse4("function-body-invalid", { problems });
|
|
1531
|
+
const results = caseRun?.(ctx.source, fn, home) ?? [];
|
|
1532
|
+
const failedAt = results.findIndex((result) => !result.passed);
|
|
1533
|
+
if (failedAt >= 0) {
|
|
1534
|
+
const failed = results[failedAt];
|
|
1535
|
+
const entry = (fn.cases ?? [])[failedAt];
|
|
1536
|
+
return refuse4("case-failed", {
|
|
1537
|
+
case: entry.name,
|
|
1538
|
+
args: entry.args,
|
|
1539
|
+
expected: entry.expected,
|
|
1540
|
+
...failed.ok ? { actual: failed.actual } : { error: failed.error }
|
|
1541
|
+
});
|
|
1542
|
+
}
|
|
1523
1543
|
const moved = landing.nowFeature ? landing.wasApp : landing.wasFeature;
|
|
1524
1544
|
const next = savedFunctionHomes(homes, fn, landing);
|
|
1525
1545
|
return {
|
|
@@ -2253,6 +2273,10 @@ function purity(ts, file, prependLines, bodyStart, bodyLineOffset) {
|
|
|
2253
2273
|
return found;
|
|
2254
2274
|
}
|
|
2255
2275
|
var functionBodyCheckFor = (ts) => (source, fn, featureId) => {
|
|
2276
|
+
const scope = functionScopeOf(source, featureId);
|
|
2277
|
+
return checkFunctionBody(ts, scope.shapes, fn, scope.allowlist, scope.enums);
|
|
2278
|
+
};
|
|
2279
|
+
var functionScopeOf = (source, featureId) => {
|
|
2256
2280
|
const shapes = { ...source.sharedShapes };
|
|
2257
2281
|
Object.values(source.features).forEach((feature) => Object.assign(shapes, feature.shapes));
|
|
2258
2282
|
source.screens.forEach(({ state }) => Object.assign(shapes, (0, import_codegen15.formShapeMap)(state.controlMap)));
|
|
@@ -2265,7 +2289,86 @@ var functionBodyCheckFor = (ts) => (source, fn, featureId) => {
|
|
|
2265
2289
|
);
|
|
2266
2290
|
return found.some((entry) => entry.library) ? found : [...found, import_codegen15.SORT_DIRECTION_ENUM];
|
|
2267
2291
|
})() : [import_codegen15.SORT_DIRECTION_ENUM];
|
|
2268
|
-
return
|
|
2292
|
+
return { shapes, allowlist: source.npmAllowlist ?? {}, enums };
|
|
2293
|
+
};
|
|
2294
|
+
|
|
2295
|
+
// apps/m-one-ui/src/app/pages/design/lib/function-case-runner.ts
|
|
2296
|
+
var import_codegen16 = require("./index.js");
|
|
2297
|
+
function transpileFunction(ts, shapes, fn, cases, enums) {
|
|
2298
|
+
const named = fn.name.trim() ? fn : { ...fn, name: "name" };
|
|
2299
|
+
const shapeSource = ambientTypes(shapes, named, enums);
|
|
2300
|
+
const caseSource = cases.map((entry) => `[[${entry.args.join(", ")}], ${entry.expected}]`).join(",\n");
|
|
2301
|
+
const source = `${shapeSource}${(0, import_codegen16.signatureText)(shapes, named, enums)}
|
|
2302
|
+
${fn.body}
|
|
2303
|
+
};
|
|
2304
|
+
`.replace(
|
|
2305
|
+
/^export\s+/gm,
|
|
2306
|
+
""
|
|
2307
|
+
);
|
|
2308
|
+
const { outputText, diagnostics } = ts.transpileModule(
|
|
2309
|
+
`${source}const __cases: unknown = [
|
|
2310
|
+
${caseSource}
|
|
2311
|
+
];
|
|
2312
|
+
`,
|
|
2313
|
+
{
|
|
2314
|
+
compilerOptions: {
|
|
2315
|
+
target: ts.ScriptTarget.ES2020,
|
|
2316
|
+
// TS 6.0 reports `module: None` as a deprecation diagnostic; this
|
|
2317
|
+
// runner treats Error-category diagnostics as fatal, so the
|
|
2318
|
+
// deprecation has to be acknowledged explicitly.
|
|
2319
|
+
ignoreDeprecations: "6.0",
|
|
2320
|
+
module: ts.ModuleKind.None,
|
|
2321
|
+
strict: true
|
|
2322
|
+
},
|
|
2323
|
+
reportDiagnostics: true
|
|
2324
|
+
}
|
|
2325
|
+
);
|
|
2326
|
+
const fatal = (diagnostics ?? []).filter(
|
|
2327
|
+
(d) => d.category === ts.DiagnosticCategory.Error
|
|
2328
|
+
);
|
|
2329
|
+
if (fatal.length) {
|
|
2330
|
+
return {
|
|
2331
|
+
values: [],
|
|
2332
|
+
error: fatal.map((d) => ts.flattenDiagnosticMessageText(d.messageText, " ")).join("\n")
|
|
2333
|
+
};
|
|
2334
|
+
}
|
|
2335
|
+
try {
|
|
2336
|
+
const [impl, values] = new Function(
|
|
2337
|
+
`${outputText}
|
|
2338
|
+
return [${named.name}, __cases];`
|
|
2339
|
+
)();
|
|
2340
|
+
return { impl, values };
|
|
2341
|
+
} catch (error) {
|
|
2342
|
+
return {
|
|
2343
|
+
values: [],
|
|
2344
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
var errorText = (error) => error instanceof Error ? error.message : String(error);
|
|
2349
|
+
var functionCaseRunFor = (ts) => (source, fn, featureId) => {
|
|
2350
|
+
const cases = fn.cases ?? [];
|
|
2351
|
+
if (!cases.length) return [];
|
|
2352
|
+
const scope = functionScopeOf(source, featureId);
|
|
2353
|
+
const runnable = cases.filter((entry) => (0, import_codegen16.caseFits)(fn, entry, scope.shapes));
|
|
2354
|
+
const compiled = transpileFunction(ts, scope.shapes, fn, runnable, scope.enums);
|
|
2355
|
+
const impl = compiled.impl;
|
|
2356
|
+
if (!impl)
|
|
2357
|
+
return cases.map(() => ({ ok: false, passed: false, error: compiled.error ?? "" }));
|
|
2358
|
+
let next = 0;
|
|
2359
|
+
return cases.map((entry) => {
|
|
2360
|
+
if (!(0, import_codegen16.caseFits)(fn, entry, scope.shapes))
|
|
2361
|
+
return { ok: false, passed: false, error: "The case no longer fits the signature." };
|
|
2362
|
+
const [args, expected] = compiled.values[next++];
|
|
2363
|
+
try {
|
|
2364
|
+
const actual = impl(...args);
|
|
2365
|
+
if (actual instanceof Promise)
|
|
2366
|
+
return { ok: false, passed: false, error: "The body answered a Promise." };
|
|
2367
|
+
return { ok: true, passed: (0, import_codegen16.caseEquals)(actual, expected), actual };
|
|
2368
|
+
} catch (error) {
|
|
2369
|
+
return { ok: false, passed: false, error: errorText(error) };
|
|
2370
|
+
}
|
|
2371
|
+
});
|
|
2269
2372
|
};
|
|
2270
2373
|
|
|
2271
2374
|
// apps/m-one-ui/src/app/pages/design/lib/gesture-catalog.ts
|
|
@@ -2324,8 +2427,10 @@ var runBatch = (source, steps) => {
|
|
|
2324
2427
|
GESTURES,
|
|
2325
2428
|
applyGesture,
|
|
2326
2429
|
functionBodyCheckFor,
|
|
2430
|
+
functionCaseRunFor,
|
|
2327
2431
|
gestureByName,
|
|
2328
2432
|
runBatch,
|
|
2329
2433
|
runGesture,
|
|
2330
|
-
setFunctionBodyCheck
|
|
2434
|
+
setFunctionBodyCheck,
|
|
2435
|
+
setFunctionCaseRun
|
|
2331
2436
|
});
|
package/codegen/index.js
CHANGED
|
@@ -24433,7 +24433,10 @@ function renderPluginTag(node, pad2, tag, methods, operationOf, storeProp, ctx)
|
|
|
24433
24433
|
OUTPUT_ATTR
|
|
24434
24434
|
)
|
|
24435
24435
|
].map(
|
|
24436
|
-
([, name3, handler]) => `${inner}<m-plugin-output name="${name3}" (fired)="${handler
|
|
24436
|
+
([, name3, handler]) => `${inner}<m-plugin-output name="${name3}" (fired)="${handler.replace(
|
|
24437
|
+
/\$event\b/g,
|
|
24438
|
+
"$any($event)"
|
|
24439
|
+
)}" />`
|
|
24437
24440
|
);
|
|
24438
24441
|
if (inputs.length) ctx.writtenTags.add("m-plugin-input");
|
|
24439
24442
|
if (outputs.length) ctx.writtenTags.add("m-plugin-output");
|
|
@@ -29007,7 +29010,7 @@ __export(package_exports2, {
|
|
|
29007
29010
|
version: () => version2
|
|
29008
29011
|
});
|
|
29009
29012
|
var name2 = "@magmonium/cli";
|
|
29010
|
-
var version2 = "0.10.
|
|
29013
|
+
var version2 = "0.10.3";
|
|
29011
29014
|
var description2 = "A powerful and extensible asset compilation tool that can be shared across multiple projects";
|
|
29012
29015
|
var bin = {
|
|
29013
29016
|
"mag-cli": "bin/cli.js"
|
|
@@ -35540,6 +35543,8 @@ coverage/
|
|
|
35540
35543
|
# Compiled from mag_assets by \`npm run assets:compile\` \u2014 never hand-edited,
|
|
35541
35544
|
# and never committed.
|
|
35542
35545
|
public/assets/
|
|
35546
|
+
# The web-component build's cache, written by \`npm run build\`.
|
|
35547
|
+
.mag-cache/
|
|
35543
35548
|
|
|
35544
35549
|
# The GeneratedSet: regenerated from the design source by \`npm run gen:code\`
|
|
35545
35550
|
# on every start, build and test, never committed (ADR 0181).
|