@dialecte/cli 0.0.2 → 0.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 +1 -1
- package/dist/cli.js +35 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ npm i -D @dialecte/cli # provides the `dialecte` binary
|
|
|
19
19
|
|
|
20
20
|
```
|
|
21
21
|
dialecte coverage # generate complete, schema-driven type-coverage probes
|
|
22
|
-
dialecte bench [--check] # measure type-instantiation cost (
|
|
22
|
+
dialecte bench [--check] # measure the type-instantiation cost of your own types (library .d.ts skipped); --check gates CI
|
|
23
23
|
dialecte audit # render the public type surface and flag readability issues (C1–C6)
|
|
24
24
|
dialecte --help
|
|
25
25
|
```
|
package/dist/cli.js
CHANGED
|
@@ -358,6 +358,26 @@ var METRICS = [
|
|
|
358
358
|
];
|
|
359
359
|
var STABLE_METRICS = ["Instantiations", "Types", "Symbols"];
|
|
360
360
|
var THRESHOLD = 0.05;
|
|
361
|
+
function isolatedTsconfig(params) {
|
|
362
|
+
const { tsconfig, file } = params;
|
|
363
|
+
return {
|
|
364
|
+
extends: `./${tsconfig}`,
|
|
365
|
+
compilerOptions: {
|
|
366
|
+
noEmit: true,
|
|
367
|
+
skipLibCheck: true,
|
|
368
|
+
rootDir: ".",
|
|
369
|
+
declaration: false,
|
|
370
|
+
declarationMap: false,
|
|
371
|
+
emitDeclarationOnly: false
|
|
372
|
+
},
|
|
373
|
+
include: [file]
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function wholeProgramArgs(params) {
|
|
377
|
+
const { tsconfig, mode } = params;
|
|
378
|
+
const output = mode === "check" ? ["--noEmit"] : ["--emitDeclarationOnly", "--outDir", ".bench-dts"];
|
|
379
|
+
return ["-p", tsconfig, ...output, "--skipLibCheck", "--extendedDiagnostics"];
|
|
380
|
+
}
|
|
361
381
|
function parseTscMetrics(output) {
|
|
362
382
|
const m = {};
|
|
363
383
|
for (const metric of METRICS) {
|
|
@@ -411,20 +431,7 @@ async function run2(argv) {
|
|
|
411
431
|
const measure = (args) => aggregateRuns(Array.from({ length: RUNS }, () => runTsc(args)));
|
|
412
432
|
const isolated = (file) => {
|
|
413
433
|
const name = `.bench-${file.replace(/[/.]/g, "_")}.tsconfig.json`;
|
|
414
|
-
writeFileSync2(
|
|
415
|
-
join4(ROOT, name),
|
|
416
|
-
JSON.stringify({
|
|
417
|
-
extends: `./${tsconfig}`,
|
|
418
|
-
compilerOptions: {
|
|
419
|
-
noEmit: true,
|
|
420
|
-
rootDir: ".",
|
|
421
|
-
declaration: false,
|
|
422
|
-
declarationMap: false,
|
|
423
|
-
emitDeclarationOnly: false
|
|
424
|
-
},
|
|
425
|
-
include: [file]
|
|
426
|
-
})
|
|
427
|
-
);
|
|
434
|
+
writeFileSync2(join4(ROOT, name), JSON.stringify(isolatedTsconfig({ tsconfig, file })));
|
|
428
435
|
return name;
|
|
429
436
|
};
|
|
430
437
|
const measureFile = (file) => {
|
|
@@ -436,15 +443,8 @@ async function run2(argv) {
|
|
|
436
443
|
const col = (s, w) => String(s).padEnd(w);
|
|
437
444
|
const num = (n) => n == null ? "\u2014" : Math.round(n).toLocaleString("en-US");
|
|
438
445
|
console.log(`bench \u2014 ${RUNS} runs (min) \u2014 whole program \u2026`);
|
|
439
|
-
const wholeCheck = measure(
|
|
440
|
-
const wholeEmit = measure(
|
|
441
|
-
"-p",
|
|
442
|
-
tsconfig,
|
|
443
|
-
"--emitDeclarationOnly",
|
|
444
|
-
"--outDir",
|
|
445
|
-
".bench-dts",
|
|
446
|
-
"--extendedDiagnostics"
|
|
447
|
-
]);
|
|
446
|
+
const wholeCheck = measure(wholeProgramArgs({ tsconfig, mode: "check" }));
|
|
447
|
+
const wholeEmit = measure(wholeProgramArgs({ tsconfig, mode: "emit" }));
|
|
448
448
|
rmSync2(join4(ROOT, ".bench-dts"), { recursive: true, force: true });
|
|
449
449
|
let failed = false;
|
|
450
450
|
for (const t of targets) {
|
|
@@ -610,9 +610,20 @@ function refsOf(b) {
|
|
|
610
610
|
}
|
|
611
611
|
var attrValue = (d) => {
|
|
612
612
|
if (d?.fixed) return d.fixed;
|
|
613
|
-
const enums = d?.
|
|
613
|
+
const enums = enumerated(d?.type)?.filter((v) => v !== "");
|
|
614
614
|
return enums?.length ? enums[0] : "x";
|
|
615
615
|
};
|
|
616
|
+
function enumerated(datatype) {
|
|
617
|
+
if (datatype === void 0 || holdsQualifiedNames(datatype)) return void 0;
|
|
618
|
+
if (datatype.facets?.enumeration !== void 0) return datatype.facets.enumeration;
|
|
619
|
+
const members = (datatype.union ?? []).flatMap((member) => enumerated(member) ?? []);
|
|
620
|
+
return members.length > 0 ? [...new Set(members)] : void 0;
|
|
621
|
+
}
|
|
622
|
+
function holdsQualifiedNames(datatype) {
|
|
623
|
+
if (datatype.builtin === "QName" || datatype.builtin === "NOTATION") return true;
|
|
624
|
+
if (datatype.list !== void 0) return holdsQualifiedNames(datatype.list);
|
|
625
|
+
return (datatype.union ?? []).some(holdsQualifiedNames);
|
|
626
|
+
}
|
|
616
627
|
function genSurface(b) {
|
|
617
628
|
const r = refsOf(b);
|
|
618
629
|
const lines = [
|