@akanjs/devkit 3.3.0-rc.6 → 3.3.0-rc.61
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/DEV_RUNTIME_KNOBS.md +1 -1
- package/README.ko.md +8 -2
- package/README.md +8 -3
- package/akanApp/akanApp.host.test.ts +4 -2
- package/akanApp/akanApp.host.ts +11 -0
- package/akanConfig/akanBin.ts +4 -0
- package/akanConfig/akanConfig.test.ts +280 -19
- package/akanConfig/akanConfig.ts +96 -270
- package/akanConfig/akanWorkers.test.ts +73 -0
- package/akanConfig/akanWorkers.ts +61 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +216 -0
- package/akanConfig/index.ts +2 -0
- package/akanConfig/nativeFileSettings.ts +33 -0
- package/akanConfig/nativeKeys.ts +52 -0
- package/akanConfig/types.ts +2 -0
- package/app/appBin.test.ts +63 -0
- package/app/appBin.ts +50 -0
- package/app/applicationBuildReporter.test.ts +51 -1
- package/app/applicationBuildReporter.ts +6 -1
- package/app/applicationBuildRunner.test.ts +358 -5
- package/app/applicationBuildRunner.ts +204 -30
- package/app/dictionarySizes.test.ts +40 -0
- package/app/dictionarySizes.ts +95 -0
- package/app/routeFilesReport.test.ts +59 -0
- package/app/routeFilesReport.ts +46 -0
- package/app/routeJsBudget.ts +18 -4
- package/artifact/implicitRootLayout.test.ts +19 -0
- package/artifact/implicitRootLayout.ts +16 -2
- package/artifact/implicitRootLayoutRender.test.tsx +4 -1
- package/artifact/storeBootstrap.test.ts +28 -0
- package/artifact/storeBootstrap.ts +64 -8
- package/biome.base.json +7 -5
- package/codeAgent/agent/CodeAgent.ts +36 -16
- package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
- package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
- package/codeAgent/agent/CodeAgentGate.ts +23 -4
- package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +62 -0
- package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
- package/codeAgent/agent/codeAgentContract.test.ts +117 -5
- package/codeAgent/skills/akan-agent/SKILL.md +8 -1
- package/codeAgent/skills/akan-code/SKILL.md +38 -3
- package/codeAgent/skills/akan-debug/SKILL.md +1 -1
- package/codeAgent/skills/akan-deps/SKILL.md +3 -2
- package/codeAgent/skills/akan-err/SKILL.md +13 -8
- package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
- package/codeAgent/skills/akan-module/SKILL.md +2 -2
- package/codeAgent/skills/akan-page/SKILL.md +52 -28
- package/codeAgent/skills/akan-query/SKILL.md +13 -20
- package/codeAgent/skills/akan-runtime/SKILL.md +21 -1
- package/codeAgent/skills/akan-service/SKILL.md +10 -11
- package/codeAgent/skills/akan-transport/SKILL.md +5 -14
- package/codeAgent/skills/akan-ui/SKILL.md +16 -21
- package/commandDecorators/command.ts +28 -12
- package/commandDecorators/commandBuilder.ts +8 -1
- package/commandDecorators/commandDecorators.test.ts +70 -3
- package/commandDecorators/helpFormatter.ts +14 -12
- package/context/akanContext.ts +2 -0
- package/csrE2e/devHmrLatency.e2e.test.ts +1 -1
- package/docs/apiReference.test.ts +19 -0
- package/docs/apiReference.ts +28 -5
- package/executors/appExecutor.ts +26 -12
- package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
- package/executors/clientRuntimeKeys.fixture.json +393 -0
- package/executors/clientRuntimeKeys.test.ts +1690 -0
- package/executors/executor.ts +14 -6
- package/executors/executors.test.ts +140 -1
- package/executors/sysExecutor.ts +112 -8
- package/executors/workspaceExecutor.ts +7 -4
- package/frontendBuild/allRoutesBuilder.ts +99 -7
- package/frontendBuild/autoImportSync.ts +3 -2
- package/frontendBuild/buildRouteClient.test.ts +686 -13
- package/frontendBuild/clientBuildTypes.ts +26 -0
- package/frontendBuild/clientEntriesBundler.ts +49 -1
- package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
- package/frontendBuild/clientEntryDiscovery.ts +136 -14
- package/frontendBuild/clientEntryGroups.test.ts +77 -0
- package/frontendBuild/clientEntryGroups.ts +61 -0
- package/frontendBuild/csrDevArtifactWriter.ts +2 -2
- package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
- package/frontendBuild/csrDevModuleCompiler.ts +44 -8
- package/frontendBuild/csrDevPatcher.test.ts +1 -1
- package/frontendBuild/csrDevPatcher.ts +33 -7
- package/frontendBuild/csrDevTypes.ts +9 -0
- package/frontendBuild/devBarrelImports.test.ts +154 -0
- package/frontendBuild/devBarrelImports.ts +83 -23
- package/frontendBuild/devRegistryBundler.ts +4 -2
- package/frontendBuild/devRouteRuntime.test.ts +492 -0
- package/frontendBuild/devRouteRuntime.ts +167 -0
- package/frontendBuild/dictionaryAssetBuilder.test.ts +408 -0
- package/frontendBuild/dictionaryAssetBuilder.ts +185 -17
- package/frontendBuild/dictionaryConstants.ts +136 -0
- package/frontendBuild/dictionaryOwnParts.ts +88 -0
- package/frontendBuild/dictionaryPackState.ts +131 -0
- package/frontendBuild/dictionaryPacking.test.ts +207 -0
- package/frontendBuild/dictionaryPacking.ts +160 -0
- package/frontendBuild/dictionaryRoutes.test.ts +251 -0
- package/frontendBuild/dictionaryRoutes.ts +227 -0
- package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
- package/frontendBuild/pagesBundleBuilder.ts +78 -2
- package/frontendBuild/precompressArtifacts.test.ts +22 -0
- package/frontendBuild/precompressArtifacts.ts +34 -8
- package/frontendBuild/registryMetadataFingerprint.ts +3 -3
- package/frontendBuild/renderedEntries.ts +144 -0
- package/frontendBuild/routeClientBuilder.ts +407 -43
- package/frontendBuild/routeHandoffs.test.ts +155 -0
- package/frontendBuild/routeHandoffs.ts +117 -0
- package/frontendBuild/routeModulePreloads.test.ts +32 -0
- package/frontendBuild/routeModulePreloads.ts +20 -11
- package/frontendBuild/routeRuntimeCheck.test.ts +280 -0
- package/frontendBuild/routeRuntimeCheck.ts +248 -0
- package/frontendBuild/routeRuntimePays.test.ts +143 -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/buildBatch.proc.ts +9 -9
- package/incrementalBuilder/buildBatchProtocol.ts +1 -1
- package/incrementalBuilder/builderBoot.ts +5 -5
- package/incrementalBuilder/builderGraphPayloads.ts +4 -4
- package/incrementalBuilder/builderLanes.ts +2 -2
- package/incrementalBuilder/builderWatch.ts +8 -8
- package/incrementalBuilder/csrRegistry.ts +4 -4
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +79 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +27 -8
- package/incrementalBuilder/ssrRegistry.ts +6 -6
- package/index.ts +1 -1
- package/integration/renderAdmissionSoak.test.ts +99 -0
- package/integration/renderAdmissionSoak.ts +609 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
- package/lint/biomeBase.test.ts +50 -3
- package/lint/biomeBase.ts +1 -1
- package/lint/biomeCheck.test.ts +162 -0
- package/lint/biomeCheck.ts +131 -0
- package/lint/linter.test.ts +16 -11
- package/lint/no-arbitrary-color.grit +5 -0
- package/lint/no-conditional-st-hook.grit +5 -1
- package/lint/no-daisyui-legacy-class.grit +8 -0
- package/lint/no-document-cookie.grit +3 -0
- package/lint/no-inline-color.grit +10 -2
- package/lint/no-oversized-list-limit.grit +2 -0
- package/lint/no-raw-palette-class.grit +7 -0
- package/lint/no-unpublished-form-setter.grit +2 -0
- package/lint/no-web-only-api-outside-webkit.grit +5 -0
- package/lint/no-web-storage.grit +3 -0
- package/lint/withheldEnvFile.ts +17 -0
- package/mobile/desktopBin.ts +2 -2
- package/mobile/desktopServerStage.test.ts +18 -3
- package/mobile/desktopServerStage.ts +7 -2
- package/mobile/nativeApp.test.ts +7 -5
- package/mobile/nativeApp.ts +2 -2
- package/mobile/nativeConfig.test.ts +96 -1
- package/mobile/nativeConfig.ts +46 -12
- package/mobile/nativePublicEnv.ts +1 -1
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +20 -171
- package/packageExports.test.ts +38 -24
- package/quality/dictionaryKeys.test.ts +356 -0
- package/quality/dictionaryKeys.ts +488 -0
- package/quality/objectImportReport.test.ts +36 -0
- package/quality/objectImportReport.ts +105 -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/quality/translatorBindings.ts +187 -0
- package/test/secretEnvFixture.ts +134 -0
- package/test/testHelpers.ts +11 -0
- package/transforms/barrelAnalyzer.ts +26 -4
- package/transforms/barrelImportsPlugin.ts +121 -32
- package/transforms/exportReach.test.ts +162 -0
- package/transforms/exportReach.ts +308 -0
- 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/moduleParts.test.ts +225 -0
- package/transforms/moduleParts.ts +418 -0
- package/transforms/objectImportEdits.ts +150 -0
- package/transforms/objectMemberImports.test.ts +633 -0
- package/transforms/objectMemberImports.ts +571 -0
- package/transforms/objectMemberLookup.ts +150 -0
- package/transforms/objectModule.test.ts +307 -0
- package/transforms/objectModule.ts +482 -0
- package/transforms/objectModuleAnalyzer.ts +104 -0
- package/transforms/partImports.test.ts +76 -0
- package/transforms/partImports.ts +110 -0
- package/transforms/partModules.test.ts +187 -0
- package/transforms/partModules.ts +90 -0
- package/transforms/partPurity.ts +124 -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/secretEnvDeclaration.test.ts +208 -0
- package/transforms/secretEnvDeclaration.ts +213 -0
- package/transforms/secretEnvFile.test.ts +117 -0
- package/transforms/secretEnvFile.ts +113 -0
- package/transforms/secretEnvName.test.ts +54 -0
- package/transforms/secretEnvName.ts +29 -0
- package/transforms/secretEnvSource.test.ts +148 -0
- package/transforms/secretEnvSource.ts +166 -0
- package/transforms/serverEnvEvaluationError.ts +11 -0
- package/transforms/serverEnvPlugin.test.ts +2 -1
- package/transforms/serverEnvPlugin.ts +13 -0
- package/transforms/serverEnvProfile.test.ts +129 -2
- package/transforms/serverEnvProfile.ts +126 -40
- package/transforms/serverEnvSecrets.test.ts +292 -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 +180 -3
- package/transforms/tsconfigPackageResolver.test.ts +1 -0
- package/tunnel/createTunnel.test.ts +29 -8
- package/tunnel/createTunnel.ts +22 -11
- package/tunnel/ssh2Module.test.ts +37 -0
- package/tunnel/ssh2Module.ts +32 -0
- package/tunnel/sshTunnel.ts +4 -2
- package/typecheck/projectTypecheck.test.ts +32 -1
- package/typecheck/projectTypecheck.ts +3 -3
- package/typecheck/typeChecker.test.ts +49 -0
- package/typecheck/typeChecker.ts +9 -7
- package/typecheck/withheldDiagnostics.ts +41 -0
- package/util/fileEditor.ts +1 -0
- package/util/selectModel.ts +1 -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/envSeed.test.ts +30 -1
- package/workspace/envSeed.ts +30 -1
- package/workspace/getRelatedCnsts.ts +7 -0
- package/workspace/mainCheckout.test.ts +55 -0
- package/workspace/mainCheckout.ts +38 -0
- package/workspace/scanInfo.test.ts +39 -0
- package/workspace/scanInfo.ts +55 -6
- package/workspace/slicePlanner.ts +1 -1
- package/workspace/workspaceLayout.test.ts +5 -1
- package/workspace/workspaceLayout.ts +3 -0
- package/CHANGELOG.md +0 -2717
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { tempDirs, writeText } from "../test/testHelpers";
|
|
4
|
+
import { type RouteRuntimeBuildReport, RouteRuntimeReport } from "./routeRuntimeReport";
|
|
5
|
+
|
|
6
|
+
const makeTempRoot = tempDirs("akan-devkit-route-runtime-report-");
|
|
7
|
+
|
|
8
|
+
const report: RouteRuntimeBuildReport = {
|
|
9
|
+
app: "demo",
|
|
10
|
+
routes: 12,
|
|
11
|
+
perModule: ["/memo"],
|
|
12
|
+
notSmaller: ["/board", "/board/:id"],
|
|
13
|
+
refused: ["/tally"],
|
|
14
|
+
causes: [
|
|
15
|
+
{
|
|
16
|
+
rule: "reader",
|
|
17
|
+
file: "apps/demo/ui/Pick.tsx",
|
|
18
|
+
line: 7,
|
|
19
|
+
message: "`st.use[name]`: the name is picked at run time",
|
|
20
|
+
entries: ["apps/demo/ui/Pick.tsx", "apps/demo/ui/Frame.tsx"],
|
|
21
|
+
routes: ["/a", "/b", "/c", "/d", "/e", "/f", "/g", "/h", "/i"],
|
|
22
|
+
chains: [["apps/demo/ui/Frame.tsx", "apps/demo/ui/Pick.tsx"]],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
rule: "not-smaller",
|
|
26
|
+
message: "/board is 950 B loading per module and 900 B with the whole runtime",
|
|
27
|
+
entries: ["apps/demo/ui/Board.tsx"],
|
|
28
|
+
routes: ["/board", "/board/:id"],
|
|
29
|
+
chains: [],
|
|
30
|
+
},
|
|
31
|
+
{ rule: "unheld", message: "no page loading per module holds it", entries: ["a", "b"], routes: [], chains: [] },
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
describe("what a build decided for each route, as akan quality runtime prints it", () => {
|
|
36
|
+
test("the build's one line counts the routes per module, the ones measured no smaller, and the ones kept for a named reason", () => {
|
|
37
|
+
expect(RouteRuntimeReport.summary(report)).toBe(
|
|
38
|
+
"1 route loads per module, 2 keep the whole runtime because per module would not be smaller, 9 keep it for a reason `akan quality runtime` names",
|
|
39
|
+
);
|
|
40
|
+
expect(RouteRuntimeReport.summary({ ...report, routes: 3 })).toBe(
|
|
41
|
+
"1 route loads per module, 2 keep the whole runtime because per module would not be smaller",
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("every reason names its file and line or its rule, the entries and routes it holds, and how the file is reached", () => {
|
|
46
|
+
expect(RouteRuntimeReport.format([report]).split("\n")).toEqual([
|
|
47
|
+
"Last build of apps/demo: 1 route loads per module, 2 keep the whole runtime because per module would not be smaller, 9 keep it for a reason `akan quality runtime` names.",
|
|
48
|
+
" per module: /memo",
|
|
49
|
+
" [reader] apps/demo/ui/Pick.tsx:7 `st.use[name]`: the name is picked at run time",
|
|
50
|
+
" 2 entries on 9 routes: /a, /b, /c, /d, /e, /f, and 3 more",
|
|
51
|
+
" reached as apps/demo/ui/Frame.tsx → apps/demo/ui/Pick.tsx",
|
|
52
|
+
" [not-smaller] /board is 950 B loading per module and 900 B with the whole runtime",
|
|
53
|
+
" 1 entry on 2 routes: /board, /board/:id",
|
|
54
|
+
" [unheld] no page loading per module holds it",
|
|
55
|
+
" 2 entries on 0 routes",
|
|
56
|
+
" 1 route measured no smaller per module than where every page keeps the whole runtime, and larger still keeping it here, so it loads per module: /tally",
|
|
57
|
+
]);
|
|
58
|
+
const many = { ...report, perModule: ["/a", "/b", "/c", "/d", "/e", "/f", "/g", "/h"], causes: [], refused: [] };
|
|
59
|
+
expect(RouteRuntimeReport.format([many]).split("\n")[1]).toBe(" per module: /a, /b, /c, /d, /e, /f, and 2 more");
|
|
60
|
+
expect(RouteRuntimeReport.format([])).toBe("");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("a build's report is read back from every app that has one, a file that is not a report left out", async () => {
|
|
64
|
+
const root = await makeTempRoot();
|
|
65
|
+
await RouteRuntimeReport.write(path.join(root, "apps/demo"), report);
|
|
66
|
+
await writeText(path.join(root, "apps/other", RouteRuntimeReport.file), "{}\n");
|
|
67
|
+
expect(await RouteRuntimeReport.read(root)).toEqual([report]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("a route that loads every text of the page dictionary is listed under the file and line that cost it", async () => {
|
|
71
|
+
const root = await makeTempRoot();
|
|
72
|
+
const appDir = path.join(root, "apps/demo");
|
|
73
|
+
const dictionary = [
|
|
74
|
+
{ file: "apps/demo/ui/Label.tsx", line: 4, why: "`l(key)`: the key is picked at run time", routes: ["/a", "/b"] },
|
|
75
|
+
{ file: "apps/demo/ui/Pick.tsx", why: "needs every module's client runtime", routes: ["/c"] },
|
|
76
|
+
];
|
|
77
|
+
await RouteRuntimeReport.addDictionary(appDir, dictionary);
|
|
78
|
+
expect(await RouteRuntimeReport.read(root)).toEqual([]);
|
|
79
|
+
|
|
80
|
+
await RouteRuntimeReport.write(appDir, { ...report, causes: [], refused: [] });
|
|
81
|
+
await RouteRuntimeReport.addDictionary(appDir, dictionary);
|
|
82
|
+
const reports = await RouteRuntimeReport.read(root);
|
|
83
|
+
expect(reports[0]?.dictionary).toEqual(dictionary);
|
|
84
|
+
expect(RouteRuntimeReport.format(reports).split("\n").slice(2)).toEqual([
|
|
85
|
+
" [dictionary] apps/demo/ui/Label.tsx:4 `l(key)`: the key is picked at run time",
|
|
86
|
+
" 2 routes load every text of the page dictionary: /a, /b",
|
|
87
|
+
" [dictionary] apps/demo/ui/Pick.tsx needs every module's client runtime",
|
|
88
|
+
" 1 route loads every text of the page dictionary: /c",
|
|
89
|
+
]);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { RouteRuntimeCause } from "../transforms/routeRuntimePlan";
|
|
3
|
+
|
|
4
|
+
export interface RouteRuntimeBuildReport {
|
|
5
|
+
app: string;
|
|
6
|
+
routes: number;
|
|
7
|
+
perModule: string[];
|
|
8
|
+
//? Routes the analysis could load per module, kept whole because the build measured them no smaller that way.
|
|
9
|
+
notSmaller: string[];
|
|
10
|
+
//? Routes no smaller per module than where every page keeps the whole runtime, which came out larger still when the
|
|
11
|
+
//? build kept it for them among this app's other pages: they load per module.
|
|
12
|
+
refused?: string[];
|
|
13
|
+
causes: RouteRuntimeCause[];
|
|
14
|
+
dictionary?: RouteRuntimeDictionaryFallback[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface RouteRuntimeDictionaryFallback {
|
|
18
|
+
file: string;
|
|
19
|
+
line?: number;
|
|
20
|
+
why: string;
|
|
21
|
+
routes: string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const count = (items: readonly unknown[], one: string, many = `${one}s`) =>
|
|
25
|
+
`${items.length} ${items.length === 1 ? one : many}`;
|
|
26
|
+
|
|
27
|
+
export class RouteRuntimeReport {
|
|
28
|
+
//? Under `.akan/cache`: the development server clears the rest of `.akan` when it starts.
|
|
29
|
+
static readonly file = ".akan/cache/route-runtime.json";
|
|
30
|
+
static readonly shown = 6;
|
|
31
|
+
|
|
32
|
+
static summary({ perModule, notSmaller, routes }: RouteRuntimeBuildReport): string {
|
|
33
|
+
const named = routes - perModule.length - notSmaller.length;
|
|
34
|
+
const verb = (many: number, word: string) => (many === 1 ? `${word}s` : word);
|
|
35
|
+
return [
|
|
36
|
+
`${count(perModule, "route")} ${verb(perModule.length, "load")} per module`,
|
|
37
|
+
`${notSmaller.length} ${verb(notSmaller.length, "keep")} the whole runtime because per module would not be smaller`,
|
|
38
|
+
...(named > 0 ? [`${named} ${verb(named, "keep")} it for a reason \`akan quality runtime\` names`] : []),
|
|
39
|
+
].join(", ");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static format(reports: readonly RouteRuntimeBuildReport[]): string {
|
|
43
|
+
return reports
|
|
44
|
+
.map((report) =>
|
|
45
|
+
[
|
|
46
|
+
`Last build of apps/${report.app}: ${RouteRuntimeReport.summary(report)}.`,
|
|
47
|
+
...RouteRuntimeReport.#perModuleLines(report.perModule),
|
|
48
|
+
...report.causes.flatMap((cause) => RouteRuntimeReport.#causeLines(cause)),
|
|
49
|
+
...RouteRuntimeReport.#refusedLines(report.refused ?? []),
|
|
50
|
+
...(report.dictionary ?? []).flatMap((fallback) => RouteRuntimeReport.#dictionaryLines(fallback)),
|
|
51
|
+
].join("\n"),
|
|
52
|
+
)
|
|
53
|
+
.join("\n\n");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static #perModuleLines(routes: readonly string[]): string[] {
|
|
57
|
+
if (routes.length === 0) return [];
|
|
58
|
+
const more =
|
|
59
|
+
routes.length > RouteRuntimeReport.shown ? `, and ${routes.length - RouteRuntimeReport.shown} more` : "";
|
|
60
|
+
return [` per module: ${routes.slice(0, RouteRuntimeReport.shown).join(", ")}${more}`];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static #causeLines({ rule, file, line, message, entries, routes, chains }: RouteRuntimeCause): string[] {
|
|
64
|
+
const where = file ? `${file}${line ? `:${line}` : ""} ` : "";
|
|
65
|
+
const listed = routes.slice(0, RouteRuntimeReport.shown).join(", ");
|
|
66
|
+
const more =
|
|
67
|
+
routes.length > RouteRuntimeReport.shown ? `, and ${routes.length - RouteRuntimeReport.shown} more` : "";
|
|
68
|
+
return [
|
|
69
|
+
` [${rule}] ${where}${message}`,
|
|
70
|
+
` ${count(entries, "entry", "entries")} on ${count(routes, "route")}${routes.length ? `: ${listed}${more}` : ""}`,
|
|
71
|
+
...chains.map((chain) => ` reached as ${RouteRuntimeReport.#chain(chain)}`),
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static #refusedLines(routes: readonly string[]): string[] {
|
|
76
|
+
if (routes.length === 0) return [];
|
|
77
|
+
const more =
|
|
78
|
+
routes.length > RouteRuntimeReport.shown ? `, and ${routes.length - RouteRuntimeReport.shown} more` : "";
|
|
79
|
+
return [
|
|
80
|
+
` ${count(routes, "route")} measured no smaller per module than where every page keeps the whole runtime, and larger still keeping it here, so ${routes.length === 1 ? "it loads" : "they load"} per module: ${routes.slice(0, RouteRuntimeReport.shown).join(", ")}${more}`,
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static #dictionaryLines({ file, line, why, routes }: RouteRuntimeDictionaryFallback): string[] {
|
|
85
|
+
const more =
|
|
86
|
+
routes.length > RouteRuntimeReport.shown ? `, and ${routes.length - RouteRuntimeReport.shown} more` : "";
|
|
87
|
+
return [
|
|
88
|
+
` [dictionary] ${file}${line ? `:${line}` : ""} ${why}`,
|
|
89
|
+
` ${count(routes, "route")} ${routes.length === 1 ? "loads" : "load"} every text of the page dictionary: ${routes.slice(0, RouteRuntimeReport.shown).join(", ")}${more}`,
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static #chain(chain: readonly string[]) {
|
|
94
|
+
return chain.length > 6
|
|
95
|
+
? `${chain.slice(0, 2).join(" → ")} → … → ${chain.slice(-3).join(" → ")}`
|
|
96
|
+
: chain.join(" → ");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static async write(appDir: string, report: RouteRuntimeBuildReport) {
|
|
100
|
+
await Bun.write(path.join(appDir, RouteRuntimeReport.file), `${JSON.stringify(report, null, 1)}\n`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static async addDictionary(appDir: string, dictionary: RouteRuntimeDictionaryFallback[]) {
|
|
104
|
+
const report: RouteRuntimeBuildReport | null = await Bun.file(path.join(appDir, RouteRuntimeReport.file))
|
|
105
|
+
.json()
|
|
106
|
+
.catch(() => null);
|
|
107
|
+
if (report) await RouteRuntimeReport.write(appDir, { ...report, dictionary });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static async read(workspaceRoot: string): Promise<RouteRuntimeBuildReport[]> {
|
|
111
|
+
const files = [...new Bun.Glob(`apps/*/${RouteRuntimeReport.file}`).scanSync({ cwd: workspaceRoot, dot: true })];
|
|
112
|
+
const reports = await Promise.all(
|
|
113
|
+
files.sort().map((file) =>
|
|
114
|
+
Bun.file(path.join(workspaceRoot, file))
|
|
115
|
+
.json()
|
|
116
|
+
.catch(() => null),
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
return reports.filter((report): report is RouteRuntimeBuildReport => !!report && Array.isArray(report.causes));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import type { RuntimeSourceFile } from "./runtimeModuleFacts";
|
|
4
|
+
|
|
5
|
+
export interface RuntimeConstantFact {
|
|
6
|
+
scope: string;
|
|
7
|
+
module: string;
|
|
8
|
+
kind: "database" | "scalar";
|
|
9
|
+
file: string;
|
|
10
|
+
exports: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type RuntimeConstantEntry =
|
|
14
|
+
| { type: "model" | "export"; fact: RuntimeConstantFact }
|
|
15
|
+
| { type: "namespace"; scope: string };
|
|
16
|
+
|
|
17
|
+
const constantPath = /^((?:apps|libs)\/[^/]+)\/lib\/(__scalar\/)?([^/_][^/]*)\/\3\.constant$/;
|
|
18
|
+
|
|
19
|
+
export class RuntimeConstantFacts {
|
|
20
|
+
static of({ file, sourceFile }: RuntimeSourceFile): RuntimeConstantFact | null {
|
|
21
|
+
const [, scope, scalar, module] = file.replace(/\.ts$/, "").match(constantPath) ?? [];
|
|
22
|
+
if (!scope || !module) return null;
|
|
23
|
+
const exports = new Set<string>();
|
|
24
|
+
for (const statement of sourceFile.statements) {
|
|
25
|
+
if (ts.isExportDeclaration(statement)) {
|
|
26
|
+
if (statement.isTypeOnly) continue;
|
|
27
|
+
const clause = statement.exportClause;
|
|
28
|
+
if (clause && ts.isNamedExports(clause))
|
|
29
|
+
for (const element of clause.elements) if (!element.isTypeOnly) exports.add(element.name.text);
|
|
30
|
+
} else for (const name of RuntimeConstantFacts.#declaredExports(statement)) exports.add(name);
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
scope,
|
|
34
|
+
module,
|
|
35
|
+
kind: scalar ? "scalar" : "database",
|
|
36
|
+
file: file.replace(/\.ts$/, ""),
|
|
37
|
+
exports: [...exports].sort(),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static ownerOf(specifier: string, fileName: string): { scope: string; module: string } | null {
|
|
42
|
+
const aliased = specifier.match(/^@((?:apps|libs)\/[\s\S]+)$/)?.[1];
|
|
43
|
+
const joined =
|
|
44
|
+
aliased ?? (specifier.startsWith(".") ? path.posix.join(path.posix.dirname(fileName), specifier) : null);
|
|
45
|
+
const [, scope, , module] = joined
|
|
46
|
+
? (path.posix.normalize(joined).replace(/\.ts$/, "").match(constantPath) ?? [])
|
|
47
|
+
: [];
|
|
48
|
+
return scope && module ? { scope, module } : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static #declaredExports(statement: ts.Statement): string[] {
|
|
52
|
+
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) : undefined;
|
|
53
|
+
const exported = modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
54
|
+
if (!exported || modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DeclareKeyword)) return [];
|
|
55
|
+
if (modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword)) return [];
|
|
56
|
+
if (ts.isVariableStatement(statement))
|
|
57
|
+
return statement.declarationList.declarations.flatMap((declaration) =>
|
|
58
|
+
RuntimeConstantFacts.#bindingNames(declaration.name),
|
|
59
|
+
);
|
|
60
|
+
if (ts.isClassDeclaration(statement) || ts.isFunctionDeclaration(statement) || ts.isEnumDeclaration(statement))
|
|
61
|
+
return statement.name ? [statement.name.text] : [];
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static #bindingNames(name: ts.BindingName): string[] {
|
|
66
|
+
if (ts.isIdentifier(name)) return [name.text];
|
|
67
|
+
return name.elements.flatMap((element) =>
|
|
68
|
+
ts.isOmittedExpression(element) ? [] : RuntimeConstantFacts.#bindingNames(element.name),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import type { RuntimeConstantFact } from "./runtimeConstantFacts";
|
|
4
|
+
import type { RuntimeNameTable, RuntimeOwner } from "./runtimeNameTable";
|
|
5
|
+
import { RuntimeUse, type RuntimeUseProblem } from "./runtimeUse";
|
|
6
|
+
|
|
7
|
+
export interface RuntimeConstantNeeds {
|
|
8
|
+
owners: RuntimeOwner[];
|
|
9
|
+
problems: RuntimeUseProblem[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const keyOf = ({ scope, module }: RuntimeOwner) => `${scope}/${module}`;
|
|
13
|
+
|
|
14
|
+
export class RuntimeConstantGraph {
|
|
15
|
+
readonly #table: RuntimeNameTable;
|
|
16
|
+
readonly #read: (file: string) => string | null;
|
|
17
|
+
readonly #needs = new Map<string, RuntimeConstantNeeds>();
|
|
18
|
+
|
|
19
|
+
constructor(table: RuntimeNameTable, read: (file: string) => string | null) {
|
|
20
|
+
this.#table = table;
|
|
21
|
+
this.#read = read;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static ofDisk(workspaceRoot: string, table: RuntimeNameTable) {
|
|
25
|
+
return new RuntimeConstantGraph(table, (file) => {
|
|
26
|
+
try {
|
|
27
|
+
return readFileSync(path.join(workspaceRoot, file), "utf8");
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get table() {
|
|
35
|
+
return this.#table;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
factOf({ scope, module }: RuntimeOwner): RuntimeConstantFact | null {
|
|
39
|
+
return this.#table.constantsOf(scope).find((fact) => fact.module === module) ?? null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
declarationsOf(owner: RuntimeOwner): RuntimeOwner[] {
|
|
43
|
+
const kind = this.factOf(owner)?.kind;
|
|
44
|
+
return kind ? this.#declarationsOf(owner.module, kind) : [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#declarationsOf(module: string, kind: RuntimeConstantFact["kind"]): RuntimeOwner[] {
|
|
48
|
+
return this.#table.layers
|
|
49
|
+
.filter(({ constants }) => constants?.some((fact) => fact.module === module && fact.kind === kind))
|
|
50
|
+
.map(({ scope }) => ({ scope, module }));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
modelOf(module: string): RuntimeOwner | null {
|
|
54
|
+
return this.#declarationsOf(module, "database").at(-1) ?? null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//? The outermost scope: an app model extends the lib model of its name, so the app's piece registers both, lib first.
|
|
58
|
+
registrationOf(owner: RuntimeOwner): RuntimeOwner | null {
|
|
59
|
+
return this.declarationsOf(owner).at(-1) ?? null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
needsOf(owner: RuntimeOwner): RuntimeConstantNeeds {
|
|
63
|
+
const key = keyOf(owner);
|
|
64
|
+
const known = this.#needs.get(key);
|
|
65
|
+
if (known) return known;
|
|
66
|
+
const file = this.factOf(owner)?.file;
|
|
67
|
+
const needs = file ? this.needsOfFile(`${file}.ts`) : { owners: [], problems: [] };
|
|
68
|
+
const result = { ...needs, owners: needs.owners.filter((named) => keyOf(named) !== key) };
|
|
69
|
+
this.#needs.set(key, result);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
needsOfFile(fileName: string): RuntimeConstantNeeds {
|
|
74
|
+
const text = this.#read(fileName);
|
|
75
|
+
if (text === null) return { owners: [], problems: [] };
|
|
76
|
+
const { constants } = RuntimeUse.analyze({ fileName, text }, this.#table);
|
|
77
|
+
const owners = new Map<string, RuntimeOwner>();
|
|
78
|
+
for (const owner of constants.imports) owners.set(keyOf(owner), owner);
|
|
79
|
+
for (const read of constants.reads)
|
|
80
|
+
for (const { owner } of read.kind === "member" ? [read] : read.keys) owners.set(keyOf(owner), owner);
|
|
81
|
+
return { owners: [...owners.values()], problems: constants.problems };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fetchNeedsOf(module: string): RuntimeOwner[] | null {
|
|
85
|
+
const model = this.modelOf(module);
|
|
86
|
+
const owners = model ? [model] : [];
|
|
87
|
+
for (const { scope, modules } of this.#table.layers)
|
|
88
|
+
for (const fact of modules)
|
|
89
|
+
if (fact.module === module && fact.signal) {
|
|
90
|
+
const dir = fact.kind === "service" ? `_${module}` : module;
|
|
91
|
+
const needs = this.needsOfFile(`${scope}/lib/${dir}/${module}.signal.ts`);
|
|
92
|
+
if (needs.problems.length) return null;
|
|
93
|
+
owners.push(...needs.owners);
|
|
94
|
+
}
|
|
95
|
+
return this.closureOf(owners);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
closureOf(owners: RuntimeOwner[]): RuntimeOwner[] {
|
|
99
|
+
const found = new Map<string, RuntimeOwner>();
|
|
100
|
+
const visit = (owner: RuntimeOwner) => {
|
|
101
|
+
const registration = this.registrationOf(owner);
|
|
102
|
+
if (!registration || found.has(keyOf(registration))) return;
|
|
103
|
+
found.set(keyOf(registration), registration);
|
|
104
|
+
for (const declaration of this.declarationsOf(registration))
|
|
105
|
+
for (const named of this.needsOf(declaration).owners) visit(named);
|
|
106
|
+
};
|
|
107
|
+
owners.forEach(visit);
|
|
108
|
+
return [...found.values()];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//? An edge closing a cycle is left out: a piece imported back by one it imports reads an unset binding at load.
|
|
112
|
+
piecesBefore(owner: RuntimeOwner): { libs: RuntimeOwner[]; named: RuntimeOwner[] } {
|
|
113
|
+
const libs = this.declarationsOf(owner).filter(({ scope }) => scope !== owner.scope);
|
|
114
|
+
const named = new Map<string, RuntimeOwner>();
|
|
115
|
+
for (const need of this.needsOf(owner).owners) {
|
|
116
|
+
const registration = this.registrationOf(need);
|
|
117
|
+
if (!registration || keyOf(registration) === keyOf(owner)) continue;
|
|
118
|
+
if (this.closureOf([registration]).some((reached) => keyOf(reached) === keyOf(owner))) continue;
|
|
119
|
+
named.set(keyOf(registration), registration);
|
|
120
|
+
}
|
|
121
|
+
return { libs, named: [...named.values()] };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { type RuntimeConstantEntry, RuntimeConstantFacts } from "./runtimeConstantFacts";
|
|
3
|
+
import type { RuntimeNameTable, RuntimeOwner } from "./runtimeNameTable";
|
|
4
|
+
import { climb, memberName, type PositionedProblem, problemAt, sortedProblems, staticName } from "./runtimeSyntax";
|
|
5
|
+
import type { RuntimeUseProblem, RuntimeUseReason } from "./runtimeUse";
|
|
6
|
+
|
|
7
|
+
export interface RuntimeConstantName {
|
|
8
|
+
name: string;
|
|
9
|
+
owner: RuntimeOwner;
|
|
10
|
+
file: string;
|
|
11
|
+
//? The object `ConstantRegistry.buildModel` returns, which only the model's registration piece exports.
|
|
12
|
+
model: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type RuntimeConstantRead =
|
|
16
|
+
| ({ kind: "member"; start: number; end: number } & RuntimeConstantName)
|
|
17
|
+
| { kind: "destructure"; start: number; end: number; keys: ({ key: string } & RuntimeConstantName)[] };
|
|
18
|
+
|
|
19
|
+
export interface RuntimeConstantUse {
|
|
20
|
+
reads: RuntimeConstantRead[];
|
|
21
|
+
imports: RuntimeOwner[];
|
|
22
|
+
problems: RuntimeUseProblem[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class RuntimeConstantReads {
|
|
26
|
+
readonly #source: ts.SourceFile;
|
|
27
|
+
readonly #fileName: string;
|
|
28
|
+
readonly #consumer: RuntimeNameTable | null;
|
|
29
|
+
readonly #recording: () => boolean;
|
|
30
|
+
readonly #reads = new Map<number, RuntimeConstantRead>();
|
|
31
|
+
readonly #imports = new Map<string, RuntimeOwner>();
|
|
32
|
+
readonly #problems: PositionedProblem[] = [];
|
|
33
|
+
|
|
34
|
+
constructor(source: ts.SourceFile, fileName: string, consumer: RuntimeNameTable | null, recording: () => boolean) {
|
|
35
|
+
this.#source = source;
|
|
36
|
+
this.#fileName = fileName;
|
|
37
|
+
this.#consumer = consumer;
|
|
38
|
+
this.#recording = recording;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get use(): RuntimeConstantUse {
|
|
42
|
+
return {
|
|
43
|
+
reads: [...this.#reads.values()].sort((a, b) => a.start - b.start),
|
|
44
|
+
imports: [...this.#imports.values()],
|
|
45
|
+
problems: sortedProblems([...this.#problems]),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
imported(specifier: string) {
|
|
50
|
+
const owner = RuntimeConstantFacts.ownerOf(specifier, this.#fileName);
|
|
51
|
+
if (owner) this.#imports.set(`${owner.scope}/${owner.module}`, owner);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
follow(node: ts.Expression, scope: string) {
|
|
55
|
+
const { current, parent } = climb(node);
|
|
56
|
+
const access =
|
|
57
|
+
(ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent)) && parent.expression === current
|
|
58
|
+
? parent
|
|
59
|
+
: null;
|
|
60
|
+
if (access) this.#member(access, scope);
|
|
61
|
+
else if (ts.isVariableDeclaration(parent) && parent.initializer === current)
|
|
62
|
+
this.#destructure(parent, current, scope);
|
|
63
|
+
else this.problem("passed-on", current, "the constants are handed on whole");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
#member(access: ts.PropertyAccessExpression | ts.ElementAccessExpression, scope: string) {
|
|
67
|
+
const name = memberName(access);
|
|
68
|
+
const entry = name === null ? null : this.#consumer?.constantOf(scope, name);
|
|
69
|
+
if (name === null) this.problem("computed-access", access, "the constant is picked at run time");
|
|
70
|
+
else if (!entry) this.problem("unknown-name", access, `${name} is not a constant ${scope} hands out`);
|
|
71
|
+
else if (entry.type === "namespace") this.follow(access, entry.scope);
|
|
72
|
+
else {
|
|
73
|
+
const [start, end] = [access.getStart(this.#source), access.end];
|
|
74
|
+
this.#read({ kind: "member", start, end, ...RuntimeConstantReads.#nameOf(name, entry) });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
problem(reason: RuntimeUseReason, node: ts.Node, why: string) {
|
|
79
|
+
if (!this.#recording()) return;
|
|
80
|
+
const found = problemAt(this.#source, reason, node, why);
|
|
81
|
+
if (!this.#problems.some(({ position }) => position === found.position)) this.#problems.push(found);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#destructure(declaration: ts.VariableDeclaration, initializer: ts.Expression, scope: string) {
|
|
85
|
+
const list = declaration.parent;
|
|
86
|
+
const statement = list.parent;
|
|
87
|
+
const exported =
|
|
88
|
+
ts.isVariableStatement(statement) &&
|
|
89
|
+
!!statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
90
|
+
const pattern = declaration.name;
|
|
91
|
+
if (exported || !(list.flags & ts.NodeFlags.Const) || !ts.isObjectBindingPattern(pattern))
|
|
92
|
+
return this.problem("passed-on", declaration, "the constants are held whole under another name");
|
|
93
|
+
const keys: ({ key: string } & RuntimeConstantName)[] = [];
|
|
94
|
+
for (const element of pattern.elements) {
|
|
95
|
+
const key = element.propertyName ?? element.name;
|
|
96
|
+
const name = ts.isIdentifier(key) ? key.text : staticName(key);
|
|
97
|
+
const entry = name === null ? null : this.#consumer?.constantOf(scope, name);
|
|
98
|
+
if (element.dotDotDotToken || name === null || !ts.isIdentifier(element.name))
|
|
99
|
+
return this.problem("hidden-by-destructuring", element, "a rest, computed or nested key hides names");
|
|
100
|
+
if (!entry) return this.problem("unknown-name", element, `${name} is not a constant ${scope} hands out`);
|
|
101
|
+
if (entry.type === "namespace")
|
|
102
|
+
return this.problem("passed-on", element, `${name} holds ${entry.scope}'s constants whole`);
|
|
103
|
+
keys.push({ key: name, ...RuntimeConstantReads.#nameOf(name, entry) });
|
|
104
|
+
}
|
|
105
|
+
this.#read({ kind: "destructure", start: initializer.getStart(this.#source), end: initializer.end, keys });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#read(read: RuntimeConstantRead) {
|
|
109
|
+
if (this.#recording()) this.#reads.set(read.start, read);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static #nameOf(name: string, entry: Exclude<RuntimeConstantEntry, { type: "namespace" }>): RuntimeConstantName {
|
|
113
|
+
const { scope, module, file } = entry.fact;
|
|
114
|
+
return { name, owner: { scope, module }, file, model: entry.type === "model" };
|
|
115
|
+
}
|
|
116
|
+
}
|