@akanjs/devkit 3.2.0-rc.3 → 3.2.0-rc.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +367 -11
- package/DEV_RUNTIME_KNOBS.md +4 -3
- package/README.ko.md +3 -2
- package/README.md +4 -2
- package/akanApp/BackendImportGraph.test.ts +1 -1
- package/akanApp/akanApp.host.test.ts +257 -1
- package/akanApp/akanApp.host.ts +146 -1223
- package/akanApp/akanApp.host.wiring.test.ts +727 -0
- package/akanApp/builderGap.ts +68 -0
- package/akanApp/builderRequestRelay.test.ts +93 -0
- package/akanApp/builderRequestRelay.ts +100 -0
- package/akanApp/builderRssRecycler.ts +182 -0
- package/akanApp/devBackend.ts +392 -0
- package/akanApp/devBuildStatusBoard.ts +128 -0
- package/akanApp/devBuilder.ts +196 -0
- package/akanApp/devHostPolicy.test.ts +11 -11
- package/akanApp/devHostPolicy.ts +2 -4
- package/akanApp/devIdleSuspend.test.ts +221 -0
- package/akanApp/devIdleSuspend.ts +192 -0
- package/akanApp/devIdleSuspend.watcher.test.ts +120 -0
- package/akanApp/devRecycler.test.ts +66 -0
- package/akanApp/devRecycler.ts +305 -0
- package/akanApp/processRss.ts +61 -0
- package/akanConfig/akanConfig.test.ts +24 -1
- package/akanConfig/akanConfig.ts +10 -10
- package/akanConfig/akanWorkspaceConfig.ts +1 -1
- package/akanConfig/productionLockfile.ts +1 -1
- package/apiReport/apiDeclarationPrinter.ts +120 -0
- package/apiReport/apiReport.test.ts +526 -0
- package/apiReport/apiReport.ts +232 -0
- package/apiReport/apiReportDiff.ts +160 -0
- package/apiReport/apiReportPolicy.ts +65 -0
- package/apiReport/apiTargets.ts +311 -0
- package/apiReport/changesetBump.ts +19 -0
- package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +21 -0
- package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +10 -49
- package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +74 -7
- package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +20 -15
- package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
- package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +48 -12
- package/{routeJsBudget.ts → app/routeJsBudget.ts} +90 -27
- package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
- package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
- package/artifact/implicitRootLayout.test.ts +71 -3
- package/artifact/implicitRootLayout.ts +21 -4
- package/artifact/implicitRootLayoutRender.test.tsx +297 -0
- package/biome.base.json +2 -1
- package/cloud/cloudApi.test.ts +1 -1
- package/cloud/configLock.test.ts +1 -1
- package/cloud/globalConfig.test.ts +1 -1
- package/cloud/globalConfig.ts +1 -1
- package/cloud/updatePackUpload.test.ts +1 -1
- package/codeAgent/agent/AkanCodeEnv.ts +1 -1
- package/codeAgent/agent/akanCodePaths.ts +1 -1
- package/codeAgent/agent/akanSystemPrompt.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +1 -1
- package/codeAgent/skills/akan-debug/SKILL.md +10 -3
- package/codeAgent/skills/akan-err/SKILL.md +7 -0
- package/codeAgent/skills/akan-mcp/SKILL.md +14 -2
- package/codeAgent/skills/akan-scaffold/SKILL.md +2 -2
- package/codeAgent/skills/akan-transport/SKILL.md +2 -0
- package/codeAgent/skills/akan-validate/SKILL.md +1 -0
- package/codeAgent/tools/AkanCli.ts +1 -1
- package/codeAgent/tools/AkanToolPack.ts +1 -1
- package/codeAgent/tools/McpClient.ts +28 -6
- package/codeAgent/tools/McpToolPack.ts +1 -1
- package/codeAgent/tools/akanCodePlugins.test.ts +14 -2
- package/commandDecorators/argMeta.ts +4 -0
- package/commandDecorators/cliError.ts +72 -0
- package/commandDecorators/command.ts +165 -91
- package/commandDecorators/commandBuilder.ts +1 -1
- package/commandDecorators/commandDecorators.test.ts +191 -16
- package/commandDecorators/exitCodeError.ts +6 -7
- package/commandDecorators/index.ts +1 -0
- package/commandDecorators/targetMeta.ts +1 -0
- package/commandDecorators/workspaceVersionCheck.test.ts +1 -1
- package/commandDecorators/workspaceVersionCheck.ts +1 -1
- package/context/akanContext.ts +576 -0
- package/context/akanContextInspection.ts +296 -0
- package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
- package/{akanMcpContract.ts → context/akanMcpContract.ts} +32 -262
- package/context/akanMcpToolError.ts +16 -0
- package/context/doctor/agentGuideCheck.ts +81 -0
- package/context/doctor/configLeftoverCheck.ts +35 -0
- package/context/doctor/doctorFindings.ts +70 -0
- package/context/doctor/generatedFreshness.ts +56 -0
- package/context/doctor/moduleShapeCheck.ts +88 -0
- package/context/doctor/recipeDuplicateCheck.ts +39 -0
- package/context/doctor/recipeIndexCheck.ts +87 -0
- package/context/doctor/rootShapeCheck.ts +55 -0
- package/context/doctor/workflowScope.ts +97 -0
- package/{constantFieldNames.test.ts → context/moduleFieldNames.test.ts} +24 -2
- package/context/moduleFieldNames.ts +25 -0
- package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
- package/context/safeRead.ts +9 -0
- package/csrE2e/csrE2eHarness.fixture.ts +1 -1
- package/devkitUtils.test.ts +39 -5
- package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
- package/{apiReference.ts → docs/apiReference.ts} +2 -2
- package/docs/errorCodeReference.test.ts +282 -0
- package/docs/errorCodeReference.ts +71 -0
- package/docs/errorCodeScan.ts +551 -0
- package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
- package/executors/appExecutor.ts +448 -0
- package/executors/commandExecutionError.ts +53 -0
- package/executors/executor.ts +527 -0
- package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
- package/{executors.test.ts → executors/executors.test.ts} +76 -15
- package/executors/index.ts +8 -0
- package/executors/libExecutor.ts +23 -0
- package/executors/moduleExecutor.ts +18 -0
- package/executors/pkgExecutor.ts +129 -0
- package/executors/sysExecutor.ts +301 -0
- package/executors/workspaceExecutor.ts +277 -0
- package/frontendBuild/allRoutesBuilder.test.ts +17 -5
- package/frontendBuild/allRoutesBuilder.ts +24 -6
- package/frontendBuild/autoImportSync.test.ts +1 -1
- package/frontendBuild/autoImportSync.ts +1 -1
- package/frontendBuild/buildRouteClient.test.ts +1 -1
- package/frontendBuild/bundleDefine.ts +2 -0
- package/frontendBuild/clientBuildTypes.ts +5 -2
- package/frontendBuild/clientEntriesBundler.test.ts +1 -1
- package/frontendBuild/clientEntryDiscovery.test.ts +28 -0
- package/frontendBuild/clientEntryDiscovery.ts +25 -6
- package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
- package/frontendBuild/csrDevArtifactWriter.ts +1 -1
- package/frontendBuild/cssCompiler.test.ts +1 -1
- package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
- package/frontendBuild/devGeneratedIndexSync.ts +7 -38
- package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
- package/frontendBuild/fontOptimizer.test.ts +1 -1
- package/frontendBuild/fontPruner.test.ts +1 -1
- package/frontendBuild/frontendBuild.test.ts +3 -3
- package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
- package/frontendBuild/hmrWatcher.test.ts +1 -1
- package/frontendBuild/hmrWatcher.ts +22 -1
- package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
- package/frontendBuild/mcpAppViewBuilder.ts +1 -1
- package/frontendBuild/nativeCore.test.ts +148 -0
- package/frontendBuild/optionalPeers.test.ts +36 -8
- package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
- package/frontendBuild/pagesBundleBuilder.ts +1 -1
- package/frontendBuild/precompressArtifacts.test.ts +1 -1
- package/frontendBuild/precompressArtifacts.ts +1 -1
- package/frontendBuild/serverGraphFile.ts +1 -1
- package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
- package/frontendBuild/ssrBaseArtifactBuilder.test.ts +26 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +23 -19
- package/frontendBuild/ssrDevBundler.test.ts +1 -1
- package/frontendBuild/vendorImportScanner.test.ts +25 -4
- package/frontendBuild/vendorImportScanner.ts +25 -10
- package/frontendBuild/vendorNarrowing.test.ts +1 -1
- package/frontendBuild/watchRootResolver.test.ts +1 -1
- package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
- package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
- package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
- package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
- package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
- package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
- package/{prompter.ts → guideline/prompter.ts} +2 -3
- package/incrementalBuilder/buildBatch.proc.ts +14 -4
- package/incrementalBuilder/buildBatchProtocol.ts +2 -0
- package/incrementalBuilder/buildBatchRunner.test.ts +108 -1
- package/incrementalBuilder/buildBatchRunner.ts +17 -4
- package/incrementalBuilder/builderBoot.ts +106 -0
- package/incrementalBuilder/builderBuildStatus.ts +23 -0
- package/incrementalBuilder/builderChannel.test.ts +1 -1
- package/incrementalBuilder/builderChannel.ts +11 -0
- package/incrementalBuilder/builderGraphPayloads.ts +3 -3
- package/incrementalBuilder/builderLanes.ts +157 -0
- package/incrementalBuilder/builderWatch.ts +213 -0
- package/incrementalBuilder/csrRegistry.ts +234 -0
- package/incrementalBuilder/incrementalBuilder.host.test.ts +30 -1
- package/incrementalBuilder/incrementalBuilder.host.ts +10 -22
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +93 -2
- package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
- package/incrementalBuilder/ssrRegistry.ts +278 -0
- package/index.ts +22 -22
- package/integration/devStability.integration.test.ts +62 -56
- package/integration/devStabilityHarness.test.ts +1 -1
- package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
- package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
- package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
- package/lint/gritRules.test.ts +1 -1
- package/{linter.test.ts → lint/linter.test.ts} +1 -1
- package/lint/no-import-common-err.grit +31 -0
- package/lint/no-init-fetch-in-client.grit +1 -1
- package/lint/no-web-only-api-outside-webkit.grit +3 -3
- package/mobile/desktopBin.test.ts +1 -1
- package/mobile/desktopRelease.test.ts +1 -1
- package/mobile/desktopServerStage.test.ts +2 -2
- package/mobile/desktopServerStage.ts +1 -1
- package/mobile/nativeApi.test.ts +1 -1
- package/mobile/nativeApp.test.ts +1 -1
- package/mobile/nativeConfig.test.ts +1 -1
- package/mobile/nativePluginFolders.test.ts +1 -1
- package/mobile/nativePublicEnv.test.ts +1 -1
- package/mobile/nativeWebDir.test.ts +1 -1
- package/mobile/serverBundleSecrets.test.ts +1 -1
- package/mobile/tarWriter.test.ts +1 -1
- package/mobile/updatePackFolder.test.ts +1 -1
- package/package.json +167 -3
- package/packageExports.test.ts +20 -2
- package/piDependencyPins.test.ts +1 -1
- package/pipeline/PipelineDefinition.ts +1 -1
- package/platformTest/IdleWatchedProcess.test.ts +1 -1
- package/platformTest/PlatformTestRun.test.ts +1 -1
- package/platformTest/TestSnapshot.test.ts +1 -1
- package/preview/PreviewView.ts +32 -13
- package/preview/previewView.test.ts +33 -3
- package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
- package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
- package/quality/bareErrorScanner.ts +126 -0
- package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
- package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
- package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
- package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
- package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
- package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
- package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
- package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
- package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +1 -1
- package/{qualityScanner.ts → quality/qualityScanner.ts} +8 -8
- package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
- package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
- package/{subspace.ts → subspace/subspace.ts} +5 -5
- package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
- package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
- package/{testHelpers.ts → test/testHelpers.ts} +37 -1
- package/transforms/barrelAnalyzer.ts +31 -10
- package/transforms/browserDirnamePlugin.test.ts +1 -1
- package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
- package/transforms/mcpAppPageTrimmer.test.ts +1 -1
- package/transforms/pureLazyMarker.test.ts +1 -1
- package/transforms/serverEnvPlugin.test.ts +1 -1
- package/transforms/serverEnvProfile.test.ts +1 -1
- package/transforms/sideEffectImportOrder.test.ts +1 -1
- package/transforms/transforms.test.ts +52 -2
- package/transforms/tsconfigPackageResolver.test.ts +1 -1
- package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
- package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
- package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
- package/typecheck/projectTypecheck.test.ts +1 -1
- package/typecheck/projectTypecheck.ts +6 -2
- package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
- package/{typeChecker.ts → typecheck/typeChecker.ts} +1 -1
- package/typecheck/typecheck.proc.ts +4 -3
- package/typecheck/typecheckFailure.ts +7 -2
- package/util/errorReport.ts +66 -0
- package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
- package/workflow/artifacts.ts +8 -7
- package/workflow/constantSource.ts +187 -0
- package/workflow/dictionarySource.ts +184 -0
- package/workflow/executor.ts +6 -9
- package/workflow/fieldExpression.ts +153 -0
- package/workflow/fieldLabel.ts +61 -0
- package/workflow/fieldOrder.ts +117 -0
- package/workflow/fieldType.ts +93 -0
- package/workflow/guardCatalog.test.ts +1 -1
- package/workflow/index.ts +1 -0
- package/workflow/keyRename.ts +1 -1
- package/workflow/moduleIndex.test.ts +2 -2
- package/workflow/moduleIndex.ts +2 -2
- package/workflow/modulePaths.ts +27 -0
- package/workflow/mutationScaffold.ts +7 -15
- package/workflow/mutationSource.ts +2 -1
- package/workflow/plainName.ts +16 -3
- package/workflow/plan.ts +14 -2
- package/workflow/primitiveReport.ts +78 -0
- package/workflow/rolloutGate.test.ts +1 -1
- package/workflow/rolloutGate.ts +1 -1
- package/workflow/serviceSource.ts +33 -0
- package/workflow/signalSource.ts +96 -0
- package/workflow/source.ts +50 -1105
- package/workflow/sourceAst.ts +30 -0
- package/workflow/sourceImports.ts +105 -0
- package/workflow/sourceText.ts +13 -0
- package/workflow/templateSource.ts +30 -0
- package/workflow/testSource.ts +31 -0
- package/workflow/types.ts +1 -1
- package/workflow/uiPolicy.ts +1 -1
- package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
- package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
- package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
- package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
- package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
- package/{envSeed.ts → workspace/envSeed.ts} +1 -1
- package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
- package/{libSource.ts → workspace/libSource.ts} +1 -1
- package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
- package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
- package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
- package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
- package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
- package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
- package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
- package/akanContext.ts +0 -1084
- package/constantFieldNames.ts +0 -18
- package/executors.ts +0 -1749
- /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
- /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
- /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
- /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
- /package/{linter.ts → lint/linter.ts} +0 -0
- /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
- /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
- /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
- /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
- /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
- /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
- /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
- /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
- /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
- /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
- /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
- /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
- /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
- /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
- /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
- /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
- /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
- /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
- /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
- /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
- /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
- /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
- /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
- /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
- /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
- /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
- /package/{storeSource.ts → quality/storeSource.ts} +0 -0
- /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
- /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
- /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
- /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
- /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
- /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
- /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
- /package/{writePath.ts → quality/writePath.ts} +0 -0
- /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
- /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
- /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
- /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
- /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
- /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
- /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
- /package/{fileSys.test.ts → util/fileSys.test.ts} +0 -0
- /package/{fileSys.ts → util/fileSys.ts} +0 -0
- /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
- /package/{selectModel.ts → util/selectModel.ts} +0 -0
- /package/{semver.test.ts → util/semver.test.ts} +0 -0
- /package/{semver.ts → util/semver.ts} +0 -0
- /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
- /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
- /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
- /package/{spinner.ts → util/spinner.ts} +0 -0
- /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
- /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
- /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
- /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
- /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
- /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
- /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
- /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
- /package/{types.ts → workspace/types.ts} +0 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { ApiDeclarationPrinter } from "./apiDeclarationPrinter";
|
|
4
|
+
import { type ApiTarget, ApiTargets } from "./apiTargets";
|
|
5
|
+
|
|
6
|
+
export interface ApiEntry {
|
|
7
|
+
subpath: string;
|
|
8
|
+
specifier: string;
|
|
9
|
+
file: string;
|
|
10
|
+
reportName: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ApiEntryPoints {
|
|
14
|
+
packageName: string;
|
|
15
|
+
entries: ApiEntry[];
|
|
16
|
+
wildcards: string[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface ApiBlock {
|
|
20
|
+
key: string;
|
|
21
|
+
text: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type PackageExports = Record<string, string | Record<string, unknown>>;
|
|
25
|
+
|
|
26
|
+
export class ApiReport {
|
|
27
|
+
static readonly extension = ".api.md";
|
|
28
|
+
static readonly referencedHeading = "## Referenced, not exported";
|
|
29
|
+
readonly #packageDir: string;
|
|
30
|
+
readonly #program: ts.Program;
|
|
31
|
+
readonly #targets: ApiTargets;
|
|
32
|
+
#exported: Set<string> | null = null;
|
|
33
|
+
|
|
34
|
+
static compare(a: string, b: string) {
|
|
35
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static entriesOf(packageJson: { name: string; exports?: PackageExports }, packageDir: string): ApiEntryPoints {
|
|
39
|
+
const entries: ApiEntry[] = [];
|
|
40
|
+
const wildcards: string[] = [];
|
|
41
|
+
for (const [subpath, value] of Object.entries(packageJson.exports ?? {})) {
|
|
42
|
+
const target = typeof value === "string" ? value : (value.types ?? value.import ?? value.default);
|
|
43
|
+
if (typeof target !== "string") continue;
|
|
44
|
+
if (subpath.includes("*")) {
|
|
45
|
+
wildcards.push(subpath);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (!/\.tsx?$/.test(target)) continue;
|
|
49
|
+
const specifier = subpath === "." ? packageJson.name : `${packageJson.name}/${subpath.slice(2)}`;
|
|
50
|
+
entries.push({
|
|
51
|
+
subpath,
|
|
52
|
+
specifier,
|
|
53
|
+
file: path.resolve(packageDir, target),
|
|
54
|
+
reportName: `${specifier.replace(/^@/, "").replaceAll("/", ".")}${ApiReport.extension}`,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return { packageName: packageJson.name, entries, wildcards: wildcards.sort(ApiReport.compare) };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static async generate(packageDir: string, tsconfigPath = path.join(packageDir, "tsconfig.json")) {
|
|
61
|
+
const packageJson = (await Bun.file(path.join(packageDir, "package.json")).json()) as {
|
|
62
|
+
name: string;
|
|
63
|
+
exports?: PackageExports;
|
|
64
|
+
};
|
|
65
|
+
const { packageName, entries, wildcards } = ApiReport.entriesOf(packageJson, packageDir);
|
|
66
|
+
const report = new ApiReport(packageDir, entries, tsconfigPath);
|
|
67
|
+
const files = new Map(entries.map((entry) => [entry.reportName, report.render(entry, entries)]));
|
|
68
|
+
if (wildcards.length) files.set(`${packageName}.wildcards${ApiReport.extension}`, ApiReport.#wildcards(wildcards));
|
|
69
|
+
return new Map([...files].sort(([a], [b]) => ApiReport.compare(a, b)));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
constructor(packageDir: string, entries: ApiEntry[], tsconfigPath: string) {
|
|
73
|
+
this.#packageDir = packageDir;
|
|
74
|
+
const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
|
|
75
|
+
if (configFile.error) throw new Error(ts.flattenDiagnosticMessageText(configFile.error.messageText, "\n"));
|
|
76
|
+
const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(tsconfigPath), {
|
|
77
|
+
declaration: true,
|
|
78
|
+
declarationMap: false,
|
|
79
|
+
emitDeclarationOnly: true,
|
|
80
|
+
noEmit: false,
|
|
81
|
+
noEmitOnError: false,
|
|
82
|
+
sourceMap: false,
|
|
83
|
+
incremental: false,
|
|
84
|
+
composite: false,
|
|
85
|
+
});
|
|
86
|
+
const rootNames = entries.map((entry) => entry.file);
|
|
87
|
+
const reached = ts.createProgram({ rootNames, options: parsed.options });
|
|
88
|
+
//? A workspace package the build embeds is reached through a node_modules link, so tsc treats it as external and
|
|
89
|
+
//? emits nothing for it until it is named as a root.
|
|
90
|
+
const embedded = reached
|
|
91
|
+
.getSourceFiles()
|
|
92
|
+
.filter((sourceFile) => !sourceFile.isDeclarationFile && reached.isSourceFileFromExternalLibrary(sourceFile))
|
|
93
|
+
.map((sourceFile) => sourceFile.fileName);
|
|
94
|
+
this.#program = embedded.length
|
|
95
|
+
? ts.createProgram({ rootNames: [...rootNames, ...embedded], options: parsed.options, oldProgram: reached })
|
|
96
|
+
: reached;
|
|
97
|
+
const emitted = new Map<string, string>();
|
|
98
|
+
this.#program.emit(
|
|
99
|
+
undefined,
|
|
100
|
+
(_fileName, text, _bom, _onError, sourceFiles) => {
|
|
101
|
+
const source = sourceFiles?.[0];
|
|
102
|
+
if (source) emitted.set(source.fileName, text);
|
|
103
|
+
},
|
|
104
|
+
undefined,
|
|
105
|
+
true,
|
|
106
|
+
);
|
|
107
|
+
this.#targets = new ApiTargets(this.#program, emitted);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
render(entry: ApiEntry, entries: ApiEntry[] = [entry]) {
|
|
111
|
+
const exported = this.#exportedBy(entries);
|
|
112
|
+
const symbols = this.#exportsOfEntry(entry);
|
|
113
|
+
const blocks = symbols
|
|
114
|
+
.map((symbol) => ({ key: symbol.getName(), text: this.#exportBlockOf(symbol) }))
|
|
115
|
+
.sort((a, b) => ApiReport.compare(a.key, b.key));
|
|
116
|
+
const referenced = this.#referencedBlocks(
|
|
117
|
+
this.#targets.expand(symbols.flatMap((symbol) => this.#targets.ofSymbol(symbol))),
|
|
118
|
+
exported,
|
|
119
|
+
);
|
|
120
|
+
const text = [
|
|
121
|
+
`# \`${entry.specifier}\``,
|
|
122
|
+
"",
|
|
123
|
+
"Generated from the declaration emit by `bun run api:report`. Do not edit it by hand.",
|
|
124
|
+
"",
|
|
125
|
+
...ApiReport.#fenced(blocks),
|
|
126
|
+
...(referenced.length
|
|
127
|
+
? [
|
|
128
|
+
ApiReport.referencedHeading,
|
|
129
|
+
"",
|
|
130
|
+
"The declarations above name these, and no entry point exports them.",
|
|
131
|
+
"",
|
|
132
|
+
...ApiReport.#fenced(referenced),
|
|
133
|
+
]
|
|
134
|
+
: []),
|
|
135
|
+
].join("\n");
|
|
136
|
+
if (text.includes('import("/'))
|
|
137
|
+
throw new Error(`The API report of ${entry.specifier} names a module by an absolute path.`);
|
|
138
|
+
return text;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#exportsOfEntry(entry: ApiEntry) {
|
|
142
|
+
const sourceFile = this.#program.getSourceFile(entry.file);
|
|
143
|
+
if (!sourceFile) throw new Error(`${entry.file} is not in the program built for the API report.`);
|
|
144
|
+
return this.#targets.exportsOf(sourceFile);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
#exportedBy(entries: ApiEntry[]) {
|
|
148
|
+
if (this.#exported) return this.#exported;
|
|
149
|
+
const targets = entries.flatMap((entry) =>
|
|
150
|
+
this.#exportsOfEntry(entry).flatMap((symbol) => this.#targets.ofSymbol(symbol)),
|
|
151
|
+
);
|
|
152
|
+
this.#exported = new Set([...targets, ...this.#targets.expand(targets)].map((target) => target.id));
|
|
153
|
+
return this.#exported;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
#exportBlockOf(symbol: ts.Symbol): string {
|
|
157
|
+
const name = symbol.getName();
|
|
158
|
+
const texts = [...new Set(this.#targets.ofSymbol(symbol).flatMap((target) => this.#exportTextsOf(target, name)))];
|
|
159
|
+
return texts.length ? texts.join("\n") : `export declare const ${name}: ${this.#targets.typeTextOf(symbol)};`;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
#exportTextsOf(target: ApiTarget, name: string): string[] {
|
|
163
|
+
if (target.thirdParty) {
|
|
164
|
+
if (target.members) return [`export * as ${name} from "${target.thirdParty}";`];
|
|
165
|
+
const binding = target.name === name ? name : `${target.name} as ${name}`;
|
|
166
|
+
return [`export { ${binding} } from "${target.thirdParty}";`];
|
|
167
|
+
}
|
|
168
|
+
if (target.members) {
|
|
169
|
+
const members = target.members
|
|
170
|
+
.map((member) => ({ key: member.getName(), text: this.#exportBlockOf(member) }))
|
|
171
|
+
.sort((a, b) => ApiReport.compare(a.key, b.key))
|
|
172
|
+
.map(({ text }) => text.replace(/^export (?:declare )?(?![{*])/gm, "").replace(/^/gm, " "));
|
|
173
|
+
return [`export declare namespace ${name} {\n${members.join("\n")}\n}`];
|
|
174
|
+
}
|
|
175
|
+
const file = target.file;
|
|
176
|
+
if (!file) return [];
|
|
177
|
+
return target.statements.map((statement) =>
|
|
178
|
+
ApiDeclarationPrinter.print(statement, file, { localName: target.name, name, mode: "export" }),
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
#referencedBlocks(roots: ApiTarget[], exported: ReadonlySet<string>): ApiBlock[] {
|
|
183
|
+
const found = new Map<string, ApiTarget>();
|
|
184
|
+
const queue = [...roots];
|
|
185
|
+
for (let target = queue.pop(); target; target = queue.pop()) {
|
|
186
|
+
for (const reference of this.#targets.referencesOf(target)) {
|
|
187
|
+
if (reference.thirdParty || exported.has(reference.id) || found.has(reference.id)) continue;
|
|
188
|
+
found.set(reference.id, reference);
|
|
189
|
+
queue.push(reference);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const rendered = [...found.values()].flatMap((target) => {
|
|
193
|
+
const file = target.file;
|
|
194
|
+
if (!file || !target.statements.length) return [];
|
|
195
|
+
const text = target.statements
|
|
196
|
+
.map((statement) =>
|
|
197
|
+
ApiDeclarationPrinter.print(statement, file, { localName: target.name, name: target.name, mode: "declare" }),
|
|
198
|
+
)
|
|
199
|
+
.join("\n");
|
|
200
|
+
return [{ name: target.name, module: this.#modulePathOf(target.origin), text }];
|
|
201
|
+
});
|
|
202
|
+
const counts = new Map<string, number>();
|
|
203
|
+
for (const { name } of rendered) counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
204
|
+
return rendered
|
|
205
|
+
.map(({ name, module, text }) =>
|
|
206
|
+
(counts.get(name) ?? 0) > 1 ? { key: `${name} ${module}`, text: `// ${module}\n${text}` } : { key: name, text },
|
|
207
|
+
)
|
|
208
|
+
.sort((a, b) => ApiReport.compare(a.key, b.key));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
#modulePathOf(fileName: string) {
|
|
212
|
+
return path
|
|
213
|
+
.relative(this.#packageDir, fileName)
|
|
214
|
+
.replaceAll("\\", "/")
|
|
215
|
+
.replace(/(?:\.d)?\.tsx?$/, "");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
static #fenced(blocks: ApiBlock[]) {
|
|
219
|
+
return ["```ts", blocks.map((block) => block.text).join("\n\n"), "```", ""];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
static #wildcards(wildcards: string[]) {
|
|
223
|
+
return [
|
|
224
|
+
"# Wildcard subpaths",
|
|
225
|
+
"",
|
|
226
|
+
"Each of these makes every file under it importable. Their files are not reported one by one.",
|
|
227
|
+
"",
|
|
228
|
+
...wildcards.map((wildcard) => `- \`${wildcard}\``),
|
|
229
|
+
"",
|
|
230
|
+
].join("\n");
|
|
231
|
+
}
|
|
232
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { ApiReport } from "./apiReport";
|
|
3
|
+
|
|
4
|
+
export interface ApiBreak {
|
|
5
|
+
report: string;
|
|
6
|
+
name: string;
|
|
7
|
+
kind: "removed" | "changed";
|
|
8
|
+
before?: string;
|
|
9
|
+
after?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ApiDrift {
|
|
13
|
+
changed: string[];
|
|
14
|
+
added: string[];
|
|
15
|
+
removed: string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type ApiReportFiles = ReadonlyMap<string, string>;
|
|
19
|
+
|
|
20
|
+
export class ApiReportDiff {
|
|
21
|
+
static readonly #declarationPattern =
|
|
22
|
+
/^(?:export )?(?:declare )?(?:abstract |const )?(?:class|function|interface|type|enum|namespace|module|const|let|var) ([^\s<(:=;{]+)/;
|
|
23
|
+
static readonly #reexportPattern = /^export \{ (\S+)(?: as (\S+))? \} from /;
|
|
24
|
+
static readonly #namespaceReexportPattern = /^export \* as (\S+) from /;
|
|
25
|
+
static readonly #tagLine = /^\/\*\* (?:@\w+ ?)+\*\/$/;
|
|
26
|
+
static readonly #printer = ts.createPrinter({ removeComments: true, newLine: ts.NewLineKind.LineFeed });
|
|
27
|
+
static readonly #subpathPattern = /^- `(\S+)`$/gm;
|
|
28
|
+
static readonly #referencedSuffix = " (referenced)";
|
|
29
|
+
static readonly #referencedMark = " (referenced";
|
|
30
|
+
|
|
31
|
+
static blocksOf(text: string) {
|
|
32
|
+
const [exported = "", referenced = ""] = text.split(`\n${ApiReport.referencedHeading}\n`);
|
|
33
|
+
const blocks = new Map<string, string>();
|
|
34
|
+
for (const [name, block] of ApiReportDiff.#namedBlocksOf(exported)) blocks.set(name, block);
|
|
35
|
+
for (const [block, subpath = ""] of ApiReportDiff.#subpathsOf(exported)) blocks.set(subpath, block);
|
|
36
|
+
for (const [name, block, module] of ApiReportDiff.#namedBlocksOf(referenced))
|
|
37
|
+
blocks.set(module ? `${name} (referenced, ${module})` : `${name}${ApiReportDiff.#referencedSuffix}`, block);
|
|
38
|
+
return blocks;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static drift(committed: ApiReportFiles, generated: ApiReportFiles): ApiDrift {
|
|
42
|
+
return {
|
|
43
|
+
changed: [...generated]
|
|
44
|
+
.filter(([file, text]) => committed.has(file) && committed.get(file) !== text)
|
|
45
|
+
.map(([file]) => file),
|
|
46
|
+
added: [...generated.keys()].filter((file) => !committed.has(file)),
|
|
47
|
+
removed: [...committed.keys()].filter((file) => !generated.has(file)),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static hasDrift({ changed, added, removed }: ApiDrift) {
|
|
52
|
+
return changed.length + added.length + removed.length > 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static breaks(before: ApiReportFiles, after: ApiReportFiles): ApiBreak[] {
|
|
56
|
+
const nextReports = new Map([...after].map(([report, text]) => [report, ApiReportDiff.blocksOf(text)]));
|
|
57
|
+
return [...before].flatMap(([report, text]) => {
|
|
58
|
+
const next = nextReports.get(report) ?? new Map<string, string>();
|
|
59
|
+
return [...ApiReportDiff.blocksOf(text)].flatMap(([name, block]): ApiBreak[] => {
|
|
60
|
+
const current = next.get(name);
|
|
61
|
+
if (current !== undefined)
|
|
62
|
+
return ApiReportDiff.#sameDeclaration(current, block)
|
|
63
|
+
? []
|
|
64
|
+
: [{ report, name, kind: "changed", before: block, after: current }];
|
|
65
|
+
const referenced = ApiReportDiff.#referencedNameOf(name);
|
|
66
|
+
if (referenced === null) return [{ report, name, kind: "removed", before: block }];
|
|
67
|
+
const successors = ApiReportDiff.#successorsOf(referenced, report, nextReports);
|
|
68
|
+
//? Found nowhere, it is named by nothing now: whatever named it changed, and that change is the break.
|
|
69
|
+
if (!successors.length || successors.some((successor) => ApiReportDiff.#sameDeclaration(successor, block)))
|
|
70
|
+
return [];
|
|
71
|
+
return [{ report, name, kind: "changed", before: block, after: successors.join("\n\n") }];
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static #successorsOf(name: string, report: string, nextReports: ReadonlyMap<string, ReadonlyMap<string, string>>) {
|
|
77
|
+
const others = [...nextReports].filter(([other]) => other !== report).map(([, blocks]) => blocks);
|
|
78
|
+
const found = [nextReports.get(report) ?? new Map<string, string>(), ...others].flatMap((blocks) =>
|
|
79
|
+
[...blocks]
|
|
80
|
+
.filter(([key]) => key === name || ApiReportDiff.#referencedNameOf(key) === name)
|
|
81
|
+
.map(([, block]) => block),
|
|
82
|
+
);
|
|
83
|
+
return found.filter(
|
|
84
|
+
(block, idx) => found.findIndex((other) => ApiReportDiff.#sameDeclaration(other, block)) === idx,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static #namedBlocksOf(section: string): [string, string, string | null][] {
|
|
89
|
+
const body = /```ts\n([\s\S]*?)\n?```/.exec(section)?.[1] ?? "";
|
|
90
|
+
return body.split("\n\n").flatMap((block): [string, string, string | null][] => {
|
|
91
|
+
const lines = block.split("\n");
|
|
92
|
+
const module = lines[0]?.startsWith("// ") ? lines[0].slice(3) : null;
|
|
93
|
+
const head = lines.find((line) => !line.startsWith("/**") && !line.startsWith("// ")) ?? "";
|
|
94
|
+
const name = ApiReportDiff.#nameOf(head);
|
|
95
|
+
return name === null ? [] : [[name, block, module]];
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static #subpathsOf(section: string) {
|
|
100
|
+
return section.replace(/```ts\n[\s\S]*?```/g, "").matchAll(ApiReportDiff.#subpathPattern);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static #nameOf(head: string) {
|
|
104
|
+
if (head.startsWith("export default ")) return "default";
|
|
105
|
+
const reexport = ApiReportDiff.#reexportPattern.exec(head);
|
|
106
|
+
if (reexport) return reexport[2] ?? reexport[1] ?? null;
|
|
107
|
+
const namespaceReexport = ApiReportDiff.#namespaceReexportPattern.exec(head);
|
|
108
|
+
if (namespaceReexport) return namespaceReexport[1] ?? null;
|
|
109
|
+
return ApiReportDiff.#declarationPattern.exec(head)?.[1] ?? null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static #referencedNameOf(key: string) {
|
|
113
|
+
const index = key.indexOf(ApiReportDiff.#referencedMark);
|
|
114
|
+
return index < 0 ? null : key.slice(0, index);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static #sameDeclaration(a: string, b: string) {
|
|
118
|
+
const [left, right] = [ApiReportDiff.#declarationOf(a), ApiReportDiff.#declarationOf(b)];
|
|
119
|
+
return left === right || ApiReportDiff.#unorderedOf(left) === ApiReportDiff.#unorderedOf(right);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//? The checker orders union members and mapped keys by first sight, so checking files in another order moves them.
|
|
123
|
+
static #unorderedOf(declaration: string) {
|
|
124
|
+
const source = ts.createSourceFile("block.d.ts", declaration, ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
|
|
125
|
+
//? `parseDiagnostics` is internal: parser recovery can drop tokens, so a block that failed to parse stays as text.
|
|
126
|
+
if ("parseDiagnostics" in source && Array.isArray(source.parseDiagnostics) && source.parseDiagnostics.length)
|
|
127
|
+
return declaration;
|
|
128
|
+
const textOf = (node: ts.Node) => ApiReportDiff.#printer.printNode(ts.EmitHint.Unspecified, node, source);
|
|
129
|
+
const byText = (a: ts.Node, b: ts.Node) => ApiReport.compare(textOf(a), textOf(b));
|
|
130
|
+
const byName = (a: ts.TypeElement, b: ts.TypeElement) =>
|
|
131
|
+
ApiReport.compare(a.name ? textOf(a.name) : "", b.name ? textOf(b.name) : "");
|
|
132
|
+
const sortMembers: ts.TransformerFactory<ts.SourceFile> = (context) => {
|
|
133
|
+
const visit = (node: ts.Node): ts.Node => {
|
|
134
|
+
const next = ts.visitEachChild(node, visit, context);
|
|
135
|
+
if (ts.isUnionTypeNode(next))
|
|
136
|
+
return context.factory.updateUnionTypeNode(
|
|
137
|
+
next,
|
|
138
|
+
context.factory.createNodeArray([...next.types].sort(byText)),
|
|
139
|
+
);
|
|
140
|
+
if (ts.isTypeLiteralNode(next))
|
|
141
|
+
return context.factory.updateTypeLiteralNode(
|
|
142
|
+
next,
|
|
143
|
+
context.factory.createNodeArray([...next.members].sort(byName)),
|
|
144
|
+
);
|
|
145
|
+
return next;
|
|
146
|
+
};
|
|
147
|
+
return (file) => ts.visitEachChild(file, visit, context);
|
|
148
|
+
};
|
|
149
|
+
const [sorted = source] = ts.transform(source, [sortMembers]).transformed;
|
|
150
|
+
return ApiReportDiff.#printer.printFile(sorted);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
static #declarationOf(block: string) {
|
|
154
|
+
return block
|
|
155
|
+
.split("\n")
|
|
156
|
+
.filter((line, idx) => !ApiReportDiff.#tagLine.test(line) && !(idx === 0 && line.startsWith("// ")))
|
|
157
|
+
.map((line) => (line.startsWith("export ") ? line.slice("export ".length) : line))
|
|
158
|
+
.join("\n");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { readdir } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ApiReport } from "./apiReport";
|
|
4
|
+
import { type ApiBreak, ApiReportDiff } from "./apiReportDiff";
|
|
5
|
+
import { ChangesetBump } from "./changesetBump";
|
|
6
|
+
|
|
7
|
+
export interface ApiPolicyVerdict {
|
|
8
|
+
breaks: ApiBreak[];
|
|
9
|
+
bumped: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class ApiReportPolicy {
|
|
13
|
+
readonly #root: string;
|
|
14
|
+
readonly #reportDir: string;
|
|
15
|
+
readonly #packageName: string;
|
|
16
|
+
|
|
17
|
+
constructor(root: string, reportDir: string, packageName: string) {
|
|
18
|
+
this.#root = root;
|
|
19
|
+
this.#reportDir = reportDir;
|
|
20
|
+
this.#packageName = packageName;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get reportDir() {
|
|
24
|
+
return this.#reportDir;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async readReports() {
|
|
28
|
+
const dir = path.join(this.#root, this.#reportDir);
|
|
29
|
+
const files = (await readdir(dir).catch(() => [] as string[])).filter((file) => file.endsWith(ApiReport.extension));
|
|
30
|
+
const reports = new Map<string, string>();
|
|
31
|
+
for (const file of files.sort(ApiReport.compare)) reports.set(file, await Bun.file(path.join(dir, file)).text());
|
|
32
|
+
return reports;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async check(base: string): Promise<ApiPolicyVerdict | null> {
|
|
36
|
+
if ((await this.#git(["rev-parse", "--verify", "--quiet", `${base}^{commit}`])) === null) return null;
|
|
37
|
+
const mergeBase = (await this.#git(["merge-base", base, "HEAD"]))?.trim();
|
|
38
|
+
if (!mergeBase) return null;
|
|
39
|
+
const before = new Map<string, string>();
|
|
40
|
+
const listed = (await this.#git(["ls-tree", "--name-only", `${mergeBase}:${this.#reportDir}`])) ?? "";
|
|
41
|
+
for (const file of listed.split("\n").filter((name) => name.endsWith(ApiReport.extension)))
|
|
42
|
+
before.set(file, (await this.#git(["show", `${mergeBase}:${this.#reportDir}/${file}`])) ?? "");
|
|
43
|
+
const breaks = ApiReportDiff.breaks(before, await this.readReports());
|
|
44
|
+
if (!breaks.length) return { breaks, bumped: false };
|
|
45
|
+
const added = [
|
|
46
|
+
...(
|
|
47
|
+
(await this.#git(["diff", "--name-only", "--no-renames", "--diff-filter=A", mergeBase, "--", ".changeset"])) ??
|
|
48
|
+
""
|
|
49
|
+
).split("\n"),
|
|
50
|
+
...((await this.#git(["ls-files", "--others", "--exclude-standard", "--", ".changeset"])) ?? "").split("\n"),
|
|
51
|
+
].filter((file) => file.endsWith(".md") && !file.endsWith("README.md"));
|
|
52
|
+
const bumps = await Promise.all(
|
|
53
|
+
added.map(async (file) =>
|
|
54
|
+
ChangesetBump.of(await Bun.file(path.join(this.#root, file)).text(), this.#packageName),
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
return { breaks, bumped: bumps.some((bump) => ChangesetBump.atLeast(bump, "minor")) };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async #git(args: string[]) {
|
|
61
|
+
const proc = Bun.spawn(["git", ...args], { cwd: this.#root, stdout: "pipe", stderr: "ignore" });
|
|
62
|
+
const [stdout, exitCode] = await Promise.all([new Response(proc.stdout).text(), proc.exited]);
|
|
63
|
+
return exitCode === 0 ? stdout : null;
|
|
64
|
+
}
|
|
65
|
+
}
|