@akanjs/devkit 3.2.0-rc.8 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -528
- package/DEV_RUNTIME_KNOBS.md +4 -3
- package/README.ko.md +3 -2
- package/README.md +4 -2
- package/akanApp/BackendImportGraph.test.ts +1 -1
- package/akanApp/akanApp.host.test.ts +132 -3
- package/akanApp/akanApp.host.ts +146 -1216
- package/akanApp/akanApp.host.wiring.test.ts +727 -0
- package/akanApp/builderGap.ts +68 -0
- package/akanApp/builderRequestRelay.test.ts +93 -0
- package/akanApp/builderRequestRelay.ts +100 -0
- package/akanApp/builderRssRecycler.ts +182 -0
- package/akanApp/devBackend.ts +392 -0
- package/akanApp/devBuildStatusBoard.ts +128 -0
- package/akanApp/devBuilder.ts +196 -0
- package/akanApp/devIdleSuspend.test.ts +221 -0
- package/akanApp/devIdleSuspend.ts +192 -0
- package/akanApp/devIdleSuspend.watcher.test.ts +120 -0
- package/akanApp/devRecycler.test.ts +66 -0
- package/akanApp/devRecycler.ts +305 -0
- package/akanApp/processRss.ts +61 -0
- package/akanConfig/akanConfig.test.ts +45 -17
- package/akanConfig/akanConfig.ts +10 -10
- package/akanConfig/akanWorkspaceConfig.ts +1 -1
- package/akanConfig/productionLockfile.ts +1 -1
- package/apiReport/apiReport.test.ts +34 -3
- package/apiReport/apiReportDiff.ts +35 -1
- package/apiReport/apiReportPolicy.ts +3 -2
- package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +2 -49
- package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +71 -8
- package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +60 -21
- package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
- package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +17 -1
- package/{routeJsBudget.ts → app/routeJsBudget.ts} +9 -3
- package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
- package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
- package/artifact/implicitRootLayout.test.ts +71 -3
- package/artifact/implicitRootLayout.ts +9 -3
- package/artifact/implicitRootLayoutRender.test.tsx +297 -0
- package/biome.base.json +2 -1
- package/cloud/cloudApi.test.ts +1 -1
- package/cloud/configLock.test.ts +1 -1
- package/cloud/globalConfig.test.ts +1 -1
- package/cloud/globalConfig.ts +1 -1
- package/cloud/updatePackUpload.test.ts +1 -1
- package/codeAgent/agent/AkanCodeEnv.ts +1 -1
- package/codeAgent/agent/AkanCodeServices.ts +23 -0
- package/codeAgent/agent/akanCodePaths.ts +1 -1
- package/codeAgent/agent/akanCodeServices.test.ts +54 -0
- package/codeAgent/agent/akanSystemPrompt.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +1 -1
- package/codeAgent/skills/akan-debug/SKILL.md +8 -5
- package/codeAgent/skills/akan-err/SKILL.md +7 -0
- package/codeAgent/skills/akan-mcp/SKILL.md +19 -1
- package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
- package/codeAgent/skills/akan-validate/SKILL.md +3 -3
- package/codeAgent/tools/AkanCli.ts +1 -1
- package/codeAgent/tools/AkanToolPack.ts +2 -2
- package/codeAgent/tools/akanCodePlugins.test.ts +1 -1
- package/commandDecorators/command.ts +35 -6
- package/commandDecorators/commandBuilder.ts +1 -1
- package/commandDecorators/commandDecorators.test.ts +107 -6
- package/commandDecorators/targetMeta.ts +2 -0
- package/commandDecorators/workspaceVersionCheck.test.ts +70 -1
- package/commandDecorators/workspaceVersionCheck.ts +64 -14
- package/context/akanContext.ts +576 -0
- package/context/akanContextInspection.ts +296 -0
- package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
- package/{akanMcpContract.ts → context/akanMcpContract.ts} +16 -256
- package/context/doctor/agentGuideCheck.ts +81 -0
- package/context/doctor/configLeftoverCheck.ts +35 -0
- package/context/doctor/doctorFindings.ts +70 -0
- package/context/doctor/generatedFreshness.ts +56 -0
- package/context/doctor/moduleShapeCheck.ts +88 -0
- package/context/doctor/recipeDuplicateCheck.ts +42 -0
- package/context/doctor/recipeIndexCheck.ts +87 -0
- package/context/doctor/rootShapeCheck.ts +55 -0
- package/context/doctor/workflowScope.ts +97 -0
- package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
- package/context/safeRead.ts +9 -0
- package/csrE2e/csrE2eHarness.fixture.ts +1 -1
- package/devkitUtils.test.ts +39 -5
- package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
- package/{apiReference.ts → docs/apiReference.ts} +2 -2
- package/docs/errorCodeReference.test.ts +282 -0
- package/docs/errorCodeReference.ts +71 -0
- package/docs/errorCodeScan.ts +551 -0
- package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
- package/executors/appExecutor.ts +448 -0
- package/executors/commandExecutionError.ts +53 -0
- package/executors/executor.ts +527 -0
- package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
- package/{executors.test.ts → executors/executors.test.ts} +76 -15
- package/executors/index.ts +8 -0
- package/executors/libExecutor.ts +23 -0
- package/executors/moduleExecutor.ts +18 -0
- package/executors/pkgExecutor.ts +129 -0
- package/executors/sysExecutor.ts +301 -0
- package/executors/workspaceExecutor.ts +277 -0
- package/frontendBuild/allRoutesBuilder.test.ts +1 -1
- package/frontendBuild/autoImportSync.test.ts +1 -1
- package/frontendBuild/autoImportSync.ts +1 -1
- package/frontendBuild/buildRouteClient.test.ts +1 -1
- package/frontendBuild/clientEntriesBundler.test.ts +1 -1
- package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
- package/frontendBuild/csrDevArtifactWriter.ts +1 -1
- package/frontendBuild/cssCompiler.test.ts +3 -2
- package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
- package/frontendBuild/devGeneratedIndexSync.ts +7 -38
- package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
- package/frontendBuild/fontOptimizer.test.ts +1 -1
- package/frontendBuild/fontPruner.test.ts +1 -1
- package/frontendBuild/frontendBuild.test.ts +3 -3
- package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
- package/frontendBuild/hmrWatcher.test.ts +1 -1
- package/frontendBuild/hmrWatcher.ts +22 -1
- package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
- package/frontendBuild/mcpAppViewBuilder.ts +1 -1
- package/frontendBuild/nativeCore.test.ts +1 -1
- package/frontendBuild/optionalPeers.test.ts +36 -8
- package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
- package/frontendBuild/pagesBundleBuilder.ts +1 -1
- package/frontendBuild/precompressArtifacts.test.ts +1 -1
- package/frontendBuild/precompressArtifacts.ts +19 -6
- package/frontendBuild/serverGraphFile.ts +1 -1
- package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
- package/frontendBuild/ssrDevBundler.test.ts +1 -1
- package/frontendBuild/vendorImportScanner.test.ts +1 -1
- package/frontendBuild/vendorNarrowing.test.ts +1 -1
- package/frontendBuild/watchRootResolver.test.ts +1 -1
- package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
- package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
- package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
- package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
- package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
- package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
- package/{prompter.ts → guideline/prompter.ts} +2 -3
- package/incrementalBuilder/buildBatch.proc.ts +14 -4
- package/incrementalBuilder/buildBatchProtocol.ts +2 -0
- package/incrementalBuilder/buildBatchRunner.test.ts +122 -2
- package/incrementalBuilder/buildBatchRunner.ts +17 -4
- package/incrementalBuilder/builderBoot.ts +106 -0
- package/incrementalBuilder/builderBuildStatus.ts +23 -0
- package/incrementalBuilder/builderChannel.test.ts +1 -1
- package/incrementalBuilder/builderChannel.ts +11 -0
- package/incrementalBuilder/builderGraphPayloads.ts +3 -3
- package/incrementalBuilder/builderLanes.ts +157 -0
- package/incrementalBuilder/builderWatch.ts +213 -0
- package/incrementalBuilder/csrRegistry.ts +234 -0
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +101 -7
- package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
- package/incrementalBuilder/ssrRegistry.ts +282 -0
- package/index.ts +22 -22
- package/integration/devStability.integration.test.ts +62 -56
- package/integration/devStabilityHarness.test.ts +1 -1
- package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
- package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
- package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
- package/lint/gritRules.test.ts +1 -1
- package/{linter.test.ts → lint/linter.test.ts} +1 -1
- package/lint/no-import-common-err.grit +31 -0
- package/lint/no-init-fetch-in-client.grit +1 -1
- package/mobile/desktopBin.test.ts +1 -1
- package/mobile/desktopRelease.test.ts +1 -1
- package/mobile/desktopServerStage.test.ts +2 -2
- package/mobile/desktopServerStage.ts +1 -1
- package/mobile/nativeApi.test.ts +1 -1
- package/mobile/nativeApp.test.ts +1 -1
- package/mobile/nativeConfig.test.ts +1 -1
- package/mobile/nativePluginFolders.test.ts +1 -1
- package/mobile/nativePublicEnv.test.ts +1 -1
- package/mobile/nativeWebDir.test.ts +1 -1
- package/mobile/serverBundleSecrets.test.ts +1 -1
- package/mobile/tarWriter.test.ts +1 -1
- package/mobile/updatePackFolder.test.ts +1 -1
- package/package.json +173 -9
- package/packageExports.test.ts +20 -2
- package/piDependencyPins.test.ts +1 -1
- package/pipeline/PipelineDefinition.ts +1 -1
- package/platformTest/IdleWatchedProcess.test.ts +1 -1
- package/platformTest/LinuxDockerTarget.ts +1 -1
- package/platformTest/PlatformTestRun.test.ts +1 -1
- package/platformTest/TestSnapshot.test.ts +1 -1
- package/platformTest/WindowsSshTarget.ts +1 -1
- package/preview/previewView.test.ts +23 -1
- package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
- package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
- package/quality/bareErrorScanner.ts +126 -0
- package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
- package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
- package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
- package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
- package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
- package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
- package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
- package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
- package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +41 -1
- package/{qualityScanner.ts → quality/qualityScanner.ts} +25 -91
- package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
- package/quality/workspaceSourceFiles.ts +82 -0
- package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
- package/{subspace.ts → subspace/subspace.ts} +5 -5
- package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
- package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
- package/{testHelpers.ts → test/testHelpers.ts} +37 -1
- package/transforms/barrelAnalyzer.ts +31 -10
- package/transforms/browserDirnamePlugin.test.ts +1 -1
- package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
- package/transforms/mcpAppPageTrimmer.test.ts +1 -1
- package/transforms/pureLazyMarker.test.ts +1 -1
- package/transforms/serverEnvPlugin.test.ts +1 -1
- package/transforms/serverEnvProfile.test.ts +1 -1
- package/transforms/sideEffectImportOrder.test.ts +1 -1
- package/transforms/transforms.test.ts +52 -2
- package/transforms/tsconfigPackageResolver.test.ts +1 -1
- package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
- package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
- package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
- package/typecheck/projectTypecheck.test.ts +23 -1
- package/typecheck/projectTypecheck.ts +10 -2
- package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
- package/{typeChecker.ts → typecheck/typeChecker.ts} +5 -4
- package/typecheck/typecheck.proc.ts +6 -2
- package/typecheck/typecheckFailure.ts +1 -1
- package/util/errorReport.ts +66 -0
- package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
- package/workflow/constantSource.ts +187 -0
- package/workflow/dictionarySource.ts +184 -0
- package/workflow/executor.ts +6 -9
- package/workflow/fieldExpression.ts +153 -0
- package/workflow/fieldLabel.ts +61 -0
- package/workflow/fieldOrder.ts +117 -0
- package/workflow/fieldType.ts +2 -1
- package/workflow/guardCatalog.test.ts +1 -1
- package/workflow/keyRename.ts +1 -1
- package/workflow/moduleIndex.test.ts +2 -2
- package/workflow/moduleIndex.ts +2 -2
- package/workflow/modulePaths.ts +27 -0
- package/workflow/mutationScaffold.ts +7 -15
- package/workflow/mutationSource.ts +2 -1
- package/workflow/plan.ts +2 -1
- package/workflow/primitiveReport.ts +78 -0
- package/workflow/rolloutGate.test.ts +1 -1
- package/workflow/rolloutGate.ts +1 -1
- package/workflow/serviceSource.ts +33 -0
- package/workflow/signalSource.ts +96 -0
- package/workflow/source.ts +50 -1100
- package/workflow/sourceAst.ts +30 -0
- package/workflow/sourceImports.ts +105 -0
- package/workflow/sourceText.ts +13 -0
- package/workflow/templateSource.ts +30 -0
- package/workflow/testSource.ts +31 -0
- package/workflow/types.ts +1 -1
- package/workflow/uiPolicy.ts +1 -1
- package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
- package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
- package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
- package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
- package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
- package/{envSeed.ts → workspace/envSeed.ts} +1 -1
- package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
- package/{libSource.ts → workspace/libSource.ts} +1 -1
- package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
- package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
- package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
- package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
- package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
- package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
- package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
- package/akanContext.ts +0 -1083
- package/executors.ts +0 -1749
- /package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +0 -0
- /package/{akanMcpToolError.ts → context/akanMcpToolError.ts} +0 -0
- /package/{moduleFieldNames.test.ts → context/moduleFieldNames.test.ts} +0 -0
- /package/{moduleFieldNames.ts → context/moduleFieldNames.ts} +0 -0
- /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
- /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
- /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
- /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
- /package/{linter.ts → lint/linter.ts} +0 -0
- /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
- /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
- /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
- /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
- /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
- /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
- /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
- /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
- /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
- /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
- /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
- /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
- /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
- /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
- /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
- /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
- /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
- /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
- /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
- /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
- /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
- /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
- /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
- /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
- /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
- /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
- /package/{storeSource.ts → quality/storeSource.ts} +0 -0
- /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
- /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
- /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
- /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
- /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
- /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
- /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
- /package/{writePath.ts → quality/writePath.ts} +0 -0
- /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
- /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
- /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
- /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
- /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
- /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
- /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
- /package/{fileSys.test.ts → util/fileSys.test.ts} +0 -0
- /package/{fileSys.ts → util/fileSys.ts} +0 -0
- /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
- /package/{selectModel.ts → util/selectModel.ts} +0 -0
- /package/{semver.test.ts → util/semver.test.ts} +0 -0
- /package/{semver.ts → util/semver.ts} +0 -0
- /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
- /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
- /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
- /package/{spinner.ts → util/spinner.ts} +0 -0
- /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
- /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
- /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
- /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
- /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
- /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
- /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
- /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
- /package/{types.ts → workspace/types.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import * as ts from "typescript";
|
|
4
|
-
import { tempDirs, writeJson, writeText } from "
|
|
4
|
+
import { tempDirs, writeJson, writeText } from "../test/testHelpers";
|
|
5
5
|
import { TypeChecker } from "./typeChecker";
|
|
6
6
|
|
|
7
7
|
const makeTempRoot = tempDirs("akan-devkit-type-checker-");
|
|
@@ -3,7 +3,7 @@ import * as path from "node:path";
|
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import * as ts from "typescript";
|
|
5
5
|
|
|
6
|
-
import type { Executor } from "
|
|
6
|
+
import type { Executor } from "../executors";
|
|
7
7
|
|
|
8
8
|
export interface ProjectTypecheckResult {
|
|
9
9
|
configPath: string;
|
|
@@ -167,12 +167,13 @@ export class TypeChecker {
|
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
static checkProject(configPath: string): ProjectTypecheckResult {
|
|
170
|
+
static checkProject(configPath: string, overrides: ts.CompilerOptions = {}): ProjectTypecheckResult {
|
|
171
171
|
const parsedConfig = TypeChecker.parseConfig(configPath);
|
|
172
|
-
const
|
|
172
|
+
const options = { ...parsedConfig.options, ...overrides };
|
|
173
|
+
const host = ts.createIncrementalCompilerHost(options);
|
|
173
174
|
const builderProgram = ts.createIncrementalProgram({
|
|
174
175
|
rootNames: parsedConfig.fileNames,
|
|
175
|
-
options
|
|
176
|
+
options,
|
|
176
177
|
projectReferences: parsedConfig.projectReferences,
|
|
177
178
|
configFileParsingDiagnostics: parsedConfig.errors,
|
|
178
179
|
host,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Logger } from "akanjs/common";
|
|
2
|
-
import { TypeChecker } from "
|
|
2
|
+
import { TypeChecker } from "./typeChecker";
|
|
3
3
|
import { TypecheckFailure } from "./typecheckFailure";
|
|
4
4
|
|
|
5
5
|
try {
|
|
@@ -24,7 +24,11 @@ try {
|
|
|
24
24
|
|
|
25
25
|
const configPath = process.env.AKAN_TYPECHECK_TSCONFIG;
|
|
26
26
|
if (!configPath) throw new Error("AKAN_TYPECHECK_TSCONFIG is required");
|
|
27
|
-
const
|
|
27
|
+
const tsBuildInfoFile = process.env.AKAN_TYPECHECK_BUILDINFO;
|
|
28
|
+
const result = TypeChecker.checkProject(
|
|
29
|
+
configPath,
|
|
30
|
+
tsBuildInfoFile ? { noEmit: true, incremental: true, tsBuildInfoFile } : {},
|
|
31
|
+
);
|
|
28
32
|
if (process.env.AKAN_TYPECHECK_FORMAT === "json") {
|
|
29
33
|
//? Not process.cwd(): that is the realpath (/private/var on macOS) while TypeScript keeps the spelling it was given.
|
|
30
34
|
const root = process.env.AKAN_TYPECHECK_ROOT ?? process.cwd();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliError } from "../commandDecorators/cliError";
|
|
2
|
-
import type { TypecheckRecord } from "
|
|
2
|
+
import type { TypecheckRecord } from "./typeChecker";
|
|
3
3
|
|
|
4
4
|
export class TypecheckFailure extends CliError<"checkFailed"> {
|
|
5
5
|
//? The worker's exit when the project has type errors, so its crash, which exits 1, is told apart.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export class ErrorReport {
|
|
5
|
+
static readonly shownNestedErrors = 20;
|
|
6
|
+
|
|
7
|
+
static format(error: unknown, workspaceRoot = process.cwd()): string {
|
|
8
|
+
return ErrorReport.#format(error, workspaceRoot, []);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static #format(error: unknown, workspaceRoot: string, ancestors: readonly unknown[]): string {
|
|
12
|
+
if (ancestors.includes(error)) return "[circular]";
|
|
13
|
+
const chain = [...ancestors, error];
|
|
14
|
+
if (error instanceof AggregateError) {
|
|
15
|
+
const shown = error.errors.slice(0, ErrorReport.shownNestedErrors);
|
|
16
|
+
const hidden = error.errors.length - shown.length;
|
|
17
|
+
const nestedMessages = [
|
|
18
|
+
...shown.map(
|
|
19
|
+
(nestedError, index) =>
|
|
20
|
+
ErrorReport.#format(nestedError, workspaceRoot, chain).trim() || `Unknown error ${index + 1}`,
|
|
21
|
+
),
|
|
22
|
+
...(hidden > 0 ? [`…and ${hidden} more`] : []),
|
|
23
|
+
]
|
|
24
|
+
.map((message) => message.replace(/^/gm, " "))
|
|
25
|
+
.join("\n");
|
|
26
|
+
const message = nestedMessages ? `${error.message}\n${nestedMessages}` : error.message;
|
|
27
|
+
return `${message}${ErrorReport.#causeOf(error, workspaceRoot, chain)}`;
|
|
28
|
+
}
|
|
29
|
+
if (error instanceof Error)
|
|
30
|
+
return `${ErrorReport.#withLocation(error.message, error, workspaceRoot)}${ErrorReport.#causeOf(error, workspaceRoot, chain)}`;
|
|
31
|
+
if (typeof error === "object" && error !== null && "message" in error)
|
|
32
|
+
return ErrorReport.#withLocation(String(error.message), error, workspaceRoot);
|
|
33
|
+
return String(error);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static #causeOf(error: Error, workspaceRoot: string, chain: readonly unknown[]): string {
|
|
37
|
+
return error.cause ? `\nCaused by: ${ErrorReport.#format(error.cause, workspaceRoot, chain)}` : "";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static #withLocation(message: string, error: object, workspaceRoot: string): string {
|
|
41
|
+
const { position } = error as { position?: { file: string; line: number; column: number } | null };
|
|
42
|
+
if (!position?.file) return message;
|
|
43
|
+
const file = ErrorReport.#relativeToWorkspace(position.file, workspaceRoot);
|
|
44
|
+
const location = position.line > 0 ? `${file}:${position.line}:${position.column}` : file;
|
|
45
|
+
return message.includes(location) ? message : message.replace(/^.*/, (headline) => `${headline} (${location})`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Bun names the file by its realpath, so a workspace root reached through a symlink is matched by its own too.
|
|
49
|
+
static #relativeToWorkspace(file: string, workspaceRoot: string): string {
|
|
50
|
+
if (!path.isAbsolute(file)) return file;
|
|
51
|
+
for (const root of [workspaceRoot, ErrorReport.#realpathOf(workspaceRoot)]) {
|
|
52
|
+
const relative = path.relative(root, file);
|
|
53
|
+
if (!relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative))
|
|
54
|
+
return relative.replaceAll(path.sep, "/");
|
|
55
|
+
}
|
|
56
|
+
return file;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static #realpathOf(dir: string): string {
|
|
60
|
+
try {
|
|
61
|
+
return realpathSync(dir);
|
|
62
|
+
} catch {
|
|
63
|
+
return dir;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { formatWithBiome, hasBiome } from "../test/testHelpers";
|
|
2
3
|
import { JsonFormatter } from "./jsonFormatter";
|
|
3
|
-
import { formatWithBiome, hasBiome } from "./testHelpers";
|
|
4
4
|
|
|
5
5
|
const pad = (length: number) => "x".repeat(length);
|
|
6
6
|
const thousands = Array.from({ length: 40 }, (_, idx) => idx * 1000);
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { insertOrderedFieldLine, locatedObject, type ObjectInsertionLocator } from "./fieldOrder";
|
|
3
|
+
import {
|
|
4
|
+
expressionName,
|
|
5
|
+
firstObjectReturnedByArrow,
|
|
6
|
+
hasParseDiagnostics,
|
|
7
|
+
heritageCall,
|
|
8
|
+
nodeName,
|
|
9
|
+
propertyName,
|
|
10
|
+
sourceFileFor,
|
|
11
|
+
} from "./sourceAst";
|
|
12
|
+
import { findNamedImport } from "./sourceImports";
|
|
13
|
+
import { spliceText } from "./sourceText";
|
|
14
|
+
|
|
15
|
+
interface ArrayInsertionLocator {
|
|
16
|
+
projectionStart: number;
|
|
17
|
+
projectionEnd: number;
|
|
18
|
+
fields: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AkanConstantFieldStructure {
|
|
22
|
+
name: string;
|
|
23
|
+
expressionBuilder: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface AkanConstantStructure {
|
|
27
|
+
parseValid: boolean;
|
|
28
|
+
inputObjectFound: boolean;
|
|
29
|
+
builderName: string | null;
|
|
30
|
+
fields: AkanConstantFieldStructure[];
|
|
31
|
+
lightProjectionFields: string[];
|
|
32
|
+
baseImports: string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const findConstantInputObject = (source: ts.SourceFile, className: string): ObjectInsertionLocator | null => {
|
|
36
|
+
let locator: ObjectInsertionLocator | null = null;
|
|
37
|
+
const visit = (node: ts.Node) => {
|
|
38
|
+
if (locator) return;
|
|
39
|
+
if (!ts.isClassDeclaration(node) || node.name?.text !== className) {
|
|
40
|
+
ts.forEachChild(node, visit);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const viaCall = heritageCall(node);
|
|
44
|
+
const callback = viaCall?.arguments.find((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
|
|
45
|
+
const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
|
|
46
|
+
if (objectLiteral) locator = locatedObject(source, objectLiteral);
|
|
47
|
+
};
|
|
48
|
+
ts.forEachChild(source, visit);
|
|
49
|
+
return locator;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const findLightProjectionArray = (source: ts.SourceFile, moduleClassName: string): ArrayInsertionLocator | null => {
|
|
53
|
+
let locator: ArrayInsertionLocator | null = null;
|
|
54
|
+
const visit = (node: ts.Node) => {
|
|
55
|
+
if (locator) return;
|
|
56
|
+
if (!ts.isClassDeclaration(node) || node.name?.text !== `Light${moduleClassName}`) {
|
|
57
|
+
ts.forEachChild(node, visit);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const viaCall = heritageCall(node);
|
|
61
|
+
const projectionArg = viaCall?.arguments.find((arg) => {
|
|
62
|
+
const expression = ts.isAsExpression(arg) ? arg.expression : arg;
|
|
63
|
+
return ts.isArrayLiteralExpression(expression);
|
|
64
|
+
});
|
|
65
|
+
const arrayLiteral = projectionArg
|
|
66
|
+
? ts.isAsExpression(projectionArg)
|
|
67
|
+
? projectionArg.expression
|
|
68
|
+
: projectionArg
|
|
69
|
+
: null;
|
|
70
|
+
if (!projectionArg || !arrayLiteral || !ts.isArrayLiteralExpression(arrayLiteral)) return;
|
|
71
|
+
locator = {
|
|
72
|
+
projectionStart: projectionArg.getStart(source),
|
|
73
|
+
projectionEnd: projectionArg.getEnd(),
|
|
74
|
+
fields: arrayLiteral.elements
|
|
75
|
+
.map((element) => (ts.isStringLiteralLike(element) ? element.text : null))
|
|
76
|
+
.filter((field): field is string => field !== null),
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
ts.forEachChild(source, visit);
|
|
80
|
+
return locator;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const fieldExpressionBuilder = (property: ts.ObjectLiteralElementLike) => {
|
|
84
|
+
if (!ts.isPropertyAssignment(property)) return null;
|
|
85
|
+
const initializer = ts.isAsExpression(property.initializer) ? property.initializer.expression : property.initializer;
|
|
86
|
+
if (!ts.isCallExpression(initializer)) return null;
|
|
87
|
+
return expressionName(initializer.expression);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const viaBuilderParameterName = (content: string, className: string) => {
|
|
91
|
+
const source = sourceFileFor("constant.ts", content);
|
|
92
|
+
let builderName: string | null = null;
|
|
93
|
+
const visit = (node: ts.Node) => {
|
|
94
|
+
if (builderName !== null) return;
|
|
95
|
+
if (!ts.isClassDeclaration(node) || node.name?.text !== className) {
|
|
96
|
+
ts.forEachChild(node, visit);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const viaCall = heritageCall(node);
|
|
100
|
+
const callback = viaCall?.arguments.find((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
|
|
101
|
+
if (callback && (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback))) {
|
|
102
|
+
builderName = nodeName(callback.parameters[0]?.name);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
ts.forEachChild(source, visit);
|
|
106
|
+
return builderName;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const inspectConstantStructure = (
|
|
110
|
+
content: string,
|
|
111
|
+
className: string,
|
|
112
|
+
moduleClassName: string,
|
|
113
|
+
): AkanConstantStructure => {
|
|
114
|
+
const source = sourceFileFor("constant.ts", content);
|
|
115
|
+
const inputObject = findConstantInputObject(source, className);
|
|
116
|
+
const lightProjection = findLightProjectionArray(source, moduleClassName);
|
|
117
|
+
const baseImport = findNamedImport(source, "akanjs/base");
|
|
118
|
+
const fields: AkanConstantFieldStructure[] = [];
|
|
119
|
+
if (inputObject) {
|
|
120
|
+
const visit = (node: ts.Node) => {
|
|
121
|
+
if (!ts.isClassDeclaration(node) || node.name?.text !== className) {
|
|
122
|
+
ts.forEachChild(node, visit);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const viaCall = heritageCall(node);
|
|
126
|
+
const callback = viaCall?.arguments.find((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
|
|
127
|
+
const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
|
|
128
|
+
if (!objectLiteral) return;
|
|
129
|
+
fields.push(
|
|
130
|
+
...objectLiteral.properties
|
|
131
|
+
.map((property): AkanConstantFieldStructure | null => {
|
|
132
|
+
const name = propertyName(property);
|
|
133
|
+
if (!name) return null;
|
|
134
|
+
return { name, expressionBuilder: fieldExpressionBuilder(property) };
|
|
135
|
+
})
|
|
136
|
+
.filter((field): field is AkanConstantFieldStructure => field !== null),
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
ts.forEachChild(source, visit);
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
parseValid: !hasParseDiagnostics(source),
|
|
143
|
+
inputObjectFound: inputObject !== null,
|
|
144
|
+
builderName: viaBuilderParameterName(content, className),
|
|
145
|
+
fields,
|
|
146
|
+
lightProjectionFields: lightProjection?.fields ?? [],
|
|
147
|
+
baseImports: baseImport?.names ?? [],
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export const insertIntoObject = (content: string, className: string, line: string) => {
|
|
152
|
+
const fieldName = /^([A-Za-z_$][\w$]*)\s*:/.exec(line.trim())?.[1];
|
|
153
|
+
if (!fieldName) return null;
|
|
154
|
+
const source = sourceFileFor("constant.ts", content);
|
|
155
|
+
const locator = findConstantInputObject(source, className);
|
|
156
|
+
if (!locator) return null;
|
|
157
|
+
return insertOrderedFieldLine(content, locator, fieldName, line, { fieldIndent: " ", closingIndent: "" });
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const insertLightProjectionField = (content: string, moduleClassName: string, fieldName: string) => {
|
|
161
|
+
const source = sourceFileFor("constant.ts", content);
|
|
162
|
+
const locator = findLightProjectionArray(source, moduleClassName);
|
|
163
|
+
if (!locator) return null;
|
|
164
|
+
if (locator.fields.includes(fieldName)) return content;
|
|
165
|
+
const nextFields = [...locator.fields, fieldName];
|
|
166
|
+
const nextArray =
|
|
167
|
+
nextFields.length === 0
|
|
168
|
+
? "[] as const"
|
|
169
|
+
: `[\n${nextFields.map((field) => ` ${JSON.stringify(field)},`).join("\n")}\n] as const`;
|
|
170
|
+
return spliceText(content, locator.projectionStart, locator.projectionEnd, nextArray);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export const insertEnumClass = (content: string, enumClassName: string, enumName: string, values: string[]) => {
|
|
174
|
+
if (content.includes(`export class ${enumClassName} extends enumOf`)) return content;
|
|
175
|
+
const enumClass = `export class ${enumClassName} extends enumOf("${enumName}", [\n${values
|
|
176
|
+
.map((value) => ` ${JSON.stringify(value)},`)
|
|
177
|
+
.join("\n")}\n] as const) {}\n\n`;
|
|
178
|
+
const firstClassIndex = content.indexOf("export class ");
|
|
179
|
+
if (firstClassIndex < 0) return `${content}\n${enumClass}`;
|
|
180
|
+
return `${content.slice(0, firstClassIndex)}${enumClass}${content.slice(firstClassIndex)}`;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export const hasConstantInputField = (content: string, className: string, fieldName: string) => {
|
|
184
|
+
const source = sourceFileFor("constant.ts", content);
|
|
185
|
+
if (hasParseDiagnostics(source)) return false;
|
|
186
|
+
return findConstantInputObject(source, className)?.fields.some((field) => field.name === fieldName) ?? false;
|
|
187
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { bilingualDescriptionForField, bilingualLabelForField, titleize } from "./fieldLabel";
|
|
3
|
+
import { insertOrderedFieldLine, locatedObject, type ObjectInsertionLocator } from "./fieldOrder";
|
|
4
|
+
import {
|
|
5
|
+
callExpressionName,
|
|
6
|
+
expressionName,
|
|
7
|
+
firstObjectReturnedByArrow,
|
|
8
|
+
hasParseDiagnostics,
|
|
9
|
+
sourceFileFor,
|
|
10
|
+
} from "./sourceAst";
|
|
11
|
+
import { lineStartAt, spliceText } from "./sourceText";
|
|
12
|
+
|
|
13
|
+
export interface AkanDictionaryStructure {
|
|
14
|
+
parseValid: boolean;
|
|
15
|
+
modelObjectFound: boolean;
|
|
16
|
+
chainOrderValid: boolean;
|
|
17
|
+
chainMethods: string[];
|
|
18
|
+
fields: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface DictionaryModelLocator extends ObjectInsertionLocator {
|
|
22
|
+
chainMethods: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const chainMethodsForCall = (node: ts.Expression): string[] => {
|
|
26
|
+
if (ts.isAsExpression(node) || ts.isParenthesizedExpression(node)) return chainMethodsForCall(node.expression);
|
|
27
|
+
if (!ts.isCallExpression(node)) return [];
|
|
28
|
+
if (ts.isPropertyAccessExpression(node.expression)) {
|
|
29
|
+
return [...chainMethodsForCall(node.expression.expression), node.expression.name.text];
|
|
30
|
+
}
|
|
31
|
+
const name = expressionName(node.expression);
|
|
32
|
+
return name ? [name] : [];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const outermostFluentCall = (node: ts.CallExpression) => {
|
|
36
|
+
let current: ts.CallExpression = node;
|
|
37
|
+
while (
|
|
38
|
+
ts.isPropertyAccessExpression(current.parent) &&
|
|
39
|
+
current.parent.expression === current &&
|
|
40
|
+
ts.isCallExpression(current.parent.parent) &&
|
|
41
|
+
current.parent.parent.expression === current.parent
|
|
42
|
+
) {
|
|
43
|
+
current = current.parent.parent;
|
|
44
|
+
}
|
|
45
|
+
return current;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const protectedDictionaryChainOrder = ["model", "slice", "enum", "error", "translate"] as const;
|
|
49
|
+
|
|
50
|
+
const dictionaryChainOrderValid = (chainMethods: readonly string[]) => {
|
|
51
|
+
const protectedOrder = new Map(protectedDictionaryChainOrder.map((method, index) => [method, index]));
|
|
52
|
+
let lastOrder = -1;
|
|
53
|
+
for (const method of chainMethods) {
|
|
54
|
+
const order = protectedOrder.get(method as (typeof protectedDictionaryChainOrder)[number]);
|
|
55
|
+
if (order === undefined) continue;
|
|
56
|
+
if (order < lastOrder) return false;
|
|
57
|
+
lastOrder = order;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const findDictionaryModelObject = (source: ts.SourceFile, moduleClassName: string) =>
|
|
63
|
+
findDictionaryStageObject(source, "model", moduleClassName);
|
|
64
|
+
|
|
65
|
+
const findDictionaryStageObject = (
|
|
66
|
+
source: ts.SourceFile,
|
|
67
|
+
stage: string,
|
|
68
|
+
typeName: string,
|
|
69
|
+
): DictionaryModelLocator | null => {
|
|
70
|
+
let locator: DictionaryModelLocator | null = null;
|
|
71
|
+
const visit = (node: ts.Node) => {
|
|
72
|
+
if (locator) return;
|
|
73
|
+
if (!ts.isCallExpression(node) || callExpressionName(node) !== stage) {
|
|
74
|
+
ts.forEachChild(node, visit);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const typeArgument = node.typeArguments?.[0];
|
|
78
|
+
if (!typeArgument || typeArgument.getText(source) !== typeName) {
|
|
79
|
+
ts.forEachChild(node, visit);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const callback = node.arguments.find((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
|
|
83
|
+
const objectLiteral = callback ? firstObjectReturnedByArrow(callback) : null;
|
|
84
|
+
if (objectLiteral) {
|
|
85
|
+
locator = {
|
|
86
|
+
...locatedObject(source, objectLiteral),
|
|
87
|
+
chainMethods: chainMethodsForCall(outermostFluentCall(node)),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
ts.forEachChild(source, visit);
|
|
92
|
+
return locator;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const inspectDictionaryStructure = (content: string, moduleClassName: string): AkanDictionaryStructure => {
|
|
96
|
+
const source = sourceFileFor("dictionary.ts", content);
|
|
97
|
+
const modelObject = findDictionaryModelObject(source, moduleClassName);
|
|
98
|
+
return {
|
|
99
|
+
parseValid: !hasParseDiagnostics(source),
|
|
100
|
+
modelObjectFound: modelObject !== null,
|
|
101
|
+
chainOrderValid: modelObject ? dictionaryChainOrderValid(modelObject.chainMethods) : false,
|
|
102
|
+
chainMethods: modelObject?.chainMethods ?? [],
|
|
103
|
+
fields: modelObject?.fields.map((field) => field.name) ?? [],
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const dictionaryModelFieldLine = (fieldName: string) => {
|
|
108
|
+
const label = bilingualLabelForField(fieldName);
|
|
109
|
+
const desc = bilingualDescriptionForField(fieldName);
|
|
110
|
+
return `${fieldName}: t([${JSON.stringify(label.en)}, ${JSON.stringify(label.ko)}]).desc([${JSON.stringify(
|
|
111
|
+
desc.en,
|
|
112
|
+
)}, ${JSON.stringify(desc.ko)}]),`;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export const insertDictionaryModelField = (content: string, moduleClassName: string, fieldName: string) => {
|
|
116
|
+
const source = sourceFileFor("dictionary.ts", content);
|
|
117
|
+
const locator = findDictionaryModelObject(source, moduleClassName);
|
|
118
|
+
if (!locator) return null;
|
|
119
|
+
return insertOrderedFieldLine(content, locator, fieldName, dictionaryModelFieldLine(fieldName), {
|
|
120
|
+
fieldIndent: " ",
|
|
121
|
+
closingIndent: " ",
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export const hasDictionaryModelField = (content: string, moduleClassName: string, fieldName: string) => {
|
|
126
|
+
const source = sourceFileFor("dictionary.ts", content);
|
|
127
|
+
if (hasParseDiagnostics(source)) return false;
|
|
128
|
+
return findDictionaryModelObject(source, moduleClassName)?.fields.some((field) => field.name === fieldName) ?? false;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const hasDictionaryEndpointEntry = (content: string, moduleClassName: string, entryName: string) => {
|
|
132
|
+
const source = sourceFileFor("dictionary.ts", content);
|
|
133
|
+
return (
|
|
134
|
+
findDictionaryStageObject(source, "endpoint", `${moduleClassName}Endpoint`)?.fields.some(
|
|
135
|
+
(field) => field.name === entryName,
|
|
136
|
+
) ?? false
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const insertDictionaryEndpointEntry = (
|
|
141
|
+
content: string,
|
|
142
|
+
moduleClassName: string,
|
|
143
|
+
entryName: string,
|
|
144
|
+
entryText: string,
|
|
145
|
+
) => {
|
|
146
|
+
const source = sourceFileFor("dictionary.ts", content);
|
|
147
|
+
const locator = findDictionaryStageObject(source, "endpoint", `${moduleClassName}Endpoint`);
|
|
148
|
+
if (!locator) return null;
|
|
149
|
+
return insertOrderedFieldLine(content, locator, entryName, entryText, { fieldIndent: " ", closingIndent: " " });
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const dictionaryChainOf = (node: ts.Node): ts.CallExpression | undefined => {
|
|
153
|
+
if (
|
|
154
|
+
ts.isCallExpression(node) &&
|
|
155
|
+
outermostFluentCall(node) === node &&
|
|
156
|
+
protectedDictionaryChainOrder.some((method) => chainMethodsForCall(node).includes(method))
|
|
157
|
+
)
|
|
158
|
+
return node;
|
|
159
|
+
return ts.forEachChild(node, dictionaryChainOf);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const chainMethodNames = (call: ts.Expression): ts.Identifier[] => {
|
|
163
|
+
if (!ts.isCallExpression(call) || !ts.isPropertyAccessExpression(call.expression)) return [];
|
|
164
|
+
const name = call.expression.name;
|
|
165
|
+
return [...chainMethodNames(call.expression.expression), ...(ts.isIdentifier(name) ? [name] : [])];
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
//* Located on the parsed chain, never by text search: the sample dictionary's header comment mentions `.error()`.
|
|
169
|
+
export const insertDictionaryEnum = (content: string, enumClassName: string, enumName: string, values: string[]) => {
|
|
170
|
+
if (content.includes(`.enum<${enumClassName}>("${enumName}"`)) return content;
|
|
171
|
+
const source = sourceFileFor("dictionary.ts", content);
|
|
172
|
+
if (hasParseDiagnostics(source)) return null;
|
|
173
|
+
const chain = dictionaryChainOf(source);
|
|
174
|
+
if (!chain) return null;
|
|
175
|
+
const enumBlock = ` .enum<${enumClassName}>("${enumName}", (t) => ({\n${values
|
|
176
|
+
.map((value) => ` ${value}: t([${JSON.stringify(titleize(value))}, ${JSON.stringify(titleize(value))}]),`)
|
|
177
|
+
.join("\n")}\n }))\n`;
|
|
178
|
+
const later = chainMethodNames(chain).find((name) => name.text === "error" || name.text === "translate");
|
|
179
|
+
if (!later) return spliceText(content, chain.getEnd(), chain.getEnd(), `\n${enumBlock.trimEnd()}`);
|
|
180
|
+
const dot = content.lastIndexOf(".", later.getStart(source));
|
|
181
|
+
const lineStart = lineStartAt(content, dot);
|
|
182
|
+
if (content.slice(lineStart, dot).trim() === "") return spliceText(content, lineStart, lineStart, enumBlock);
|
|
183
|
+
return spliceText(content, dot, dot, `\n${enumBlock}`);
|
|
184
|
+
};
|
package/workflow/executor.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { capitalize } from "akanjs/common";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import type { AkanModuleContext } from "../akanContext";
|
|
4
3
|
import type { Sys, Workspace } from "../commandDecorators";
|
|
4
|
+
import type { AkanModuleContext } from "../context/akanContext";
|
|
5
5
|
import { AppExecutor, LibExecutor } from "../executors";
|
|
6
6
|
import { createWorkflowApplyReport, workflowCommandsForPlan } from "./artifacts";
|
|
7
|
+
import { inspectConstantStructure } from "./constantSource";
|
|
8
|
+
import { inspectDictionaryStructure } from "./dictionarySource";
|
|
9
|
+
import { normalizeFieldType } from "./fieldExpression";
|
|
10
|
+
import { insertionIndexForFieldOrder } from "./fieldOrder";
|
|
7
11
|
import { buildAkanModuleContextIndex } from "./moduleIndex";
|
|
8
|
-
import {
|
|
9
|
-
insertionIndexForFieldOrder,
|
|
10
|
-
inspectConstantStructure,
|
|
11
|
-
inspectDictionaryStructure,
|
|
12
|
-
moduleComponentName,
|
|
13
|
-
moduleSourcePaths,
|
|
14
|
-
normalizeFieldType,
|
|
15
|
-
} from "./source";
|
|
12
|
+
import { moduleComponentName, moduleSourcePaths } from "./modulePaths";
|
|
16
13
|
import type {
|
|
17
14
|
PrimitiveChangedFile,
|
|
18
15
|
PrimitiveGeneratedFile,
|