@akanjs/devkit 3.2.0-rc.3 → 3.2.0-rc.31
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 +369 -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 +17 -2
- package/codeAgent/skills/akan-scaffold/SKILL.md +2 -2
- package/codeAgent/skills/akan-transport/SKILL.md +2 -0
- package/codeAgent/skills/akan-validate/SKILL.md +1 -0
- package/codeAgent/tools/AkanCli.ts +1 -1
- package/codeAgent/tools/AkanToolPack.ts +1 -1
- package/codeAgent/tools/McpClient.ts +28 -6
- package/codeAgent/tools/McpToolPack.ts +1 -1
- package/codeAgent/tools/akanCodePlugins.test.ts +14 -2
- package/commandDecorators/argMeta.ts +4 -0
- package/commandDecorators/cliError.ts +72 -0
- package/commandDecorators/command.ts +165 -91
- package/commandDecorators/commandBuilder.ts +1 -1
- package/commandDecorators/commandDecorators.test.ts +191 -16
- package/commandDecorators/exitCodeError.ts +6 -7
- package/commandDecorators/index.ts +1 -0
- package/commandDecorators/targetMeta.ts +1 -0
- package/commandDecorators/workspaceVersionCheck.test.ts +1 -1
- package/commandDecorators/workspaceVersionCheck.ts +1 -1
- package/context/akanContext.ts +576 -0
- package/context/akanContextInspection.ts +296 -0
- package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
- package/{akanMcpContract.ts → context/akanMcpContract.ts} +32 -262
- package/context/akanMcpToolError.ts +16 -0
- package/context/doctor/agentGuideCheck.ts +81 -0
- package/context/doctor/configLeftoverCheck.ts +35 -0
- package/context/doctor/doctorFindings.ts +70 -0
- package/context/doctor/generatedFreshness.ts +56 -0
- package/context/doctor/moduleShapeCheck.ts +88 -0
- package/context/doctor/recipeDuplicateCheck.ts +39 -0
- package/context/doctor/recipeIndexCheck.ts +87 -0
- package/context/doctor/rootShapeCheck.ts +55 -0
- package/context/doctor/workflowScope.ts +97 -0
- package/{constantFieldNames.test.ts → context/moduleFieldNames.test.ts} +24 -2
- package/context/moduleFieldNames.ts +25 -0
- package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
- package/context/safeRead.ts +9 -0
- package/csrE2e/csrE2eHarness.fixture.ts +1 -1
- package/devkitUtils.test.ts +39 -5
- package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
- package/{apiReference.ts → docs/apiReference.ts} +2 -2
- package/docs/errorCodeReference.test.ts +282 -0
- package/docs/errorCodeReference.ts +71 -0
- package/docs/errorCodeScan.ts +551 -0
- package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
- package/executors/appExecutor.ts +448 -0
- package/executors/commandExecutionError.ts +53 -0
- package/executors/executor.ts +527 -0
- package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
- package/{executors.test.ts → executors/executors.test.ts} +76 -15
- package/executors/index.ts +8 -0
- package/executors/libExecutor.ts +23 -0
- package/executors/moduleExecutor.ts +18 -0
- package/executors/pkgExecutor.ts +129 -0
- package/executors/sysExecutor.ts +301 -0
- package/executors/workspaceExecutor.ts +277 -0
- package/frontendBuild/allRoutesBuilder.test.ts +17 -5
- package/frontendBuild/allRoutesBuilder.ts +24 -6
- package/frontendBuild/autoImportSync.test.ts +1 -1
- package/frontendBuild/autoImportSync.ts +1 -1
- package/frontendBuild/buildRouteClient.test.ts +1 -1
- package/frontendBuild/bundleDefine.ts +2 -0
- package/frontendBuild/clientBuildTypes.ts +5 -2
- package/frontendBuild/clientEntriesBundler.test.ts +1 -1
- package/frontendBuild/clientEntryDiscovery.test.ts +28 -0
- package/frontendBuild/clientEntryDiscovery.ts +25 -6
- package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
- package/frontendBuild/csrDevArtifactWriter.ts +1 -1
- package/frontendBuild/cssCompiler.test.ts +1 -1
- package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
- package/frontendBuild/devGeneratedIndexSync.ts +7 -38
- package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
- package/frontendBuild/fontOptimizer.test.ts +1 -1
- package/frontendBuild/fontPruner.test.ts +1 -1
- package/frontendBuild/frontendBuild.test.ts +3 -3
- package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
- package/frontendBuild/hmrWatcher.test.ts +1 -1
- package/frontendBuild/hmrWatcher.ts +22 -1
- package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
- package/frontendBuild/mcpAppViewBuilder.ts +1 -1
- package/frontendBuild/nativeCore.test.ts +148 -0
- package/frontendBuild/optionalPeers.test.ts +36 -8
- package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
- package/frontendBuild/pagesBundleBuilder.ts +1 -1
- package/frontendBuild/precompressArtifacts.test.ts +1 -1
- package/frontendBuild/precompressArtifacts.ts +1 -1
- package/frontendBuild/serverGraphFile.ts +1 -1
- package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
- package/frontendBuild/ssrBaseArtifactBuilder.test.ts +26 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +23 -19
- package/frontendBuild/ssrDevBundler.test.ts +1 -1
- package/frontendBuild/vendorImportScanner.test.ts +25 -4
- package/frontendBuild/vendorImportScanner.ts +25 -10
- package/frontendBuild/vendorNarrowing.test.ts +1 -1
- package/frontendBuild/watchRootResolver.test.ts +1 -1
- package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
- package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
- package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
- package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
- package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
- package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
- package/{prompter.ts → guideline/prompter.ts} +2 -3
- package/incrementalBuilder/buildBatch.proc.ts +14 -4
- package/incrementalBuilder/buildBatchProtocol.ts +2 -0
- package/incrementalBuilder/buildBatchRunner.test.ts +108 -1
- package/incrementalBuilder/buildBatchRunner.ts +17 -4
- package/incrementalBuilder/builderBoot.ts +106 -0
- package/incrementalBuilder/builderBuildStatus.ts +23 -0
- package/incrementalBuilder/builderChannel.test.ts +1 -1
- package/incrementalBuilder/builderChannel.ts +11 -0
- package/incrementalBuilder/builderGraphPayloads.ts +3 -3
- package/incrementalBuilder/builderLanes.ts +157 -0
- package/incrementalBuilder/builderWatch.ts +213 -0
- package/incrementalBuilder/csrRegistry.ts +234 -0
- package/incrementalBuilder/incrementalBuilder.host.test.ts +30 -1
- package/incrementalBuilder/incrementalBuilder.host.ts +10 -22
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +93 -2
- package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
- package/incrementalBuilder/ssrRegistry.ts +278 -0
- package/index.ts +22 -22
- package/integration/devStability.integration.test.ts +62 -56
- package/integration/devStabilityHarness.test.ts +1 -1
- package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
- package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
- package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
- package/lint/gritRules.test.ts +1 -1
- package/{linter.test.ts → lint/linter.test.ts} +1 -1
- package/lint/no-import-common-err.grit +31 -0
- package/lint/no-init-fetch-in-client.grit +1 -1
- package/lint/no-web-only-api-outside-webkit.grit +3 -3
- package/mobile/desktopBin.test.ts +1 -1
- package/mobile/desktopRelease.test.ts +1 -1
- package/mobile/desktopServerStage.test.ts +2 -2
- package/mobile/desktopServerStage.ts +1 -1
- package/mobile/nativeApi.test.ts +1 -1
- package/mobile/nativeApp.test.ts +1 -1
- package/mobile/nativeConfig.test.ts +1 -1
- package/mobile/nativePluginFolders.test.ts +1 -1
- package/mobile/nativePublicEnv.test.ts +1 -1
- package/mobile/nativeWebDir.test.ts +1 -1
- package/mobile/serverBundleSecrets.test.ts +1 -1
- package/mobile/tarWriter.test.ts +1 -1
- package/mobile/updatePackFolder.test.ts +1 -1
- package/package.json +167 -3
- package/packageExports.test.ts +20 -2
- package/piDependencyPins.test.ts +1 -1
- package/pipeline/PipelineDefinition.ts +1 -1
- package/platformTest/IdleWatchedProcess.test.ts +1 -1
- package/platformTest/PlatformTestRun.test.ts +1 -1
- package/platformTest/TestSnapshot.test.ts +1 -1
- package/preview/PreviewView.ts +32 -13
- package/preview/previewView.test.ts +33 -3
- package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
- package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
- package/quality/bareErrorScanner.ts +126 -0
- package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
- package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
- package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
- package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
- package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
- package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
- package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
- package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
- package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +1 -1
- package/{qualityScanner.ts → quality/qualityScanner.ts} +8 -8
- package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
- package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
- package/{subspace.ts → subspace/subspace.ts} +5 -5
- package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
- package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
- package/{testHelpers.ts → test/testHelpers.ts} +37 -1
- package/transforms/barrelAnalyzer.ts +31 -10
- package/transforms/browserDirnamePlugin.test.ts +1 -1
- package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
- package/transforms/mcpAppPageTrimmer.test.ts +1 -1
- package/transforms/pureLazyMarker.test.ts +1 -1
- package/transforms/serverEnvPlugin.test.ts +1 -1
- package/transforms/serverEnvProfile.test.ts +1 -1
- package/transforms/sideEffectImportOrder.test.ts +1 -1
- package/transforms/transforms.test.ts +52 -2
- package/transforms/tsconfigPackageResolver.test.ts +1 -1
- package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
- package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
- package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
- package/typecheck/projectTypecheck.test.ts +1 -1
- package/typecheck/projectTypecheck.ts +6 -2
- package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
- package/{typeChecker.ts → typecheck/typeChecker.ts} +1 -1
- package/typecheck/typecheck.proc.ts +4 -3
- package/typecheck/typecheckFailure.ts +7 -2
- package/util/errorReport.ts +66 -0
- package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
- package/workflow/artifacts.ts +8 -7
- package/workflow/constantSource.ts +187 -0
- package/workflow/dictionarySource.ts +184 -0
- package/workflow/executor.ts +6 -9
- package/workflow/fieldExpression.ts +153 -0
- package/workflow/fieldLabel.ts +61 -0
- package/workflow/fieldOrder.ts +117 -0
- package/workflow/fieldType.ts +93 -0
- package/workflow/guardCatalog.test.ts +1 -1
- package/workflow/index.ts +1 -0
- package/workflow/keyRename.ts +1 -1
- package/workflow/moduleIndex.test.ts +2 -2
- package/workflow/moduleIndex.ts +2 -2
- package/workflow/modulePaths.ts +27 -0
- package/workflow/mutationScaffold.ts +7 -15
- package/workflow/mutationSource.ts +2 -1
- package/workflow/plainName.ts +16 -3
- package/workflow/plan.ts +14 -2
- package/workflow/primitiveReport.ts +78 -0
- package/workflow/rolloutGate.test.ts +1 -1
- package/workflow/rolloutGate.ts +1 -1
- package/workflow/serviceSource.ts +33 -0
- package/workflow/signalSource.ts +96 -0
- package/workflow/source.ts +50 -1105
- package/workflow/sourceAst.ts +30 -0
- package/workflow/sourceImports.ts +105 -0
- package/workflow/sourceText.ts +13 -0
- package/workflow/templateSource.ts +30 -0
- package/workflow/testSource.ts +31 -0
- package/workflow/types.ts +1 -1
- package/workflow/uiPolicy.ts +1 -1
- package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
- package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
- package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
- package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
- package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
- package/{envSeed.ts → workspace/envSeed.ts} +1 -1
- package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
- package/{libSource.ts → workspace/libSource.ts} +1 -1
- package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
- package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
- package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
- package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
- package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
- package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
- package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
- package/akanContext.ts +0 -1084
- package/constantFieldNames.ts +0 -18
- package/executors.ts +0 -1749
- /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
- /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
- /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
- /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
- /package/{linter.ts → lint/linter.ts} +0 -0
- /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
- /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
- /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
- /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
- /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
- /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
- /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
- /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
- /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
- /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
- /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
- /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
- /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
- /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
- /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
- /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
- /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
- /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
- /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
- /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
- /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
- /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
- /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
- /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
- /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
- /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
- /package/{storeSource.ts → quality/storeSource.ts} +0 -0
- /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
- /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
- /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
- /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
- /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
- /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
- /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
- /package/{writePath.ts → quality/writePath.ts} +0 -0
- /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
- /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
- /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
- /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
- /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
- /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
- /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
- /package/{fileSys.test.ts → util/fileSys.test.ts} +0 -0
- /package/{fileSys.ts → util/fileSys.ts} +0 -0
- /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
- /package/{selectModel.ts → util/selectModel.ts} +0 -0
- /package/{semver.test.ts → util/semver.test.ts} +0 -0
- /package/{semver.ts → util/semver.ts} +0 -0
- /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
- /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
- /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
- /package/{spinner.ts → util/spinner.ts} +0 -0
- /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
- /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
- /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
- /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
- /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
- /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
- /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
- /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
- /package/{types.ts → workspace/types.ts} +0 -0
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
import { MaintainabilityLimits } from "../quality/maintainabilityLimits";
|
|
5
|
+
|
|
6
|
+
export interface ErrorCodeRow {
|
|
7
|
+
code: string | null;
|
|
8
|
+
byStatus: boolean;
|
|
9
|
+
statusCode: number | null;
|
|
10
|
+
error: string;
|
|
11
|
+
forwarded: boolean;
|
|
12
|
+
wire: boolean;
|
|
13
|
+
file: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const byStatus = Symbol("byStatus");
|
|
17
|
+
|
|
18
|
+
type Value = string | number | undefined | typeof byStatus;
|
|
19
|
+
type Values = readonly Value[] | null;
|
|
20
|
+
type Env = ReadonlyMap<string, Binding>;
|
|
21
|
+
type Pins = ReadonlyMap<ts.ParameterDeclaration, Value>;
|
|
22
|
+
|
|
23
|
+
interface Binding {
|
|
24
|
+
values: Values;
|
|
25
|
+
source: { expression: ts.Expression; env: Env } | null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface Call {
|
|
29
|
+
args: readonly ts.Expression[];
|
|
30
|
+
env: Env;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface Evaluation {
|
|
34
|
+
codes: Values;
|
|
35
|
+
statuses: Values;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type ClassNode = ts.ClassDeclaration | ts.ClassExpression;
|
|
39
|
+
|
|
40
|
+
const unwrapped = (expression: ts.Expression) => {
|
|
41
|
+
let current = expression;
|
|
42
|
+
while (
|
|
43
|
+
ts.isParenthesizedExpression(current) ||
|
|
44
|
+
ts.isAsExpression(current) ||
|
|
45
|
+
ts.isSatisfiesExpression(current) ||
|
|
46
|
+
ts.isNonNullExpression(current)
|
|
47
|
+
)
|
|
48
|
+
current = current.expression;
|
|
49
|
+
return current;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const isClassNode = (node: ts.Node | undefined): node is ClassNode =>
|
|
53
|
+
!!node && (ts.isClassDeclaration(node) || ts.isClassExpression(node));
|
|
54
|
+
|
|
55
|
+
const statusCodeOf = (property: ts.ObjectLiteralElementLike): ts.Expression | null => {
|
|
56
|
+
if (ts.isPropertyAssignment(property) && property.name.getText() === "statusCode") return property.initializer;
|
|
57
|
+
if (ts.isShorthandPropertyAssignment(property) && property.name.text === "statusCode") return property.name;
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const byCodeUnit = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0);
|
|
62
|
+
|
|
63
|
+
export class ErrorCodeScan {
|
|
64
|
+
readonly #dir: string;
|
|
65
|
+
readonly #roots: ReadonlySet<string>;
|
|
66
|
+
readonly #program: ts.Program;
|
|
67
|
+
readonly #checker: ts.TypeChecker;
|
|
68
|
+
readonly #akanError: ts.ClassDeclaration;
|
|
69
|
+
readonly #statuses: ReadonlyMap<number, readonly [code: string, reason: string]>;
|
|
70
|
+
readonly #callSites = new Map<ClassNode, Call[]>();
|
|
71
|
+
readonly #descends = new Map<ClassNode, boolean>();
|
|
72
|
+
|
|
73
|
+
constructor(akanjsDir: string) {
|
|
74
|
+
this.#dir = akanjsDir;
|
|
75
|
+
this.#roots = ErrorCodeScan.#rootsOf(akanjsDir);
|
|
76
|
+
const configPath = path.join(akanjsDir, "tsconfig.json");
|
|
77
|
+
const config = ts.sys.fileExists(configPath) ? ts.readConfigFile(configPath, ts.sys.readFile).config : {};
|
|
78
|
+
const parsed = ts.parseJsonConfigFileContent(config, ts.sys, akanjsDir, undefined, configPath);
|
|
79
|
+
this.#program = ts.createProgram({
|
|
80
|
+
rootNames: [...this.#roots].map((file) => path.join(akanjsDir, file)),
|
|
81
|
+
options: { ...parsed.options, noEmit: true },
|
|
82
|
+
});
|
|
83
|
+
this.#checker = this.#program.getTypeChecker();
|
|
84
|
+
const base = this.#program.getSourceFile(path.join(akanjsDir, "base", "akanError.ts"));
|
|
85
|
+
const akanError = base?.statements.find(
|
|
86
|
+
(statement): statement is ts.ClassDeclaration =>
|
|
87
|
+
ts.isClassDeclaration(statement) && statement.name?.text === "AkanError",
|
|
88
|
+
);
|
|
89
|
+
if (!akanError) throw new Error(`${akanjsDir}/base/akanError.ts declares no AkanError class`);
|
|
90
|
+
this.#akanError = akanError;
|
|
91
|
+
this.#statuses = ErrorCodeScan.#statusTableOf(akanError);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get statuses() {
|
|
95
|
+
return this.#statuses;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
rows(): ErrorCodeRow[] {
|
|
99
|
+
const classes = this.#classes();
|
|
100
|
+
for (const call of this.#newExpressions()) {
|
|
101
|
+
const target = this.#classOf(call.expression);
|
|
102
|
+
if (target && classes.includes(target))
|
|
103
|
+
this.#callSites.set(target, [
|
|
104
|
+
...(this.#callSites.get(target) ?? []),
|
|
105
|
+
{ args: call.arguments ?? [], env: new Map() },
|
|
106
|
+
]);
|
|
107
|
+
}
|
|
108
|
+
const rows = new Map<string, ErrorCodeRow>();
|
|
109
|
+
for (const node of classes) {
|
|
110
|
+
const forwardedOf = this.#forwardedOf(node);
|
|
111
|
+
const toJsonHasCode = this.#toJsonHasCode(node);
|
|
112
|
+
const file = this.#relative(node.getSourceFile().fileName);
|
|
113
|
+
for (const { codes, statuses } of this.#evaluationsOf(node))
|
|
114
|
+
for (const code of codes ?? [null])
|
|
115
|
+
for (const statusCode of statuses ?? [null]) {
|
|
116
|
+
const forwarded = forwardedOf(code);
|
|
117
|
+
const row: ErrorCodeRow = {
|
|
118
|
+
code: typeof code === "string" ? code : null,
|
|
119
|
+
byStatus: code === byStatus,
|
|
120
|
+
statusCode: typeof statusCode === "number" ? statusCode : null,
|
|
121
|
+
error: this.#nameOf(node),
|
|
122
|
+
forwarded,
|
|
123
|
+
wire: !forwarded || toJsonHasCode,
|
|
124
|
+
file,
|
|
125
|
+
};
|
|
126
|
+
rows.set(`${row.code}|${row.byStatus}|${row.statusCode}|${row.error}|${row.file}`, row);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return [...rows.values()].sort(ErrorCodeScan.#byCode);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
#evaluationsOf(node: ClassNode): Evaluation[] {
|
|
133
|
+
const sites = this.#callSites.get(node) ?? [];
|
|
134
|
+
if (node === this.#akanError) return sites.map((call) => this.#akanErrorCall(call));
|
|
135
|
+
const free = this.#evaluate(node, null);
|
|
136
|
+
if (free.codes !== null && free.statuses !== null) return this.#perCode(node, free);
|
|
137
|
+
return sites.length ? sites.map((call) => this.#evaluate(node, call)) : [free];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
#perCode(node: ClassNode, free: Evaluation): Evaluation[] {
|
|
141
|
+
const codes = free.codes ?? [];
|
|
142
|
+
if (codes.length < 2 || (free.statuses?.length ?? 0) < 2) return [free];
|
|
143
|
+
const parameter = this.#freeParametersOf(node).find((each) => {
|
|
144
|
+
const values = this.#literalsOf(this.#checker.getTypeAtLocation(each.name));
|
|
145
|
+
return values?.length === codes.length && values.every((value) => codes.includes(value));
|
|
146
|
+
});
|
|
147
|
+
if (!parameter) return [free];
|
|
148
|
+
return codes.map((code) => this.#evaluate(node, null, new Map([[parameter, code]])));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
#freeParametersOf(node: ClassNode): readonly ts.ParameterDeclaration[] {
|
|
152
|
+
for (
|
|
153
|
+
let current: ClassNode | null = node;
|
|
154
|
+
current && current !== this.#akanError;
|
|
155
|
+
current = this.#baseOf(current)
|
|
156
|
+
) {
|
|
157
|
+
const ctor = current.members.find(
|
|
158
|
+
(member): member is ts.ConstructorDeclaration => ts.isConstructorDeclaration(member) && !!member.body,
|
|
159
|
+
);
|
|
160
|
+
if (ctor) return ctor.parameters;
|
|
161
|
+
}
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
#evaluate(node: ClassNode, call: Call | null, pins: Pins = new Map()): Evaluation {
|
|
166
|
+
const base = this.#baseOf(node);
|
|
167
|
+
const ctor = node.members.find(
|
|
168
|
+
(member): member is ts.ConstructorDeclaration => ts.isConstructorDeclaration(member) && !!member.body,
|
|
169
|
+
);
|
|
170
|
+
if (!ctor) {
|
|
171
|
+
if (base === this.#akanError) return this.#akanErrorCall(call);
|
|
172
|
+
return base ? this.#evaluate(base, call, pins) : { codes: null, statuses: null };
|
|
173
|
+
}
|
|
174
|
+
const env = new Map<string, Binding>();
|
|
175
|
+
ctor.parameters.forEach((parameter, idx) => {
|
|
176
|
+
if (!ts.isIdentifier(parameter.name)) return;
|
|
177
|
+
env.set(parameter.name.text, this.#bindingOf(parameter, idx, call, env, pins));
|
|
178
|
+
});
|
|
179
|
+
const superCall = ctor.body?.statements
|
|
180
|
+
.map((statement) => (ts.isExpressionStatement(statement) ? unwrapped(statement.expression) : null))
|
|
181
|
+
.find(
|
|
182
|
+
(expression): expression is ts.CallExpression =>
|
|
183
|
+
!!expression && ts.isCallExpression(expression) && expression.expression.kind === ts.SyntaxKind.SuperKeyword,
|
|
184
|
+
);
|
|
185
|
+
if (!superCall) return { codes: null, statuses: null };
|
|
186
|
+
const passed: Call = { args: superCall.arguments, env };
|
|
187
|
+
if (base === this.#akanError) return this.#akanErrorCall(passed);
|
|
188
|
+
return base ? this.#evaluate(base, passed) : { codes: null, statuses: null };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
#bindingOf(parameter: ts.ParameterDeclaration, idx: number, call: Call | null, env: Env, pins: Pins): Binding {
|
|
192
|
+
if (call === null) {
|
|
193
|
+
const pinned: Values = pins.has(parameter) ? [pins.get(parameter)] : null;
|
|
194
|
+
return { values: pinned ?? this.#literalsOf(this.#checker.getTypeAtLocation(parameter.name)), source: null };
|
|
195
|
+
}
|
|
196
|
+
if (parameter.dotDotDotToken || call.args.slice(0, idx + 1).some(ts.isSpreadElement))
|
|
197
|
+
return { values: null, source: null };
|
|
198
|
+
const expression = call.args[idx] ?? parameter.initializer;
|
|
199
|
+
if (!expression) return { values: [undefined], source: null };
|
|
200
|
+
const scope = call.args[idx] ? call.env : env;
|
|
201
|
+
return { values: this.#value(expression, scope), source: { expression, env: scope } };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
#akanErrorCall(call: Call | null): Evaluation {
|
|
205
|
+
if (!call) return { codes: null, statuses: null };
|
|
206
|
+
const [code, , options] = call.args;
|
|
207
|
+
return { codes: code ? this.#value(code, call.env) : null, statuses: this.#statusOf(options, call.env) };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
#statusOf(options: ts.Expression | undefined, env: Env): Values {
|
|
211
|
+
if (!options) return [500];
|
|
212
|
+
const inner = unwrapped(options);
|
|
213
|
+
const binding = ts.isIdentifier(inner) ? env.get(inner.text) : undefined;
|
|
214
|
+
if (binding?.source) return this.#statusOf(binding.source.expression, binding.source.env);
|
|
215
|
+
if (binding?.values?.every((each) => each === undefined)) return [500];
|
|
216
|
+
if (!ts.isObjectLiteralExpression(inner)) return this.#holdsStatusCode(inner) ? null : [500];
|
|
217
|
+
for (const property of [...inner.properties].reverse()) {
|
|
218
|
+
if (ts.isSpreadAssignment(property)) {
|
|
219
|
+
if (this.#holdsStatusCode(property.expression)) return null;
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const initializer = statusCodeOf(property);
|
|
223
|
+
if (initializer) return this.#value(initializer, env)?.map((each) => (each === undefined ? 500 : each)) ?? null;
|
|
224
|
+
}
|
|
225
|
+
return [500];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
#holdsStatusCode(expression: ts.Expression) {
|
|
229
|
+
const type = this.#checker.getNonNullableType(this.#checker.getTypeAtLocation(expression));
|
|
230
|
+
return !!type.getProperty("statusCode");
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
#value(expression: ts.Expression, env: Env): Values {
|
|
234
|
+
const inner = unwrapped(expression);
|
|
235
|
+
if (ts.isStringLiteral(inner) || ts.isNoSubstitutionTemplateLiteral(inner)) return [inner.text];
|
|
236
|
+
if (ts.isNumericLiteral(inner)) return [Number(inner.text)];
|
|
237
|
+
if (ts.isConditionalExpression(inner)) {
|
|
238
|
+
const holds = this.#holds(inner.condition, env);
|
|
239
|
+
if (holds !== null) return this.#value(holds ? inner.whenTrue : inner.whenFalse, env);
|
|
240
|
+
const [whenTrue, whenFalse] = [this.#value(inner.whenTrue, env), this.#value(inner.whenFalse, env)];
|
|
241
|
+
return whenTrue && whenFalse ? [...new Set([...whenTrue, ...whenFalse])] : null;
|
|
242
|
+
}
|
|
243
|
+
if (ts.isIdentifier(inner)) {
|
|
244
|
+
const binding = env.get(inner.text);
|
|
245
|
+
if (binding) return binding.values;
|
|
246
|
+
if (inner.text === "undefined") return [undefined];
|
|
247
|
+
}
|
|
248
|
+
if (ts.isElementAccessExpression(inner)) return this.#lookup(inner, env);
|
|
249
|
+
if (ts.isCallExpression(inner) && this.#isCodeOfStatus(inner.expression)) {
|
|
250
|
+
const [status] = inner.arguments;
|
|
251
|
+
const statuses = status ? this.#value(status, env) : null;
|
|
252
|
+
const known = statuses?.filter((each): each is number => typeof each === "number") ?? [];
|
|
253
|
+
return statuses && known.length === statuses.length ? known.map((each) => this.#codeOf(each)) : [byStatus];
|
|
254
|
+
}
|
|
255
|
+
return this.#literalsOf(this.#checker.getTypeAtLocation(inner));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
#holds(condition: ts.Expression, env: Env): boolean | null {
|
|
259
|
+
const inner = unwrapped(condition);
|
|
260
|
+
if (!ts.isBinaryExpression(inner)) return null;
|
|
261
|
+
const operator = inner.operatorToken.kind;
|
|
262
|
+
const equal = operator === ts.SyntaxKind.EqualsEqualsEqualsToken;
|
|
263
|
+
if (!equal && operator !== ts.SyntaxKind.ExclamationEqualsEqualsToken) return null;
|
|
264
|
+
const [left, right] = [this.#value(inner.left, env), this.#value(inner.right, env)];
|
|
265
|
+
if (left?.length !== 1 || right?.length !== 1) return null;
|
|
266
|
+
return (left[0] === right[0]) === equal;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
#lookup(access: ts.ElementAccessExpression, env: Env): Values {
|
|
270
|
+
const table = this.#tableOf(access.expression);
|
|
271
|
+
const keys = this.#value(access.argumentExpression, env);
|
|
272
|
+
if (!table || !keys) return null;
|
|
273
|
+
const values = new Set<Value>();
|
|
274
|
+
for (const key of keys) {
|
|
275
|
+
const entry = table.properties.find(
|
|
276
|
+
(property): property is ts.PropertyAssignment =>
|
|
277
|
+
ts.isPropertyAssignment(property) &&
|
|
278
|
+
(ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) || ts.isNumericLiteral(property.name)) &&
|
|
279
|
+
property.name.text === String(key),
|
|
280
|
+
);
|
|
281
|
+
const found = entry ? this.#value(entry.initializer, new Map()) : null;
|
|
282
|
+
if (!found) return null;
|
|
283
|
+
for (const value of found) values.add(value);
|
|
284
|
+
}
|
|
285
|
+
return [...values];
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
#tableOf(expression: ts.Expression): ts.ObjectLiteralExpression | null {
|
|
289
|
+
const symbol = this.#checker.getSymbolAtLocation(unwrapped(expression));
|
|
290
|
+
for (const declaration of symbol?.declarations ?? []) {
|
|
291
|
+
if (!ts.isPropertyDeclaration(declaration) || !declaration.initializer) continue;
|
|
292
|
+
if (!(ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Readonly)) continue;
|
|
293
|
+
const initializer = unwrapped(declaration.initializer);
|
|
294
|
+
if (ts.isObjectLiteralExpression(initializer)) return initializer;
|
|
295
|
+
}
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
#codeOf(statusCode: number) {
|
|
300
|
+
return this.#statuses.get(statusCode)?.[0] ?? `http${statusCode}`;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
#isCodeOfStatus(callee: ts.Expression) {
|
|
304
|
+
return (
|
|
305
|
+
ts.isPropertyAccessExpression(callee) &&
|
|
306
|
+
callee.name.text === "codeOfStatus" &&
|
|
307
|
+
this.#classOf(callee.expression) === this.#akanError
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
#literalsOf(type: ts.Type): Values {
|
|
312
|
+
const members = type.isUnion() ? type.types : [type];
|
|
313
|
+
const values: Value[] = [];
|
|
314
|
+
for (const member of members) {
|
|
315
|
+
if (member.isStringLiteral() || member.isNumberLiteral()) values.push(member.value);
|
|
316
|
+
else if (!(member.flags & ts.TypeFlags.Undefined)) return null;
|
|
317
|
+
}
|
|
318
|
+
return values.length ? values : null;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
#forwardedOf(node: ClassNode): (code: Value | null) => boolean {
|
|
322
|
+
for (let current: ClassNode | null = node; current; current = this.#baseOf(current)) {
|
|
323
|
+
const getter = current.members.find(
|
|
324
|
+
(member): member is ts.GetAccessorDeclaration =>
|
|
325
|
+
ts.isGetAccessorDeclaration(member) && member.name.getText() === "forwarded",
|
|
326
|
+
);
|
|
327
|
+
if (!getter) continue;
|
|
328
|
+
const [statement, ...rest] = getter.body?.statements ?? [];
|
|
329
|
+
const returned =
|
|
330
|
+
statement && !rest.length && ts.isReturnStatement(statement) && statement.expression
|
|
331
|
+
? unwrapped(statement.expression)
|
|
332
|
+
: null;
|
|
333
|
+
if (returned?.kind === ts.SyntaxKind.TrueKeyword) return () => true;
|
|
334
|
+
if (returned?.kind === ts.SyntaxKind.FalseKeyword) return () => false;
|
|
335
|
+
const byCode = returned ? ErrorCodeScan.#codeComparisonOf(returned) : null;
|
|
336
|
+
if (byCode) return byCode;
|
|
337
|
+
if (returned && ErrorCodeScan.#readsRestoredState(returned)) return () => true;
|
|
338
|
+
throw new Error(
|
|
339
|
+
`${this.#nameOf(current)}'s forwarded getter returns more than a literal true or false, or this.code compared to a literal`,
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
return () => false;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
//? `wireCodeOf(this) === undefined`: only a copy restored from the wire holds that state, and this scan reads `new` sites.
|
|
346
|
+
static #readsRestoredState(expression: ts.Expression) {
|
|
347
|
+
if (!ts.isBinaryExpression(expression)) return false;
|
|
348
|
+
if (expression.operatorToken.kind !== ts.SyntaxKind.EqualsEqualsEqualsToken) return false;
|
|
349
|
+
const read = unwrapped(expression.left);
|
|
350
|
+
const compared = unwrapped(expression.right);
|
|
351
|
+
return (
|
|
352
|
+
ts.isCallExpression(read) &&
|
|
353
|
+
read.arguments.length === 1 &&
|
|
354
|
+
read.arguments[0]?.kind === ts.SyntaxKind.ThisKeyword &&
|
|
355
|
+
ts.isIdentifier(compared) &&
|
|
356
|
+
compared.text === "undefined"
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
static #codeComparisonOf(expression: ts.Expression): ((code: Value | null) => boolean) | null {
|
|
361
|
+
if (!ts.isBinaryExpression(expression)) return null;
|
|
362
|
+
const operator = expression.operatorToken.kind;
|
|
363
|
+
const equal = operator === ts.SyntaxKind.EqualsEqualsEqualsToken;
|
|
364
|
+
if (!equal && operator !== ts.SyntaxKind.ExclamationEqualsEqualsToken) return null;
|
|
365
|
+
const isThisCode = (side: ts.Expression) => {
|
|
366
|
+
const property = unwrapped(side);
|
|
367
|
+
return (
|
|
368
|
+
ts.isPropertyAccessExpression(property) &&
|
|
369
|
+
property.expression.kind === ts.SyntaxKind.ThisKeyword &&
|
|
370
|
+
property.name.text === "code"
|
|
371
|
+
);
|
|
372
|
+
};
|
|
373
|
+
const literalOf = (side: ts.Expression) => {
|
|
374
|
+
const literal = unwrapped(side);
|
|
375
|
+
return ts.isStringLiteralLike(literal) ? literal.text : null;
|
|
376
|
+
};
|
|
377
|
+
const compared = isThisCode(expression.left)
|
|
378
|
+
? literalOf(expression.right)
|
|
379
|
+
: isThisCode(expression.right)
|
|
380
|
+
? literalOf(expression.left)
|
|
381
|
+
: null;
|
|
382
|
+
if (compared === null) return null;
|
|
383
|
+
return (code) => (code === compared) === equal;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
#toJsonHasCode(node: ClassNode): boolean {
|
|
387
|
+
for (let current: ClassNode | null = node; current; current = this.#baseOf(current)) {
|
|
388
|
+
if (current === this.#akanError) return true;
|
|
389
|
+
const method = current.members.find(
|
|
390
|
+
(member): member is ts.MethodDeclaration =>
|
|
391
|
+
ts.isMethodDeclaration(member) && member.name.getText() === "toJSON",
|
|
392
|
+
);
|
|
393
|
+
if (!method) continue;
|
|
394
|
+
const returned = method.body?.statements.find(ts.isReturnStatement)?.expression;
|
|
395
|
+
const base = this.#baseOf(current);
|
|
396
|
+
return !!returned && this.#carriesCode(returned, base);
|
|
397
|
+
}
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
#carriesCode(expression: ts.Expression, base: ClassNode | null): boolean {
|
|
402
|
+
const inner = unwrapped(expression);
|
|
403
|
+
if (ts.isConditionalExpression(inner))
|
|
404
|
+
return this.#carriesCode(inner.whenTrue, base) || this.#carriesCode(inner.whenFalse, base);
|
|
405
|
+
if (ts.isCallExpression(inner) && ts.isPropertyAccessExpression(inner.expression))
|
|
406
|
+
return inner.expression.expression.kind === ts.SyntaxKind.SuperKeyword && !!base && this.#toJsonHasCode(base);
|
|
407
|
+
if (!ts.isObjectLiteralExpression(inner)) return false;
|
|
408
|
+
return inner.properties.some((property) =>
|
|
409
|
+
ts.isSpreadAssignment(property)
|
|
410
|
+
? this.#carriesCode(property.expression, base)
|
|
411
|
+
: property.name?.getText() === "code",
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
#classes(): ClassNode[] {
|
|
416
|
+
const classes: ClassNode[] = [this.#akanError];
|
|
417
|
+
const visit = (node: ts.Node) => {
|
|
418
|
+
if (isClassNode(node) && node !== this.#akanError && this.#descendsFromAkanError(node)) classes.push(node);
|
|
419
|
+
ts.forEachChild(node, visit);
|
|
420
|
+
};
|
|
421
|
+
for (const sourceFile of this.#ownSources()) visit(sourceFile);
|
|
422
|
+
return classes;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
#descendsFromAkanError(node: ClassNode): boolean {
|
|
426
|
+
const known = this.#descends.get(node);
|
|
427
|
+
if (known !== undefined) return known;
|
|
428
|
+
this.#descends.set(node, false);
|
|
429
|
+
const base = this.#baseOf(node);
|
|
430
|
+
const descends = !!base && (base === this.#akanError || this.#descendsFromAkanError(base));
|
|
431
|
+
this.#descends.set(node, descends);
|
|
432
|
+
return descends;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
#baseOf(node: ClassNode): ClassNode | null {
|
|
436
|
+
const extended = node.heritageClauses?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
|
|
437
|
+
return extended ? this.#classOf(extended.expression) : null;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
#classOf(expression: ts.Expression): ClassNode | null {
|
|
441
|
+
let symbol = this.#checker.getSymbolAtLocation(expression);
|
|
442
|
+
if (symbol && symbol.flags & ts.SymbolFlags.Alias) symbol = this.#checker.getAliasedSymbol(symbol);
|
|
443
|
+
for (const declaration of symbol?.declarations ?? []) {
|
|
444
|
+
if (isClassNode(declaration)) return declaration;
|
|
445
|
+
if (ts.isPropertyDeclaration(declaration) && declaration.initializer) {
|
|
446
|
+
const initializer = unwrapped(declaration.initializer);
|
|
447
|
+
if (isClassNode(initializer)) return initializer;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
#nameOf(node: ClassNode) {
|
|
454
|
+
const { parent } = node;
|
|
455
|
+
if (ts.isPropertyDeclaration(parent) && isClassNode(parent.parent) && parent.parent.name)
|
|
456
|
+
return `${parent.parent.name.text}.${parent.name.getText()}`;
|
|
457
|
+
return node.name?.text ?? "(anonymous)";
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
#newExpressions() {
|
|
461
|
+
const found: ts.NewExpression[] = [];
|
|
462
|
+
const visit = (node: ts.Node) => {
|
|
463
|
+
if (ts.isNewExpression(node)) found.push(node);
|
|
464
|
+
ts.forEachChild(node, visit);
|
|
465
|
+
};
|
|
466
|
+
for (const sourceFile of this.#ownSources()) visit(sourceFile);
|
|
467
|
+
return found;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
#ownSources() {
|
|
471
|
+
return this.#program.getSourceFiles().filter((sourceFile) => this.#roots.has(this.#relative(sourceFile.fileName)));
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
#relative(fileName: string) {
|
|
475
|
+
return path.relative(this.#dir, fileName).split(path.sep).join("/");
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
//? Tracked files only, unlike the gate: an untracked scratch file would otherwise shift the page CI compares.
|
|
479
|
+
static #sourcesOf(dir: string) {
|
|
480
|
+
const listed = Bun.spawnSync(["git", "ls-files", "-z", "--", "."], { cwd: dir, stdout: "pipe", stderr: "pipe" });
|
|
481
|
+
if (listed.exitCode !== 0) throw new Error(`git ls-files failed in ${dir}: ${listed.stderr.toString().trim()}`);
|
|
482
|
+
return listed.stdout
|
|
483
|
+
.toString()
|
|
484
|
+
.split("\0")
|
|
485
|
+
.filter((file) => file && !file.includes("node_modules/") && MaintainabilityLimits.isPackageSource(file));
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
//? Parsing every source costs seconds; a file that names no AkanError descendant can neither declare nor build one.
|
|
489
|
+
static #rootsOf(dir: string) {
|
|
490
|
+
const texts = ErrorCodeScan.#sourcesOf(dir)
|
|
491
|
+
.filter((file) => existsSync(path.join(dir, file)))
|
|
492
|
+
.map((file) => [file, readFileSync(path.join(dir, file), "utf8")] as const);
|
|
493
|
+
const edges = texts.flatMap(([, text]) => [...ErrorCodeScan.#extendsIn(text)]);
|
|
494
|
+
const names = new Set(["AkanError"]);
|
|
495
|
+
for (let grown = true; grown; ) {
|
|
496
|
+
grown = false;
|
|
497
|
+
for (const [name, base] of edges) {
|
|
498
|
+
if (!names.has(base) || names.has(name)) continue;
|
|
499
|
+
names.add(name);
|
|
500
|
+
grown = true;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
const escaped = [...names].map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
504
|
+
const mention = new RegExp(`(?<![\\w$])(?:${escaped.join("|")})(?![\\w$])`);
|
|
505
|
+
return new Set(texts.filter(([, text]) => mention.test(text)).map(([file]) => file));
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
static *#extendsIn(text: string): Generator<readonly [name: string, base: string]> {
|
|
509
|
+
for (const head of text.matchAll(/\bclass\s+([A-Za-z_$][\w$]*)\s*/g)) {
|
|
510
|
+
const [matched, name] = head;
|
|
511
|
+
if (!name) continue;
|
|
512
|
+
let at = head.index + matched.length;
|
|
513
|
+
for (let depth = 0; at < text.length && (text[at] === "<" || depth > 0); at++) {
|
|
514
|
+
if (text[at] === "<") depth++;
|
|
515
|
+
else if (text[at] === ">" && text[at - 1] !== "=") depth--;
|
|
516
|
+
}
|
|
517
|
+
const heritage = /\s*extends\s+([A-Za-z_$][\w$]*)/y;
|
|
518
|
+
heritage.lastIndex = at;
|
|
519
|
+
const extended: RegExpExecArray | null = heritage.exec(text);
|
|
520
|
+
const base = extended?.[1];
|
|
521
|
+
if (base) yield [name, base];
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
static #statusTableOf(akanError: ts.ClassDeclaration) {
|
|
526
|
+
const table = new Map<number, readonly [string, string]>();
|
|
527
|
+
const property = akanError.members.find(
|
|
528
|
+
(member): member is ts.PropertyDeclaration =>
|
|
529
|
+
ts.isPropertyDeclaration(member) && member.name.getText() === "#statuses",
|
|
530
|
+
);
|
|
531
|
+
const initializer = property?.initializer ? unwrapped(property.initializer) : null;
|
|
532
|
+
if (!initializer || !ts.isObjectLiteralExpression(initializer))
|
|
533
|
+
throw new Error("AkanError holds no #statuses table to name a status's code by");
|
|
534
|
+
for (const entry of initializer.properties) {
|
|
535
|
+
if (!ts.isPropertyAssignment(entry) || !ts.isArrayLiteralExpression(entry.initializer)) continue;
|
|
536
|
+
const [code, reason] = entry.initializer.elements;
|
|
537
|
+
if (code && reason && ts.isStringLiteral(code) && ts.isStringLiteral(reason))
|
|
538
|
+
table.set(Number(entry.name.getText()), [code.text, reason.text]);
|
|
539
|
+
}
|
|
540
|
+
return table;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
static #byCode(a: ErrorCodeRow, b: ErrorCodeRow) {
|
|
544
|
+
return (
|
|
545
|
+
byCodeUnit(a.code ?? "~", b.code ?? "~") ||
|
|
546
|
+
Number(a.byStatus) - Number(b.byStatus) ||
|
|
547
|
+
(a.statusCode ?? 0) - (b.statusCode ?? 0) ||
|
|
548
|
+
byCodeUnit(a.error, b.error)
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { FrameworkGraph } from "./frameworkGraph";
|
|
6
6
|
|
|
7
|
-
const workspaceRoot = path.resolve(import.meta.dir, "
|
|
7
|
+
const workspaceRoot = path.resolve(import.meta.dir, "../../../..");
|
|
8
8
|
//? The other end of these lies outside the source read here: @akanjs/native's desktop shell answers file and secret
|
|
9
9
|
//? requests, AkanApp's child reports a boot error from a code string, and the browser tab sends `sync-navigation` and
|
|
10
10
|
//? handles every HmrMessage in a script string. `ws.*` and HMR `ok` have no site.
|