@akanjs/devkit 3.2.0-rc.3 → 3.2.0-rc.30
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 +367 -11
- 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 +257 -1
- package/akanApp/akanApp.host.ts +146 -1223
- 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/devHostPolicy.test.ts +11 -11
- package/akanApp/devHostPolicy.ts +2 -4
- 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 +24 -1
- package/akanConfig/akanConfig.ts +10 -10
- package/akanConfig/akanWorkspaceConfig.ts +1 -1
- package/akanConfig/productionLockfile.ts +1 -1
- package/apiReport/apiDeclarationPrinter.ts +120 -0
- package/apiReport/apiReport.test.ts +526 -0
- package/apiReport/apiReport.ts +232 -0
- package/apiReport/apiReportDiff.ts +160 -0
- package/apiReport/apiReportPolicy.ts +65 -0
- package/apiReport/apiTargets.ts +311 -0
- package/apiReport/changesetBump.ts +19 -0
- package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +21 -0
- package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +10 -49
- package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +74 -7
- package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +20 -15
- package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
- package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +48 -12
- package/{routeJsBudget.ts → app/routeJsBudget.ts} +90 -27
- 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 +21 -4
- 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/akanCodePaths.ts +1 -1
- package/codeAgent/agent/akanSystemPrompt.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +1 -1
- package/codeAgent/skills/akan-debug/SKILL.md +10 -3
- package/codeAgent/skills/akan-err/SKILL.md +7 -0
- package/codeAgent/skills/akan-mcp/SKILL.md +14 -2
- package/codeAgent/skills/akan-scaffold/SKILL.md +2 -2
- package/codeAgent/skills/akan-transport/SKILL.md +2 -0
- package/codeAgent/skills/akan-validate/SKILL.md +1 -0
- package/codeAgent/tools/AkanCli.ts +1 -1
- package/codeAgent/tools/AkanToolPack.ts +1 -1
- package/codeAgent/tools/McpClient.ts +28 -6
- package/codeAgent/tools/McpToolPack.ts +1 -1
- package/codeAgent/tools/akanCodePlugins.test.ts +14 -2
- package/commandDecorators/argMeta.ts +4 -0
- package/commandDecorators/cliError.ts +72 -0
- package/commandDecorators/command.ts +165 -91
- package/commandDecorators/commandBuilder.ts +1 -1
- package/commandDecorators/commandDecorators.test.ts +191 -16
- package/commandDecorators/exitCodeError.ts +6 -7
- package/commandDecorators/index.ts +1 -0
- package/commandDecorators/targetMeta.ts +1 -0
- package/commandDecorators/workspaceVersionCheck.test.ts +1 -1
- package/commandDecorators/workspaceVersionCheck.ts +1 -1
- 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} +32 -262
- package/context/akanMcpToolError.ts +16 -0
- 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 +39 -0
- package/context/doctor/recipeIndexCheck.ts +87 -0
- package/context/doctor/rootShapeCheck.ts +55 -0
- package/context/doctor/workflowScope.ts +97 -0
- package/{constantFieldNames.test.ts → context/moduleFieldNames.test.ts} +24 -2
- package/context/moduleFieldNames.ts +25 -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 +17 -5
- package/frontendBuild/allRoutesBuilder.ts +24 -6
- package/frontendBuild/autoImportSync.test.ts +1 -1
- package/frontendBuild/autoImportSync.ts +1 -1
- package/frontendBuild/buildRouteClient.test.ts +1 -1
- package/frontendBuild/bundleDefine.ts +2 -0
- package/frontendBuild/clientBuildTypes.ts +5 -2
- package/frontendBuild/clientEntriesBundler.test.ts +1 -1
- package/frontendBuild/clientEntryDiscovery.test.ts +28 -0
- package/frontendBuild/clientEntryDiscovery.ts +25 -6
- package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
- package/frontendBuild/csrDevArtifactWriter.ts +1 -1
- package/frontendBuild/cssCompiler.test.ts +1 -1
- 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 +148 -0
- 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 +1 -1
- package/frontendBuild/serverGraphFile.ts +1 -1
- package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
- package/frontendBuild/ssrBaseArtifactBuilder.test.ts +26 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +23 -19
- package/frontendBuild/ssrDevBundler.test.ts +1 -1
- package/frontendBuild/vendorImportScanner.test.ts +25 -4
- package/frontendBuild/vendorImportScanner.ts +25 -10
- 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 +108 -1
- 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.host.test.ts +30 -1
- package/incrementalBuilder/incrementalBuilder.host.ts +10 -22
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +93 -2
- package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
- package/incrementalBuilder/ssrRegistry.ts +278 -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/lint/no-web-only-api-outside-webkit.grit +3 -3
- 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 +167 -3
- 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/PlatformTestRun.test.ts +1 -1
- package/platformTest/TestSnapshot.test.ts +1 -1
- package/preview/PreviewView.ts +32 -13
- package/preview/previewView.test.ts +33 -3
- 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} +1 -1
- package/{qualityScanner.ts → quality/qualityScanner.ts} +8 -8
- package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
- 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 +1 -1
- package/typecheck/projectTypecheck.ts +6 -2
- package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
- package/{typeChecker.ts → typecheck/typeChecker.ts} +1 -1
- package/typecheck/typecheck.proc.ts +4 -3
- package/typecheck/typecheckFailure.ts +7 -2
- package/util/errorReport.ts +66 -0
- package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
- package/workflow/artifacts.ts +8 -7
- 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 +93 -0
- package/workflow/guardCatalog.test.ts +1 -1
- package/workflow/index.ts +1 -0
- 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/plainName.ts +16 -3
- package/workflow/plan.ts +14 -2
- 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 -1105
- 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 -1084
- package/constantFieldNames.ts +0 -18
- package/executors.ts +0 -1749
- /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,448 @@
|
|
|
1
|
+
import { cp as cpEntry, lstat, mkdir, readdir as readDirEntries, realpath, symlink } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import type { AkanPlugin, AkanSyncContext } from "akanjs";
|
|
5
|
+
import { isRouteSourceFile, parseRouteModuleKey, validatePageSourceFile, validateSubRoutePageKey } from "akanjs/common";
|
|
6
|
+
import { AkanAppConfig, decreaseBuildNum, increaseBuildNum } from "../akanConfig";
|
|
7
|
+
import type { RouteSourceInfo } from "../app/routeSourceValidator";
|
|
8
|
+
import { getRootBoundarySegments, isRootBoundarySegments } from "../artifact/implicitRootLayout";
|
|
9
|
+
import { FileSys } from "../util/fileSys";
|
|
10
|
+
import type { AppInfo } from "../workspace/scanInfo";
|
|
11
|
+
import { Executor, execEmoji } from "./executor";
|
|
12
|
+
import { LibExecutor } from "./libExecutor";
|
|
13
|
+
import { type NamedExecutorOptions, SysExecutor } from "./sysExecutor";
|
|
14
|
+
import { WorkspaceExecutor } from "./workspaceExecutor";
|
|
15
|
+
|
|
16
|
+
export interface PageRoot {
|
|
17
|
+
/** App-relative location of the route files, i.e. the symlink for a synced lib. */
|
|
18
|
+
dir: string;
|
|
19
|
+
/** Where the files actually live, which is what a file watcher reports. */
|
|
20
|
+
realDir: string;
|
|
21
|
+
/** Prefix that turns a `dir`-relative path into an app page key (empty for the app's own `page`). */
|
|
22
|
+
keyPrefix: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface AppRouteSource {
|
|
26
|
+
key: string;
|
|
27
|
+
absPath: string;
|
|
28
|
+
info: RouteSourceInfo;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class AppExecutor extends SysExecutor {
|
|
32
|
+
// Lazy: the validator pulls in `typescript` (~65MB resident).
|
|
33
|
+
static #routeSourceValidator: typeof import("../app/routeSourceValidator").RouteSourceValidator | null = null;
|
|
34
|
+
static async #getRouteSourceValidator() {
|
|
35
|
+
AppExecutor.#routeSourceValidator ??= (await import("../app/routeSourceValidator")).RouteSourceValidator;
|
|
36
|
+
return AppExecutor.#routeSourceValidator;
|
|
37
|
+
}
|
|
38
|
+
dist: Executor;
|
|
39
|
+
override emoji = execEmoji.app;
|
|
40
|
+
constructor({ workspace, name }: NamedExecutorOptions) {
|
|
41
|
+
super({ workspace, name, type: "app" });
|
|
42
|
+
this.dist = new Executor(`dist/${name}`, `${this.workspace.workspaceRoot}/dist/apps/${name}`);
|
|
43
|
+
}
|
|
44
|
+
static from(executor: SysExecutor | WorkspaceExecutor, name: string) {
|
|
45
|
+
return new AppExecutor({ workspace: executor instanceof WorkspaceExecutor ? executor : executor.workspace, name });
|
|
46
|
+
}
|
|
47
|
+
//* Not dev output: the downloaded `bin` sources.
|
|
48
|
+
static readonly #keptOnStart = [path.join(".akan", "cache", "bin")];
|
|
49
|
+
//* Native builds moved to dist/native/<app>; the old folder may hold a signed release nobody uploaded yet.
|
|
50
|
+
static readonly #legacyNative = path.join(".akan", "native");
|
|
51
|
+
async #removeDevOutput(dir = ".akan") {
|
|
52
|
+
const entries = await readDirEntries(this.getPath(dir)).catch(() => [] as string[]);
|
|
53
|
+
await Promise.all(
|
|
54
|
+
entries.map(async (name) => {
|
|
55
|
+
const entry = path.join(dir, name);
|
|
56
|
+
if (entry === AppExecutor.#legacyNative) {
|
|
57
|
+
this.logger.warn(
|
|
58
|
+
`apps/${this.name}/.akan/native holds native builds from before they moved to dist/native/${this.name}: upload any release waiting in its updates folders, then delete it.`,
|
|
59
|
+
);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (AppExecutor.#keptOnStart.includes(entry)) return;
|
|
63
|
+
if (AppExecutor.#keptOnStart.some((kept) => kept.startsWith(`${entry}${path.sep}`)))
|
|
64
|
+
return await this.#removeDevOutput(entry);
|
|
65
|
+
await this.removeDir(entry);
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
getEnv() {
|
|
70
|
+
return WorkspaceExecutor.getBaseDevEnv().env;
|
|
71
|
+
}
|
|
72
|
+
/** `AKAN_DEV_PORT` pins it; the derived port moves whenever an app directory appears or disappears. */
|
|
73
|
+
async getDevPort() {
|
|
74
|
+
const pinned = Number(process.env.AKAN_DEV_PORT);
|
|
75
|
+
if (Number.isInteger(pinned) && pinned > 0 && pinned <= 65_535) return pinned;
|
|
76
|
+
const basePort = 8282;
|
|
77
|
+
const appNames = (await this.workspace.getApps()).sort((a, b) => a.localeCompare(b));
|
|
78
|
+
const appIndex = Math.max(appNames.indexOf(this.name), 0);
|
|
79
|
+
const portOffset = WorkspaceExecutor.getBaseDevEnv().portOffset;
|
|
80
|
+
return basePort + appIndex + portOffset;
|
|
81
|
+
}
|
|
82
|
+
getCommandEnv(env: Record<string, string> = {}): Record<string, string> {
|
|
83
|
+
const { portOffset, repoName, serveDomain } = WorkspaceExecutor.getBaseDevEnv();
|
|
84
|
+
const PORT = (8282 + portOffset).toString();
|
|
85
|
+
return {
|
|
86
|
+
...process.env,
|
|
87
|
+
AKAN_PUBLIC_REPO_NAME: repoName,
|
|
88
|
+
AKAN_PUBLIC_SERVE_DOMAIN: serveDomain,
|
|
89
|
+
AKAN_PUBLIC_APP_NAME: this.name,
|
|
90
|
+
AKAN_WORKSPACE_ROOT: this.workspace.workspaceRoot,
|
|
91
|
+
NODE_NO_WARNINGS: "1",
|
|
92
|
+
PORT,
|
|
93
|
+
AKAN_PUBLIC_CLIENT_PORT: PORT,
|
|
94
|
+
...(portOffset ? { AKAN_PUBLIC_SERVER_PORT: PORT } : {}),
|
|
95
|
+
...env,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async getDatabaseModeEnv() {
|
|
99
|
+
const akanConfig = await this.getConfig();
|
|
100
|
+
return {
|
|
101
|
+
AKAN_DATABASE_MODE: akanConfig.resolveDatabaseMode(),
|
|
102
|
+
AKAN_DATABASE_MODES: akanConfig.database.modes.join(","),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async prepareCommand(type: "build" | "start") {
|
|
106
|
+
const akanConfig = await this.getConfig();
|
|
107
|
+
const routeEnv = {
|
|
108
|
+
AKAN_PUBLIC_BASE_PATHS: [...akanConfig.basePaths].join(","),
|
|
109
|
+
AKAN_PUBLIC_API_PREFIX: akanConfig.api.prefix,
|
|
110
|
+
AKAN_PUBLIC_WS_PREFIX: akanConfig.api.websocketPrefix,
|
|
111
|
+
...(await this.getDatabaseModeEnv()),
|
|
112
|
+
};
|
|
113
|
+
Object.assign(process.env, routeEnv);
|
|
114
|
+
if (type === "build") {
|
|
115
|
+
//* `scanSync` read the route set unfiltered; drop the cache so build phases re-read it without dev-only routes.
|
|
116
|
+
this.#excludeDevOnlyPages = true;
|
|
117
|
+
this.#pageKeys = null;
|
|
118
|
+
await this.dist.removeDir(this.dist.cwdPath);
|
|
119
|
+
await Promise.all([this.dist.mkdir("private"), this.dist.mkdir("public")]);
|
|
120
|
+
//* Lib assets are symlinks, which neither the docker context nor the release tarball follows out of dist.
|
|
121
|
+
//* Only the web router reads `public/`, so an api-only build leaves it out.
|
|
122
|
+
await Promise.all([
|
|
123
|
+
this.cp("private", `${this.dist.cwdPath}/private`, { dereference: true }),
|
|
124
|
+
...(akanConfig.web.ssr ? [this.cp("public", `${this.dist.cwdPath}/public`, { dereference: true })] : []),
|
|
125
|
+
]);
|
|
126
|
+
} else {
|
|
127
|
+
await this.#removeDevOutput();
|
|
128
|
+
//? `akan start` keeps the full dev surface: the incremental builder is also the file watcher.
|
|
129
|
+
if (!akanConfig.web.ssr || !akanConfig.web.csr)
|
|
130
|
+
this.logger.verbose(
|
|
131
|
+
`akan.config.ts disables web.${!akanConfig.web.ssr ? "ssr" : "csr"}; \`akan start\` still serves it, \`akan build\` will not`,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
//? Bun auto-loads `.env`, so NODE_ENV=production can arrive unexported and send the dev server to the production
|
|
135
|
+
//? route cache. Set on `process.env` because the builder runs here and bakes NODE_ENV into its bundles.
|
|
136
|
+
if (type === "start") process.env.NODE_ENV = "development";
|
|
137
|
+
const devPort = type === "start" ? (await this.getDevPort()).toString() : undefined;
|
|
138
|
+
const env = this.getCommandEnv({
|
|
139
|
+
AKAN_COMMAND_TYPE: type,
|
|
140
|
+
...routeEnv,
|
|
141
|
+
...(devPort ? { PORT: devPort, AKAN_PUBLIC_CLIENT_PORT: devPort, AKAN_PUBLIC_SERVER_PORT: devPort } : {}),
|
|
142
|
+
});
|
|
143
|
+
// `build` runs its phases in this process, so the env is published here (only AKAN_PUBLIC_* reaches bundles).
|
|
144
|
+
// Ports and the operation mode are dropped: `define` would bake them in and outrank the container's own values.
|
|
145
|
+
if (type === "build") {
|
|
146
|
+
const buildEnv = { ...env };
|
|
147
|
+
for (const key of ["AKAN_PUBLIC_CLIENT_PORT", "AKAN_PUBLIC_SERVER_PORT", "AKAN_PUBLIC_OPERATION_MODE"]) {
|
|
148
|
+
delete buildEnv[key];
|
|
149
|
+
delete process.env[key];
|
|
150
|
+
}
|
|
151
|
+
Object.assign(process.env, buildEnv);
|
|
152
|
+
}
|
|
153
|
+
return { env };
|
|
154
|
+
}
|
|
155
|
+
#publicEnv: Record<string, string> | null = null;
|
|
156
|
+
getPublicEnv(...patterns: string[]) {
|
|
157
|
+
if (this.#publicEnv) return this.#publicEnv;
|
|
158
|
+
const searchPatterns = [...patterns, "AKAN_PUBLIC_*"];
|
|
159
|
+
const regexes = searchPatterns.map(
|
|
160
|
+
(pattern) =>
|
|
161
|
+
new RegExp(
|
|
162
|
+
`^${pattern
|
|
163
|
+
.split("*")
|
|
164
|
+
.map((part) => part.replace(/[.+^${}()|[\]\\?]/g, "\\$&"))
|
|
165
|
+
.join(".*")}$`,
|
|
166
|
+
),
|
|
167
|
+
);
|
|
168
|
+
const publicEnv: Record<string, string> = {};
|
|
169
|
+
for (const [k, v] of Object.entries(process.env)) {
|
|
170
|
+
if (typeof v !== "string") continue;
|
|
171
|
+
if (regexes.some((r) => r.test(k))) publicEnv[k] = v;
|
|
172
|
+
}
|
|
173
|
+
this.#publicEnv = publicEnv;
|
|
174
|
+
return publicEnv;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
#akanConfig: AkanAppConfig | null = null;
|
|
178
|
+
override async getConfig({ refresh }: { refresh?: boolean } = {}) {
|
|
179
|
+
if (this.#akanConfig && !refresh) return this.#akanConfig;
|
|
180
|
+
this.#akanConfig = await AkanAppConfig.from(this, { bustImportCache: refresh });
|
|
181
|
+
return this.#akanConfig;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
#pageKeys: string[] | null = null;
|
|
185
|
+
#routeSources: AppRouteSource[] = [];
|
|
186
|
+
#excludeDevOnlyPages = false;
|
|
187
|
+
async getPageKeys({ refresh }: { refresh?: boolean } = {}): Promise<string[]> {
|
|
188
|
+
if (this.#pageKeys && !refresh) return this.#pageKeys;
|
|
189
|
+
const akanConfig = await this.getConfig();
|
|
190
|
+
const glob = new Bun.Glob("**/*");
|
|
191
|
+
const pageKeys: string[] = [];
|
|
192
|
+
const owners = new Map<string, { absPath: string; fromLib: boolean }>();
|
|
193
|
+
const devOnlyKeys = new Set<string>();
|
|
194
|
+
const devOnlyDirs: string[] = [];
|
|
195
|
+
const pageRoots = await this.getPageRoots();
|
|
196
|
+
const routeSources: AppRouteSource[] = [];
|
|
197
|
+
const libKeyPrefixes = pageRoots.map((root) => root.keyPrefix).filter(Boolean);
|
|
198
|
+
for (const root of pageRoots) {
|
|
199
|
+
if (!(await FileSys.dirExists(root.dir))) continue;
|
|
200
|
+
for await (const rel of glob.scan({
|
|
201
|
+
cwd: root.dir,
|
|
202
|
+
absolute: false,
|
|
203
|
+
onlyFiles: true,
|
|
204
|
+
})) {
|
|
205
|
+
const segments = rel.split(path.sep);
|
|
206
|
+
if (segments.some((s) => s === "node_modules")) continue;
|
|
207
|
+
const posix = `${root.keyPrefix}${segments.join("/")}`;
|
|
208
|
+
//* A lib folder that is a copy rather than a link (the Windows fallback) is walked into from `page` too.
|
|
209
|
+
if (!root.keyPrefix && libKeyPrefixes.some((prefix) => posix.startsWith(prefix))) continue;
|
|
210
|
+
const absPath = path.join(root.dir, ...segments);
|
|
211
|
+
validatePageSourceFile(posix, { filePath: absPath });
|
|
212
|
+
if (!isRouteSourceFile(posix)) continue;
|
|
213
|
+
const key = `./${posix}`;
|
|
214
|
+
validateSubRoutePageKey(key, akanConfig.basePaths, {
|
|
215
|
+
appName: this.name,
|
|
216
|
+
filePath: absPath,
|
|
217
|
+
});
|
|
218
|
+
const parsed = parseRouteModuleKey(key);
|
|
219
|
+
if (parsed.isInternalRootLayout) {
|
|
220
|
+
throw new Error(`[route-convention] __root_layout is reserved for Akan.js generated root layout: ${absPath}`);
|
|
221
|
+
}
|
|
222
|
+
const fromLib = !!root.keyPrefix;
|
|
223
|
+
const routeId = `${parsed.kind}:${parsed.pattern}`;
|
|
224
|
+
const owner = owners.get(routeId);
|
|
225
|
+
//* App-owned routes may collide (two groups, one pattern); a synced lib cannot see the other side.
|
|
226
|
+
if (owner && (owner.fromLib || fromLib)) {
|
|
227
|
+
throw new Error(
|
|
228
|
+
`[route-convention] duplicate ${parsed.kind} route "${parsed.pattern}" in app "${this.name}":\n- ${owner.absPath}\n- ${absPath}`,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
if (!owner) owners.set(routeId, { absPath, fromLib });
|
|
232
|
+
const layoutSegments = getRootBoundarySegments(key);
|
|
233
|
+
const isRootLayout = layoutSegments !== null && isRootBoundarySegments(layoutSegments, akanConfig.basePaths);
|
|
234
|
+
const routeSource = await Bun.file(absPath).text();
|
|
235
|
+
const validator = await AppExecutor.#getRouteSourceValidator();
|
|
236
|
+
if (parsed.kind === "overrides") validator.validateOverridesSourceExports(routeSource, absPath);
|
|
237
|
+
else {
|
|
238
|
+
const info = validator.validateRouteSourceExports(routeSource, absPath, parsed.kind, {
|
|
239
|
+
rootLayout: isRootLayout,
|
|
240
|
+
pattern: parsed.pattern,
|
|
241
|
+
});
|
|
242
|
+
routeSources.push({ key, absPath, info });
|
|
243
|
+
if (info.devOnly) {
|
|
244
|
+
devOnlyKeys.add(key);
|
|
245
|
+
//* A dev-only layout takes its whole subtree, or its pages would ship without their chrome.
|
|
246
|
+
if (parsed.kind === "layout") devOnlyDirs.push(key.replace(/[^/]+$/, ""));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
pageKeys.push(key);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
pageKeys.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
253
|
+
this.#routeSources = routeSources.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
|
|
254
|
+
this.#pageKeys = this.#excludeDevOnlyPages ? this.#dropDevOnlyPages(pageKeys, devOnlyKeys, devOnlyDirs) : pageKeys;
|
|
255
|
+
return this.#pageKeys;
|
|
256
|
+
}
|
|
257
|
+
/** Each page and layout file `getPageKeys` read, with what its chain declares; overrides files are not listed. */
|
|
258
|
+
async getRouteSources({ refresh }: { refresh?: boolean } = {}): Promise<AppRouteSource[]> {
|
|
259
|
+
await this.getPageKeys({ refresh });
|
|
260
|
+
return this.#routeSources;
|
|
261
|
+
}
|
|
262
|
+
#dropDevOnlyPages(pageKeys: string[], devOnlyKeys: Set<string>, devOnlyDirs: string[]): string[] {
|
|
263
|
+
if (!devOnlyKeys.size) return pageKeys;
|
|
264
|
+
const isDevOnly = (key: string) => devOnlyKeys.has(key) || devOnlyDirs.some((dir) => key.startsWith(dir));
|
|
265
|
+
const dropped = pageKeys.filter(isDevOnly);
|
|
266
|
+
this.verbose(`[route] excluded ${dropped.length} dev-only route file(s) from the build: ${dropped.join(", ")}`);
|
|
267
|
+
return pageKeys.filter((key) => !isDevOnly(key));
|
|
268
|
+
}
|
|
269
|
+
/** Lib roots are the `syncPages` symlinks, listed because neither Bun's glob nor TS `include` crosses one. */
|
|
270
|
+
async getPageRoots(): Promise<PageRoot[]> {
|
|
271
|
+
const akanConfig = await this.getConfig();
|
|
272
|
+
const pageDir = `${this.cwdPath}/page`;
|
|
273
|
+
const roots: PageRoot[] = [{ dir: pageDir, realDir: pageDir, keyPrefix: "" }];
|
|
274
|
+
for (const parent of AppExecutor.#pageLibParents(akanConfig.basePaths)) {
|
|
275
|
+
const libsDir = `${pageDir}/${parent}${AppExecutor.#pageLibsDir}`;
|
|
276
|
+
const entries = await readDirEntries(libsDir).catch(() => [] as string[]);
|
|
277
|
+
for (const entry of entries.sort()) {
|
|
278
|
+
const dir = `${libsDir}/${entry}`;
|
|
279
|
+
if (!(await FileSys.dirExists(dir))) continue;
|
|
280
|
+
roots.push({ dir, realDir: await realpath(dir), keyPrefix: `${parent}${AppExecutor.#pageLibsDir}/${entry}/` });
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return roots;
|
|
284
|
+
}
|
|
285
|
+
setPageKeys(pageKeys: string[]) {
|
|
286
|
+
this.#pageKeys = pageKeys;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
static readonly #pageLibsDir = "(libs)";
|
|
290
|
+
static #pageLibParents(basePaths: Iterable<string>): string[] {
|
|
291
|
+
const parents = [...basePaths].map((basePath) => `${basePath}/`);
|
|
292
|
+
return parents.length ? parents : [""];
|
|
293
|
+
}
|
|
294
|
+
/** Whether the linked page set changed, which makes the app's route keys stale. */
|
|
295
|
+
async syncPages(libDeps: string[]): Promise<boolean> {
|
|
296
|
+
const akanConfig = await this.getConfig();
|
|
297
|
+
const parents = AppExecutor.#pageLibParents(akanConfig.basePaths);
|
|
298
|
+
const libs = await this.#resolvePageLibs(akanConfig.syncPageLibs, libDeps);
|
|
299
|
+
//* Not `getPageRoots`: it drops links whose target is gone, exactly the ones a sync must clean up.
|
|
300
|
+
const linked = (
|
|
301
|
+
await Promise.all(
|
|
302
|
+
parents.map(async (parent) => {
|
|
303
|
+
const libsDir = `${this.cwdPath}/page/${parent}${AppExecutor.#pageLibsDir}`;
|
|
304
|
+
const entries = await readDirEntries(libsDir).catch(() => [] as string[]);
|
|
305
|
+
return entries.map((entry) => `${parent}${AppExecutor.#pageLibsDir}/${entry}/`);
|
|
306
|
+
}),
|
|
307
|
+
)
|
|
308
|
+
).flat();
|
|
309
|
+
const wanted = parents.flatMap((parent) => libs.map((lib) => `${parent}${AppExecutor.#pageLibsDir}/(${lib})/`));
|
|
310
|
+
//* A copy — the Windows fallback when a junction is refused — does not follow its lib, so only links are current.
|
|
311
|
+
const isLink = async (key: string) =>
|
|
312
|
+
(await lstat(`${this.cwdPath}/page/${key.slice(0, -1)}`).catch(() => null))?.isSymbolicLink() ?? false;
|
|
313
|
+
if (linked.sort().join(",") === wanted.sort().join(",") && (await Promise.all(linked.map(isLink))).every(Boolean))
|
|
314
|
+
return false;
|
|
315
|
+
await Promise.all(
|
|
316
|
+
parents.map((parent) => this.removeDir(`${this.cwdPath}/page/${parent}${AppExecutor.#pageLibsDir}`)),
|
|
317
|
+
);
|
|
318
|
+
for (const parent of parents) {
|
|
319
|
+
if (!libs.length) break;
|
|
320
|
+
const libsDir = `${this.cwdPath}/page/${parent}${AppExecutor.#pageLibsDir}`;
|
|
321
|
+
await this.mkdir(libsDir);
|
|
322
|
+
await Promise.all(
|
|
323
|
+
libs.map((lib) =>
|
|
324
|
+
AppExecutor.#linkLibAsset(`${this.workspace.workspaceRoot}/libs/${lib}/page`, `${libsDir}/(${lib})`),
|
|
325
|
+
),
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
this.#pageKeys = null;
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
async #resolvePageLibs(syncPageLibs: string[] | boolean, libDeps: string[]): Promise<string[]> {
|
|
332
|
+
if (!syncPageLibs) return [];
|
|
333
|
+
const hasPageDir = async (lib: string) =>
|
|
334
|
+
await FileSys.dirExists(`${this.workspace.workspaceRoot}/libs/${lib}/page`);
|
|
335
|
+
if (syncPageLibs === true) {
|
|
336
|
+
const libs: string[] = [];
|
|
337
|
+
for (const lib of libDeps) if (await hasPageDir(lib)) libs.push(lib);
|
|
338
|
+
return libs;
|
|
339
|
+
}
|
|
340
|
+
for (const lib of syncPageLibs) {
|
|
341
|
+
if (!libDeps.includes(lib))
|
|
342
|
+
throw new Error(
|
|
343
|
+
`[syncPageLibs] app "${this.name}" lists lib "${lib}" but does not depend on it (deps: ${libDeps.join(", ") || "none"})`,
|
|
344
|
+
);
|
|
345
|
+
if (!(await hasPageDir(lib)))
|
|
346
|
+
throw new Error(`[syncPageLibs] app "${this.name}" lists lib "${lib}" but libs/${lib}/page does not exist`);
|
|
347
|
+
}
|
|
348
|
+
return [...syncPageLibs];
|
|
349
|
+
}
|
|
350
|
+
async syncAssets(libDeps: string[]) {
|
|
351
|
+
await Promise.all((["public", "private"] as const).map((facet) => this.#syncLibAssets(facet, libDeps)));
|
|
352
|
+
}
|
|
353
|
+
async #syncLibAssets(facet: "public" | "private", libDeps: string[]) {
|
|
354
|
+
const libLinkPath = `${this.cwdPath}/${facet}/libs`;
|
|
355
|
+
await this.removeDir(libLinkPath);
|
|
356
|
+
const targetDeps = [] as string[];
|
|
357
|
+
for (const dep of libDeps) {
|
|
358
|
+
if (await this.exists(`${this.workspace.workspaceRoot}/libs/${dep}/${facet}`)) targetDeps.push(dep);
|
|
359
|
+
}
|
|
360
|
+
if (!targetDeps.length) return;
|
|
361
|
+
await this.mkdir(libLinkPath);
|
|
362
|
+
await Promise.all(
|
|
363
|
+
targetDeps.map((dep) =>
|
|
364
|
+
AppExecutor.#linkLibAsset(`${this.workspace.workspaceRoot}/libs/${dep}/${facet}`, `${libLinkPath}/${dep}`),
|
|
365
|
+
),
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
static async #linkLibAsset(targetPath: string, linkPath: string) {
|
|
369
|
+
//* Relative, so it survives a remount (containers, CI); a Windows junction needs an absolute target.
|
|
370
|
+
const isWindows = process.platform === "win32";
|
|
371
|
+
try {
|
|
372
|
+
const target = isWindows ? targetPath : path.relative(path.dirname(linkPath), targetPath);
|
|
373
|
+
await symlink(target, linkPath, isWindows ? "junction" : "dir");
|
|
374
|
+
} catch (error) {
|
|
375
|
+
if (!isWindows) throw error;
|
|
376
|
+
await mkdir(linkPath, { recursive: true });
|
|
377
|
+
await cpEntry(targetPath, linkPath, { recursive: true, dereference: true, force: true });
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
async scanSync({ refresh = false, write = true }: { refresh?: boolean; write?: boolean } = {}) {
|
|
381
|
+
const scanInfo = (await this.scan({
|
|
382
|
+
refresh,
|
|
383
|
+
write,
|
|
384
|
+
writeLib: write,
|
|
385
|
+
})) as AppInfo;
|
|
386
|
+
if (write) await this.syncAssets(scanInfo.getScanResult().libDeps);
|
|
387
|
+
//* `scan` read the routes off the page tree this sync may be about to change, so re-read them.
|
|
388
|
+
if (write && (await this.syncPages(scanInfo.getScanResult().libDeps)))
|
|
389
|
+
scanInfo.setRoutes(await this.getPageKeys({ refresh: true }));
|
|
390
|
+
if (write) await this.#runPluginSyncAssets();
|
|
391
|
+
return scanInfo;
|
|
392
|
+
}
|
|
393
|
+
async #runPluginSyncAssets() {
|
|
394
|
+
const plugins = await this.collectPlugins();
|
|
395
|
+
if (!plugins.some((plugin) => plugin.syncAssets)) return;
|
|
396
|
+
const ctx = this.#makeSyncContext();
|
|
397
|
+
for (const plugin of plugins) await plugin.syncAssets?.(ctx);
|
|
398
|
+
}
|
|
399
|
+
#makeSyncContext(): AkanSyncContext {
|
|
400
|
+
return {
|
|
401
|
+
appName: this.name,
|
|
402
|
+
appPath: this.cwdPath,
|
|
403
|
+
executor: this,
|
|
404
|
+
getPath: (rel) => this.getPath(rel),
|
|
405
|
+
fileExists: (rel) => FileSys.fileExists(this.getPath(rel)),
|
|
406
|
+
readFile: (rel) => this.readFile(rel),
|
|
407
|
+
writeFile: async (rel, content, opts) => {
|
|
408
|
+
await this.writeFile(rel, content, opts);
|
|
409
|
+
},
|
|
410
|
+
readEnvClient: async () => {
|
|
411
|
+
const envClientPath = path.join(this.cwdPath, "env", "env.client.ts");
|
|
412
|
+
if (!(await FileSys.fileExists(envClientPath))) return null;
|
|
413
|
+
try {
|
|
414
|
+
const envUrl = pathToFileURL(envClientPath);
|
|
415
|
+
envUrl.searchParams.set("t", String(Date.now()));
|
|
416
|
+
const envModule = (await import(envUrl.href)) as { env?: Record<string, unknown> };
|
|
417
|
+
return envModule.env ?? null;
|
|
418
|
+
} catch {
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
},
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
async collectPlugins(): Promise<AkanPlugin[]> {
|
|
425
|
+
const scanInfo = (await this.scan({ write: false })) as AppInfo;
|
|
426
|
+
const libDeps = scanInfo.getLibs();
|
|
427
|
+
const appConfig = await this.getConfig();
|
|
428
|
+
const collected: AkanPlugin[] = [...appConfig.plugins];
|
|
429
|
+
for (const libName of libDeps) {
|
|
430
|
+
const libConfig = await LibExecutor.from(this, libName)
|
|
431
|
+
.getConfig()
|
|
432
|
+
.catch(() => null);
|
|
433
|
+
if (libConfig) collected.push(...libConfig.plugins);
|
|
434
|
+
}
|
|
435
|
+
const seen = new Set<string>();
|
|
436
|
+
return collected.filter((plugin) => {
|
|
437
|
+
if (seen.has(plugin.name)) return false;
|
|
438
|
+
seen.add(plugin.name);
|
|
439
|
+
return true;
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
async increaseBuildNum() {
|
|
443
|
+
await increaseBuildNum(this);
|
|
444
|
+
}
|
|
445
|
+
async decreaseBuildNum() {
|
|
446
|
+
await decreaseBuildNum(this);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//? A backslash is a path separator on Windows but an escape in a POSIX shell, so only there does it force quoting.
|
|
2
|
+
const plainCommandArgPattern = process.platform === "win32" ? /^[\w@%+=:,./\\-]+$/ : /^[\w@%+=:,./-]+$/;
|
|
3
|
+
const formatCommandArg = (value: string) => (plainCommandArgPattern.test(value) ? value : JSON.stringify(value));
|
|
4
|
+
|
|
5
|
+
const formatCommandForDisplay = (command: string, args: string[] = []) =>
|
|
6
|
+
[command, ...args].map(formatCommandArg).join(" ");
|
|
7
|
+
|
|
8
|
+
export interface CommandExecutionErrorOptions {
|
|
9
|
+
command: string;
|
|
10
|
+
args?: string[];
|
|
11
|
+
cwd: string;
|
|
12
|
+
code: number | null;
|
|
13
|
+
signal: string | null;
|
|
14
|
+
stdout?: string;
|
|
15
|
+
stderr?: string;
|
|
16
|
+
cause?: unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class CommandExecutionError extends Error {
|
|
20
|
+
command: string;
|
|
21
|
+
args: string[];
|
|
22
|
+
cwd: string;
|
|
23
|
+
code: number | null;
|
|
24
|
+
signal: string | null;
|
|
25
|
+
stdout: string;
|
|
26
|
+
stderr: string;
|
|
27
|
+
|
|
28
|
+
constructor({
|
|
29
|
+
command,
|
|
30
|
+
args = [],
|
|
31
|
+
cwd,
|
|
32
|
+
code,
|
|
33
|
+
signal,
|
|
34
|
+
stdout = "",
|
|
35
|
+
stderr = "",
|
|
36
|
+
cause,
|
|
37
|
+
}: CommandExecutionErrorOptions) {
|
|
38
|
+
const displayCommand = formatCommandForDisplay(command, args);
|
|
39
|
+
const status = signal ? `signal: ${signal}` : `exit code: ${code ?? "unknown"}`;
|
|
40
|
+
const output = (stderr || stdout).trim();
|
|
41
|
+
super([`Command failed: ${displayCommand}`, `cwd: ${cwd}`, status, output ? `\n${output}` : ""].join("\n"), {
|
|
42
|
+
cause,
|
|
43
|
+
});
|
|
44
|
+
this.name = "CommandExecutionError";
|
|
45
|
+
this.command = command;
|
|
46
|
+
this.args = args;
|
|
47
|
+
this.cwd = cwd;
|
|
48
|
+
this.code = code;
|
|
49
|
+
this.signal = signal;
|
|
50
|
+
this.stdout = stdout;
|
|
51
|
+
this.stderr = stderr;
|
|
52
|
+
}
|
|
53
|
+
}
|