@akanjs/devkit 3.3.0-rc.7 → 3.3.0-rc.71
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 +10 -3
- package/README.md +10 -4
- package/akanApp/akanApp.host.test.ts +4 -2
- package/akanApp/akanApp.host.ts +26 -2
- package/akanApp/akanApp.host.wiring.test.ts +111 -0
- package/akanApp/devHostPolicy.ts +5 -0
- package/akanApp/devMetadataRestart.ts +93 -0
- package/akanApp/devRecycler.test.ts +2 -0
- package/akanApp/devRecycler.ts +9 -0
- package/akanConfig/akanBin.ts +4 -0
- package/akanConfig/akanConfig.test.ts +358 -21
- package/akanConfig/akanConfig.ts +113 -272
- package/akanConfig/akanPreview.test.ts +28 -0
- package/akanConfig/akanPreview.ts +24 -0
- package/akanConfig/akanWorkers.test.ts +73 -0
- package/akanConfig/akanWorkers.ts +61 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +250 -0
- package/akanConfig/index.ts +3 -0
- package/akanConfig/nativeFileSettings.ts +33 -0
- package/akanConfig/nativeKeys.ts +52 -0
- package/akanConfig/types.ts +4 -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 +427 -5
- package/app/applicationBuildRunner.ts +232 -37
- package/app/clientServerBoundary.test.ts +115 -0
- package/app/clientServerBoundary.ts +89 -0
- 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/index.ts +1 -34
- 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 +8 -3
- package/codeAgent/skills/akan-deps/SKILL.md +10 -3
- 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 +65 -30
- 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 +21 -20
- package/codeAgent/skills/akan-transport/SKILL.md +5 -14
- package/codeAgent/skills/akan-ui/SKILL.md +16 -21
- package/codeAgent/skills/akan-validate/SKILL.md +8 -2
- 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/csrE2e/ssrRegistry.e2e.test.ts +108 -22
- package/docs/apiReference.test.ts +25 -0
- package/docs/apiReference.ts +38 -5
- package/docs/declarationReader.ts +30 -0
- 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 +155 -1
- package/executors/pkgExecutor.ts +2 -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 +4 -5
- package/frontendBuild/csrDevPatcher.ts +37 -11
- package/frontendBuild/csrDevTypes.ts +9 -0
- package/frontendBuild/devBarrelImports.test.ts +154 -0
- package/frontendBuild/devBarrelImports.ts +83 -23
- package/frontendBuild/devChangePlanner.ts +0 -1
- 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/frontendBuild.test.ts +5 -3
- 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 +30 -35
- 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.test.ts +47 -3
- package/frontendBuild/vendorNarrowing.ts +38 -2
- package/frontendBuild/vendorSpecifiers.ts +2 -0
- package/guideline/agentAssets.ts +1 -1
- package/incrementalBuilder/buildBatch.proc.ts +35 -9
- package/incrementalBuilder/buildBatchProtocol.ts +2 -1
- package/incrementalBuilder/builderBoot.ts +5 -5
- package/incrementalBuilder/builderGraphPayloads.ts +4 -4
- package/incrementalBuilder/builderLanes.ts +2 -2
- package/incrementalBuilder/builderWatch.ts +19 -9
- package/incrementalBuilder/csrRegistry.ts +4 -4
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +159 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +38 -10
- package/incrementalBuilder/pendingMetadata.test.ts +27 -0
- package/incrementalBuilder/pendingMetadata.ts +19 -0
- package/incrementalBuilder/ssrRegistry.ts +6 -6
- package/index.ts +1 -1
- package/integration/devResourceProbe.ts +14 -0
- package/integration/devStability.integration.test.ts +46 -21
- package/integration/renderAdmissionSoak.test.ts +99 -0
- package/integration/renderAdmissionSoak.ts +615 -0
- package/integration/ssrMemoryProbe.ts +5 -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 +13 -5
- package/mobile/nativeApp.ts +9 -4
- 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 +22 -178
- package/packageExports.test.ts +39 -24
- package/preview/PreviewView.ts +25 -3
- 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/fakeTerminal.ts +45 -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 +211 -0
- package/transforms/secretEnvDeclaration.ts +219 -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 +152 -0
- package/transforms/secretEnvSource.ts +197 -0
- package/transforms/serverEnvEvaluationError.ts +11 -0
- package/transforms/serverEnvPlugin.test.ts +118 -1
- package/transforms/serverEnvPlugin.ts +95 -2
- package/transforms/serverEnvProfile.test.ts +129 -2
- package/transforms/serverEnvProfile.ts +133 -43
- package/transforms/serverEnvSecrets.test.ts +268 -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 +28 -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/devInstallCommand.ts +7 -0
- package/util/fileEditor.ts +1 -0
- package/util/jsonFormatter.test.ts +13 -9
- 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 +2 -1
- package/workspace/workspaceLayout.test.ts +22 -1
- package/workspace/workspaceLayout.ts +3 -3
- package/CHANGELOG.md +0 -2718
- package/codeAgent/agent/AkanCodeCompaction.ts +0 -49
- package/codeAgent/agent/AkanCodeServices.ts +0 -122
- package/codeAgent/agent/AkanContextFiles.ts +0 -94
- package/codeAgent/agent/CodeAgent.ts +0 -606
- package/codeAgent/agent/CodeAgentAsks.ts +0 -66
- package/codeAgent/agent/CodeAgentEventMapper.ts +0 -225
- package/codeAgent/agent/CodeAgentGate.ts +0 -239
- package/codeAgent/agent/CodeAgentProxy.ts +0 -83
- package/codeAgent/agent/CodeAgentRpcHost.ts +0 -109
- package/codeAgent/agent/CodeAgentRpcListener.ts +0 -195
- package/codeAgent/agent/CodeAgentStreamPrinter.ts +0 -86
- package/codeAgent/agent/CodeAgentSuspended.ts +0 -85
- package/codeAgent/agent/CodeAgentUi.ts +0 -47
- package/codeAgent/agent/CodeMailbox.ts +0 -148
- package/codeAgent/agent/CodeSessionFork.ts +0 -56
- package/codeAgent/agent/CodeSessionIndex.ts +0 -78
- package/codeAgent/agent/SubagentPool.ts +0 -219
- package/codeAgent/agent/WorkspaceTrust.ts +0 -200
- package/codeAgent/agent/akanCodeCompaction.test.ts +0 -36
- package/codeAgent/agent/akanCodeModel.ts +0 -47
- package/codeAgent/agent/akanCodeServices.test.ts +0 -54
- package/codeAgent/agent/akanContextFiles.test.ts +0 -116
- package/codeAgent/agent/akanSystemPrompt.ts +0 -50
- package/codeAgent/agent/codeAgent.test.ts +0 -275
- package/codeAgent/agent/codeAgentContract.test.ts +0 -643
- package/codeAgent/agent/codeAgentHosts.ts +0 -30
- package/codeAgent/agent/codeAgentProxy.test.ts +0 -126
- package/codeAgent/agent/codeAgentRpcListener.test.ts +0 -215
- package/codeAgent/agent/codeAgentSuspended.test.ts +0 -47
- package/codeAgent/agent/codeMailbox.test.ts +0 -76
- package/codeAgent/agent/codeSessionFork.test.ts +0 -58
- package/codeAgent/agent/codeSessionIndex.test.ts +0 -77
- package/codeAgent/agent/consoleToStderr.ts +0 -8
- package/codeAgent/agent/jsonLines.ts +0 -29
- package/codeAgent/agent/stringArg.ts +0 -5
- package/codeAgent/feedback/DevLogFeedback.ts +0 -82
- package/codeAgent/feedback/PreviewFeedback.ts +0 -46
- package/codeAgent/feedback/TurnFeedback.ts +0 -98
- package/codeAgent/feedback/VerifyFeedback.ts +0 -39
- package/codeAgent/tools/AkanCli.ts +0 -51
- package/codeAgent/tools/AkanCodePlugins.ts +0 -142
- package/codeAgent/tools/AkanEditScope.ts +0 -53
- package/codeAgent/tools/AkanEnvKeys.ts +0 -50
- package/codeAgent/tools/AkanToolPack.ts +0 -86
- package/codeAgent/tools/AkanVerifier.ts +0 -30
- package/codeAgent/tools/AskToolPack.ts +0 -99
- package/codeAgent/tools/DeepSeekWeb.ts +0 -127
- package/codeAgent/tools/MailToolPack.ts +0 -76
- package/codeAgent/tools/McpClient.ts +0 -209
- package/codeAgent/tools/McpOAuth.ts +0 -233
- package/codeAgent/tools/McpOAuthLoopback.ts +0 -64
- package/codeAgent/tools/McpServerConfig.ts +0 -131
- package/codeAgent/tools/McpSignIn.ts +0 -158
- package/codeAgent/tools/McpTokenStore.ts +0 -128
- package/codeAgent/tools/McpToolPack.ts +0 -206
- package/codeAgent/tools/SessionToolPack.ts +0 -91
- package/codeAgent/tools/WebToolPack.ts +0 -315
- package/codeAgent/tools/akanCodePlugins.test.ts +0 -954
- package/codeAgent/tools/askToolPack.test.ts +0 -116
- package/codeAgent/tools/deepSeekWeb.test.ts +0 -113
- package/codeAgent/tools/mcpOAuth.test.ts +0 -648
- package/codeAgent/tools/mcpServerConfig.test.ts +0 -341
- package/piDependencyPins.test.ts +0 -45
|
@@ -0,0 +1,835 @@
|
|
|
1
|
+
import { beforeAll, describe, expect, test } from "bun:test";
|
|
2
|
+
import { runtimeFixtureTables } from "../quality/runtimeTable.fixture";
|
|
3
|
+
import { RuntimeUse, type RuntimeUseReason } from "../quality/runtimeUse";
|
|
4
|
+
import { RouteRuntime } from "./routeRuntime";
|
|
5
|
+
|
|
6
|
+
const root = "/ws";
|
|
7
|
+
const appPieces = ["_useClient", "_st", "_base.fetch", "memo.fetch", "memo.st", "note.fetch", "note.st", "tag.fetch"];
|
|
8
|
+
const kitPieces = ["_useClient", "_st", "note.fetch", "note.st", "tag.fetch", "tag.st", "util.st"];
|
|
9
|
+
const piecesOf = (app = appPieces, kit = kitPieces) =>
|
|
10
|
+
new Set([
|
|
11
|
+
...app.map((piece) => `apps/demo/lib/__client/${piece}`),
|
|
12
|
+
...kit.map((piece) => `libs/kit/lib/__client/${piece}`),
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
let runtime: RouteRuntime;
|
|
16
|
+
let withoutTagStore: RouteRuntime;
|
|
17
|
+
let withStores: (stores: Record<string, string>, kit?: string[]) => RouteRuntime;
|
|
18
|
+
|
|
19
|
+
beforeAll(async () => {
|
|
20
|
+
const { demo } = await runtimeFixtureTables();
|
|
21
|
+
runtime = new RouteRuntime(root, demo, piecesOf());
|
|
22
|
+
withStores = (stores, kit) =>
|
|
23
|
+
new RouteRuntime(root, demo, piecesOf(appPieces, kit), (absPath) => stores[absPath] ?? null);
|
|
24
|
+
withoutTagStore = new RouteRuntime(
|
|
25
|
+
root,
|
|
26
|
+
demo,
|
|
27
|
+
piecesOf(
|
|
28
|
+
appPieces,
|
|
29
|
+
kitPieces.filter((piece) => piece !== "tag.st"),
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const transform = (source: string, file = "apps/demo/ui/Card.tsx", target = runtime) =>
|
|
35
|
+
target.transform(source, `${root}/${file}`);
|
|
36
|
+
|
|
37
|
+
const bound = (...pieces: [name: string, specifier: string][]) =>
|
|
38
|
+
[
|
|
39
|
+
'import { loadedAfter as __akanLoadedAfter } from "akanjs/base";',
|
|
40
|
+
...pieces.map(([name, specifier], index) =>
|
|
41
|
+
name === "*"
|
|
42
|
+
? `import * as __akanLoaded${index} from "${specifier}";`
|
|
43
|
+
: `import { ${name} as __akanLoaded${index} } from "${specifier}";`,
|
|
44
|
+
),
|
|
45
|
+
`__akanLoadedAfter(${pieces.map((_, index) => `__akanLoaded${index}`).join(", ")});`,
|
|
46
|
+
].join(" ");
|
|
47
|
+
|
|
48
|
+
const whole = `${bound(
|
|
49
|
+
["*", "/ws/apps/demo/lib/cnst.ts"],
|
|
50
|
+
["sig", "/ws/apps/demo/lib/__client/_useClient.ts"],
|
|
51
|
+
["st", "/ws/apps/demo/lib/__client/_st.ts"],
|
|
52
|
+
)} `;
|
|
53
|
+
|
|
54
|
+
describe("a client file under the per-route runtime", () => {
|
|
55
|
+
test("takes its handles from the page runtime and gains the pieces of the modules it names", () => {
|
|
56
|
+
const source = `"use client";
|
|
57
|
+
import { fetch, Memo, st } from "@apps/demo/client";
|
|
58
|
+
|
|
59
|
+
export const Card = () => {
|
|
60
|
+
void fetch.memoNote();
|
|
61
|
+
return [st.use.draft(), st.use.label(), Memo];
|
|
62
|
+
};
|
|
63
|
+
`;
|
|
64
|
+
const result = transform(source);
|
|
65
|
+
expect(result?.perModule).toBe(true);
|
|
66
|
+
expect(result?.pieces).toEqual([
|
|
67
|
+
"apps/demo/lib/__client/memo.fetch",
|
|
68
|
+
"apps/demo/lib/__client/memo.st",
|
|
69
|
+
"libs/kit/lib/__client/util.st",
|
|
70
|
+
]);
|
|
71
|
+
expect(result?.source.split("\n").slice(0, 2)).toEqual([
|
|
72
|
+
'"use client";',
|
|
73
|
+
`${bound(
|
|
74
|
+
["loaded", "@apps/demo/lib/__client/memo.fetch"],
|
|
75
|
+
["memo", "@apps/demo/lib/__client/memo.st"],
|
|
76
|
+
["util", "@libs/kit/lib/__client/util.st"],
|
|
77
|
+
)} import { fetch } from "@apps/demo/lib/usePage"; import { st } from "akanjs/store"; import { Memo } from "@apps/demo/client";`,
|
|
78
|
+
]);
|
|
79
|
+
expect(result?.source.split("\n").length).toBe(source.split("\n").length);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("keeps every line where it was when the import spans several", () => {
|
|
83
|
+
const source = `import {
|
|
84
|
+
fetch,
|
|
85
|
+
type cnst,
|
|
86
|
+
} from "@apps/demo/client";
|
|
87
|
+
export const count = (value: cnst.Memo) => [fetch.memoNote(), value];
|
|
88
|
+
`;
|
|
89
|
+
const result = transform(source);
|
|
90
|
+
expect(
|
|
91
|
+
result?.source,
|
|
92
|
+
).toBe(`${bound(["loaded", "@apps/demo/lib/__client/memo.fetch"])} import { fetch } from "@apps/demo/lib/usePage"; import type { cnst } from "@apps/demo/client";
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
export const count = (value: cnst.Memo) => [fetch.memoNote(), value];
|
|
97
|
+
`);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("loads a lib file's modules from the app's pieces, and a store the app does not extend from the lib's", () => {
|
|
101
|
+
const source =
|
|
102
|
+
'import { fetch, st } from "@libs/kit/client";\nexport const read = () => [st.use.noteCount(), st.use.tagFilter(), fetch.tagCount()];\n';
|
|
103
|
+
const result = transform(source, "libs/kit/ui/Count.tsx");
|
|
104
|
+
expect(result?.pieces).toEqual([
|
|
105
|
+
"apps/demo/lib/__client/note.fetch",
|
|
106
|
+
"apps/demo/lib/__client/tag.fetch",
|
|
107
|
+
"apps/demo/lib/__client/note.st",
|
|
108
|
+
"libs/kit/lib/__client/tag.st",
|
|
109
|
+
]);
|
|
110
|
+
expect(result?.source).toContain('import { loaded as __akanLoaded0 } from "@apps/demo/lib/__client/note.fetch";');
|
|
111
|
+
expect(result?.source).toContain('import { tag as __akanLoaded3 } from "@libs/kit/lib/__client/tag.st";');
|
|
112
|
+
expect(result?.source).toContain(
|
|
113
|
+
'import { fetch } from "@libs/kit/lib/usePage"; import { st } from "akanjs/store";',
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("points a whole-runtime file import at the page runtime and the tab's store", () => {
|
|
118
|
+
const result = transform(
|
|
119
|
+
'import { st } from "../lib/st";\nimport { fetch } from "@apps/demo/lib/useClient";\nexport const read = () => [st.use.draft(), fetch.memoNote()];\n',
|
|
120
|
+
);
|
|
121
|
+
expect(result?.source).toContain('import { st } from "akanjs/store";');
|
|
122
|
+
expect(result?.source).toContain('import { fetch } from "@apps/demo/lib/usePage";');
|
|
123
|
+
expect(result?.pieces).toEqual(["apps/demo/lib/__client/memo.fetch", "apps/demo/lib/__client/memo.st"]);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("gives a store file its own descriptors and never its own store piece", () => {
|
|
127
|
+
const source = `import { store } from "akanjs/store";
|
|
128
|
+
|
|
129
|
+
import { sig } from "../useClient";
|
|
130
|
+
|
|
131
|
+
export class MemoStore extends store(sig.memo, () => ({ draft: "" })) {}
|
|
132
|
+
`;
|
|
133
|
+
const result = transform(source, "apps/demo/lib/memo/memo.store.ts");
|
|
134
|
+
expect(result?.pieces).toEqual(["apps/demo/lib/__client/memo.fetch"]);
|
|
135
|
+
expect(result?.source).toContain('import { sig } from "@apps/demo/lib/usePage";');
|
|
136
|
+
expect(result?.source).not.toContain("memo.st");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("gives a lib store file the app extends its descriptors, and not the app's store piece that imports it", () => {
|
|
140
|
+
const source = `import { store } from "akanjs/store";
|
|
141
|
+
|
|
142
|
+
import { sig } from "../useClient";
|
|
143
|
+
|
|
144
|
+
export class NoteStore extends store(sig.note, () => ({ noteCount: 0 })) {}
|
|
145
|
+
`;
|
|
146
|
+
const result = transform(source, "libs/kit/lib/note/note.store.ts");
|
|
147
|
+
expect(result?.pieces).toEqual(["apps/demo/lib/__client/note.fetch"]);
|
|
148
|
+
expect(result?.source).not.toContain("note.st");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("loads, in each file naming a store, the store pieces that store's own code names", () => {
|
|
152
|
+
const naming = withStores({
|
|
153
|
+
"/ws/apps/demo/lib/memo/memo.store.ts": `import { store } from "akanjs/store";
|
|
154
|
+
|
|
155
|
+
import { st } from "../st";
|
|
156
|
+
import { sig } from "../useClient";
|
|
157
|
+
|
|
158
|
+
export class MemoStore extends store(sig.memo, () => ({ draft: "" })) {
|
|
159
|
+
relabel() {
|
|
160
|
+
st.do.pickLabel(st.get().tagFilter);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
`,
|
|
164
|
+
});
|
|
165
|
+
const source = 'import { st } from "@apps/demo/client";\nexport const read = () => st.use.draft();\n';
|
|
166
|
+
expect(transform(source)?.pieces).toEqual(["apps/demo/lib/__client/memo.fetch", "apps/demo/lib/__client/memo.st"]);
|
|
167
|
+
expect(transform(source, "apps/demo/ui/Card.tsx", naming)?.pieces).toEqual([
|
|
168
|
+
"apps/demo/lib/__client/memo.fetch",
|
|
169
|
+
"apps/demo/lib/__client/memo.st",
|
|
170
|
+
"libs/kit/lib/__client/tag.st",
|
|
171
|
+
"libs/kit/lib/__client/util.st",
|
|
172
|
+
]);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("gives a store file no piece of a store it names, which that store's piece would import back", () => {
|
|
176
|
+
const source = `import { store } from "akanjs/store";
|
|
177
|
+
|
|
178
|
+
import { st } from "../st";
|
|
179
|
+
import { sig } from "../useClient";
|
|
180
|
+
|
|
181
|
+
export class MemoStore extends store(sig.memo, () => ({ draft: "" })) {
|
|
182
|
+
relabel() {
|
|
183
|
+
st.do.pickLabel(st.get().tagFilter);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
`;
|
|
187
|
+
const result = transform(source, "apps/demo/lib/memo/memo.store.ts");
|
|
188
|
+
expect(result?.pieces).toEqual(["apps/demo/lib/__client/memo.fetch", "apps/demo/lib/__client/tag.fetch"]);
|
|
189
|
+
expect(result?.source).toContain('import { st } from "akanjs/store";');
|
|
190
|
+
expect(result?.source).not.toMatch(/__client\/[\w.]+\.st"/);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test("a model's reference loads that model's store, not another store with a state field of the model's name", async () => {
|
|
194
|
+
const { demo } = await runtimeFixtureTables({
|
|
195
|
+
demo: {
|
|
196
|
+
"apps/demo/lib/_auth/auth.store.ts": `import { store } from "akanjs/store";
|
|
197
|
+
|
|
198
|
+
export class AuthStore extends store("auth" as const, () => ({ memo: null as string | null, note: "" })) {}
|
|
199
|
+
`,
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
const withAuth = new RouteRuntime(root, demo, piecesOf([...appPieces, "auth.st"]));
|
|
203
|
+
const reference = (model: string) =>
|
|
204
|
+
transform(
|
|
205
|
+
`"use client";\n\nexport const reference = "${model}";\n`,
|
|
206
|
+
`apps/demo/lib/__client/${model}.ref.ts`,
|
|
207
|
+
withAuth,
|
|
208
|
+
);
|
|
209
|
+
expect(reference("memo")?.pieces).toEqual(["apps/demo/lib/__client/memo.fetch", "apps/demo/lib/__client/memo.st"]);
|
|
210
|
+
expect(reference("note")?.pieces).toEqual(["apps/demo/lib/__client/note.fetch", "apps/demo/lib/__client/note.st"]);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("loads the framework's own descriptors for a call to one of them", () => {
|
|
214
|
+
const result = transform('import { fetch } from "@apps/demo/client";\nexport const check = () => fetch.ping();\n');
|
|
215
|
+
expect(result?.pieces).toEqual(["apps/demo/lib/__client/_base.fetch"]);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("leaves a file that reaches no runtime as it is", () => {
|
|
219
|
+
const source = 'import { cn } from "akanjs/client";\nexport const box = cn("p-2");\n';
|
|
220
|
+
expect(transform(source)).toEqual({ source, perModule: true, pieces: [] });
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
const pickingStore = `import { store } from "akanjs/store";
|
|
225
|
+
|
|
226
|
+
import { st } from "../st";
|
|
227
|
+
import { fetch, sig } from "../useClient";
|
|
228
|
+
|
|
229
|
+
export class MemoStore extends store(sig.memo, () => ({ draft: "" })) {
|
|
230
|
+
run(name: string) {
|
|
231
|
+
return [fetch[name](), st.get().draft];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
`;
|
|
235
|
+
|
|
236
|
+
describe("a client file whose modules cannot be told", () => {
|
|
237
|
+
test("loads the app's whole runtime after its directive when a name is picked at run time", () => {
|
|
238
|
+
const source =
|
|
239
|
+
'"use client";\nimport { st } from "@apps/demo/client";\nexport const run = (name: string) => st.do[name]();\n';
|
|
240
|
+
const result = transform(source);
|
|
241
|
+
expect(result).toEqual({
|
|
242
|
+
source: `"use client";\n${whole}import { st } from "@apps/demo/client";\nexport const run = (name: string) => st.do[name]();\n`,
|
|
243
|
+
perModule: false,
|
|
244
|
+
pieces: [],
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("loads the whole runtime when the import also takes the barrel's default export, and leaves that import as written", () => {
|
|
249
|
+
const source = 'import Kit, { st } from "@apps/demo/client";\nexport const read = () => [st.use.draft(), Kit];\n';
|
|
250
|
+
expect(transform(source)).toEqual({ source: `${whole}${source}`, perModule: false, pieces: [] });
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test("loads the whole runtime when a piece it needs was not generated", () => {
|
|
254
|
+
const source = 'import { st } from "@apps/demo/client";\nexport const read = () => st.use.tagFilter();\n';
|
|
255
|
+
expect(transform(source)?.pieces).toEqual(["apps/demo/lib/__client/tag.fetch", "libs/kit/lib/__client/tag.st"]);
|
|
256
|
+
const result = transform(source, "apps/demo/ui/Card.tsx", withoutTagStore);
|
|
257
|
+
expect(result?.perModule).toBe(false);
|
|
258
|
+
expect(result?.source).toBe(`${whole}${source}`);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test("names the lib to sync on the routes of an entry naming a store that lib has no piece for", () => {
|
|
262
|
+
const entry = `${root}/apps/demo/ui/Card.tsx`;
|
|
263
|
+
const source = 'import { st } from "@apps/demo/client";\nexport const read = () => st.use.tagFilter();\n';
|
|
264
|
+
const unsynced = withStores(
|
|
265
|
+
{ [entry]: source },
|
|
266
|
+
kitPieces.filter((piece) => piece !== "tag.st"),
|
|
267
|
+
);
|
|
268
|
+
unsynced.plan({
|
|
269
|
+
importsByModule: new Map([[entry, []]]),
|
|
270
|
+
entries: [entry],
|
|
271
|
+
entriesByRoute: new Map([["/card", [entry]]]),
|
|
272
|
+
});
|
|
273
|
+
expect(unsynced.decided?.causes()).toEqual([
|
|
274
|
+
expect.objectContaining({
|
|
275
|
+
rule: "reader",
|
|
276
|
+
file: "apps/demo/ui/Card.tsx",
|
|
277
|
+
message: "names tag, which has no generated piece: run `akan sync kit`",
|
|
278
|
+
routes: ["/card"],
|
|
279
|
+
}),
|
|
280
|
+
]);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test("gives a store file that picks a name at run time its own descriptors and the page runtime's handles, and no store piece", () => {
|
|
284
|
+
const result = transform(pickingStore, "apps/demo/lib/memo/memo.store.ts");
|
|
285
|
+
expect(result?.perModule).toBe(true);
|
|
286
|
+
expect(result?.pieces).toEqual(["apps/demo/lib/__client/memo.fetch"]);
|
|
287
|
+
expect(result?.source).toBe(
|
|
288
|
+
`${bound(["loaded", "@apps/demo/lib/__client/memo.fetch"])} ${pickingStore
|
|
289
|
+
.replace('"../useClient"', '"@apps/demo/lib/usePage"')
|
|
290
|
+
.replace('"../st"', '"akanjs/store"')}`,
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test("leaves a store file's import of the whole store root as written where it takes more than the handle", () => {
|
|
295
|
+
const source = pickingStore.replace('import { st } from "../st";', 'import * as root from "../st";');
|
|
296
|
+
const result = transform(source, "apps/demo/lib/memo/memo.store.ts");
|
|
297
|
+
expect(result?.source).toContain('import * as root from "../st";');
|
|
298
|
+
expect(result?.source).toContain('import { fetch, sig } from "@apps/demo/lib/usePage";');
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
test("loads the whole runtime in each file naming a store whose own code picks a name at run time", () => {
|
|
302
|
+
const picking = withStores({ "/ws/apps/demo/lib/memo/memo.store.ts": pickingStore });
|
|
303
|
+
const source = 'import { st } from "@apps/demo/client";\nexport const read = () => st.use.draft();\n';
|
|
304
|
+
expect(transform(source)?.perModule).toBe(true);
|
|
305
|
+
expect(transform(source, "apps/demo/ui/Card.tsx", picking)).toEqual({
|
|
306
|
+
source: `${whole}${source}`,
|
|
307
|
+
perModule: false,
|
|
308
|
+
pieces: [],
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test("loads the whole runtime in a lib file too, as the app's", () => {
|
|
313
|
+
const source = 'import { st } from "@libs/kit/client";\nexport const run = (name: string) => st.do[name]();\n';
|
|
314
|
+
expect(transform(source, "libs/kit/ui/Run.tsx")?.source).toBe(`${whole}${source}`);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const namingRead = 'import { st } from "@apps/demo/client";\nexport const read = () => st.use.draft();\n';
|
|
319
|
+
const namingSide = 'import { st } from "@apps/demo/client";\nexport const side = () => st.use.tagFilter();\n';
|
|
320
|
+
const pickingRun = 'import { st } from "@apps/demo/client";\nexport const run = (name: string) => st.do[name]();\n';
|
|
321
|
+
const uiFile = (name: string) => `${root}/apps/demo/ui/${name}.tsx`;
|
|
322
|
+
const memoStoreFile = `${root}/apps/demo/lib/memo/memo.store.ts`;
|
|
323
|
+
const relabelFile = `${root}/apps/demo/webkit/relabel.ts`;
|
|
324
|
+
|
|
325
|
+
interface PlannedBundle {
|
|
326
|
+
files: Record<string, string>;
|
|
327
|
+
imports?: Record<string, (string | { lazy: string })[]>;
|
|
328
|
+
entries: string[];
|
|
329
|
+
routes?: Record<string, string[]>;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const plan = ({ files, imports = {}, entries, routes }: PlannedBundle) => {
|
|
333
|
+
const target = withStores(files);
|
|
334
|
+
const importsByModule = new Map(
|
|
335
|
+
Object.keys(files).map((file) => [
|
|
336
|
+
file,
|
|
337
|
+
(imports[file] ?? []).map((imported) =>
|
|
338
|
+
typeof imported === "string" ? { path: imported, lazy: false } : { path: imported.lazy, lazy: true },
|
|
339
|
+
),
|
|
340
|
+
]),
|
|
341
|
+
);
|
|
342
|
+
const kept = target.plan({
|
|
343
|
+
importsByModule,
|
|
344
|
+
entries,
|
|
345
|
+
entriesByRoute: routes ? new Map(Object.entries(routes)) : undefined,
|
|
346
|
+
});
|
|
347
|
+
const piecesOf = (file: string) => {
|
|
348
|
+
const result = target.transform(files[file] ?? "", file);
|
|
349
|
+
return result ? result.pieces : "as written";
|
|
350
|
+
};
|
|
351
|
+
return { target, kept: [...kept].sort(), piecesOf };
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
describe("a build planned over the bundle that loads the whole runtime everywhere", () => {
|
|
355
|
+
const memoPieces = ["apps/demo/lib/__client/memo.fetch", "apps/demo/lib/__client/memo.st"];
|
|
356
|
+
const tagPieces = ["apps/demo/lib/__client/tag.fetch", "libs/kit/lib/__client/tag.st"];
|
|
357
|
+
|
|
358
|
+
test("keeps the whole runtime in an entry reaching a file whose modules cannot be told, and leaves the files only it reaches as written", () => {
|
|
359
|
+
const { target, kept, piecesOf } = plan({
|
|
360
|
+
files: {
|
|
361
|
+
[uiFile("Frame")]:
|
|
362
|
+
'import { run } from "./Run";\nimport { side } from "./Side";\nexport const Frame = [run, side];\n',
|
|
363
|
+
[uiFile("Run")]: pickingRun,
|
|
364
|
+
[uiFile("Side")]: namingSide,
|
|
365
|
+
[uiFile("Card")]: `import { side } from "./Side";\n${namingRead}export const Card = side;\n`,
|
|
366
|
+
[uiFile("Lone")]: namingSide,
|
|
367
|
+
},
|
|
368
|
+
imports: {
|
|
369
|
+
[uiFile("Frame")]: [uiFile("Run"), uiFile("Side"), uiFile("Lone")],
|
|
370
|
+
[uiFile("Card")]: [uiFile("Side")],
|
|
371
|
+
},
|
|
372
|
+
entries: [uiFile("Frame"), uiFile("Card")],
|
|
373
|
+
});
|
|
374
|
+
expect(kept).toEqual([uiFile("Frame")]);
|
|
375
|
+
expect([...target.wholeReaders]).toEqual([uiFile("Run")]);
|
|
376
|
+
expect(["Frame", "Run", "Lone"].map((name) => piecesOf(uiFile(name)))).toEqual([
|
|
377
|
+
"as written",
|
|
378
|
+
"as written",
|
|
379
|
+
"as written",
|
|
380
|
+
]);
|
|
381
|
+
expect(piecesOf(uiFile("Side"))).toEqual(tagPieces);
|
|
382
|
+
expect(piecesOf(uiFile("Card"))).toEqual(memoPieces);
|
|
383
|
+
expect(target.redirectOf(`${root}/apps/demo/lib/st.ts`)).toBeNull();
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
test("keeps the whole runtime in an entry only whole-runtime routes hold, and narrows one another route holds too", () => {
|
|
387
|
+
const files = { [uiFile("Run")]: pickingRun, [uiFile("Card")]: namingRead, [uiFile("Side")]: namingSide };
|
|
388
|
+
const entries = Object.keys(files);
|
|
389
|
+
const routes = {
|
|
390
|
+
"/picked": [uiFile("Run"), uiFile("Card")],
|
|
391
|
+
"/read": [uiFile("Card")],
|
|
392
|
+
"/side": [uiFile("Run"), uiFile("Side")],
|
|
393
|
+
};
|
|
394
|
+
const byRoute = plan({ files, entries, routes });
|
|
395
|
+
expect(byRoute.kept).toEqual([uiFile("Run"), uiFile("Side")]);
|
|
396
|
+
expect(byRoute.piecesOf(uiFile("Side"))).toBe("as written");
|
|
397
|
+
expect(byRoute.piecesOf(uiFile("Card"))).toEqual(memoPieces);
|
|
398
|
+
const alone = plan({ files, entries });
|
|
399
|
+
expect(alone.kept).toEqual([uiFile("Run")]);
|
|
400
|
+
expect(alone.piecesOf(uiFile("Side"))).toEqual(tagPieces);
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
test("keeps the whole runtime on the one route rendering a client file that exports the store, and on every route once the root layout renders it", () => {
|
|
404
|
+
const exporting =
|
|
405
|
+
'"use client";\nimport { st } from "@apps/demo/client";\n\nexport const wholeRuntime = st;\n\nexport const WholeRuntime = () => null;\n';
|
|
406
|
+
const files = { [uiFile("WholeRuntime")]: exporting, [uiFile("Card")]: namingRead, [uiFile("Side")]: namingSide };
|
|
407
|
+
const entries = Object.keys(files);
|
|
408
|
+
const onOneRoute = plan({
|
|
409
|
+
files,
|
|
410
|
+
entries,
|
|
411
|
+
routes: {
|
|
412
|
+
"/kept": [uiFile("WholeRuntime"), uiFile("Card")],
|
|
413
|
+
"/read": [uiFile("Card")],
|
|
414
|
+
"/side": [uiFile("Side")],
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
expect(onOneRoute.kept).toEqual([uiFile("WholeRuntime")]);
|
|
418
|
+
expect(onOneRoute.piecesOf(uiFile("Card"))).toEqual(memoPieces);
|
|
419
|
+
expect(onOneRoute.target.decided?.causes()).toEqual([
|
|
420
|
+
expect.objectContaining({
|
|
421
|
+
rule: "reader",
|
|
422
|
+
file: "apps/demo/ui/WholeRuntime.tsx",
|
|
423
|
+
line: 4,
|
|
424
|
+
message: "`wholeRuntime = st`: other files read the runtime through this one",
|
|
425
|
+
routes: ["/kept"],
|
|
426
|
+
}),
|
|
427
|
+
]);
|
|
428
|
+
const fromTheRootLayout = plan({
|
|
429
|
+
files,
|
|
430
|
+
entries,
|
|
431
|
+
routes: { "/read": [uiFile("WholeRuntime"), uiFile("Card")], "/side": [uiFile("WholeRuntime"), uiFile("Side")] },
|
|
432
|
+
});
|
|
433
|
+
expect(fromTheRootLayout.kept).toEqual([uiFile("Card"), uiFile("Side"), uiFile("WholeRuntime")]);
|
|
434
|
+
expect(["Card", "Side"].map((name) => fromTheRootLayout.piecesOf(uiFile(name)))).toEqual([
|
|
435
|
+
"as written",
|
|
436
|
+
"as written",
|
|
437
|
+
]);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test("keeps the whole runtime in an entry naming a module that more whole-runtime routes hold than others, and narrows one naming none", () => {
|
|
441
|
+
const plain = "export const Plain = 1;\n";
|
|
442
|
+
const files = { [uiFile("Run")]: pickingRun, [uiFile("Card")]: namingRead, [uiFile("Plain")]: plain };
|
|
443
|
+
const entries = Object.keys(files);
|
|
444
|
+
const shared = [uiFile("Card"), uiFile("Plain")];
|
|
445
|
+
const mostlyWhole = plan({
|
|
446
|
+
files,
|
|
447
|
+
entries,
|
|
448
|
+
routes: { "/a": [uiFile("Run"), ...shared], "/b": [uiFile("Run"), ...shared], "/read": shared },
|
|
449
|
+
});
|
|
450
|
+
expect(mostlyWhole.kept).toEqual([uiFile("Card"), uiFile("Plain"), uiFile("Run")]);
|
|
451
|
+
expect(mostlyWhole.piecesOf(uiFile("Card"))).toBe("as written");
|
|
452
|
+
const evenly = plan({
|
|
453
|
+
files,
|
|
454
|
+
entries,
|
|
455
|
+
routes: { "/a": [uiFile("Run"), ...shared], "/read": shared, "/plain": [uiFile("Plain")] },
|
|
456
|
+
});
|
|
457
|
+
expect(evenly.kept).toEqual([uiFile("Run")]);
|
|
458
|
+
expect(evenly.piecesOf(uiFile("Card"))).toEqual(memoPieces);
|
|
459
|
+
const plainOnly = plan({
|
|
460
|
+
files,
|
|
461
|
+
entries,
|
|
462
|
+
routes: {
|
|
463
|
+
"/a": [uiFile("Run"), uiFile("Plain")],
|
|
464
|
+
"/b": [uiFile("Run"), uiFile("Plain")],
|
|
465
|
+
"/c": [uiFile("Plain"), uiFile("Card")],
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
expect(plainOnly.kept).toEqual([uiFile("Run")]);
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
test("keeps the whole runtime in an entry no route holds once a route keeps it, so the file it shares with that route loads no piece", () => {
|
|
472
|
+
const loose = 'import { side } from "./Side";\nexport const Loose = side;\n';
|
|
473
|
+
const files = {
|
|
474
|
+
[uiFile("Run")]: `import { side } from "./Side";\n${pickingRun}export const Run = side;\n`,
|
|
475
|
+
[uiFile("Card")]: namingRead,
|
|
476
|
+
[uiFile("Loose")]: loose,
|
|
477
|
+
[uiFile("Side")]: namingSide,
|
|
478
|
+
};
|
|
479
|
+
const imports = { [uiFile("Run")]: [uiFile("Side")], [uiFile("Loose")]: [uiFile("Side")] };
|
|
480
|
+
const entries = [uiFile("Run"), uiFile("Card"), uiFile("Loose")];
|
|
481
|
+
const beside = plan({ files, imports, entries, routes: { "/run": [uiFile("Run")], "/read": [uiFile("Card")] } });
|
|
482
|
+
expect(beside.kept).toEqual([uiFile("Loose"), uiFile("Run")]);
|
|
483
|
+
expect(beside.piecesOf(uiFile("Side"))).toBe("as written");
|
|
484
|
+
expect(beside.target.decided?.causes().map(({ rule, entries: held }) => [rule, held])).toEqual([
|
|
485
|
+
["reader", ["apps/demo/ui/Run.tsx"]],
|
|
486
|
+
["unheld", ["apps/demo/ui/Loose.tsx"]],
|
|
487
|
+
]);
|
|
488
|
+
const alone = plan({
|
|
489
|
+
files,
|
|
490
|
+
imports,
|
|
491
|
+
entries: [uiFile("Card"), uiFile("Loose")],
|
|
492
|
+
routes: { "/read": [uiFile("Card")] },
|
|
493
|
+
});
|
|
494
|
+
expect(alone.kept).toEqual([]);
|
|
495
|
+
expect(alone.piecesOf(uiFile("Side"))).toEqual(tagPieces);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
test("an entry kept after its page was measured takes with it the entries only whole pages hold, never one a page loading per module holds", () => {
|
|
499
|
+
const files = {
|
|
500
|
+
[uiFile("Card")]: namingRead,
|
|
501
|
+
[uiFile("Side")]: namingSide,
|
|
502
|
+
[uiFile("Plain")]: "export const Plain = 1;\n",
|
|
503
|
+
};
|
|
504
|
+
const routes = { "/read": [uiFile("Card"), uiFile("Plain")], "/side": [uiFile("Side"), uiFile("Plain")] };
|
|
505
|
+
const { target, kept, piecesOf } = plan({ files, entries: Object.keys(files), routes });
|
|
506
|
+
expect(kept).toEqual([]);
|
|
507
|
+
const measured = { rule: "not-smaller", route: "/read", whole: 900, perModule: 950 } as const;
|
|
508
|
+
expect([...target.keep([uiFile("Card")], measured)]).toEqual([uiFile("Card")]);
|
|
509
|
+
expect(piecesOf(uiFile("Card"))).toBe("as written");
|
|
510
|
+
expect(piecesOf(uiFile("Side"))).toEqual(tagPieces);
|
|
511
|
+
expect(target.decided?.causes()[0]).toMatchObject({
|
|
512
|
+
rule: "not-smaller",
|
|
513
|
+
message: "/read is 950 B loading per module and 900 B with the whole runtime",
|
|
514
|
+
routes: ["/read"],
|
|
515
|
+
});
|
|
516
|
+
expect([...target.keep([uiFile("Side")], { ...measured, route: "/side" })].sort()).toEqual(
|
|
517
|
+
Object.keys(files).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)),
|
|
518
|
+
);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
test("a scope's whole runtime file takes from their pieces the descriptors a page loading per module reaches, and keeps its own where every page is whole", () => {
|
|
522
|
+
const files = { [uiFile("Run")]: pickingRun, [uiFile("Card")]: namingRead };
|
|
523
|
+
const entries = Object.keys(files);
|
|
524
|
+
const whole = `${root}/apps/demo/lib/useClient.ts`;
|
|
525
|
+
const mixed = plan({
|
|
526
|
+
files,
|
|
527
|
+
entries,
|
|
528
|
+
routes: { "/run": [uiFile("Run"), uiFile("Card")], "/read": [uiFile("Card")] },
|
|
529
|
+
});
|
|
530
|
+
expect(mixed.kept).toEqual([uiFile("Run")]);
|
|
531
|
+
expect(mixed.target.takenFromPieces(whole)).toEqual([
|
|
532
|
+
`${root}/apps/demo/lib/__client/_base.fetch.ts`,
|
|
533
|
+
`${root}/apps/demo/lib/__client/memo.fetch.ts`,
|
|
534
|
+
]);
|
|
535
|
+
expect(mixed.target.takenFromPieces(`${root}/apps/demo/lib/st.ts`)).toBeNull();
|
|
536
|
+
const everyWhole = plan({ files, entries, routes: { "/run": [uiFile("Run"), uiFile("Card")] } });
|
|
537
|
+
expect(everyWhole.kept).toEqual(entries.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
538
|
+
expect(everyWhole.target.takenFromPieces(whole)).toBeNull();
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
test("keeps the whole runtime in an entry asking with `import()` for a file that needs every module, and in a file only such entries ask for", () => {
|
|
542
|
+
const files = {
|
|
543
|
+
[uiFile("Card")]: namingRead,
|
|
544
|
+
[uiFile("Run")]: pickingRun,
|
|
545
|
+
[uiFile("Side")]: namingSide,
|
|
546
|
+
[uiFile("Other")]: namingRead,
|
|
547
|
+
};
|
|
548
|
+
const asking = { [uiFile("Card")]: [{ lazy: uiFile("Run") }, { lazy: uiFile("Side") }] };
|
|
549
|
+
const entries = [uiFile("Card"), uiFile("Other")];
|
|
550
|
+
const lazy = plan({ files, imports: asking, entries });
|
|
551
|
+
expect(lazy.kept).toEqual([uiFile("Card"), uiFile("Run"), uiFile("Side")]);
|
|
552
|
+
expect(lazy.piecesOf(uiFile("Other"))).toEqual(memoPieces);
|
|
553
|
+
const shared = plan({ files, imports: { ...asking, [uiFile("Other")]: [{ lazy: uiFile("Side") }] }, entries });
|
|
554
|
+
expect(shared.kept).toEqual([uiFile("Card"), uiFile("Run")]);
|
|
555
|
+
expect(shared.piecesOf(uiFile("Side"))).toEqual(tagPieces);
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
test("gives a file a store file imports no store piece, and loads the stores its code names in each file outside importing it or naming that store", () => {
|
|
559
|
+
const files = {
|
|
560
|
+
[memoStoreFile]: `import { store } from "akanjs/store";
|
|
561
|
+
|
|
562
|
+
import { relabel } from "../../webkit/relabel";
|
|
563
|
+
import { sig } from "../useClient";
|
|
564
|
+
|
|
565
|
+
export class MemoStore extends store(sig.memo, () => ({ draft: "" })) {
|
|
566
|
+
relabel() {
|
|
567
|
+
relabel();
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
`,
|
|
571
|
+
[relabelFile]:
|
|
572
|
+
'import { st } from "@apps/demo/client";\nexport const relabel = () => st.do.pickLabel(st.get().tagFilter);\n',
|
|
573
|
+
[uiFile("Card")]: namingRead,
|
|
574
|
+
[uiFile("Other")]: 'import { relabel } from "../webkit/relabel";\nexport const Other = () => relabel();\n',
|
|
575
|
+
};
|
|
576
|
+
const imports = { [memoStoreFile]: [relabelFile], [uiFile("Other")]: [relabelFile] };
|
|
577
|
+
const { target, kept, piecesOf } = plan({ files, imports, entries: [uiFile("Card"), uiFile("Other")] });
|
|
578
|
+
const named = ["libs/kit/lib/__client/tag.st", "libs/kit/lib/__client/util.st"];
|
|
579
|
+
expect(kept).toEqual([]);
|
|
580
|
+
expect(piecesOf(relabelFile)).toEqual(["apps/demo/lib/__client/tag.fetch"]);
|
|
581
|
+
expect(target.transform(files[relabelFile] ?? "", relabelFile)?.source).toContain(
|
|
582
|
+
'import { st } from "akanjs/store";',
|
|
583
|
+
);
|
|
584
|
+
expect(piecesOf(memoStoreFile)).toEqual(["apps/demo/lib/__client/memo.fetch"]);
|
|
585
|
+
expect(piecesOf(uiFile("Card"))).toEqual([...memoPieces, ...named]);
|
|
586
|
+
expect(piecesOf(uiFile("Other"))).toEqual(named);
|
|
587
|
+
expect(plan({ files, imports, entries: [relabelFile] }).kept).toEqual([relabelFile]);
|
|
588
|
+
});
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
const memoConstant = `import { enumOf, via } from "akanjs/constant";
|
|
592
|
+
|
|
593
|
+
export const MemoStatus = enumOf("memoStatus", ["draft", "done"] as const);
|
|
594
|
+
export class MemoInput extends via((field) => ({ title: field(String), status: field(MemoStatus) })) {}
|
|
595
|
+
export class MemoObject extends via(MemoInput, (field) => ({})) {}
|
|
596
|
+
export class LightMemo extends via(MemoObject, ["title"] as const, (resolve) => ({})) {}
|
|
597
|
+
export class Memo extends via(MemoObject, LightMemo, (resolve) => ({})) {}
|
|
598
|
+
`;
|
|
599
|
+
const boardConstant = `import { via } from "akanjs/constant";
|
|
600
|
+
import { cnst } from "@libs/kit";
|
|
601
|
+
|
|
602
|
+
export class BoardInput extends via((field) => ({ note: field(cnst.Note) })) {}
|
|
603
|
+
export class BoardObject extends via(BoardInput, (field) => ({})) {}
|
|
604
|
+
export class LightBoard extends via(BoardObject, [] as const, (resolve) => ({})) {}
|
|
605
|
+
export class Board extends via(BoardObject, LightBoard, (resolve) => ({})) {}
|
|
606
|
+
`;
|
|
607
|
+
|
|
608
|
+
describe("the constants a file reads under the per-route runtime", () => {
|
|
609
|
+
let constants: RouteRuntime;
|
|
610
|
+
let constantsOf: (pieces: Set<string>) => RouteRuntime;
|
|
611
|
+
beforeAll(async () => {
|
|
612
|
+
const files = {
|
|
613
|
+
"apps/demo/lib/memo/memo.constant.ts": memoConstant,
|
|
614
|
+
"apps/demo/lib/board/board.constant.ts": boardConstant,
|
|
615
|
+
};
|
|
616
|
+
const { demo } = await runtimeFixtureTables({ demo: files });
|
|
617
|
+
constantsOf = (pieces) =>
|
|
618
|
+
new RouteRuntime(
|
|
619
|
+
root,
|
|
620
|
+
demo,
|
|
621
|
+
pieces,
|
|
622
|
+
(absPath) => files[absPath.slice(`${root}/`.length) as keyof typeof files] ?? null,
|
|
623
|
+
);
|
|
624
|
+
constants = constantsOf(
|
|
625
|
+
piecesOf([...appPieces, "memo.cnst", "board.cnst"], [...kitPieces, "note.cnst", "tag.cnst"]),
|
|
626
|
+
);
|
|
627
|
+
});
|
|
628
|
+
const read = (source: string, file = "apps/demo/ui/Card.tsx") => constants.transform(source, `${root}/${file}`);
|
|
629
|
+
const cnstImports = (...lines: [name: string, specifier: string][]) =>
|
|
630
|
+
lines.map(([name, specifier], index) => `import { ${name} as __akanCnst${index} } from "${specifier}";`).join(" ");
|
|
631
|
+
|
|
632
|
+
test("takes each constant from the file declaring it, and a model from its registration piece, which loads first", () => {
|
|
633
|
+
const source = `import { cnst, fetch } from "@apps/demo/client";
|
|
634
|
+
export const read = () => [cnst.MemoStatus, cnst.memo, cnst.kit.Note, fetch.memoNote()];
|
|
635
|
+
`;
|
|
636
|
+
const result = read(source);
|
|
637
|
+
expect(result?.pieces).toEqual([
|
|
638
|
+
"apps/demo/lib/__client/memo.cnst",
|
|
639
|
+
"libs/kit/lib/__client/note.cnst",
|
|
640
|
+
"apps/demo/lib/__client/memo.fetch",
|
|
641
|
+
]);
|
|
642
|
+
expect(result?.source).toBe(`${bound(
|
|
643
|
+
["memo", "@apps/demo/lib/__client/memo.cnst"],
|
|
644
|
+
["note", "@libs/kit/lib/__client/note.cnst"],
|
|
645
|
+
["loaded", "@apps/demo/lib/__client/memo.fetch"],
|
|
646
|
+
)} ${cnstImports(
|
|
647
|
+
["MemoStatus", "../lib/memo/memo.constant"],
|
|
648
|
+
["memo", "@apps/demo/lib/__client/memo.cnst"],
|
|
649
|
+
["Note", "../../../libs/kit/lib/note/note.constant"],
|
|
650
|
+
)} import { fetch } from "@apps/demo/lib/usePage"; import type { cnst } from "@apps/demo/client";
|
|
651
|
+
export const read = () => [__akanCnst0, __akanCnst1, __akanCnst2, fetch.memoNote()];
|
|
652
|
+
`);
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
test("takes the names a destructuring of the constants holds, and the whole-runtime file's constants likewise", () => {
|
|
656
|
+
const destructured = read(
|
|
657
|
+
'import { cnst } from "@apps/demo/client";\nconst { MemoStatus, memo } = cnst;\nexport const pick = (value: cnst.Memo) => [MemoStatus, memo, value];\n',
|
|
658
|
+
);
|
|
659
|
+
expect(destructured?.pieces).toEqual(["apps/demo/lib/__client/memo.cnst"]);
|
|
660
|
+
expect(destructured?.source.split("\n").slice(0, 2)).toEqual([
|
|
661
|
+
`${bound(["memo", "@apps/demo/lib/__client/memo.cnst"])} ${cnstImports(
|
|
662
|
+
["MemoStatus", "../lib/memo/memo.constant"],
|
|
663
|
+
["memo", "@apps/demo/lib/__client/memo.cnst"],
|
|
664
|
+
)} import type { cnst } from "@apps/demo/client";`,
|
|
665
|
+
'const { MemoStatus, memo } = { "MemoStatus": __akanCnst0, "memo": __akanCnst1 };',
|
|
666
|
+
]);
|
|
667
|
+
const namespace = read('import * as cnst from "../lib/cnst";\nexport const model = () => cnst.memo;\n');
|
|
668
|
+
expect(namespace?.source).toContain('import type * as cnst from "../lib/cnst";');
|
|
669
|
+
expect(namespace?.source).toContain("export const model = () => __akanCnst0;");
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
test("keeps a lib file's constants from the lib, and leaves a constant used only as a type to the type checker", () => {
|
|
673
|
+
expect(
|
|
674
|
+
read('import { cnst } from "@libs/kit/client";\nexport const note = () => cnst.Note;\n', "libs/kit/ui/Note.tsx")
|
|
675
|
+
?.pieces,
|
|
676
|
+
).toEqual(["libs/kit/lib/__client/note.cnst"]);
|
|
677
|
+
const typed = 'import { cnst } from "@apps/demo/client";\nexport const same = (value: cnst.Memo) => value;\n';
|
|
678
|
+
expect(read(typed)).toEqual({
|
|
679
|
+
source: typed.replace("import { cnst }", "import type { cnst }"),
|
|
680
|
+
perModule: true,
|
|
681
|
+
pieces: [],
|
|
682
|
+
});
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
test.each<[string, string, RuntimeUseReason]>([
|
|
686
|
+
["a computed member", "export const pick = (name: string) => cnst[name];", "computed-access"],
|
|
687
|
+
["the constants handed on", "export const names = () => Object.keys(cnst);", "passed-on"],
|
|
688
|
+
["a spread", "export const all = { ...cnst };", "passed-on"],
|
|
689
|
+
["a name the scope does not hand out", "export const none = () => cnst.Nope;", "unknown-name"],
|
|
690
|
+
[
|
|
691
|
+
"a rest in a destructuring",
|
|
692
|
+
"const { memo, ...rest } = cnst;\nexport const both = [memo, rest];",
|
|
693
|
+
"hidden-by-destructuring",
|
|
694
|
+
],
|
|
695
|
+
])("keeps every constant for %s, and says why", (_, body, reason) => {
|
|
696
|
+
const source = `import { cnst } from "@apps/demo/client";\n${body}\n`;
|
|
697
|
+
expect(read(source)).toEqual({ source, perModule: true, pieces: [], wholeConstants: true });
|
|
698
|
+
expect(constants.wholeConstantReaders).toContain(`${root}/apps/demo/ui/Card.tsx`);
|
|
699
|
+
const { constants: use } = RuntimeUse.analyze({ fileName: "apps/demo/ui/Card.tsx", text: source }, constants.table);
|
|
700
|
+
expect(use.problems.map((problem) => problem.reason)).toEqual([reason]);
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
test("takes a lib model a constant file reads from that lib's registration piece, never the barrel's whole constants", () => {
|
|
704
|
+
const result = read(boardConstant, "apps/demo/lib/board/board.constant.ts");
|
|
705
|
+
expect(result?.pieces).toEqual(["libs/kit/lib/__client/note.cnst"]);
|
|
706
|
+
expect(result?.source.split("\n").slice(0, 2)).toEqual([
|
|
707
|
+
`${bound(["note", "@libs/kit/lib/__client/note.cnst"])} ${cnstImports([
|
|
708
|
+
"Note",
|
|
709
|
+
"../../../../libs/kit/lib/note/note.constant",
|
|
710
|
+
])} import { via } from "akanjs/constant";`,
|
|
711
|
+
'import type { cnst } from "@libs/kit";',
|
|
712
|
+
]);
|
|
713
|
+
expect(result?.source).toContain("field(__akanCnst0)");
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
const registered = (model: string, kind = "Model") =>
|
|
717
|
+
`export const ${model} = ConstantRegistry.build${kind}("${model}" as const, ${model}Cnst);`;
|
|
718
|
+
const fromPiece = (model: string) => `export { ${model} } from "./__client/${model}.cnst";`;
|
|
719
|
+
|
|
720
|
+
test("registers a model per page only where a page loading no whole runtime reaches it, and takes it from the constants of every model elsewhere", async () => {
|
|
721
|
+
const files: Record<string, string> = {
|
|
722
|
+
"apps/demo/lib/memo/memo.constant.ts": memoConstant,
|
|
723
|
+
"apps/demo/lib/board/board.constant.ts": boardConstant,
|
|
724
|
+
"apps/demo/lib/__client/memo.cnst.ts":
|
|
725
|
+
'import * as cnst from "../memo/memo.constant";\nexport const memo = cnst;\n',
|
|
726
|
+
"apps/demo/lib/__client/board.cnst.ts":
|
|
727
|
+
'import * as cnst from "../board/board.constant";\nexport const board = cnst;\n',
|
|
728
|
+
"libs/kit/lib/__client/note.cnst.ts":
|
|
729
|
+
'import * as cnst from "../note/note.constant";\nexport const note = cnst;\n',
|
|
730
|
+
"apps/demo/ui/Card.tsx": 'import { cnst } from "@apps/demo/client";\nexport const card = () => cnst.memo;\n',
|
|
731
|
+
"apps/demo/ui/Lone.tsx": 'import { cnst } from "@apps/demo/client";\nexport const lone = () => cnst.board;\n',
|
|
732
|
+
"apps/demo/lib/cnst.ts": `${registered("board")}\n${registered("memo")}\n`,
|
|
733
|
+
"libs/kit/lib/cnst.ts": `${registered("note")}\n${registered("tag", "Scalar")}\n`,
|
|
734
|
+
};
|
|
735
|
+
const { demo } = await runtimeFixtureTables({ demo: files });
|
|
736
|
+
const pieces = piecesOf([...appPieces, "memo.cnst", "board.cnst"], [...kitPieces, "note.cnst", "tag.cnst"]);
|
|
737
|
+
const planned = (routes: Record<string, string[]>) => {
|
|
738
|
+
const target = new RouteRuntime(root, demo, pieces, (absPath) => files[absPath.slice(`${root}/`.length)] ?? null);
|
|
739
|
+
const entries = [uiFile("Card"), uiFile("Lone")];
|
|
740
|
+
target.plan({
|
|
741
|
+
importsByModule: new Map(entries.map((entry) => [entry, []])),
|
|
742
|
+
entries,
|
|
743
|
+
entriesByRoute: new Map(Object.entries(routes)),
|
|
744
|
+
});
|
|
745
|
+
return (file: string) => target.transform(files[file] ?? "", `${root}/${file}`);
|
|
746
|
+
};
|
|
747
|
+
const lone = planned({ "/card": [uiFile("Card")] });
|
|
748
|
+
expect(lone("apps/demo/ui/Lone.tsx")?.pieces).toEqual([
|
|
749
|
+
"apps/demo/lib/__client/board.cnst",
|
|
750
|
+
"libs/kit/lib/__client/note.cnst",
|
|
751
|
+
]);
|
|
752
|
+
expect(lone("apps/demo/lib/__client/memo.cnst.ts")).toBeNull();
|
|
753
|
+
expect(lone("apps/demo/lib/__client/board.cnst.ts")).toEqual({
|
|
754
|
+
source: 'export { board } from "../cnst";\nexport * as loaded from "../cnst";\n',
|
|
755
|
+
perModule: true,
|
|
756
|
+
pieces: [],
|
|
757
|
+
wholeConstants: true,
|
|
758
|
+
});
|
|
759
|
+
expect(lone("libs/kit/lib/__client/note.cnst.ts")?.source).toBe(
|
|
760
|
+
`export { note } from "../cnst";\nexport * as loaded from "${root}/apps/demo/lib/cnst.ts";\n`,
|
|
761
|
+
);
|
|
762
|
+
expect(lone("apps/demo/lib/board/board.constant.ts")).toBeNull();
|
|
763
|
+
expect(lone("apps/demo/lib/cnst.ts")?.source).toBe(
|
|
764
|
+
`${registered("board")}\n${fromPiece("memo")}\n\nimport "${root}/apps/demo/lib/__client/board.cnst.ts";\nimport "${root}/libs/kit/lib/__client/note.cnst.ts";\nimport "${root}/libs/kit/lib/__client/tag.cnst.ts";\n`,
|
|
765
|
+
);
|
|
766
|
+
expect(lone("libs/kit/lib/cnst.ts")).toBeNull();
|
|
767
|
+
const both = planned({ "/card": [uiFile("Card")], "/lone": [uiFile("Lone")] });
|
|
768
|
+
expect(both("apps/demo/lib/__client/board.cnst.ts")).toBeNull();
|
|
769
|
+
expect(both("apps/demo/lib/board/board.constant.ts")?.pieces).toEqual(["libs/kit/lib/__client/note.cnst"]);
|
|
770
|
+
expect(both("libs/kit/lib/__client/note.cnst.ts")).toBeNull();
|
|
771
|
+
expect(both("apps/demo/lib/cnst.ts")?.source).toBe(
|
|
772
|
+
`${fromPiece("board")}\n${fromPiece("memo")}\n\nimport "${root}/libs/kit/lib/__client/tag.cnst.ts";\n`,
|
|
773
|
+
);
|
|
774
|
+
expect(both("libs/kit/lib/cnst.ts")?.source).toBe(`${fromPiece("note")}\n${registered("tag", "Scalar")}\n\n\n`);
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
test("keeps every constant where a piece it would load was not generated", () => {
|
|
778
|
+
const source = 'import { cnst } from "@apps/demo/client";\nexport const model = () => cnst.memo;\n';
|
|
779
|
+
const withoutMemo = constantsOf(piecesOf([...appPieces, "board.cnst"], [...kitPieces, "note.cnst", "tag.cnst"]));
|
|
780
|
+
expect(withoutMemo.transform(source, `${root}/apps/demo/ui/Card.tsx`)).toEqual({
|
|
781
|
+
source,
|
|
782
|
+
perModule: true,
|
|
783
|
+
pieces: [],
|
|
784
|
+
wholeConstants: true,
|
|
785
|
+
});
|
|
786
|
+
});
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
describe("a file the per-route runtime does not touch", () => {
|
|
790
|
+
const source = 'import { st } from "@apps/demo/client";\nexport const read = () => st.use.draft();\n';
|
|
791
|
+
|
|
792
|
+
test.each([
|
|
793
|
+
["a file outside every app and lib", "pkgs/akanjs/ui/Card.tsx"],
|
|
794
|
+
["a generated file", "apps/demo/lib/st.ts"],
|
|
795
|
+
["a generated entry", "apps/demo/.akan/generated/client-entry-bootstrap-route/Card.tsx"],
|
|
796
|
+
["a hand-kept piece", "apps/demo/lib/__client/memo.st.ts"],
|
|
797
|
+
["a server-only file", "apps/demo/srvkit/guards.ts"],
|
|
798
|
+
["a module's constant", "apps/demo/lib/memo/memo.constant.ts"],
|
|
799
|
+
["a test", "apps/demo/ui/Card.test.tsx"],
|
|
800
|
+
])("%s", (_, file) => {
|
|
801
|
+
expect(transform(source, file)).toBeNull();
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
test("a macro host", () => {
|
|
805
|
+
expect(transform(`import { read } from "./read" with { type: "macro" };\n${source}`)).toBeNull();
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
test("a file that does not parse", () => {
|
|
809
|
+
expect(transform(`${source}export const = ;\n`)).toBeNull();
|
|
810
|
+
});
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
describe("a scope's whole runtime file", () => {
|
|
814
|
+
test("is answered from the scope's assembled pieces", () => {
|
|
815
|
+
expect(runtime.redirectOf("/ws/apps/demo/lib/useClient.ts")).toBe('export * from "./__client/_useClient";\n');
|
|
816
|
+
expect(runtime.redirectOf("/ws/apps/demo/lib/st.ts")).toBe('export * from "./__client/_st";\n');
|
|
817
|
+
expect(runtime.redirectOf("/ws/libs/kit/lib/useClient.ts")).toBe('export * from "./__client/_useClient";\n');
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
test("is followed by the app's store root when it is a lib's, so an app store keeps its actions over the lib's", () => {
|
|
821
|
+
expect(runtime.redirectOf("/ws/libs/kit/lib/st.ts")).toBe(
|
|
822
|
+
'export * from "./__client/_st";\nimport "/ws/apps/demo/lib/__client/_st.ts";\n',
|
|
823
|
+
);
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
test("stays as written where the scope has no assembled piece, and for every other file", () => {
|
|
827
|
+
expect(runtime.redirectOf("/ws/libs/other/lib/st.ts")).toBeNull();
|
|
828
|
+
expect(runtime.redirectOf("/ws/apps/demo/lib/usePage.ts")).toBeNull();
|
|
829
|
+
expect(runtime.redirectOf("/ws/apps/demo/lib/memo/memo.store.ts")).toBeNull();
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
test("is imported by absolute path, each piece by a name the importer uses", () => {
|
|
833
|
+
expect(runtime.wholeSource).toBe(`${whole.trim().split("; ").join(";\n")}\n`);
|
|
834
|
+
});
|
|
835
|
+
});
|