@akanjs/devkit 3.2.0-rc.9 → 3.2.1-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/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 +152 -6
- package/akanApp/akanApp.host.ts +187 -1220
- package/akanApp/akanApp.host.wiring.test.ts +931 -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 +394 -0
- package/akanApp/devBuildStatusBoard.ts +128 -0
- package/akanApp/devBuilder.ts +200 -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/devStartTimeline.test.ts +115 -0
- package/akanApp/devStartTimeline.ts +69 -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 +463 -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} +106 -18
- 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/buildCacheStamp.test.ts +42 -0
- package/frontendBuild/buildCacheStamp.ts +23 -0
- 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/cssCandidateCache.test.ts +70 -1
- package/frontendBuild/cssCandidateCache.ts +17 -10
- 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 +145 -4
- package/frontendBuild/fontOptimizer.ts +103 -18
- 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/ssrBaseArtifactBuilder.test.ts +30 -1
- package/frontendBuild/ssrBaseArtifactBuilder.ts +40 -12
- 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 +16 -5
- package/incrementalBuilder/buildBatchProtocol.ts +3 -0
- package/incrementalBuilder/buildBatchRunner.test.ts +122 -2
- package/incrementalBuilder/buildBatchRunner.ts +17 -4
- package/incrementalBuilder/builderBoot.ts +113 -0
- package/incrementalBuilder/builderBuildStatus.ts +23 -0
- package/incrementalBuilder/builderChannel.test.ts +1 -1
- package/incrementalBuilder/builderChannel.ts +19 -2
- 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.host.test.ts +16 -0
- package/incrementalBuilder/incrementalBuilder.host.ts +7 -1
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +142 -7
- package/incrementalBuilder/incrementalBuilder.proc.ts +82 -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/nativePublicEnv.ts +2 -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/{fileSys.test.ts → util/fileSys.test.ts} +13 -0
- package/{fileSys.ts → util/fileSys.ts} +2 -2
- 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/{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
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { rm } from "node:fs/promises";
|
|
2
4
|
import path from "node:path";
|
|
3
|
-
import { createTempApp, tempRoots, writeText } from "../testHelpers";
|
|
5
|
+
import { createTempApp, tempRoots, writeText } from "../test/testHelpers";
|
|
6
|
+
import type { BuildBatchMessage, BuildBatchRequest, BuildBatchResult } from "./buildBatchProtocol";
|
|
4
7
|
import { BuildBatchRunner } from "./buildBatchRunner";
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
//? `run` returns on the result while the released worker may live on in its cwd, which Windows refuses to delete, and
|
|
10
|
+
//? Bun's `rm` ignores `maxRetries` there.
|
|
11
|
+
const removeOnceReleased = async (root: string) => {
|
|
12
|
+
for (let attempt = 1; ; attempt++) {
|
|
13
|
+
try {
|
|
14
|
+
return await rm(root, { recursive: true, force: true });
|
|
15
|
+
} catch (error) {
|
|
16
|
+
if ((error as NodeJS.ErrnoException).code !== "EBUSY" || attempt >= 30) throw error;
|
|
17
|
+
await Bun.sleep(100);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const track = tempRoots(removeOnceReleased);
|
|
22
|
+
const isAlive = (pid: number) => {
|
|
23
|
+
try {
|
|
24
|
+
process.kill(pid, 0);
|
|
25
|
+
return true;
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
7
30
|
|
|
8
31
|
describe("BuildBatchRunner", () => {
|
|
9
32
|
test("reports a boot build the bundler refuses with where each reason sits in the workspace", async () => {
|
|
@@ -62,4 +85,101 @@ setTimeout(() => process.exit(1), 50);
|
|
|
62
85
|
expect(result.errors.css).toBe("css broke");
|
|
63
86
|
expect(result.errors.pages).toContain("exited with code 1");
|
|
64
87
|
}, 30_000);
|
|
88
|
+
|
|
89
|
+
test("releases a worker as soon as its result arrives, so one that holds its exit for that is not left waiting", async () => {
|
|
90
|
+
const { root } = track(await createTempApp("demo"));
|
|
91
|
+
const appDir = path.join(root, "apps/demo");
|
|
92
|
+
const released = path.join(root, "released");
|
|
93
|
+
await writeText(
|
|
94
|
+
path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
|
|
95
|
+
`import fs from "node:fs";
|
|
96
|
+
const { generation } = JSON.parse(process.argv[2]);
|
|
97
|
+
process.once("disconnect", () => fs.writeFileSync(${JSON.stringify(released)}, ""));
|
|
98
|
+
process.send({ type: "build-batch-result", data: { generation, errors: {} } });
|
|
99
|
+
setTimeout(() => process.exit(1), 2_000).unref();
|
|
100
|
+
`,
|
|
101
|
+
);
|
|
102
|
+
const result = await new BuildBatchRunner({ workspaceRoot: root, cwd: appDir }).run({
|
|
103
|
+
appName: "demo",
|
|
104
|
+
workspaceRoot: root,
|
|
105
|
+
repoName: "repo",
|
|
106
|
+
generation: 3,
|
|
107
|
+
needs: ["pages"],
|
|
108
|
+
changedFiles: [],
|
|
109
|
+
pageKeys: null,
|
|
110
|
+
optimizedFonts: null,
|
|
111
|
+
cssAssets: null,
|
|
112
|
+
artifactDir: path.join(appDir, ".akan/artifact"),
|
|
113
|
+
});
|
|
114
|
+
expect(result).toEqual({ generation: 3, errors: {} });
|
|
115
|
+
const deadline = Date.now() + 1_500;
|
|
116
|
+
while (!(await Bun.file(released).exists()) && Date.now() < deadline) await Bun.sleep(20);
|
|
117
|
+
expect(await Bun.file(released).exists()).toBe(true);
|
|
118
|
+
}, 30_000);
|
|
119
|
+
|
|
120
|
+
test("returns a result as it arrives from a worker the release never reaches, then kills that worker", async () => {
|
|
121
|
+
const { root } = track(await createTempApp("demo"));
|
|
122
|
+
const appDir = path.join(root, "apps/demo");
|
|
123
|
+
const sent = path.join(root, "sent");
|
|
124
|
+
await writeText(
|
|
125
|
+
path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
|
|
126
|
+
`import fs from "node:fs";
|
|
127
|
+
const { generation } = JSON.parse(process.argv[2]);
|
|
128
|
+
fs.writeFileSync(${JSON.stringify(sent)}, String(process.pid));
|
|
129
|
+
process.send({ type: "build-batch-result", data: { generation, errors: {} } });
|
|
130
|
+
setTimeout(() => process.exit(0), 5_000);
|
|
131
|
+
`,
|
|
132
|
+
);
|
|
133
|
+
const result = await new BuildBatchRunner({ workspaceRoot: root, cwd: appDir }).run({
|
|
134
|
+
appName: "demo",
|
|
135
|
+
workspaceRoot: root,
|
|
136
|
+
repoName: "repo",
|
|
137
|
+
generation: 5,
|
|
138
|
+
needs: ["pages"],
|
|
139
|
+
changedFiles: [],
|
|
140
|
+
pageKeys: null,
|
|
141
|
+
optimizedFonts: null,
|
|
142
|
+
cssAssets: null,
|
|
143
|
+
artifactDir: path.join(appDir, ".akan/artifact"),
|
|
144
|
+
});
|
|
145
|
+
//? Read before any await: the kill timer cannot fire until this turn's microtasks are done.
|
|
146
|
+
const pid = Number(readFileSync(sent, "utf8"));
|
|
147
|
+
const upAtReturn = isAlive(pid);
|
|
148
|
+
expect(result).toEqual({ generation: 5, errors: {} });
|
|
149
|
+
expect(upAtReturn).toBe(true);
|
|
150
|
+
const deadline = Date.now() + 3_000;
|
|
151
|
+
while (isAlive(pid) && Date.now() < deadline) await Bun.sleep(20);
|
|
152
|
+
expect(isAlive(pid)).toBe(false);
|
|
153
|
+
}, 30_000);
|
|
154
|
+
|
|
155
|
+
test("the build worker stays up after reporting its result until its runner releases it", async () => {
|
|
156
|
+
const { root } = track(await createTempApp("demo", path.join(import.meta.dir, "..", "local")));
|
|
157
|
+
const appDir = path.join(root, "apps/demo");
|
|
158
|
+
const request = {
|
|
159
|
+
appName: "demo",
|
|
160
|
+
workspaceRoot: root,
|
|
161
|
+
repoName: "repo",
|
|
162
|
+
generation: 4,
|
|
163
|
+
needs: [],
|
|
164
|
+
changedFiles: [],
|
|
165
|
+
pageKeys: [],
|
|
166
|
+
optimizedFonts: null,
|
|
167
|
+
cssAssets: null,
|
|
168
|
+
artifactDir: path.join(appDir, ".akan/artifact"),
|
|
169
|
+
} satisfies BuildBatchRequest;
|
|
170
|
+
const { promise: reported, resolve: report } = Promise.withResolvers<BuildBatchResult>();
|
|
171
|
+
const worker = Bun.spawn(["bun", path.join(import.meta.dir, "buildBatch.proc.ts"), JSON.stringify(request)], {
|
|
172
|
+
cwd: appDir,
|
|
173
|
+
stdio: ["ignore", "inherit", "inherit"],
|
|
174
|
+
serialization: "advanced",
|
|
175
|
+
ipc: (message: BuildBatchMessage) => {
|
|
176
|
+
if (message.type === "build-batch-result") report(message.data);
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
expect(await reported).toEqual({ generation: 4, errors: {} });
|
|
180
|
+
const unreleased = await Promise.race([worker.exited.then(() => "exited"), Bun.sleep(300).then(() => "running")]);
|
|
181
|
+
worker.disconnect();
|
|
182
|
+
expect(unreleased).toBe("running");
|
|
183
|
+
expect(await worker.exited).toBe(0);
|
|
184
|
+
}, 30_000);
|
|
65
185
|
});
|
|
@@ -7,6 +7,7 @@ import type { BuildBatchMessage, BuildBatchRequest, BuildBatchResult } from "./b
|
|
|
7
7
|
// their own work (the slow lane, the css queue, the SSR registry's boot build beside them), so a few can overlap.
|
|
8
8
|
// A worker that dies without reporting must not take the watcher down; its needs come back as errors.
|
|
9
9
|
export class BuildBatchRunner {
|
|
10
|
+
static readonly #exitGraceMs = 500;
|
|
10
11
|
#logger = new Logger("BuildBatchRunner");
|
|
11
12
|
#entry: string | null = null;
|
|
12
13
|
#workspaceRoot: string;
|
|
@@ -39,6 +40,7 @@ export class BuildBatchRunner {
|
|
|
39
40
|
const started = Date.now();
|
|
40
41
|
const entry = await this.#resolveEntry();
|
|
41
42
|
let result: BuildBatchResult | null = null;
|
|
43
|
+
const resultArrived = Promise.withResolvers<null>();
|
|
42
44
|
const reported = new Map<string, string | undefined>();
|
|
43
45
|
const payload = request.trace ? { ...request, trace: { ...request.trace, spawnAt: Date.now() } } : request;
|
|
44
46
|
// argv rather than IPC, so the worker starts on its first tick instead of waiting for a handshake.
|
|
@@ -47,16 +49,27 @@ export class BuildBatchRunner {
|
|
|
47
49
|
env: process.env,
|
|
48
50
|
stdio: ["ignore", "inherit", "inherit"],
|
|
49
51
|
serialization: "advanced",
|
|
50
|
-
ipc: (message: BuildBatchMessage | BuilderMessage) => {
|
|
52
|
+
ipc: (message: BuildBatchMessage | BuilderMessage, worker) => {
|
|
51
53
|
if (!message || typeof message !== "object") return;
|
|
52
|
-
if (message.type === "build-batch-result")
|
|
53
|
-
|
|
54
|
+
if (message.type === "build-batch-result") {
|
|
55
|
+
result = message.data;
|
|
56
|
+
// On Bun 1.4 a worker that exits within ms of spawning can lose everything it sent: it exits on this release.
|
|
57
|
+
worker.disconnect();
|
|
58
|
+
//? Bun on Windows may never deliver that release; the worker would hold its arenas for its own 5 s bound.
|
|
59
|
+
const lingering = setTimeout(() => {
|
|
60
|
+
this.#logger.verbose(`[build-batch] worker still up ${BuildBatchRunner.#exitGraceMs}ms after its result`);
|
|
61
|
+
worker.kill("SIGKILL");
|
|
62
|
+
}, BuildBatchRunner.#exitGraceMs);
|
|
63
|
+
void worker.exited.then(() => clearTimeout(lingering));
|
|
64
|
+
resultArrived.resolve(null);
|
|
65
|
+
} else {
|
|
54
66
|
if (message.type === "build-status") reported.set(message.data.phase, message.data.message);
|
|
55
67
|
onMessage(message);
|
|
56
68
|
}
|
|
57
69
|
},
|
|
58
70
|
});
|
|
59
|
-
|
|
71
|
+
//? On the result, not the exit: a worker the release never reaches would make each batch wait for the kill.
|
|
72
|
+
const exitCode = await Promise.race([proc.exited, resultArrived.promise]);
|
|
60
73
|
if (result) {
|
|
61
74
|
this.#logger.verbose(
|
|
62
75
|
`[build-batch] generation=${request.generation} needs=${request.needs.join(",")} done in ${Date.now() - started}ms`,
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
basePhaseMs: Record<string, number>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export class BuilderBoot {
|
|
27
|
+
// Discovery stays in-process because route builds need it live; it is free at boot, building its graph lazily.
|
|
28
|
+
static async buildBootDeps(app: App, runner: BuildBatchRunner): Promise<IncrementalBuilderBootDeps> {
|
|
29
|
+
const result = await runner.run({
|
|
30
|
+
appName: app.name,
|
|
31
|
+
workspaceRoot: app.workspace.workspaceRoot,
|
|
32
|
+
repoName: app.workspace.repoName,
|
|
33
|
+
generation: 0,
|
|
34
|
+
needs: ["base"],
|
|
35
|
+
changedFiles: [],
|
|
36
|
+
pageKeys: null,
|
|
37
|
+
optimizedFonts: null,
|
|
38
|
+
cssAssets: null,
|
|
39
|
+
artifactDir: path.resolve(`${app.cwdPath}/.akan/artifact`),
|
|
40
|
+
});
|
|
41
|
+
// Throws rather than degrading quietly: `main` catches it to enter degraded watch mode.
|
|
42
|
+
if (result.errors.base) throw new Error(result.errors.base);
|
|
43
|
+
if (!result.artifact || !result.optimizedFonts)
|
|
44
|
+
throw new Error("boot build reported success without an artifact; the build worker likely died");
|
|
45
|
+
const discovery = await GraphClientEntryDiscovery.create(app);
|
|
46
|
+
return {
|
|
47
|
+
artifact: result.artifact,
|
|
48
|
+
optimizedFonts: result.optimizedFonts,
|
|
49
|
+
discovery,
|
|
50
|
+
basePhaseMs: result.basePhaseMs ?? {},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// A boot compile error must not kill the builder, the dev server's only file watcher: report it, emit builder-ready
|
|
55
|
+
// so the backend keeps the last-good artifact, and retry the boot build on every change.
|
|
56
|
+
static recoverBoot<Builder>(
|
|
57
|
+
app: App,
|
|
58
|
+
bootError: unknown,
|
|
59
|
+
logger: Logger,
|
|
60
|
+
runner: BuildBatchRunner,
|
|
61
|
+
initialGeneration: number,
|
|
62
|
+
create: (options: IncrementalBuilderOptions) => Builder,
|
|
63
|
+
): Promise<{ builder: Builder; changedFiles: string[] }> {
|
|
64
|
+
const firstMessage = bootError instanceof Error ? bootError.message : String(bootError);
|
|
65
|
+
logger.error(`boot build failed; entering degraded watch mode until the error is fixed: ${firstMessage}`);
|
|
66
|
+
let generation = initialGeneration;
|
|
67
|
+
const sendFailure = (files: string[], message: string) => {
|
|
68
|
+
BuilderChannel.emit({
|
|
69
|
+
type: "build-status",
|
|
70
|
+
data: { generation, phase: "pages", ok: false, files, message: `Boot build failed: ${message}` },
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
sendFailure([], firstMessage);
|
|
74
|
+
BuilderChannel.emit({ type: "builder-ready" });
|
|
75
|
+
// Nothing builds until a save fixes the boot, so the next app's boot need not wait for this one.
|
|
76
|
+
BuilderChannel.emit({ type: "boot-armed" });
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
void (async () => {
|
|
79
|
+
const roots = await new WatchRootResolver(app).resolve();
|
|
80
|
+
const watcher = new HmrWatcher({
|
|
81
|
+
roots,
|
|
82
|
+
logger,
|
|
83
|
+
onBatch: async (batch) => {
|
|
84
|
+
generation += 1;
|
|
85
|
+
const files = [...batch.files].sort();
|
|
86
|
+
try {
|
|
87
|
+
// A broken akan.config.ts caches its import failure; re-import it before rebuilding.
|
|
88
|
+
if (new Set(batch.kinds).has("config")) await app.getConfig({ refresh: true });
|
|
89
|
+
const deps = await BuilderBoot.buildBootDeps(app, runner);
|
|
90
|
+
const builder = create({ app, watch: true, initialGeneration: generation, ...deps });
|
|
91
|
+
watcher.stop();
|
|
92
|
+
logger.info(`boot build recovered generation=${generation}`);
|
|
93
|
+
resolve({ builder, changedFiles: files });
|
|
94
|
+
} catch (err) {
|
|
95
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
96
|
+
logger.error(`boot build retry failed: ${message}`);
|
|
97
|
+
sendFailure(files, message);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
await watcher.start();
|
|
102
|
+
logger.warn(`[degraded] watching ${roots.length} roots for a fix`);
|
|
103
|
+
})().catch(reject);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//? A replacement builder continues past the host's last generation: from 0, the save fixing an error read older than
|
|
108
|
+
//? the failure the tabs hold, and from that generation itself its arming builds' ok did not read as the fix either.
|
|
109
|
+
static initialGeneration(): number {
|
|
110
|
+
const generation = Number(process.env.AKAN_BUILDER_INITIAL_GENERATION);
|
|
111
|
+
return Number.isInteger(generation) && generation > 0 ? generation + 1 : 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -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,5 +1,12 @@
|
|
|
1
|
+
import type { Logger } from "akanjs/common";
|
|
1
2
|
import type { BuilderMessage } from "akanjs/server";
|
|
2
3
|
|
|
4
|
+
//? For the host alone, never relayed: the boot artifact is on disk, and `builder-ready` follows once the watcher is up.
|
|
5
|
+
export interface BaseBuiltMessage {
|
|
6
|
+
type: "base-built";
|
|
7
|
+
phaseMs: Record<string, number>;
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
// `process.exit` drops an ipc write that has not flushed (a natural exit does not), and whether one survives
|
|
4
11
|
// depends on the message's shape as well as its size — so every send reports its flush and `shutdown` drains.
|
|
5
12
|
export class BuilderChannel {
|
|
@@ -7,7 +14,7 @@ export class BuilderChannel {
|
|
|
7
14
|
static readonly #flushTimeoutMs = 5_000;
|
|
8
15
|
static readonly #flushing = new Set<Promise<void>>();
|
|
9
16
|
|
|
10
|
-
static send(message: BuilderMessage): Promise<void> {
|
|
17
|
+
static send(message: BuilderMessage | BaseBuiltMessage): Promise<void> {
|
|
11
18
|
const send = process.send;
|
|
12
19
|
if (!send) return Promise.resolve();
|
|
13
20
|
const flushed = new Promise<void>((resolve) => {
|
|
@@ -24,10 +31,20 @@ export class BuilderChannel {
|
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
// Tracked like `send`: for an event nobody awaits, `drain` is all that stands between it and the exit.
|
|
27
|
-
static emit(message: BuilderMessage): void {
|
|
34
|
+
static emit(message: BuilderMessage | BaseBuiltMessage): void {
|
|
28
35
|
void BuilderChannel.send(message);
|
|
29
36
|
}
|
|
30
37
|
|
|
38
|
+
//? `AKAN_DEV_BUILDER_READY_GATE` is a test hook: the dev-stability suite holds a replacement short of ready.
|
|
39
|
+
static async announceReady(logger: Logger): Promise<void> {
|
|
40
|
+
const gate = process.env.AKAN_DEV_BUILDER_READY_GATE;
|
|
41
|
+
if (gate && !(await Bun.file(gate).exists())) {
|
|
42
|
+
logger.warn(`AKAN_DEV_BUILDER_READY_GATE is set: holding builder-ready until ${gate} exists`);
|
|
43
|
+
while (!(await Bun.file(gate).exists())) await Bun.sleep(100);
|
|
44
|
+
}
|
|
45
|
+
BuilderChannel.emit({ type: "builder-ready" });
|
|
46
|
+
}
|
|
47
|
+
|
|
31
48
|
// Loops because `#reportMetrics` can send from a work item's `finally` after the drain has begun.
|
|
32
49
|
static async drain(): Promise<number> {
|
|
33
50
|
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
|
+
}
|