@akanjs/cli 3.1.2-rc.4 → 3.2.0-rc.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/.build-stamp +1 -1
- package/{CodeAgent-z34p8m91.js → CodeAgent-vmd9k4ak.js} +3 -3
- package/{CodeTui-nvd9fk3g.js → CodeTui-zka44v52.js} +1 -1
- package/README.ko.md +9 -0
- package/README.md +9 -0
- package/TunnelShare-k3ja4w9x.js +14 -0
- package/{agent.command-962mp3kg.js → agent.command-2f657613.js} +19 -17
- package/akanCode.js +6 -6
- package/{application.command-1nr0bqq1.js → application.command-q6skd3am.js} +36 -22
- package/{applicationBuildRunner-xy7hnfzq.js → applicationBuildRunner-sctcmkyx.js} +55 -16
- package/buildBatch.proc.js +7 -7
- package/{cloud.command-cj7b3m6y.js → cloud.command-7642pks6.js} +36 -19
- package/cloud.script-1sfseznn.js +30 -0
- package/{code.command-asq7xrr6.js → code.command-7s4ndq2k.js} +6 -6
- package/commandManifest.json +1 -1
- package/{context.command-fw4g2pw1.js → context.command-569z0rqf.js} +20 -19
- package/context.runner-ms8v1rxy.js +29 -0
- package/{devTui-evr3b35y.js → devTui-w38ch13a.js} +1 -1
- package/{guideline.command-43gfjsjv.js → guideline.command-gnv3e8p8.js} +2 -2
- package/guidelines/akanApi/akanApi.instruction.md +317 -0
- package/guidelines/conventions/rules/app.md +5 -5
- package/guidelines/conventions/rules/config.md +1 -1
- package/guidelines/conventions/rules/gates.md +10 -5
- package/incrementalBuilder.proc.js +69 -39
- package/{index-0tkj05cz.js → index-0fb3cpbt.js} +3 -3
- package/{index-6t7fkx73.js → index-1q1cjn8s.js} +21 -11
- package/{index-tenw3mah.js → index-23860fej.js} +16 -6
- package/{index-6zgt7zmx.js → index-48d5qsj3.js} +4 -4
- package/{index-z47rw9ez.js → index-5w9my9qe.js} +8 -8
- package/{index-qwe079ww.js → index-6wpaq392.js} +61 -15
- package/{index-kc871vpc.js → index-7xdpww43.js} +69 -12
- package/index-7y5yghjg.js +2969 -0
- package/{index-38patcx6.js → index-8g7tdsk4.js} +249 -696
- package/{index-90q0w90q.js → index-8kczhnmv.js} +1 -1
- package/{index-kdswbvys.js → index-8pb9yvp8.js} +63 -21
- package/{index-hmj94es2.js → index-8ts9774g.js} +4 -4
- package/{index-r0q2ka2b.js → index-93ewzmp6.js} +43 -14
- package/{index-y0y0pnx8.js → index-9tbgb4d8.js} +1 -1
- package/{index-jzpeny42.js → index-a8a9ede9.js} +7 -7
- package/index-abgh0jve.js +126 -0
- package/{index-t0hk1kxq.js → index-aj3ehkcx.js} +1 -1
- package/{index-demt944k.js → index-d4n1wmrz.js} +37 -4
- package/{index-sra1a5f8.js → index-drz9e84d.js} +22 -8
- package/{index-gfh90r3t.js → index-e3vmjtph.js} +2 -2
- package/{index-k64mhwbw.js → index-eajbmk10.js} +2 -1
- package/{index-g0yds382.js → index-ed6ea0qp.js} +1 -1
- package/{index-ap6ac70m.js → index-fjr4d6yd.js} +444 -368
- package/index-hqrkqxx2.js +176 -0
- package/{index-ampz4vgv.js → index-kpdv34rq.js} +4 -4
- package/{index-kc6ffq0s.js → index-ktb3wcqz.js} +73 -34
- package/{index-dcm66hss.js → index-mmym5xmb.js} +4 -2
- package/{index-8d9r465x.js → index-mqntfzv5.js} +2 -2
- package/{index-4am4dvmf.js → index-ny2k80mv.js} +15 -3
- package/index-p6hjwt2d.js +1668 -0
- package/{index-53h0053j.js → index-rc5fvqj2.js} +12 -14
- package/{index-jzz6ye8x.js → index-s2grpzef.js} +40 -8
- package/{index-38by07nw.js → index-sr5da35e.js} +32 -9
- package/{index-qev8p5wp.js → index-sy481q2x.js} +1 -1
- package/{index-ck64kxrn.js → index-thckcabc.js} +2 -2
- package/{index-2yan1ajk.js → index-v4p1zye8.js} +18 -9
- package/{index-wymcdsas.js → index-vkzfk7qt.js} +25 -23
- package/{index-r8t5sq7z.js → index-vr68mxj5.js} +68 -21
- package/{index-vkpqe29t.js → index-w639tvkd.js} +24 -125
- package/index-ygdbn9jn.js +122 -0
- package/{index-w60zxxye.js → index-zpv14wpy.js} +3 -3
- package/index.js +24 -23
- package/{library.command-zh29tjdd.js → library.command-1gp5qe3r.js} +3 -3
- package/{localRegistry.command-k9pn9ahj.js → localRegistry.command-x7jptkd3.js} +26 -17
- package/{module.command-dgpqs9fz.js → module.command-4xz9he6h.js} +6 -6
- package/{package.command-1je4hsca.js → package.command-s7qpnn1g.js} +12 -3
- package/package.json +2 -2
- package/{page.command-cgsasanh.js → page.command-fan34c49.js} +3 -3
- package/{pipeline.command-tb46sa8v.js → pipeline.command-ph4fnn9w.js} +2 -2
- package/{primitive.command-bzsy23x5.js → primitive.command-3fqh8emf.js} +7 -7
- package/{projectTypecheck-h8rgaczy.js → projectTypecheck-vkb40hjc.js} +1 -1
- package/{quality.command-120m9h6v.js → quality.command-ecj6exsh.js} +15 -10
- package/{repair.command-6m4wd0qv.js → repair.command-fe9jw719.js} +6 -6
- package/{scalar.command-3dn5hsc6.js → scalar.command-cnvfhk0n.js} +5 -5
- package/skills/akan-debug/SKILL.md +2 -1
- package/skills/akan-page/SKILL.md +16 -7
- package/skills/akan-service/SKILL.md +48 -19
- package/{subspace.command-s8nyfqbn.js → subspace.command-qw5ddd6y.js} +8 -8
- package/templates/app/lib/___appName__/__appName__.abstract.md.template +6 -0
- package/templates/app/page/_index.tsx +4 -284
- package/templates/app/page/_layout.tsx +1 -26
- package/templates/app/page/styles.css.template +58 -318
- package/templates/appSample/page/_index.tsx +281 -0
- package/templates/appSample/page/_layout.tsx +55 -0
- package/templates/appSample/page/styles.css.template +327 -0
- package/templates/libRoot/lib/___libName__/__libName__.abstract.md.template +6 -0
- package/templates/workspaceRoot/package.json.template +1 -12
- package/{tunnel.command-8mwrqkr3.js → tunnel.command-ggj38mqf.js} +7 -7
- package/{verify.command-2pspfy7k.js → verify.command-w9ttxkdz.js} +16 -14
- package/{workflow.command-7sy5vnsj.js → workflow.command-ss8devj0.js} +12 -12
- package/{workspace.command-x518tdv4.js → workspace.command-6z2rh8ze.js} +51 -39
- package/TunnelShare-jwbb50kz.js +0 -14
- package/cloud.script-8kr7qgfa.js +0 -27
- package/context.runner-p6m5cxk3.js +0 -28
- package/index-d894868w.js +0 -842
- package/index-re2kfscb.js +0 -1363
- /package/templates/{app → appSample}/page/_overrides.tsx +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-Black.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-Bold.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-ExtraBold.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-ExtraLight.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-Light.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-Medium.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-Regular.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-SemiBold.woff2 +0 -0
- /package/templates/{app → appSample}/public/fonts/Pretendard-Thin.woff2 +0 -0
- /package/templates/{app → appSample}/public/jelly/cloud.webp +0 -0
- /package/templates/{app → appSample}/public/jelly/comet.webp +0 -0
- /package/templates/{app → appSample}/public/jelly/moon.webp +0 -0
- /package/templates/{app → appSample}/public/jelly/planet.webp +0 -0
- /package/templates/{app → appSample}/public/jelly/rocket.webp +0 -0
- /package/templates/{app → appSample}/public/jelly/star.webp +0 -0
- /package/templates/{app → appSample}/public/jelly/sugar.webp +0 -0
- /package/templates/{app → appSample}/public/logo.png +0 -0
- /package/templates/{app → appSample}/ui/Recipe/index.ts +0 -0
- /package/templates/{app → appSample}/ui/Recipe/jellyButton.ts +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
camelToKebabCase,
|
|
4
4
|
runner
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-93ewzmp6.js";
|
|
6
6
|
import {
|
|
7
7
|
FileSys2
|
|
8
8
|
} from "./index-bns3wcpc.js";
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
extractAgentBlock,
|
|
11
11
|
collectScopeRecipeSources,
|
|
12
12
|
renderScopeAgentBlock,
|
|
13
|
-
JsonFormatter,
|
|
14
13
|
Linter,
|
|
15
14
|
rootAllowedFiles,
|
|
16
15
|
rootAllowedDirs,
|
|
@@ -20,17 +19,24 @@ import {
|
|
|
20
19
|
rootEntryHintOf,
|
|
21
20
|
WorkspaceExecutor,
|
|
22
21
|
SysExecutor,
|
|
23
|
-
LibExecutor
|
|
24
|
-
|
|
22
|
+
LibExecutor,
|
|
23
|
+
PkgExecutor
|
|
24
|
+
} from "./index-sr5da35e.js";
|
|
25
25
|
import {
|
|
26
26
|
countBlocking,
|
|
27
27
|
formatStyleContract,
|
|
28
28
|
ThemeValidator
|
|
29
29
|
} from "./index-62md4dwy.js";
|
|
30
30
|
import {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
GitRevision
|
|
32
|
+
} from "./index-ygdbn9jn.js";
|
|
33
|
+
import {
|
|
34
|
+
MaintainabilityBaseline
|
|
35
|
+
} from "./index-hqrkqxx2.js";
|
|
36
|
+
import {
|
|
37
|
+
createFactReader,
|
|
38
|
+
createAst
|
|
39
|
+
} from "./index-7y5yghjg.js";
|
|
34
40
|
import {
|
|
35
41
|
collectRecipeSources2,
|
|
36
42
|
scanRecipes2
|
|
@@ -38,11 +44,11 @@ import {
|
|
|
38
44
|
import {
|
|
39
45
|
getNpmRegistryUrl,
|
|
40
46
|
getLatestPackageVersion
|
|
41
|
-
} from "./index-
|
|
47
|
+
} from "./index-ny2k80mv.js";
|
|
42
48
|
import {
|
|
43
49
|
sysInputs,
|
|
44
50
|
workflowSpecs
|
|
45
|
-
} from "./index-
|
|
51
|
+
} from "./index-eajbmk10.js";
|
|
46
52
|
|
|
47
53
|
// pkgs/@akanjs/cli/workspace/workspace.runner.ts
|
|
48
54
|
import { mkdir, writeFile as writeFile2 } from "fs/promises";
|
|
@@ -56,7 +62,7 @@ var biomeVersion = "2.5.14";
|
|
|
56
62
|
import { existsSync } from "fs";
|
|
57
63
|
import { readFile, rm, writeFile } from "fs/promises";
|
|
58
64
|
import path4 from "path";
|
|
59
|
-
import
|
|
65
|
+
import ts12 from "typescript";
|
|
60
66
|
|
|
61
67
|
// pkgs/@akanjs/devkit/componentSizeScanner.ts
|
|
62
68
|
import ts from "typescript";
|
|
@@ -444,170 +450,6 @@ class EndpointReach {
|
|
|
444
450
|
}
|
|
445
451
|
}
|
|
446
452
|
|
|
447
|
-
// pkgs/@akanjs/devkit/maintainabilityBaseline.ts
|
|
448
|
-
class MaintainabilityBaseline {
|
|
449
|
-
sections;
|
|
450
|
-
reasons;
|
|
451
|
-
static fileName = "akan.baseline.json";
|
|
452
|
-
static reasonMinChars = 10;
|
|
453
|
-
static debtRules = [
|
|
454
|
-
"akan.size.file",
|
|
455
|
-
"akan.size.component",
|
|
456
|
-
"akan.component.store-access",
|
|
457
|
-
"akan.store.multi-write",
|
|
458
|
-
"akan.store.root-write-chain",
|
|
459
|
-
"akan.component.write-chain",
|
|
460
|
-
"akan.write.placement",
|
|
461
|
-
"akan.service.call-in-loop"
|
|
462
|
-
];
|
|
463
|
-
static reasonedRules = new Set([
|
|
464
|
-
"akan.size.file",
|
|
465
|
-
"akan.size.component",
|
|
466
|
-
"akan.component.store-access",
|
|
467
|
-
"akan.service.call-in-loop"
|
|
468
|
-
]);
|
|
469
|
-
static countOf(violation) {
|
|
470
|
-
if (violation.kind === "size")
|
|
471
|
-
return violation.lineCount;
|
|
472
|
-
if (violation.kind === "storeAccess")
|
|
473
|
-
return violation.accessCount;
|
|
474
|
-
if (violation.kind === "multiWrite")
|
|
475
|
-
return violation.writeCount;
|
|
476
|
-
if (violation.kind === "writePlacement")
|
|
477
|
-
return violation.writes.length;
|
|
478
|
-
return violation.calls.length;
|
|
479
|
-
}
|
|
480
|
-
static isDebtRule(name) {
|
|
481
|
-
return MaintainabilityBaseline.debtRules.includes(name);
|
|
482
|
-
}
|
|
483
|
-
static parse(text, source = MaintainabilityBaseline.fileName, { lenient = false } = {}) {
|
|
484
|
-
let json;
|
|
485
|
-
try {
|
|
486
|
-
json = JSON.parse(text);
|
|
487
|
-
} catch {
|
|
488
|
-
throw new Error(`${source} is not valid JSON.`);
|
|
489
|
-
}
|
|
490
|
-
if (typeof json !== "object" || json === null || Array.isArray(json))
|
|
491
|
-
throw new Error(`${source} holds an object keyed by rule id.`);
|
|
492
|
-
const sections = new Map;
|
|
493
|
-
let reasons = new Map;
|
|
494
|
-
for (const [name, value] of Object.entries(json)) {
|
|
495
|
-
if (name === "reasons") {
|
|
496
|
-
const entries = MaintainabilityBaseline.#reasonsOf(value);
|
|
497
|
-
if (!entries)
|
|
498
|
-
throw new Error(`${source}: "reasons" maps an entry's key to a sentence.`);
|
|
499
|
-
reasons = new Map(entries);
|
|
500
|
-
continue;
|
|
501
|
-
}
|
|
502
|
-
if (!MaintainabilityBaseline.isDebtRule(name)) {
|
|
503
|
-
if (lenient)
|
|
504
|
-
continue;
|
|
505
|
-
throw new Error(`${source}: "${name}" is not a rule id. Its sections are ${MaintainabilityBaseline.debtRules.join(", ")} and "reasons"; rewrite it with \`akan quality baseline --force\`.`);
|
|
506
|
-
}
|
|
507
|
-
const counts = MaintainabilityBaseline.#countsOf(value);
|
|
508
|
-
if (!counts)
|
|
509
|
-
throw new Error(`${source}: "${name}" maps each key to a whole-number count.`);
|
|
510
|
-
sections.set(name, new Map(counts));
|
|
511
|
-
}
|
|
512
|
-
return new MaintainabilityBaseline(sections, reasons);
|
|
513
|
-
}
|
|
514
|
-
static of(violations, reasons = new Map) {
|
|
515
|
-
const sections = new Map;
|
|
516
|
-
for (const violation of violations) {
|
|
517
|
-
const counts = sections.get(violation.rule) ?? new Map;
|
|
518
|
-
const count = MaintainabilityBaseline.countOf(violation);
|
|
519
|
-
counts.set(violation.key, Math.max(counts.get(violation.key) ?? 0, count));
|
|
520
|
-
sections.set(violation.rule, counts);
|
|
521
|
-
}
|
|
522
|
-
return new MaintainabilityBaseline(sections).#withReasonsOf(reasons);
|
|
523
|
-
}
|
|
524
|
-
constructor(sections = new Map, reasons = new Map) {
|
|
525
|
-
this.sections = sections;
|
|
526
|
-
this.reasons = reasons;
|
|
527
|
-
}
|
|
528
|
-
get isEmpty() {
|
|
529
|
-
return [...this.sections.values()].every((counts) => !counts.size);
|
|
530
|
-
}
|
|
531
|
-
allows(violation) {
|
|
532
|
-
const recorded = this.recordedOf(violation);
|
|
533
|
-
return recorded !== undefined && MaintainabilityBaseline.countOf(violation) <= recorded;
|
|
534
|
-
}
|
|
535
|
-
recordedOf(violation) {
|
|
536
|
-
return this.sections.get(violation.rule)?.get(violation.key);
|
|
537
|
-
}
|
|
538
|
-
reasonOf(key) {
|
|
539
|
-
const reason = this.#holdsReasoned(key) ? this.reasons.get(key) : undefined;
|
|
540
|
-
return reason && reason.replace(/\s/g, "").length >= MaintainabilityBaseline.reasonMinChars ? reason : undefined;
|
|
541
|
-
}
|
|
542
|
-
entriesByRule() {
|
|
543
|
-
return new Map([...this.sections].filter(([, counts]) => counts.size).map(([rule, counts]) => [
|
|
544
|
-
rule,
|
|
545
|
-
[...counts].map(([key, count]) => ({
|
|
546
|
-
key,
|
|
547
|
-
count,
|
|
548
|
-
reason: MaintainabilityBaseline.reasonedRules.has(rule) ? this.reasonOf(key) : undefined
|
|
549
|
-
}))
|
|
550
|
-
]));
|
|
551
|
-
}
|
|
552
|
-
tightenedBy(violations) {
|
|
553
|
-
const current = MaintainabilityBaseline.of(violations);
|
|
554
|
-
const sections = new Map([...this.sections].map(([rule, counts]) => [
|
|
555
|
-
rule,
|
|
556
|
-
MaintainabilityBaseline.#lowered(counts, current.sections.get(rule) ?? new Map)
|
|
557
|
-
]));
|
|
558
|
-
return new MaintainabilityBaseline(sections).#withReasonsOf(this.reasons);
|
|
559
|
-
}
|
|
560
|
-
#withReasonsOf(reasons) {
|
|
561
|
-
return new MaintainabilityBaseline(this.sections, new Map([...reasons].filter(([key]) => this.#holdsReasoned(key))));
|
|
562
|
-
}
|
|
563
|
-
grownFrom(committed) {
|
|
564
|
-
return [...this.sections].flatMap(([rule, counts]) => MaintainabilityBaseline.#raised(counts, committed.sections.get(rule) ?? new Map).filter(([key]) => !(MaintainabilityBaseline.reasonedRules.has(rule) && this.reasonOf(key))).map(([key, count, recorded]) => ({ rule, key, count, committed: recorded })));
|
|
565
|
-
}
|
|
566
|
-
stringify() {
|
|
567
|
-
const sections = MaintainabilityBaseline.debtRules.flatMap((rule) => {
|
|
568
|
-
const counts = this.sections.get(rule);
|
|
569
|
-
return counts?.size ? [[rule, MaintainabilityBaseline.#sortedObjectOf(counts)]] : [];
|
|
570
|
-
});
|
|
571
|
-
return JsonFormatter.stringify({
|
|
572
|
-
...Object.fromEntries(sections),
|
|
573
|
-
...this.reasons.size ? { reasons: MaintainabilityBaseline.#sortedObjectOf(this.reasons) } : {}
|
|
574
|
-
}, MaintainabilityBaseline.fileName);
|
|
575
|
-
}
|
|
576
|
-
#holdsReasoned(key) {
|
|
577
|
-
return [...this.sections].some(([rule, counts]) => MaintainabilityBaseline.reasonedRules.has(rule) && counts.has(key));
|
|
578
|
-
}
|
|
579
|
-
static #countsOf(value) {
|
|
580
|
-
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
581
|
-
return null;
|
|
582
|
-
const entries = Object.entries(value);
|
|
583
|
-
return entries.every(([, count]) => Number.isInteger(count)) ? entries : null;
|
|
584
|
-
}
|
|
585
|
-
static #reasonsOf(value) {
|
|
586
|
-
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
587
|
-
return null;
|
|
588
|
-
const entries = Object.entries(value);
|
|
589
|
-
return entries.every(([, reason]) => typeof reason === "string") ? entries : null;
|
|
590
|
-
}
|
|
591
|
-
static #lowered(recorded, current) {
|
|
592
|
-
return new Map([...recorded].flatMap(([key, count]) => {
|
|
593
|
-
const measured = current.get(key);
|
|
594
|
-
return measured === undefined ? [] : [[key, Math.min(count, measured)]];
|
|
595
|
-
}));
|
|
596
|
-
}
|
|
597
|
-
static #raised(working, committed) {
|
|
598
|
-
return [...working].flatMap(([key, count]) => {
|
|
599
|
-
const recorded = committed.get(key);
|
|
600
|
-
return recorded !== undefined && count <= recorded ? [] : [[key, count, recorded]];
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
static #sortedObjectOf(values) {
|
|
604
|
-
return Object.fromEntries([...values].sort(([a], [b]) => MaintainabilityBaseline.#byKey(a, b)));
|
|
605
|
-
}
|
|
606
|
-
static #byKey(a, b) {
|
|
607
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
|
|
611
453
|
// pkgs/@akanjs/devkit/maintainabilityLimits.ts
|
|
612
454
|
import path3 from "path";
|
|
613
455
|
import ts6 from "typescript";
|
|
@@ -626,7 +468,8 @@ class AbstractDoc {
|
|
|
626
468
|
return filePath.endsWith(AbstractDoc.suffix);
|
|
627
469
|
}
|
|
628
470
|
static lineCountOf(content) {
|
|
629
|
-
return content.split(/\r?\n/).length
|
|
471
|
+
return content.split(/\r?\n/).length - (content.endsWith(`
|
|
472
|
+
`) ? 1 : 0);
|
|
630
473
|
}
|
|
631
474
|
static kindOf(filePath) {
|
|
632
475
|
const [root, folder, ...rest] = filePath.split("/");
|
|
@@ -693,6 +536,9 @@ class MaintainabilityLimits {
|
|
|
693
536
|
static #maxLinesByKind = { ...MaintainabilityLimits.fileMaxLines, ...MaintainabilityLimits.folderMaxLines };
|
|
694
537
|
static componentMaxLines = 250;
|
|
695
538
|
static componentMaxStoreAccesses = 16;
|
|
539
|
+
static packageFileMaxLines = 800;
|
|
540
|
+
static functionMaxLines = 150;
|
|
541
|
+
static classMaxMembers = 60;
|
|
696
542
|
static fileKindOf(sysRelativePath) {
|
|
697
543
|
const kinds = Object.keys(MaintainabilityLimits.#maxLinesByKind);
|
|
698
544
|
const suffix = kinds.find((kind) => sysRelativePath.endsWith(kind));
|
|
@@ -721,6 +567,9 @@ class MaintainabilityLimits {
|
|
|
721
567
|
return sysRelativePath.endsWith(".tsx");
|
|
722
568
|
return /^(ui|webkit)\/.+\.tsx?$/.test(sysRelativePath) && !sysRelativePath.endsWith(".d.ts");
|
|
723
569
|
}
|
|
570
|
+
static isPackageSource(pkgRelativePath) {
|
|
571
|
+
return /\.tsx?$/.test(pkgRelativePath) && !pkgRelativePath.endsWith(".d.ts") && !/(^|\/)(examples|test|tests|__tests__|__fixtures__|__mocks__)\//.test(pkgRelativePath) && !/\.(test|spec|fixture|instance|bench)\.tsx?$/.test(pkgRelativePath);
|
|
572
|
+
}
|
|
724
573
|
static #isTest(sysRelativePath) {
|
|
725
574
|
return /\.(test|spec)\.tsx?$/.test(sysRelativePath);
|
|
726
575
|
}
|
|
@@ -742,8 +591,11 @@ class MaintainabilityReport {
|
|
|
742
591
|
".store.ts": "Move business logic into the service behind an endpoint and derived values onto Light<Model>; an action is fetch, set, toast.",
|
|
743
592
|
".document.ts": "Move display and predicate logic onto Light<Model>, and split an unrelated concept into its own module.",
|
|
744
593
|
".service.ts": "Move state transitions into document chain methods, and split an unrelated responsibility into its own module.",
|
|
594
|
+
package: "Split it by responsibility: one class per file, and each family of helpers in a file of its own behind the package's existing exports.",
|
|
745
595
|
[AbstractDoc.suffix]: "Trim the abstract to a title, one sentence naming what the module owns, and a `## Rules` list of the invariants the code cannot show.",
|
|
746
596
|
"akan.size.component": MaintainabilityReport.#clientSplitFix,
|
|
597
|
+
"akan.size.function": "Split it by family into named functions or a collaborator class, each under the limit, keeping its signature for callers.",
|
|
598
|
+
"akan.size.class": "Move each family of members into a collaborator the class holds, and keep the public members on the class as its facade.",
|
|
747
599
|
"akan.store.multi-write": MaintainabilityReport.#oneEndpointFix,
|
|
748
600
|
"akan.store.root-write-chain": `A store may call another through \`RootStore\`, but that does not make the writes one. ${MaintainabilityReport.#oneEndpointFix}`,
|
|
749
601
|
"akan.component.write-chain": "Move the writes into one service method behind one endpoint, called by one store action the handler calls once; a component chaining `st.do` writes, or writing once per item, leaves an agent or another screen half-done.",
|
|
@@ -755,7 +607,10 @@ class MaintainabilityReport {
|
|
|
755
607
|
static #labels = {
|
|
756
608
|
"ui/": "ui/**",
|
|
757
609
|
"webkit/": "webkit/**",
|
|
610
|
+
package: "package file",
|
|
758
611
|
"akan.size.component": "component or hook",
|
|
612
|
+
"akan.size.function": "function",
|
|
613
|
+
"akan.size.class": "class",
|
|
759
614
|
"akan.store.multi-write": "store action with several writes",
|
|
760
615
|
"akan.store.root-write-chain": "store method chaining other stores' writes",
|
|
761
616
|
"akan.component.write-chain": "handler with several writes",
|
|
@@ -767,6 +622,8 @@ class MaintainabilityReport {
|
|
|
767
622
|
static #units = {
|
|
768
623
|
"akan.size.file": "lines",
|
|
769
624
|
"akan.size.component": "lines",
|
|
625
|
+
"akan.size.function": "lines",
|
|
626
|
+
"akan.size.class": "members",
|
|
770
627
|
"akan.component.store-access": "store accesses",
|
|
771
628
|
"akan.store.multi-write": "writes",
|
|
772
629
|
"akan.store.root-write-chain": "writes",
|
|
@@ -777,7 +634,7 @@ class MaintainabilityReport {
|
|
|
777
634
|
static describe(sysPath, failures, commands = {}) {
|
|
778
635
|
const groups = new Map;
|
|
779
636
|
for (const failure of failures) {
|
|
780
|
-
const fixKey = MaintainabilityReport.#fixKeyOf(failure);
|
|
637
|
+
const fixKey = MaintainabilityReport.#fixKeyOf(sysPath, failure);
|
|
781
638
|
const fix = MaintainabilityReport.#fixes[fixKey];
|
|
782
639
|
const group = groups.get(fix) ?? { labels: [], rules: new Set };
|
|
783
640
|
const label = MaintainabilityReport.#labelOf(fixKey);
|
|
@@ -803,14 +660,17 @@ class MaintainabilityReport {
|
|
|
803
660
|
line: failure.line,
|
|
804
661
|
rule: failure.rule,
|
|
805
662
|
problem: MaintainabilityReport.#problemOf(failure),
|
|
806
|
-
fix: MaintainabilityReport.#fixes[MaintainabilityReport.#fixKeyOf(failure)],
|
|
663
|
+
fix: MaintainabilityReport.#fixes[MaintainabilityReport.#fixKeyOf(sysPath, failure)],
|
|
807
664
|
path: commands[failure.rule]?.[0] ?? null
|
|
808
665
|
}));
|
|
809
666
|
}
|
|
810
667
|
static #problemOf(failure) {
|
|
811
668
|
if (failure.kind === "baselineGrowth") {
|
|
812
669
|
const entry = `entry "${failure.key}" under ${failure.debtRule}`;
|
|
813
|
-
|
|
670
|
+
const units = MaintainabilityReport.#units[failure.debtRule];
|
|
671
|
+
if (failure.measured)
|
|
672
|
+
return failure.committed === undefined ? `${entry} is debt the code at ${failure.reference} does not hold, and with no baseline there the baseline may only shrink from that code` : `${entry} allows ${failure.count} ${units}, above the ${failure.committed} the code at ${failure.reference} holds with no baseline there; the baseline may only shrink`;
|
|
673
|
+
return failure.committed === undefined ? `${entry} is not in the baseline at ${failure.reference}, which may only shrink` : `${entry} allows ${failure.count} ${units}, above the ${failure.committed} at ${failure.reference}; the baseline may only shrink`;
|
|
814
674
|
}
|
|
815
675
|
const grown = failure.recorded === undefined ? "" : `, more than the ${failure.recorded} recorded`;
|
|
816
676
|
if (failure.kind === "multiWrite") {
|
|
@@ -826,18 +686,22 @@ class MaintainabilityReport {
|
|
|
826
686
|
return `sends ${failure.writes.length} server write(s) from outside a store action or a module component: ${failure.writes.join(", ")}${grown}`;
|
|
827
687
|
if (failure.kind === "loopCall")
|
|
828
688
|
return `service method ${failure.owner} calls once per item: ${failure.calls.join(", ")}${grown}`;
|
|
689
|
+
if (failure.kind === "classSize")
|
|
690
|
+
return `class ${failure.owner} has ${failure.memberCount} members, over the ${failure.maxMembers}-member limit${failure.recorded === undefined ? "" : `, up from ${failure.recorded}`}`;
|
|
829
691
|
if (failure.kind === "storeAccess")
|
|
830
692
|
return `${MaintainabilityReport.#unitOf(failure.component)} ${failure.component} reaches the store ${failure.accessCount} times, over the ${failure.maxAccesses}-access limit${failure.recorded === undefined ? "" : `, up from ${failure.recorded}`}`;
|
|
831
|
-
const subject = failure.component ? `${MaintainabilityReport.#unitOf(failure.component)} ${failure.component} has` : "file has";
|
|
693
|
+
const subject = failure.function ? `function ${failure.function} has` : failure.component ? `${MaintainabilityReport.#unitOf(failure.component)} ${failure.component} has` : "file has";
|
|
832
694
|
const up = failure.recorded === undefined ? "" : `, up from ${failure.recorded}`;
|
|
833
695
|
return `${subject} ${failure.lineCount} lines, over the ${failure.maxLines}-line limit${up}`;
|
|
834
696
|
}
|
|
835
697
|
static #unitOf(name) {
|
|
836
698
|
return /^use[A-Z]/.test(name) ? "hook" : "component";
|
|
837
699
|
}
|
|
838
|
-
static #fixKeyOf(failure) {
|
|
700
|
+
static #fixKeyOf(sysPath, failure) {
|
|
839
701
|
if (failure.rule !== "akan.size.file")
|
|
840
702
|
return failure.rule;
|
|
703
|
+
if (sysPath.startsWith("pkgs/"))
|
|
704
|
+
return "package";
|
|
841
705
|
return MaintainabilityLimits.fileKindOf(failure.file) ?? "akan.size.component";
|
|
842
706
|
}
|
|
843
707
|
static #labelOf(fixKey) {
|
|
@@ -1171,8 +1035,120 @@ class StoreWriteScanner {
|
|
|
1171
1035
|
}
|
|
1172
1036
|
}
|
|
1173
1037
|
|
|
1174
|
-
// pkgs/@akanjs/devkit/
|
|
1038
|
+
// pkgs/@akanjs/devkit/structureScanner.ts
|
|
1175
1039
|
import ts10 from "typescript";
|
|
1040
|
+
|
|
1041
|
+
class StructureScanner {
|
|
1042
|
+
measure(sourceFile) {
|
|
1043
|
+
const functions = [];
|
|
1044
|
+
const classes = [];
|
|
1045
|
+
const lineOf = (pos) => sourceFile.getLineAndCharacterOfPosition(pos).line + 1;
|
|
1046
|
+
const visit = (node, owners) => {
|
|
1047
|
+
if (ts10.isClassDeclaration(node) || ts10.isClassExpression(node)) {
|
|
1048
|
+
const name = StructureScanner.#classNameOf(node);
|
|
1049
|
+
classes.push({
|
|
1050
|
+
name: [...owners, name].join("."),
|
|
1051
|
+
line: lineOf(node.getStart(sourceFile)),
|
|
1052
|
+
memberCount: StructureScanner.#memberCountOf(node)
|
|
1053
|
+
});
|
|
1054
|
+
ts10.forEachChild(node, (child) => visit(child, [...owners, name]));
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
if (StructureScanner.#isFunction(node)) {
|
|
1058
|
+
const name = StructureScanner.#functionNameOf(node);
|
|
1059
|
+
const line = lineOf(node.getStart(sourceFile));
|
|
1060
|
+
functions.push({
|
|
1061
|
+
name: [...owners, name].join("."),
|
|
1062
|
+
line,
|
|
1063
|
+
lineCount: lineOf(node.getEnd()) - line + 1
|
|
1064
|
+
});
|
|
1065
|
+
ts10.forEachChild(node, (child) => visit(child, [...owners, name]));
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
if (ts10.isObjectLiteralExpression(node)) {
|
|
1069
|
+
const name = StructureScanner.#boundNameOf(node);
|
|
1070
|
+
ts10.forEachChild(node, (child) => visit(child, name === "<anonymous>" ? owners : [...owners, name]));
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
ts10.forEachChild(node, (child) => visit(child, owners));
|
|
1074
|
+
};
|
|
1075
|
+
ts10.forEachChild(sourceFile, (child) => visit(child, []));
|
|
1076
|
+
return { functions, classes };
|
|
1077
|
+
}
|
|
1078
|
+
static #memberCountOf(node) {
|
|
1079
|
+
const methods = new Set;
|
|
1080
|
+
return node.members.filter((member) => {
|
|
1081
|
+
if (ts10.isSemicolonClassElement(member) || ts10.isIndexSignatureDeclaration(member) || ts10.isClassStaticBlockDeclaration(member))
|
|
1082
|
+
return false;
|
|
1083
|
+
if (!ts10.isMethodDeclaration(member) && !ts10.isConstructorDeclaration(member))
|
|
1084
|
+
return true;
|
|
1085
|
+
const isStatic = ts10.getModifiers(member)?.some((modifier) => modifier.kind === ts10.SyntaxKind.StaticKeyword);
|
|
1086
|
+
const key = `${isStatic ? "static " : ""}${ts10.isConstructorDeclaration(member) ? "constructor" : StructureScanner.#textOf(member.name)}`;
|
|
1087
|
+
if (methods.has(key))
|
|
1088
|
+
return false;
|
|
1089
|
+
methods.add(key);
|
|
1090
|
+
return true;
|
|
1091
|
+
}).length;
|
|
1092
|
+
}
|
|
1093
|
+
static #isFunction(node) {
|
|
1094
|
+
return (ts10.isFunctionDeclaration(node) || ts10.isMethodDeclaration(node) || ts10.isConstructorDeclaration(node) || ts10.isGetAccessorDeclaration(node) || ts10.isSetAccessorDeclaration(node) || ts10.isFunctionExpression(node) || ts10.isArrowFunction(node)) && node.body !== undefined;
|
|
1095
|
+
}
|
|
1096
|
+
static #functionNameOf(node) {
|
|
1097
|
+
if (ts10.isConstructorDeclaration(node))
|
|
1098
|
+
return "constructor";
|
|
1099
|
+
if (ts10.isGetAccessorDeclaration(node))
|
|
1100
|
+
return `get ${StructureScanner.#textOf(node.name)}`;
|
|
1101
|
+
if (ts10.isSetAccessorDeclaration(node))
|
|
1102
|
+
return `set ${StructureScanner.#textOf(node.name)}`;
|
|
1103
|
+
if (node.name)
|
|
1104
|
+
return StructureScanner.#textOf(node.name);
|
|
1105
|
+
return ts10.isFunctionDeclaration(node) ? "default" : StructureScanner.#boundNameOf(node);
|
|
1106
|
+
}
|
|
1107
|
+
static #classNameOf(node) {
|
|
1108
|
+
if (node.name)
|
|
1109
|
+
return node.name.text;
|
|
1110
|
+
return ts10.isClassDeclaration(node) ? "default" : StructureScanner.#boundNameOf(node);
|
|
1111
|
+
}
|
|
1112
|
+
static #boundNameOf(node) {
|
|
1113
|
+
let current = StructureScanner.#outerOf(node);
|
|
1114
|
+
let call = null;
|
|
1115
|
+
while (ts10.isCallExpression(current.parent) || ts10.isNewExpression(current.parent)) {
|
|
1116
|
+
const callee = current.parent.expression;
|
|
1117
|
+
if (current === callee)
|
|
1118
|
+
break;
|
|
1119
|
+
call ??= `${ts10.isPropertyAccessExpression(callee) ? callee.name.text : ts10.isIdentifier(callee) ? callee.text : "call"}()`;
|
|
1120
|
+
current = StructureScanner.#outerOf(current.parent);
|
|
1121
|
+
}
|
|
1122
|
+
const { parent } = current;
|
|
1123
|
+
if ((ts10.isVariableDeclaration(parent) || ts10.isPropertyAssignment(parent) || ts10.isPropertyDeclaration(parent) || ts10.isParameter(parent) || ts10.isBindingElement(parent)) && parent.name && !ts10.isObjectBindingPattern(parent.name) && !ts10.isArrayBindingPattern(parent.name))
|
|
1124
|
+
return StructureScanner.#textOf(parent.name);
|
|
1125
|
+
if (ts10.isBinaryExpression(parent) && parent.operatorToken.kind === ts10.SyntaxKind.EqualsToken)
|
|
1126
|
+
return ts10.isPropertyAccessExpression(parent.left) ? parent.left.name.text : ts10.isIdentifier(parent.left) ? parent.left.text : "assigned";
|
|
1127
|
+
if (ts10.isExportAssignment(parent))
|
|
1128
|
+
return "default";
|
|
1129
|
+
if (ts10.isJsxExpression(parent))
|
|
1130
|
+
return ts10.isJsxAttribute(parent.parent) ? ts10.isIdentifier(parent.parent.name) ? parent.parent.name.text : parent.parent.name.getText() : "children";
|
|
1131
|
+
return call ?? "<anonymous>";
|
|
1132
|
+
}
|
|
1133
|
+
static #outerOf(node) {
|
|
1134
|
+
let current = node;
|
|
1135
|
+
while (ts10.isParenthesizedExpression(current.parent) || ts10.isAsExpression(current.parent) || ts10.isSatisfiesExpression(current.parent) || ts10.isNonNullExpression(current.parent) || ts10.isTypeAssertionExpression(current.parent) || ts10.isPropertyAccessExpression(current.parent) && current.parent.expression === current || ts10.isCallExpression(current.parent) && current.parent.expression === current)
|
|
1136
|
+
current = current.parent;
|
|
1137
|
+
return current;
|
|
1138
|
+
}
|
|
1139
|
+
static #textOf(name) {
|
|
1140
|
+
if (ts10.isIdentifier(name) || ts10.isPrivateIdentifier(name) || ts10.isStringLiteral(name))
|
|
1141
|
+
return name.text;
|
|
1142
|
+
if (ts10.isNumericLiteral(name) || ts10.isNoSubstitutionTemplateLiteral(name))
|
|
1143
|
+
return name.text;
|
|
1144
|
+
if (ts10.isComputedPropertyName(name))
|
|
1145
|
+
return `[${name.expression.getText()}]`;
|
|
1146
|
+
return "<pattern>";
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
// pkgs/@akanjs/devkit/writePlacementScanner.ts
|
|
1151
|
+
import ts11 from "typescript";
|
|
1176
1152
|
class WritePlacementScanner {
|
|
1177
1153
|
#index;
|
|
1178
1154
|
constructor(index) {
|
|
@@ -1185,9 +1161,9 @@ class WritePlacementScanner {
|
|
|
1185
1161
|
return null;
|
|
1186
1162
|
const sites = [];
|
|
1187
1163
|
const visit = (node) => {
|
|
1188
|
-
if (
|
|
1164
|
+
if (ts11.isPropertyAccessExpression(node) && this.#isWrite(node, workspaceFile, fetchNames, stNames))
|
|
1189
1165
|
sites.push(node);
|
|
1190
|
-
|
|
1166
|
+
ts11.forEachChild(node, visit);
|
|
1191
1167
|
};
|
|
1192
1168
|
visit(sourceFile);
|
|
1193
1169
|
const first = sites[0];
|
|
@@ -1200,9 +1176,9 @@ class WritePlacementScanner {
|
|
|
1200
1176
|
}
|
|
1201
1177
|
#isWrite(access, workspaceFile, fetchNames, stNames) {
|
|
1202
1178
|
const owner = access.expression;
|
|
1203
|
-
if (
|
|
1179
|
+
if (ts11.isIdentifier(owner) && fetchNames.has(owner.text))
|
|
1204
1180
|
return this.#index.isMutation(workspaceFile, access.name.text);
|
|
1205
|
-
return
|
|
1181
|
+
return ts11.isPropertyAccessExpression(owner) && owner.name.text === "do" && ts11.isIdentifier(owner.expression) && stNames.has(owner.expression.text) && this.#index.isWritingAction(access.name.text);
|
|
1206
1182
|
}
|
|
1207
1183
|
}
|
|
1208
1184
|
|
|
@@ -1266,6 +1242,8 @@ class MaintainabilityContract {
|
|
|
1266
1242
|
static ruleIds = [
|
|
1267
1243
|
"akan.size.file",
|
|
1268
1244
|
"akan.size.component",
|
|
1245
|
+
"akan.size.function",
|
|
1246
|
+
"akan.size.class",
|
|
1269
1247
|
"akan.store.multi-write",
|
|
1270
1248
|
"akan.store.root-write-chain",
|
|
1271
1249
|
"akan.component.write-chain",
|
|
@@ -1279,6 +1257,7 @@ class MaintainabilityContract {
|
|
|
1279
1257
|
#workspaceRoot;
|
|
1280
1258
|
#scope;
|
|
1281
1259
|
#libNames;
|
|
1260
|
+
#tree = null;
|
|
1282
1261
|
constructor(workspaceRoot, scope, libNames = []) {
|
|
1283
1262
|
this.#workspaceRoot = workspaceRoot;
|
|
1284
1263
|
this.#scope = scope;
|
|
@@ -1291,6 +1270,8 @@ class MaintainabilityContract {
|
|
|
1291
1270
|
return path4.join(this.#workspaceRoot, this.sysPath, MaintainabilityBaseline.fileName);
|
|
1292
1271
|
}
|
|
1293
1272
|
async measure() {
|
|
1273
|
+
if (this.#scope.type === "pkg")
|
|
1274
|
+
return await this.#measurePackage();
|
|
1294
1275
|
const [signalFiles, storeFiles, serviceFiles] = await Promise.all([
|
|
1295
1276
|
this.#reachedSources("lib/**/*.signal.ts"),
|
|
1296
1277
|
this.#reachedSources("lib/**/*.store.ts"),
|
|
@@ -1298,7 +1279,7 @@ class MaintainabilityContract {
|
|
|
1298
1279
|
]);
|
|
1299
1280
|
const index = new WritingActionIndex(new SignalMutationIndex(signalFiles), storeFiles);
|
|
1300
1281
|
const reach = new EndpointReach(signalFiles, serviceFiles);
|
|
1301
|
-
const files = await
|
|
1282
|
+
const files = await this.#filesIn(this.sysPath, MaintainabilityContract.#measuredFiles);
|
|
1302
1283
|
const violations = await Promise.all(files.map((file) => this.#measureFile(file, index, reach)));
|
|
1303
1284
|
return violations.flat().sort((a, b) => a.file < b.file ? -1 : a.file > b.file ? 1 : a.line - b.line);
|
|
1304
1285
|
}
|
|
@@ -1316,17 +1297,20 @@ class MaintainabilityContract {
|
|
|
1316
1297
|
const recorded = baseline.recordedOf(violation);
|
|
1317
1298
|
return recorded === undefined ? violation : { ...violation, recorded };
|
|
1318
1299
|
});
|
|
1319
|
-
|
|
1300
|
+
const working = fix ? tightened : baseline;
|
|
1301
|
+
const source = `${reference.label}:${this.sysPath}/${MaintainabilityBaseline.fileName}`;
|
|
1302
|
+
const committed = reference.text !== null ? MaintainabilityBaseline.parse(reference.text, source, { lenient: true }) : working.isEmpty ? null : await this.#measuredAt(reference.ref);
|
|
1303
|
+
if (committed === null)
|
|
1320
1304
|
return failures;
|
|
1321
1305
|
const lines = (await this.#readBaseline() ?? "").split(/\r?\n/);
|
|
1322
|
-
const
|
|
1323
|
-
const growths = (fix ? tightened : baseline).grownFrom(MaintainabilityBaseline.parse(reference.text, label, { lenient: true })).map(({ rule, ...growth }) => ({
|
|
1306
|
+
const growths = working.grownFrom(committed).map(({ rule, ...growth }) => ({
|
|
1324
1307
|
kind: "baselineGrowth",
|
|
1325
1308
|
rule: "akan.baseline.growth",
|
|
1326
1309
|
file: MaintainabilityBaseline.fileName,
|
|
1327
1310
|
line: MaintainabilityContract.#lineOf(lines, rule, growth.key),
|
|
1328
1311
|
debtRule: rule,
|
|
1329
|
-
reference: reference.
|
|
1312
|
+
reference: reference.label,
|
|
1313
|
+
...reference.text === null ? { measured: true } : {},
|
|
1330
1314
|
...growth
|
|
1331
1315
|
})).sort((a, b) => a.line - b.line);
|
|
1332
1316
|
return [...growths, ...failures];
|
|
@@ -1346,6 +1330,63 @@ class MaintainabilityContract {
|
|
|
1346
1330
|
describe(failures, commands) {
|
|
1347
1331
|
return MaintainabilityReport.describe(this.sysPath, failures, commands);
|
|
1348
1332
|
}
|
|
1333
|
+
async#measurePackage() {
|
|
1334
|
+
const files = (await this.#packageFiles()).filter(MaintainabilityLimits.isPackageSource);
|
|
1335
|
+
const violations = await Promise.all(files.map(async (file) => {
|
|
1336
|
+
const workspaceFile = `${this.sysPath}/${file}`;
|
|
1337
|
+
const content = await this.#read(workspaceFile);
|
|
1338
|
+
return MaintainabilityContract.#measurePackageFile(file, this.#sourceOf(workspaceFile, content).sourceFile);
|
|
1339
|
+
}));
|
|
1340
|
+
return violations.flat();
|
|
1341
|
+
}
|
|
1342
|
+
static #measurePackageFile(file, sourceFile) {
|
|
1343
|
+
const violations = [];
|
|
1344
|
+
const maxLines = MaintainabilityLimits.packageFileMaxLines;
|
|
1345
|
+
const lineCount = MaintainabilityLimits.lineCountOf(sourceFile.text);
|
|
1346
|
+
if (lineCount > maxLines && !MaintainabilityLimits.isReexportBarrel(file, sourceFile.text))
|
|
1347
|
+
violations.push({ kind: "size", rule: "akan.size.file", key: file, file, line: 1, lineCount, maxLines });
|
|
1348
|
+
const { functions, classes } = new StructureScanner().measure(sourceFile);
|
|
1349
|
+
const longFunctions = functions.filter(({ lineCount }) => lineCount > MaintainabilityLimits.functionMaxLines);
|
|
1350
|
+
for (const { name, line, lineCount } of MaintainabilityContract.#numbered(longFunctions))
|
|
1351
|
+
violations.push({
|
|
1352
|
+
kind: "size",
|
|
1353
|
+
rule: "akan.size.function",
|
|
1354
|
+
key: `${file}#${name}`,
|
|
1355
|
+
file,
|
|
1356
|
+
line,
|
|
1357
|
+
lineCount,
|
|
1358
|
+
maxLines: MaintainabilityLimits.functionMaxLines,
|
|
1359
|
+
function: name
|
|
1360
|
+
});
|
|
1361
|
+
const largeClasses = classes.filter(({ memberCount }) => memberCount > MaintainabilityLimits.classMaxMembers);
|
|
1362
|
+
for (const { name, line, memberCount } of MaintainabilityContract.#numbered(largeClasses))
|
|
1363
|
+
violations.push({
|
|
1364
|
+
kind: "classSize",
|
|
1365
|
+
rule: "akan.size.class",
|
|
1366
|
+
key: `${file}#${name}`,
|
|
1367
|
+
file,
|
|
1368
|
+
line,
|
|
1369
|
+
owner: name,
|
|
1370
|
+
memberCount,
|
|
1371
|
+
maxMembers: MaintainabilityLimits.classMaxMembers
|
|
1372
|
+
});
|
|
1373
|
+
return violations;
|
|
1374
|
+
}
|
|
1375
|
+
static #numbered(items) {
|
|
1376
|
+
const seen = new Map;
|
|
1377
|
+
return items.map((item) => {
|
|
1378
|
+
const count = (seen.get(item.name) ?? 0) + 1;
|
|
1379
|
+
seen.set(item.name, count);
|
|
1380
|
+
return count === 1 ? item : { ...item, name: `${item.name}[${count}]` };
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
async#packageFiles() {
|
|
1384
|
+
const listed = this.#tree ? null : await this.#git(["ls-files", "-z", "-co", "--exclude-standard", "--", `./${this.sysPath}`]);
|
|
1385
|
+
if (listed === null)
|
|
1386
|
+
return await this.#filesIn(this.sysPath, "**/*.{ts,tsx}");
|
|
1387
|
+
const prefix = `${this.sysPath}/`;
|
|
1388
|
+
return listed.split("\x00").filter((file) => file.startsWith(prefix) && existsSync(path4.join(this.#workspaceRoot, file))).map((file) => file.slice(prefix.length)).filter((file) => !file.includes("node_modules/")).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
1389
|
+
}
|
|
1349
1390
|
async#measureFile(file, index, reach) {
|
|
1350
1391
|
const maxLines = MaintainabilityLimits.fileMaxLinesOf(file);
|
|
1351
1392
|
const isStore = file.endsWith(".store.ts");
|
|
@@ -1354,7 +1395,7 @@ class MaintainabilityContract {
|
|
|
1354
1395
|
if (!maxLines && !isStore && !isClientCode)
|
|
1355
1396
|
return [];
|
|
1356
1397
|
const workspaceFile = `${this.sysPath}/${file}`;
|
|
1357
|
-
const content = await
|
|
1398
|
+
const content = await this.#read(workspaceFile);
|
|
1358
1399
|
const violations = [];
|
|
1359
1400
|
const lineCount = MaintainabilityLimits.lineCountOf(content);
|
|
1360
1401
|
if (maxLines && lineCount > maxLines && !MaintainabilityLimits.isReexportBarrel(file, content))
|
|
@@ -1433,16 +1474,16 @@ class MaintainabilityContract {
|
|
|
1433
1474
|
}
|
|
1434
1475
|
async#reachedSources(pattern) {
|
|
1435
1476
|
const roots = [this.sysPath, ...this.#libNames.map((libName) => `libs/${libName}`)];
|
|
1436
|
-
const files = await Promise.all(roots.map(async (root) => (await
|
|
1437
|
-
return await Promise.all(files.flat().map(async (file) => this.#sourceOf(file, await
|
|
1477
|
+
const files = await Promise.all(roots.map(async (root) => (await this.#filesIn(root, pattern)).map((file) => `${root}/${file}`)));
|
|
1478
|
+
return await Promise.all(files.flat().map(async (file) => this.#sourceOf(file, await this.#read(file))));
|
|
1438
1479
|
}
|
|
1439
1480
|
#sourceOf(file, content) {
|
|
1440
|
-
const scriptKind = file.endsWith(".tsx") ?
|
|
1481
|
+
const scriptKind = file.endsWith(".tsx") ? ts12.ScriptKind.TSX : ts12.ScriptKind.TS;
|
|
1441
1482
|
return {
|
|
1442
1483
|
file,
|
|
1443
1484
|
absolutePath: path4.join(this.#workspaceRoot, file),
|
|
1444
1485
|
content,
|
|
1445
|
-
sourceFile:
|
|
1486
|
+
sourceFile: ts12.createSourceFile(file, content, ts12.ScriptTarget.Latest, true, scriptKind)
|
|
1446
1487
|
};
|
|
1447
1488
|
}
|
|
1448
1489
|
async#readBaseline() {
|
|
@@ -1451,7 +1492,15 @@ class MaintainabilityContract {
|
|
|
1451
1492
|
async#readReferenceBaseline() {
|
|
1452
1493
|
const ref = await this.#referenceRef();
|
|
1453
1494
|
const text = await this.#git(["show", `${ref}:./${this.sysPath}/${MaintainabilityBaseline.fileName}`]);
|
|
1454
|
-
return
|
|
1495
|
+
return { ref, label: ref === "HEAD" ? ref : ref.slice(0, 12), text };
|
|
1496
|
+
}
|
|
1497
|
+
async#measuredAt(ref) {
|
|
1498
|
+
if (await this.#git(["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]) === null)
|
|
1499
|
+
return null;
|
|
1500
|
+
const roots = [this.sysPath, ...this.#libNames.map((libName) => `libs/${libName}`)];
|
|
1501
|
+
const contract = new MaintainabilityContract(this.#workspaceRoot, this.#scope, this.#libNames);
|
|
1502
|
+
contract.#tree = await new GitRevision(this.#workspaceRoot).filesAt(ref, (file) => /\.(tsx?|md)$/.test(file), roots);
|
|
1503
|
+
return MaintainabilityBaseline.of(await contract.measure());
|
|
1455
1504
|
}
|
|
1456
1505
|
async#referenceRef() {
|
|
1457
1506
|
for (const branch of MaintainabilityContract.#defaultBranches) {
|
|
@@ -1498,11 +1547,19 @@ class MaintainabilityContract {
|
|
|
1498
1547
|
const idx = lines.findIndex((line, lineIdx) => lineIdx >= from && line.includes(`${JSON.stringify(key)}:`));
|
|
1499
1548
|
return Math.max(idx + 1, 1);
|
|
1500
1549
|
}
|
|
1501
|
-
|
|
1550
|
+
async#filesIn(root, pattern) {
|
|
1551
|
+
const glob = new Bun.Glob(pattern);
|
|
1552
|
+
const files = this.#tree ? [...this.#tree.keys()].filter((file) => file.startsWith(`${root}/`)).map((file) => file.slice(root.length + 1)).filter((file) => glob.match(file)) : await MaintainabilityContract.#filesOnDisk(path4.join(this.#workspaceRoot, root), glob);
|
|
1553
|
+
return files.filter((file) => !file.includes("node_modules/")).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
1554
|
+
}
|
|
1555
|
+
static async#filesOnDisk(root, glob) {
|
|
1502
1556
|
if (!existsSync(root))
|
|
1503
1557
|
return [];
|
|
1504
|
-
const files = await Array.fromAsync(
|
|
1505
|
-
return files.map((file) => file.split(path4.sep).join("/"))
|
|
1558
|
+
const files = await Array.fromAsync(glob.scan({ cwd: root, onlyFiles: true }));
|
|
1559
|
+
return files.map((file) => file.split(path4.sep).join("/"));
|
|
1560
|
+
}
|
|
1561
|
+
async#read(file) {
|
|
1562
|
+
return this.#tree ? this.#tree.get(file) ?? "" : await readFile(path4.join(this.#workspaceRoot, file), "utf8");
|
|
1506
1563
|
}
|
|
1507
1564
|
}
|
|
1508
1565
|
|
|
@@ -1514,6 +1571,8 @@ class MaintainabilityPaths {
|
|
|
1514
1571
|
static pathless = new Set([
|
|
1515
1572
|
"akan.size.file",
|
|
1516
1573
|
"akan.size.component",
|
|
1574
|
+
"akan.size.function",
|
|
1575
|
+
"akan.size.class",
|
|
1517
1576
|
"akan.service.call-in-loop",
|
|
1518
1577
|
"akan.baseline.growth"
|
|
1519
1578
|
]);
|
|
@@ -1588,7 +1647,8 @@ class WorkspaceRunner extends runner("workspace") {
|
|
|
1588
1647
|
akanVersion,
|
|
1589
1648
|
registryUrl,
|
|
1590
1649
|
owner = "",
|
|
1591
|
-
libs = []
|
|
1650
|
+
libs = [],
|
|
1651
|
+
bunDependency
|
|
1592
1652
|
}) {
|
|
1593
1653
|
const cwdPath = process.cwd();
|
|
1594
1654
|
const workspaceRoot = inPlace ? path5.resolve(cwdPath, dirname) : path5.resolve(cwdPath, dirname, repoName);
|
|
@@ -1627,10 +1687,18 @@ class WorkspaceRunner extends runner("workspace") {
|
|
|
1627
1687
|
const { typescript, ...dependencies } = peerDependencies;
|
|
1628
1688
|
const packageJson = {
|
|
1629
1689
|
...rootPackageJson,
|
|
1690
|
+
...bunDependency ? {
|
|
1691
|
+
scripts: {
|
|
1692
|
+
...rootPackageJson.scripts,
|
|
1693
|
+
build: `akan build ${appName}`,
|
|
1694
|
+
start: `cd dist/apps/${appName} && bun main.js`
|
|
1695
|
+
}
|
|
1696
|
+
} : {},
|
|
1630
1697
|
dependencies: {
|
|
1631
1698
|
...rootPackageJson.dependencies,
|
|
1632
1699
|
...dependencies,
|
|
1633
|
-
akanjs: akanVersion
|
|
1700
|
+
akanjs: akanVersion,
|
|
1701
|
+
...bunDependency ? { bun: bunDependency } : {}
|
|
1634
1702
|
},
|
|
1635
1703
|
devDependencies: {
|
|
1636
1704
|
...rootPackageJson.devDependencies,
|
|
@@ -1765,14 +1833,16 @@ class WorkspaceRunner extends runner("workspace") {
|
|
|
1765
1833
|
() => this.#enforceAgentsIndex(exec)
|
|
1766
1834
|
])
|
|
1767
1835
|
await gate().catch((error) => messages.push(error instanceof Error ? error.message : String(error)));
|
|
1768
|
-
if (!(exec instanceof SysExecutor))
|
|
1836
|
+
if (!(exec instanceof SysExecutor) && !(exec instanceof PkgExecutor))
|
|
1769
1837
|
return { messages, maintainability: [] };
|
|
1770
1838
|
const contract = await this.maintainabilityContractOf(exec);
|
|
1771
1839
|
const failures = await contract.enforce({ fix });
|
|
1772
|
-
const maintainability = MaintainabilityReport.entriesOf(contract.sysPath, failures,
|
|
1840
|
+
const maintainability = MaintainabilityReport.entriesOf(contract.sysPath, failures, WorkspaceRunner.#maintainabilityCommandsOf(exec));
|
|
1773
1841
|
return { messages, maintainability };
|
|
1774
1842
|
}
|
|
1775
1843
|
async maintainabilityContractOf(exec) {
|
|
1844
|
+
if (exec instanceof PkgExecutor)
|
|
1845
|
+
return new MaintainabilityContract(exec.workspace.workspaceRoot, { type: "pkg", name: exec.name });
|
|
1776
1846
|
const libNames = new Set;
|
|
1777
1847
|
const visit = async (sys) => {
|
|
1778
1848
|
for (const libName of (await sys.scan({ write: false })).getScanResult().libDeps) {
|
|
@@ -1809,12 +1879,15 @@ class WorkspaceRunner extends runner("workspace") {
|
|
|
1809
1879
|
throw new Error(`[agentsIndex] The recipe index in ${scope.type}s/${scope.name}/AGENTS.md is stale: it differs from the recipe ` + `sources. Run \`akan sync ${scope.name}\` to regenerate it.`);
|
|
1810
1880
|
}
|
|
1811
1881
|
async#enforceMaintainability(exec, fix) {
|
|
1812
|
-
if (!(exec instanceof SysExecutor))
|
|
1882
|
+
if (!(exec instanceof SysExecutor) && !(exec instanceof PkgExecutor))
|
|
1813
1883
|
return;
|
|
1814
1884
|
const contract = await this.maintainabilityContractOf(exec);
|
|
1815
1885
|
const failures = await contract.enforce({ fix });
|
|
1816
1886
|
if (failures.length)
|
|
1817
|
-
throw new Error(contract.describe(failures,
|
|
1887
|
+
throw new Error(contract.describe(failures, WorkspaceRunner.#maintainabilityCommandsOf(exec)));
|
|
1888
|
+
}
|
|
1889
|
+
static #maintainabilityCommandsOf(exec) {
|
|
1890
|
+
return exec instanceof PkgExecutor ? {} : new MaintainabilityPaths().commandsOf(exec.name);
|
|
1818
1891
|
}
|
|
1819
1892
|
async#enforceRecipeGate(exec) {
|
|
1820
1893
|
const cwdPath = exec.cwdPath;
|
|
@@ -1878,17 +1951,17 @@ import { readdir as readdir2, readFile as readFile3, stat } from "fs/promises";
|
|
|
1878
1951
|
import path9 from "path";
|
|
1879
1952
|
import { RESERVED_ROUTE_CONFIG_EXPORTS } from "akanjs/common";
|
|
1880
1953
|
import ignore from "ignore";
|
|
1881
|
-
import
|
|
1954
|
+
import ts20 from "typescript";
|
|
1882
1955
|
|
|
1883
1956
|
// pkgs/@akanjs/devkit/commentDensityScanner.ts
|
|
1884
1957
|
import path6 from "path";
|
|
1885
|
-
import
|
|
1958
|
+
import ts14 from "typescript";
|
|
1886
1959
|
|
|
1887
1960
|
// pkgs/@akanjs/devkit/sourceComments.ts
|
|
1888
|
-
import
|
|
1961
|
+
import ts13 from "typescript";
|
|
1889
1962
|
|
|
1890
1963
|
class SourceComments {
|
|
1891
|
-
static #scanner =
|
|
1964
|
+
static #scanner = ts13.createScanner(ts13.ScriptTarget.Latest, false);
|
|
1892
1965
|
static of(sourceFile) {
|
|
1893
1966
|
const comments = [];
|
|
1894
1967
|
const scanGap = (start, end) => {
|
|
@@ -1896,22 +1969,22 @@ class SourceComments {
|
|
|
1896
1969
|
return;
|
|
1897
1970
|
const scanner = SourceComments.#scanner;
|
|
1898
1971
|
scanner.setText(sourceFile.text, start, end - start);
|
|
1899
|
-
for (let kind = scanner.scan();kind !==
|
|
1900
|
-
if (kind !==
|
|
1972
|
+
for (let kind = scanner.scan();kind !== ts13.SyntaxKind.EndOfFileToken; kind = scanner.scan()) {
|
|
1973
|
+
if (kind !== ts13.SyntaxKind.SingleLineCommentTrivia && kind !== ts13.SyntaxKind.MultiLineCommentTrivia)
|
|
1901
1974
|
continue;
|
|
1902
1975
|
comments.push(SourceComments.#commentOf(sourceFile, scanner.getTokenStart(), scanner.getTokenText()));
|
|
1903
1976
|
}
|
|
1904
1977
|
scanner.setText(undefined);
|
|
1905
1978
|
};
|
|
1906
1979
|
const visit = (node) => {
|
|
1907
|
-
if (node.kind ===
|
|
1980
|
+
if (node.kind === ts13.SyntaxKind.JsxText)
|
|
1908
1981
|
return;
|
|
1909
|
-
if (
|
|
1982
|
+
if (ts13.isToken(node)) {
|
|
1910
1983
|
scanGap(node.pos, node.getStart(sourceFile));
|
|
1911
1984
|
return;
|
|
1912
1985
|
}
|
|
1913
1986
|
const children = [];
|
|
1914
|
-
|
|
1987
|
+
ts13.forEachChild(node, (child) => {
|
|
1915
1988
|
children.push(child);
|
|
1916
1989
|
}, (nodes) => {
|
|
1917
1990
|
children.push(...nodes);
|
|
@@ -2014,7 +2087,7 @@ class CommentDensityScanner {
|
|
|
2014
2087
|
static #isMeasured({ file, sourceFile }) {
|
|
2015
2088
|
if (/\.(test|spec)\.tsx?$/.test(file) || path6.basename(file) === "guards.ts")
|
|
2016
2089
|
return false;
|
|
2017
|
-
return !sourceFile.statements.every((statement) =>
|
|
2090
|
+
return !sourceFile.statements.every((statement) => ts14.isExportDeclaration(statement) || ts14.isExpressionStatement(statement) && ts14.isStringLiteral(statement.expression));
|
|
2018
2091
|
}
|
|
2019
2092
|
}
|
|
2020
2093
|
|
|
@@ -2042,7 +2115,7 @@ class DeprecatedCommentScanner {
|
|
|
2042
2115
|
|
|
2043
2116
|
// pkgs/@akanjs/devkit/formSetterScanner.ts
|
|
2044
2117
|
import { capitalize, formSetterNames } from "akanjs/common";
|
|
2045
|
-
import
|
|
2118
|
+
import ts15 from "typescript";
|
|
2046
2119
|
|
|
2047
2120
|
class FormSetterScanner {
|
|
2048
2121
|
static #constantPath = /(?:^|\/)lib\/([^_/][^/]*)\/\1\.constant\.ts$/;
|
|
@@ -2061,7 +2134,7 @@ class FormSetterScanner {
|
|
|
2061
2134
|
const fullModelClasses = new Set([`${className}Input`, `${className}Object`, `Light${className}`, className]);
|
|
2062
2135
|
const keys = new Set(FormSetterScanner.#baseFields);
|
|
2063
2136
|
for (const statement of sourceFile.statements)
|
|
2064
|
-
if (
|
|
2137
|
+
if (ts15.isClassDeclaration(statement) && statement.name && fullModelClasses.has(statement.name.text))
|
|
2065
2138
|
for (const key of FormSetterScanner.#viaFieldKeysOf(statement))
|
|
2066
2139
|
keys.add(key);
|
|
2067
2140
|
for (const key of keys)
|
|
@@ -2070,33 +2143,33 @@ class FormSetterScanner {
|
|
|
2070
2143
|
return setters;
|
|
2071
2144
|
}
|
|
2072
2145
|
static #viaFieldKeysOf(declaration) {
|
|
2073
|
-
const via = declaration.heritageClauses?.find((clause) => clause.token ===
|
|
2074
|
-
if (!via || !
|
|
2146
|
+
const via = declaration.heritageClauses?.find((clause) => clause.token === ts15.SyntaxKind.ExtendsKeyword)?.types[0]?.expression;
|
|
2147
|
+
if (!via || !ts15.isCallExpression(via))
|
|
2075
2148
|
return [];
|
|
2076
2149
|
return via.arguments.flatMap((argument) => {
|
|
2077
|
-
if (!
|
|
2150
|
+
if (!ts15.isArrowFunction(argument) && !ts15.isFunctionExpression(argument))
|
|
2078
2151
|
return [];
|
|
2079
2152
|
const fields = FormSetterScanner.#returnedObjectOf(argument.body);
|
|
2080
|
-
return (fields?.properties ?? []).flatMap((property) => property.name && (
|
|
2153
|
+
return (fields?.properties ?? []).flatMap((property) => property.name && (ts15.isIdentifier(property.name) || ts15.isStringLiteral(property.name)) ? [property.name.text] : []);
|
|
2081
2154
|
});
|
|
2082
2155
|
}
|
|
2083
2156
|
static #returnedObjectOf(body) {
|
|
2084
2157
|
let expression = body;
|
|
2085
|
-
if (
|
|
2086
|
-
expression = body.statements.find(
|
|
2087
|
-
while (expression && (
|
|
2158
|
+
if (ts15.isBlock(body))
|
|
2159
|
+
expression = body.statements.find(ts15.isReturnStatement)?.expression;
|
|
2160
|
+
while (expression && (ts15.isParenthesizedExpression(expression) || ts15.isAsExpression(expression)))
|
|
2088
2161
|
expression = expression.expression;
|
|
2089
|
-
return expression &&
|
|
2162
|
+
return expression && ts15.isObjectLiteralExpression(expression) ? expression : null;
|
|
2090
2163
|
}
|
|
2091
2164
|
#scanFile({ file, sourceFile }, fieldSetters) {
|
|
2092
2165
|
const wrapped = [];
|
|
2093
2166
|
const visit = (node) => {
|
|
2094
|
-
if (
|
|
2167
|
+
if (ts15.isJsxAttribute(node)) {
|
|
2095
2168
|
const setter = FormSetterScanner.#wrappedSetterOf(node, fieldSetters);
|
|
2096
2169
|
if (setter)
|
|
2097
2170
|
wrapped.push({ setter, line: FormSetterScanner.#lineOf(sourceFile, node) });
|
|
2098
2171
|
}
|
|
2099
|
-
|
|
2172
|
+
ts15.forEachChild(node, visit);
|
|
2100
2173
|
};
|
|
2101
2174
|
visit(sourceFile);
|
|
2102
2175
|
if (!wrapped.length)
|
|
@@ -2115,13 +2188,13 @@ class FormSetterScanner {
|
|
|
2115
2188
|
];
|
|
2116
2189
|
}
|
|
2117
2190
|
static #wrappedSetterOf(attribute, fieldSetters) {
|
|
2118
|
-
if (!
|
|
2191
|
+
if (!ts15.isIdentifier(attribute.name) || !/^on[A-Z]/.test(attribute.name.text))
|
|
2119
2192
|
return null;
|
|
2120
2193
|
const initializer = attribute.initializer;
|
|
2121
|
-
if (!initializer || !
|
|
2194
|
+
if (!initializer || !ts15.isJsxExpression(initializer) || !initializer.expression)
|
|
2122
2195
|
return null;
|
|
2123
2196
|
const handler = initializer.expression;
|
|
2124
|
-
if (!
|
|
2197
|
+
if (!ts15.isArrowFunction(handler) && !ts15.isFunctionExpression(handler))
|
|
2125
2198
|
return null;
|
|
2126
2199
|
if (!handler.parameters.length)
|
|
2127
2200
|
return null;
|
|
@@ -2132,14 +2205,14 @@ class FormSetterScanner {
|
|
|
2132
2205
|
const visit = (current) => {
|
|
2133
2206
|
if (found)
|
|
2134
2207
|
return;
|
|
2135
|
-
if (
|
|
2208
|
+
if (ts15.isCallExpression(current) && ts15.isPropertyAccessExpression(current.expression)) {
|
|
2136
2209
|
const { expression, name } = current.expression;
|
|
2137
|
-
if (
|
|
2210
|
+
if (ts15.isPropertyAccessExpression(expression) && ts15.isIdentifier(expression.expression) && expression.expression.text === "st" && expression.name.text === "do" && fieldSetters.has(name.text)) {
|
|
2138
2211
|
found = name.text;
|
|
2139
2212
|
return;
|
|
2140
2213
|
}
|
|
2141
2214
|
}
|
|
2142
|
-
|
|
2215
|
+
ts15.forEachChild(current, visit);
|
|
2143
2216
|
};
|
|
2144
2217
|
visit(node);
|
|
2145
2218
|
return found;
|
|
@@ -2151,7 +2224,7 @@ class FormSetterScanner {
|
|
|
2151
2224
|
|
|
2152
2225
|
// pkgs/@akanjs/devkit/kindBranchScanner.ts
|
|
2153
2226
|
import path7 from "path";
|
|
2154
|
-
import
|
|
2227
|
+
import ts16 from "typescript";
|
|
2155
2228
|
|
|
2156
2229
|
class KindBranchScanner {
|
|
2157
2230
|
static rule = "akan.global.kind-branch";
|
|
@@ -2159,10 +2232,10 @@ class KindBranchScanner {
|
|
|
2159
2232
|
static #kindName = /(Kind|Type|Mode)$/;
|
|
2160
2233
|
static #kindSubject = /^(kind|type|mode)$|[a-z](Kind|Type|Mode)$/;
|
|
2161
2234
|
static #equalities = new Set([
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2235
|
+
ts16.SyntaxKind.EqualsEqualsEqualsToken,
|
|
2236
|
+
ts16.SyntaxKind.ExclamationEqualsEqualsToken,
|
|
2237
|
+
ts16.SyntaxKind.EqualsEqualsToken,
|
|
2238
|
+
ts16.SyntaxKind.ExclamationEqualsToken
|
|
2166
2239
|
]);
|
|
2167
2240
|
scan(sourceFiles) {
|
|
2168
2241
|
const enums = sourceFiles.flatMap((sourceFile) => KindBranchScanner.#enumsOf(sourceFile));
|
|
@@ -2214,7 +2287,7 @@ class KindBranchScanner {
|
|
|
2214
2287
|
static #sitesIn({ file, sourceFile }, ownersByValue) {
|
|
2215
2288
|
const sites = [];
|
|
2216
2289
|
const record = (literal, subject) => {
|
|
2217
|
-
if (!
|
|
2290
|
+
if (!ts16.isStringLiteralLike(literal) || !ownersByValue.has(literal.text))
|
|
2218
2291
|
return;
|
|
2219
2292
|
if (!KindBranchScanner.#isKindSubject(subject))
|
|
2220
2293
|
return;
|
|
@@ -2225,28 +2298,28 @@ class KindBranchScanner {
|
|
|
2225
2298
|
});
|
|
2226
2299
|
};
|
|
2227
2300
|
const visit = (node) => {
|
|
2228
|
-
if (
|
|
2301
|
+
if (ts16.isBinaryExpression(node) && KindBranchScanner.#equalities.has(node.operatorToken.kind)) {
|
|
2229
2302
|
record(node.left, node.right);
|
|
2230
2303
|
record(node.right, node.left);
|
|
2231
|
-
} else if (
|
|
2304
|
+
} else if (ts16.isCaseClause(node) && ts16.isSwitchStatement(node.parent.parent))
|
|
2232
2305
|
record(node.expression, node.parent.parent.expression);
|
|
2233
|
-
|
|
2306
|
+
ts16.forEachChild(node, visit);
|
|
2234
2307
|
};
|
|
2235
2308
|
visit(sourceFile);
|
|
2236
2309
|
return sites;
|
|
2237
2310
|
}
|
|
2238
2311
|
static #isKindSubject(subject) {
|
|
2239
2312
|
let current = subject;
|
|
2240
|
-
while (
|
|
2313
|
+
while (ts16.isParenthesizedExpression(current) || ts16.isAsExpression(current) || ts16.isNonNullExpression(current))
|
|
2241
2314
|
current = current.expression;
|
|
2242
|
-
const name =
|
|
2315
|
+
const name = ts16.isIdentifier(current) ? current.text : ts16.isPropertyAccessExpression(current) ? current.name.text : ts16.isElementAccessExpression(current) && ts16.isStringLiteralLike(current.argumentExpression) ? current.argumentExpression.text : "";
|
|
2243
2316
|
return KindBranchScanner.#kindSubject.test(name);
|
|
2244
2317
|
}
|
|
2245
2318
|
static #enumsOf({ file, sourceFile }) {
|
|
2246
2319
|
if (!/^(apps|libs)\/[^/]+\/lib\/.+\.constant\.ts$/.test(file))
|
|
2247
2320
|
return [];
|
|
2248
2321
|
return sourceFile.statements.flatMap((statement) => {
|
|
2249
|
-
if (!
|
|
2322
|
+
if (!ts16.isClassDeclaration(statement) || !statement.name)
|
|
2250
2323
|
return [];
|
|
2251
2324
|
if (!KindBranchScanner.#kindName.test(statement.name.text))
|
|
2252
2325
|
return [];
|
|
@@ -2271,16 +2344,16 @@ class KindBranchScanner {
|
|
|
2271
2344
|
static #enumValuesOf(statement) {
|
|
2272
2345
|
for (const clause of statement.heritageClauses ?? [])
|
|
2273
2346
|
for (const { expression } of clause.types) {
|
|
2274
|
-
if (!
|
|
2347
|
+
if (!ts16.isCallExpression(expression) || !ts16.isIdentifier(expression.expression))
|
|
2275
2348
|
continue;
|
|
2276
2349
|
if (expression.expression.text !== "enumOf")
|
|
2277
2350
|
continue;
|
|
2278
2351
|
let list = expression.arguments[1];
|
|
2279
|
-
while (list && (
|
|
2352
|
+
while (list && (ts16.isAsExpression(list) || ts16.isParenthesizedExpression(list)))
|
|
2280
2353
|
list = list.expression;
|
|
2281
|
-
if (!list || !
|
|
2354
|
+
if (!list || !ts16.isArrayLiteralExpression(list))
|
|
2282
2355
|
return null;
|
|
2283
|
-
return list.elements.filter(
|
|
2356
|
+
return list.elements.filter(ts16.isStringLiteralLike).map(({ text }) => text);
|
|
2284
2357
|
}
|
|
2285
2358
|
return null;
|
|
2286
2359
|
}
|
|
@@ -2295,16 +2368,19 @@ class MaintainabilityExceptionScanner {
|
|
|
2295
2368
|
static #shapeFix = "Many reasoned exceptions under one rule mean its threshold is wrong: fix the limit in MaintainabilityLimits rather than record another. Otherwise shrink the code, and `akan lint` lowers each entry and drops it once it passes.";
|
|
2296
2369
|
static #correctnessFix = "A write rule takes no exception: send the writes through one store action and one endpoint (`akan workflow plan add-mutation`), and `akan lint` drops the entry.";
|
|
2297
2370
|
async scan(workspaceRoot) {
|
|
2298
|
-
const sysPaths = await Promise.all(["apps", "libs"].map(
|
|
2299
|
-
const absoluteRoot = path8.join(workspaceRoot, sysRoot);
|
|
2300
|
-
if (!existsSync2(absoluteRoot))
|
|
2301
|
-
return [];
|
|
2302
|
-
const entries = await readdir(absoluteRoot, { withFileTypes: true });
|
|
2303
|
-
return entries.filter((entry) => entry.isDirectory()).map((entry) => `${sysRoot}/${entry.name}`);
|
|
2304
|
-
}));
|
|
2371
|
+
const sysPaths = await Promise.all(["apps", "libs", "pkgs"].map((sysRoot) => MaintainabilityExceptionScanner.#dirsIn(workspaceRoot, sysRoot)));
|
|
2305
2372
|
const warnings = await Promise.all(sysPaths.flat().map((sysPath) => MaintainabilityExceptionScanner.#scanSys(workspaceRoot, sysPath)));
|
|
2306
2373
|
return warnings.flat();
|
|
2307
2374
|
}
|
|
2375
|
+
static async#dirsIn(workspaceRoot, root) {
|
|
2376
|
+
const absoluteRoot = path8.join(workspaceRoot, root);
|
|
2377
|
+
if (!existsSync2(absoluteRoot))
|
|
2378
|
+
return [];
|
|
2379
|
+
const entries = await readdir(absoluteRoot, { withFileTypes: true });
|
|
2380
|
+
const dirs = entries.filter((entry) => entry.isDirectory()).map((entry) => `${root}/${entry.name}`);
|
|
2381
|
+
const nested = await Promise.all(dirs.map(async (dir) => root === "pkgs" && path8.posix.basename(dir).startsWith("@") ? await MaintainabilityExceptionScanner.#dirsIn(workspaceRoot, dir) : [dir]));
|
|
2382
|
+
return nested.flat();
|
|
2383
|
+
}
|
|
2308
2384
|
static async#scanSys(workspaceRoot, sysPath) {
|
|
2309
2385
|
const file = `${sysPath}/${MaintainabilityBaseline.fileName}`;
|
|
2310
2386
|
const absolutePath = path8.join(workspaceRoot, file);
|
|
@@ -2346,10 +2422,10 @@ class MaintainabilityExceptionScanner {
|
|
|
2346
2422
|
}
|
|
2347
2423
|
|
|
2348
2424
|
// pkgs/@akanjs/devkit/ssrScanner.ts
|
|
2349
|
-
import
|
|
2425
|
+
import ts18 from "typescript";
|
|
2350
2426
|
|
|
2351
2427
|
// pkgs/@akanjs/devkit/renderMutationScanner.ts
|
|
2352
|
-
import
|
|
2428
|
+
import ts17 from "typescript";
|
|
2353
2429
|
|
|
2354
2430
|
class RenderMutationScanner {
|
|
2355
2431
|
static rule = "akan.ssr.render-mutation";
|
|
@@ -2378,7 +2454,7 @@ class RenderMutationScanner {
|
|
|
2378
2454
|
const helper = follow ? RenderMutationScanner.#helperOf(node, functions) : undefined;
|
|
2379
2455
|
if (helper)
|
|
2380
2456
|
helpers.add(helper);
|
|
2381
|
-
|
|
2457
|
+
ts17.forEachChild(node, (child) => visit(child, follow));
|
|
2382
2458
|
};
|
|
2383
2459
|
for (const body of RenderMutationScanner.#renderBodiesOf(sourceFile, functions))
|
|
2384
2460
|
visit(body, true);
|
|
@@ -2395,7 +2471,7 @@ class RenderMutationScanner {
|
|
|
2395
2471
|
}));
|
|
2396
2472
|
}
|
|
2397
2473
|
#isRenderMutation(file, node, fetchNames) {
|
|
2398
|
-
if (!
|
|
2474
|
+
if (!ts17.isCallExpression(node))
|
|
2399
2475
|
return false;
|
|
2400
2476
|
const name = RenderMutationScanner.#endpointOf(node.expression, fetchNames);
|
|
2401
2477
|
if (!name || !this.#mutations.isMutation(file, name))
|
|
@@ -2403,64 +2479,64 @@ class RenderMutationScanner {
|
|
|
2403
2479
|
return !RenderMutationScanner.#optsIn(node, this.#mutations.policyIndexOf(file, name));
|
|
2404
2480
|
}
|
|
2405
2481
|
static #isEventHandler(node) {
|
|
2406
|
-
return
|
|
2482
|
+
return ts17.isJsxAttribute(node) && ts17.isIdentifier(node.name) && /^on[A-Z]/.test(node.name.text);
|
|
2407
2483
|
}
|
|
2408
2484
|
static #endpointOf(callee, fetchNames) {
|
|
2409
|
-
if (
|
|
2485
|
+
if (ts17.isPropertyAccessExpression(callee))
|
|
2410
2486
|
return RenderMutationScanner.#isFetch(callee.expression, fetchNames) ? callee.name.text : null;
|
|
2411
|
-
if (
|
|
2487
|
+
if (ts17.isElementAccessExpression(callee) && ts17.isStringLiteralLike(callee.argumentExpression))
|
|
2412
2488
|
return RenderMutationScanner.#isFetch(callee.expression, fetchNames) ? callee.argumentExpression.text : null;
|
|
2413
2489
|
return null;
|
|
2414
2490
|
}
|
|
2415
2491
|
static #isFetch(expression, fetchNames) {
|
|
2416
|
-
return
|
|
2492
|
+
return ts17.isIdentifier(expression) && fetchNames.has(expression.text);
|
|
2417
2493
|
}
|
|
2418
2494
|
static #optsIn(call, policyIndex) {
|
|
2419
2495
|
if (policyIndex === null)
|
|
2420
2496
|
return false;
|
|
2421
2497
|
const leading = call.arguments.slice(0, policyIndex + 1);
|
|
2422
|
-
if (leading.some((argument) =>
|
|
2498
|
+
if (leading.some((argument) => ts17.isSpreadElement(argument)))
|
|
2423
2499
|
return true;
|
|
2424
2500
|
const policy = leading[policyIndex];
|
|
2425
2501
|
return policy ? RenderMutationScanner.#policyOptsIn(policy) : false;
|
|
2426
2502
|
}
|
|
2427
2503
|
static #policyOptsIn(argument) {
|
|
2428
2504
|
const policy = RenderMutationScanner.#unwrap(argument);
|
|
2429
|
-
if (!
|
|
2505
|
+
if (!ts17.isObjectLiteralExpression(policy))
|
|
2430
2506
|
return !RenderMutationScanner.#cannotBePolicy(policy);
|
|
2431
2507
|
return policy.properties.some((property) => {
|
|
2432
|
-
if (
|
|
2508
|
+
if (ts17.isSpreadAssignment(property))
|
|
2433
2509
|
return true;
|
|
2434
|
-
if (!
|
|
2510
|
+
if (!ts17.isPropertyAssignment(property) && !ts17.isShorthandPropertyAssignment(property))
|
|
2435
2511
|
return false;
|
|
2436
|
-
if (!(
|
|
2512
|
+
if (!(ts17.isIdentifier(property.name) || ts17.isStringLiteral(property.name)))
|
|
2437
2513
|
return false;
|
|
2438
2514
|
if (property.name.text !== "duringRender")
|
|
2439
2515
|
return false;
|
|
2440
|
-
if (
|
|
2516
|
+
if (ts17.isShorthandPropertyAssignment(property))
|
|
2441
2517
|
return true;
|
|
2442
2518
|
const value = RenderMutationScanner.#unwrap(property.initializer);
|
|
2443
|
-
return value.kind !==
|
|
2519
|
+
return value.kind !== ts17.SyntaxKind.FalseKeyword && !(ts17.isIdentifier(value) && value.text === "undefined");
|
|
2444
2520
|
});
|
|
2445
2521
|
}
|
|
2446
2522
|
static #unwrap(expression) {
|
|
2447
2523
|
let current = expression;
|
|
2448
|
-
while (
|
|
2524
|
+
while (ts17.isParenthesizedExpression(current) || ts17.isAsExpression(current) || ts17.isSatisfiesExpression(current) || ts17.isNonNullExpression(current) || ts17.isTypeAssertionExpression(current))
|
|
2449
2525
|
current = current.expression;
|
|
2450
2526
|
return current;
|
|
2451
2527
|
}
|
|
2452
2528
|
static #cannotBePolicy(expression) {
|
|
2453
|
-
if (
|
|
2529
|
+
if (ts17.isIdentifier(expression))
|
|
2454
2530
|
return expression.text === "undefined";
|
|
2455
|
-
return
|
|
2531
|
+
return ts17.isLiteralExpression(expression) || ts17.isNoSubstitutionTemplateLiteral(expression) || ts17.isTemplateExpression(expression) || ts17.isArrayLiteralExpression(expression) || ts17.isArrowFunction(expression) || ts17.isFunctionExpression(expression) || ts17.isVoidExpression(expression) || ts17.isPrefixUnaryExpression(expression) || [ts17.SyntaxKind.NullKeyword, ts17.SyntaxKind.TrueKeyword, ts17.SyntaxKind.FalseKeyword].includes(expression.kind);
|
|
2456
2532
|
}
|
|
2457
2533
|
static #fetchBindingsOf(sourceFile) {
|
|
2458
2534
|
const names = new Set;
|
|
2459
2535
|
for (const statement of sourceFile.statements) {
|
|
2460
|
-
if (!
|
|
2536
|
+
if (!ts17.isImportDeclaration(statement) || statement.importClause?.isTypeOnly)
|
|
2461
2537
|
continue;
|
|
2462
2538
|
const bindings = statement.importClause?.namedBindings;
|
|
2463
|
-
if (!bindings || !
|
|
2539
|
+
if (!bindings || !ts17.isNamedImports(bindings))
|
|
2464
2540
|
continue;
|
|
2465
2541
|
for (const element of bindings.elements)
|
|
2466
2542
|
if (!element.isTypeOnly && (element.propertyName ?? element.name).text === "fetch")
|
|
@@ -2471,35 +2547,35 @@ class RenderMutationScanner {
|
|
|
2471
2547
|
static #functionsOf(sourceFile) {
|
|
2472
2548
|
const functions = new Map;
|
|
2473
2549
|
for (const statement of sourceFile.statements) {
|
|
2474
|
-
if (
|
|
2550
|
+
if (ts17.isFunctionDeclaration(statement) && statement.name && statement.body)
|
|
2475
2551
|
functions.set(statement.name.text, statement.body);
|
|
2476
|
-
if (!
|
|
2552
|
+
if (!ts17.isVariableStatement(statement))
|
|
2477
2553
|
continue;
|
|
2478
2554
|
for (const declaration of statement.declarationList.declarations) {
|
|
2479
2555
|
const initializer = declaration.initializer && RenderMutationScanner.#unwrap(declaration.initializer);
|
|
2480
|
-
if (!
|
|
2556
|
+
if (!ts17.isIdentifier(declaration.name) || !initializer)
|
|
2481
2557
|
continue;
|
|
2482
|
-
if (
|
|
2558
|
+
if (ts17.isArrowFunction(initializer) || ts17.isFunctionExpression(initializer))
|
|
2483
2559
|
functions.set(declaration.name.text, initializer.body);
|
|
2484
2560
|
}
|
|
2485
2561
|
}
|
|
2486
2562
|
return functions;
|
|
2487
2563
|
}
|
|
2488
2564
|
static #helperOf(node, functions) {
|
|
2489
|
-
const callee =
|
|
2490
|
-
return callee &&
|
|
2565
|
+
const callee = ts17.isCallExpression(node) ? node.expression : ts17.isJsxSelfClosingElement(node) || ts17.isJsxOpeningElement(node) ? node.tagName : undefined;
|
|
2566
|
+
return callee && ts17.isIdentifier(callee) ? functions.get(callee.text) : undefined;
|
|
2491
2567
|
}
|
|
2492
2568
|
static #renderBodiesOf(sourceFile, functions) {
|
|
2493
2569
|
const bodies = [];
|
|
2494
|
-
const bodyOf = (node) =>
|
|
2570
|
+
const bodyOf = (node) => ts17.isIdentifier(node) ? functions.get(node.text) : node;
|
|
2495
2571
|
const visit = (node) => {
|
|
2496
|
-
if (
|
|
2572
|
+
if (ts17.isCallExpression(node) && ts17.isPropertyAccessExpression(node.expression) && RenderMutationScanner.#stages.has(node.expression.name.text) && RenderMutationScanner.#isRouteChain(node.expression.expression))
|
|
2497
2573
|
for (const argument of node.arguments) {
|
|
2498
2574
|
const body = bodyOf(argument);
|
|
2499
2575
|
if (body)
|
|
2500
2576
|
bodies.push(body);
|
|
2501
2577
|
}
|
|
2502
|
-
|
|
2578
|
+
ts17.forEachChild(node, visit);
|
|
2503
2579
|
};
|
|
2504
2580
|
visit(sourceFile);
|
|
2505
2581
|
for (const statement of sourceFile.statements) {
|
|
@@ -2511,24 +2587,24 @@ class RenderMutationScanner {
|
|
|
2511
2587
|
}
|
|
2512
2588
|
static #isRouteChain(expression) {
|
|
2513
2589
|
let current = expression;
|
|
2514
|
-
while (
|
|
2515
|
-
if (
|
|
2590
|
+
while (ts17.isCallExpression(current)) {
|
|
2591
|
+
if (ts17.isIdentifier(current.expression))
|
|
2516
2592
|
return RenderMutationScanner.#builders.has(current.expression.text);
|
|
2517
|
-
if (!
|
|
2593
|
+
if (!ts17.isPropertyAccessExpression(current.expression))
|
|
2518
2594
|
return false;
|
|
2519
2595
|
current = current.expression.expression;
|
|
2520
2596
|
}
|
|
2521
2597
|
return false;
|
|
2522
2598
|
}
|
|
2523
2599
|
static #legacyPageOf(statement, functions) {
|
|
2524
|
-
if (
|
|
2525
|
-
return statement.modifiers?.some((modifier) => modifier.kind ===
|
|
2526
|
-
if (!
|
|
2600
|
+
if (ts17.isFunctionDeclaration(statement))
|
|
2601
|
+
return statement.modifiers?.some((modifier) => modifier.kind === ts17.SyntaxKind.DefaultKeyword) ? statement.body : undefined;
|
|
2602
|
+
if (!ts17.isExportAssignment(statement))
|
|
2527
2603
|
return;
|
|
2528
2604
|
const expression = RenderMutationScanner.#unwrap(statement.expression);
|
|
2529
|
-
if (
|
|
2605
|
+
if (ts17.isIdentifier(expression))
|
|
2530
2606
|
return functions.get(expression.text);
|
|
2531
|
-
return
|
|
2607
|
+
return ts17.isArrowFunction(expression) || ts17.isFunctionExpression(expression) ? expression.body : undefined;
|
|
2532
2608
|
}
|
|
2533
2609
|
}
|
|
2534
2610
|
|
|
@@ -2613,18 +2689,18 @@ class SsrScanner {
|
|
|
2613
2689
|
return warnings;
|
|
2614
2690
|
}
|
|
2615
2691
|
#isMountEffect(sourceFile, node) {
|
|
2616
|
-
if (!
|
|
2692
|
+
if (!ts18.isCallExpression(node))
|
|
2617
2693
|
return false;
|
|
2618
2694
|
const callee = node.expression.getText(sourceFile);
|
|
2619
2695
|
if (callee !== "useEffect" && callee !== "useLayoutEffect")
|
|
2620
2696
|
return false;
|
|
2621
2697
|
const deps = node.arguments[1];
|
|
2622
|
-
return !!deps &&
|
|
2698
|
+
return !!deps && ts18.isArrayLiteralExpression(deps) && deps.elements.length === 0;
|
|
2623
2699
|
}
|
|
2624
2700
|
#getLoadCalls(sourceFile, node) {
|
|
2625
2701
|
const calls = [];
|
|
2626
2702
|
SsrScanner.#walk(node, (child) => {
|
|
2627
|
-
if (!
|
|
2703
|
+
if (!ts18.isCallExpression(child))
|
|
2628
2704
|
return;
|
|
2629
2705
|
const callee = child.expression.getText(sourceFile);
|
|
2630
2706
|
if (/^fetch\.[a-z]/.test(callee) || /^st\.do\.(init|get|view|load|list|count|insight)[A-Z]/.test(callee))
|
|
@@ -2637,7 +2713,7 @@ class SsrScanner {
|
|
|
2637
2713
|
return [];
|
|
2638
2714
|
const warnings = [];
|
|
2639
2715
|
SsrScanner.#walk(sourceFile.sourceFile, (node) => {
|
|
2640
|
-
if (
|
|
2716
|
+
if (ts18.isCallExpression(node) && node.expression.getText(sourceFile.sourceFile) === "useState")
|
|
2641
2717
|
warnings.push(fileWarning("akan.ssr.template-client-state", "ssr", sourceFile.file, "Template holds form state in useState. Templates are store-driven and carry no local state.", this.#getLine(sourceFile.sourceFile, node)));
|
|
2642
2718
|
});
|
|
2643
2719
|
return warnings;
|
|
@@ -2680,14 +2756,14 @@ class SsrScanner {
|
|
|
2680
2756
|
return components;
|
|
2681
2757
|
}
|
|
2682
2758
|
#getComponentNodes(statement) {
|
|
2683
|
-
if (
|
|
2759
|
+
if (ts18.isFunctionDeclaration(statement) && statement.body)
|
|
2684
2760
|
return [{ name: statement.name?.text ?? "default", node: statement.body }];
|
|
2685
|
-
if (!
|
|
2761
|
+
if (!ts18.isVariableStatement(statement))
|
|
2686
2762
|
return [];
|
|
2687
2763
|
return statement.declarationList.declarations.flatMap((declaration) => {
|
|
2688
|
-
if (!
|
|
2764
|
+
if (!ts18.isIdentifier(declaration.name) || !declaration.initializer)
|
|
2689
2765
|
return [];
|
|
2690
|
-
if (!
|
|
2766
|
+
if (!ts18.isArrowFunction(declaration.initializer) && !ts18.isFunctionExpression(declaration.initializer))
|
|
2691
2767
|
return [];
|
|
2692
2768
|
return [{ name: declaration.name.text, node: declaration.initializer }];
|
|
2693
2769
|
});
|
|
@@ -2695,7 +2771,7 @@ class SsrScanner {
|
|
|
2695
2771
|
#getTouches(sourceFile, node) {
|
|
2696
2772
|
const touches = [];
|
|
2697
2773
|
SsrScanner.#walk(node, (child) => {
|
|
2698
|
-
if (
|
|
2774
|
+
if (ts18.isCallExpression(child)) {
|
|
2699
2775
|
const callee = child.expression.getText(sourceFile);
|
|
2700
2776
|
const bareName = callee.split(".").pop() ?? callee;
|
|
2701
2777
|
if (callee === "createContext" || callee === "lazy")
|
|
@@ -2703,9 +2779,9 @@ class SsrScanner {
|
|
|
2703
2779
|
else if (/^use[A-Z]/.test(bareName) && !SsrScanner.#serverSafeCalls.has(bareName))
|
|
2704
2780
|
touches.push(bareName);
|
|
2705
2781
|
}
|
|
2706
|
-
if (
|
|
2782
|
+
if (ts18.isJsxAttribute(child) && /^on[A-Z]/.test(child.name.getText(sourceFile)))
|
|
2707
2783
|
touches.push(child.name.getText(sourceFile));
|
|
2708
|
-
if (
|
|
2784
|
+
if (ts18.isPropertyAccessExpression(child)) {
|
|
2709
2785
|
const root = getAccessRoot(child);
|
|
2710
2786
|
if (root === "st")
|
|
2711
2787
|
touches.push("st");
|
|
@@ -2718,7 +2794,7 @@ class SsrScanner {
|
|
|
2718
2794
|
#getTagNames(sourceFile, node) {
|
|
2719
2795
|
const tags = new Set;
|
|
2720
2796
|
SsrScanner.#walk(node, (child) => {
|
|
2721
|
-
if (
|
|
2797
|
+
if (ts18.isJsxOpeningElement(child) || ts18.isJsxSelfClosingElement(child))
|
|
2722
2798
|
tags.add(child.tagName.getText(sourceFile).split(".")[0]);
|
|
2723
2799
|
});
|
|
2724
2800
|
return tags;
|
|
@@ -2726,7 +2802,7 @@ class SsrScanner {
|
|
|
2726
2802
|
#getMass(node) {
|
|
2727
2803
|
let mass = 0;
|
|
2728
2804
|
SsrScanner.#walk(node, (child) => {
|
|
2729
|
-
if (
|
|
2805
|
+
if (ts18.isJsxOpeningElement(child) || ts18.isJsxSelfClosingElement(child))
|
|
2730
2806
|
mass += 1;
|
|
2731
2807
|
});
|
|
2732
2808
|
return mass;
|
|
@@ -2734,30 +2810,30 @@ class SsrScanner {
|
|
|
2734
2810
|
static #walk(node, visit) {
|
|
2735
2811
|
const walk = (child) => {
|
|
2736
2812
|
visit(child);
|
|
2737
|
-
|
|
2813
|
+
ts18.forEachChild(child, walk);
|
|
2738
2814
|
};
|
|
2739
|
-
|
|
2815
|
+
ts18.forEachChild(node, walk);
|
|
2740
2816
|
}
|
|
2741
2817
|
#hasUseClient(sourceFile) {
|
|
2742
2818
|
const first = sourceFile.statements[0];
|
|
2743
|
-
if (!first || !
|
|
2819
|
+
if (!first || !ts18.isExpressionStatement(first) || !ts18.isStringLiteral(first.expression))
|
|
2744
2820
|
return false;
|
|
2745
2821
|
return first.expression.text === "use client";
|
|
2746
2822
|
}
|
|
2747
2823
|
#hasVendorImport(sourceFile) {
|
|
2748
|
-
return sourceFile.statements.some((statement) =>
|
|
2824
|
+
return sourceFile.statements.some((statement) => ts18.isImportDeclaration(statement) && isVendorSpecifier(getSpecifier(statement)));
|
|
2749
2825
|
}
|
|
2750
2826
|
#getVendorNames(sourceFile) {
|
|
2751
2827
|
const names = new Set;
|
|
2752
2828
|
for (const statement of sourceFile.statements) {
|
|
2753
|
-
if (!
|
|
2829
|
+
if (!ts18.isImportDeclaration(statement) || !isVendorSpecifier(getSpecifier(statement)))
|
|
2754
2830
|
continue;
|
|
2755
2831
|
const clause = statement.importClause;
|
|
2756
2832
|
if (clause?.name)
|
|
2757
2833
|
names.add(clause.name.text);
|
|
2758
|
-
if (clause?.namedBindings &&
|
|
2834
|
+
if (clause?.namedBindings && ts18.isNamespaceImport(clause.namedBindings))
|
|
2759
2835
|
names.add(clause.namedBindings.name.text);
|
|
2760
|
-
if (clause?.namedBindings &&
|
|
2836
|
+
if (clause?.namedBindings && ts18.isNamedImports(clause.namedBindings))
|
|
2761
2837
|
for (const element of clause.namedBindings.elements)
|
|
2762
2838
|
names.add(element.name.text);
|
|
2763
2839
|
}
|
|
@@ -2765,10 +2841,10 @@ class SsrScanner {
|
|
|
2765
2841
|
}
|
|
2766
2842
|
#importsClientRuntime(sourceFile) {
|
|
2767
2843
|
for (const statement of sourceFile.statements) {
|
|
2768
|
-
if (!
|
|
2844
|
+
if (!ts18.isImportDeclaration(statement))
|
|
2769
2845
|
continue;
|
|
2770
2846
|
const bindings = statement.importClause?.namedBindings;
|
|
2771
|
-
if (!bindings || !
|
|
2847
|
+
if (!bindings || !ts18.isNamedImports(bindings))
|
|
2772
2848
|
continue;
|
|
2773
2849
|
if (bindings.elements.some((element) => SsrScanner.#clientRuntimeImports.has(element.name.text)))
|
|
2774
2850
|
return true;
|
|
@@ -2819,7 +2895,7 @@ function getShare(serverMass, clientMass) {
|
|
|
2819
2895
|
return total === 0 ? 1 : serverMass / total;
|
|
2820
2896
|
}
|
|
2821
2897
|
function getSpecifier(statement) {
|
|
2822
|
-
return
|
|
2898
|
+
return ts18.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : "";
|
|
2823
2899
|
}
|
|
2824
2900
|
function isVendorSpecifier(specifier) {
|
|
2825
2901
|
if (specifier === "" || specifier.startsWith(".") || specifier.startsWith("/"))
|
|
@@ -2832,13 +2908,13 @@ function isVendorSpecifier(specifier) {
|
|
|
2832
2908
|
}
|
|
2833
2909
|
function getAccessRoot(node) {
|
|
2834
2910
|
let current = node;
|
|
2835
|
-
while (
|
|
2911
|
+
while (ts18.isPropertyAccessExpression(current))
|
|
2836
2912
|
current = current.expression;
|
|
2837
|
-
return
|
|
2913
|
+
return ts18.isIdentifier(current) ? current.text : "";
|
|
2838
2914
|
}
|
|
2839
2915
|
|
|
2840
2916
|
// pkgs/@akanjs/devkit/testOnlyExportScanner.ts
|
|
2841
|
-
import
|
|
2917
|
+
import ts19 from "typescript";
|
|
2842
2918
|
|
|
2843
2919
|
class TestOnlyExportScanner {
|
|
2844
2920
|
static rule = "akan.global.test-only-export";
|
|
@@ -2889,9 +2965,9 @@ class TestOnlyExportScanner {
|
|
|
2889
2965
|
static #identifierLinesOf(sourceFile) {
|
|
2890
2966
|
const lines = new Map;
|
|
2891
2967
|
const visit = (node) => {
|
|
2892
|
-
if (
|
|
2968
|
+
if (ts19.isIdentifier(node) && !lines.has(node.text))
|
|
2893
2969
|
lines.set(node.text, sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1);
|
|
2894
|
-
|
|
2970
|
+
ts19.forEachChild(node, visit);
|
|
2895
2971
|
};
|
|
2896
2972
|
visit(sourceFile);
|
|
2897
2973
|
return lines;
|
|
@@ -2908,15 +2984,15 @@ class TestOnlyExportScanner {
|
|
|
2908
2984
|
});
|
|
2909
2985
|
}
|
|
2910
2986
|
static #isNamedExport(statement) {
|
|
2911
|
-
if (!
|
|
2987
|
+
if (!ts19.canHaveModifiers(statement))
|
|
2912
2988
|
return false;
|
|
2913
|
-
const modifiers =
|
|
2914
|
-
return modifiers.some((modifier) => modifier.kind ===
|
|
2989
|
+
const modifiers = ts19.getModifiers(statement) ?? [];
|
|
2990
|
+
return modifiers.some((modifier) => modifier.kind === ts19.SyntaxKind.ExportKeyword) && !modifiers.some((modifier) => modifier.kind === ts19.SyntaxKind.DefaultKeyword);
|
|
2915
2991
|
}
|
|
2916
2992
|
static #declaredNamesOf(statement) {
|
|
2917
|
-
if (
|
|
2918
|
-
return statement.declarationList.declarations.map((declaration) => declaration.name).filter((name) =>
|
|
2919
|
-
if (
|
|
2993
|
+
if (ts19.isVariableStatement(statement))
|
|
2994
|
+
return statement.declarationList.declarations.map((declaration) => declaration.name).filter((name) => ts19.isIdentifier(name));
|
|
2995
|
+
if (ts19.isFunctionDeclaration(statement) || ts19.isClassDeclaration(statement) || ts19.isInterfaceDeclaration(statement) || ts19.isTypeAliasDeclaration(statement) || ts19.isEnumDeclaration(statement))
|
|
2920
2996
|
return statement.name ? [statement.name] : [];
|
|
2921
2997
|
return [];
|
|
2922
2998
|
}
|
|
@@ -2926,10 +3002,10 @@ class TestOnlyExportScanner {
|
|
|
2926
3002
|
const visit = (node) => {
|
|
2927
3003
|
if (used || ownStatements.has(node))
|
|
2928
3004
|
return;
|
|
2929
|
-
if (
|
|
3005
|
+
if (ts19.isIdentifier(node) && node.text === name)
|
|
2930
3006
|
used = true;
|
|
2931
3007
|
else
|
|
2932
|
-
|
|
3008
|
+
ts19.forEachChild(node, visit);
|
|
2933
3009
|
};
|
|
2934
3010
|
visit(sourceFile);
|
|
2935
3011
|
return used;
|
|
@@ -3077,7 +3153,7 @@ class AkanQualityScanner {
|
|
|
3077
3153
|
file,
|
|
3078
3154
|
absolutePath,
|
|
3079
3155
|
content,
|
|
3080
|
-
sourceFile:
|
|
3156
|
+
sourceFile: ts20.createSourceFile(file, content, ts20.ScriptTarget.Latest, true, getScriptKind(file))
|
|
3081
3157
|
};
|
|
3082
3158
|
}
|
|
3083
3159
|
async#readTextFile(workspaceRoot, file) {
|
|
@@ -3276,13 +3352,13 @@ function getExportedFunctionLikes(sourceFile) {
|
|
|
3276
3352
|
duplicateNameExempt: nameExempt || isConventionDuplicateNameExempt(sourceFile.file, isEnumClass)
|
|
3277
3353
|
});
|
|
3278
3354
|
for (const statement of sourceFile.sourceFile.statements) {
|
|
3279
|
-
if (
|
|
3355
|
+
if (ts20.isFunctionDeclaration(statement) && statement.name && isExported(statement))
|
|
3280
3356
|
add(statement.name.text, "function", statement, statement.body);
|
|
3281
|
-
if (
|
|
3357
|
+
if (ts20.isClassDeclaration(statement) && statement.name && isExported(statement))
|
|
3282
3358
|
add(statement.name.text, "class", statement, statement, isEnumClassStatement(sourceFile.sourceFile, statement));
|
|
3283
|
-
if (
|
|
3359
|
+
if (ts20.isVariableStatement(statement) && isExported(statement)) {
|
|
3284
3360
|
for (const declaration of statement.declarationList.declarations) {
|
|
3285
|
-
if (!
|
|
3361
|
+
if (!ts20.isIdentifier(declaration.name) || !isFunctionLikeInitializer(declaration.initializer))
|
|
3286
3362
|
continue;
|
|
3287
3363
|
add(declaration.name.text, "function-variable", declaration, declaration.initializer);
|
|
3288
3364
|
}
|
|
@@ -3310,14 +3386,14 @@ function isConventionDuplicateNameExempt(file, isEnumClass) {
|
|
|
3310
3386
|
return false;
|
|
3311
3387
|
}
|
|
3312
3388
|
function isEnumClassStatement(sourceFile, statement) {
|
|
3313
|
-
if (!
|
|
3389
|
+
if (!ts20.isClassDeclaration(statement))
|
|
3314
3390
|
return false;
|
|
3315
|
-
const heritageClause = statement.heritageClauses?.find((clause) => clause.token ===
|
|
3391
|
+
const heritageClause = statement.heritageClauses?.find((clause) => clause.token === ts20.SyntaxKind.ExtendsKeyword);
|
|
3316
3392
|
const expression = heritageClause?.types[0]?.expression;
|
|
3317
3393
|
return !!expression && expression.getText(sourceFile).startsWith("enumOf(");
|
|
3318
3394
|
}
|
|
3319
3395
|
function getExportedClassNames(sourceFile) {
|
|
3320
|
-
return sourceFile.statements.filter((statement) =>
|
|
3396
|
+
return sourceFile.statements.filter((statement) => ts20.isClassDeclaration(statement)).filter((statement) => isExported(statement)).map((statement) => statement.name?.text).filter((name) => !!name);
|
|
3321
3397
|
}
|
|
3322
3398
|
function isComponentDeclarationFile(file) {
|
|
3323
3399
|
if (!file.endsWith(".tsx"))
|
|
@@ -3333,7 +3409,7 @@ function isComponentDeclarationFile(file) {
|
|
|
3333
3409
|
function getComponentFileDeclarations(sourceFile) {
|
|
3334
3410
|
const reExportedNames = new Set;
|
|
3335
3411
|
for (const statement of sourceFile.statements) {
|
|
3336
|
-
if (
|
|
3412
|
+
if (ts20.isExportDeclaration(statement) && statement.exportClause && ts20.isNamedExports(statement.exportClause)) {
|
|
3337
3413
|
for (const element of statement.exportClause.elements)
|
|
3338
3414
|
reExportedNames.add((element.propertyName ?? element.name).text);
|
|
3339
3415
|
}
|
|
@@ -3343,19 +3419,19 @@ function getComponentFileDeclarations(sourceFile) {
|
|
|
3343
3419
|
const isDefaultExport = isDefaultExportStatement(statement);
|
|
3344
3420
|
const inlineExported = isExported(statement);
|
|
3345
3421
|
const add = (name, kind, line) => declarations.push({ name, kind, line, exported: inlineExported || reExportedNames.has(name), isDefaultExport });
|
|
3346
|
-
if (
|
|
3422
|
+
if (ts20.isInterfaceDeclaration(statement))
|
|
3347
3423
|
add(statement.name.text, "interface", getLine(sourceFile, statement));
|
|
3348
|
-
else if (
|
|
3424
|
+
else if (ts20.isTypeAliasDeclaration(statement))
|
|
3349
3425
|
add(statement.name.text, "type", getLine(sourceFile, statement));
|
|
3350
|
-
else if (
|
|
3426
|
+
else if (ts20.isEnumDeclaration(statement))
|
|
3351
3427
|
add(statement.name.text, "enum", getLine(sourceFile, statement));
|
|
3352
|
-
else if (
|
|
3428
|
+
else if (ts20.isFunctionDeclaration(statement) && statement.name)
|
|
3353
3429
|
add(statement.name.text, "function", getLine(sourceFile, statement));
|
|
3354
|
-
else if (
|
|
3430
|
+
else if (ts20.isClassDeclaration(statement) && statement.name)
|
|
3355
3431
|
add(statement.name.text, "class", getLine(sourceFile, statement));
|
|
3356
|
-
else if (
|
|
3432
|
+
else if (ts20.isVariableStatement(statement)) {
|
|
3357
3433
|
for (const declaration of statement.declarationList.declarations) {
|
|
3358
|
-
if (!
|
|
3434
|
+
if (!ts20.isIdentifier(declaration.name))
|
|
3359
3435
|
continue;
|
|
3360
3436
|
const kind = isFunctionLikeInitializer(declaration.initializer) ? "function" : "variable";
|
|
3361
3437
|
add(declaration.name.text, kind, getLine(sourceFile, declaration));
|
|
@@ -3367,15 +3443,15 @@ function getComponentFileDeclarations(sourceFile) {
|
|
|
3367
3443
|
function getCompoundComponentNames(sourceFile) {
|
|
3368
3444
|
const names = new Set;
|
|
3369
3445
|
for (const statement of sourceFile.statements) {
|
|
3370
|
-
if (!
|
|
3446
|
+
if (!ts20.isExpressionStatement(statement))
|
|
3371
3447
|
continue;
|
|
3372
3448
|
const { expression } = statement;
|
|
3373
|
-
if (!
|
|
3449
|
+
if (!ts20.isBinaryExpression(expression) || expression.operatorToken.kind !== ts20.SyntaxKind.EqualsToken)
|
|
3374
3450
|
continue;
|
|
3375
|
-
if (!
|
|
3451
|
+
if (!ts20.isPropertyAccessExpression(expression.left) || !isPascalCaseName(expression.left.name.text))
|
|
3376
3452
|
continue;
|
|
3377
3453
|
names.add(expression.left.name.text);
|
|
3378
|
-
if (
|
|
3454
|
+
if (ts20.isIdentifier(expression.right) && isPascalCaseName(expression.right.text))
|
|
3379
3455
|
names.add(expression.right.text);
|
|
3380
3456
|
}
|
|
3381
3457
|
return names;
|
|
@@ -3395,11 +3471,11 @@ function isPascalCaseName(name) {
|
|
|
3395
3471
|
return /^[A-Z]/.test(name) && !/^[A-Z0-9_]+$/.test(name);
|
|
3396
3472
|
}
|
|
3397
3473
|
function isDefaultExportStatement(statement) {
|
|
3398
|
-
if (
|
|
3474
|
+
if (ts20.isExportAssignment(statement))
|
|
3399
3475
|
return !statement.isExportEquals;
|
|
3400
|
-
if (!
|
|
3476
|
+
if (!ts20.canHaveModifiers(statement))
|
|
3401
3477
|
return false;
|
|
3402
|
-
return !!
|
|
3478
|
+
return !!ts20.getModifiers(statement)?.some((modifier) => modifier.kind === ts20.SyntaxKind.DefaultKeyword);
|
|
3403
3479
|
}
|
|
3404
3480
|
function getBangCommentWarnings(sourceFile) {
|
|
3405
3481
|
if (!isClientReachableFile(sourceFile.file))
|
|
@@ -3435,11 +3511,11 @@ function getGlobalMutationWarnings(sourceFile) {
|
|
|
3435
3511
|
const warnings = [];
|
|
3436
3512
|
for (const statement of sourceFile.sourceFile.statements) {
|
|
3437
3513
|
const warn = (rule, message) => warnings.push(fileWarning(rule, "file", sourceFile.file, message, getLine(sourceFile.sourceFile, statement)));
|
|
3438
|
-
if (
|
|
3514
|
+
if (ts20.isModuleDeclaration(statement) && statement.name.getText(sourceFile.sourceFile) === "global")
|
|
3439
3515
|
warn("akan.file.global-declaration", "Global declarations require an explicit low-level integration allowlist.");
|
|
3440
|
-
if (
|
|
3516
|
+
if (ts20.isInterfaceDeclaration(statement) && statement.name.text === "Window")
|
|
3441
3517
|
warn("akan.file.window-augmentation", "Window augmentation should be isolated to approved browser integration files.");
|
|
3442
|
-
if (
|
|
3518
|
+
if (ts20.isExpressionStatement(statement) && statement.expression.getText(sourceFile.sourceFile).includes(".prototype."))
|
|
3443
3519
|
warn("akan.file.prototype-mutation", "Prototype mutation should be avoided or isolated to approved low-level integration files.");
|
|
3444
3520
|
}
|
|
3445
3521
|
return warnings;
|
|
@@ -3456,19 +3532,19 @@ function getTopLevelDeclaration(sourceFile, statement) {
|
|
|
3456
3532
|
exported: isExported(statement),
|
|
3457
3533
|
node: statement
|
|
3458
3534
|
});
|
|
3459
|
-
if (
|
|
3535
|
+
if (ts20.isClassDeclaration(statement) && statement.name)
|
|
3460
3536
|
return [declared(statement.name.text, "class")];
|
|
3461
|
-
if (
|
|
3537
|
+
if (ts20.isFunctionDeclaration(statement) && statement.name)
|
|
3462
3538
|
return [declared(statement.name.text, "function")];
|
|
3463
|
-
if (
|
|
3539
|
+
if (ts20.isInterfaceDeclaration(statement))
|
|
3464
3540
|
return [declared(statement.name.text, "interface")];
|
|
3465
|
-
if (
|
|
3541
|
+
if (ts20.isTypeAliasDeclaration(statement))
|
|
3466
3542
|
return [declared(statement.name.text, "type")];
|
|
3467
|
-
if (
|
|
3543
|
+
if (ts20.isEnumDeclaration(statement))
|
|
3468
3544
|
return [declared(statement.name.text, "enum")];
|
|
3469
|
-
if (
|
|
3470
|
-
return statement.declarationList.declarations.filter((declaration) =>
|
|
3471
|
-
if (
|
|
3545
|
+
if (ts20.isVariableStatement(statement))
|
|
3546
|
+
return statement.declarationList.declarations.filter((declaration) => ts20.isIdentifier(declaration.name)).map((declaration) => declared(declaration.name.text, "variable", getLine(sourceFile, declaration)));
|
|
3547
|
+
if (ts20.isExportDeclaration(statement))
|
|
3472
3548
|
return [{ name: "export declaration", kind: "export", line, exported: true, node: statement }];
|
|
3473
3549
|
return [];
|
|
3474
3550
|
}
|
|
@@ -3556,13 +3632,13 @@ function getModuleInfo(file) {
|
|
|
3556
3632
|
return { moduleName, fileName, kind: "database" };
|
|
3557
3633
|
}
|
|
3558
3634
|
function isExportedConst(declaration) {
|
|
3559
|
-
return declaration.exported &&
|
|
3635
|
+
return declaration.exported && ts20.isVariableStatement(declaration.node) && (declaration.node.declarationList.flags & ts20.NodeFlags.Const) !== 0;
|
|
3560
3636
|
}
|
|
3561
3637
|
function isExported(node) {
|
|
3562
|
-
return !!(
|
|
3638
|
+
return !!(ts20.getCombinedModifierFlags(node) & ts20.ModifierFlags.Export);
|
|
3563
3639
|
}
|
|
3564
3640
|
function isFunctionLikeInitializer(node) {
|
|
3565
|
-
return !!node && (
|
|
3641
|
+
return !!node && (ts20.isArrowFunction(node) || ts20.isFunctionExpression(node));
|
|
3566
3642
|
}
|
|
3567
3643
|
function getBodyFingerprint(sourceFile, node) {
|
|
3568
3644
|
if (!node)
|
|
@@ -3584,7 +3660,7 @@ async function isDirectory(absolutePath) {
|
|
|
3584
3660
|
}
|
|
3585
3661
|
}
|
|
3586
3662
|
function getScriptKind(file) {
|
|
3587
|
-
return file.endsWith(".tsx") ?
|
|
3663
|
+
return file.endsWith(".tsx") ? ts20.ScriptKind.TSX : ts20.ScriptKind.TS;
|
|
3588
3664
|
}
|
|
3589
3665
|
function getLine(sourceFile, node) {
|
|
3590
3666
|
return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
|
|
@@ -3619,4 +3695,4 @@ function compareWarnings(a, b) {
|
|
|
3619
3695
|
return a.scope.localeCompare(b.scope) || (a.file ?? "").localeCompare(b.file ?? "") || (a.line ?? 0) - (b.line ?? 0) || a.rule.localeCompare(b.rule);
|
|
3620
3696
|
}
|
|
3621
3697
|
|
|
3622
|
-
export {
|
|
3698
|
+
export { defaultMaxDiagnostics, WorkspaceRunner, AkanQualityScanner, formatQualityScanResult, formatSsrScanResult };
|