@akanjs/devkit 3.3.0-rc.9 → 4.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEV_RUNTIME_KNOBS.md +1 -1
- package/README.ko.md +7 -1
- package/README.md +7 -1
- package/akanApp/akanApp.host.test.ts +3 -1
- 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 +269 -18
- package/akanConfig/akanConfig.ts +104 -210
- 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 +212 -0
- package/akanConfig/index.ts +3 -0
- package/akanConfig/nativeFileSettings.ts +33 -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 +358 -5
- package/app/applicationBuildRunner.ts +221 -31
- 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 +2 -2
- 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 +684 -6
- package/frontendBuild/clientBuildTypes.ts +26 -0
- package/frontendBuild/clientEntriesBundler.ts +49 -1
- package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
- package/frontendBuild/clientEntryDiscovery.ts +134 -12
- 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 +124 -0
- package/frontendBuild/devBarrelImports.ts +81 -21
- 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 +27 -1
- package/incrementalBuilder/buildBatchProtocol.ts +1 -0
- package/incrementalBuilder/builderWatch.ts +11 -1
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +159 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +31 -3
- package/incrementalBuilder/pendingMetadata.test.ts +27 -0
- package/incrementalBuilder/pendingMetadata.ts +19 -0
- package/integration/devStability.integration.test.ts +46 -21
- 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 +17 -1
- package/mobile/nativeConfig.ts +11 -6
- package/mobile/nativePublicEnv.ts +1 -1
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +11 -12
- package/packageExports.test.ts +3 -2
- 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 +24 -2
- 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 +177 -0
- package/transforms/tsconfigPackageResolver.test.ts +1 -0
- package/tunnel/createTunnel.ts +5 -1
- 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/jsonFormatter.test.ts +13 -9
- 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/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 -2904
- 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 -626
- package/codeAgent/agent/CodeAgentAllowed.ts +0 -35
- package/codeAgent/agent/CodeAgentAsks.ts +0 -66
- package/codeAgent/agent/CodeAgentCommandLine.ts +0 -372
- package/codeAgent/agent/CodeAgentEventMapper.ts +0 -225
- package/codeAgent/agent/CodeAgentGate.ts +0 -258
- 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 -337
- package/codeAgent/agent/codeAgentCommandLine.test.ts +0 -212
- package/codeAgent/agent/codeAgentContract.test.ts +0 -755
- 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
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
1
|
+
import { describe, expect, spyOn, test } from "bun:test";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { StoreBootstrap } from "../artifact/storeBootstrap";
|
|
3
4
|
import { tempDirs, writeText as write } from "../test/testHelpers";
|
|
5
|
+
import { ModelReference } from "../transforms/modelReference";
|
|
6
|
+
import { RouteRuntime } from "../transforms/routeRuntime";
|
|
4
7
|
import { SsrDevBundler } from "./ssrDevBundler";
|
|
5
8
|
|
|
6
9
|
const makeTempRoot = tempDirs("akan-ssr-dev-bundler-");
|
|
@@ -24,3 +27,149 @@ describe("SsrDevBundler bootstrap", () => {
|
|
|
24
27
|
expect(await bootstrapOf(await makeTempRoot())).toBe("export {};\n");
|
|
25
28
|
});
|
|
26
29
|
});
|
|
30
|
+
|
|
31
|
+
describe("SsrDevBundler loading per module", () => {
|
|
32
|
+
const appOf = (root: string, warnings: string[] = []) =>
|
|
33
|
+
({
|
|
34
|
+
name: "demo",
|
|
35
|
+
cwdPath: path.join(root, "apps/demo"),
|
|
36
|
+
workspace: { workspaceRoot: root },
|
|
37
|
+
basePaths: new Set<string>(),
|
|
38
|
+
getConfig: async () => ({ optimizeImports: [], barrelImports: [], basePaths: new Set<string>() }),
|
|
39
|
+
getPublicEnv: () => ({}),
|
|
40
|
+
logger: { warn: (message: string) => warnings.push(message) },
|
|
41
|
+
}) as never;
|
|
42
|
+
const writeLib = async (root: string, files: string[]) => {
|
|
43
|
+
for (const file of files) await write(path.join(root, "apps/demo/lib", file), "export {};\n");
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const pageFiles = [
|
|
47
|
+
"st.ts",
|
|
48
|
+
"useClient.ts",
|
|
49
|
+
`${StoreBootstrap.pageRuntime}.ts`,
|
|
50
|
+
`${StoreBootstrap.baseDescriptors}.ts`,
|
|
51
|
+
...StoreBootstrap.assembled.map((file) => `${file}.ts`),
|
|
52
|
+
`${ModelReference.registry}.ts`,
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
const writeFrameworkBase = async (root: string) => {
|
|
56
|
+
const akanjsRoot = path.dirname(Bun.resolveSync("akanjs/package.json", import.meta.dir));
|
|
57
|
+
for (const file of ["package.json", "store/baseSt.ts", "signal/base.signal.ts", "signal/agent.signal.ts"])
|
|
58
|
+
await write(path.join(root, "node_modules/akanjs", file), await Bun.file(path.join(akanjsRoot, file)).text());
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
test("boots the page runtime with the framework's own descriptors and answers the model runtime marker with the app's assembled pieces", async () => {
|
|
62
|
+
const root = await makeTempRoot();
|
|
63
|
+
await writeLib(root, pageFiles);
|
|
64
|
+
await writeFrameworkBase(root);
|
|
65
|
+
const warnings: string[] = [];
|
|
66
|
+
const bundler = new SsrDevBundler(appOf(root, warnings));
|
|
67
|
+
const context = await bundler.context();
|
|
68
|
+
const { files } = await bundler.writeEntries(context);
|
|
69
|
+
|
|
70
|
+
expect(warnings).toEqual([]);
|
|
71
|
+
|
|
72
|
+
const bootstrap = await Bun.file(files[SsrDevBundler.bootstrapKey] ?? "").text();
|
|
73
|
+
expect(bootstrap).toStartWith(
|
|
74
|
+
`import "@apps/demo/lib/${StoreBootstrap.pageRuntime}";\nimport "@apps/demo/lib/${StoreBootstrap.baseDescriptors}";\n`,
|
|
75
|
+
);
|
|
76
|
+
expect(bootstrap).toEndWith('import "./storeOwners";\n');
|
|
77
|
+
const owners = path.join(path.dirname(files[SsrDevBundler.bootstrapKey] ?? ""), "storeOwners.ts");
|
|
78
|
+
expect(await Bun.file(owners).text()).toContain('[Symbol.for("akanjs.store.owners")] = {"use":');
|
|
79
|
+
expect(context.routeRuntime).toBeDefined();
|
|
80
|
+
const [useClient, st] = StoreBootstrap.assembled.map((piece) =>
|
|
81
|
+
JSON.stringify(path.join(root, "apps/demo/lib", `${piece}.ts`).split(path.sep).join("/")),
|
|
82
|
+
);
|
|
83
|
+
const constants = JSON.stringify(path.join(root, "apps/demo/lib/cnst.ts").split(path.sep).join("/"));
|
|
84
|
+
expect(context.modelRuntime).toBe(
|
|
85
|
+
[
|
|
86
|
+
'import { loadedAfter as __akanLoadedAfter } from "akanjs/base";',
|
|
87
|
+
`import * as __akanLoaded0 from ${constants};`,
|
|
88
|
+
`import { sig as __akanLoaded1 } from ${useClient};`,
|
|
89
|
+
`import { st as __akanLoaded2 } from ${st};`,
|
|
90
|
+
"__akanLoadedAfter(__akanLoaded0, __akanLoaded1, __akanLoaded2);",
|
|
91
|
+
"",
|
|
92
|
+
].join("\n"),
|
|
93
|
+
);
|
|
94
|
+
await Bun.file(path.join(root, "apps/demo/lib", pageFiles.at(-1) ?? "")).delete();
|
|
95
|
+
const whole = await new SsrDevBundler(appOf(root)).context();
|
|
96
|
+
expect(context.configKey).not.toBe(whole.configKey);
|
|
97
|
+
expect(whole.routeRuntime).toBeUndefined();
|
|
98
|
+
expect(whole.modelRuntime).toBeUndefined();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
for (const missing of pageFiles.slice(2))
|
|
102
|
+
test(`keeps the whole runtime when the app was not synced to lib/${missing} yet`, async () => {
|
|
103
|
+
const root = await makeTempRoot();
|
|
104
|
+
await writeLib(
|
|
105
|
+
root,
|
|
106
|
+
pageFiles.filter((file) => file !== missing),
|
|
107
|
+
);
|
|
108
|
+
const bundler = new SsrDevBundler(appOf(root));
|
|
109
|
+
const context = await bundler.context();
|
|
110
|
+
const { files } = await bundler.writeEntries(context);
|
|
111
|
+
|
|
112
|
+
expect(context.modelRuntime).toBeUndefined();
|
|
113
|
+
expect(await Bun.file(files[SsrDevBundler.bootstrapKey] ?? "").text()).toBe(
|
|
114
|
+
'import "@apps/demo/lib/useClient";\nimport "@apps/demo/lib/st";\n',
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("says once, not on every save, that an app missing its runtime files loads the whole runtime", async () => {
|
|
119
|
+
const root = await makeTempRoot();
|
|
120
|
+
await writeLib(root, pageFiles.slice(0, -1));
|
|
121
|
+
await writeFrameworkBase(root);
|
|
122
|
+
const warnings: string[] = [];
|
|
123
|
+
const bundler = new SsrDevBundler(appOf(root, warnings));
|
|
124
|
+
|
|
125
|
+
await bundler.context();
|
|
126
|
+
await bundler.context();
|
|
127
|
+
expect(warnings).toHaveLength(1);
|
|
128
|
+
expect(warnings[0]).toBe(
|
|
129
|
+
"[client-runtime] the per-module runtime files of demo or a lib it mounts are missing, so every page of the development server loads the whole client runtime, not only what it uses. Run `akan sync demo`.",
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
await writeLib(root, pageFiles.slice(-1));
|
|
133
|
+
expect((await bundler.context()).routeRuntime).toBeDefined();
|
|
134
|
+
await Bun.file(path.join(root, "apps/demo/lib", pageFiles.at(-1) ?? "")).delete();
|
|
135
|
+
await bundler.context();
|
|
136
|
+
expect(warnings).toHaveLength(2);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("loads per module again once a lib the app mounts is synced, with no change to the app's own files", async () => {
|
|
140
|
+
const root = await makeTempRoot();
|
|
141
|
+
await writeLib(root, pageFiles);
|
|
142
|
+
await write(path.join(root, "apps/demo/lib/st.ts"), 'export { st as shared } from "@libs/shared/client";\n');
|
|
143
|
+
await writeFrameworkBase(root);
|
|
144
|
+
const warnings: string[] = [];
|
|
145
|
+
const bundler = new SsrDevBundler(appOf(root, warnings));
|
|
146
|
+
|
|
147
|
+
expect((await bundler.context()).routeRuntime).toBeUndefined();
|
|
148
|
+
expect(warnings).toEqual([expect.stringContaining("runtime files of demo or a lib it mounts are missing")]);
|
|
149
|
+
|
|
150
|
+
await write(path.join(root, "libs/shared/lib/st.ts"), "export const st = {};\n");
|
|
151
|
+
expect((await bundler.context()).routeRuntime?.scopes).toEqual(["libs/shared", "apps/demo"]);
|
|
152
|
+
expect(warnings).toHaveLength(1);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("says what failed when the modules cannot be read, and loads per module again once they can", async () => {
|
|
156
|
+
const root = await makeTempRoot();
|
|
157
|
+
await writeLib(root, pageFiles);
|
|
158
|
+
await writeFrameworkBase(root);
|
|
159
|
+
const warnings: string[] = [];
|
|
160
|
+
const bundler = new SsrDevBundler(appOf(root, warnings));
|
|
161
|
+
const read = spyOn(RouteRuntime, "read").mockRejectedValue(new Error("memo.store.ts is unreadable"));
|
|
162
|
+
try {
|
|
163
|
+
expect((await bundler.context()).routeRuntime).toBeUndefined();
|
|
164
|
+
await bundler.context();
|
|
165
|
+
} finally {
|
|
166
|
+
read.mockRestore();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
expect(warnings).toEqual([
|
|
170
|
+
expect.stringContaining("the modules of demo or a lib it mounts could not be read (memo.store.ts is unreadable)"),
|
|
171
|
+
]);
|
|
172
|
+
expect(warnings[0]).toContain("Fix that, then run `akan sync demo`.");
|
|
173
|
+
expect((await bundler.context()).routeRuntime).toBeDefined();
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -5,14 +5,14 @@ import { resolveSsrPageEntriesForApp } from "../artifact/implicitRootLayout";
|
|
|
5
5
|
import { computeRouteSeedIndex } from "../artifact/routeSeedIndex";
|
|
6
6
|
import { StoreBootstrap } from "../artifact/storeBootstrap";
|
|
7
7
|
import type { App } from "../commandDecorators";
|
|
8
|
-
import { workspaceBarrels } from "../transforms/barrelImportsPlugin";
|
|
9
8
|
import { bundleDefine } from "./bundleDefine";
|
|
10
9
|
import type { ClientEntryDiscovery } from "./clientBuildTypes";
|
|
11
10
|
import { GraphClientEntryDiscovery } from "./clientEntryDiscovery";
|
|
12
11
|
import { CsrDevPaths } from "./csrDevPaths";
|
|
13
12
|
import type { CsrDevContext } from "./csrDevTypes";
|
|
14
13
|
import { DevRegistryBundler } from "./devRegistryBundler";
|
|
15
|
-
import {
|
|
14
|
+
import { DevRouteRuntime } from "./devRouteRuntime";
|
|
15
|
+
import { VendorFileImports } from "./vendorFileImports";
|
|
16
16
|
|
|
17
17
|
//* Dev-only client code of SSR pages as a module registry, under `.akan/artifact/ssr-dev`. Its roots are a bootstrap
|
|
18
18
|
//* (the app's client runtime) and every `"use client"` entry; React and the akanjs vendor facets stay the import map's,
|
|
@@ -23,6 +23,8 @@ export class SsrDevBundler extends DevRegistryBundler {
|
|
|
23
23
|
readonly reloadsOnEntryChange = false;
|
|
24
24
|
#discovery: ClientEntryDiscovery | null = null;
|
|
25
25
|
readonly #sharedDiscovery: (() => ClientEntryDiscovery) | null;
|
|
26
|
+
#route: { inputs: string; runtime: DevRouteRuntime } | null = null;
|
|
27
|
+
#wholeWarned: string | null = null;
|
|
26
28
|
|
|
27
29
|
/** `discovery` is the resident builder's, which it keeps current with every save; a worker discovers afresh. */
|
|
28
30
|
constructor(app: App, { discovery }: { discovery?: () => ClientEntryDiscovery } = {}) {
|
|
@@ -34,7 +36,16 @@ export class SsrDevBundler extends DevRegistryBundler {
|
|
|
34
36
|
const akanConfig = await this.app.getConfig();
|
|
35
37
|
const define = bundleDefine(this.app, "start", "ssr");
|
|
36
38
|
const optimizeImports = [...akanConfig.optimizeImports];
|
|
37
|
-
const
|
|
39
|
+
const externals = await VendorFileImports.specifiersIn(this.app.workspace.workspaceRoot);
|
|
40
|
+
//? The framework barrels narrow as in a route build: `akanjs/ui` whole names every model runtime marker, which
|
|
41
|
+
//? would load every module's store on every page.
|
|
42
|
+
const barrelImports = [...new Set(akanConfig.barrelImports)].filter(
|
|
43
|
+
(barrel) => barrel && !(externals as readonly string[]).includes(barrel),
|
|
44
|
+
);
|
|
45
|
+
const route = await this.#routeRuntime();
|
|
46
|
+
const routeRuntime = typeof route === "string" ? null : route;
|
|
47
|
+
this.#warnWhole(typeof route === "string" ? route : null);
|
|
48
|
+
const modelRuntime = routeRuntime?.wholeSource;
|
|
38
49
|
const configKey = Bun.hash(
|
|
39
50
|
JSON.stringify([
|
|
40
51
|
"ssr",
|
|
@@ -42,8 +53,9 @@ export class SsrDevBundler extends DevRegistryBundler {
|
|
|
42
53
|
Bun.version,
|
|
43
54
|
define,
|
|
44
55
|
optimizeImports,
|
|
45
|
-
|
|
56
|
+
externals,
|
|
46
57
|
barrelImports,
|
|
58
|
+
...(modelRuntime === undefined ? [] : [modelRuntime]),
|
|
47
59
|
]),
|
|
48
60
|
).toString(36);
|
|
49
61
|
return {
|
|
@@ -54,27 +66,70 @@ export class SsrDevBundler extends DevRegistryBundler {
|
|
|
54
66
|
optimizeImports,
|
|
55
67
|
configKey,
|
|
56
68
|
refreshFile: null,
|
|
57
|
-
externals
|
|
69
|
+
externals,
|
|
58
70
|
barrelImports,
|
|
71
|
+
...(routeRuntime ? { modelRuntime, routeRuntime } : {}),
|
|
59
72
|
};
|
|
60
73
|
}
|
|
61
74
|
|
|
62
|
-
//?
|
|
75
|
+
//? A runtime that could not be read is never kept: syncing a lib it mounts changes none of the app's own inputs.
|
|
76
|
+
async #routeRuntime(): Promise<DevRouteRuntime | string> {
|
|
77
|
+
const { name } = this.app;
|
|
78
|
+
const whole = (why: string, first = "Run") =>
|
|
79
|
+
`[client-runtime] ${why}, so every page of the development server loads the whole client runtime, not only what it uses. ${first} \`akan sync ${name}\`.`;
|
|
80
|
+
const missing = whole(`the per-module runtime files of ${name} or a lib it mounts are missing`);
|
|
81
|
+
if ((await StoreBootstrap.scopeOf(this.app)) !== "page") return missing;
|
|
82
|
+
const root = this.app.workspace.workspaceRoot;
|
|
83
|
+
const scope = `apps/${name}`;
|
|
84
|
+
const scopes = this.#route?.runtime.scopes ?? [scope];
|
|
85
|
+
const inputs = DevRouteRuntime.inputsOf(root, scopes);
|
|
86
|
+
if (this.#route?.inputs === inputs) return this.#route.runtime;
|
|
87
|
+
this.#route = null;
|
|
88
|
+
try {
|
|
89
|
+
const runtime = await DevRouteRuntime.read(root, scope);
|
|
90
|
+
if (!runtime) return missing;
|
|
91
|
+
const moved = JSON.stringify(runtime.scopes) !== JSON.stringify(scopes);
|
|
92
|
+
this.#route = { inputs: moved ? DevRouteRuntime.inputsOf(root, runtime.scopes) : inputs, runtime };
|
|
93
|
+
return runtime;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
96
|
+
return whole(`the modules of ${name} or a lib it mounts could not be read (${reason})`, "Fix that, then run");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#warnWhole(warning: string | null) {
|
|
101
|
+
if (warning && warning !== this.#wholeWarned) this.app.logger.warn(warning);
|
|
102
|
+
this.#wholeWarned = warning;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//? The client runtime of an SSR page inlines no dictionary (`lib/usePage.ts` reads one only when rendering csr), so
|
|
63
106
|
//? a dictionary save is none of this registry's business.
|
|
64
107
|
override isMetadataFile(file: string): boolean {
|
|
65
108
|
return super.isMetadataFile(file) && !file.endsWith(".dictionary.ts") && path.basename(file) !== "dict.ts";
|
|
66
109
|
}
|
|
67
110
|
|
|
68
111
|
// Run first in the tab, before any client module the payload names: the store registry must exist by then.
|
|
69
|
-
async writeEntries(): Promise<{ files: Record<string, string>; changed: string[] }> {
|
|
112
|
+
async writeEntries(context?: CsrDevContext): Promise<{ files: Record<string, string>; changed: string[] }> {
|
|
70
113
|
await mkdir(this.entryDir, { recursive: true });
|
|
71
|
-
const file = path.join(this.entryDir, "bootstrap.ts");
|
|
72
114
|
const hasStore = await Bun.file(path.join(this.app.cwdPath, "lib", "st.ts")).exists();
|
|
73
|
-
const
|
|
115
|
+
const scope = context?.modelRuntime === undefined ? "whole" : "page";
|
|
116
|
+
const owners = hasStore ? context?.routeRuntime?.ownersSource() : undefined;
|
|
117
|
+
const { ownersModule } = DevRouteRuntime;
|
|
118
|
+
const bootstrap = hasStore
|
|
119
|
+
? `${StoreBootstrap.source(this.app.name, scope)}${owners ? `import "./${ownersModule}";\n` : ""}`
|
|
120
|
+
: "export {};\n";
|
|
121
|
+
const entryFile = await SsrDevBundler.#writeIfChanged(path.join(this.entryDir, "bootstrap.ts"), bootstrap);
|
|
122
|
+
const ownersFile = owners
|
|
123
|
+
? await SsrDevBundler.#writeIfChanged(path.join(this.entryDir, `${ownersModule}.ts`), owners)
|
|
124
|
+
: null;
|
|
125
|
+
const changed = [entryFile, ownersFile].flatMap((written) => (written?.changed ? [written.file] : []));
|
|
126
|
+
return { files: { [SsrDevBundler.bootstrapKey]: entryFile.file }, changed };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static async #writeIfChanged(file: string, source: string): Promise<{ file: string; changed: boolean }> {
|
|
74
130
|
const unchanged = (await Bun.file(file).exists()) && (await Bun.file(file).text()) === source;
|
|
75
131
|
if (!unchanged) await Bun.write(file, source);
|
|
76
|
-
|
|
77
|
-
return { files: { [SsrDevBundler.bootstrapKey]: entryFile }, changed: unchanged ? [] : [entryFile] };
|
|
132
|
+
return { file: CsrDevPaths.realpath(file), changed: !unchanged };
|
|
78
133
|
}
|
|
79
134
|
|
|
80
135
|
/** Every `"use client"` entry the app's routes reach, the ones a route build names in its manifest. */
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdir, realpath, symlink } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { printedInOwnProcess, tempDirs, writeText as write } from "../test/testHelpers";
|
|
5
|
+
import { VendorFileImports } from "./vendorFileImports";
|
|
6
|
+
import { VENDOR_SPECIFIERS } from "./vendorSpecifiers";
|
|
7
|
+
|
|
8
|
+
const makeTempRoot = tempDirs("akan-vendor-files-");
|
|
9
|
+
const akanjsRoot = path.resolve(import.meta.dir, "../../../akanjs");
|
|
10
|
+
const inAkanjs = (file: string) => path.join(akanjsRoot, file);
|
|
11
|
+
|
|
12
|
+
describe("VendorFileImports.vendorOf", () => {
|
|
13
|
+
const files = new VendorFileImports(akanjsRoot, VENDOR_SPECIFIERS);
|
|
14
|
+
|
|
15
|
+
test("a file its vendor's barrel re-exports whole comes from that vendor, by any path", () => {
|
|
16
|
+
expect(files.vendorOf("../../client/cn", inAkanjs("ui/recipe/factory.ts"))).toBe("akanjs/client");
|
|
17
|
+
expect(files.vendorOf("../client/sharedContext", inAkanjs("ui/overlayLayer.ts"))).toBe("akanjs/client");
|
|
18
|
+
expect(files.vendorOf("./device", inAkanjs("client/keyboardRide.ts"))).toBe("akanjs/client");
|
|
19
|
+
expect(files.vendorOf(inAkanjs("client/csrTypes.ts"), "/app/.akan/generated/wrapper.tsx")).toBe("akanjs/client");
|
|
20
|
+
expect(files.vendorOf("akanjs/client", inAkanjs("ui/overlayLayer.ts"))).toBe("akanjs/client");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("a file the barrel leaves out stays the importer's", () => {
|
|
24
|
+
expect(files.vendorOf("../../client/rscRoutePatch", inAkanjs("ui/System/Client.tsx"))).toBeNull();
|
|
25
|
+
expect(files.vendorOf("akanjs/client/native", inAkanjs("ui/overlayLayer.ts"))).toBeNull();
|
|
26
|
+
expect(files.vendorOf("../../store/openSeq", inAkanjs("ui/Model/LoadStore.tsx"))).toBeNull();
|
|
27
|
+
expect(files.vendorOf("../webkit/useTransitionStore", inAkanjs("server/rscClient.tsx"))).toBeNull();
|
|
28
|
+
expect(files.vendorOf("react", inAkanjs("ui/overlayLayer.ts"))).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("a file of another vendor stays the importer's, even one its barrel re-exports whole", () => {
|
|
32
|
+
expect(files.vendorOf("../../store/action", inAkanjs("ui/Model/LoadStore.tsx"))).toBeNull();
|
|
33
|
+
expect(files.vendorOf("akanjs/base/akanError", inAkanjs("ui/overlayLayer.ts"))).toBeNull();
|
|
34
|
+
expect(files.vendorOf("../common/akanNames", inAkanjs("client/device.ts"))).toBeNull();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("without an akanjs to read, every vendor stays external and no file maps to one", () => {
|
|
38
|
+
const unread = new VendorFileImports(null, VENDOR_SPECIFIERS);
|
|
39
|
+
expect(unread.specifiers).toEqual(VENDOR_SPECIFIERS);
|
|
40
|
+
expect(unread.vendorOf("../../client/cn", inAkanjs("ui/recipe/factory.ts"))).toBeNull();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("VendorFileImports.wholeReexports", () => {
|
|
45
|
+
test("lists only the files a barrel re-exports in full under their own names, none it shadows", async () => {
|
|
46
|
+
const root = await makeTempRoot();
|
|
47
|
+
const files: Record<string, string> = {
|
|
48
|
+
"named.ts": "export const a = 1;\nexport const b = 2;\n",
|
|
49
|
+
"starred.ts": "export const c = 1;\n",
|
|
50
|
+
"partial.ts": "export const d = 1;\nexport const e = 2;\n",
|
|
51
|
+
"renamed.ts": "export const f = 1;\n",
|
|
52
|
+
"clashA.ts": "export const g = 1;\n",
|
|
53
|
+
"clashB.ts": "export const g = 2;\n",
|
|
54
|
+
"forwarding.ts": 'export * from "./named";\n',
|
|
55
|
+
"typed.ts": "export interface T {\n t: number;\n}\n",
|
|
56
|
+
"shadowed.ts": "export const h = 1;\n",
|
|
57
|
+
"shadowedByList.ts": "export const k = 1;\n",
|
|
58
|
+
"index.ts": [
|
|
59
|
+
'export { a, b } from "./named";',
|
|
60
|
+
'export * from "./starred";',
|
|
61
|
+
'export { d } from "./partial";',
|
|
62
|
+
'export { f as renamedF } from "./renamed";',
|
|
63
|
+
'export * from "./clashA";',
|
|
64
|
+
'export * from "./clashB";',
|
|
65
|
+
'export * from "./forwarding";',
|
|
66
|
+
'export type { T } from "./typed";',
|
|
67
|
+
'export * from "./shadowed";',
|
|
68
|
+
"export const h = 2;",
|
|
69
|
+
'export * from "./shadowedByList";',
|
|
70
|
+
"const k = 2;",
|
|
71
|
+
"export { k };",
|
|
72
|
+
"",
|
|
73
|
+
].join("\n"),
|
|
74
|
+
};
|
|
75
|
+
for (const [name, source] of Object.entries(files)) await write(path.join(root, name), source);
|
|
76
|
+
|
|
77
|
+
const whole = VendorFileImports.wholeReexports(path.join(root, "index.ts")).map((file) => path.basename(file));
|
|
78
|
+
|
|
79
|
+
expect(whole.sort((a, b) => a.localeCompare(b))).toEqual(["named.ts", "starred.ts"]);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("VendorFileImports.plugin", () => {
|
|
84
|
+
test("a static import of a covered file becomes the vendor; a dynamic one stays a chunk of the build", async () => {
|
|
85
|
+
const root = await makeTempRoot();
|
|
86
|
+
const pkg = path.join(root, "akanjs");
|
|
87
|
+
await write(path.join(pkg, "client/index.ts"), 'export * from "./cn";\nexport * from "./lazy";\n');
|
|
88
|
+
await write(path.join(pkg, "client/cn.ts"), 'export const cn = () => "cn-marker";\n');
|
|
89
|
+
await write(path.join(pkg, "client/lazy.ts"), 'export const lazy = () => "lazy-marker";\n');
|
|
90
|
+
await write(
|
|
91
|
+
path.join(root, "entry.ts"),
|
|
92
|
+
'import { cn } from "./akanjs/client/cn";\nexport const run = async () => [cn(), (await import("./akanjs/client/lazy")).lazy()];\n',
|
|
93
|
+
);
|
|
94
|
+
const result = await Bun.build({
|
|
95
|
+
entrypoints: [path.join(root, "entry.ts")],
|
|
96
|
+
outdir: path.join(root, "out"),
|
|
97
|
+
splitting: true,
|
|
98
|
+
format: "esm",
|
|
99
|
+
plugins: [new VendorFileImports(pkg, ["akanjs/client"]).plugin()],
|
|
100
|
+
});
|
|
101
|
+
const code = (await Promise.all(result.outputs.map((output) => output.text()))).join("\n");
|
|
102
|
+
|
|
103
|
+
expect(code).toContain('from "akanjs/client"');
|
|
104
|
+
expect(code).not.toContain("cn-marker");
|
|
105
|
+
expect(code).toContain("lazy-marker");
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
interface BuildsReport {
|
|
110
|
+
builds: number;
|
|
111
|
+
runtimeHoldsDevice: boolean;
|
|
112
|
+
shared: string[];
|
|
113
|
+
}
|
|
114
|
+
const nativeBridge =
|
|
115
|
+
"the native bridge the barrel leaves out: the vendor's device.ts and storage.ts import it lazily, the page by path, and only the CSR shell loads either";
|
|
116
|
+
const underNativeBridge = "imported by the native bridge, so written with each of its two copies";
|
|
117
|
+
const allowedInBoth: Record<string, string> = {
|
|
118
|
+
"akanjs/client/native.ts": nativeBridge,
|
|
119
|
+
"@akanjs/native/packages/core/src/acl.ts": underNativeBridge,
|
|
120
|
+
"@akanjs/native/packages/core/src/boot.ts": underNativeBridge,
|
|
121
|
+
"@akanjs/native/packages/core/src/contract.ts": underNativeBridge,
|
|
122
|
+
"@akanjs/native/packages/core/src/errors.ts": underNativeBridge,
|
|
123
|
+
"@akanjs/native/packages/core/src/kernel.ts": underNativeBridge,
|
|
124
|
+
"@akanjs/native/packages/core/src/live.ts": underNativeBridge,
|
|
125
|
+
"@akanjs/native/packages/core/src/plugin.ts": underNativeBridge,
|
|
126
|
+
"@akanjs/native/packages/core/src/protocol.ts": underNativeBridge,
|
|
127
|
+
"@akanjs/native/packages/core/src/runtime.ts": underNativeBridge,
|
|
128
|
+
"@akanjs/native/packages/core/src/state.ts": underNativeBridge,
|
|
129
|
+
"@akanjs/native/packages/core/src/veto.ts": underNativeBridge,
|
|
130
|
+
"@akanjs/native/packages/react/src/index.ts": underNativeBridge,
|
|
131
|
+
"@akanjs/native/plugins/app-state/src/index.ts": underNativeBridge,
|
|
132
|
+
"@akanjs/native/plugins/app-state/src/web.ts": underNativeBridge,
|
|
133
|
+
"@akanjs/native/plugins/app/src/index.ts": underNativeBridge,
|
|
134
|
+
"@akanjs/native/plugins/app/src/web.ts": underNativeBridge,
|
|
135
|
+
"@akanjs/native/plugins/auth-session/src/index.ts": underNativeBridge,
|
|
136
|
+
"@akanjs/native/plugins/browser/src/args.ts": underNativeBridge,
|
|
137
|
+
"@akanjs/native/plugins/browser/src/index.ts": underNativeBridge,
|
|
138
|
+
"@akanjs/native/plugins/browser/src/web.ts": underNativeBridge,
|
|
139
|
+
"@akanjs/native/plugins/device/src/index.ts": underNativeBridge,
|
|
140
|
+
"@akanjs/native/plugins/device/src/web.ts": underNativeBridge,
|
|
141
|
+
"@akanjs/native/plugins/dialog/src/index.ts": underNativeBridge,
|
|
142
|
+
"@akanjs/native/plugins/dialog/src/options.ts": underNativeBridge,
|
|
143
|
+
"@akanjs/native/plugins/dialog/src/web.ts": underNativeBridge,
|
|
144
|
+
"@akanjs/native/plugins/file-picker/src/common.ts": underNativeBridge,
|
|
145
|
+
"@akanjs/native/plugins/file-picker/src/index.ts": underNativeBridge,
|
|
146
|
+
"@akanjs/native/plugins/file-picker/src/web.ts": underNativeBridge,
|
|
147
|
+
"@akanjs/native/plugins/haptics/src/index.ts": underNativeBridge,
|
|
148
|
+
"@akanjs/native/plugins/haptics/src/web.ts": underNativeBridge,
|
|
149
|
+
"@akanjs/native/plugins/keyboard/src/index.ts": underNativeBridge,
|
|
150
|
+
"@akanjs/native/plugins/keyboard/src/web.ts": underNativeBridge,
|
|
151
|
+
"@akanjs/native/plugins/opener/src/index.ts": underNativeBridge,
|
|
152
|
+
"@akanjs/native/plugins/opener/src/url.ts": underNativeBridge,
|
|
153
|
+
"@akanjs/native/plugins/opener/src/web.ts": underNativeBridge,
|
|
154
|
+
"@akanjs/native/plugins/preferences/src/index.ts": underNativeBridge,
|
|
155
|
+
"@akanjs/native/plugins/preferences/src/web.ts": underNativeBridge,
|
|
156
|
+
"@akanjs/native/plugins/push/src/index.ts": underNativeBridge,
|
|
157
|
+
"@akanjs/native/plugins/secure-storage/src/index.ts": underNativeBridge,
|
|
158
|
+
"@akanjs/native/plugins/updates/src/index.ts": underNativeBridge,
|
|
159
|
+
"@akanjs/native/plugins/volume/src/index.ts": underNativeBridge,
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
describe("a page's two browser builds", () => {
|
|
163
|
+
test("share only the native bridge the CSR shell loads, by the barrel, a linked path, a relative one or `akanjs/client/native`", async () => {
|
|
164
|
+
const root = await realpath(await makeTempRoot());
|
|
165
|
+
const appDir = path.join(root, "apps/demo");
|
|
166
|
+
await mkdir(path.join(root, "pkgs"), { recursive: true });
|
|
167
|
+
await symlink(akanjsRoot, path.join(root, "pkgs/akanjs"), "dir");
|
|
168
|
+
const paths = { "@apps/*": ["./apps/*"], "akanjs/*": ["./pkgs/akanjs/*"] };
|
|
169
|
+
await write(path.join(root, "tsconfig.json"), JSON.stringify({ compilerOptions: { baseUrl: ".", paths } }));
|
|
170
|
+
await write(path.join(appDir, "lib/useClient.ts"), "export const usePage = () => 1;\n");
|
|
171
|
+
await write(path.join(appDir, "lib/st.ts"), "export const st = Object.freeze({});\n");
|
|
172
|
+
await write(
|
|
173
|
+
path.join(appDir, "ui/Barrel.tsx"),
|
|
174
|
+
'"use client";\nimport { cn, Device, sharedContext } from "akanjs/client";\nexport const Barrel = () => [cn("a"), Device.name, sharedContext];\n',
|
|
175
|
+
);
|
|
176
|
+
await write(
|
|
177
|
+
path.join(appDir, "ui/Relative.tsx"),
|
|
178
|
+
'"use client";\nimport { cn } from "../../../pkgs/akanjs/client/cn";\nexport const Relative = () => cn("b");\n',
|
|
179
|
+
);
|
|
180
|
+
await write(
|
|
181
|
+
path.join(appDir, "ui/Native.tsx"),
|
|
182
|
+
'"use client";\nimport { isNativeApp } from "akanjs/client/native";\nexport const Native = () => isNativeApp();\n',
|
|
183
|
+
);
|
|
184
|
+
const linked = path.join(root, "pkgs/akanjs");
|
|
185
|
+
const entries = [
|
|
186
|
+
path.join(appDir, "ui/Barrel.tsx"),
|
|
187
|
+
path.join(appDir, "ui/Relative.tsx"),
|
|
188
|
+
path.join(appDir, "ui/Native.tsx"),
|
|
189
|
+
path.join(linked, "client/device.ts"),
|
|
190
|
+
path.join(linked, "client/sharedContext.ts"),
|
|
191
|
+
path.join(linked, "client/csrTypes.ts"),
|
|
192
|
+
path.join(linked, "ui/UiOverride/UiOverride.tsx"),
|
|
193
|
+
];
|
|
194
|
+
|
|
195
|
+
const { shared, ...builds } = (await printedInOwnProcess(
|
|
196
|
+
`
|
|
197
|
+
const fs = await import("node:fs");
|
|
198
|
+
const path = await import("node:path");
|
|
199
|
+
const dir = ${JSON.stringify(import.meta.dir)};
|
|
200
|
+
const { RouteClientBuilder } = await import(path.join(dir, "routeClientBuilder.ts"));
|
|
201
|
+
const { SsrBaseArtifactBuilder } = await import(path.join(dir, "ssrBaseArtifactBuilder.ts"));
|
|
202
|
+
const { VendorImportScanner } = await import(path.join(dir, "vendorImportScanner.ts"));
|
|
203
|
+
const { NARROWABLE_VENDOR_SPECIFIERS } = await import(path.join(dir, "vendorSpecifiers.ts"));
|
|
204
|
+
const [root, entries, paths] = ${JSON.stringify([root, entries, paths])};
|
|
205
|
+
const builds = [];
|
|
206
|
+
const build = Bun.build;
|
|
207
|
+
Bun.build = async (config) => {
|
|
208
|
+
const result = await build(config);
|
|
209
|
+
if (config.target === "browser") builds.push({ entrypoints: config.entrypoints, metafile: result.metafile });
|
|
210
|
+
return result;
|
|
211
|
+
};
|
|
212
|
+
const app = {
|
|
213
|
+
name: "demo",
|
|
214
|
+
cwdPath: root + "/apps/demo",
|
|
215
|
+
dist: { cwdPath: root + "/dist/apps/demo" },
|
|
216
|
+
workspace: { workspaceRoot: root },
|
|
217
|
+
getConfig: async () => ({ barrelImports: [], optimizeImports: [] }),
|
|
218
|
+
getTsConfig: async () => ({ compilerOptions: { paths } }),
|
|
219
|
+
getPublicEnv: () => ({}),
|
|
220
|
+
logger: { warn: () => {} },
|
|
221
|
+
verbose: () => {},
|
|
222
|
+
};
|
|
223
|
+
const routes = await new RouteClientBuilder({ app, seeds: [], entries, command: "build", browser: "chunks" }).build();
|
|
224
|
+
const vendorExports = await VendorImportScanner.exportsUsedIn(
|
|
225
|
+
root + "/dist/apps/demo/.akan/artifact/client",
|
|
226
|
+
NARROWABLE_VENDOR_SPECIFIERS,
|
|
227
|
+
Object.values(routes.manifestDelta).map(({ id }) => id),
|
|
228
|
+
);
|
|
229
|
+
await new SsrBaseArtifactBuilder(app, "build", { vendorExports }).buildRuntimeClientEntries();
|
|
230
|
+
const modulesOf = ({ metafile }) => {
|
|
231
|
+
const modules = new Set();
|
|
232
|
+
for (const output of Object.values(metafile.outputs))
|
|
233
|
+
for (const [input, { bytesInOutput }] of Object.entries(output.inputs)) {
|
|
234
|
+
const file = path.resolve(root, input);
|
|
235
|
+
if (bytesInOutput > 0 && fs.existsSync(file)) modules.add(fs.realpathSync(file));
|
|
236
|
+
}
|
|
237
|
+
return modules;
|
|
238
|
+
};
|
|
239
|
+
const [routeBuild, runtimeBuild] = builds.map(modulesOf);
|
|
240
|
+
const pkgs = ${JSON.stringify(path.dirname(akanjsRoot))};
|
|
241
|
+
console.log(JSON.stringify({
|
|
242
|
+
builds: builds.length,
|
|
243
|
+
runtimeHoldsDevice: runtimeBuild.has(path.join(pkgs, "akanjs/client/device.ts")),
|
|
244
|
+
shared: [...routeBuild].filter((file) => runtimeBuild.has(file)).map((file) => path.relative(pkgs, file)).sort(),
|
|
245
|
+
}));
|
|
246
|
+
`,
|
|
247
|
+
root,
|
|
248
|
+
)) as BuildsReport;
|
|
249
|
+
|
|
250
|
+
expect(builds).toEqual({ builds: 2, runtimeHoldsDevice: true });
|
|
251
|
+
expect(shared).toContain("akanjs/client/native.ts");
|
|
252
|
+
expect(shared.filter((file) => !Object.hasOwn(allowedInBoth, file))).toEqual([]);
|
|
253
|
+
}, 120_000);
|
|
254
|
+
});
|