@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
|
@@ -95,3 +95,87 @@ describe("PagesBundleBuilder.transformServerUseClientFetchSource", () => {
|
|
|
95
95
|
}
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
|
+
|
|
99
|
+
describe("PagesBundleBuilder on the generated layout with lib/usePage.ts", () => {
|
|
100
|
+
const emptyBuild = "const fetchProto = FetchClient.build<typeof signal>({}, {});";
|
|
101
|
+
const generatedPage = (fetchProtoLine = emptyBuild) =>
|
|
102
|
+
[
|
|
103
|
+
'import { makePageProto, registerClientRuntime } from "akanjs/client";',
|
|
104
|
+
'import { FetchClient } from "akanjs/fetch";',
|
|
105
|
+
'import { getAllDictionary } from "./dict" with { type: "macro" };',
|
|
106
|
+
'import type * as dict from "./dict";',
|
|
107
|
+
'import type * as signal from "./sig";',
|
|
108
|
+
"",
|
|
109
|
+
'const dictionary = process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? getAllDictionary() : {};',
|
|
110
|
+
"const pageProto = makePageProto<typeof dict>(dictionary);",
|
|
111
|
+
fetchProtoLine,
|
|
112
|
+
'export const runtime = registerClientRuntime({ ...pageProto, ...fetchProto }, { scope: "app" });',
|
|
113
|
+
"",
|
|
114
|
+
"export const { msg, Err, usePage, sig, fetch } = runtime;",
|
|
115
|
+
"",
|
|
116
|
+
].join("\n");
|
|
117
|
+
const generatedUseClientOnPage = (lines: { importLine?: string; signalArg?: string } = {}) =>
|
|
118
|
+
[
|
|
119
|
+
'import { FetchClient } from "akanjs/fetch";',
|
|
120
|
+
'import * as cnst from "./cnst";',
|
|
121
|
+
'import { fetch as pageFetch, sig as pageSig } from "./usePage";',
|
|
122
|
+
lines.importLine ?? macroImport,
|
|
123
|
+
'import type * as signal from "./sig";',
|
|
124
|
+
"",
|
|
125
|
+
`Object.assign(pageSig, FetchClient.build<typeof signal>(cnst, ${lines.signalArg ?? "getSerializedSignal()"}, { base: pageFetch }).sig);`,
|
|
126
|
+
"",
|
|
127
|
+
"export const fetch = pageFetch;",
|
|
128
|
+
"export const sig = pageSig;",
|
|
129
|
+
'export { Err, msg, runtime, usePage } from "./usePage";',
|
|
130
|
+
"",
|
|
131
|
+
].join("\n");
|
|
132
|
+
|
|
133
|
+
test("builds usePage.ts's client onto the live server fetch, so a server render calls what it calls today", () => {
|
|
134
|
+
expect(PagesBundleBuilder.transformServerPageFetchSource(generatedPage())).toBe(
|
|
135
|
+
`${serverImport}\n${generatedPage("const fetchProto = FetchClient.build<typeof signal>({}, {}, { base: serverFetch });")}`,
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("applies the server fetch's own signal in useClient.ts instead of the signal macro", () => {
|
|
140
|
+
expect(transform(generatedUseClientOnPage())).toBe(
|
|
141
|
+
generatedUseClientOnPage({ importLine: serverImport, signalArg: "serverFetch.serializedSignal" }),
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("leaves a usePage.ts or useClient.ts it does not recognise unchanged", () => {
|
|
146
|
+
const withDescriptors = generatedPage("const fetchProto = FetchClient.build<typeof signal>(cnst, {});");
|
|
147
|
+
expect(PagesBundleBuilder.transformServerPageFetchSource(withDescriptors)).toBe(withDescriptors);
|
|
148
|
+
const commented = generatedPage(`// ${emptyBuild}`);
|
|
149
|
+
expect(PagesBundleBuilder.transformServerPageFetchSource(commented)).toBe(commented);
|
|
150
|
+
const withoutMacroImport = generatedUseClientOnPage({ importLine: 'import { getSerializedSignal } from "./sig";' });
|
|
151
|
+
expect(transform(withoutMacroImport)).toBe(withoutMacroImport);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("PagesBundleBuilder on a generated lib/__client fetch piece", () => {
|
|
156
|
+
const pieceMacroImport = `import { getSerializedSignalOf } from "../sig" with { type: "macro" };`;
|
|
157
|
+
const generatedPiece = (importLine = pieceMacroImport) =>
|
|
158
|
+
[
|
|
159
|
+
'import { FetchClient } from "akanjs/fetch";',
|
|
160
|
+
'import * as cnst from "../cnst";',
|
|
161
|
+
'import { fetch, sig } from "../usePage";',
|
|
162
|
+
importLine,
|
|
163
|
+
'import type * as signal from "../sig";',
|
|
164
|
+
"",
|
|
165
|
+
'Object.assign(sig, FetchClient.build<typeof signal>(cnst, getSerializedSignalOf("memo"), { base: fetch }).sig);',
|
|
166
|
+
"",
|
|
167
|
+
].join("\n");
|
|
168
|
+
|
|
169
|
+
test("reads the module's descriptors from the live server signal instead of the build-time macro", () => {
|
|
170
|
+
expect(PagesBundleBuilder.transformServerClientPieceSource(generatedPiece())).toBe(
|
|
171
|
+
generatedPiece('import { getSerializedSignalOf } from "../sig";'),
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("leaves a piece it does not recognise unchanged", () => {
|
|
176
|
+
const commented = generatedPiece(`// ${pieceMacroImport}`);
|
|
177
|
+
expect(PagesBundleBuilder.transformServerClientPieceSource(commented)).toBe(commented);
|
|
178
|
+
const otherMacro = generatedPiece(`import { getSerializedSignal } from "../sig" with { type: "macro" };`);
|
|
179
|
+
expect(PagesBundleBuilder.transformServerClientPieceSource(otherMacro)).toBe(otherMacro);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
@@ -171,9 +171,15 @@ export class PagesBundleBuilder {
|
|
|
171
171
|
return {
|
|
172
172
|
name: "akan-server-use-client-fetch",
|
|
173
173
|
setup(build) {
|
|
174
|
-
|
|
174
|
+
const filter = /[/\\]lib[/\\](?:useClient|usePage|__client[/\\][^/\\]+\.fetch)\.(ts|tsx|js|jsx)$/;
|
|
175
|
+
build.onLoad({ filter }, async (args) => {
|
|
175
176
|
const source = await Bun.file(args.path).text();
|
|
176
|
-
const transformed =
|
|
177
|
+
const transformed =
|
|
178
|
+
path.basename(path.dirname(args.path)) === "__client"
|
|
179
|
+
? PagesBundleBuilder.transformServerClientPieceSource(source)
|
|
180
|
+
: path.basename(args.path).startsWith("usePage.")
|
|
181
|
+
? PagesBundleBuilder.transformServerPageFetchSource(source)
|
|
182
|
+
: PagesBundleBuilder.transformServerUseClientFetchSource(source);
|
|
177
183
|
if (transformed === source) return undefined;
|
|
178
184
|
return { contents: transformed, loader: loaderFor(args.path) };
|
|
179
185
|
});
|
|
@@ -200,12 +206,47 @@ export class PagesBundleBuilder {
|
|
|
200
206
|
end: fetchProtoEnd.end,
|
|
201
207
|
text: "const fetchProto = FetchClient.build<typeof signal>(cnst, serverFetch.serializedSignal, { base: serverFetch });",
|
|
202
208
|
});
|
|
209
|
+
const macroCallAt =
|
|
210
|
+
fetchProtoAt === -1 && importAt !== -1
|
|
211
|
+
? PagesBundleBuilder.#indexOfTokens(tokens, PagesBundleBuilder.#macroCallTokens)
|
|
212
|
+
: -1;
|
|
213
|
+
if (macroCallAt !== -1)
|
|
214
|
+
edits.push({
|
|
215
|
+
start: tokens[macroCallAt].start,
|
|
216
|
+
end: tokens[macroCallAt + PagesBundleBuilder.#macroCallTokens.length - 1].end,
|
|
217
|
+
text: "serverFetch.serializedSignal",
|
|
218
|
+
});
|
|
203
219
|
let transformed = source;
|
|
204
220
|
for (const { start, end, text } of edits.sort((a, b) => b.start - a.start))
|
|
205
221
|
transformed = transformed.slice(0, start) + text + transformed.slice(end);
|
|
206
222
|
return transformed;
|
|
207
223
|
}
|
|
208
224
|
|
|
225
|
+
//? A piece reads its descriptors from the live server signal at render time instead of inlining them at build time.
|
|
226
|
+
static transformServerClientPieceSource(source: string): string {
|
|
227
|
+
if (!source.includes(`with { type: "macro" }`)) return source;
|
|
228
|
+
const tokens = PagesBundleBuilder.#tokenize(source);
|
|
229
|
+
const at = PagesBundleBuilder.#indexOfTokens(tokens, PagesBundleBuilder.#pieceMacroImportTokens);
|
|
230
|
+
if (at === -1) return source;
|
|
231
|
+
const end = tokens[at + PagesBundleBuilder.#pieceMacroImportTokens.length - 1].end;
|
|
232
|
+
return `${source.slice(0, tokens[at].start)}import { getSerializedSignalOf } from "../sig";${source.slice(end)}`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
static readonly #pieceMacroImportTokens = [
|
|
236
|
+
"import",
|
|
237
|
+
"{",
|
|
238
|
+
"getSerializedSignalOf",
|
|
239
|
+
"}",
|
|
240
|
+
"from",
|
|
241
|
+
'"../sig"',
|
|
242
|
+
"with",
|
|
243
|
+
"{",
|
|
244
|
+
"type",
|
|
245
|
+
":",
|
|
246
|
+
'"macro"',
|
|
247
|
+
"}",
|
|
248
|
+
";",
|
|
249
|
+
] as const;
|
|
209
250
|
static readonly #macroImportTokens = [
|
|
210
251
|
"import",
|
|
211
252
|
"{",
|
|
@@ -222,6 +263,41 @@ export class PagesBundleBuilder {
|
|
|
222
263
|
";",
|
|
223
264
|
] as const;
|
|
224
265
|
static readonly #fetchProtoTokens = ["const", "fetchProto", "=", "FetchClient", ".", "build", "<"] as const;
|
|
266
|
+
static readonly #macroCallTokens = ["getSerializedSignal", "(", ")"] as const;
|
|
267
|
+
static readonly #pageFetchProtoTokens = [
|
|
268
|
+
"const",
|
|
269
|
+
"fetchProto",
|
|
270
|
+
"=",
|
|
271
|
+
"FetchClient",
|
|
272
|
+
".",
|
|
273
|
+
"build",
|
|
274
|
+
"<",
|
|
275
|
+
"typeof",
|
|
276
|
+
"signal",
|
|
277
|
+
">",
|
|
278
|
+
"(",
|
|
279
|
+
"{",
|
|
280
|
+
"}",
|
|
281
|
+
",",
|
|
282
|
+
"{",
|
|
283
|
+
"}",
|
|
284
|
+
")",
|
|
285
|
+
";",
|
|
286
|
+
] as const;
|
|
287
|
+
|
|
288
|
+
static transformServerPageFetchSource(source: string): string {
|
|
289
|
+
if (!source.includes("FetchClient.build")) return source;
|
|
290
|
+
const tokens = PagesBundleBuilder.#tokenize(source);
|
|
291
|
+
const at = PagesBundleBuilder.#indexOfTokens(tokens, PagesBundleBuilder.#pageFetchProtoTokens);
|
|
292
|
+
if (at === -1) return source;
|
|
293
|
+
const end = tokens[at + PagesBundleBuilder.#pageFetchProtoTokens.length - 1].end;
|
|
294
|
+
return [
|
|
295
|
+
`import { fetch as serverFetch } from "./sig";\n`,
|
|
296
|
+
source.slice(0, tokens[at].start),
|
|
297
|
+
"const fetchProto = FetchClient.build<typeof signal>({}, {}, { base: serverFetch });",
|
|
298
|
+
source.slice(end),
|
|
299
|
+
].join("");
|
|
300
|
+
}
|
|
225
301
|
|
|
226
302
|
//? The scanner, not the parser: parsing recurses per nesting level and overflows the stack on a deep `{` run.
|
|
227
303
|
static #tokenize(source: string): TextSpan[] {
|
|
@@ -39,4 +39,26 @@ describe("precompressArtifacts", () => {
|
|
|
39
39
|
expect(await readFile(`${chunkPath}.br`)).toEqual(brotliAt(await readFile(chunkPath), 9));
|
|
40
40
|
expect(await Bun.file(`${dictPath}.gz`).exists()).toBe(true);
|
|
41
41
|
});
|
|
42
|
+
|
|
43
|
+
test("compresses a chunk under 1 KB too, and writes no sidecar that would be larger than its file", async () => {
|
|
44
|
+
const distPath = await tempRoot();
|
|
45
|
+
const artifactDir = path.join(distPath, ".akan/artifact");
|
|
46
|
+
const stubPath = path.join(artifactDir, "client/stub.js");
|
|
47
|
+
const tinyPath = path.join(artifactDir, "client/tiny.js");
|
|
48
|
+
await mkdir(path.dirname(stubPath), { recursive: true });
|
|
49
|
+
await writeFile(
|
|
50
|
+
stubPath,
|
|
51
|
+
'import{a as memoStore,b as memoList}from"./chunks/abc.js";export{memoStore,memoList};\n'.repeat(4),
|
|
52
|
+
);
|
|
53
|
+
await writeFile(tinyPath, "x");
|
|
54
|
+
const app = { dist: { cwdPath: distPath }, verbose: () => undefined } as unknown as App;
|
|
55
|
+
|
|
56
|
+
expect((await precompressArtifacts(app)).files).toBe(1);
|
|
57
|
+
const stubBytes = await readFile(stubPath);
|
|
58
|
+
expect(stubBytes.byteLength).toBeLessThan(1024);
|
|
59
|
+
expect(await readFile(`${stubPath}.br`)).toEqual(brotliAt(stubBytes, 9));
|
|
60
|
+
expect((await readFile(`${stubPath}.gz`)).byteLength).toBeLessThan(stubBytes.byteLength);
|
|
61
|
+
expect(await Bun.file(`${tinyPath}.br`).exists()).toBe(false);
|
|
62
|
+
expect(await Bun.file(`${tinyPath}.gz`).exists()).toBe(false);
|
|
63
|
+
});
|
|
42
64
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { promisify } from "node:util";
|
|
3
4
|
import zlib from "node:zlib";
|
|
4
5
|
import type { App } from "../commandDecorators";
|
|
5
6
|
import { FontPruner } from "./fontPruner";
|
|
6
7
|
|
|
7
8
|
const COMPRESSIBLE_EXTS = new Set([".css", ".html", ".js", ".json", ".svg"]);
|
|
8
|
-
const MIN_COMPRESS_BYTES = 1024;
|
|
9
9
|
// Brotli 11 is ~100x slower than gzip: worth it for the one CSS asset per basePath and one dictionary per locale, not
|
|
10
10
|
// for hundreds of JS chunks.
|
|
11
11
|
const MAX_BROTLI_QUALITY = 11;
|
|
@@ -59,11 +59,17 @@ async function precompressRoot(
|
|
|
59
59
|
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer;
|
|
60
60
|
const gz = Bun.gzipSync(buffer, { level: GZIP_LEVEL });
|
|
61
61
|
const br = brotliCompress(buffer, brotliQuality ?? brotliQualityOf(path.extname(filePath).toLowerCase()));
|
|
62
|
-
|
|
62
|
+
//? No 1 KB floor, unlike a response compressed as it is sent: serving a sidecar costs nothing per request.
|
|
63
|
+
const smaller = [
|
|
64
|
+
{ ext: ".gz", encoded: gz },
|
|
65
|
+
{ ext: ".br", encoded: br },
|
|
66
|
+
].filter(({ encoded }) => encoded.byteLength < bytes.byteLength);
|
|
67
|
+
if (smaller.length === 0) continue;
|
|
68
|
+
await Promise.all(smaller.map(({ ext, encoded }) => Bun.write(`${filePath}${ext}`, encoded)));
|
|
63
69
|
result.files += 1;
|
|
64
70
|
result.inputBytes += bytes.byteLength;
|
|
65
|
-
result.outputBytes += gz.byteLength;
|
|
66
|
-
result.brotliBytes += br.byteLength;
|
|
71
|
+
result.outputBytes += Math.min(gz.byteLength, bytes.byteLength);
|
|
72
|
+
result.brotliBytes += Math.min(br.byteLength, bytes.byteLength);
|
|
67
73
|
}
|
|
68
74
|
}
|
|
69
75
|
|
|
@@ -73,13 +79,35 @@ export async function servedBrotliBytesOf(artifactDir: string, filePath: string)
|
|
|
73
79
|
const bytes = await Bun.file(filePath).bytes();
|
|
74
80
|
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer;
|
|
75
81
|
const quality = ROOT_BROTLI_QUALITY[root] ?? brotliQualityOf(path.extname(filePath).toLowerCase());
|
|
76
|
-
return brotliCompress(buffer, quality).byteLength;
|
|
82
|
+
return Math.min(bytes.byteLength, brotliCompress(buffer, quality).byteLength);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function chunkBrotliBytesOf(bytes: Uint8Array): number {
|
|
86
|
+
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer;
|
|
87
|
+
return Math.min(bytes.byteLength, brotliCompress(buffer, brotliQualityOf(".js")).byteLength);
|
|
77
88
|
}
|
|
78
89
|
|
|
79
90
|
function brotliQualityOf(ext: string): number {
|
|
80
91
|
return BROTLI_QUALITY_BY_EXT[ext as keyof typeof BROTLI_QUALITY_BY_EXT] ?? DEFAULT_BROTLI_QUALITY;
|
|
81
92
|
}
|
|
82
93
|
|
|
94
|
+
export function dictionaryBrotliBytesOf(source: string): number {
|
|
95
|
+
const bytes = new TextEncoder().encode(source);
|
|
96
|
+
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer;
|
|
97
|
+
return brotliCompress(buffer, ROOT_BROTLI_QUALITY.dict ?? MAX_BROTLI_QUALITY).byteLength;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//? What a browser downloads of a `dict/` file once this phase has run: its `.br`, or the file when that is no smaller.
|
|
101
|
+
export async function dictionaryServedBytesOf(source: string): Promise<number> {
|
|
102
|
+
const bytes = new TextEncoder().encode(source);
|
|
103
|
+
const params = {
|
|
104
|
+
[zlib.constants.BROTLI_PARAM_QUALITY]: ROOT_BROTLI_QUALITY.dict ?? MAX_BROTLI_QUALITY,
|
|
105
|
+
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: bytes.byteLength,
|
|
106
|
+
};
|
|
107
|
+
const encoded = await promisify(zlib.brotliCompress)(bytes, { params });
|
|
108
|
+
return Math.min(bytes.byteLength, encoded.byteLength);
|
|
109
|
+
}
|
|
110
|
+
|
|
83
111
|
function brotliCompress(buffer: ArrayBuffer, quality: number): Buffer {
|
|
84
112
|
return zlib.brotliCompressSync(buffer, {
|
|
85
113
|
params: {
|
|
@@ -92,7 +120,5 @@ function brotliCompress(buffer: ArrayBuffer, quality: number): Buffer {
|
|
|
92
120
|
async function shouldPrecompress(filePath: string): Promise<boolean> {
|
|
93
121
|
if (filePath.endsWith(".gz") || filePath.endsWith(".br")) return false;
|
|
94
122
|
if (!COMPRESSIBLE_EXTS.has(path.extname(filePath).toLowerCase())) return false;
|
|
95
|
-
|
|
96
|
-
if (!(await file.exists())) return false;
|
|
97
|
-
return file.size >= MIN_COMPRESS_BYTES;
|
|
123
|
+
return Bun.file(filePath).exists();
|
|
98
124
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
|
-
//* The sources `lib/useClient.ts`
|
|
5
|
-
//* records their stamp, so a builder that loads one built before a signal or dictionary save
|
|
6
|
-
//* process saw that save (a builder restarted for it never finishes the rebuild it started).
|
|
4
|
+
//* The sources `lib/useClient.ts` and `lib/usePage.ts` read through macros, which no registry graph lists as a
|
|
5
|
+
//* dependency. A registry records their stamp, so a builder that loads one built before a signal or dictionary save
|
|
6
|
+
//* rebuilds it, whichever process saw that save (a builder restarted for it never finishes the rebuild it started).
|
|
7
7
|
export class RegistryMetadataFingerprint {
|
|
8
8
|
static readonly #sources = new Bun.Glob("**/*.{signal,dictionary}.ts");
|
|
9
9
|
static readonly #libFiles = ["sig.ts", "dict.ts", "useClient.ts"];
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ExportReach, ReachedImport } from "../transforms/exportReach";
|
|
3
|
+
import type { DiscoverOptions, ScannedImport } from "./clientBuildTypes";
|
|
4
|
+
|
|
5
|
+
export interface RenderedFile {
|
|
6
|
+
isClientEntry: boolean;
|
|
7
|
+
imports: ScannedImport[];
|
|
8
|
+
/** Null for a module whose exports cannot be read. */
|
|
9
|
+
reach?: ExportReach | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RenderedGraph {
|
|
13
|
+
fileOf(file: string): Promise<RenderedFile | null>;
|
|
14
|
+
resolve(specifier: string, fromDir: string): Promise<string | null>;
|
|
15
|
+
/** Bumped when a file changed: an answer computed across a bump is not kept. */
|
|
16
|
+
epoch(): number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface ExportAsk {
|
|
20
|
+
file: string;
|
|
21
|
+
name: string;
|
|
22
|
+
how: "whole" | "always" | "named" | "starred";
|
|
23
|
+
key: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface AskAnswer {
|
|
27
|
+
isEntry: boolean;
|
|
28
|
+
whole: boolean;
|
|
29
|
+
next: ExportAsk[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type ImportsAs = NonNullable<DiscoverOptions["importsAs"]>;
|
|
33
|
+
|
|
34
|
+
interface RenderedWalk {
|
|
35
|
+
serverModules: string[];
|
|
36
|
+
within: string[];
|
|
37
|
+
importsAs?: ImportsAs;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The client entries a route can render. A server module asked for one export gives only what that export's
|
|
42
|
+
* declaration reaches, and every server module the route evaluates gives what its top-level statements reach.
|
|
43
|
+
*/
|
|
44
|
+
export class RenderedEntries {
|
|
45
|
+
#graph: RenderedGraph;
|
|
46
|
+
#answers = new Map<string, AskAnswer>();
|
|
47
|
+
//? Keyed by a walk's `importsAs`: an ask's answer under swapped imports holds only for walks swapping the same ones.
|
|
48
|
+
#swappedAnswers = new WeakMap<ImportsAs, Map<string, AskAnswer>>();
|
|
49
|
+
|
|
50
|
+
constructor(graph: RenderedGraph) {
|
|
51
|
+
this.#graph = graph;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
forget(): void {
|
|
55
|
+
this.#answers.clear();
|
|
56
|
+
this.#swappedAnswers = new WeakMap();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async of(seeds: string[], options: RenderedWalk): Promise<string[]> {
|
|
60
|
+
return [...(await this.asked(seeds, options)).keys()].sort();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//* The same entries with the export names the route's server modules ask of each: null where one asks for them all.
|
|
64
|
+
async asked(
|
|
65
|
+
seeds: string[],
|
|
66
|
+
{ serverModules, within, importsAs }: RenderedWalk,
|
|
67
|
+
): Promise<Map<string, string[] | null>> {
|
|
68
|
+
const answers = importsAs ? this.#answersUnder(importsAs) : this.#answers;
|
|
69
|
+
const reachable = new Set(within);
|
|
70
|
+
const entries = new Map<string, string[] | null>();
|
|
71
|
+
const seen = new Set<string>();
|
|
72
|
+
const whole = new Set<string>();
|
|
73
|
+
const queue = seeds.map((seed) => RenderedEntries.#ask(path.resolve(seed), "whole"));
|
|
74
|
+
for (const file of serverModules) queue.push(RenderedEntries.#ask(file, "always"));
|
|
75
|
+
for (const ask of queue) {
|
|
76
|
+
if (seen.has(ask.key) || whole.has(ask.file)) continue;
|
|
77
|
+
seen.add(ask.key);
|
|
78
|
+
const answer = answers.get(ask.key) ?? (await this.#answer(ask, answers, importsAs));
|
|
79
|
+
if (answer.isEntry) {
|
|
80
|
+
if (ask.how === "always" || !reachable.has(ask.file)) continue;
|
|
81
|
+
const names = entries.get(ask.file);
|
|
82
|
+
if (ask.how === "whole") entries.set(ask.file, null);
|
|
83
|
+
else if (names === undefined) entries.set(ask.file, [ask.name]);
|
|
84
|
+
else if (names && !names.includes(ask.name)) names.push(ask.name);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (answer.whole) whole.add(ask.file);
|
|
88
|
+
for (const next of answer.next) if (!seen.has(next.key) && !whole.has(next.file)) queue.push(next);
|
|
89
|
+
}
|
|
90
|
+
return entries;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
#answersUnder(importsAs: ImportsAs): Map<string, AskAnswer> {
|
|
94
|
+
const answers = this.#swappedAnswers.get(importsAs) ?? new Map<string, AskAnswer>();
|
|
95
|
+
this.#swappedAnswers.set(importsAs, answers);
|
|
96
|
+
return answers;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async #answer(ask: ExportAsk, answers: Map<string, AskAnswer>, importsAs?: ImportsAs): Promise<AskAnswer> {
|
|
100
|
+
const epoch = this.#graph.epoch();
|
|
101
|
+
const answer = await this.#answerOf(ask, importsAs);
|
|
102
|
+
if (epoch === this.#graph.epoch()) answers.set(ask.key, answer);
|
|
103
|
+
return answer;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async #answerOf(ask: ExportAsk, importsAs?: ImportsAs): Promise<AskAnswer> {
|
|
107
|
+
const facts = await this.#graph.fileOf(ask.file);
|
|
108
|
+
if (!facts) return { isEntry: false, whole: false, next: [] };
|
|
109
|
+
if (facts.isClientEntry) return { isEntry: true, whole: false, next: [] };
|
|
110
|
+
const reached = RenderedEntries.#reachedBy(ask, facts);
|
|
111
|
+
const swaps = importsAs?.get(ask.file);
|
|
112
|
+
const next: ExportAsk[] = [];
|
|
113
|
+
for (const { specifier, names } of reached.imports) {
|
|
114
|
+
const swapped = swaps?.get(specifier);
|
|
115
|
+
const spec = swapped === undefined ? specifier : swapped;
|
|
116
|
+
if (!spec) continue;
|
|
117
|
+
const resolved = await this.#graph.resolve(spec, path.dirname(ask.file));
|
|
118
|
+
if (!resolved) continue;
|
|
119
|
+
const file = path.resolve(resolved);
|
|
120
|
+
if (names === null) next.push(RenderedEntries.#ask(file, "whole"));
|
|
121
|
+
else for (const name of names) next.push(RenderedEntries.#ask(file, reached.starred ? "starred" : "named", name));
|
|
122
|
+
}
|
|
123
|
+
return { isEntry: false, whole: reached.whole ?? false, next };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//? A name asked through `export *` that the target does not hold is another target's, so it reaches nothing here.
|
|
127
|
+
static #reachedBy(
|
|
128
|
+
{ name, how }: ExportAsk,
|
|
129
|
+
{ reach, imports }: RenderedFile,
|
|
130
|
+
): { imports: ReachedImport[]; whole?: boolean; starred?: boolean } {
|
|
131
|
+
if (!reach) return { imports: imports.map((imported) => ({ specifier: imported.path, names: null })), whole: true };
|
|
132
|
+
if (how === "whole") return { imports: reach.whole(), whole: true };
|
|
133
|
+
if (how === "always") return { imports: reach.always() };
|
|
134
|
+
const reached = reach.of(name);
|
|
135
|
+
if (reached.known) return { imports: reached.imports };
|
|
136
|
+
if (reached.stars.length > 0)
|
|
137
|
+
return { imports: reached.stars.map((specifier) => ({ specifier, names: [name] })), starred: true };
|
|
138
|
+
return how === "starred" ? { imports: [] } : { imports: reach.whole(), whole: true };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static #ask(file: string, how: ExportAsk["how"], name = ""): ExportAsk {
|
|
142
|
+
return { file, name, how, key: `${file}\0${how}\0${name}` };
|
|
143
|
+
}
|
|
144
|
+
}
|