@akanjs/devkit 3.3.0-rc.24 → 3.3.0-rc.26
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/CHANGELOG.md +294 -0
- package/akanApp/akanApp.host.ts +11 -0
- package/akanConfig/akanBin.ts +4 -0
- package/akanConfig/akanConfig.test.ts +11 -0
- package/akanConfig/akanConfig.ts +39 -137
- package/akanConfig/akanWorkers.test.ts +39 -0
- package/akanConfig/akanWorkers.ts +32 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +20 -0
- package/akanConfig/types.ts +1 -0
- package/app/appBin.test.ts +63 -0
- package/app/appBin.ts +50 -0
- package/app/applicationBuildReporter.test.ts +32 -0
- package/app/applicationBuildReporter.ts +4 -0
- package/app/applicationBuildRunner.test.ts +3 -0
- package/app/applicationBuildRunner.ts +40 -4
- package/app/dictionarySizes.ts +94 -0
- package/artifact/implicitRootLayout.test.ts +19 -0
- package/artifact/implicitRootLayout.ts +16 -2
- package/artifact/storeBootstrap.test.ts +28 -0
- package/artifact/storeBootstrap.ts +60 -8
- package/biome.base.json +5 -1
- package/codeAgent/skills/akan-agent/SKILL.md +2 -2
- package/codeAgent/skills/akan-deps/SKILL.md +3 -2
- package/codeAgent/skills/akan-err/SKILL.md +2 -6
- package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
- package/codeAgent/skills/akan-module/SKILL.md +2 -2
- package/codeAgent/skills/akan-query/SKILL.md +13 -20
- package/codeAgent/skills/akan-service/SKILL.md +2 -5
- package/codeAgent/skills/akan-transport/SKILL.md +5 -14
- package/codeAgent/skills/akan-ui/SKILL.md +2 -5
- package/context/akanContext.ts +2 -0
- package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
- package/executors/clientRuntimeKeys.fixture.json +393 -0
- package/executors/clientRuntimeKeys.test.ts +1591 -0
- package/executors/executors.test.ts +2 -0
- package/executors/sysExecutor.ts +66 -3
- package/frontendBuild/allRoutesBuilder.ts +72 -3
- package/frontendBuild/autoImportSync.ts +3 -2
- package/frontendBuild/buildRouteClient.test.ts +513 -5
- package/frontendBuild/clientBuildTypes.ts +15 -0
- package/frontendBuild/clientEntriesBundler.ts +38 -0
- package/frontendBuild/clientEntryDiscovery.test.ts +60 -1
- package/frontendBuild/clientEntryDiscovery.ts +72 -4
- package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
- package/frontendBuild/csrDevModuleCompiler.ts +44 -8
- package/frontendBuild/csrDevPatcher.ts +33 -7
- package/frontendBuild/csrDevTypes.ts +9 -0
- package/frontendBuild/devBarrelImports.test.ts +70 -0
- package/frontendBuild/devBarrelImports.ts +80 -21
- package/frontendBuild/devRegistryBundler.ts +4 -2
- package/frontendBuild/devRouteRuntime.test.ts +492 -0
- package/frontendBuild/devRouteRuntime.ts +167 -0
- package/frontendBuild/dictionaryAssetBuilder.test.ts +316 -0
- package/frontendBuild/dictionaryAssetBuilder.ts +152 -16
- package/frontendBuild/dictionaryConstants.ts +82 -0
- package/frontendBuild/dictionaryPacking.test.ts +84 -0
- package/frontendBuild/dictionaryPacking.ts +92 -0
- package/frontendBuild/dictionaryRoutes.test.ts +186 -0
- package/frontendBuild/dictionaryRoutes.ts +225 -0
- package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
- package/frontendBuild/pagesBundleBuilder.ts +78 -2
- package/frontendBuild/precompressArtifacts.ts +7 -0
- package/frontendBuild/registryMetadataFingerprint.ts +3 -3
- package/frontendBuild/routeClientBuilder.ts +288 -15
- package/frontendBuild/routeHandoffs.test.ts +119 -0
- package/frontendBuild/routeHandoffs.ts +94 -0
- package/frontendBuild/routeRuntimeCheck.test.ts +257 -0
- package/frontendBuild/routeRuntimeCheck.ts +241 -0
- package/frontendBuild/routeRuntimePays.test.ts +137 -0
- package/frontendBuild/routeRuntimePays.ts +117 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +24 -34
- package/frontendBuild/ssrDevBundler.test.ts +150 -1
- package/frontendBuild/ssrDevBundler.ts +66 -11
- package/frontendBuild/vendorFileImports.test.ts +254 -0
- package/frontendBuild/vendorFileImports.ts +163 -0
- package/frontendBuild/vendorNarrowing.ts +28 -0
- package/frontendBuild/vendorSpecifiers.ts +2 -0
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +79 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +20 -1
- package/mobile/desktopBin.ts +2 -2
- package/mobile/desktopServerStage.ts +1 -0
- package/package.json +4 -3
- package/quality/dictionaryKeys.test.ts +173 -0
- package/quality/dictionaryKeys.ts +415 -0
- package/quality/objectImportReport.test.ts +36 -0
- package/quality/objectImportReport.ts +102 -0
- package/quality/qualityScanner.ts +1 -1
- package/quality/routeRuntimeReport.test.ts +91 -0
- package/quality/routeRuntimeReport.ts +121 -0
- package/quality/runtimeConstantFacts.ts +71 -0
- package/quality/runtimeConstantGraph.ts +123 -0
- package/quality/runtimeConstantReads.ts +116 -0
- package/quality/runtimeImports.test.ts +190 -0
- package/quality/runtimeImports.ts +233 -0
- package/quality/runtimeKeyNames.ts +46 -0
- package/quality/runtimeLexicalScope.ts +132 -0
- package/quality/runtimeMarkerReach.test.ts +84 -0
- package/quality/runtimeMarkerReach.ts +255 -0
- package/quality/runtimeModuleFacts.ts +290 -0
- package/quality/runtimeNameTable.test.ts +172 -0
- package/quality/runtimeNameTable.ts +477 -0
- package/quality/runtimeScopeReport.test.ts +123 -0
- package/quality/runtimeScopeReport.ts +167 -0
- package/quality/runtimeSliceKey.ts +269 -0
- package/quality/runtimeSyntax.ts +133 -0
- package/quality/runtimeTable.fixture.ts +189 -0
- package/quality/runtimeUse.test.ts +737 -0
- package/quality/runtimeUse.ts +696 -0
- package/quality/runtimeUseReadable.test.ts +393 -0
- package/quality/ssrScanner.test.ts +13 -0
- package/quality/ssrScanner.ts +1 -1
- package/test/testHelpers.ts +11 -0
- package/transforms/barrelAnalyzer.ts +17 -1
- package/transforms/barrelImportsPlugin.ts +81 -13
- package/transforms/frameworkObjects.fixture.tsx +58 -0
- package/transforms/frameworkObjects.test.ts +54 -0
- package/transforms/modelReference.test.ts +196 -0
- package/transforms/modelReference.ts +39 -0
- package/transforms/objectImportEdits.ts +150 -0
- package/transforms/objectMemberImports.test.ts +347 -0
- package/transforms/objectMemberImports.ts +537 -0
- package/transforms/objectModule.test.ts +237 -0
- package/transforms/objectModule.ts +458 -0
- package/transforms/objectModuleAnalyzer.ts +104 -0
- package/transforms/reactIconImports.test.ts +231 -0
- package/transforms/reactIconImports.ts +325 -0
- package/transforms/routeConstants.ts +122 -0
- package/transforms/routeRuntime.test.ts +835 -0
- package/transforms/routeRuntime.ts +703 -0
- package/transforms/routeRuntimeEdits.ts +92 -0
- package/transforms/routeRuntimeGraph.ts +66 -0
- package/transforms/routeRuntimePlan.ts +244 -0
- package/transforms/signalDescriptors.test.ts +280 -0
- package/transforms/signalDescriptors.ts +227 -0
- package/transforms/thisFreeExports.ts +87 -0
- package/transforms/transforms.test.ts +139 -0
- package/workflow/executor.ts +6 -2
- package/workflow/index.ts +1 -0
- package/workflow/plan.ts +36 -7
- package/workflow/types.ts +1 -1
- package/workflow/uiTarget.ts +50 -0
- package/workspace/scanInfo.ts +1 -1
- package/workspace/workspaceLayout.ts +1 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import { beforeAll, describe, expect, test } from "bun:test";
|
|
2
|
+
import type { RuntimeNameEntry, RuntimeNameTable } from "./runtimeNameTable";
|
|
3
|
+
import { runtimeFixtureTables } from "./runtimeTable.fixture";
|
|
4
|
+
import { RuntimeUse, type RuntimeUseVerdict } from "./runtimeUse";
|
|
5
|
+
|
|
6
|
+
let demo: RuntimeNameTable;
|
|
7
|
+
let kit: RuntimeNameTable;
|
|
8
|
+
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
({ demo, kit } = await runtimeFixtureTables());
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const head = 'import { fetch, st } from "@apps/demo/client";\n';
|
|
14
|
+
const sliceHead = `import { capitalize } from "akanjs/common";\nimport type { SliceMeta } from "akanjs/fetch";\n${head}`;
|
|
15
|
+
const memo = ["apps/demo/memo store"];
|
|
16
|
+
const memoAndNote = ["apps/demo/memo store", "apps/demo/note store"];
|
|
17
|
+
|
|
18
|
+
const summaryOf = (verdict: RuntimeUseVerdict) =>
|
|
19
|
+
verdict.resolvable
|
|
20
|
+
? verdict.owners.map(({ scope, module, needs }) => `${scope}/${module} ${needs}`)
|
|
21
|
+
: `${verdict.reason}: ${verdict.text}`;
|
|
22
|
+
|
|
23
|
+
const analyze = (text: string, fileName = "apps/demo/ui/Card.tsx", table: RuntimeNameTable = demo) =>
|
|
24
|
+
summaryOf(RuntimeUse.analyze({ fileName, text }, table));
|
|
25
|
+
|
|
26
|
+
const storeOf = (body: string, lead = "") =>
|
|
27
|
+
analyze(
|
|
28
|
+
`import { store } from "akanjs/store";\nimport { sig } from "../useClient";\n${lead}\nexport class MemoStore extends store(sig.memo, () => ({ draft: "" })) {\n${body}\n}\n`,
|
|
29
|
+
"apps/demo/lib/memo/memo.store.ts",
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
describe("RuntimeUse.analyze, names read through a cast", () => {
|
|
33
|
+
test("reads a name written after a cast as it reads it with no cast", () => {
|
|
34
|
+
const loose = "{ [key: string]: () => unknown }";
|
|
35
|
+
expect([
|
|
36
|
+
analyze(`${head}export const a = () => (st.use as unknown as ${loose}).draft();\n`),
|
|
37
|
+
analyze(`${head}const use = st.use as ${loose};\nexport const a = () => use.draft();\n`),
|
|
38
|
+
analyze(`${head}export const a = () => {\n const { draft } = st.get() as unknown as { draft: string };\n};\n`),
|
|
39
|
+
analyze(`${head}export const a = () => (st.do satisfies object).clearDraft();\n`),
|
|
40
|
+
analyze(`${head}export const a = () => st.do!.clearDraft();\n`),
|
|
41
|
+
analyze(`${head}export const a = () => (<any>st.do).clearDraft();\n`, "apps/demo/webkit/clear.ts"),
|
|
42
|
+
analyze(`${head}export const a = () => (st.get() as any).pinned;\n`),
|
|
43
|
+
]).toEqual([memo, memo, memo, memo, memo, memo, ["apps/demo/note store"]]);
|
|
44
|
+
expect(
|
|
45
|
+
analyze(`${head}export const a = () => (fetch as unknown as { memoNote: () => void }).memoNote();\n`),
|
|
46
|
+
).toEqual(["apps/demo/memo descriptor"]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("reads the framework's fetch cast to the app's as the app's, and a store's state read taken off it once", () => {
|
|
50
|
+
expect(
|
|
51
|
+
analyze(
|
|
52
|
+
'import { fetch as runtimeFetch } from "akanjs/client";\nimport type { fetch } from "@apps/demo/client";\nconst live = runtimeFetch as unknown as typeof fetch;\nexport const a = () => live.memoNote();\n',
|
|
53
|
+
),
|
|
54
|
+
).toEqual(["apps/demo/memo descriptor"]);
|
|
55
|
+
expect(
|
|
56
|
+
analyze(
|
|
57
|
+
`${head}const get = st.get as unknown as <T>() => { [key: string]: T };\nexport const a = () => get<string>().draft;\n`,
|
|
58
|
+
),
|
|
59
|
+
).toEqual(memo);
|
|
60
|
+
expect(analyze(`${head}const get = st.get;\nexport const a = (run: (get: unknown) => void) => run(get);\n`)).toBe(
|
|
61
|
+
"passed-on: get",
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("keeps the whole runtime for every read a cast does not make visible", () => {
|
|
66
|
+
expect([
|
|
67
|
+
analyze(`${head}export const a = (name: string) => (st.use as any)[name]();\n`),
|
|
68
|
+
analyze(`${head}export const a = () => (fetch as unknown as { notThere: () => void }).notThere();\n`),
|
|
69
|
+
analyze(`${head}export const a = () => ({ ...(st.do as object) });\n`),
|
|
70
|
+
analyze(`${head}export const a = (run: (all: unknown) => void) => run(st.do as any);\n`),
|
|
71
|
+
analyze(`${head}export const a = () => (st as any).everything;\n`),
|
|
72
|
+
analyze(`${head}export const a = () => (st.get() as any).nothing;\n`),
|
|
73
|
+
]).toEqual([
|
|
74
|
+
"computed-access: (st.use as any)[name]",
|
|
75
|
+
"unknown-name: (fetch as unknown as { notThere: () => void }).notThere",
|
|
76
|
+
"passed-on: (st.do as object)",
|
|
77
|
+
"passed-on: st.do as any",
|
|
78
|
+
"unknown-name: (st as any).everything",
|
|
79
|
+
"unknown-name: (st.get() as any).nothing",
|
|
80
|
+
]);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("RuntimeUse.analyze, a key asserted as a name", () => {
|
|
85
|
+
test("reads a computed key asserted as a name, directly or through a const, as that name", () => {
|
|
86
|
+
expect([
|
|
87
|
+
analyze(`${head}export const a = (key: string) => st.use[key as "draft"]();\n`),
|
|
88
|
+
analyze(`${head}export const a = (key: string) => st.use[<"draft">key]();\n`, "apps/demo/webkit/draft.ts"),
|
|
89
|
+
analyze(
|
|
90
|
+
`${head}export const a = (name: string) => {\n const key = name.replace("x", "draft") as "draft";\n return st.get()[key];\n};\n`,
|
|
91
|
+
),
|
|
92
|
+
analyze(`${head}const key = "draft";\nexport const a = () => st.use[key]();\n`),
|
|
93
|
+
analyze(`${head}export const a = (key: string) => st.slice[key as "memoInBoard"].use.memoList();\n`),
|
|
94
|
+
]).toEqual([memo, memo, memo, memo, memo]);
|
|
95
|
+
expect(analyze(`${head}export const a = (key: string) => st.use[key as "draft" | "pinned"]();\n`)).toEqual(
|
|
96
|
+
memoAndNote,
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("reads an asserted key of a destructuring, a state write and a pick in a store", () => {
|
|
101
|
+
const key = ' const key = slice.replace("x", "pinned") as "pinned";\n';
|
|
102
|
+
expect([
|
|
103
|
+
storeOf(` show(slice: string) {\n${key} const { [key]: value } = this.get();\n return value;\n }`),
|
|
104
|
+
storeOf(` show(slice: string) {\n${key} this.set({ [key]: true });\n }`),
|
|
105
|
+
storeOf(` show(slice: string) {\n${key} return this.pick(key);\n }`),
|
|
106
|
+
]).toEqual([memoAndNote, memoAndNote, memoAndNote]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("keeps the whole runtime for a spread written through a cast `this`, which is not the store's own typed `set`", () => {
|
|
110
|
+
const mergeOf = (write: string) => storeOf(` merge(patch: { draft: string }) {\n ${write};\n }`);
|
|
111
|
+
expect([
|
|
112
|
+
mergeOf("this.set({ ...patch })"),
|
|
113
|
+
mergeOf("(this as any).set({ ...patch })"),
|
|
114
|
+
mergeOf("(this as unknown as { set(p: object): void }).set({ ...patch })"),
|
|
115
|
+
mergeOf("(this as any)['set']({ ...patch })"),
|
|
116
|
+
]).toEqual([
|
|
117
|
+
["apps/demo/memo store"],
|
|
118
|
+
"computed-access: patch",
|
|
119
|
+
"computed-access: patch",
|
|
120
|
+
"computed-access: patch",
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("reports an asserted name the runtime does not have, and keeps the whole runtime for a key nothing asserts", () => {
|
|
125
|
+
expect([
|
|
126
|
+
analyze(`${head}export const a = (key: string) => st.use[key as "nothing"]();\n`),
|
|
127
|
+
analyze(`${head}export const a = (key: string) => st.use[key as string]();\n`),
|
|
128
|
+
analyze(
|
|
129
|
+
`${head}export const a = (key: string) => {\n let name = key as "draft";\n return st.use[name]();\n};\n`,
|
|
130
|
+
),
|
|
131
|
+
analyze(`${head}export const a = (key: string) => st[key as "do" | "use"];\n`),
|
|
132
|
+
storeOf(" show(key: string) {\n const { [key]: value } = this.get();\n return value;\n }"),
|
|
133
|
+
storeOf(" show(key: string) {\n this.set({ [key]: true });\n }"),
|
|
134
|
+
]).toEqual([
|
|
135
|
+
'unknown-name: st.use[key as "nothing"]',
|
|
136
|
+
"computed-access: st.use[key as string]",
|
|
137
|
+
"computed-access: st.use[name]",
|
|
138
|
+
'computed-access: st[key as "do" | "use"]',
|
|
139
|
+
"hidden-by-destructuring: [key]: value",
|
|
140
|
+
"computed-access: [key]: true",
|
|
141
|
+
]);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("RuntimeUse.analyze, a name built from a slice the function is handed", () => {
|
|
146
|
+
const props = "interface Props {\n className?: string;\n slice: SliceMeta;\n}\n";
|
|
147
|
+
|
|
148
|
+
test("reads a name built from the sliceName or refName of a slice parameter, loading nothing the slice brought", () => {
|
|
149
|
+
expect([
|
|
150
|
+
analyze(
|
|
151
|
+
`${sliceHead}${props}export const Search = ({ slice }: Props) => {\n const { sliceName } = slice;\n const use = st.use as unknown as { [key: string]: () => unknown };\n return () => use[\`queryArgsOf\${capitalize(sliceName)}\`]();\n};\n`,
|
|
152
|
+
),
|
|
153
|
+
analyze(
|
|
154
|
+
`${sliceHead}export const More = ({ slice }: { slice?: SliceMeta }) => {\n const SliceName = capitalize(slice.sliceName);\n return (st.do as any)["loadMoreOf" + SliceName]();\n};\n`,
|
|
155
|
+
),
|
|
156
|
+
analyze(`${sliceHead}export const sliceOf = (slice: SliceMeta | null) => st.slice[slice.sliceName];\n`),
|
|
157
|
+
analyze(
|
|
158
|
+
`${sliceHead}type Handed = SliceMeta & { title: string };\nexport const uploadOf = (slice: Handed) => (fetch as any)[\`add\${capitalize(slice.refName)}Files\`];\n`,
|
|
159
|
+
),
|
|
160
|
+
]).toEqual([[], [], [], []]);
|
|
161
|
+
expect(
|
|
162
|
+
analyze(
|
|
163
|
+
`import { capitalize } from "akanjs/common";\nimport type { SliceMeta } from "akanjs/fetch";\nimport { fetch } from "@libs/kit/client";\nexport const uploadOf = (slice: SliceMeta) => (fetch as any)[\`add\${capitalize(slice.sliceName)}Files\`];\n`,
|
|
164
|
+
"libs/kit/ui/upload.ts",
|
|
165
|
+
kit,
|
|
166
|
+
),
|
|
167
|
+
).toEqual([]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("keeps the whole runtime where the name's parts are not one handed slice's", () => {
|
|
171
|
+
const built = `st.use[\`queryArgsOf\${capitalize(sliceName)}\`]`;
|
|
172
|
+
const read = ` return ${built}();\n};\n`;
|
|
173
|
+
expect([
|
|
174
|
+
analyze(`${sliceHead}export const a = (sliceName: string) => {\n${read}`),
|
|
175
|
+
analyze(
|
|
176
|
+
`${sliceHead}export const a = (slice: { sliceName: string }) => {\n const { sliceName } = slice;\n${read}`,
|
|
177
|
+
),
|
|
178
|
+
analyze(
|
|
179
|
+
`import { capitalize } from "akanjs/common";\nimport type { SliceMeta } from "./slice";\n${head}export const a = (slice: SliceMeta) => {\n const { sliceName } = slice;\n${read}`,
|
|
180
|
+
),
|
|
181
|
+
analyze(
|
|
182
|
+
`import type { SliceMeta } from "akanjs/fetch";\n${head}const capitalize = (text: string) => text;\nexport const a = (slice: SliceMeta) => {\n const { sliceName } = slice;\n${read}`,
|
|
183
|
+
),
|
|
184
|
+
analyze(
|
|
185
|
+
`${sliceHead}export const a = (slice: SliceMeta) => {\n const { sliceName = "memoInBoard" } = slice;\n${read}`,
|
|
186
|
+
),
|
|
187
|
+
analyze(`${sliceHead}export const a = (slice: SliceMeta) => {\n let { sliceName } = slice;\n${read}`),
|
|
188
|
+
analyze(
|
|
189
|
+
`${sliceHead}export const a = (one: SliceMeta, other: SliceMeta) => st.use[\`\${one.refName}ListIn\${other.sliceName}\`]();\n`,
|
|
190
|
+
),
|
|
191
|
+
analyze(
|
|
192
|
+
`${sliceHead}export const a = (slice: SliceMeta) => st.use[\`nothingOf\${capitalize(slice.sliceName)}\`]();\n`,
|
|
193
|
+
),
|
|
194
|
+
analyze(`${sliceHead}export const a = (slice: SliceMeta) => st[slice.refName];\n`),
|
|
195
|
+
]).toEqual([
|
|
196
|
+
`computed-access: ${built}`,
|
|
197
|
+
`computed-access: ${built}`,
|
|
198
|
+
`computed-access: ${built}`,
|
|
199
|
+
`computed-access: ${built}`,
|
|
200
|
+
`computed-access: ${built}`,
|
|
201
|
+
`computed-access: ${built}`,
|
|
202
|
+
`computed-access: st.use[\`\${one.refName}ListIn\${other.sliceName}\`]`,
|
|
203
|
+
`computed-access: st.use[\`nothingOf\${capitalize(slice.sliceName)}\`]`,
|
|
204
|
+
"computed-access: st[slice.refName]",
|
|
205
|
+
]);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("keeps the whole runtime where the slice parameter is reassigned or defaulted", () => {
|
|
209
|
+
const built = `st.use[\`queryArgsOf\${capitalize(slice.sliceName)}\`]`;
|
|
210
|
+
const read = `${built}()`;
|
|
211
|
+
const inFunction = (parameters: string, before: string) =>
|
|
212
|
+
analyze(`${sliceHead}export const a = (${parameters}) => {\n${before} return ${read};\n};\n`);
|
|
213
|
+
expect([
|
|
214
|
+
inFunction("slice: SliceMeta, other: any", " slice = other;\n"),
|
|
215
|
+
inFunction("slice: SliceMeta, other: any", " ({ slice } = other);\n"),
|
|
216
|
+
inFunction("slice: SliceMeta, other: any", " [slice] = other;\n"),
|
|
217
|
+
inFunction("slice: SliceMeta, other: any", " (slice as any) = other;\n"),
|
|
218
|
+
inFunction("slice: SliceMeta", " for (slice of []) break;\n"),
|
|
219
|
+
inFunction("slice: SliceMeta", " slice ||= slice;\n"),
|
|
220
|
+
inFunction("slice = (undefined as unknown) as SliceMeta", ""),
|
|
221
|
+
inFunction("{ slice }: { slice: SliceMeta }, other: any", " slice = other;\n"),
|
|
222
|
+
inFunction("{ slice = other as SliceMeta }: { slice?: SliceMeta }, other: any", ""),
|
|
223
|
+
inFunction("{ slice }: { slice: SliceMeta } = { slice: {} as SliceMeta }", ""),
|
|
224
|
+
inFunction("slice: SliceMeta", " const other = { slice };\n"),
|
|
225
|
+
]).toEqual([...Array.from({ length: 10 }, () => `computed-access: ${built}`), []]);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("loads a module the slice's own arrival does not, for every slice the name may stand for", () => {
|
|
229
|
+
const entry = (scope: string, module: string): RuntimeNameEntry => ({
|
|
230
|
+
owners: [{ scope, module }],
|
|
231
|
+
definedBy: [{ scope, module }],
|
|
232
|
+
base: null,
|
|
233
|
+
needs: "store",
|
|
234
|
+
uses: [],
|
|
235
|
+
});
|
|
236
|
+
const names: Record<string, RuntimeNameEntry> = {
|
|
237
|
+
"fetch.slice/postInFeed": entry("libs/base", "post"),
|
|
238
|
+
"st.slice/postInFeed": entry("apps/blog", "post"),
|
|
239
|
+
"st.use/post": entry("apps/blog", "post"),
|
|
240
|
+
"st.use/queryArgsOfPostInFeed": entry("apps/blog", "post"),
|
|
241
|
+
"fetch.slice/tagInFeed": entry("libs/base", "tag"),
|
|
242
|
+
"st.use/tag": entry("libs/base", "tag"),
|
|
243
|
+
"st.use/queryArgsOfTagInFeed": entry("libs/base", "tag"),
|
|
244
|
+
};
|
|
245
|
+
const blog = {
|
|
246
|
+
scope: "apps/blog",
|
|
247
|
+
layers: [{ scope: "libs/base" }, { scope: "apps/blog" }],
|
|
248
|
+
lookup: (family: string, key: string) => names[`${family}/${key}`] ?? null,
|
|
249
|
+
keysOf: (family: string) =>
|
|
250
|
+
Object.keys(names).flatMap((name) => (name.startsWith(`${family}/`) ? [name.slice(family.length + 1)] : [])),
|
|
251
|
+
} as unknown as RuntimeNameTable;
|
|
252
|
+
expect(
|
|
253
|
+
analyze(
|
|
254
|
+
`import { capitalize } from "akanjs/common";\nimport type { SliceMeta } from "akanjs/fetch";\nimport { st } from "@apps/blog/client";\nexport const a = (slice: SliceMeta) => st.use[\`queryArgsOf\${capitalize(slice.sliceName)}\`]();\n`,
|
|
255
|
+
"apps/blog/ui/Search.tsx",
|
|
256
|
+
blog,
|
|
257
|
+
),
|
|
258
|
+
).toEqual(["apps/blog/post store"]);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test("loads nothing for a copy of a handed slice's names, and keeps the whole runtime for any other copy", () => {
|
|
262
|
+
const type = 'import type { SliceMeta } from "akanjs/fetch";\n';
|
|
263
|
+
const copy = "{ refName: slice.refName, sliceName: slice.sliceName, argLength: 0 }";
|
|
264
|
+
expect([
|
|
265
|
+
analyze(`${type}export const copy = (slice: SliceMeta) => (${copy});\n`),
|
|
266
|
+
analyze(
|
|
267
|
+
`${type}export const copy = (slice: SliceMeta) => {\n const { refName, sliceName } = slice;\n return { refName, sliceName, argLength: 0 };\n};\n`,
|
|
268
|
+
),
|
|
269
|
+
analyze(
|
|
270
|
+
`${type}export const copy = (slice: SliceMeta, other: SliceMeta) => {\n slice = other;\n return ${copy};\n};\n`,
|
|
271
|
+
),
|
|
272
|
+
analyze(
|
|
273
|
+
`${type}export const copy = (slice: SliceMeta) => ({ refName: slice.refName, sliceName: slice.refName, argLength: 0 });\n`,
|
|
274
|
+
),
|
|
275
|
+
analyze(`${type}export const copy = (slice: { refName: string; sliceName: string }) => (${copy});\n`),
|
|
276
|
+
]).toEqual([
|
|
277
|
+
[],
|
|
278
|
+
[],
|
|
279
|
+
"computed-access: sliceName: slice.sliceName",
|
|
280
|
+
"computed-access: sliceName: slice.refName",
|
|
281
|
+
"computed-access: sliceName: slice.sliceName",
|
|
282
|
+
]);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test("reads a slice written out by hand as naming its model, and keeps the whole runtime where its name is not written", () => {
|
|
286
|
+
expect([
|
|
287
|
+
analyze('export const slice = { refName: "memo", sliceName: "memoInBoard", argLength: 0 };\n'),
|
|
288
|
+
analyze(
|
|
289
|
+
"export const sliceOf = (refName: string, sliceName: string) => ({ refName, sliceName, argLength: 0 });\n",
|
|
290
|
+
),
|
|
291
|
+
analyze('export const slice = { refName: "memo", sliceName: "nothing", argLength: 0 };\n'),
|
|
292
|
+
analyze('export const names = { sliceName: "memoInBoard" };\n'),
|
|
293
|
+
]).toEqual([memo, "computed-access: sliceName", 'unknown-name: sliceName: "nothing"', []]);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
describe("RuntimeUse.analyze, state handed to a function of the same file", () => {
|
|
298
|
+
test("reads the names a function of the file reads from the state it is handed", () => {
|
|
299
|
+
expect([
|
|
300
|
+
storeOf(
|
|
301
|
+
" static announce({ draft, pinned }: { draft: string; pinned: boolean }) {\n return [draft, pinned];\n }\n show() {\n return MemoStore.announce(this.get());\n }",
|
|
302
|
+
),
|
|
303
|
+
analyze(
|
|
304
|
+
`${head}const labelOf = (state: { draft: string }) => state.draft;\nexport const a = () => labelOf(st.get());\n`,
|
|
305
|
+
),
|
|
306
|
+
analyze(
|
|
307
|
+
`${head}export const a = () => labelOf(1, st.get() as never);\nfunction labelOf(this: void, count: number, state: { draft: string }) {\n return state.draft.repeat(count);\n}\n`,
|
|
308
|
+
),
|
|
309
|
+
analyze(
|
|
310
|
+
`${head}const inner = ({ pinned }: { pinned: boolean }) => pinned;\nconst outer = (state: { draft: string }) => [state.draft, inner(state as never)];\nexport const a = () => outer(st.get());\n`,
|
|
311
|
+
),
|
|
312
|
+
]).toEqual([memoAndNote, memo, memo, memoAndNote]);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test("keeps the whole runtime where the function hands the state on, picks a name at run time or is not the file's", () => {
|
|
316
|
+
expect([
|
|
317
|
+
analyze(
|
|
318
|
+
`${head}const labelOf = (state: object, run: (all: object) => void) => run(state);\nexport const a = () => labelOf(st.get(), () => {});\n`,
|
|
319
|
+
),
|
|
320
|
+
analyze(
|
|
321
|
+
`${head}const labelOf = (state: Record<string, string>, key: string) => state[key];\nexport const a = () => labelOf(st.get(), "draft");\n`,
|
|
322
|
+
),
|
|
323
|
+
analyze(`${head}const labelOf = (...states: object[]) => states;\nexport const a = () => labelOf(st.get());\n`),
|
|
324
|
+
analyze(
|
|
325
|
+
`${head}function labelOf(state: object) {\n return arguments[0];\n}\nexport const a = () => labelOf(st.get());\n`,
|
|
326
|
+
),
|
|
327
|
+
analyze(`${head}import { labelOf } from "./label";\nexport const a = () => labelOf(st.get());\n`),
|
|
328
|
+
analyze(
|
|
329
|
+
`${head}let labelOf = (state: { draft: string }) => state.draft;\nexport const a = () => labelOf(st.get());\n`,
|
|
330
|
+
),
|
|
331
|
+
analyze(
|
|
332
|
+
`${head}const labelOf = (state: { draft: string }) => state.draft;\nexport const a = () => labelOf(st.do);\n`,
|
|
333
|
+
),
|
|
334
|
+
storeOf(
|
|
335
|
+
" label(state: { draft: string }) {\n return state.draft;\n }\n show() {\n return this.label(this.get());\n }",
|
|
336
|
+
),
|
|
337
|
+
]).toEqual([
|
|
338
|
+
"passed-on: state",
|
|
339
|
+
"computed-access: state[key]",
|
|
340
|
+
"passed-on: st.get()",
|
|
341
|
+
"passed-on: st.get()",
|
|
342
|
+
"passed-on: st.get()",
|
|
343
|
+
"passed-on: st.get()",
|
|
344
|
+
"passed-on: st.do",
|
|
345
|
+
"passed-on: this.get()",
|
|
346
|
+
]);
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
describe("RuntimeUse.analyze, the agent entry of the framework store", () => {
|
|
351
|
+
test("reads the screen and cursor exports as no runtime, and the ones holding the root store as the whole runtime", () => {
|
|
352
|
+
expect([
|
|
353
|
+
analyze(
|
|
354
|
+
'import { ScreenSettle, ScreenTarget } from "akanjs/store/agent";\nexport const a = [ScreenSettle, ScreenTarget];\n',
|
|
355
|
+
),
|
|
356
|
+
analyze('import { AgentBridge } from "akanjs/store/agent";\nexport const a = AgentBridge;\n'),
|
|
357
|
+
analyze('import * as agent from "akanjs/store/agent";\nexport const a = agent;\n'),
|
|
358
|
+
analyze('import { ScreenSettle } from "akanjs/store/agent/ScreenSettle";\nexport const a = ScreenSettle;\n'),
|
|
359
|
+
]).toEqual([
|
|
360
|
+
[],
|
|
361
|
+
"whole-runtime-import: AgentBridge",
|
|
362
|
+
"whole-runtime-import: agent",
|
|
363
|
+
"whole-runtime-import: ScreenSettle",
|
|
364
|
+
]);
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
describe("RuntimeUse.analyze, the note of a read that keeps the whole runtime", () => {
|
|
369
|
+
test("ends with what to write instead, where there is a usual answer", () => {
|
|
370
|
+
const answerOf = (text: string) => {
|
|
371
|
+
const verdict = RuntimeUse.analyze({ fileName: "apps/demo/ui/Card.tsx", text }, demo);
|
|
372
|
+
return verdict.resolvable ? null : (verdict.message.split("; ")[1] ?? null);
|
|
373
|
+
};
|
|
374
|
+
const assertKey = 'assert the key as the name it stands for (`key as "name"`)';
|
|
375
|
+
expect([
|
|
376
|
+
answerOf(`${head}export const a = (name: string) => st.use[name]();\n`),
|
|
377
|
+
answerOf(`${head}export const a = (name: string) => fetch[name]();\n`),
|
|
378
|
+
answerOf(`${head}export const a = (sliceName: string) => st.slice[sliceName];\n`),
|
|
379
|
+
answerOf(`${head}export const a = (run: (all: unknown) => void) => run(fetch);\n`),
|
|
380
|
+
answerOf(`${head}export const a = (run: (all: unknown) => void) => run(st.get());\n`),
|
|
381
|
+
answerOf(`${head}export const a = (key: string) => {\n const { [key]: value } = st.get();\n};\n`),
|
|
382
|
+
answerOf(`${head}export const a = () => st.use.nothing();\n`),
|
|
383
|
+
]).toEqual([
|
|
384
|
+
assertKey,
|
|
385
|
+
`name the endpoint, or ${assertKey}`,
|
|
386
|
+
`take the slice as a \`SliceMeta\` parameter, or ${assertKey}`,
|
|
387
|
+
"name the endpoint here and pass that",
|
|
388
|
+
"read the names here",
|
|
389
|
+
assertKey,
|
|
390
|
+
null,
|
|
391
|
+
]);
|
|
392
|
+
});
|
|
393
|
+
});
|
|
@@ -35,6 +35,19 @@ describe("akan.ssr.unnecessary-use-client", () => {
|
|
|
35
35
|
expect(scanOne(UI, `"use client";\n${body}\n`)).not.toContain("akan.ssr.unnecessary-use-client");
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
+
test("a module's Zone, Template or Util carries the directive by role, in a service module too", () => {
|
|
39
|
+
const plain = `"use client";\nexport const Main = () => <div />;\n`;
|
|
40
|
+
for (const file of [
|
|
41
|
+
"apps/demo/lib/task/Task.Zone.tsx",
|
|
42
|
+
"apps/demo/lib/task/Task.Template.tsx",
|
|
43
|
+
"apps/demo/lib/_camera/Camera.Zone.tsx",
|
|
44
|
+
"libs/shared/lib/_camera/Camera.Util.tsx",
|
|
45
|
+
])
|
|
46
|
+
expect(scanOne(file, plain)).not.toContain("akan.ssr.unnecessary-use-client");
|
|
47
|
+
for (const file of ["apps/demo/lib/task/Task.View.tsx", "apps/demo/lib/__scalar/geo/Geo.Template.tsx"])
|
|
48
|
+
expect(scanOne(file, plain)).toContain("akan.ssr.unnecessary-use-client");
|
|
49
|
+
});
|
|
50
|
+
|
|
38
51
|
test("a third-party import is a reason the AST cannot rule out", () => {
|
|
39
52
|
expect(scanOne(UI, `"use client";\nimport Chart from "recharts";\nexport const Thing = () => <div />;\n`)).toEqual(
|
|
40
53
|
[],
|
package/quality/ssrScanner.ts
CHANGED
|
@@ -354,7 +354,7 @@ export class SsrScanner {
|
|
|
354
354
|
// Zone/Template/Util carry the directive by file role, and `index_.tsx` is the declared lazy() boundary.
|
|
355
355
|
#isConventionClientFile(file: string) {
|
|
356
356
|
if (file.endsWith("/index_.tsx")) return true;
|
|
357
|
-
return
|
|
357
|
+
return /\/lib\/_?[^_/][^/]*\/.*\.(Zone|Template|Util)\.tsx$/.test(file);
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
#isBalancedFile(file: string) {
|
package/test/testHelpers.ts
CHANGED
|
@@ -129,6 +129,17 @@ export const writeJson = async (filePath: string, value: object) => {
|
|
|
129
129
|
await writeText(filePath, `${JSON.stringify(value, null, 2)}\n`);
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
+
export const printedInOwnProcess = async (script: string, cwd: string): Promise<unknown> => {
|
|
133
|
+
const proc = Bun.spawn([process.execPath, "--eval", script], { cwd, stdout: "pipe", stderr: "pipe" });
|
|
134
|
+
const [code, stdout, stderr] = await Promise.all([
|
|
135
|
+
proc.exited,
|
|
136
|
+
new Response(proc.stdout).text(),
|
|
137
|
+
new Response(proc.stderr).text(),
|
|
138
|
+
]);
|
|
139
|
+
if (code !== 0) throw new Error(`the script exited with code ${code}:\n${stderr}`);
|
|
140
|
+
return JSON.parse(stdout.trim().split("\n").at(-1) ?? "null");
|
|
141
|
+
};
|
|
142
|
+
|
|
132
143
|
export const heldMtimeIndex = () => {
|
|
133
144
|
const primes: PromiseWithResolvers<void>[] = [];
|
|
134
145
|
const scans: PromiseWithResolvers<string[]>[] = [];
|
|
@@ -26,6 +26,8 @@ export interface BarrelAnalyzerOptions {
|
|
|
26
26
|
resolvePackage: (pkgName: string) => Promise<PackageEntry | null>;
|
|
27
27
|
/** Resolves to an absolute file path on disk. */
|
|
28
28
|
resolveRelative?: (fromFile: string, relSpec: string) => Promise<string | null>;
|
|
29
|
+
/** Maps a name the barrel entry re-exports from a package to that package, when it resolves the same from here. */
|
|
30
|
+
packageRoot?: string;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
// `Transpiler.scan` gives the export names but not their sources; this regex supplies the name↔source mapping.
|
|
@@ -145,7 +147,11 @@ export class BarrelAnalyzer {
|
|
|
145
147
|
const nsAs = m[2];
|
|
146
148
|
const namedList = m[3];
|
|
147
149
|
const spec = m[5] ?? "";
|
|
148
|
-
if (!isRelative(spec))
|
|
150
|
+
if (!isRelative(spec)) {
|
|
151
|
+
if (namedList !== undefined && absFile === pkg.entryFile && this.#isSamePackage(spec, absFile))
|
|
152
|
+
attribute(namedList, spec);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
149
155
|
|
|
150
156
|
if (star) {
|
|
151
157
|
if (!nsAs) starSpecs.push(spec);
|
|
@@ -220,6 +226,16 @@ export class BarrelAnalyzer {
|
|
|
220
226
|
return tail === "" ? pkg.pkgName : `${pkg.pkgName}/${tail}`;
|
|
221
227
|
}
|
|
222
228
|
|
|
229
|
+
#isSamePackage(spec: string, absFile: string): boolean {
|
|
230
|
+
const root = this.#opts.packageRoot;
|
|
231
|
+
if (!root) return false;
|
|
232
|
+
try {
|
|
233
|
+
return Bun.resolveSync(spec, path.dirname(absFile)) === Bun.resolveSync(spec, root);
|
|
234
|
+
} catch {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
223
239
|
async #resolveRel(fromFile: string, relSpec: string): Promise<string | null> {
|
|
224
240
|
if (this.#opts.resolveRelative) return this.#opts.resolveRelative(fromFile, relSpec);
|
|
225
241
|
return defaultResolveRelative(fromFile, relSpec);
|