@akanjs/devkit 3.2.0-rc.9 → 3.2.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/CHANGELOG.md +0 -529
- package/DEV_RUNTIME_KNOBS.md +4 -3
- package/README.ko.md +3 -2
- package/README.md +4 -2
- package/akanApp/BackendImportGraph.test.ts +1 -1
- package/akanApp/akanApp.host.test.ts +132 -3
- package/akanApp/akanApp.host.ts +146 -1216
- package/akanApp/akanApp.host.wiring.test.ts +727 -0
- package/akanApp/builderGap.ts +68 -0
- package/akanApp/builderRequestRelay.test.ts +93 -0
- package/akanApp/builderRequestRelay.ts +100 -0
- package/akanApp/builderRssRecycler.ts +182 -0
- package/akanApp/devBackend.ts +392 -0
- package/akanApp/devBuildStatusBoard.ts +128 -0
- package/akanApp/devBuilder.ts +196 -0
- package/akanApp/devIdleSuspend.test.ts +221 -0
- package/akanApp/devIdleSuspend.ts +192 -0
- package/akanApp/devIdleSuspend.watcher.test.ts +120 -0
- package/akanApp/devRecycler.test.ts +66 -0
- package/akanApp/devRecycler.ts +305 -0
- package/akanApp/processRss.ts +61 -0
- package/akanConfig/akanConfig.test.ts +45 -17
- package/akanConfig/akanConfig.ts +10 -10
- package/akanConfig/akanWorkspaceConfig.ts +1 -1
- package/akanConfig/productionLockfile.ts +1 -1
- package/apiReport/apiReport.test.ts +34 -3
- package/apiReport/apiReportDiff.ts +35 -1
- package/apiReport/apiReportPolicy.ts +3 -2
- package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +2 -49
- package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +71 -8
- package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +60 -21
- package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
- package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +17 -1
- package/{routeJsBudget.ts → app/routeJsBudget.ts} +9 -3
- package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
- package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
- package/artifact/implicitRootLayout.test.ts +71 -3
- package/artifact/implicitRootLayout.ts +9 -3
- package/artifact/implicitRootLayoutRender.test.tsx +297 -0
- package/biome.base.json +2 -1
- package/cloud/cloudApi.test.ts +1 -1
- package/cloud/configLock.test.ts +1 -1
- package/cloud/globalConfig.test.ts +1 -1
- package/cloud/globalConfig.ts +1 -1
- package/cloud/updatePackUpload.test.ts +1 -1
- package/codeAgent/agent/AkanCodeEnv.ts +1 -1
- package/codeAgent/agent/AkanCodeServices.ts +23 -0
- package/codeAgent/agent/akanCodePaths.ts +1 -1
- package/codeAgent/agent/akanCodeServices.test.ts +54 -0
- package/codeAgent/agent/akanSystemPrompt.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +1 -1
- package/codeAgent/skills/akan-debug/SKILL.md +8 -5
- package/codeAgent/skills/akan-err/SKILL.md +7 -0
- package/codeAgent/skills/akan-mcp/SKILL.md +19 -1
- package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
- package/codeAgent/skills/akan-validate/SKILL.md +3 -3
- package/codeAgent/tools/AkanCli.ts +1 -1
- package/codeAgent/tools/AkanToolPack.ts +2 -2
- package/codeAgent/tools/akanCodePlugins.test.ts +1 -1
- package/commandDecorators/command.ts +35 -6
- package/commandDecorators/commandBuilder.ts +1 -1
- package/commandDecorators/commandDecorators.test.ts +107 -6
- package/commandDecorators/targetMeta.ts +2 -0
- package/commandDecorators/workspaceVersionCheck.test.ts +70 -1
- package/commandDecorators/workspaceVersionCheck.ts +64 -14
- package/context/akanContext.ts +576 -0
- package/context/akanContextInspection.ts +296 -0
- package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
- package/{akanMcpContract.ts → context/akanMcpContract.ts} +16 -256
- package/context/doctor/agentGuideCheck.ts +81 -0
- package/context/doctor/configLeftoverCheck.ts +35 -0
- package/context/doctor/doctorFindings.ts +70 -0
- package/context/doctor/generatedFreshness.ts +56 -0
- package/context/doctor/moduleShapeCheck.ts +88 -0
- package/context/doctor/recipeDuplicateCheck.ts +42 -0
- package/context/doctor/recipeIndexCheck.ts +87 -0
- package/context/doctor/rootShapeCheck.ts +55 -0
- package/context/doctor/workflowScope.ts +97 -0
- package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
- package/context/safeRead.ts +9 -0
- package/csrE2e/csrE2eHarness.fixture.ts +1 -1
- package/devkitUtils.test.ts +39 -5
- package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
- package/{apiReference.ts → docs/apiReference.ts} +2 -2
- package/docs/errorCodeReference.test.ts +282 -0
- package/docs/errorCodeReference.ts +71 -0
- package/docs/errorCodeScan.ts +551 -0
- package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
- package/executors/appExecutor.ts +448 -0
- package/executors/commandExecutionError.ts +53 -0
- package/executors/executor.ts +527 -0
- package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
- package/{executors.test.ts → executors/executors.test.ts} +76 -15
- package/executors/index.ts +8 -0
- package/executors/libExecutor.ts +23 -0
- package/executors/moduleExecutor.ts +18 -0
- package/executors/pkgExecutor.ts +129 -0
- package/executors/sysExecutor.ts +301 -0
- package/executors/workspaceExecutor.ts +277 -0
- package/frontendBuild/allRoutesBuilder.test.ts +1 -1
- package/frontendBuild/autoImportSync.test.ts +1 -1
- package/frontendBuild/autoImportSync.ts +1 -1
- package/frontendBuild/buildRouteClient.test.ts +1 -1
- package/frontendBuild/clientEntriesBundler.test.ts +1 -1
- package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
- package/frontendBuild/csrDevArtifactWriter.ts +1 -1
- package/frontendBuild/cssCompiler.test.ts +3 -2
- package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
- package/frontendBuild/devGeneratedIndexSync.ts +7 -38
- package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
- package/frontendBuild/fontOptimizer.test.ts +1 -1
- package/frontendBuild/fontPruner.test.ts +1 -1
- package/frontendBuild/frontendBuild.test.ts +3 -3
- package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
- package/frontendBuild/hmrWatcher.test.ts +1 -1
- package/frontendBuild/hmrWatcher.ts +22 -1
- package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
- package/frontendBuild/mcpAppViewBuilder.ts +1 -1
- package/frontendBuild/nativeCore.test.ts +1 -1
- package/frontendBuild/optionalPeers.test.ts +36 -8
- package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
- package/frontendBuild/pagesBundleBuilder.ts +1 -1
- package/frontendBuild/precompressArtifacts.test.ts +1 -1
- package/frontendBuild/precompressArtifacts.ts +19 -6
- package/frontendBuild/serverGraphFile.ts +1 -1
- package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
- package/frontendBuild/ssrDevBundler.test.ts +1 -1
- package/frontendBuild/vendorImportScanner.test.ts +1 -1
- package/frontendBuild/vendorNarrowing.test.ts +1 -1
- package/frontendBuild/watchRootResolver.test.ts +1 -1
- package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
- package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
- package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
- package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
- package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
- package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
- package/{prompter.ts → guideline/prompter.ts} +2 -3
- package/incrementalBuilder/buildBatch.proc.ts +14 -4
- package/incrementalBuilder/buildBatchProtocol.ts +2 -0
- package/incrementalBuilder/buildBatchRunner.test.ts +122 -2
- package/incrementalBuilder/buildBatchRunner.ts +17 -4
- package/incrementalBuilder/builderBoot.ts +106 -0
- package/incrementalBuilder/builderBuildStatus.ts +23 -0
- package/incrementalBuilder/builderChannel.test.ts +1 -1
- package/incrementalBuilder/builderChannel.ts +11 -0
- package/incrementalBuilder/builderGraphPayloads.ts +3 -3
- package/incrementalBuilder/builderLanes.ts +157 -0
- package/incrementalBuilder/builderWatch.ts +213 -0
- package/incrementalBuilder/csrRegistry.ts +234 -0
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +101 -7
- package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
- package/incrementalBuilder/ssrRegistry.ts +282 -0
- package/index.ts +22 -22
- package/integration/devStability.integration.test.ts +62 -56
- package/integration/devStabilityHarness.test.ts +1 -1
- package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
- package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
- package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
- package/lint/gritRules.test.ts +1 -1
- package/{linter.test.ts → lint/linter.test.ts} +1 -1
- package/lint/no-import-common-err.grit +31 -0
- package/lint/no-init-fetch-in-client.grit +1 -1
- package/mobile/desktopBin.test.ts +1 -1
- package/mobile/desktopRelease.test.ts +1 -1
- package/mobile/desktopServerStage.test.ts +2 -2
- package/mobile/desktopServerStage.ts +1 -1
- package/mobile/nativeApi.test.ts +1 -1
- package/mobile/nativeApp.test.ts +1 -1
- package/mobile/nativeConfig.test.ts +1 -1
- package/mobile/nativePluginFolders.test.ts +1 -1
- package/mobile/nativePublicEnv.test.ts +1 -1
- package/mobile/nativeWebDir.test.ts +1 -1
- package/mobile/serverBundleSecrets.test.ts +1 -1
- package/mobile/tarWriter.test.ts +1 -1
- package/mobile/updatePackFolder.test.ts +1 -1
- package/package.json +173 -9
- package/packageExports.test.ts +20 -2
- package/piDependencyPins.test.ts +1 -1
- package/pipeline/PipelineDefinition.ts +1 -1
- package/platformTest/IdleWatchedProcess.test.ts +1 -1
- package/platformTest/LinuxDockerTarget.ts +1 -1
- package/platformTest/PlatformTestRun.test.ts +1 -1
- package/platformTest/TestSnapshot.test.ts +1 -1
- package/platformTest/WindowsSshTarget.ts +1 -1
- package/preview/previewView.test.ts +23 -1
- package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
- package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
- package/quality/bareErrorScanner.ts +126 -0
- package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
- package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
- package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
- package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
- package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
- package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
- package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
- package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
- package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +41 -1
- package/{qualityScanner.ts → quality/qualityScanner.ts} +25 -91
- package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
- package/quality/workspaceSourceFiles.ts +82 -0
- package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
- package/{subspace.ts → subspace/subspace.ts} +5 -5
- package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
- package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
- package/{testHelpers.ts → test/testHelpers.ts} +37 -1
- package/transforms/barrelAnalyzer.ts +31 -10
- package/transforms/browserDirnamePlugin.test.ts +1 -1
- package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
- package/transforms/mcpAppPageTrimmer.test.ts +1 -1
- package/transforms/pureLazyMarker.test.ts +1 -1
- package/transforms/serverEnvPlugin.test.ts +1 -1
- package/transforms/serverEnvProfile.test.ts +1 -1
- package/transforms/sideEffectImportOrder.test.ts +1 -1
- package/transforms/transforms.test.ts +52 -2
- package/transforms/tsconfigPackageResolver.test.ts +1 -1
- package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
- package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
- package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
- package/typecheck/projectTypecheck.test.ts +23 -1
- package/typecheck/projectTypecheck.ts +10 -2
- package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
- package/{typeChecker.ts → typecheck/typeChecker.ts} +5 -4
- package/typecheck/typecheck.proc.ts +6 -2
- package/typecheck/typecheckFailure.ts +1 -1
- package/util/errorReport.ts +66 -0
- package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
- package/workflow/constantSource.ts +187 -0
- package/workflow/dictionarySource.ts +184 -0
- package/workflow/executor.ts +6 -9
- package/workflow/fieldExpression.ts +153 -0
- package/workflow/fieldLabel.ts +61 -0
- package/workflow/fieldOrder.ts +117 -0
- package/workflow/fieldType.ts +2 -1
- package/workflow/guardCatalog.test.ts +1 -1
- package/workflow/keyRename.ts +1 -1
- package/workflow/moduleIndex.test.ts +2 -2
- package/workflow/moduleIndex.ts +2 -2
- package/workflow/modulePaths.ts +27 -0
- package/workflow/mutationScaffold.ts +7 -15
- package/workflow/mutationSource.ts +2 -1
- package/workflow/plan.ts +2 -1
- package/workflow/primitiveReport.ts +78 -0
- package/workflow/rolloutGate.test.ts +1 -1
- package/workflow/rolloutGate.ts +1 -1
- package/workflow/serviceSource.ts +33 -0
- package/workflow/signalSource.ts +96 -0
- package/workflow/source.ts +50 -1100
- package/workflow/sourceAst.ts +30 -0
- package/workflow/sourceImports.ts +105 -0
- package/workflow/sourceText.ts +13 -0
- package/workflow/templateSource.ts +30 -0
- package/workflow/testSource.ts +31 -0
- package/workflow/types.ts +1 -1
- package/workflow/uiPolicy.ts +1 -1
- package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
- package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
- package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
- package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
- package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
- package/{envSeed.ts → workspace/envSeed.ts} +1 -1
- package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
- package/{libSource.ts → workspace/libSource.ts} +1 -1
- package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
- package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
- package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
- package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
- package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
- package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
- package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
- package/akanContext.ts +0 -1083
- package/executors.ts +0 -1749
- /package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +0 -0
- /package/{akanMcpToolError.ts → context/akanMcpToolError.ts} +0 -0
- /package/{moduleFieldNames.test.ts → context/moduleFieldNames.test.ts} +0 -0
- /package/{moduleFieldNames.ts → context/moduleFieldNames.ts} +0 -0
- /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
- /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
- /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
- /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
- /package/{linter.ts → lint/linter.ts} +0 -0
- /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
- /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
- /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
- /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
- /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
- /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
- /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
- /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
- /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
- /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
- /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
- /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
- /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
- /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
- /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
- /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
- /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
- /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
- /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
- /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
- /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
- /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
- /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
- /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
- /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
- /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
- /package/{storeSource.ts → quality/storeSource.ts} +0 -0
- /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
- /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
- /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
- /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
- /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
- /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
- /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
- /package/{writePath.ts → quality/writePath.ts} +0 -0
- /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
- /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
- /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
- /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
- /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
- /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
- /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
- /package/{fileSys.test.ts → util/fileSys.test.ts} +0 -0
- /package/{fileSys.ts → util/fileSys.ts} +0 -0
- /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
- /package/{selectModel.ts → util/selectModel.ts} +0 -0
- /package/{semver.test.ts → util/semver.test.ts} +0 -0
- /package/{semver.ts → util/semver.ts} +0 -0
- /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
- /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
- /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
- /package/{spinner.ts → util/spinner.ts} +0 -0
- /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
- /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
- /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
- /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
- /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
- /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
- /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
- /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
- /package/{types.ts → workspace/types.ts} +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
3
|
+
import type { ClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientBuildTypes";
|
|
4
|
+
import { GraphClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientEntryDiscovery";
|
|
5
|
+
import { HmrWatcher } from "@akanjs/devkit/frontendBuild/hmrWatcher";
|
|
6
|
+
import { WatchRootResolver } from "@akanjs/devkit/frontendBuild/watchRootResolver";
|
|
7
|
+
import type { Logger } from "akanjs/common";
|
|
8
|
+
import type { BaseBuildArtifact } from "akanjs/server";
|
|
9
|
+
import type { OptimizedFonts } from "./buildBatchProtocol";
|
|
10
|
+
import type { BuildBatchRunner } from "./buildBatchRunner";
|
|
11
|
+
import { BuilderChannel } from "./builderChannel";
|
|
12
|
+
|
|
13
|
+
export interface IncrementalBuilderOptions {
|
|
14
|
+
app: App;
|
|
15
|
+
artifact: BaseBuildArtifact;
|
|
16
|
+
watch: boolean;
|
|
17
|
+
optimizedFonts: OptimizedFonts;
|
|
18
|
+
discovery: ClientEntryDiscovery;
|
|
19
|
+
initialGeneration?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type IncrementalBuilderBootDeps = Pick<IncrementalBuilderOptions, "artifact" | "optimizedFonts" | "discovery">;
|
|
23
|
+
|
|
24
|
+
export class BuilderBoot {
|
|
25
|
+
// Discovery stays in-process because route builds need it live; it is free at boot, building its graph lazily.
|
|
26
|
+
static async buildBootDeps(app: App, runner: BuildBatchRunner): Promise<IncrementalBuilderBootDeps> {
|
|
27
|
+
const result = await runner.run({
|
|
28
|
+
appName: app.name,
|
|
29
|
+
workspaceRoot: app.workspace.workspaceRoot,
|
|
30
|
+
repoName: app.workspace.repoName,
|
|
31
|
+
generation: 0,
|
|
32
|
+
needs: ["base"],
|
|
33
|
+
changedFiles: [],
|
|
34
|
+
pageKeys: null,
|
|
35
|
+
optimizedFonts: null,
|
|
36
|
+
cssAssets: null,
|
|
37
|
+
artifactDir: path.resolve(`${app.cwdPath}/.akan/artifact`),
|
|
38
|
+
});
|
|
39
|
+
// Throws rather than degrading quietly: `main` catches it to enter degraded watch mode.
|
|
40
|
+
if (result.errors.base) throw new Error(result.errors.base);
|
|
41
|
+
if (!result.artifact || !result.optimizedFonts)
|
|
42
|
+
throw new Error("boot build reported success without an artifact; the build worker likely died");
|
|
43
|
+
const discovery = await GraphClientEntryDiscovery.create(app);
|
|
44
|
+
return { artifact: result.artifact, optimizedFonts: result.optimizedFonts, discovery };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// A boot compile error must not kill the builder, the dev server's only file watcher: report it, emit builder-ready
|
|
48
|
+
// so the backend keeps the last-good artifact, and retry the boot build on every change.
|
|
49
|
+
static recoverBoot<Builder>(
|
|
50
|
+
app: App,
|
|
51
|
+
bootError: unknown,
|
|
52
|
+
logger: Logger,
|
|
53
|
+
runner: BuildBatchRunner,
|
|
54
|
+
initialGeneration: number,
|
|
55
|
+
create: (options: IncrementalBuilderOptions) => Builder,
|
|
56
|
+
): Promise<{ builder: Builder; changedFiles: string[] }> {
|
|
57
|
+
const firstMessage = bootError instanceof Error ? bootError.message : String(bootError);
|
|
58
|
+
logger.error(`boot build failed; entering degraded watch mode until the error is fixed: ${firstMessage}`);
|
|
59
|
+
let generation = initialGeneration;
|
|
60
|
+
const sendFailure = (files: string[], message: string) => {
|
|
61
|
+
BuilderChannel.emit({
|
|
62
|
+
type: "build-status",
|
|
63
|
+
data: { generation, phase: "pages", ok: false, files, message: `Boot build failed: ${message}` },
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
sendFailure([], firstMessage);
|
|
67
|
+
BuilderChannel.emit({ type: "builder-ready" });
|
|
68
|
+
// Nothing builds until a save fixes the boot, so the next app's boot need not wait for this one.
|
|
69
|
+
BuilderChannel.emit({ type: "boot-armed" });
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
void (async () => {
|
|
72
|
+
const roots = await new WatchRootResolver(app).resolve();
|
|
73
|
+
const watcher = new HmrWatcher({
|
|
74
|
+
roots,
|
|
75
|
+
logger,
|
|
76
|
+
onBatch: async (batch) => {
|
|
77
|
+
generation += 1;
|
|
78
|
+
const files = [...batch.files].sort();
|
|
79
|
+
try {
|
|
80
|
+
// A broken akan.config.ts caches its import failure; re-import it before rebuilding.
|
|
81
|
+
if (new Set(batch.kinds).has("config")) await app.getConfig({ refresh: true });
|
|
82
|
+
const deps = await BuilderBoot.buildBootDeps(app, runner);
|
|
83
|
+
const builder = create({ app, watch: true, initialGeneration: generation, ...deps });
|
|
84
|
+
watcher.stop();
|
|
85
|
+
logger.info(`boot build recovered generation=${generation}`);
|
|
86
|
+
resolve({ builder, changedFiles: files });
|
|
87
|
+
} catch (err) {
|
|
88
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
89
|
+
logger.error(`boot build retry failed: ${message}`);
|
|
90
|
+
sendFailure(files, message);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
await watcher.start();
|
|
95
|
+
logger.warn(`[degraded] watching ${roots.length} roots for a fix`);
|
|
96
|
+
})().catch(reject);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//? A replacement builder continues past the host's last generation: from 0, the save fixing an error read older than
|
|
101
|
+
//? the failure the tabs hold, and from that generation itself its arming builds' ok did not read as the fix either.
|
|
102
|
+
static initialGeneration(): number {
|
|
103
|
+
const generation = Number(process.env.AKAN_BUILDER_INITIAL_GENERATION);
|
|
104
|
+
return Number.isInteger(generation) && generation > 0 ? generation + 1 : 0;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BuildPhase } from "akanjs/server";
|
|
2
|
+
import { BuilderChannel } from "./builderChannel";
|
|
3
|
+
|
|
4
|
+
export const sendBuildStatus = (
|
|
5
|
+
phase: BuildPhase,
|
|
6
|
+
{
|
|
7
|
+
generation,
|
|
8
|
+
ok,
|
|
9
|
+
files,
|
|
10
|
+
message,
|
|
11
|
+
scope,
|
|
12
|
+
}: { generation?: number; ok: boolean; files?: string[]; message?: string; scope?: string },
|
|
13
|
+
): void => {
|
|
14
|
+
if (typeof generation !== "number") return;
|
|
15
|
+
BuilderChannel.emit({
|
|
16
|
+
type: "build-status",
|
|
17
|
+
data: { generation, phase, ok, files: files ?? [], message, ...(scope !== undefined ? { scope } : {}) },
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//? A save the user broke fails the same way in a worker, so it is reported here and the patcher keeps its state: the
|
|
22
|
+
//? modules it could not compile stay pending in the graph and the fixing save compiles them.
|
|
23
|
+
export const isCompileError = (error: unknown): boolean => error instanceof AggregateError;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { tempDirs } from "../testHelpers";
|
|
3
|
+
import { tempDirs } from "../test/testHelpers";
|
|
4
4
|
import { BuilderChannel } from "./builderChannel";
|
|
5
5
|
|
|
6
6
|
const tempDir = tempDirs("builder-channel-");
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Logger } from "akanjs/common";
|
|
1
2
|
import type { BuilderMessage } from "akanjs/server";
|
|
2
3
|
|
|
3
4
|
// `process.exit` drops an ipc write that has not flushed (a natural exit does not), and whether one survives
|
|
@@ -28,6 +29,16 @@ export class BuilderChannel {
|
|
|
28
29
|
void BuilderChannel.send(message);
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
//? `AKAN_DEV_BUILDER_READY_GATE` is a test hook: the dev-stability suite holds a replacement short of ready.
|
|
33
|
+
static async announceReady(logger: Logger): Promise<void> {
|
|
34
|
+
const gate = process.env.AKAN_DEV_BUILDER_READY_GATE;
|
|
35
|
+
if (gate && !(await Bun.file(gate).exists())) {
|
|
36
|
+
logger.warn(`AKAN_DEV_BUILDER_READY_GATE is set: holding builder-ready until ${gate} exists`);
|
|
37
|
+
while (!(await Bun.file(gate).exists())) await Bun.sleep(100);
|
|
38
|
+
}
|
|
39
|
+
BuilderChannel.emit({ type: "builder-ready" });
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
// Loops because `#reportMetrics` can send from a work item's `finally` after the drain has begun.
|
|
32
43
|
static async drain(): Promise<number> {
|
|
33
44
|
let flushed = 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
2
|
-
import { FrameworkGraph } from "@akanjs/devkit/frameworkGraph";
|
|
3
|
-
import { GitRevision } from "@akanjs/devkit/gitRevision";
|
|
4
|
-
import { WorkspaceGraph } from "@akanjs/devkit/workspaceGraph";
|
|
2
|
+
import { FrameworkGraph } from "@akanjs/devkit/docs/frameworkGraph";
|
|
3
|
+
import { GitRevision } from "@akanjs/devkit/workspace/gitRevision";
|
|
4
|
+
import { WorkspaceGraph } from "@akanjs/devkit/workspace/workspaceGraph";
|
|
5
5
|
import type { BuildChangesPayload, BuilderGraphReq, BuildFrameworkPayload, BuildGraphPayload } from "akanjs/server";
|
|
6
6
|
|
|
7
7
|
export class BuilderGraphPayloads {
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
|
|
2
|
+
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
3
|
+
import type { Logger } from "akanjs/common";
|
|
4
|
+
import type { BatchWork, BuildBatchResult } from "./buildBatchProtocol";
|
|
5
|
+
import { sendBuildStatus } from "./builderBuildStatus";
|
|
6
|
+
import { BuilderChannel } from "./builderChannel";
|
|
7
|
+
import { type BatchJob, BuilderWorkQueue } from "./builderWorkQueue";
|
|
8
|
+
|
|
9
|
+
interface BuilderLanesLinks {
|
|
10
|
+
generation: () => number;
|
|
11
|
+
runQueuedBatch: (batch: BatchJob) => Promise<void>;
|
|
12
|
+
runBatch: (work: BatchWork) => Promise<BuildBatchResult>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class BuilderLanes {
|
|
16
|
+
readonly #app: App;
|
|
17
|
+
readonly #logger: Logger;
|
|
18
|
+
readonly #links: BuilderLanesLinks;
|
|
19
|
+
/** Arming and the route entries deferred behind it run beside both lanes; a recycle waits for them too. */
|
|
20
|
+
readonly #beside = new Set<Promise<void>>();
|
|
21
|
+
//* Two lanes: a save's codegen and CSR patch in the fast one, which the watcher waits for; build workers, route
|
|
22
|
+
//* builds and discovery in the slow one, which folds queued batches. A save no longer waits behind pages and css.
|
|
23
|
+
#fastQueue: Promise<void> = Promise.resolve();
|
|
24
|
+
readonly #workQueue: BuilderWorkQueue;
|
|
25
|
+
#inFlight = 0;
|
|
26
|
+
#workCount = 0;
|
|
27
|
+
#shuttingDown = false;
|
|
28
|
+
#cssRebuildQueue: Promise<void> = Promise.resolve();
|
|
29
|
+
#cssRebuildTimer: ReturnType<typeof setTimeout> | null = null;
|
|
30
|
+
#pendingCssRebuild: { generation?: number; changedFiles?: string[] } | null = null;
|
|
31
|
+
|
|
32
|
+
constructor(app: App, { logger }: { logger: Logger }, links: BuilderLanesLinks) {
|
|
33
|
+
this.#app = app;
|
|
34
|
+
this.#logger = logger;
|
|
35
|
+
this.#links = links;
|
|
36
|
+
this.#workQueue = new BuilderWorkQueue({
|
|
37
|
+
runBatch: async (batch) => await this.#links.runQueuedBatch(batch),
|
|
38
|
+
onSettled: (label, ms) => {
|
|
39
|
+
this.#workCount += 1;
|
|
40
|
+
this.#logger.verbose(`[work-queue] ${label} finished in ${ms}ms`);
|
|
41
|
+
this.#reportMetrics();
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get workQueue(): BuilderWorkQueue {
|
|
47
|
+
return this.#workQueue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get inFlight(): number {
|
|
51
|
+
return this.#inFlight;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get shuttingDown(): boolean {
|
|
55
|
+
return this.#shuttingDown;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
markShuttingDown(): void {
|
|
59
|
+
this.#shuttingDown = true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async enqueueFast<T>(label: string, fn: () => Promise<T>): Promise<T> {
|
|
63
|
+
const started = Date.now();
|
|
64
|
+
this.#inFlight += 1;
|
|
65
|
+
const run = this.#fastQueue.then(fn, fn);
|
|
66
|
+
this.#fastQueue = run.then(() => undefined).catch(() => undefined);
|
|
67
|
+
try {
|
|
68
|
+
return await run;
|
|
69
|
+
} finally {
|
|
70
|
+
this.#inFlight -= 1;
|
|
71
|
+
this.#workCount += 1;
|
|
72
|
+
this.#logger.verbose(`[fast-queue] ${label} finished in ${Date.now() - started}ms`);
|
|
73
|
+
this.#reportMetrics();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get #idle(): boolean {
|
|
78
|
+
return this.#inFlight === 0 && this.#workQueue.size === 0 && this.#cssRebuildTimer === null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Callers catch their own errors: the promise handed in never rejects.
|
|
82
|
+
runBeside(work: Promise<void>): Promise<void> {
|
|
83
|
+
this.#inFlight += 1;
|
|
84
|
+
const tracked: Promise<void> = work.finally(() => {
|
|
85
|
+
this.#inFlight -= 1;
|
|
86
|
+
this.#beside.delete(tracked);
|
|
87
|
+
this.#reportMetrics();
|
|
88
|
+
});
|
|
89
|
+
this.#beside.add(tracked);
|
|
90
|
+
return tracked;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Idle only: the host recycles on these metrics, and a recycle decided mid-work would truncate it or race the drain.
|
|
94
|
+
#reportMetrics(): void {
|
|
95
|
+
if (!this.#idle || this.#shuttingDown) return;
|
|
96
|
+
BuilderChannel.emit({
|
|
97
|
+
type: "builder-metrics",
|
|
98
|
+
data: { rssBytes: process.memoryUsage.rss(), generation: this.#links.generation(), workCount: this.#workCount },
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async drain(): Promise<void> {
|
|
103
|
+
if (this.#cssRebuildTimer) {
|
|
104
|
+
// Only if css landed after the idle report; the replacement's boot build recompiles css, so nothing is lost.
|
|
105
|
+
clearTimeout(this.#cssRebuildTimer);
|
|
106
|
+
this.#cssRebuildTimer = null;
|
|
107
|
+
this.#pendingCssRebuild = null;
|
|
108
|
+
}
|
|
109
|
+
// The fast lane first: a save it is still handling may queue a batch in the slow one.
|
|
110
|
+
await this.#fastQueue.catch(() => undefined);
|
|
111
|
+
await this.#workQueue.drain();
|
|
112
|
+
await this.#cssRebuildQueue.catch(() => undefined);
|
|
113
|
+
while (this.#beside.size > 0) await Promise.all([...this.#beside]);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Voided so the fast lane need not wait; unhandled, a rejection would exit the builder and drop the watcher with it.
|
|
117
|
+
slowLaneFailed(label: string) {
|
|
118
|
+
return (error: unknown) =>
|
|
119
|
+
this.#logger.error(
|
|
120
|
+
`${label} failed in the slow lane: ${ApplicationBuildReporter.formatError(error, this.#app.workspace.workspaceRoot)}`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
scheduleCssRebuild({ generation, changedFiles }: { generation?: number; changedFiles?: string[] }) {
|
|
125
|
+
this.#pendingCssRebuild = { generation, changedFiles };
|
|
126
|
+
if (this.#cssRebuildTimer) clearTimeout(this.#cssRebuildTimer);
|
|
127
|
+
this.#cssRebuildTimer = setTimeout(() => {
|
|
128
|
+
this.#cssRebuildTimer = null;
|
|
129
|
+
const next = this.#pendingCssRebuild;
|
|
130
|
+
this.#pendingCssRebuild = null;
|
|
131
|
+
if (!next) return;
|
|
132
|
+
this.#inFlight += 1;
|
|
133
|
+
this.#cssRebuildQueue = this.#cssRebuildQueue
|
|
134
|
+
.then(async () => {
|
|
135
|
+
await this.#links.runBatch({
|
|
136
|
+
generation: next.generation ?? this.#links.generation(),
|
|
137
|
+
needs: ["css"],
|
|
138
|
+
changedFiles: next.changedFiles ?? [],
|
|
139
|
+
});
|
|
140
|
+
})
|
|
141
|
+
.catch((err) => {
|
|
142
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
143
|
+
this.#logger.error(`css-rebuild failed: ${message}`);
|
|
144
|
+
sendBuildStatus("css", {
|
|
145
|
+
generation: next.generation,
|
|
146
|
+
ok: false,
|
|
147
|
+
files: next.changedFiles,
|
|
148
|
+
message,
|
|
149
|
+
});
|
|
150
|
+
})
|
|
151
|
+
.finally(() => {
|
|
152
|
+
this.#inFlight -= 1;
|
|
153
|
+
this.#reportMetrics();
|
|
154
|
+
});
|
|
155
|
+
}, 150);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
3
|
+
import type { PageRoot } from "@akanjs/devkit/executors";
|
|
4
|
+
import { AutoImportSync } from "@akanjs/devkit/frontendBuild/autoImportSync";
|
|
5
|
+
import { DevChangePlanner } from "@akanjs/devkit/frontendBuild/devChangePlanner";
|
|
6
|
+
import { DevGeneratedIndexSync } from "@akanjs/devkit/frontendBuild/devGeneratedIndexSync";
|
|
7
|
+
import { HmrWatcher } from "@akanjs/devkit/frontendBuild/hmrWatcher";
|
|
8
|
+
import { WatchRootResolver } from "@akanjs/devkit/frontendBuild/watchRootResolver";
|
|
9
|
+
import { CodegenLock } from "@akanjs/devkit/workspace/codegenLock";
|
|
10
|
+
import type { Logger } from "akanjs/common";
|
|
11
|
+
import type { ChangeBatch } from "akanjs/server";
|
|
12
|
+
import type { BuildBatchNeed } from "./buildBatchProtocol";
|
|
13
|
+
import { sendBuildStatus } from "./builderBuildStatus";
|
|
14
|
+
import { BuilderChannel } from "./builderChannel";
|
|
15
|
+
import type { BuilderGraphPayloads } from "./builderGraphPayloads";
|
|
16
|
+
import type { BuilderLanes } from "./builderLanes";
|
|
17
|
+
import type { BatchJob, DiscoveryJob } from "./builderWorkQueue";
|
|
18
|
+
import type { CsrRegistry } from "./csrRegistry";
|
|
19
|
+
import { prepareDevWatchBatch } from "./devWatchBatch";
|
|
20
|
+
import type { SsrRegistry } from "./ssrRegistry";
|
|
21
|
+
|
|
22
|
+
interface BuilderWatchParts {
|
|
23
|
+
logger: Logger;
|
|
24
|
+
lanes: BuilderLanes;
|
|
25
|
+
csr: CsrRegistry;
|
|
26
|
+
ssr: SsrRegistry;
|
|
27
|
+
graphPayloads: BuilderGraphPayloads;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface BuilderWatchLinks {
|
|
31
|
+
nextGeneration: () => number;
|
|
32
|
+
refreshDiscovery: (job: DiscoveryJob) => Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class BuilderWatch {
|
|
36
|
+
readonly #app: App;
|
|
37
|
+
readonly #logger: Logger;
|
|
38
|
+
readonly #lanes: BuilderLanes;
|
|
39
|
+
readonly #csr: CsrRegistry;
|
|
40
|
+
readonly #ssr: SsrRegistry;
|
|
41
|
+
readonly #graphPayloads: BuilderGraphPayloads;
|
|
42
|
+
readonly #links: BuilderWatchLinks;
|
|
43
|
+
#changePlanner: DevChangePlanner;
|
|
44
|
+
#generatedIndexSync: DevGeneratedIndexSync;
|
|
45
|
+
#autoImportSync: AutoImportSync;
|
|
46
|
+
#watcher: HmrWatcher | null = null;
|
|
47
|
+
#barrelFailed = false;
|
|
48
|
+
|
|
49
|
+
constructor(app: App, { logger, lanes, csr, ssr, graphPayloads }: BuilderWatchParts, links: BuilderWatchLinks) {
|
|
50
|
+
this.#app = app;
|
|
51
|
+
this.#logger = logger;
|
|
52
|
+
this.#lanes = lanes;
|
|
53
|
+
this.#csr = csr;
|
|
54
|
+
this.#ssr = ssr;
|
|
55
|
+
this.#graphPayloads = graphPayloads;
|
|
56
|
+
this.#links = links;
|
|
57
|
+
this.#changePlanner = new DevChangePlanner({ workspaceRoot: app.workspace.workspaceRoot });
|
|
58
|
+
this.#generatedIndexSync = new DevGeneratedIndexSync({ workspaceRoot: app.workspace.workspaceRoot });
|
|
59
|
+
this.#autoImportSync = new AutoImportSync({ workspaceRoot: app.workspace.workspaceRoot });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
stop(): void {
|
|
63
|
+
this.#watcher?.stop();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//* Watch events carry real paths: synced lib pages match by `realDir`, their keys keep the `(libs)/(<lib>)` prefix.
|
|
67
|
+
static #matchPageRoot(roots: PageRoot[], abs: string): PageRoot | null {
|
|
68
|
+
for (const root of roots) {
|
|
69
|
+
const absRoot = path.resolve(root.realDir);
|
|
70
|
+
if (abs === absRoot || abs.startsWith(`${absRoot}${path.sep}`)) return root;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
batchTouchesPagesTree(roots: PageRoot[], batch: ChangeBatch): boolean {
|
|
75
|
+
for (const f of batch.files) {
|
|
76
|
+
const abs = path.resolve(f);
|
|
77
|
+
if (!BuilderWatch.#matchPageRoot(roots, abs)) continue;
|
|
78
|
+
if (/\.(tsx|ts|jsx|js)$/.test(abs)) return true;
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
async batchMayChangePageKeys(roots: PageRoot[], batch: ChangeBatch): Promise<boolean> {
|
|
83
|
+
const pageKeys = new Set((await this.#app.getPageKeys()).map((key) => path.normalize(key)));
|
|
84
|
+
for (const f of batch.files) {
|
|
85
|
+
const abs = path.resolve(f);
|
|
86
|
+
const root = BuilderWatch.#matchPageRoot(roots, abs);
|
|
87
|
+
if (!root) continue;
|
|
88
|
+
if (!/\.(tsx|ts|jsx|js)$/.test(abs)) continue;
|
|
89
|
+
const rel = path.normalize(`${root.keyPrefix}${path.relative(path.resolve(root.realDir), abs)}`);
|
|
90
|
+
if (!(await Bun.file(abs).exists()) || !pageKeys.has(rel)) return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
async installWatcher() {
|
|
95
|
+
const roots = await new WatchRootResolver(this.#app).resolve();
|
|
96
|
+
const watcher = new HmrWatcher({
|
|
97
|
+
roots,
|
|
98
|
+
logger: this.#logger,
|
|
99
|
+
onBatch: async (batch: ChangeBatch) => {
|
|
100
|
+
await this.#lanes.enqueueFast("hmr-batch", async () => this.#handleWatchBatch(batch));
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
await watcher.start();
|
|
104
|
+
this.#watcher = watcher;
|
|
105
|
+
this.#logger.verbose(`watching ${roots.length} roots`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async #handleWatchBatch(batch: ChangeBatch) {
|
|
109
|
+
this.#graphPayloads.touched(batch.files);
|
|
110
|
+
const rawKinds = new Set(batch.kinds);
|
|
111
|
+
if (rawKinds.size === 0) return;
|
|
112
|
+
const generation = this.#links.nextGeneration();
|
|
113
|
+
const trace = { ...batch.trace, batchAt: Date.now() };
|
|
114
|
+
//* Auto-import edits touch only this batch's files, so they rebuild in this same generation.
|
|
115
|
+
const [autoImport, indexSync] = await CodegenLock.run(
|
|
116
|
+
this.#app.workspace.workspaceRoot,
|
|
117
|
+
`hmr-batch:${this.#app.name}`,
|
|
118
|
+
async () => {
|
|
119
|
+
const auto = await this.#autoImportSync.syncForBatch(batch.files);
|
|
120
|
+
return [auto, await this.#generatedIndexSync.syncForBatch(batch.files)] as const;
|
|
121
|
+
},
|
|
122
|
+
);
|
|
123
|
+
for (const error of autoImport.errors) this.#logger.error(error);
|
|
124
|
+
if (autoImport.changedFiles.length > 0)
|
|
125
|
+
this.#logger.verbose(`[auto-import] inserted imports into ${autoImport.changedFiles.length} file(s)`);
|
|
126
|
+
//* Absorbed so the watcher's verification scan does not replay these writes as a user edit next generation.
|
|
127
|
+
await this.#watcher?.absorb([...autoImport.changedFiles, ...indexSync.changedFiles]);
|
|
128
|
+
const { files, kinds, expandedBatch, devPlan, event, hasSyncErrors } = prepareDevWatchBatch({
|
|
129
|
+
generation,
|
|
130
|
+
batch,
|
|
131
|
+
indexSync,
|
|
132
|
+
changePlanner: this.#changePlanner,
|
|
133
|
+
});
|
|
134
|
+
this.#logger.verbose(
|
|
135
|
+
`[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
|
+
);
|
|
137
|
+
for (const error of indexSync.errors) this.#logger.error(error);
|
|
138
|
+
|
|
139
|
+
// Invalidated in the slow lane, under the route builds that read it; a registry check reading it beside them caches
|
|
140
|
+
// nothing a walk began before the invalidation (the discovery's epoch).
|
|
141
|
+
const discovery = kinds.includes("code") ? { files, refresh: kinds.includes("config"), generation } : undefined;
|
|
142
|
+
|
|
143
|
+
if (hasSyncErrors) {
|
|
144
|
+
this.#barrelFailed = true;
|
|
145
|
+
sendBuildStatus("barrel", { generation, ok: false, files, message: indexSync.errors.join("\n") });
|
|
146
|
+
BuilderChannel.emit(event);
|
|
147
|
+
if (discovery)
|
|
148
|
+
void this.#lanes.workQueue
|
|
149
|
+
.enqueue("discovery", async () => await this.#links.refreshDiscovery(discovery))
|
|
150
|
+
.catch(this.#lanes.slowLaneFailed("discovery"));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
// After a failure too, where nothing changed on disk: the host re-sends a phase still failing to every new tab.
|
|
154
|
+
if (indexSync.changedFiles.length > 0 || this.#barrelFailed)
|
|
155
|
+
sendBuildStatus("barrel", { generation, ok: true, files });
|
|
156
|
+
this.#barrelFailed = false;
|
|
157
|
+
|
|
158
|
+
// Server-only generations skip the client: a fresh pages buildId would rsc-refresh browsers for no visible change.
|
|
159
|
+
const rebuildClient = devPlan.actions.includes("rebuild-client");
|
|
160
|
+
if (kinds.includes("code") && !rebuildClient) {
|
|
161
|
+
this.#logger.verbose(`client rebuild skipped; devPlan actions=${devPlan.actions.join(",") || "(none)"}`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const pageRoots = await this.#app.getPageRoots();
|
|
165
|
+
if (kinds.includes("code") && rebuildClient && (await this.batchMayChangePageKeys(pageRoots, expandedBatch))) {
|
|
166
|
+
const started = Date.now();
|
|
167
|
+
await this.#app.getPageKeys({ refresh: true });
|
|
168
|
+
this.#logger.verbose(`pageKeys updated, app pageKeys are refreshed (${Date.now() - started}ms)`);
|
|
169
|
+
} else if (kinds.includes("code") && rebuildClient && this.batchTouchesPagesTree(pageRoots, expandedBatch)) {
|
|
170
|
+
this.#logger.verbose("pageKeys refresh skipped; changed page source cannot add/remove a route key");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
BuilderChannel.emit(event);
|
|
174
|
+
|
|
175
|
+
if (kinds.includes("code") && rebuildClient) {
|
|
176
|
+
// Css rides the pages batch rather than its own debounce: the slow lane folds a burst of saves into one batch.
|
|
177
|
+
const needs: BuildBatchNeed[] = ["pages", "css"];
|
|
178
|
+
if (!this.#csr.csrActive)
|
|
179
|
+
this.#logger.verbose(
|
|
180
|
+
`csr-rebundle skipped; request /__csr or ?csr=true (or set AKAN_DEV_CSR_REBUILD=1) to enable per-save CSR rebuilds`,
|
|
181
|
+
);
|
|
182
|
+
//? One after the other, since two compiles side by side slow both. CSR goes first unless its build is being armed:
|
|
183
|
+
//? a CSR patch then waits behind #csrGate, which SSR tabs must not.
|
|
184
|
+
const patchCsr = async () => (this.#csr.csrActive ? await this.#csr.patchCsr(generation, files, trace) : false);
|
|
185
|
+
const patchSsr = async () => await this.#ssr.patchSsr(generation, files, trace);
|
|
186
|
+
let csrToWorker: boolean;
|
|
187
|
+
let ssrToWorker: boolean;
|
|
188
|
+
if (this.#csr.csrArming) {
|
|
189
|
+
ssrToWorker = await patchSsr();
|
|
190
|
+
csrToWorker = await patchCsr();
|
|
191
|
+
} else {
|
|
192
|
+
csrToWorker = await patchCsr();
|
|
193
|
+
ssrToWorker = await patchSsr();
|
|
194
|
+
}
|
|
195
|
+
if (csrToWorker) needs.unshift("csr");
|
|
196
|
+
if (ssrToWorker) needs.unshift("ssr");
|
|
197
|
+
const batch: BatchJob = { generation, needs, changedFiles: files, trace, ...(discovery ? { discovery } : {}) };
|
|
198
|
+
// A worker's registry build rewrites the directory its patcher reads, so the next save waits for it.
|
|
199
|
+
if (needs.includes("csr") || needs.includes("ssr")) await this.#lanes.workQueue.enqueueBatch(batch);
|
|
200
|
+
else void this.#lanes.workQueue.enqueueBatch(batch).catch(this.#lanes.slowLaneFailed("batch"));
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (discovery)
|
|
204
|
+
void this.#lanes.workQueue
|
|
205
|
+
.enqueue("discovery", async () => await this.#links.refreshDiscovery(discovery))
|
|
206
|
+
.catch(this.#lanes.slowLaneFailed("discovery"));
|
|
207
|
+
// Css-only batches keep the debounce: they arrive in bursts while a stylesheet is edited.
|
|
208
|
+
if (kinds.includes("css")) {
|
|
209
|
+
this.#lanes.scheduleCssRebuild({ generation, changedFiles: files });
|
|
210
|
+
this.#logger.verbose(`css-rebuild scheduled generation=${generation}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|