@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
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { StoreBootstrap } from "../artifact/storeBootstrap";
|
|
4
|
+
import type { AskedExports } from "./clientBuildTypes";
|
|
5
|
+
import { ClientEntryGroups } from "./clientEntryGroups";
|
|
6
|
+
|
|
7
|
+
describe("ClientEntryGroups", () => {
|
|
8
|
+
const entry = (name: string) => path.resolve(`/repo/apps/demo/ui/${name}.tsx`);
|
|
9
|
+
const part = (name: string, ...names: string[]) => ({ entry: entry(name), names });
|
|
10
|
+
const entriesOf = (groups: readonly { entry: string }[][]) =>
|
|
11
|
+
groups.map((group) => group.map((held) => path.basename(held.entry, ".tsx")));
|
|
12
|
+
|
|
13
|
+
test("puts together the entries exactly the same routes load, whatever order the routes come in", () => {
|
|
14
|
+
const routes: Record<string, string[]> = {
|
|
15
|
+
Shell: ["/a", "/b"],
|
|
16
|
+
Nav: ["/b", "/a"],
|
|
17
|
+
Board: ["/b"],
|
|
18
|
+
Chart: ["/b"],
|
|
19
|
+
Solo: ["/a"],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const groups = ClientEntryGroups.plan(
|
|
23
|
+
Object.keys(routes).map((name) => part(name, name)),
|
|
24
|
+
(held) => routes[path.basename(held.entry, ".tsx")] ?? [],
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
expect(entriesOf(groups)).toEqual([["Shell", "Nav"], ["Board", "Chart"], ["Solo"]]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("leaves alone an entry no route loads and an entry whose export names are not known", () => {
|
|
31
|
+
const groups = ClientEntryGroups.plan(
|
|
32
|
+
[part("Unused", "Unused"), part("Other", "Other"), part("Star"), part("Bare")],
|
|
33
|
+
(held) => (held.entry === entry("Unused") || held.entry === entry("Other") ? [] : ["/a"]),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
expect(entriesOf(groups)).toEqual([["Unused"], ["Other"], ["Star"], ["Bare"]]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("a part of an entry is loaded by the routes asking it for one of its names, and by a route asking for none in particular", () => {
|
|
40
|
+
const loadedBy = ClientEntryGroups.loadedBy(
|
|
41
|
+
new Map([
|
|
42
|
+
["/a", [entry("Pair"), entry("Pair")]],
|
|
43
|
+
["/b", [entry("Pair")]],
|
|
44
|
+
["/c", [entry("Pair")]],
|
|
45
|
+
["/d", [entry("Else")]],
|
|
46
|
+
]),
|
|
47
|
+
new Map<string, AskedExports>([
|
|
48
|
+
["/a", new Map([[entry("Pair"), ["A"]]])],
|
|
49
|
+
["/b", new Map([[entry("Pair"), ["B"]]])],
|
|
50
|
+
["/c", new Map([[entry("Pair"), null]])],
|
|
51
|
+
]),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(loadedBy(part("Pair", "A"))).toEqual(["/a", "/c"]);
|
|
55
|
+
expect(loadedBy(part("Pair", "B"))).toEqual(["/b", "/c"]);
|
|
56
|
+
expect(loadedBy(part("Else", "Else"))).toEqual(["/d"]);
|
|
57
|
+
expect(loadedBy(part("Never", "Never"))).toEqual([]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("a group exports every name under a name of its own, so two entries' defaults do not collide", () => {
|
|
61
|
+
const exports = ClientEntryGroups.exportsOf([part("One", "default", "One"), part("Two", "default")]);
|
|
62
|
+
|
|
63
|
+
expect([...exports]).toEqual([
|
|
64
|
+
["g0", { entry: entry("One"), name: "default" }],
|
|
65
|
+
["g1", { entry: entry("One"), name: "One" }],
|
|
66
|
+
["g2", { entry: entry("Two"), name: "default" }],
|
|
67
|
+
]);
|
|
68
|
+
expect(ClientEntryGroups.source("demo", exports, "page")).toBe(
|
|
69
|
+
[
|
|
70
|
+
...StoreBootstrap.importLines("demo", "page"),
|
|
71
|
+
`export { default as g0, One as g1 } from ${JSON.stringify(entry("One"))};`,
|
|
72
|
+
`export { default as g2 } from ${JSON.stringify(entry("Two"))};`,
|
|
73
|
+
"",
|
|
74
|
+
].join("\n"),
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { type ClientRuntimeScope, StoreBootstrap } from "../artifact/storeBootstrap";
|
|
3
|
+
import type { AskedExports } from "./clientBuildTypes";
|
|
4
|
+
|
|
5
|
+
export interface ClientEntryPart {
|
|
6
|
+
entry: string;
|
|
7
|
+
names: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface GroupedExport {
|
|
11
|
+
entry: string;
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//? Bun gives a module a chunk per set of entries reaching it, so entries the same routes load are built as one.
|
|
16
|
+
export class ClientEntryGroups {
|
|
17
|
+
static plan<Part extends ClientEntryPart>(
|
|
18
|
+
parts: readonly Part[],
|
|
19
|
+
routesOf: (part: Part) => readonly string[],
|
|
20
|
+
): Part[][] {
|
|
21
|
+
const groups = new Map<string, Part[]>();
|
|
22
|
+
const alone: Part[][] = [];
|
|
23
|
+
for (const part of parts) {
|
|
24
|
+
const routes = routesOf(part);
|
|
25
|
+
if (routes.length === 0 || part.names.length === 0) alone.push([part]);
|
|
26
|
+
else groups.getOrInsert(routes.toSorted((a, b) => a.localeCompare(b)).join("\n"), []).push(part);
|
|
27
|
+
}
|
|
28
|
+
return [...groups.values(), ...alone];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static loadedBy(
|
|
32
|
+
entriesByRoute: ReadonlyMap<string, readonly string[]>,
|
|
33
|
+
askedByRoute?: ReadonlyMap<string, AskedExports>,
|
|
34
|
+
): (part: ClientEntryPart) => string[] {
|
|
35
|
+
const loads = new Map<string, { route: string; asked: readonly string[] | null }[]>();
|
|
36
|
+
for (const [route, entries] of entriesByRoute)
|
|
37
|
+
for (const entry of new Set(entries.map((held) => path.resolve(held))))
|
|
38
|
+
loads.getOrInsert(entry, []).push({ route, asked: askedByRoute?.get(route)?.get(entry) ?? null });
|
|
39
|
+
return ({ entry, names }) =>
|
|
40
|
+
(loads.get(path.resolve(entry)) ?? [])
|
|
41
|
+
.filter(({ asked }) => !asked || names.some((name) => asked.includes(name)))
|
|
42
|
+
.map(({ route }) => route);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static exportsOf(group: readonly ClientEntryPart[]): Map<string, GroupedExport> {
|
|
46
|
+
const exports = new Map<string, GroupedExport>();
|
|
47
|
+
for (const { entry, names } of group)
|
|
48
|
+
for (const name of names) exports.set(`g${exports.size}`, { entry: path.resolve(entry), name });
|
|
49
|
+
return exports;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static source(appName: string, exports: ReadonlyMap<string, GroupedExport>, scope: ClientRuntimeScope): string {
|
|
53
|
+
const byEntry = new Map<string, string[]>();
|
|
54
|
+
for (const [alias, { entry, name }] of exports) byEntry.getOrInsert(entry, []).push(`${name} as ${alias}`);
|
|
55
|
+
const lines = [
|
|
56
|
+
...StoreBootstrap.importLines(appName, scope),
|
|
57
|
+
...[...byEntry].map(([entry, names]) => `export { ${names.join(", ")} } from ${JSON.stringify(entry)};`),
|
|
58
|
+
];
|
|
59
|
+
return `${lines.join("\n")}\n`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -110,7 +110,7 @@ export class CsrDevArtifactWriter {
|
|
|
110
110
|
async writeVendor(graph: CsrDevGraph): Promise<string> {
|
|
111
111
|
const ids = Object.keys(graph.modules)
|
|
112
112
|
.filter((id) => graph.modules[id]?.vendor)
|
|
113
|
-
.sort();
|
|
113
|
+
.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
114
114
|
const stubs = new Set(Object.values(graph.modules).flatMap((module) => module.deps.filter(CsrDevPaths.isStub)));
|
|
115
115
|
const lines = [await this.#helperDefinitions(graph, ids), ...(await this.#defineLines(ids))];
|
|
116
116
|
for (const stub of [...stubs].sort()) {
|
|
@@ -138,7 +138,7 @@ export class CsrDevArtifactWriter {
|
|
|
138
138
|
): Promise<void> {
|
|
139
139
|
const ids = Object.keys(graph.modules)
|
|
140
140
|
.filter((id) => !graph.modules[id]?.vendor)
|
|
141
|
-
.sort();
|
|
141
|
+
.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
142
142
|
const lines = await this.#defineLines(ids, code);
|
|
143
143
|
const blocks = ids.map((id, index) => [id, lines[index] ?? ""] as [string, string]);
|
|
144
144
|
const start = this.#library
|
|
@@ -3,6 +3,7 @@ import { mkdtemp, rm } from "node:fs/promises";
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import type { App } from "../commandDecorators";
|
|
6
|
+
import { printedInOwnProcess, tempDirs } from "../test/testHelpers";
|
|
6
7
|
import { CsrDevModuleCompiler } from "./csrDevModuleCompiler";
|
|
7
8
|
import { CsrDevPaths } from "./csrDevPaths";
|
|
8
9
|
import { CsrDevResolver } from "./csrDevResolver";
|
|
@@ -189,6 +190,28 @@ describe("CsrDevModuleCompiler", () => {
|
|
|
189
190
|
await rm(root, { recursive: true, force: true });
|
|
190
191
|
});
|
|
191
192
|
|
|
193
|
+
test("answers the model runtime marker with the context's source, in an installed package and in app code", async () => {
|
|
194
|
+
const markers = ["node_modules/akanjs/ui/modelRuntime.ts", "pkgs/akanjs/ui/modelRuntime.ts"].map(file);
|
|
195
|
+
for (const marker of markers) await Bun.write(marker, "export {};\n");
|
|
196
|
+
await Bun.write(file("apps/demo/lib/st.ts"), 'export const st = "store";\n');
|
|
197
|
+
const paths = new CsrDevPaths(root);
|
|
198
|
+
const modelRuntime = `import ${JSON.stringify(file("apps/demo/lib/st.ts"))};\n`;
|
|
199
|
+
const compiler = new CsrDevModuleCompiler({
|
|
200
|
+
app: { verbose: () => undefined, logger: { error: (message: string) => logged.push(message) } } as unknown as App,
|
|
201
|
+
paths,
|
|
202
|
+
resolver: new CsrDevResolver({ paths, context, entryFiles: [] }),
|
|
203
|
+
context: { ...context, modelRuntime },
|
|
204
|
+
outDir: file("out"),
|
|
205
|
+
routePrefix: "/_akan/registry/",
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const { modules } = await compiler.compile(markers, new Set());
|
|
209
|
+
|
|
210
|
+
for (const marker of markers)
|
|
211
|
+
expect(modules.find((module) => module.file === marker)?.deps).toEqual([file("apps/demo/lib/st.ts")]);
|
|
212
|
+
expect(modules.map((module) => module.file)).toContain(file("apps/demo/lib/st.ts"));
|
|
213
|
+
});
|
|
214
|
+
|
|
192
215
|
test("a pre-bundled file keeps its own __reExport and __toESM, which Bun leaves in place of its own", async () => {
|
|
193
216
|
const { modules } = await compile("node_modules/prebundled/chunk.mjs");
|
|
194
217
|
const [module] = modules;
|
|
@@ -388,3 +411,66 @@ describe("CsrDevModuleCompiler barrel narrowing", () => {
|
|
|
388
411
|
]);
|
|
389
412
|
});
|
|
390
413
|
});
|
|
414
|
+
|
|
415
|
+
describe("CsrDevModuleCompiler loading per module", () => {
|
|
416
|
+
const makeTempRoot = tempDirs("akan-csr-dev-descriptors-");
|
|
417
|
+
|
|
418
|
+
test("answers a module piece's macro with descriptors read from the signal, in a process of its own", async () => {
|
|
419
|
+
const root = CsrDevPaths.realpath(await makeTempRoot());
|
|
420
|
+
await Bun.write(
|
|
421
|
+
path.join(root, "apps/demo/lib/sig.ts"),
|
|
422
|
+
`const serialized = { draft: { endpoint: { draftOf: { type: "query", args: [], returns: { refName: "draft-descriptor-ref" } } } } };
|
|
423
|
+
export const fetch = { ownSerializedSignal: serialized };
|
|
424
|
+
export const getSerializedSignalOf = (name: string) => (name === "base" ? {} : { [name]: serialized[name as "draft"] });
|
|
425
|
+
`,
|
|
426
|
+
);
|
|
427
|
+
const piece = path.join(root, "apps/demo/lib/__client/draft.fetch.ts");
|
|
428
|
+
await Bun.write(
|
|
429
|
+
piece,
|
|
430
|
+
'import { getSerializedSignalOf } from "../sig" with { type: "macro" };\nexport const descriptors = getSerializedSignalOf("draft");\n',
|
|
431
|
+
);
|
|
432
|
+
const dir = JSON.stringify(import.meta.dir);
|
|
433
|
+
|
|
434
|
+
const compiled = (await printedInOwnProcess(
|
|
435
|
+
`
|
|
436
|
+
const path = await import("node:path");
|
|
437
|
+
const { CsrDevModuleCompiler } = await import(path.join(${dir}, "csrDevModuleCompiler.ts"));
|
|
438
|
+
const { CsrDevPaths } = await import(path.join(${dir}, "csrDevPaths.ts"));
|
|
439
|
+
const { CsrDevResolver } = await import(path.join(${dir}, "csrDevResolver.ts"));
|
|
440
|
+
const { SignalDescriptors } = await import(path.join(${dir}, "../transforms/signalDescriptors.ts"));
|
|
441
|
+
const [root, piece] = ${JSON.stringify([root, piece])};
|
|
442
|
+
let answered = 0;
|
|
443
|
+
const inline = SignalDescriptors.prototype.inline;
|
|
444
|
+
SignalDescriptors.prototype.inline = async function (...args) {
|
|
445
|
+
const contents = await inline.apply(this, args);
|
|
446
|
+
if (contents !== null) answered += 1;
|
|
447
|
+
return contents;
|
|
448
|
+
};
|
|
449
|
+
const logged = [];
|
|
450
|
+
const context = {
|
|
451
|
+
...${JSON.stringify(context)},
|
|
452
|
+
routeRuntime: { scopes: ["apps/demo"], redirectOf: () => null, transform: () => null },
|
|
453
|
+
};
|
|
454
|
+
const paths = new CsrDevPaths(root);
|
|
455
|
+
const compiler = new CsrDevModuleCompiler({
|
|
456
|
+
app: {
|
|
457
|
+
verbose: () => undefined,
|
|
458
|
+
logger: { error: (message) => logged.push(message), warn: (message) => logged.push(message) },
|
|
459
|
+
workspace: { workspaceRoot: root },
|
|
460
|
+
},
|
|
461
|
+
paths,
|
|
462
|
+
resolver: new CsrDevResolver({ paths, context, entryFiles: [] }),
|
|
463
|
+
context,
|
|
464
|
+
outDir: path.join(root, "out"),
|
|
465
|
+
routePrefix: "/_akan/registry/",
|
|
466
|
+
});
|
|
467
|
+
const { modules } = await compiler.compile([piece], new Set());
|
|
468
|
+
console.log(JSON.stringify({ answered, logged, factories: modules.map(({ factory }) => factory) }));
|
|
469
|
+
`,
|
|
470
|
+
root,
|
|
471
|
+
)) as { answered: number; logged: string[]; factories: string[] };
|
|
472
|
+
|
|
473
|
+
expect({ answered: compiled.answered, logged: compiled.logged }).toEqual({ answered: 1, logged: [] });
|
|
474
|
+
expect(compiled.factories.join("\n")).toContain("draft-descriptor-ref");
|
|
475
|
+
}, 30_000);
|
|
476
|
+
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { SSR_DEV_DIRNAME } from "akanjs/server/hmr/csrDevManifest";
|
|
2
3
|
import type { BunPlugin } from "bun";
|
|
4
|
+
import { StoreBootstrap } from "../artifact/storeBootstrap";
|
|
3
5
|
import type { App } from "../commandDecorators";
|
|
4
6
|
import { loaderFor } from "../transforms/moduleSyntax";
|
|
7
|
+
import { SignalDescriptors } from "../transforms/signalDescriptors";
|
|
5
8
|
import { CsrDevFactoryCheck } from "./csrDevFactoryCheck";
|
|
6
9
|
import { CsrDevPaths } from "./csrDevPaths";
|
|
7
10
|
import { CsrDevResolver } from "./csrDevResolver";
|
|
@@ -13,6 +16,7 @@ import type {
|
|
|
13
16
|
CsrDevSharedHelpers,
|
|
14
17
|
} from "./csrDevTypes";
|
|
15
18
|
import { DevBarrelImports } from "./devBarrelImports";
|
|
19
|
+
import { DevRouteRuntime } from "./devRouteRuntime";
|
|
16
20
|
import { RouteClientBuilder } from "./routeClientBuilder";
|
|
17
21
|
|
|
18
22
|
interface OutputMetafile {
|
|
@@ -52,7 +56,8 @@ export interface CsrDevCompileResult {
|
|
|
52
56
|
//* Every module becomes its own CJS factory: one Bun.build with each import external, so a save re-runs only the
|
|
53
57
|
//* modules it changed instead of reloading one scope-hoisted file.
|
|
54
58
|
export class CsrDevModuleCompiler {
|
|
55
|
-
static readonly #storeRoot = /(?:^|\/)lib\/st\.ts$/;
|
|
59
|
+
static readonly #storeRoot = /(?:^|\/)lib\/(?:st|__client\/(?:_st|[^/]+\.st))\.ts$/;
|
|
60
|
+
static readonly #storeOwners = `/.akan/generated/${SSR_DEV_DIRNAME}/${DevRouteRuntime.ownersModule}.ts`;
|
|
56
61
|
static readonly #macroImport = /\b(?:with|assert)\s*\{\s*type\s*:\s*["']macro["']/;
|
|
57
62
|
static readonly #factoryArgument =
|
|
58
63
|
/(?<![\w$.])(?:require|module|exports|__akanImport|\$RefreshReg\$|\$RefreshSig\$)(?![\w$]|\s*:)/;
|
|
@@ -69,6 +74,7 @@ export class CsrDevModuleCompiler {
|
|
|
69
74
|
readonly #assets = new Set<string>();
|
|
70
75
|
#barrels: Promise<DevBarrelImports | null> | null = null;
|
|
71
76
|
readonly #narrowed = new Map<string, Record<string, CsrDevNarrowedImport>>();
|
|
77
|
+
readonly #routed = new Map<string, string>();
|
|
72
78
|
|
|
73
79
|
constructor({ app, paths, resolver, context, outDir, routePrefix }: CsrDevModuleCompilerOptions) {
|
|
74
80
|
this.#app = app;
|
|
@@ -216,6 +222,7 @@ export class CsrDevModuleCompiler {
|
|
|
216
222
|
}
|
|
217
223
|
const sourceMap = sourceMaps.get(`${artifact.path}.map`);
|
|
218
224
|
const narrowed = this.#narrowed.get(file);
|
|
225
|
+
const routed = this.#routed.get(file);
|
|
219
226
|
modules.push({
|
|
220
227
|
id,
|
|
221
228
|
file,
|
|
@@ -226,6 +233,7 @@ export class CsrDevModuleCompiler {
|
|
|
226
233
|
mtimeMs: mtimes.get(file) ?? CsrDevPaths.mtimeOf(file),
|
|
227
234
|
hash: hashes.get(file) ?? "",
|
|
228
235
|
...(narrowed && Object.keys(narrowed).length > 0 ? { narrowed } : {}),
|
|
236
|
+
...(routed ? { routed } : {}),
|
|
229
237
|
});
|
|
230
238
|
}
|
|
231
239
|
return { modules, misses, tangled };
|
|
@@ -279,8 +287,18 @@ export class CsrDevModuleCompiler {
|
|
|
279
287
|
//? rewrite leaves a free `__akanMeta` that no factory header declares. So a file importing a macro has its macros run
|
|
280
288
|
//? first by a build of its own, with every other import left as written, and the module build reads that output.
|
|
281
289
|
async #evaluateMacros(files: string[]): Promise<Map<string, string>> {
|
|
282
|
-
const
|
|
290
|
+
const { routeRuntime } = this.#context;
|
|
291
|
+
const sources = await Promise.all(
|
|
292
|
+
files
|
|
293
|
+
.filter((file) => !routeRuntime?.redirectOf(file))
|
|
294
|
+
.map(async (file) => [file, await Bun.file(file).text()] as const),
|
|
295
|
+
);
|
|
283
296
|
const importers = sources.filter(([, source]) => CsrDevModuleCompiler.#macroImport.test(source));
|
|
297
|
+
const descriptors = routeRuntime
|
|
298
|
+
? new SignalDescriptors(this.#app.workspace.workspaceRoot, routeRuntime.scopes, {
|
|
299
|
+
onUnread: (reason) => this.#app.logger.warn(`[csr-dev] ${reason}, so their pieces run the macro`),
|
|
300
|
+
}).plugin
|
|
301
|
+
: null;
|
|
284
302
|
const outputs = await Promise.all(
|
|
285
303
|
importers.map(async ([file]) => {
|
|
286
304
|
const result = await Bun.build({
|
|
@@ -288,6 +306,7 @@ export class CsrDevModuleCompiler {
|
|
|
288
306
|
target: "browser",
|
|
289
307
|
format: "esm",
|
|
290
308
|
plugins: [
|
|
309
|
+
...(descriptors ? [descriptors] : []),
|
|
291
310
|
{
|
|
292
311
|
name: "akan-csr-macro-pass",
|
|
293
312
|
setup: (build) =>
|
|
@@ -314,6 +333,14 @@ export class CsrDevModuleCompiler {
|
|
|
314
333
|
name: "akan-csr-registry",
|
|
315
334
|
setup: (build) => {
|
|
316
335
|
build.onLoad({ filter: /\.css$/ }, () => ({ contents: "", loader: "js" }));
|
|
336
|
+
const { modelRuntime, routeRuntime } = this.#context;
|
|
337
|
+
if (modelRuntime !== undefined)
|
|
338
|
+
build.onLoad({ filter: StoreBootstrap.modelRuntimeFilter }, () => ({ contents: modelRuntime, loader: "ts" }));
|
|
339
|
+
if (routeRuntime && !vendor)
|
|
340
|
+
build.onLoad({ filter: /[\\/]lib[\\/](?:useClient|st)\.ts$/ }, (args) => {
|
|
341
|
+
const contents = routeRuntime.redirectOf(args.path);
|
|
342
|
+
return contents === null ? undefined : { contents, loader: "ts" };
|
|
343
|
+
});
|
|
317
344
|
if (macroOutputs.size > 0) {
|
|
318
345
|
const exact = [...macroOutputs.keys()].map((file) => file.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
319
346
|
build.onLoad({ filter: new RegExp(`^(?:${exact.join("|")})$`) }, (args) => {
|
|
@@ -325,9 +352,16 @@ export class CsrDevModuleCompiler {
|
|
|
325
352
|
build.onLoad({ filter: /\.(?:tsx?|jsx?)$/ }, async (args) => {
|
|
326
353
|
if (CsrDevPaths.isVendorFile(args.path)) return undefined;
|
|
327
354
|
const source = await Bun.file(args.path).text();
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
355
|
+
const file = CsrDevPaths.realpath(args.path);
|
|
356
|
+
const routed = routeRuntime?.transform(source, args.path) ?? null;
|
|
357
|
+
if (routed) this.#routed.set(file, routed.stamp);
|
|
358
|
+
else this.#routed.delete(file);
|
|
359
|
+
const input = routed?.contents ?? source;
|
|
360
|
+
const rewrite = await (await this.#barrelImports())?.rewrite(input, args.path, {
|
|
361
|
+
perModule: routed?.perModule,
|
|
362
|
+
});
|
|
363
|
+
if (rewrite) this.#narrowed.set(file, rewrite.narrowed);
|
|
364
|
+
const narrowed = rewrite?.contents ?? input;
|
|
331
365
|
const normalized = args.path.endsWith(".tsx")
|
|
332
366
|
? RouteClientBuilder.normalizeNamedDefaultFunctionForFastRefresh(narrowed, { path: args.path })
|
|
333
367
|
: null;
|
|
@@ -359,7 +393,7 @@ export class CsrDevModuleCompiler {
|
|
|
359
393
|
}
|
|
360
394
|
|
|
361
395
|
#barrelImports(): Promise<DevBarrelImports | null> {
|
|
362
|
-
this.#barrels ??= DevBarrelImports.create(this.#app, this.#context
|
|
396
|
+
this.#barrels ??= DevBarrelImports.create(this.#app, this.#context);
|
|
363
397
|
return this.#barrels;
|
|
364
398
|
}
|
|
365
399
|
|
|
@@ -413,8 +447,10 @@ export class CsrDevModuleCompiler {
|
|
|
413
447
|
);
|
|
414
448
|
}
|
|
415
449
|
// StoreRegistry.build merges into one global store instance, so every importer already holds the updated `st`:
|
|
416
|
-
// re-running the store root is the whole update
|
|
417
|
-
|
|
450
|
+
// re-running the store root, or a module's store piece, is the whole update: bubbling past it would only reach the
|
|
451
|
+
// page modules.
|
|
452
|
+
if (CsrDevModuleCompiler.#storeRoot.test(id) || id.endsWith(CsrDevModuleCompiler.#storeOwners))
|
|
453
|
+
patched += "\nmodule.hot.accept();";
|
|
418
454
|
const shared = CsrDevModuleCompiler.#shareHelpers(patched);
|
|
419
455
|
//? What `import.meta` is in a browser module: a `url` and no `env`, so `import.meta.env` checks (jotai, zustand)
|
|
420
456
|
//? branch as they do in the ESM bundle. On the header line, outside the preamble that modules share.
|
|
@@ -84,14 +84,13 @@ describe("CsrDevPatcher", () => {
|
|
|
84
84
|
expect((await new CsrDevPatcher(unstamped.bundler).update([])).kind).toBe("delegate");
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
test("a resident patcher checks the stamp
|
|
87
|
+
test("a resident patcher checks the stamp of the registry it holds in memory too", async () => {
|
|
88
88
|
const { bundler, stamp } = await makeRegistry("same");
|
|
89
89
|
const patcher = new CsrDevPatcher(bundler, { resident: true });
|
|
90
90
|
expect(await patcher.update([])).toEqual({ kind: "unchanged" });
|
|
91
|
-
stamp.current = "moved";
|
|
92
91
|
expect(await patcher.update([])).toEqual({ kind: "unchanged" });
|
|
93
|
-
|
|
94
|
-
expect(
|
|
92
|
+
stamp.current = "moved";
|
|
93
|
+
expect(await patcher.update([])).toMatchObject({ kind: "delegate", generation: 5 });
|
|
95
94
|
});
|
|
96
95
|
|
|
97
96
|
test("a saved metadata file goes to a whole build even when the stamp matches", async () => {
|
|
@@ -350,7 +349,7 @@ describe("CsrDevPatcher", () => {
|
|
|
350
349
|
await Bun.write(file("ui/C.tsx"), 'export const C = () => "c2";\n');
|
|
351
350
|
expect(changedIds(await patcher.update([file("ui/C.tsx")]))).toEqual(["apps/demo/ui/C.tsx"]);
|
|
352
351
|
const graph = (await bundler.writer.readJson<CsrDevGraph>("graph.json")) as CsrDevGraph;
|
|
353
|
-
expect(Object.keys(graph.modules).sort()).toEqual([
|
|
352
|
+
expect(Object.keys(graph.modules).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))).toEqual([
|
|
354
353
|
"apps/demo/entry.ts",
|
|
355
354
|
"apps/demo/ui/C.tsx",
|
|
356
355
|
"apps/demo/ui/I.tsx",
|
|
@@ -60,8 +60,7 @@ export class CsrDevPatcher {
|
|
|
60
60
|
): Promise<CsrDevPatchResult> {
|
|
61
61
|
const context = await this.#bundler.context();
|
|
62
62
|
if (!context) return { kind: "unchanged" };
|
|
63
|
-
const
|
|
64
|
-
const state = resident ?? (await this.#load());
|
|
63
|
+
const state = this.#state ?? (await this.#load());
|
|
65
64
|
if (!state) {
|
|
66
65
|
const manifest = await this.#bundler.writer.readJson<CsrDevManifest>(CSR_DEV_MANIFEST_FILE);
|
|
67
66
|
const reason = !manifest
|
|
@@ -75,10 +74,11 @@ export class CsrDevPatcher {
|
|
|
75
74
|
if (state.graph.configKey !== context.configKey)
|
|
76
75
|
return this.#handBack("the dev bundle config changed", generation, context);
|
|
77
76
|
const metadataFile = changedFiles.find((file) => this.#bundler.isMetadataFile(file));
|
|
78
|
-
// `lib/useClient.ts`
|
|
77
|
+
// `lib/useClient.ts` and `lib/usePage.ts` inline signal and dictionary metadata through macros at build time.
|
|
79
78
|
if (metadataFile) return this.#handBack(`${path.basename(metadataFile)} changed`, generation, context);
|
|
80
|
-
//?
|
|
81
|
-
|
|
79
|
+
//? One held in memory too: the builder outlives a metadata save, so a save that reached this registry through no
|
|
80
|
+
//? changed-file list would otherwise last as long as the builder. The stat of each file costs under a millisecond.
|
|
81
|
+
if (state.graph.metadata !== (await this.#bundler.metadataFingerprint()))
|
|
82
82
|
return this.#handBack("signal or dictionary metadata changed since the registry was built", generation, context);
|
|
83
83
|
this.#state = this.#resident ? state : null;
|
|
84
84
|
//? Not over a module whose factory file is missing: this patch compiles it, and its commit writes app.js whole.
|
|
@@ -110,6 +110,8 @@ export class CsrDevPatcher {
|
|
|
110
110
|
const forgotten = this.#forgetDeletedModules(state, present);
|
|
111
111
|
const changed = onlyRoots ? new Set<string>() : await this.#changedModules(graph, changedFiles, present);
|
|
112
112
|
const restamped = onlyRoots ? null : await this.#renarrowed(context, graph, changedFiles, changed);
|
|
113
|
+
const routeTable = onlyRoots ? undefined : await this.#rerouted(context, graph, changed);
|
|
114
|
+
for (const id of CsrDevPatcher.#extendingAppStores(context, graph, changed)) changed.add(id);
|
|
113
115
|
for (const id of this.#withoutFactory(state, present)) changed.add(id);
|
|
114
116
|
for (const file of entries.changed) changed.add(paths.idOf(file));
|
|
115
117
|
const rootFiles = [...Object.values(entries.files), ...roots.filter((file) => fs.existsSync(file))];
|
|
@@ -124,6 +126,7 @@ export class CsrDevPatcher {
|
|
|
124
126
|
if (changed.size === 0) {
|
|
125
127
|
//? No importer moved (none compiles), so the restamped barrels already hold.
|
|
126
128
|
if (restamped) graph.barrels = { ...graph.barrels, ...restamped };
|
|
129
|
+
if (routeTable !== undefined) graph.routeTable = routeTable;
|
|
127
130
|
if (carried.length === 0) return { kind: "unchanged" };
|
|
128
131
|
return await this.#retryCarried(context, state, carried, { announce, allowWholeAppBuilds });
|
|
129
132
|
}
|
|
@@ -161,12 +164,7 @@ export class CsrDevPatcher {
|
|
|
161
164
|
await writer.writeJson("graph.json", graph);
|
|
162
165
|
throw error;
|
|
163
166
|
}
|
|
164
|
-
const refusal =
|
|
165
|
-
result.refusedVendors.length > 0
|
|
166
|
-
? "an npm module joined the graph"
|
|
167
|
-
: result.unresolved.length > 0
|
|
168
|
-
? `a new import needs the resolution build: ${result.unresolved[0]}`
|
|
169
|
-
: null;
|
|
167
|
+
const refusal = CsrDevPatcher.#refusalOf(result);
|
|
170
168
|
if (refusal) {
|
|
171
169
|
//? The entry files are already rewritten, so the worker would see them unchanged and patch a moved route table:
|
|
172
170
|
//? a graph whose entries name none makes it reload instead.
|
|
@@ -192,6 +190,7 @@ export class CsrDevPatcher {
|
|
|
192
190
|
}
|
|
193
191
|
graph.pending = graph.pending.filter((id) => !orphans.includes(id));
|
|
194
192
|
this.#bundler.merge(graph, resolver, compiled, { ...restamped, ...result.barrels });
|
|
193
|
+
if (routeTable !== undefined) graph.routeTable = routeTable;
|
|
195
194
|
if (!this.#resident) delete graph.failed;
|
|
196
195
|
for (const module of compiled) this.#delegated.delete(module.id);
|
|
197
196
|
graph.entries = entryIds;
|
|
@@ -261,6 +260,11 @@ export class CsrDevPatcher {
|
|
|
261
260
|
return retried.kind === "delegate" ? retried : outcome;
|
|
262
261
|
}
|
|
263
262
|
|
|
263
|
+
static #refusalOf(result: CsrDevCompileResult): string | null {
|
|
264
|
+
if (result.refusedVendors.length > 0) return "an npm module joined the graph";
|
|
265
|
+
return result.unresolved.length > 0 ? `a new import needs the resolution build: ${result.unresolved[0]}` : null;
|
|
266
|
+
}
|
|
267
|
+
|
|
264
268
|
//? Compiled apart from the save: a new root that failed to compile, and that no module imports, must not fail every
|
|
265
269
|
//? later save's round with it. Its error still reaches the overlay (this throws after the save's patch went out).
|
|
266
270
|
async #retryCarried(
|
|
@@ -540,6 +544,28 @@ export class CsrDevPatcher {
|
|
|
540
544
|
return barrels;
|
|
541
545
|
}
|
|
542
546
|
|
|
547
|
+
//? A store, signal or constant save can move a name to another module, or make one known: a module whose own text
|
|
548
|
+
//? did not change may then need other pieces. Each module the route runtime rewrote is rewritten again, and compiles
|
|
549
|
+
//? when it comes out different. The digest is recorded like a barrel stamp, with the compile that follows.
|
|
550
|
+
async #rerouted(context: CsrDevContext, graph: CsrDevGraph, changed: Set<string>): Promise<string | undefined> {
|
|
551
|
+
const { routeRuntime } = context;
|
|
552
|
+
if (!routeRuntime || graph.routeTable === routeRuntime.digest) return undefined;
|
|
553
|
+
const { paths } = this.#bundler;
|
|
554
|
+
for (const [id, module] of Object.entries(graph.modules)) {
|
|
555
|
+
if (!module.routed || changed.has(id)) continue;
|
|
556
|
+
const file = paths.fileOf(id);
|
|
557
|
+
if (!fs.existsSync(file)) continue;
|
|
558
|
+
if (routeRuntime.transform(await Bun.file(file).text(), file)?.stamp !== module.routed) changed.add(id);
|
|
559
|
+
}
|
|
560
|
+
return routeRuntime.digest;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
static #extendingAppStores(context: CsrDevContext, graph: CsrDevGraph, changed: Set<string>): string[] {
|
|
564
|
+
const { routeRuntime } = context;
|
|
565
|
+
if (!routeRuntime) return [];
|
|
566
|
+
return [...changed].flatMap((id) => routeRuntime.appStoresAfter(id, (module) => graph.modules[module]?.deps));
|
|
567
|
+
}
|
|
568
|
+
|
|
543
569
|
static #remember(code: CsrDevCode, compiled: CsrDevCompileResult["modules"]) {
|
|
544
570
|
for (const module of compiled) {
|
|
545
571
|
if (module.vendor) continue;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PageEntry } from "../artifact/implicitRootLayout";
|
|
2
|
+
import type { DevRouteRuntime } from "./devRouteRuntime";
|
|
2
3
|
|
|
3
4
|
export interface CsrDevNarrowedImport {
|
|
4
5
|
names: string[];
|
|
@@ -19,6 +20,7 @@ export interface CsrDevGraphModule {
|
|
|
19
20
|
deps: string[];
|
|
20
21
|
helpers?: string;
|
|
21
22
|
narrowed?: Record<string, CsrDevNarrowedImport>;
|
|
23
|
+
routed?: string;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export interface CsrDevGraph {
|
|
@@ -36,6 +38,8 @@ export interface CsrDevGraph {
|
|
|
36
38
|
/** The stamp of the signal and dictionary sources the last whole build inlined; see `RegistryMetadataFingerprint`. */
|
|
37
39
|
metadata?: string;
|
|
38
40
|
barrels?: Record<string, CsrDevBarrelStamp>;
|
|
41
|
+
/** The `DevRouteRuntime` digest every module's `routed` stamp was taken under. */
|
|
42
|
+
routeTable?: string;
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
export interface CsrDevContext {
|
|
@@ -50,6 +54,10 @@ export interface CsrDevContext {
|
|
|
50
54
|
/** Bare specifiers the page already loads (an SSR page's import map): required as `vendor:<specifier>`, not compiled. */
|
|
51
55
|
externals?: readonly string[];
|
|
52
56
|
barrelImports?: readonly string[];
|
|
57
|
+
/** What `akanjs/ui/modelRuntime` holds instead of its empty source, when the bootstrap loads only the page runtime. */
|
|
58
|
+
modelRuntime?: string;
|
|
59
|
+
/** Where pages load per module: what each client module imports, as the production build decides it. */
|
|
60
|
+
routeRuntime?: DevRouteRuntime;
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
export interface CsrDevSharedHelpers {
|
|
@@ -68,6 +76,7 @@ export interface CsrDevCompiledModule {
|
|
|
68
76
|
mtimeMs: number;
|
|
69
77
|
hash: string;
|
|
70
78
|
narrowed?: Record<string, CsrDevNarrowedImport>;
|
|
79
|
+
routed?: string;
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
/** Module factories by id and helper definitions by hash, kept in memory so app.js is written without a pass over the disk. */
|