@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
|
@@ -53,6 +53,7 @@ export interface ArgMeta<Context = CommandContext> {
|
|
|
53
53
|
export interface InternalArgOption {
|
|
54
54
|
nullable?: boolean;
|
|
55
55
|
onlyApp?: boolean;
|
|
56
|
+
services?: boolean;
|
|
56
57
|
}
|
|
57
58
|
export interface InternalArgMeta {
|
|
58
59
|
key: string;
|
|
@@ -112,5 +113,8 @@ export type Pkg = PkgExecutor;
|
|
|
112
113
|
export const Module = createInternalArgToken<ModuleExecutor, "Module">("Module");
|
|
113
114
|
export type Module = ModuleExecutor;
|
|
114
115
|
|
|
116
|
+
/** Module, or a service module (`lib/_<name>`) named as `<sys>:_<name>`. */
|
|
117
|
+
export const ModuleOrService = createInternalArgToken<ModuleExecutor, "Module">("Module", { services: true });
|
|
118
|
+
|
|
115
119
|
export const Workspace = createInternalArgToken<WorkspaceExecutor, "Workspace">("Workspace");
|
|
116
120
|
export type Workspace = WorkspaceExecutor;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { AkanError } from "akanjs/base";
|
|
2
|
+
|
|
3
|
+
export type CliErrorCode = "failed" | "usage" | "unknownTarget" | "refused" | "checkFailed" | "interrupted";
|
|
4
|
+
|
|
5
|
+
export interface CliErrorOptions {
|
|
6
|
+
exitCode?: number;
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface CliFailure {
|
|
11
|
+
ok: false;
|
|
12
|
+
error: string;
|
|
13
|
+
code: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//* The exit status is what a script branches on, and `code` says the same in a `--json` failure: 2 means fix the
|
|
17
|
+
//* command line or the target it names, 3 that a check ran and found problems, 1 that the command itself broke.
|
|
18
|
+
export class CliError<Code extends string = CliErrorCode> extends AkanError<Code> {
|
|
19
|
+
static readonly exitCodes: { readonly [code in CliErrorCode]: number } = {
|
|
20
|
+
failed: 1,
|
|
21
|
+
usage: 2,
|
|
22
|
+
unknownTarget: 2,
|
|
23
|
+
refused: 2,
|
|
24
|
+
checkFailed: 3,
|
|
25
|
+
interrupted: 130,
|
|
26
|
+
};
|
|
27
|
+
static readonly usageCodes: readonly string[] = ["usage", "unknownTarget"];
|
|
28
|
+
|
|
29
|
+
readonly exitCode: number;
|
|
30
|
+
|
|
31
|
+
constructor(code: Code, message: string, { exitCode, cause }: CliErrorOptions = {}) {
|
|
32
|
+
super(code, message, { cause });
|
|
33
|
+
this.exitCode = exitCode ?? CliError.#exitCodeOfCode(code) ?? 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static failureCodeOf(error: unknown): string {
|
|
37
|
+
if (AkanError.is(error)) return error.code;
|
|
38
|
+
return CliError.#isPromptExit(error) ? "interrupted" : "failed";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static exitCodeOf(error: unknown): number | null {
|
|
42
|
+
if (error instanceof CliError) return error.exitCode;
|
|
43
|
+
const code = CliError.failureCodeOf(error);
|
|
44
|
+
return code === "failed" ? null : CliError.#exitCodeOfCode(code);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static messageOf(error: unknown): string {
|
|
48
|
+
if (error instanceof Error) return error.message || error.name;
|
|
49
|
+
if (typeof error === "string") return error.trim() || "Unknown error";
|
|
50
|
+
if (error === null || error === undefined) return "Unknown error";
|
|
51
|
+
try {
|
|
52
|
+
const json = JSON.stringify(error);
|
|
53
|
+
if (json) return json;
|
|
54
|
+
} catch {
|
|
55
|
+
return String(error);
|
|
56
|
+
}
|
|
57
|
+
return String(error) || "Unknown error";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static failureOf(error: unknown): CliFailure {
|
|
61
|
+
return { ok: false, error: CliError.messageOf(error), code: CliError.failureCodeOf(error) };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static #exitCodeOfCode(code: string): number | null {
|
|
65
|
+
return Object.hasOwn(CliError.exitCodes, code) ? CliError.exitCodes[code as CliErrorCode] : null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//? By name: @inquirer/prompts loads on the first prompt, so its ExitPromptError class is not here to compare with.
|
|
69
|
+
static #isPromptExit(error: unknown) {
|
|
70
|
+
return error instanceof Error && error.name === "ExitPromptError";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -7,12 +7,21 @@ import type {
|
|
|
7
7
|
} from "@inquirer/prompts";
|
|
8
8
|
import { Logger } from "akanjs/common";
|
|
9
9
|
import chalk from "chalk";
|
|
10
|
-
import { type Command, program } from "commander";
|
|
11
|
-
import {
|
|
12
|
-
|
|
10
|
+
import { type Command, type CommanderError, program } from "commander";
|
|
11
|
+
import {
|
|
12
|
+
AppExecutor,
|
|
13
|
+
Executor,
|
|
14
|
+
LibExecutor,
|
|
15
|
+
ModuleExecutor,
|
|
16
|
+
PkgExecutor,
|
|
17
|
+
type SysExecutor,
|
|
18
|
+
WorkspaceExecutor,
|
|
19
|
+
} from "../executors";
|
|
20
|
+
import { ErrorReport } from "../util/errorReport";
|
|
13
21
|
// Never the root barrel: it drags ink, ssh2 and the cloud stack into every command process.
|
|
14
|
-
import { FileSys, getDirname } from "../fileSys";
|
|
15
|
-
import
|
|
22
|
+
import { FileSys, getDirname } from "../util/fileSys";
|
|
23
|
+
import { AppSelectionMemory } from "../workspace/appSelectionMemory";
|
|
24
|
+
import type { PackageJson } from "../workspace/types";
|
|
16
25
|
import {
|
|
17
26
|
type ArgMeta,
|
|
18
27
|
type CommandContext,
|
|
@@ -22,41 +31,68 @@ import {
|
|
|
22
31
|
type InternalArgMeta,
|
|
23
32
|
} from "./argMeta";
|
|
24
33
|
import { camelToKebabCase } from "./camelToKebabCase";
|
|
34
|
+
import { CliError, type CliErrorCode } from "./cliError";
|
|
25
35
|
import { CommandContainer } from "./dependencyBuilder";
|
|
26
|
-
import { ExitCodeError } from "./exitCodeError";
|
|
27
36
|
import { formatCommandHelp, formatHelp } from "./helpFormatter";
|
|
28
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
type CommandCls,
|
|
39
|
+
getTargetCommandNames,
|
|
40
|
+
getTargetMetas,
|
|
41
|
+
type TargetFailure,
|
|
42
|
+
type TargetOption,
|
|
43
|
+
} from "./targetMeta";
|
|
29
44
|
import { WorkspaceVersionCheck } from "./workspaceVersionCheck";
|
|
30
45
|
|
|
31
46
|
const loggedCliErrorObjects = new WeakSet<object>();
|
|
47
|
+
const answeredCliErrors = new WeakSet<object>();
|
|
32
48
|
const loggedCliErrorMessages = new Set<string>();
|
|
33
49
|
|
|
34
50
|
export const markCliErrorPrinted = (error: unknown) => {
|
|
35
|
-
if (typeof error
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const formatCliError = (error: unknown): string => {
|
|
39
|
-
if (error instanceof Error) return error.message || error.name;
|
|
40
|
-
if (typeof error === "string") return error.trim() || "Unknown error";
|
|
41
|
-
if (error === null || error === undefined) return "Unknown error";
|
|
42
|
-
try {
|
|
43
|
-
const json = JSON.stringify(error);
|
|
44
|
-
if (json) return json;
|
|
45
|
-
} catch {
|
|
46
|
-
return String(error);
|
|
47
|
-
}
|
|
48
|
-
return String(error) || "Unknown error";
|
|
51
|
+
if (typeof error !== "object" || error === null) return;
|
|
52
|
+
loggedCliErrorObjects.add(error);
|
|
53
|
+
answeredCliErrors.add(error);
|
|
49
54
|
};
|
|
50
55
|
|
|
51
|
-
const printCliError = (error: unknown) => {
|
|
56
|
+
const printCliError = (error: unknown, stream: "log" | "error" = "log") => {
|
|
52
57
|
if (typeof error === "object" && error !== null) {
|
|
53
58
|
if (loggedCliErrorObjects.has(error)) return;
|
|
54
59
|
loggedCliErrorObjects.add(error);
|
|
55
60
|
}
|
|
56
|
-
const message =
|
|
61
|
+
const message = error instanceof Error ? ErrorReport.format(error) || error.name : CliError.messageOf(error);
|
|
57
62
|
if (loggedCliErrorMessages.has(message)) return;
|
|
58
63
|
loggedCliErrorMessages.add(message);
|
|
59
|
-
Logger.rawLog(`\n${chalk.red(message)}
|
|
64
|
+
Logger.rawLog(`\n${chalk.red(message)}`, undefined, stream);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
//? The default counts: `akan mcp-call` answers JSON only.
|
|
68
|
+
const asksJson = (argMetas: (ArgMeta | InternalArgMeta)[], opt: Record<string, unknown>) =>
|
|
69
|
+
argMetas.some((argMeta) => {
|
|
70
|
+
if (argMeta.type !== "Option") return false;
|
|
71
|
+
const value = opt[argMeta.name] ?? argMeta.argsOption.default;
|
|
72
|
+
if (argMeta.name === "json") return value === true || value === "true";
|
|
73
|
+
return argMeta.name === "format" && value === "json";
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
//* Waits for stdout to take the line: the CLI exits right after, and an exit drops what a pipe still buffers.
|
|
77
|
+
const writeJsonFailure = async (error: unknown) => {
|
|
78
|
+
if (typeof error === "object" && error !== null && answeredCliErrors.has(error)) return;
|
|
79
|
+
const line = `${JSON.stringify(CliError.failureOf(error))}\n`;
|
|
80
|
+
await new Promise<void>((resolve) => process.stdout.write(line, () => resolve()));
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const failureReporterOf =
|
|
84
|
+
(json: boolean, onFailure: TargetOption["onFailure"], failure: TargetFailure) => async (error: unknown) => {
|
|
85
|
+
if (onFailure) await onFailure(error, failure);
|
|
86
|
+
else if (json) await writeJsonFailure(error);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//? commander refuses a flag, an argument or a command before any action runs, having printed why to stderr.
|
|
90
|
+
//? Thrown, not exited: the failure path awaits onFailure, and an exit drops what a pipe still buffers.
|
|
91
|
+
const usageRefusalOf = (error: CommanderError) => {
|
|
92
|
+
if (error.exitCode === 0) process.exit(0);
|
|
93
|
+
const refused = new CliError("usage", error.message.replace(/^error: /, ""));
|
|
94
|
+
loggedCliErrorObjects.add(refused);
|
|
95
|
+
return refused;
|
|
60
96
|
};
|
|
61
97
|
|
|
62
98
|
const handleOption = (programCommand: Command, argMeta: ArgMeta) => {
|
|
@@ -132,7 +168,8 @@ const assertEnumChoice = (argMeta: ArgMeta, value: unknown) => {
|
|
|
132
168
|
if (!enumChoices || typeof enumChoices === "function") return;
|
|
133
169
|
const choices = normalizeEnumChoices(enumChoices);
|
|
134
170
|
if (choices.some((choice) => String(choice.value) === String(value))) return;
|
|
135
|
-
throw new
|
|
171
|
+
throw new CliError(
|
|
172
|
+
"usage",
|
|
136
173
|
`${argLabelOf(argMeta)} argument '${String(value)}' is invalid. Allowed choices are ${choices.map((choice) => choice.name).join(", ")}.`,
|
|
137
174
|
);
|
|
138
175
|
};
|
|
@@ -146,13 +183,18 @@ export const assertPromptable = (problem: string, refusal: Refusal = {}) => {
|
|
|
146
183
|
interface Refusal {
|
|
147
184
|
choices?: readonly unknown[];
|
|
148
185
|
remedy?: string;
|
|
186
|
+
code?: CliErrorCode;
|
|
149
187
|
}
|
|
150
188
|
|
|
151
189
|
const refusalOf = (
|
|
152
190
|
problem: string,
|
|
153
191
|
reason: string,
|
|
154
|
-
{ choices = [], remedy = "pass it on the command line" }: Refusal,
|
|
155
|
-
) =>
|
|
192
|
+
{ choices = [], remedy = "pass it on the command line", code = "usage" }: Refusal,
|
|
193
|
+
) =>
|
|
194
|
+
new CliError(
|
|
195
|
+
code,
|
|
196
|
+
`${problem}: ${reason}, so ${remedy}${choices.length ? ` (choices: ${choices.join(", ")})` : ""}.`,
|
|
197
|
+
);
|
|
156
198
|
|
|
157
199
|
const inputMessageOf = ({ name, argsOption: { desc, example, ask } }: ArgMeta) =>
|
|
158
200
|
ask ? `${ask}: ` : desc ? `${desc}: ` : `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
|
|
@@ -226,7 +268,8 @@ const assertCurrentDirectoryIsWorkspaceRoot = async () => {
|
|
|
226
268
|
]);
|
|
227
269
|
if (hasPackageJson && hasTsConfig && hasMemberDirs.some(Boolean)) return;
|
|
228
270
|
|
|
229
|
-
throw new
|
|
271
|
+
throw new CliError(
|
|
272
|
+
"usage",
|
|
230
273
|
[
|
|
231
274
|
"Akan CLI commands must be run from the workspace root.",
|
|
232
275
|
`Current directory: ${cwd}`,
|
|
@@ -276,7 +319,8 @@ export const getAppsArgumentValue = async (
|
|
|
276
319
|
if (requested.length) {
|
|
277
320
|
const unknown = requested.filter((name) => !appNames.includes(name));
|
|
278
321
|
if (unknown.length)
|
|
279
|
-
throw new
|
|
322
|
+
throw new CliError(
|
|
323
|
+
"unknownTarget",
|
|
280
324
|
`Unknown app${unknown.length > 1 ? "s" : ""}: ${unknown.join(", ")}. Available: ${appNames.join(", ")}, all`,
|
|
281
325
|
);
|
|
282
326
|
return [...new Set(requested)].map((name) => AppExecutor.from(workspace, name));
|
|
@@ -307,10 +351,21 @@ export const getInternalArgumentValue = async (
|
|
|
307
351
|
const problemOf = (kind: string) => (value ? `Unknown ${kind} '${value}'` : `Missing ${kind}`);
|
|
308
352
|
//? Refused in a terminal too: a select deletes on a stray Enter, its cursor resting on the first choice.
|
|
309
353
|
const assertAskable = (kind: string, choices: readonly unknown[], placeholder: string) => {
|
|
310
|
-
const refusal = { choices, ...rerunRemedyOf(rerun, placeholder) };
|
|
354
|
+
const refusal: Refusal = { choices, code: value ? "unknownTarget" : "usage", ...rerunRemedyOf(rerun, placeholder) };
|
|
311
355
|
if (destructive) throw refusalOf(problemOf(kind), "this command deletes files and never picks its target", refusal);
|
|
312
356
|
assertPromptable(problemOf(kind), refusal);
|
|
313
357
|
};
|
|
358
|
+
const takeOnly = <Target>(kind: string, names: readonly string[], take: (name: string) => Target) => {
|
|
359
|
+
const [only] = names;
|
|
360
|
+
if (value || destructive || process.stdin.isTTY || names.length !== 1 || !only) return null;
|
|
361
|
+
const how = rerun ? `: ${rerun(only)}` : "";
|
|
362
|
+
Logger.rawLog(
|
|
363
|
+
`No ${kind} named, so this runs on '${only}', the only one in this workspace${how}`,
|
|
364
|
+
undefined,
|
|
365
|
+
"error",
|
|
366
|
+
);
|
|
367
|
+
return take(only);
|
|
368
|
+
};
|
|
314
369
|
if (sysType === "sys" || sysType === "exec") {
|
|
315
370
|
const pkgChoices = sysType === "exec" ? pkgNames : [];
|
|
316
371
|
const execOf = (name: string) => {
|
|
@@ -326,24 +381,15 @@ export const getInternalArgumentValue = async (
|
|
|
326
381
|
const [kind, placeholder] =
|
|
327
382
|
sysType === "exec" ? ["app, lib or pkg", "<app-lib-or-pkg>"] : ["app or lib", "<app-or-lib>"];
|
|
328
383
|
const choices = [...appNames, ...libNames, ...pkgChoices];
|
|
329
|
-
const only = choices
|
|
330
|
-
|
|
331
|
-
if (!value && !destructive && only && !process.stdin.isTTY) {
|
|
332
|
-
const how = rerun ? `: ${rerun(only.name)}` : "";
|
|
333
|
-
Logger.rawLog(
|
|
334
|
-
`No ${kind} named, so this runs on '${only.name}', the only one in this workspace${how}`,
|
|
335
|
-
undefined,
|
|
336
|
-
"error",
|
|
337
|
-
);
|
|
338
|
-
return only;
|
|
339
|
-
}
|
|
384
|
+
const only = takeOnly(kind, choices, execOf);
|
|
385
|
+
if (only) return only;
|
|
340
386
|
assertAskable(kind, choices, placeholder);
|
|
341
387
|
const name = await select<string>({
|
|
342
388
|
message: sysType === "exec" ? `Select the App or Lib or Pkg name` : `Select the App or Lib name`,
|
|
343
389
|
choices,
|
|
344
390
|
});
|
|
345
391
|
const picked = execOf(name);
|
|
346
|
-
if (!picked) throw new
|
|
392
|
+
if (!picked) throw new CliError("unknownTarget", `Invalid system name: ${name}`);
|
|
347
393
|
return picked;
|
|
348
394
|
} else if (sysType === "app") {
|
|
349
395
|
if (value && appNames.includes(value)) return AppExecutor.from(workspace, value);
|
|
@@ -353,40 +399,49 @@ export const getInternalArgumentValue = async (
|
|
|
353
399
|
return AppExecutor.from(workspace, appName);
|
|
354
400
|
} else if (sysType === "lib") {
|
|
355
401
|
if (value && libNames.includes(value)) return LibExecutor.from(workspace, value);
|
|
402
|
+
const only = takeOnly("lib", libNames, (name) => LibExecutor.from(workspace, name));
|
|
403
|
+
if (only) return only;
|
|
356
404
|
assertAskable("lib", libNames, "<lib>");
|
|
357
405
|
const libName = await select<string>({ message: `Select the ${sysType} name`, choices: libNames });
|
|
358
406
|
return LibExecutor.from(workspace, libName);
|
|
359
407
|
} else if (sysType === "pkg") {
|
|
360
408
|
const pkgs = await workspace.getPkgs();
|
|
361
409
|
if (value && pkgs.includes(value)) return PkgExecutor.from(workspace, value);
|
|
410
|
+
const only = takeOnly("pkg", pkgs, (name) => PkgExecutor.from(workspace, name));
|
|
411
|
+
if (only) return only;
|
|
362
412
|
assertAskable("pkg", pkgs, "<pkg>");
|
|
363
413
|
const pkgName = await select<string>({ message: `Select the ${sysType} name`, choices: pkgs });
|
|
364
414
|
return PkgExecutor.from(workspace, pkgName);
|
|
365
415
|
} else if (sysType === "module") {
|
|
366
|
-
if (value) {
|
|
367
|
-
const [sysName, moduleName] = value.split(":");
|
|
368
|
-
if (!sysName || !moduleName) throw new Error(`Invalid module name: ${value}`);
|
|
369
|
-
if (appNames.includes(sysName)) {
|
|
370
|
-
const app = AppExecutor.from(workspace, sysName);
|
|
371
|
-
const modules = await app.getModules();
|
|
372
|
-
if (modules.includes(moduleName)) return ModuleExecutor.from(app, moduleName);
|
|
373
|
-
else throw new Error(`Invalid module name: ${moduleName}`);
|
|
374
|
-
} else if (libNames.includes(sysName)) {
|
|
375
|
-
const lib = LibExecutor.from(workspace, sysName);
|
|
376
|
-
const modules = await lib.getModules();
|
|
377
|
-
if (modules.includes(moduleName)) return ModuleExecutor.from(lib, moduleName);
|
|
378
|
-
} else throw new Error(`Invalid system name: ${sysName}`);
|
|
379
|
-
}
|
|
380
416
|
const systems = [
|
|
381
417
|
...appNames.map((name) => AppExecutor.from(workspace, name)),
|
|
382
418
|
...libNames.map((name) => LibExecutor.from(workspace, name)),
|
|
383
419
|
];
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
420
|
+
const modulesOf = async (sys: SysExecutor) => [
|
|
421
|
+
...(await sys.getModules()),
|
|
422
|
+
...(argMeta.option?.services ? await sys.getServiceModules() : []),
|
|
423
|
+
];
|
|
424
|
+
const listModules = async () =>
|
|
425
|
+
(await Promise.all(systems.map(async (sys) => (await modulesOf(sys)).map((m) => `${sys.name}:${m}`)))).flat();
|
|
426
|
+
if (value) {
|
|
427
|
+
const [sysName, moduleName] = value.split(":");
|
|
428
|
+
if (!sysName || !moduleName) throw new CliError("usage", `Invalid module name: ${value}`);
|
|
429
|
+
const sys = systems.find((each) => each.name === sysName);
|
|
430
|
+
if (!sys) throw new CliError("unknownTarget", `Invalid system name: ${sysName}`);
|
|
431
|
+
if ((await modulesOf(sys)).includes(moduleName)) return ModuleExecutor.from(sys, moduleName);
|
|
432
|
+
throw refusalOf(problemOf("module"), `${sysName} has no such module`, {
|
|
433
|
+
code: "unknownTarget",
|
|
434
|
+
choices: await listModules(),
|
|
435
|
+
...rerunRemedyOf(rerun, "<sys:module>"),
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
const choices = process.stdin.isTTY && !destructive ? [] : await listModules();
|
|
439
|
+
const only = takeOnly("module", choices, (label) => {
|
|
440
|
+
const [sysName, moduleName = ""] = label.split(":");
|
|
441
|
+
const sys = systems.find((each) => each.name === sysName);
|
|
442
|
+
return sys ? ModuleExecutor.from(sys, moduleName) : null;
|
|
443
|
+
});
|
|
444
|
+
if (only) return only;
|
|
390
445
|
assertAskable("module", choices, "<sys:module>");
|
|
391
446
|
const { type, name } = await select<{ type: "app" | "lib"; name: string }>({
|
|
392
447
|
message: `select the App or Lib name`,
|
|
@@ -396,7 +451,7 @@ export const getInternalArgumentValue = async (
|
|
|
396
451
|
],
|
|
397
452
|
});
|
|
398
453
|
const executor = type === "app" ? AppExecutor.from(workspace, name) : LibExecutor.from(workspace, name);
|
|
399
|
-
const modules = await executor
|
|
454
|
+
const modules = await modulesOf(executor);
|
|
400
455
|
const moduleName = await select<string>({
|
|
401
456
|
message: `Select the module name`,
|
|
402
457
|
choices: modules.map((name) => ({ name: `${executor.name}:${name}`, value: name })),
|
|
@@ -405,13 +460,33 @@ export const getInternalArgumentValue = async (
|
|
|
405
460
|
} else throw new Error(`Invalid system type: ${argMeta.type}`);
|
|
406
461
|
};
|
|
407
462
|
|
|
463
|
+
const cliFailureOf = () => {
|
|
464
|
+
let failing = false;
|
|
465
|
+
const failure = {
|
|
466
|
+
exitCode: 1,
|
|
467
|
+
usageExitCode: undefined as number | undefined,
|
|
468
|
+
stream: "log" as "log" | "error",
|
|
469
|
+
report: async (_error: unknown) => {},
|
|
470
|
+
exitCodeOf: (error: unknown) => {
|
|
471
|
+
const { usageExitCode } = failure;
|
|
472
|
+
if (usageExitCode !== undefined && error instanceof CliError && CliError.usageCodes.includes(error.code))
|
|
473
|
+
return usageExitCode;
|
|
474
|
+
return CliError.exitCodeOf(error) ?? failure.exitCode;
|
|
475
|
+
},
|
|
476
|
+
fail: async (error: unknown) => {
|
|
477
|
+
if (failing) return;
|
|
478
|
+
failing = true;
|
|
479
|
+
printCliError(error, failure.stream);
|
|
480
|
+
await failure.report(error).catch((reportError: unknown) => printCliError(reportError, "error"));
|
|
481
|
+
process.exit(failure.exitCodeOf(error));
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
return failure;
|
|
485
|
+
};
|
|
486
|
+
|
|
408
487
|
export const runCommands = async (...commands: CommandCls[]) => {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
process.on("unhandledRejection", (error) => {
|
|
412
|
-
printCliError(error);
|
|
413
|
-
process.exit(ExitCodeError.codeOf(error) ?? failureExitCode);
|
|
414
|
-
});
|
|
488
|
+
const failure = cliFailureOf();
|
|
489
|
+
process.on("unhandledRejection", (error) => void failure.fail(error));
|
|
415
490
|
const __dirname = getDirname(import.meta.url);
|
|
416
491
|
const packageJsonCandidates = [`${path.dirname(Bun.main)}/package.json`, `${__dirname}/../package.json`];
|
|
417
492
|
let cliPackageJson: PackageJson | null = null;
|
|
@@ -445,21 +520,16 @@ export const runCommands = async (...commands: CommandCls[]) => {
|
|
|
445
520
|
let programCommand = program.command(commandName, {
|
|
446
521
|
hidden: targetMeta.targetOption.devOnly,
|
|
447
522
|
});
|
|
448
|
-
const targetFailureExitCode = targetMeta.targetOption
|
|
449
|
-
const usageExitCode = targetMeta.targetOption.usageExitCode ?? targetFailureExitCode;
|
|
523
|
+
const { failureExitCode: targetFailureExitCode, usageExitCode: targetUsageExitCode } = targetMeta.targetOption;
|
|
450
524
|
const { onFailure } = targetMeta.targetOption;
|
|
451
525
|
const [allArgMetas] = getArgMetas(command, targetMeta.key);
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
programCommand.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
const given = givenOptionsOf(allArgMetas, programCommand.opts());
|
|
460
|
-
reportFailure = async (failure) => await onFailure?.(failure, { usage: true, given });
|
|
461
|
-
throw refused;
|
|
462
|
-
});
|
|
526
|
+
programCommand.exitOverride((error) => {
|
|
527
|
+
const refused = usageRefusalOf(error);
|
|
528
|
+
failure.usageExitCode = targetUsageExitCode;
|
|
529
|
+
const given = givenOptionsOf(allArgMetas, programCommand.opts());
|
|
530
|
+
failure.report = failureReporterOf(asksJson(allArgMetas, given), onFailure, { usage: true, given });
|
|
531
|
+
throw refused;
|
|
532
|
+
});
|
|
463
533
|
for (const argMeta of allArgMetas) {
|
|
464
534
|
if (argMeta.type === "Option") programCommand = handleOption(programCommand, argMeta);
|
|
465
535
|
else if (argMeta.type === "Argument") programCommand = handleArgument(programCommand, argMeta);
|
|
@@ -488,12 +558,17 @@ export const runCommands = async (...commands: CommandCls[]) => {
|
|
|
488
558
|
};
|
|
489
559
|
|
|
490
560
|
programCommand.action(async (...args: unknown[]) => {
|
|
491
|
-
|
|
561
|
+
failure.exitCode = targetFailureExitCode ?? 1;
|
|
562
|
+
failure.usageExitCode = targetUsageExitCode;
|
|
492
563
|
if (!targetMeta.targetOption.stdio) Logger.rawLog();
|
|
493
564
|
const cmdArgs = args.slice(0, args.length - 2);
|
|
494
565
|
const opt = args[args.length - 2] as Record<string, unknown>;
|
|
495
|
-
|
|
496
|
-
|
|
566
|
+
const json = asksJson(allArgMetas, opt);
|
|
567
|
+
failure.stream = json ? "error" : "log";
|
|
568
|
+
failure.report = failureReporterOf(json, onFailure, {
|
|
569
|
+
usage: false,
|
|
570
|
+
given: givenOptionsOf(allArgMetas, opt),
|
|
571
|
+
});
|
|
497
572
|
const commandArgs = [] as unknown[];
|
|
498
573
|
if (targetMeta.targetOption.runsOnWorkspaceRoot) {
|
|
499
574
|
await assertCurrentDirectoryIsWorkspaceRoot();
|
|
@@ -537,17 +612,16 @@ export const runCommands = async (...commands: CommandCls[]) => {
|
|
|
537
612
|
await targetMeta.handler.call(cmd, ...commandArgs);
|
|
538
613
|
if (!targetMeta.targetOption.stdio) Logger.rawLog();
|
|
539
614
|
} catch (e) {
|
|
540
|
-
printCliError(e);
|
|
615
|
+
printCliError(e, failure.stream);
|
|
541
616
|
throw e;
|
|
542
617
|
}
|
|
543
618
|
});
|
|
544
619
|
}
|
|
545
620
|
}
|
|
546
621
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
printCliError(error);
|
|
550
|
-
await reportFailure(error).catch(printCliError);
|
|
551
|
-
process.exit(ExitCodeError.codeOf(error) ?? failureExitCode);
|
|
622
|
+
program.exitOverride((error) => {
|
|
623
|
+
throw usageRefusalOf(error);
|
|
552
624
|
});
|
|
625
|
+
// Handled here, not by the handler above: a rejection reaching the entry's top-level await prints Bun's own trace.
|
|
626
|
+
await program.parseAsync(process.argv).catch(failure.fail);
|
|
553
627
|
};
|
|
@@ -137,7 +137,7 @@ class TargetBuilder<Deps extends readonly DependencyCls[], Params extends unknow
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
type TargetDefinition = ReturnType<TargetBuilder<readonly DependencyCls[], unknown[]>["exec"]>;
|
|
140
|
-
type CommandBuilderContext<Deps extends readonly DependencyCls[]> = {
|
|
140
|
+
export type CommandBuilderContext<Deps extends readonly DependencyCls[]> = {
|
|
141
141
|
public: (targetOption?: Omit<TargetOption, "type">) => TargetBuilder<Deps>;
|
|
142
142
|
cloud: (targetOption?: Omit<TargetOption, "type">) => TargetBuilder<Deps>;
|
|
143
143
|
dev: (targetOption?: Omit<TargetOption, "type">) => TargetBuilder<Deps>;
|