@akanjs/devkit 3.3.0-rc.8 → 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 -2903
- 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,163 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import type { BunPlugin } from "bun";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
import { VendorNarrowing } from "./vendorNarrowing";
|
|
6
|
+
import { VENDOR_SPECIFIERS, type VendorSpecifier } from "./vendorSpecifiers";
|
|
7
|
+
|
|
8
|
+
const scriptExtensions = [".ts", ".tsx", ".js", ".jsx"];
|
|
9
|
+
//? Only the vendor a page loaded twice: a file of another vendor reached by its path stays in the build, as before.
|
|
10
|
+
const fileVendors: readonly VendorSpecifier[] = ["akanjs/client"];
|
|
11
|
+
|
|
12
|
+
//? A route build bundles a file of a vendor package reached by its path, beside the copy the vendor carries and the
|
|
13
|
+
//? state that copy holds; a file the vendor's barrel re-exports whole, under the same names, comes from the vendor.
|
|
14
|
+
export class VendorFileImports {
|
|
15
|
+
readonly specifiers: readonly VendorSpecifier[];
|
|
16
|
+
readonly #akanjsRoots: readonly string[];
|
|
17
|
+
readonly #specifierByModule: ReadonlyMap<string, VendorSpecifier>;
|
|
18
|
+
readonly #realDirs = new Map<string, string>();
|
|
19
|
+
|
|
20
|
+
static async of(workspaceRoot: string): Promise<VendorFileImports> {
|
|
21
|
+
const akanServerPath = await VendorFileImports.#akanServerPath(workspaceRoot);
|
|
22
|
+
return akanServerPath
|
|
23
|
+
? new VendorFileImports(path.dirname(akanServerPath), VendorFileImports.#shippedIn(akanServerPath))
|
|
24
|
+
: new VendorFileImports(null, VENDOR_SPECIFIERS);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static async specifiersIn(workspaceRoot: string): Promise<readonly VendorSpecifier[]> {
|
|
28
|
+
const akanServerPath = await VendorFileImports.#akanServerPath(workspaceRoot);
|
|
29
|
+
return akanServerPath ? VendorFileImports.#shippedIn(akanServerPath) : VENDOR_SPECIFIERS;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//? Only the vendors this akanjs ships an entry for: an older one has no `akanjs/client` vendor to import from.
|
|
33
|
+
static #shippedIn(akanServerPath: string): VendorSpecifier[] {
|
|
34
|
+
return VendorNarrowing.entriesIn(akanServerPath).map(({ specifier }) => specifier);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static async #akanServerPath(workspaceRoot: string): Promise<string | null> {
|
|
38
|
+
try {
|
|
39
|
+
return await VendorNarrowing.akanServerPath(workspaceRoot);
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
constructor(akanjsRoot: string | null, specifiers: readonly VendorSpecifier[]) {
|
|
46
|
+
this.specifiers = specifiers;
|
|
47
|
+
this.#akanjsRoots = akanjsRoot ? [...new Set([path.resolve(akanjsRoot), fs.realpathSync(akanjsRoot)])] : [];
|
|
48
|
+
this.#specifierByModule = akanjsRoot ? this.#mapModules(akanjsRoot) : new Map();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#mapModules(akanjsRoot: string): Map<string, VendorSpecifier> {
|
|
52
|
+
const specifierByModule = new Map<string, VendorSpecifier>();
|
|
53
|
+
const packaged = this.specifiers.filter((specifier) => fileVendors.includes(specifier));
|
|
54
|
+
for (const specifier of packaged) {
|
|
55
|
+
const barrel = VendorFileImports.#fileOf(path.join(akanjsRoot, specifier.slice("akanjs/".length)));
|
|
56
|
+
if (!barrel) continue;
|
|
57
|
+
for (const file of [barrel, ...VendorFileImports.wholeReexports(barrel)])
|
|
58
|
+
for (const root of this.#akanjsRoots)
|
|
59
|
+
for (const key of VendorFileImports.#moduleKeys(path.join(root, path.relative(akanjsRoot, file))))
|
|
60
|
+
if (!specifierByModule.has(key)) specifierByModule.set(key, specifier);
|
|
61
|
+
}
|
|
62
|
+
return specifierByModule;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
vendorOf(request: string, importer: string): VendorSpecifier | null {
|
|
66
|
+
const [akanjsRoot] = this.#akanjsRoots;
|
|
67
|
+
if (!akanjsRoot) return null;
|
|
68
|
+
const target = request.startsWith("akanjs/")
|
|
69
|
+
? path.join(akanjsRoot, request.slice("akanjs/".length))
|
|
70
|
+
: request.startsWith(".") || path.isAbsolute(request)
|
|
71
|
+
? path.resolve(path.dirname(importer), request)
|
|
72
|
+
: null;
|
|
73
|
+
if (!target) return null;
|
|
74
|
+
const extension = path.extname(target);
|
|
75
|
+
const module = scriptExtensions.includes(extension) ? target.slice(0, -extension.length) : target;
|
|
76
|
+
return this.#specifierByModule.get(module) ?? this.#specifierByModule.get(this.#realModule(module)) ?? null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//? A linked install reaches akanjs through a symlink, so an entry's path need not be the one Bun resolved.
|
|
80
|
+
#realModule(module: string): string {
|
|
81
|
+
const dir = path.dirname(module);
|
|
82
|
+
let realDir = this.#realDirs.get(dir);
|
|
83
|
+
if (realDir === undefined) {
|
|
84
|
+
realDir = fs.existsSync(dir) ? fs.realpathSync(dir) : dir;
|
|
85
|
+
this.#realDirs.set(dir, realDir);
|
|
86
|
+
}
|
|
87
|
+
return path.join(realDir, path.basename(module));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//? A dynamic import stays a lazy chunk of the route build: `import("akanjs/client")` would load the whole vendor.
|
|
91
|
+
plugin(): BunPlugin {
|
|
92
|
+
return {
|
|
93
|
+
name: "akan-vendor-file-imports",
|
|
94
|
+
setup: (build) => {
|
|
95
|
+
build.onResolve({ filter: /^(\.|\/|akanjs\/)/ }, (args) => {
|
|
96
|
+
if (args.kind !== "import-statement" || !args.importer) return undefined;
|
|
97
|
+
const specifier = this.vendorOf(args.path, args.importer);
|
|
98
|
+
return specifier && specifier !== args.path ? { path: specifier, external: true } : undefined;
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static wholeReexports(barrel: string): string[] {
|
|
105
|
+
const text = fs.readFileSync(barrel, "utf8");
|
|
106
|
+
const source = ts.createSourceFile(barrel, text, ts.ScriptTarget.Latest, false);
|
|
107
|
+
const sourceOfName = new Map<string, string | null>();
|
|
108
|
+
const starred = new Map<string, string | null>();
|
|
109
|
+
const files = new Set<string>();
|
|
110
|
+
for (const statement of source.statements) {
|
|
111
|
+
if (!ts.isExportDeclaration(statement) || statement.isTypeOnly) continue;
|
|
112
|
+
const { moduleSpecifier, exportClause } = statement;
|
|
113
|
+
if (!moduleSpecifier || !ts.isStringLiteral(moduleSpecifier)) continue;
|
|
114
|
+
const file = VendorFileImports.#fileOf(path.resolve(path.dirname(barrel), moduleSpecifier.text));
|
|
115
|
+
if (!file) continue;
|
|
116
|
+
files.add(file);
|
|
117
|
+
if (!exportClause) {
|
|
118
|
+
for (const name of VendorFileImports.#exportsOf(file) ?? [])
|
|
119
|
+
if (name !== "default") starred.set(name, starred.has(name) && starred.get(name) !== file ? null : file);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (!ts.isNamedExports(exportClause)) continue;
|
|
123
|
+
for (const element of exportClause.elements) {
|
|
124
|
+
if (element.isTypeOnly) continue;
|
|
125
|
+
const exported = element.name.text;
|
|
126
|
+
sourceOfName.set(exported, (element.propertyName ?? element.name).text === exported ? file : null);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//? A name the barrel exports itself shadows the one an `export *` brings in, so no starred file owns it.
|
|
130
|
+
for (const name of VendorFileImports.#scannedExports(barrel, text))
|
|
131
|
+
if (!sourceOfName.has(name)) sourceOfName.set(name, null);
|
|
132
|
+
const sourceOf = (name: string) => (sourceOfName.has(name) ? sourceOfName.get(name) : starred.get(name)) ?? null;
|
|
133
|
+
return [...files].filter((file) => {
|
|
134
|
+
const names = VendorFileImports.#exportsOf(file);
|
|
135
|
+
return !!names && names.length > 0 && names.every((name) => sourceOf(name) === file);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//? `null` for a file that re-exports with `export *`: its names are not all in its own source.
|
|
140
|
+
static #exportsOf(file: string): string[] | null {
|
|
141
|
+
const source = fs.readFileSync(file, "utf8");
|
|
142
|
+
if (/^\s*export\s*\*/m.test(source)) return null;
|
|
143
|
+
return VendorFileImports.#scannedExports(file, source);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static #scannedExports(file: string, source: string): string[] {
|
|
147
|
+
const loader = file.endsWith(".tsx") || file.endsWith(".jsx") ? "tsx" : "ts";
|
|
148
|
+
return new Bun.Transpiler({ loader }).scan(source).exports;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static #fileOf(base: string): string | null {
|
|
152
|
+
for (const candidate of [...scriptExtensions.map((ext) => `${base}${ext}`), path.join(base, "index.ts")])
|
|
153
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) return candidate;
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static #moduleKeys(file: string): string[] {
|
|
158
|
+
const withoutExtension = file.slice(0, -path.extname(file).length);
|
|
159
|
+
return path.basename(withoutExtension) === "index"
|
|
160
|
+
? [withoutExtension, path.dirname(withoutExtension)]
|
|
161
|
+
: [withoutExtension];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -9,6 +9,8 @@ const makeTempRoot = tempDirs("akan-vendor-narrowing-");
|
|
|
9
9
|
const akanjsRoot = path.resolve(import.meta.dir, "../../../akanjs");
|
|
10
10
|
const vendorFile = (name: string) => path.join(akanjsRoot, "server/vendor", `${name}.ts`);
|
|
11
11
|
const agentOnlyText = "path must be an internal path starting with /.";
|
|
12
|
+
const formFieldsText = "does not take null.";
|
|
13
|
+
const fieldToolsText = "Leaves every existing row untouched.";
|
|
12
14
|
|
|
13
15
|
const staticClosure = (absPath: string, seen = new Set<string>()): Set<string> => {
|
|
14
16
|
if (seen.has(absPath)) return seen;
|
|
@@ -42,7 +44,11 @@ const buildVendors = async (storeNames: string[], plugins: Awaited<ReturnType<Ve
|
|
|
42
44
|
if (!output) throw new Error(`no ${name}.js output`);
|
|
43
45
|
return output.path;
|
|
44
46
|
};
|
|
45
|
-
return {
|
|
47
|
+
return {
|
|
48
|
+
store: closureText(outputOf("store")),
|
|
49
|
+
agent: closureText(outputOf("agent")),
|
|
50
|
+
all: result.outputs.map((output) => readFileSync(output.path, "utf8")).join("\n"),
|
|
51
|
+
};
|
|
46
52
|
};
|
|
47
53
|
|
|
48
54
|
describe("VendorNarrowing", () => {
|
|
@@ -58,8 +64,9 @@ describe("VendorNarrowing", () => {
|
|
|
58
64
|
).toEqual({ "/v/akanjs-store.ts": ["st"], "/v/akanjs-base.ts": [] });
|
|
59
65
|
});
|
|
60
66
|
|
|
61
|
-
test("keeps
|
|
62
|
-
|
|
67
|
+
test("keeps each blankable re-export when a route imports one of its names, or reads the store whole", async () => {
|
|
68
|
+
const names = ["AgentContext", "FormFields", "st"];
|
|
69
|
+
expect(await new VendorNarrowing(akanjsRoot, { "akanjs/store": names }).plugins()).toEqual([]);
|
|
63
70
|
expect(await new VendorNarrowing(akanjsRoot, {}).plugins()).toEqual([]);
|
|
64
71
|
});
|
|
65
72
|
|
|
@@ -74,6 +81,29 @@ describe("VendorNarrowing", () => {
|
|
|
74
81
|
expect(agent).toContain(agentOnlyText);
|
|
75
82
|
}, 60_000);
|
|
76
83
|
|
|
84
|
+
test("a store vendor no route reads `FormFields` from loads the field tools only through a dynamic import", async () => {
|
|
85
|
+
const names = ["StoreRegistry", "store", "useFieldTool"];
|
|
86
|
+
const { store, all } = await buildVendors(
|
|
87
|
+
names,
|
|
88
|
+
await new VendorNarrowing(akanjsRoot, { "akanjs/store": names }).plugins(),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
expect(store).not.toContain(formFieldsText);
|
|
92
|
+
expect(store).not.toContain(fieldToolsText);
|
|
93
|
+
expect(all).toContain(fieldToolsText);
|
|
94
|
+
}, 60_000);
|
|
95
|
+
|
|
96
|
+
test("a route that names `FormFields` keeps it in the store vendor, and the field tools still load apart", async () => {
|
|
97
|
+
const names = ["FormFields", "StoreRegistry", "store"];
|
|
98
|
+
const { store } = await buildVendors(
|
|
99
|
+
names,
|
|
100
|
+
await new VendorNarrowing(akanjsRoot, { "akanjs/store": names }).plugins(),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
expect(store).toContain(formFieldsText);
|
|
104
|
+
expect(store).not.toContain(fieldToolsText);
|
|
105
|
+
}, 60_000);
|
|
106
|
+
|
|
77
107
|
test("without the blanking, the deprecated re-export drags the agent runtime into the store vendor", async () => {
|
|
78
108
|
const { store } = await buildVendors(["StoreRegistry", "store"], []);
|
|
79
109
|
|
|
@@ -95,6 +125,20 @@ describe("VendorNarrowing", () => {
|
|
|
95
125
|
);
|
|
96
126
|
});
|
|
97
127
|
|
|
128
|
+
test("an akanjs from before the lazy field tools has nothing there to blank but its deprecated re-export", async () => {
|
|
129
|
+
const root = await makeTempRoot();
|
|
130
|
+
await write(path.join(root, "store/deprecatedAgent.ts"), 'export { AgentContext } from "./agent";\n');
|
|
131
|
+
await write(path.join(root, "store/agentic/formFields.ts"), "export class FormFields {}\n");
|
|
132
|
+
|
|
133
|
+
const [plugin, ...rest] = await new VendorNarrowing(root, { "akanjs/store": ["st"] }).plugins();
|
|
134
|
+
const filters: RegExp[] = [];
|
|
135
|
+
void plugin?.setup({ onLoad: ({ filter }: { filter: RegExp }) => void filters.push(filter) } as never);
|
|
136
|
+
|
|
137
|
+
expect(rest).toEqual([]);
|
|
138
|
+
expect(filters.map((filter) => filter.test("/w/node_modules/akanjs/store/deprecatedAgent.ts"))).toEqual([true]);
|
|
139
|
+
expect(filters.map((filter) => filter.test("/w/node_modules/akanjs/store/agentic/formFields.ts"))).toEqual([false]);
|
|
140
|
+
});
|
|
141
|
+
|
|
98
142
|
test("an alias narrowed to no names still loads its entry, so the entry's side effects run", () => {
|
|
99
143
|
expect(ClientEntriesBundler.narrowedAliasSource("/v/akanjs-fetch.ts", [])).toBe(
|
|
100
144
|
`export {} from ${JSON.stringify(path.resolve("/v/akanjs-fetch.ts"))};\n`,
|
|
@@ -6,6 +6,10 @@ import { VENDOR_SPECIFIERS, type VendorSpecifier } from "./vendorSpecifiers";
|
|
|
6
6
|
//? Bun puts a module in the chunk of every entry that reaches it, read or not, so a deprecated re-export would keep
|
|
7
7
|
//? its target in a vendor every page loads; a narrowed build blanks it unless a route imports one of its names.
|
|
8
8
|
const deprecatedReexports: Partial<Record<VendorSpecifier, string>> = { "akanjs/store": "store/deprecatedAgent.ts" };
|
|
9
|
+
//? Blanked the same way, but kept out of the guard below: an akanjs older than the lazy field tools lacks the file.
|
|
10
|
+
const lazyReexports: Partial<Record<VendorSpecifier, string>> = {
|
|
11
|
+
"akanjs/store": "store/agentic/formFieldsReexport.ts",
|
|
12
|
+
};
|
|
9
13
|
|
|
10
14
|
export interface VendorEntry {
|
|
11
15
|
specifier: VendorSpecifier;
|
|
@@ -16,6 +20,34 @@ export class VendorNarrowing {
|
|
|
16
20
|
readonly #akanjsRoot: string;
|
|
17
21
|
readonly #vendorExports: Partial<Record<VendorSpecifier, readonly string[]>>;
|
|
18
22
|
|
|
23
|
+
static async akanServerPath(workspaceRoot: string): Promise<string> {
|
|
24
|
+
const candidates: string[] = [];
|
|
25
|
+
try {
|
|
26
|
+
candidates.push(path.dirname(Bun.resolveSync("akanjs/server", workspaceRoot)));
|
|
27
|
+
} catch {
|
|
28
|
+
// Source workspaces and bundled CLI execution have different resolution roots; try explicit candidates below.
|
|
29
|
+
}
|
|
30
|
+
candidates.push(
|
|
31
|
+
path.join(workspaceRoot, "pkgs/akanjs/server"),
|
|
32
|
+
path.join(workspaceRoot, "node_modules/akanjs/server"),
|
|
33
|
+
);
|
|
34
|
+
try {
|
|
35
|
+
candidates.push(path.dirname(Bun.resolveSync("akanjs/server", path.dirname(Bun.main))));
|
|
36
|
+
} catch {
|
|
37
|
+
// Published CLI installs may hoist dependencies differently; explicit Bun.main candidates cover that.
|
|
38
|
+
}
|
|
39
|
+
candidates.push(
|
|
40
|
+
path.join(path.dirname(Bun.main), "node_modules/akanjs/server"),
|
|
41
|
+
path.join(path.dirname(Bun.main), "../../akanjs/server"),
|
|
42
|
+
path.resolve(import.meta.dir, "../../server"),
|
|
43
|
+
path.resolve(import.meta.dir, "../server"),
|
|
44
|
+
);
|
|
45
|
+
for (const candidate of candidates) {
|
|
46
|
+
if (await Bun.file(path.join(candidate, "rscClient.tsx")).exists()) return candidate;
|
|
47
|
+
}
|
|
48
|
+
throw new Error(`[base-artifact] failed to locate akanjs/server; looked in: ${candidates.join(", ")}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
19
51
|
//? A devkit newer than the installed akanjs finds no agent vendor or deprecated re-export there, and builds that
|
|
20
52
|
//? akanjs's vendors whole, as the devkit it shipped with did.
|
|
21
53
|
static entriesIn(akanServerPath: string): VendorEntry[] {
|
|
@@ -42,9 +74,13 @@ export class VendorNarrowing {
|
|
|
42
74
|
|
|
43
75
|
async plugins(): Promise<BunPlugin[]> {
|
|
44
76
|
const blanked: string[] = [];
|
|
45
|
-
|
|
77
|
+
const reexports = [...Object.entries(deprecatedReexports), ...Object.entries(lazyReexports)] as [
|
|
78
|
+
VendorSpecifier,
|
|
79
|
+
string,
|
|
80
|
+
][];
|
|
81
|
+
for (const [specifier, file] of reexports) {
|
|
46
82
|
const used = this.#vendorExports[specifier];
|
|
47
|
-
if (!used) continue;
|
|
83
|
+
if (!used || !fs.existsSync(path.join(this.#akanjsRoot, file))) continue;
|
|
48
84
|
const source = await Bun.file(path.join(this.#akanjsRoot, file)).text();
|
|
49
85
|
const names = new Bun.Transpiler({ loader: "ts" }).scan(source).exports;
|
|
50
86
|
if (!names.some((name) => used.includes(name))) blanked.push(`akanjs/${file}`);
|
|
@@ -10,6 +10,7 @@ export const VENDOR_SPECIFIERS = [
|
|
|
10
10
|
"akanjs/store",
|
|
11
11
|
"akanjs/store/agent",
|
|
12
12
|
"akanjs/base",
|
|
13
|
+
"akanjs/client",
|
|
13
14
|
"akanjs/common",
|
|
14
15
|
"akanjs/constant",
|
|
15
16
|
"akanjs/fetch",
|
|
@@ -24,6 +25,7 @@ export const NARROWABLE_VENDOR_SPECIFIERS = [
|
|
|
24
25
|
"akanjs/store",
|
|
25
26
|
"akanjs/store/agent",
|
|
26
27
|
"akanjs/base",
|
|
28
|
+
"akanjs/client",
|
|
27
29
|
"akanjs/common",
|
|
28
30
|
"akanjs/constant",
|
|
29
31
|
"akanjs/fetch",
|
package/guideline/agentAssets.ts
CHANGED
|
@@ -54,7 +54,7 @@ export class AgentAssets {
|
|
|
54
54
|
"framework",
|
|
55
55
|
],
|
|
56
56
|
"akan-err": ["errorCodes"],
|
|
57
|
-
"akan-deps": [],
|
|
57
|
+
"akan-deps": ["syncRule"],
|
|
58
58
|
"akan-debug": [],
|
|
59
59
|
"akan-page": ["pageRule", "akanApi#imports", "akanApi#routes", "akanApi#app-config"],
|
|
60
60
|
"akan-query": ["queryRule"],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { Logger } from "akanjs/common";
|
|
3
|
-
import type { BuilderMessage, BuildPhase, HmrTrace } from "akanjs/server";
|
|
3
|
+
import type { BaseBuildArtifact, BuilderMessage, BuildPhase, HmrTrace } from "akanjs/server";
|
|
4
4
|
import { resolveDevCsrMode } from "akanjs/server/hmr/csrDevManifest";
|
|
5
5
|
import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
|
|
6
6
|
import { resolveSsrPageEntriesForApp } from "../artifact/implicitRootLayout";
|
|
@@ -202,8 +202,12 @@ class BuildBatch {
|
|
|
202
202
|
const pageEntries = await resolveSsrPageEntriesForApp(this.#app, await this.#app.getPageKeys());
|
|
203
203
|
const seedIndex = computeRouteSeedIndex(pageEntries);
|
|
204
204
|
const previousGraph = await ServerGraphFile.read(this.#request.artifactDir);
|
|
205
|
+
const dictionaries = this.#request.metadata
|
|
206
|
+
? await new SsrBaseArtifactBuilder(this.#app).buildDictionaries()
|
|
207
|
+
: null;
|
|
205
208
|
const next = await new PagesBundleBuilder(this.#app, "start", pageEntries).build();
|
|
206
209
|
await saveRouteSeedIndex(this.#request.artifactDir, seedIndex);
|
|
210
|
+
if (dictionaries) await this.#rewriteBaseArtifact(next, dictionaries);
|
|
207
211
|
const nextGraph = await ServerGraphFile.read(this.#request.artifactDir);
|
|
208
212
|
const serverTouched = await ServerGraphFile.touches(
|
|
209
213
|
previousGraph,
|
|
@@ -232,6 +236,28 @@ class BuildBatch {
|
|
|
232
236
|
}
|
|
233
237
|
}
|
|
234
238
|
|
|
239
|
+
//? Before `pages-updated` and the pages status: the dev host restarts the backend on that status, and the backend
|
|
240
|
+
//? reads this file once, at its boot.
|
|
241
|
+
async #rewriteBaseArtifact(
|
|
242
|
+
pages: { bundlePath: string; buildId: number },
|
|
243
|
+
{ assets, routes, groups }: Awaited<ReturnType<SsrBaseArtifactBuilder["buildDictionaries"]>>,
|
|
244
|
+
): Promise<void> {
|
|
245
|
+
const artifactPath = path.join(this.#request.artifactDir, "base-artifact.json");
|
|
246
|
+
const { dictRoutes, dictGroups, ...artifact } = (await Bun.file(artifactPath).json()) as BaseBuildArtifact;
|
|
247
|
+
await SsrBaseArtifactBuilder.writeArtifact(this.#request.artifactDir, {
|
|
248
|
+
...artifact,
|
|
249
|
+
cssAssets: this.#result.cssAssets ?? this.#request.cssAssets ?? artifact.cssAssets,
|
|
250
|
+
dictAssets: assets,
|
|
251
|
+
...(routes ? { dictRoutes: routes } : {}),
|
|
252
|
+
...(groups ? { dictGroups: groups } : {}),
|
|
253
|
+
pagesBundlePath: pages.bundlePath,
|
|
254
|
+
pagesBundleBuildId: pages.buildId,
|
|
255
|
+
});
|
|
256
|
+
this.#logger.verbose(
|
|
257
|
+
`base-artifact rewritten for ${this.#request.metadata?.length ?? 0} metadata file(s) buildId=${pages.buildId}`,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
235
261
|
async #buildCss(): Promise<void> {
|
|
236
262
|
const started = Date.now();
|
|
237
263
|
try {
|
|
@@ -20,6 +20,7 @@ export interface BuildBatchRequest {
|
|
|
20
20
|
cssAssets: PagesBatchCssAssets | null; // an unchanged compile skips the broadcast instead of busting hashes
|
|
21
21
|
artifactDir: string;
|
|
22
22
|
trace?: HmrTrace;
|
|
23
|
+
metadata?: string[]; // signal and dictionary saves no batch has built green yet; `pages` batches only
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export type BatchWork = Pick<BuildBatchRequest, "generation" | "needs" | "changedFiles" | "trace">;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import type { Logger } from "akanjs/common";
|
|
3
3
|
import type { ChangeBatch } from "akanjs/server";
|
|
4
|
+
import { runtimeMetadataFilesOf } from "../akanApp/devHostPolicy";
|
|
4
5
|
import type { App } from "../commandDecorators";
|
|
5
6
|
import type { PageRoot } from "../executors";
|
|
6
7
|
import { AutoImportSync } from "../frontendBuild/autoImportSync";
|
|
@@ -17,6 +18,7 @@ import type { BuilderLanes } from "./builderLanes";
|
|
|
17
18
|
import type { BatchJob, DiscoveryJob } from "./builderWorkQueue";
|
|
18
19
|
import type { CsrRegistry } from "./csrRegistry";
|
|
19
20
|
import { prepareDevWatchBatch } from "./devWatchBatch";
|
|
21
|
+
import type { PendingMetadata } from "./pendingMetadata";
|
|
20
22
|
import type { SsrRegistry } from "./ssrRegistry";
|
|
21
23
|
|
|
22
24
|
interface BuilderWatchParts {
|
|
@@ -25,6 +27,7 @@ interface BuilderWatchParts {
|
|
|
25
27
|
csr: CsrRegistry;
|
|
26
28
|
ssr: SsrRegistry;
|
|
27
29
|
graphPayloads: BuilderGraphPayloads;
|
|
30
|
+
metadata: PendingMetadata;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
interface BuilderWatchLinks {
|
|
@@ -39,6 +42,7 @@ export class BuilderWatch {
|
|
|
39
42
|
readonly #csr: CsrRegistry;
|
|
40
43
|
readonly #ssr: SsrRegistry;
|
|
41
44
|
readonly #graphPayloads: BuilderGraphPayloads;
|
|
45
|
+
readonly #metadata: PendingMetadata;
|
|
42
46
|
readonly #links: BuilderWatchLinks;
|
|
43
47
|
#changePlanner: DevChangePlanner;
|
|
44
48
|
#generatedIndexSync: DevGeneratedIndexSync;
|
|
@@ -46,13 +50,18 @@ export class BuilderWatch {
|
|
|
46
50
|
#watcher: HmrWatcher | null = null;
|
|
47
51
|
#barrelFailed = false;
|
|
48
52
|
|
|
49
|
-
constructor(
|
|
53
|
+
constructor(
|
|
54
|
+
app: App,
|
|
55
|
+
{ logger, lanes, csr, ssr, graphPayloads, metadata }: BuilderWatchParts,
|
|
56
|
+
links: BuilderWatchLinks,
|
|
57
|
+
) {
|
|
50
58
|
this.#app = app;
|
|
51
59
|
this.#logger = logger;
|
|
52
60
|
this.#lanes = lanes;
|
|
53
61
|
this.#csr = csr;
|
|
54
62
|
this.#ssr = ssr;
|
|
55
63
|
this.#graphPayloads = graphPayloads;
|
|
64
|
+
this.#metadata = metadata;
|
|
56
65
|
this.#links = links;
|
|
57
66
|
this.#changePlanner = new DevChangePlanner({ workspaceRoot: app.workspace.workspaceRoot });
|
|
58
67
|
this.#generatedIndexSync = new DevGeneratedIndexSync({ workspaceRoot: app.workspace.workspaceRoot });
|
|
@@ -131,6 +140,7 @@ export class BuilderWatch {
|
|
|
131
140
|
indexSync,
|
|
132
141
|
changePlanner: this.#changePlanner,
|
|
133
142
|
});
|
|
143
|
+
this.#metadata.note(runtimeMetadataFilesOf(devPlan), generation);
|
|
134
144
|
this.#logger.verbose(
|
|
135
145
|
`[hmr] batch generation=${generation} kinds=${kinds.join(",")} files=${files.length} generated=${indexSync.changedFiles.length} roles=${devPlan.roles.join(",") || "(none)"} actions=${devPlan.actions.join(",") || "(none)"}`,
|
|
136
146
|
);
|
|
@@ -645,6 +645,165 @@ else {
|
|
|
645
645
|
}
|
|
646
646
|
}, 60_000);
|
|
647
647
|
|
|
648
|
+
test("a route whose client entries an earlier route built still reads their dictionary groups, and one this builder never built loads the whole file", async () => {
|
|
649
|
+
const { root } = track(await createTempApp("demo", path.join(import.meta.dir, "..", "local")));
|
|
650
|
+
const appDir = path.join(root, "apps/demo");
|
|
651
|
+
await writeText(
|
|
652
|
+
path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
|
|
653
|
+
`const { generation, needs } = JSON.parse(process.argv[2]);
|
|
654
|
+
if (needs.includes("ssr")) await import(${JSON.stringify(path.join(import.meta.dir, "buildBatch.proc.ts"))});
|
|
655
|
+
else {
|
|
656
|
+
process.once("disconnect", () => {});
|
|
657
|
+
process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] } } });
|
|
658
|
+
}
|
|
659
|
+
`,
|
|
660
|
+
);
|
|
661
|
+
await writeText(path.join(appDir, "akan.config.ts"), "export default {};\n");
|
|
662
|
+
await writeText(path.join(appDir, "env/env.client.ts"), "export const env = {} as const;\n");
|
|
663
|
+
const pages = {
|
|
664
|
+
first: path.join(appDir, "page/_index.tsx"),
|
|
665
|
+
same: path.join(appDir, "page/same.tsx"),
|
|
666
|
+
more: path.join(appDir, "page/more.tsx"),
|
|
667
|
+
lone: path.join(appDir, "page/lone.tsx"),
|
|
668
|
+
};
|
|
669
|
+
await writeText(pages.lone, 'import { Lone } from "../ui/Lone";\nexport default Lone;\n');
|
|
670
|
+
await writeText(pages.first, 'import { Card } from "../ui/Card";\nexport default Card;\n');
|
|
671
|
+
await writeText(pages.same, 'import { Card } from "../ui/Card";\nexport default Card;\n');
|
|
672
|
+
await writeText(
|
|
673
|
+
pages.more,
|
|
674
|
+
'import { Card } from "../ui/Card";\nimport { Note } from "../ui/Note";\nexport default () => [Card, Note];\n',
|
|
675
|
+
);
|
|
676
|
+
const card = path.join(appDir, "ui/Card.tsx");
|
|
677
|
+
await writeText(card, '"use client";\nimport { Label } from "./Label";\nexport const Card = () => Label();\n');
|
|
678
|
+
await writeText(
|
|
679
|
+
path.join(appDir, "ui/Label.tsx"),
|
|
680
|
+
'declare const l: (key: string) => string;\nexport const Label = () => l("memo.title");\n',
|
|
681
|
+
);
|
|
682
|
+
await writeText(path.join(appDir, "ui/Note.tsx"), '"use client";\nexport const Note = () => null;\n');
|
|
683
|
+
const lone = path.join(appDir, "ui/Lone.tsx");
|
|
684
|
+
await writeText(lone, '"use client";\nexport const Lone = () => null;\n');
|
|
685
|
+
|
|
686
|
+
const messages: BuilderMessage[] = [];
|
|
687
|
+
const proc = Bun.spawn(["bun", path.join(import.meta.dir, "incrementalBuilder.proc.ts")], {
|
|
688
|
+
cwd: appDir,
|
|
689
|
+
env: {
|
|
690
|
+
...process.env,
|
|
691
|
+
AKAN_WORKSPACE_ROOT: root,
|
|
692
|
+
AKAN_PUBLIC_APP_NAME: "demo",
|
|
693
|
+
AKAN_PUBLIC_REPO_NAME: "repo",
|
|
694
|
+
AKAN_PUBLIC_SERVE_DOMAIN: "localhost",
|
|
695
|
+
AKAN_PUBLIC_ENV: "local",
|
|
696
|
+
AKAN_WATCH: "0",
|
|
697
|
+
},
|
|
698
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
699
|
+
serialization: "advanced",
|
|
700
|
+
ipc: (message: BuilderMessage) => {
|
|
701
|
+
messages.push(message);
|
|
702
|
+
},
|
|
703
|
+
});
|
|
704
|
+
const buildRoute = async (id: number, routeId: string, seed: string, knownEntries: string[]) => {
|
|
705
|
+
proc.send({ type: "build-route", id, routeId, seeds: [seed], knownEntries, generation: 3 } satisfies BuilderReq);
|
|
706
|
+
await until(proc, `build-route-res ${id}`, () =>
|
|
707
|
+
messages.some((message) => message.type === "build-route-res" && message.id === id),
|
|
708
|
+
);
|
|
709
|
+
const res = messages.find((message) => message.type === "build-route-res" && message.id === id);
|
|
710
|
+
if (res?.type !== "build-route-res" || !res.ok) throw new Error(`route ${routeId} did not build`);
|
|
711
|
+
return res.data;
|
|
712
|
+
};
|
|
713
|
+
try {
|
|
714
|
+
await until(proc, "boot-armed", () => messages.some((message) => message.type === "boot-armed"));
|
|
715
|
+
const first = await buildRoute(1, "page:/", pages.first, []);
|
|
716
|
+
expect(first.newEntries).toEqual([card]);
|
|
717
|
+
expect(first.dictionaryGroups).toEqual(["base", "memo"]);
|
|
718
|
+
expect((await buildRoute(2, "page:/more", pages.more, [card])).dictionaryGroups).toEqual(["base", "memo"]);
|
|
719
|
+
expect((await buildRoute(3, "page:/same", pages.same, [card])).dictionaryGroups).toEqual(["base", "memo"]);
|
|
720
|
+
expect((await buildRoute(4, "page:/lone", pages.lone, [lone])).dictionaryGroups).toBeNull();
|
|
721
|
+
} finally {
|
|
722
|
+
proc.kill();
|
|
723
|
+
await proc.exited;
|
|
724
|
+
}
|
|
725
|
+
}, 60_000);
|
|
726
|
+
|
|
727
|
+
test("a signal save rides every pages batch until one builds green, through the builder that saw it", async () => {
|
|
728
|
+
const { root } = track(await createTempApp("demo"));
|
|
729
|
+
const appDir = path.join(root, "apps/demo");
|
|
730
|
+
const ledger = path.join(root, "batches.log");
|
|
731
|
+
const tries = path.join(root, "metadata-tries");
|
|
732
|
+
// A stand-in batch: the first pages build carrying metadata fails, the second builds its pages but not its SSR
|
|
733
|
+
// registry, and every batch logs the metadata it carried.
|
|
734
|
+
await writeText(
|
|
735
|
+
path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
|
|
736
|
+
`import fs from "node:fs";
|
|
737
|
+
import path from "node:path";
|
|
738
|
+
const { generation, needs, metadata } = JSON.parse(process.argv[2]);
|
|
739
|
+
fs.appendFileSync(${JSON.stringify(ledger)}, needs.join(",") + " " + (metadata ?? []).map((file) => path.basename(file)).join(",") + "\\n");
|
|
740
|
+
const carried = needs.includes("pages") && !!metadata;
|
|
741
|
+
const tried = carried && fs.existsSync(${JSON.stringify(tries)}) ? fs.readFileSync(${JSON.stringify(tries)}, "utf8").length : 0;
|
|
742
|
+
if (carried) fs.appendFileSync(${JSON.stringify(tries)}, "x");
|
|
743
|
+
const errors = !carried ? {} : tried === 0 ? { pages: "the pages build is broken" } : tried === 1 ? { ssr: "the SSR registry is broken" } : {};
|
|
744
|
+
process.once("disconnect", () => {});
|
|
745
|
+
if (needs.includes("pages")) process.send({ type: "build-status", data: { generation, phase: "pages", ok: !errors.pages, files: [] } });
|
|
746
|
+
process.send({ type: "build-batch-result", data: { generation, errors, artifact: {}, optimizedFonts: { css: "", files: [] } } });
|
|
747
|
+
`,
|
|
748
|
+
);
|
|
749
|
+
const page = path.join(appDir, "page/_index.tsx");
|
|
750
|
+
const signal = path.join(appDir, "lib/demo/demo.signal.ts");
|
|
751
|
+
await writeText(page, "export default () => null;\n");
|
|
752
|
+
await writeText(signal, "export const signal = 0;\n");
|
|
753
|
+
await writeText(
|
|
754
|
+
path.join(appDir, "tsconfig.json"),
|
|
755
|
+
JSON.stringify({ compilerOptions: { target: "ESNext", paths: { "@apps/*": ["./apps/*"] } } }),
|
|
756
|
+
);
|
|
757
|
+
const messages: BuilderMessage[] = [];
|
|
758
|
+
const proc = Bun.spawn(["bun", path.join(import.meta.dir, "incrementalBuilder.proc.ts")], {
|
|
759
|
+
cwd: appDir,
|
|
760
|
+
env: {
|
|
761
|
+
...process.env,
|
|
762
|
+
AKAN_WORKSPACE_ROOT: root,
|
|
763
|
+
AKAN_PUBLIC_APP_NAME: "demo",
|
|
764
|
+
AKAN_PUBLIC_REPO_NAME: "repo",
|
|
765
|
+
AKAN_PUBLIC_SERVE_DOMAIN: "localhost",
|
|
766
|
+
AKAN_PUBLIC_ENV: "local",
|
|
767
|
+
AKAN_DEV_CSR_PATCHER: "off",
|
|
768
|
+
},
|
|
769
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
770
|
+
serialization: "advanced",
|
|
771
|
+
ipc: (message: BuilderMessage) => {
|
|
772
|
+
messages.push(message);
|
|
773
|
+
},
|
|
774
|
+
});
|
|
775
|
+
const pagesBatches = async () =>
|
|
776
|
+
(
|
|
777
|
+
await Bun.file(ledger)
|
|
778
|
+
.text()
|
|
779
|
+
.catch(() => "")
|
|
780
|
+
)
|
|
781
|
+
.split("\n")
|
|
782
|
+
.filter((line) => line.split(" ")[0]?.split(",").includes("pages"))
|
|
783
|
+
.map((line) => line.split(" ")[1] ?? "");
|
|
784
|
+
const pagesStatuses = () =>
|
|
785
|
+
messages.flatMap((message) =>
|
|
786
|
+
message.type === "build-status" && message.data.phase === "pages" ? [message.data.ok] : [],
|
|
787
|
+
);
|
|
788
|
+
try {
|
|
789
|
+
await until(proc, "boot-armed", () => messages.some((message) => message.type === "boot-armed"));
|
|
790
|
+
await writeText(signal, "export const signal = 1;\n");
|
|
791
|
+
await until(proc, "the signal save's pages status", () => pagesStatuses().length === 1);
|
|
792
|
+
await writeText(page, "export default () => 1;\n");
|
|
793
|
+
await until(proc, "the next save's pages status", () => pagesStatuses().length === 2);
|
|
794
|
+
await writeText(page, "export default () => 2;\n");
|
|
795
|
+
await until(proc, "the third save's pages status", () => pagesStatuses().length === 3);
|
|
796
|
+
await writeText(page, "export default () => 3;\n");
|
|
797
|
+
await until(proc, "the fourth save's pages status", () => pagesStatuses().length === 4);
|
|
798
|
+
} finally {
|
|
799
|
+
proc.kill();
|
|
800
|
+
await proc.exited;
|
|
801
|
+
}
|
|
802
|
+
expect(pagesStatuses()).toEqual([false, true, true, true]);
|
|
803
|
+
expect(await pagesBatches()).toEqual(["demo.signal.ts", "demo.signal.ts", "demo.signal.ts", ""]);
|
|
804
|
+
expect(messages.filter((message) => message.type === "builder-ready")).toHaveLength(1);
|
|
805
|
+
}, 60_000);
|
|
806
|
+
|
|
648
807
|
test("a failed boot build waits for the save that fixes it, and the builder it recovers continues the generation and watches", async () => {
|
|
649
808
|
const { root } = track(await createTempApp("demo"));
|
|
650
809
|
const appDir = path.join(root, "apps/demo");
|