@akanjs/devkit 3.2.0-rc.9 → 3.2.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -529
- 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 +152 -6
- package/akanApp/akanApp.host.ts +187 -1220
- package/akanApp/akanApp.host.wiring.test.ts +931 -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 +394 -0
- package/akanApp/devBuildStatusBoard.ts +128 -0
- package/akanApp/devBuilder.ts +200 -0
- package/akanApp/devIdleSuspend.test.ts +221 -0
- package/akanApp/devIdleSuspend.ts +192 -0
- package/akanApp/devIdleSuspend.watcher.test.ts +120 -0
- package/akanApp/devRecycler.test.ts +66 -0
- package/akanApp/devRecycler.ts +305 -0
- package/akanApp/devStartTimeline.test.ts +115 -0
- package/akanApp/devStartTimeline.ts +69 -0
- package/akanApp/processRss.ts +61 -0
- package/akanConfig/akanConfig.test.ts +45 -17
- package/akanConfig/akanConfig.ts +10 -10
- package/akanConfig/akanWorkspaceConfig.ts +1 -1
- package/akanConfig/productionLockfile.ts +1 -1
- package/apiReport/apiReport.test.ts +34 -3
- package/apiReport/apiReportDiff.ts +35 -1
- package/apiReport/apiReportPolicy.ts +3 -2
- package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +2 -49
- package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +71 -8
- package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +60 -21
- package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
- package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +17 -1
- package/{routeJsBudget.ts → app/routeJsBudget.ts} +9 -3
- package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
- package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
- package/artifact/implicitRootLayout.test.ts +71 -3
- package/artifact/implicitRootLayout.ts +9 -3
- package/artifact/implicitRootLayoutRender.test.tsx +297 -0
- package/biome.base.json +2 -1
- package/cloud/cloudApi.test.ts +1 -1
- package/cloud/configLock.test.ts +1 -1
- package/cloud/globalConfig.test.ts +1 -1
- package/cloud/globalConfig.ts +1 -1
- package/cloud/updatePackUpload.test.ts +1 -1
- package/codeAgent/agent/AkanCodeEnv.ts +1 -1
- package/codeAgent/agent/AkanCodeServices.ts +23 -0
- package/codeAgent/agent/akanCodePaths.ts +1 -1
- package/codeAgent/agent/akanCodeServices.test.ts +54 -0
- package/codeAgent/agent/akanSystemPrompt.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +1 -1
- package/codeAgent/skills/akan-debug/SKILL.md +8 -5
- package/codeAgent/skills/akan-err/SKILL.md +7 -0
- package/codeAgent/skills/akan-mcp/SKILL.md +19 -1
- package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
- package/codeAgent/skills/akan-validate/SKILL.md +3 -3
- package/codeAgent/tools/AkanCli.ts +1 -1
- package/codeAgent/tools/AkanToolPack.ts +2 -2
- package/codeAgent/tools/akanCodePlugins.test.ts +1 -1
- package/commandDecorators/command.ts +35 -6
- package/commandDecorators/commandBuilder.ts +1 -1
- package/commandDecorators/commandDecorators.test.ts +107 -6
- package/commandDecorators/targetMeta.ts +2 -0
- package/commandDecorators/workspaceVersionCheck.test.ts +70 -1
- package/commandDecorators/workspaceVersionCheck.ts +64 -14
- package/context/akanContext.ts +576 -0
- package/context/akanContextInspection.ts +296 -0
- package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
- package/{akanMcpContract.ts → context/akanMcpContract.ts} +16 -256
- package/context/doctor/agentGuideCheck.ts +81 -0
- package/context/doctor/configLeftoverCheck.ts +35 -0
- package/context/doctor/doctorFindings.ts +70 -0
- package/context/doctor/generatedFreshness.ts +56 -0
- package/context/doctor/moduleShapeCheck.ts +88 -0
- package/context/doctor/recipeDuplicateCheck.ts +42 -0
- package/context/doctor/recipeIndexCheck.ts +87 -0
- package/context/doctor/rootShapeCheck.ts +55 -0
- package/context/doctor/workflowScope.ts +97 -0
- package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
- package/context/safeRead.ts +9 -0
- package/csrE2e/csrE2eHarness.fixture.ts +1 -1
- package/devkitUtils.test.ts +39 -5
- package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
- package/{apiReference.ts → docs/apiReference.ts} +2 -2
- package/docs/errorCodeReference.test.ts +282 -0
- package/docs/errorCodeReference.ts +71 -0
- package/docs/errorCodeScan.ts +551 -0
- package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
- package/executors/appExecutor.ts +463 -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} +106 -18
- package/executors/index.ts +8 -0
- package/executors/libExecutor.ts +23 -0
- package/executors/moduleExecutor.ts +18 -0
- package/executors/pkgExecutor.ts +129 -0
- package/executors/sysExecutor.ts +301 -0
- package/executors/workspaceExecutor.ts +277 -0
- package/frontendBuild/allRoutesBuilder.test.ts +1 -1
- package/frontendBuild/autoImportSync.test.ts +1 -1
- package/frontendBuild/autoImportSync.ts +1 -1
- package/frontendBuild/buildCacheStamp.test.ts +42 -0
- package/frontendBuild/buildCacheStamp.ts +23 -0
- package/frontendBuild/buildRouteClient.test.ts +1 -1
- package/frontendBuild/clientEntriesBundler.test.ts +1 -1
- package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
- package/frontendBuild/csrDevArtifactWriter.ts +1 -1
- package/frontendBuild/cssCandidateCache.test.ts +70 -1
- package/frontendBuild/cssCandidateCache.ts +17 -10
- package/frontendBuild/cssCompiler.test.ts +3 -2
- package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
- package/frontendBuild/devGeneratedIndexSync.ts +7 -38
- package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
- package/frontendBuild/fontOptimizer.test.ts +145 -4
- package/frontendBuild/fontOptimizer.ts +103 -18
- package/frontendBuild/fontPruner.test.ts +1 -1
- package/frontendBuild/frontendBuild.test.ts +3 -3
- package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
- package/frontendBuild/hmrWatcher.test.ts +1 -1
- package/frontendBuild/hmrWatcher.ts +22 -1
- package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
- package/frontendBuild/mcpAppViewBuilder.ts +1 -1
- package/frontendBuild/nativeCore.test.ts +1 -1
- package/frontendBuild/optionalPeers.test.ts +36 -8
- package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
- package/frontendBuild/pagesBundleBuilder.ts +1 -1
- package/frontendBuild/precompressArtifacts.test.ts +1 -1
- package/frontendBuild/precompressArtifacts.ts +19 -6
- package/frontendBuild/serverGraphFile.ts +1 -1
- package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
- package/frontendBuild/ssrBaseArtifactBuilder.test.ts +30 -1
- package/frontendBuild/ssrBaseArtifactBuilder.ts +40 -12
- package/frontendBuild/ssrDevBundler.test.ts +1 -1
- package/frontendBuild/vendorImportScanner.test.ts +1 -1
- package/frontendBuild/vendorNarrowing.test.ts +1 -1
- package/frontendBuild/watchRootResolver.test.ts +1 -1
- package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
- package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
- package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
- package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
- package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
- package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
- package/{prompter.ts → guideline/prompter.ts} +2 -3
- package/incrementalBuilder/buildBatch.proc.ts +16 -5
- package/incrementalBuilder/buildBatchProtocol.ts +3 -0
- package/incrementalBuilder/buildBatchRunner.test.ts +122 -2
- package/incrementalBuilder/buildBatchRunner.ts +17 -4
- package/incrementalBuilder/builderBoot.ts +113 -0
- package/incrementalBuilder/builderBuildStatus.ts +23 -0
- package/incrementalBuilder/builderChannel.test.ts +1 -1
- package/incrementalBuilder/builderChannel.ts +19 -2
- 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 +16 -0
- package/incrementalBuilder/incrementalBuilder.host.ts +7 -1
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +142 -7
- package/incrementalBuilder/incrementalBuilder.proc.ts +82 -823
- package/incrementalBuilder/ssrRegistry.ts +282 -0
- package/index.ts +22 -22
- package/integration/devStability.integration.test.ts +62 -56
- package/integration/devStabilityHarness.test.ts +1 -1
- package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
- package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
- package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
- package/lint/gritRules.test.ts +1 -1
- package/{linter.test.ts → lint/linter.test.ts} +1 -1
- package/lint/no-import-common-err.grit +31 -0
- package/lint/no-init-fetch-in-client.grit +1 -1
- package/mobile/desktopBin.test.ts +1 -1
- package/mobile/desktopRelease.test.ts +1 -1
- package/mobile/desktopServerStage.test.ts +2 -2
- package/mobile/desktopServerStage.ts +1 -1
- package/mobile/nativeApi.test.ts +1 -1
- package/mobile/nativeApp.test.ts +1 -1
- package/mobile/nativeConfig.test.ts +1 -1
- package/mobile/nativePluginFolders.test.ts +1 -1
- package/mobile/nativePublicEnv.test.ts +1 -1
- package/mobile/nativePublicEnv.ts +2 -1
- package/mobile/nativeWebDir.test.ts +1 -1
- package/mobile/serverBundleSecrets.test.ts +1 -1
- package/mobile/tarWriter.test.ts +1 -1
- package/mobile/updatePackFolder.test.ts +1 -1
- package/package.json +173 -9
- package/packageExports.test.ts +20 -2
- package/piDependencyPins.test.ts +1 -1
- package/pipeline/PipelineDefinition.ts +1 -1
- package/platformTest/IdleWatchedProcess.test.ts +1 -1
- package/platformTest/LinuxDockerTarget.ts +1 -1
- package/platformTest/PlatformTestRun.test.ts +1 -1
- package/platformTest/TestSnapshot.test.ts +1 -1
- package/platformTest/WindowsSshTarget.ts +1 -1
- package/preview/previewView.test.ts +23 -1
- package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
- package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
- package/quality/bareErrorScanner.ts +126 -0
- package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
- package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
- package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
- package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
- package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
- package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
- package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
- package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
- package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +41 -1
- package/{qualityScanner.ts → quality/qualityScanner.ts} +25 -91
- package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
- package/quality/workspaceSourceFiles.ts +82 -0
- package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
- package/{subspace.ts → subspace/subspace.ts} +5 -5
- package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
- package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
- package/{testHelpers.ts → test/testHelpers.ts} +37 -1
- package/transforms/barrelAnalyzer.ts +31 -10
- package/transforms/browserDirnamePlugin.test.ts +1 -1
- package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
- package/transforms/mcpAppPageTrimmer.test.ts +1 -1
- package/transforms/pureLazyMarker.test.ts +1 -1
- package/transforms/serverEnvPlugin.test.ts +1 -1
- package/transforms/serverEnvProfile.test.ts +1 -1
- package/transforms/sideEffectImportOrder.test.ts +1 -1
- package/transforms/transforms.test.ts +52 -2
- package/transforms/tsconfigPackageResolver.test.ts +1 -1
- package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
- package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
- package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
- package/typecheck/projectTypecheck.test.ts +23 -1
- package/typecheck/projectTypecheck.ts +10 -2
- package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
- package/{typeChecker.ts → typecheck/typeChecker.ts} +5 -4
- package/typecheck/typecheck.proc.ts +6 -2
- package/typecheck/typecheckFailure.ts +1 -1
- package/util/errorReport.ts +66 -0
- package/{fileSys.test.ts → util/fileSys.test.ts} +13 -0
- package/{fileSys.ts → util/fileSys.ts} +2 -2
- package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
- package/workflow/constantSource.ts +187 -0
- package/workflow/dictionarySource.ts +184 -0
- package/workflow/executor.ts +6 -9
- package/workflow/fieldExpression.ts +153 -0
- package/workflow/fieldLabel.ts +61 -0
- package/workflow/fieldOrder.ts +117 -0
- package/workflow/fieldType.ts +2 -1
- package/workflow/guardCatalog.test.ts +1 -1
- package/workflow/keyRename.ts +1 -1
- package/workflow/moduleIndex.test.ts +2 -2
- package/workflow/moduleIndex.ts +2 -2
- package/workflow/modulePaths.ts +27 -0
- package/workflow/mutationScaffold.ts +7 -15
- package/workflow/mutationSource.ts +2 -1
- package/workflow/plan.ts +2 -1
- package/workflow/primitiveReport.ts +78 -0
- package/workflow/rolloutGate.test.ts +1 -1
- package/workflow/rolloutGate.ts +1 -1
- package/workflow/serviceSource.ts +33 -0
- package/workflow/signalSource.ts +96 -0
- package/workflow/source.ts +50 -1100
- package/workflow/sourceAst.ts +30 -0
- package/workflow/sourceImports.ts +105 -0
- package/workflow/sourceText.ts +13 -0
- package/workflow/templateSource.ts +30 -0
- package/workflow/testSource.ts +31 -0
- package/workflow/types.ts +1 -1
- package/workflow/uiPolicy.ts +1 -1
- package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
- package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
- package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
- package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
- package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
- package/{envSeed.ts → workspace/envSeed.ts} +1 -1
- package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
- package/{libSource.ts → workspace/libSource.ts} +1 -1
- package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
- package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
- package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
- package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
- package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
- package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
- package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
- package/akanContext.ts +0 -1083
- package/executors.ts +0 -1749
- /package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +0 -0
- /package/{akanMcpToolError.ts → context/akanMcpToolError.ts} +0 -0
- /package/{moduleFieldNames.test.ts → context/moduleFieldNames.test.ts} +0 -0
- /package/{moduleFieldNames.ts → context/moduleFieldNames.ts} +0 -0
- /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
- /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
- /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
- /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
- /package/{linter.ts → lint/linter.ts} +0 -0
- /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
- /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
- /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
- /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
- /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
- /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
- /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
- /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
- /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
- /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
- /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
- /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
- /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
- /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
- /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
- /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
- /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
- /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
- /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
- /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
- /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
- /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
- /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
- /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
- /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
- /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
- /package/{storeSource.ts → quality/storeSource.ts} +0 -0
- /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
- /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
- /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
- /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
- /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
- /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
- /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
- /package/{writePath.ts → quality/writePath.ts} +0 -0
- /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
- /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
- /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
- /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
- /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
- /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
- /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
- /package/{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,527 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ChildProcess,
|
|
3
|
+
type ExecOptions,
|
|
4
|
+
exec,
|
|
5
|
+
type ForkOptions,
|
|
6
|
+
fork,
|
|
7
|
+
type SpawnOptions,
|
|
8
|
+
spawn,
|
|
9
|
+
} from "node:child_process";
|
|
10
|
+
import { copyFile, cp as cpEntry, mkdir, readdir as readDirEntries, rm, stat } from "node:fs/promises";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { capitalize, Logger, toError } from "akanjs/common";
|
|
13
|
+
import { $ } from "bun";
|
|
14
|
+
import chalk from "chalk";
|
|
15
|
+
import { Linter } from "../lint/linter";
|
|
16
|
+
import { ProjectTypecheck } from "../typecheck/projectTypecheck";
|
|
17
|
+
// Type-only: `getTypeChecker` loads it on demand to keep `typescript` out of the resident module graph.
|
|
18
|
+
import type { TypeChecker } from "../typecheck/typeChecker";
|
|
19
|
+
import { FileSys, getDirname } from "../util/fileSys";
|
|
20
|
+
import { JsonFormatter } from "../util/jsonFormatter";
|
|
21
|
+
import { Spinner } from "../util/spinner";
|
|
22
|
+
import type { AppInfo, LibInfo } from "../workspace/scanInfo";
|
|
23
|
+
import type { FileContent, PackageJson, TsConfigJson } from "../workspace/types";
|
|
24
|
+
import { CommandExecutionError } from "./commandExecutionError";
|
|
25
|
+
|
|
26
|
+
export interface WrittenFileContent extends FileContent {
|
|
27
|
+
written: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const staticTemplateFileExtensions = new Set(
|
|
31
|
+
".avif .bmp .cjs .css .eot .gif .html .ico .jpeg .jpg .js .json .map .md .mjs .mp3 .mp4 .ogg .otf .pdf .png .svg"
|
|
32
|
+
.split(" ")
|
|
33
|
+
.concat(".ttf .txt .wasm .wav .webm .webp .woff .woff2 .xml".split(" ")),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const execEmoji = {
|
|
37
|
+
workspace: "🏠",
|
|
38
|
+
app: "🚀",
|
|
39
|
+
lib: "🔧",
|
|
40
|
+
pkg: "📦",
|
|
41
|
+
dist: "💿",
|
|
42
|
+
module: "⚙️",
|
|
43
|
+
default: "✈️",
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const withCapitalizedDict = (dict: { [key: string]: string } = {}) => ({
|
|
47
|
+
...dict,
|
|
48
|
+
...Object.fromEntries(Object.entries(dict).map(([key, value]) => [capitalize(key), capitalize(value)])),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export class Executor {
|
|
52
|
+
static verbose = false;
|
|
53
|
+
static setVerbose(verbose: boolean) {
|
|
54
|
+
Executor.verbose = verbose;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
name: string;
|
|
58
|
+
logger: Logger;
|
|
59
|
+
logs: string[];
|
|
60
|
+
cwdPath: string;
|
|
61
|
+
emoji = execEmoji.default;
|
|
62
|
+
typeChecker: TypeChecker | null = null;
|
|
63
|
+
linter: Linter | null = null;
|
|
64
|
+
constructor(name: string, cwdPath: string) {
|
|
65
|
+
this.name = name;
|
|
66
|
+
this.logger = new Logger(name);
|
|
67
|
+
this.logs = [] as string[];
|
|
68
|
+
this.cwdPath = cwdPath;
|
|
69
|
+
}
|
|
70
|
+
#stdout(data: Buffer) {
|
|
71
|
+
if (Executor.verbose) Logger.raw(chalk.dim(data.toString()));
|
|
72
|
+
}
|
|
73
|
+
#stderr(data: Buffer) {
|
|
74
|
+
Logger.raw(chalk.red(data.toString()));
|
|
75
|
+
}
|
|
76
|
+
#settle(
|
|
77
|
+
proc: ChildProcess,
|
|
78
|
+
target: { command: string; args?: string[]; cwd: string },
|
|
79
|
+
{ onClose = false, keepLogs = false, redStderr = false } = {},
|
|
80
|
+
): Promise<{ code: number | null; signal: NodeJS.Signals | null; stdout: string }> {
|
|
81
|
+
let stdout = "";
|
|
82
|
+
let stderr = "";
|
|
83
|
+
proc.stdout?.on("data", (data: Buffer) => {
|
|
84
|
+
stdout += data.toString();
|
|
85
|
+
if (keepLogs) this.logs.push(data.toString());
|
|
86
|
+
this.#stdout(data);
|
|
87
|
+
});
|
|
88
|
+
proc.stderr?.on("data", (data: Buffer) => {
|
|
89
|
+
stderr += data.toString();
|
|
90
|
+
if (keepLogs) this.logs.push(data.toString());
|
|
91
|
+
if (redStderr) this.#stderr(data);
|
|
92
|
+
else this.#stdout(data); // 정상로그도 stderr로 나옴
|
|
93
|
+
});
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
proc.on("error", (cause) =>
|
|
96
|
+
reject(new CommandExecutionError({ ...target, code: null, signal: null, stdout, stderr, cause })),
|
|
97
|
+
);
|
|
98
|
+
proc.on(onClose ? "close" : "exit", (code: number | null, signal: NodeJS.Signals | null) => {
|
|
99
|
+
if ((onClose ? code !== 0 : code) || signal)
|
|
100
|
+
reject(new CommandExecutionError({ ...target, code, signal, stdout, stderr }));
|
|
101
|
+
else resolve({ code, signal, stdout });
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
exec(command: string, options: ExecOptions = {}): Promise<unknown> {
|
|
106
|
+
const target = { command, cwd: options.cwd?.toString() ?? this.cwdPath };
|
|
107
|
+
const proc = exec(command, { cwd: this.cwdPath, ...options });
|
|
108
|
+
return this.#settle(proc, target).then(({ code, signal }) => ({ code, signal }));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
spawn(command: string, args: string[] = [], options: SpawnOptions = {}): Promise<string> {
|
|
112
|
+
const target = { command, args, cwd: options.cwd?.toString() ?? this.cwdPath };
|
|
113
|
+
const proc = spawn(command, args, { cwd: this.cwdPath, ...options });
|
|
114
|
+
return this.#settle(proc, target, { onClose: true, keepLogs: true }).then(({ stdout }) => stdout);
|
|
115
|
+
}
|
|
116
|
+
spawnSync(command: string, args: string[] = [], options: SpawnOptions = {}): ChildProcess {
|
|
117
|
+
return spawn(command, args, { cwd: this.cwdPath, ...options });
|
|
118
|
+
}
|
|
119
|
+
fork(modulePath: string, args: string[] = [], options: ForkOptions = {}): Promise<unknown> {
|
|
120
|
+
const target = { command: modulePath, args, cwd: options.cwd?.toString() ?? this.cwdPath };
|
|
121
|
+
const proc = fork(modulePath, args, { cwd: this.cwdPath, ...options });
|
|
122
|
+
return this.#settle(proc, target, { redStderr: true }).then(({ code, signal }) => ({ code, signal }));
|
|
123
|
+
}
|
|
124
|
+
getPath(filePath: string) {
|
|
125
|
+
if (path.isAbsolute(filePath)) return filePath;
|
|
126
|
+
if (filePath.startsWith(".")) return path.join(this.cwdPath, filePath);
|
|
127
|
+
const baseParts = this.cwdPath.split(/[\\/]/).filter(Boolean);
|
|
128
|
+
const targetParts = filePath.split(/[\\/]/).filter(Boolean);
|
|
129
|
+
|
|
130
|
+
let overlapLength = 0;
|
|
131
|
+
for (let i = 1; i <= Math.min(baseParts.length, targetParts.length); i++) {
|
|
132
|
+
let isOverlap = true;
|
|
133
|
+
for (let j = 0; j < i; j++)
|
|
134
|
+
if (baseParts[baseParts.length - i + j] !== targetParts[j]) {
|
|
135
|
+
isOverlap = false;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
if (isOverlap) overlapLength = i;
|
|
139
|
+
}
|
|
140
|
+
return path.join(this.cwdPath, ...targetParts.slice(overlapLength));
|
|
141
|
+
}
|
|
142
|
+
async mkdir(dirPath: string) {
|
|
143
|
+
const writePath = this.getPath(dirPath);
|
|
144
|
+
if (!(await FileSys.dirExists(writePath))) await mkdir(writePath, { recursive: true });
|
|
145
|
+
this.logger.verbose(`Make directory ${writePath}`);
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
async readdir(dirPath: string): Promise<string[]> {
|
|
149
|
+
const readPath = this.getPath(dirPath);
|
|
150
|
+
try {
|
|
151
|
+
const glob = new Bun.Glob("*");
|
|
152
|
+
return Array.from(glob.scanSync({ cwd: readPath, onlyFiles: false })).sort();
|
|
153
|
+
} catch {
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async getAllFiles(pattern = "**/*", { cwd }: { cwd?: string } = {}): Promise<string[]> {
|
|
158
|
+
const glob = new Bun.Glob(pattern);
|
|
159
|
+
return Array.from(glob.scanSync({ cwd: cwd ?? this.cwdPath, onlyFiles: true })).sort();
|
|
160
|
+
}
|
|
161
|
+
async getFilesAndDirs(dirPath: string): Promise<{ files: string[]; dirs: string[] }> {
|
|
162
|
+
const fullDirPath = this.getPath(dirPath);
|
|
163
|
+
const glob = new Bun.Glob("*");
|
|
164
|
+
const files = Array.from(glob.scanSync({ cwd: fullDirPath, onlyFiles: true })).sort();
|
|
165
|
+
const allEntries = Array.from(glob.scanSync({ cwd: fullDirPath, onlyFiles: false })).sort();
|
|
166
|
+
const dirs = allEntries.filter((entry) => !files.includes(entry));
|
|
167
|
+
return { files, dirs };
|
|
168
|
+
}
|
|
169
|
+
async exists(filePath: string) {
|
|
170
|
+
return await FileSys.exists(this.getPath(filePath));
|
|
171
|
+
}
|
|
172
|
+
async remove(filePath: string) {
|
|
173
|
+
const readPath = this.getPath(filePath);
|
|
174
|
+
if (await FileSys.fileExists(readPath)) await FileSys.delete(readPath);
|
|
175
|
+
this.logger.verbose(`Remove file ${readPath}`);
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
async removeDir(dirPath: string) {
|
|
179
|
+
//* XXX: `path.join(…, ".")` drops a trailing slash: `rm -rf link/` wipes the target, `rm -rf link` only unlinks.
|
|
180
|
+
const readPath = path.join(this.getPath(dirPath), ".");
|
|
181
|
+
if (await FileSys.entryExists(readPath)) await rm(readPath, { recursive: true, force: true });
|
|
182
|
+
this.logger.verbose(`Remove directory ${readPath}`);
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
async writeFile(
|
|
186
|
+
filePath: string,
|
|
187
|
+
content: string | object,
|
|
188
|
+
{ overwrite = true, silent = false }: { overwrite?: boolean; silent?: boolean } = {},
|
|
189
|
+
): Promise<WrittenFileContent> {
|
|
190
|
+
const writePath = this.getPath(filePath);
|
|
191
|
+
const dir = path.dirname(writePath);
|
|
192
|
+
if (!(await FileSys.dirExists(dir))) await mkdir(dir, { recursive: true });
|
|
193
|
+
let contentStr = typeof content === "string" ? content : JsonFormatter.stringify(content, writePath);
|
|
194
|
+
let written = true;
|
|
195
|
+
|
|
196
|
+
if (await FileSys.fileExists(writePath)) {
|
|
197
|
+
const currentContent = await FileSys.readText(writePath);
|
|
198
|
+
if (currentContent === contentStr || !overwrite) {
|
|
199
|
+
this.logger.verbose(`File ${writePath} is unchanged`);
|
|
200
|
+
contentStr = currentContent;
|
|
201
|
+
written = false;
|
|
202
|
+
} else {
|
|
203
|
+
await FileSys.writeText(writePath, contentStr);
|
|
204
|
+
if (Logger.isVerbose()) this.logger.rawLog(chalk.yellow(`File Update: ${filePath}`));
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
await FileSys.writeText(writePath, contentStr);
|
|
208
|
+
if (!silent) this.logger.rawLog(chalk.green(`File Create: ${filePath}`));
|
|
209
|
+
}
|
|
210
|
+
return { filePath: writePath, content: contentStr, written };
|
|
211
|
+
}
|
|
212
|
+
async writeJson(filePath: string, content: object) {
|
|
213
|
+
await this.writeFile(filePath, content);
|
|
214
|
+
}
|
|
215
|
+
async getLocalFile(targetPath: string) {
|
|
216
|
+
const filePath = path.isAbsolute(targetPath) ? targetPath : targetPath.replace(this.cwdPath, "");
|
|
217
|
+
const content = await this.readFile(filePath);
|
|
218
|
+
return { filePath, content };
|
|
219
|
+
}
|
|
220
|
+
async readFile(filePath: string) {
|
|
221
|
+
return await FileSys.readText(this.getPath(filePath));
|
|
222
|
+
}
|
|
223
|
+
async readJson(filePath: string) {
|
|
224
|
+
return await FileSys.readJson<object>(this.getPath(filePath));
|
|
225
|
+
}
|
|
226
|
+
async cp(srcPath: string, destPath: string, { dereference = false }: { dereference?: boolean } = {}) {
|
|
227
|
+
const src = this.getPath(srcPath);
|
|
228
|
+
const dest = this.getPath(destPath);
|
|
229
|
+
if (!(await FileSys.exists(src))) return;
|
|
230
|
+
const isDirectory = (await stat(src)).isDirectory();
|
|
231
|
+
if (!(await FileSys.exists(dest)) && isDirectory) await mkdir(dest, { recursive: true });
|
|
232
|
+
//* `cp -r` keeps symlinks on GNU but follows them on macOS; Windows has no `cp -r <dir>/.` and rarely the
|
|
233
|
+
//* privilege a symlink needs, so it always copies real files.
|
|
234
|
+
if (dereference || process.platform === "win32")
|
|
235
|
+
await cpEntry(src, dest, { recursive: isDirectory, dereference: true, force: true });
|
|
236
|
+
else await $`cp -r ${src}${isDirectory ? "/." : ""} ${dest}`;
|
|
237
|
+
}
|
|
238
|
+
log(msg: string) {
|
|
239
|
+
this.logger.info(msg);
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
verbose(msg: string) {
|
|
243
|
+
this.logger.verbose(msg);
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
debug(msg: string) {
|
|
247
|
+
this.logger.debug(msg);
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
spinning(msg: string, { prefix = `${this.emoji}${this.name}`, indent = 0, enableSpin = !Executor.verbose } = {}) {
|
|
251
|
+
return new Spinner(msg, { prefix, indent, enableSpin }).start();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
#tsconfig: TsConfigJson | null = null;
|
|
255
|
+
async getTsConfig(pathname = "tsconfig.json", { refresh }: { refresh?: boolean } = {}): Promise<TsConfigJson> {
|
|
256
|
+
if (this.#tsconfig && !refresh) return this.#tsconfig;
|
|
257
|
+
let tsconfig = (await this.readJson(pathname)) as TsConfigJson;
|
|
258
|
+
if (tsconfig.extends) {
|
|
259
|
+
const base = await this.getTsConfig(tsconfig.extends, { refresh });
|
|
260
|
+
tsconfig = { ...base, ...tsconfig, compilerOptions: { ...base.compilerOptions, ...tsconfig.compilerOptions } };
|
|
261
|
+
}
|
|
262
|
+
this.#tsconfig = tsconfig;
|
|
263
|
+
return tsconfig;
|
|
264
|
+
}
|
|
265
|
+
async setTsConfig(tsconfig: TsConfigJson) {
|
|
266
|
+
await this.writeJson("tsconfig.json", tsconfig);
|
|
267
|
+
this.#tsconfig = tsconfig;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
#packageJson: PackageJson | null = null;
|
|
271
|
+
async getPackageJson({ refresh }: { refresh?: boolean } = {}): Promise<PackageJson> {
|
|
272
|
+
if (this.#packageJson && !refresh) return this.#packageJson;
|
|
273
|
+
const packageJson = (await this.readJson("package.json")) as PackageJson;
|
|
274
|
+
this.#packageJson = packageJson;
|
|
275
|
+
return packageJson;
|
|
276
|
+
}
|
|
277
|
+
async setPackageJson(packageJson: PackageJson) {
|
|
278
|
+
await this.writeJson("package.json", packageJson);
|
|
279
|
+
this.#packageJson = packageJson;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
#gitignorePatterns: string[] = [];
|
|
283
|
+
async getGitignorePatterns(): Promise<string[]> {
|
|
284
|
+
if (this.#gitignorePatterns.length) return this.#gitignorePatterns;
|
|
285
|
+
const gitignore = await this.readFile(".gitignore");
|
|
286
|
+
this.#gitignorePatterns = gitignore
|
|
287
|
+
.split("\n")
|
|
288
|
+
.map((line) => line.trim())
|
|
289
|
+
.filter((line) => !!line && !line.startsWith("#"));
|
|
290
|
+
return this.#gitignorePatterns;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async #applyTemplateFile(
|
|
294
|
+
{
|
|
295
|
+
templatePath,
|
|
296
|
+
targetPath,
|
|
297
|
+
scanInfo,
|
|
298
|
+
overwrite = true,
|
|
299
|
+
dryRun = false,
|
|
300
|
+
}: {
|
|
301
|
+
templatePath: string;
|
|
302
|
+
targetPath: string;
|
|
303
|
+
scanInfo?: AppInfo | LibInfo | null;
|
|
304
|
+
overwrite?: boolean;
|
|
305
|
+
dryRun?: boolean;
|
|
306
|
+
},
|
|
307
|
+
dict: { [key: string]: string } = {},
|
|
308
|
+
options: { [key: string]: unknown } = {},
|
|
309
|
+
): Promise<WrittenFileContent | null> {
|
|
310
|
+
const convertPath = (target: string) =>
|
|
311
|
+
Object.entries(dict).reduce(
|
|
312
|
+
(converted, [key, value]) => converted.replace(new RegExp(`__${key}__`, "g"), value),
|
|
313
|
+
target,
|
|
314
|
+
);
|
|
315
|
+
if (targetPath.endsWith(".ts") || targetPath.endsWith(".tsx")) {
|
|
316
|
+
const getContent = (await import(templatePath)) as {
|
|
317
|
+
default: (
|
|
318
|
+
scanInfo: AppInfo | LibInfo | null,
|
|
319
|
+
dict: { [key: string]: string },
|
|
320
|
+
options?: { [key: string]: unknown },
|
|
321
|
+
) => Promise<string | null | { filename: string; content: string }>;
|
|
322
|
+
};
|
|
323
|
+
const result = await getContent.default(scanInfo ?? null, dict, options);
|
|
324
|
+
if (result === null) return null;
|
|
325
|
+
const filename = typeof result === "object" ? result.filename : path.basename(targetPath).replace(".js", ".ts");
|
|
326
|
+
const content = typeof result === "object" ? result.content : result;
|
|
327
|
+
const convertedTargetPath = convertPath(`${path.dirname(targetPath)}/${filename}`);
|
|
328
|
+
if (dryRun) return { filePath: this.getPath(convertedTargetPath), content, written: false };
|
|
329
|
+
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
330
|
+
return this.writeFile(convertedTargetPath, content, { overwrite });
|
|
331
|
+
} else if (targetPath.endsWith(".template")) {
|
|
332
|
+
const content = await FileSys.readText(templatePath);
|
|
333
|
+
const convertedTargetPath = convertPath(targetPath.slice(0, -9));
|
|
334
|
+
const convertedContent = Object.entries(dict).reduce(
|
|
335
|
+
(data, [key, value]) => data.replace(new RegExp(`<%= ${key} %>`, "g"), value),
|
|
336
|
+
content,
|
|
337
|
+
);
|
|
338
|
+
if (dryRun) return { filePath: this.getPath(convertedTargetPath), content: convertedContent, written: false };
|
|
339
|
+
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
340
|
+
return this.writeFile(convertedTargetPath, convertedContent, { overwrite });
|
|
341
|
+
} else if (staticTemplateFileExtensions.has(path.extname(targetPath).toLowerCase())) {
|
|
342
|
+
const convertedTargetPath = convertPath(targetPath);
|
|
343
|
+
const writePath = this.getPath(convertedTargetPath);
|
|
344
|
+
if (dryRun) return { filePath: writePath, content: "", written: false };
|
|
345
|
+
if (!overwrite && (await FileSys.fileExists(writePath)))
|
|
346
|
+
return { filePath: writePath, content: "", written: false };
|
|
347
|
+
const dirname = path.dirname(writePath);
|
|
348
|
+
if (!(await FileSys.dirExists(dirname))) await mkdir(dirname, { recursive: true });
|
|
349
|
+
await copyFile(templatePath, writePath);
|
|
350
|
+
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
351
|
+
return { filePath: writePath, content: "", written: true };
|
|
352
|
+
} else return null;
|
|
353
|
+
}
|
|
354
|
+
async _applyTemplate({
|
|
355
|
+
basePath,
|
|
356
|
+
template,
|
|
357
|
+
scanInfo,
|
|
358
|
+
dict = {},
|
|
359
|
+
options = {},
|
|
360
|
+
overwrite = true,
|
|
361
|
+
dryRun = false,
|
|
362
|
+
}: {
|
|
363
|
+
basePath: string;
|
|
364
|
+
template: string;
|
|
365
|
+
scanInfo?: AppInfo | LibInfo | null;
|
|
366
|
+
dict?: { [key: string]: string };
|
|
367
|
+
options?: { [key: string]: unknown };
|
|
368
|
+
overwrite?: boolean;
|
|
369
|
+
dryRun?: boolean;
|
|
370
|
+
}): Promise<WrittenFileContent[]> {
|
|
371
|
+
const templateRoot = await this.#resolveTemplateRoot();
|
|
372
|
+
const templatePath = `${templateRoot}${template ? `/${template}` : ""}`;
|
|
373
|
+
if ((await stat(templatePath)).isFile()) {
|
|
374
|
+
const fileContent = await this.#applyTemplateFile(
|
|
375
|
+
{
|
|
376
|
+
templatePath,
|
|
377
|
+
targetPath: path.join(basePath, path.basename(templatePath)),
|
|
378
|
+
scanInfo,
|
|
379
|
+
overwrite,
|
|
380
|
+
dryRun,
|
|
381
|
+
},
|
|
382
|
+
dict,
|
|
383
|
+
options,
|
|
384
|
+
);
|
|
385
|
+
return fileContent ? [fileContent] : ([] as WrittenFileContent[]);
|
|
386
|
+
} else {
|
|
387
|
+
const subdirs = await readDirEntries(templatePath);
|
|
388
|
+
const fileContents = (
|
|
389
|
+
await Promise.all(
|
|
390
|
+
subdirs.map(async (subdir) => {
|
|
391
|
+
const subpath = path.join(templatePath, subdir);
|
|
392
|
+
if ((await stat(subpath)).isFile()) {
|
|
393
|
+
const fileContent = await this.#applyTemplateFile(
|
|
394
|
+
{
|
|
395
|
+
templatePath: subpath,
|
|
396
|
+
targetPath: path.join(basePath, subdir),
|
|
397
|
+
scanInfo,
|
|
398
|
+
overwrite,
|
|
399
|
+
dryRun,
|
|
400
|
+
},
|
|
401
|
+
dict,
|
|
402
|
+
options,
|
|
403
|
+
);
|
|
404
|
+
return fileContent ? [fileContent] : ([] as WrittenFileContent[]);
|
|
405
|
+
} else
|
|
406
|
+
return await this._applyTemplate({
|
|
407
|
+
basePath: path.join(basePath, subdir),
|
|
408
|
+
template: path.join(template, subdir),
|
|
409
|
+
scanInfo,
|
|
410
|
+
dict,
|
|
411
|
+
overwrite,
|
|
412
|
+
dryRun,
|
|
413
|
+
options,
|
|
414
|
+
});
|
|
415
|
+
}),
|
|
416
|
+
)
|
|
417
|
+
).flat();
|
|
418
|
+
return fileContents;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
async #resolveTemplateRoot() {
|
|
422
|
+
const candidates = [
|
|
423
|
+
path.resolve(getDirname(import.meta.url), "templates"),
|
|
424
|
+
path.resolve(getDirname(import.meta.url), "../../cli/templates"),
|
|
425
|
+
];
|
|
426
|
+
for (const candidate of candidates) {
|
|
427
|
+
if (await FileSys.dirExists(candidate)) return candidate;
|
|
428
|
+
}
|
|
429
|
+
return candidates[0];
|
|
430
|
+
}
|
|
431
|
+
async applyTemplate(options: {
|
|
432
|
+
basePath: string;
|
|
433
|
+
template: string;
|
|
434
|
+
scanInfo?: AppInfo | LibInfo | null;
|
|
435
|
+
dict?: { [key: string]: string };
|
|
436
|
+
options?: { [key: string]: unknown };
|
|
437
|
+
overwrite?: boolean;
|
|
438
|
+
dryRun?: boolean;
|
|
439
|
+
}): Promise<FileContent[]> {
|
|
440
|
+
const fileContents = await this._applyTemplate({ ...options, dict: withCapitalizedDict(options.dict) });
|
|
441
|
+
await this.#formatAppliedTemplate(fileContents.filter((fileContent) => fileContent.written));
|
|
442
|
+
return fileContents;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// Best-effort: `create-akan-workspace` scaffolds before `bun install`, with no local Biome binary yet, so a
|
|
446
|
+
// template emits Biome's form itself (`templates/biomeForm.ts`).
|
|
447
|
+
async #formatAppliedTemplate(fileContents: FileContent[]) {
|
|
448
|
+
const filePaths = fileContents
|
|
449
|
+
.map((fileContent) => fileContent.filePath)
|
|
450
|
+
.filter((filePath) => filePath.endsWith(".ts") || filePath.endsWith(".tsx"));
|
|
451
|
+
if (filePaths.length === 0) return;
|
|
452
|
+
try {
|
|
453
|
+
const { fixed } = await this.getLinter().fixFiles(filePaths);
|
|
454
|
+
if (fixed.length > 0) this.logger.verbose(`Formatted ${fixed.length} scaffolded file(s)`);
|
|
455
|
+
} catch (err) {
|
|
456
|
+
this.logger.verbose(`Skipped formatting scaffolded files: ${toError(err).message}`);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
// Async so `typescript` (~65MB resident) loads only in the commands that typecheck.
|
|
460
|
+
async getTypeChecker() {
|
|
461
|
+
const { TypeChecker } = await import("../typecheck/typeChecker");
|
|
462
|
+
this.typeChecker ??= new TypeChecker(this);
|
|
463
|
+
return this.typeChecker;
|
|
464
|
+
}
|
|
465
|
+
async typeCheck(filePath: string) {
|
|
466
|
+
const path = this.getPath(filePath);
|
|
467
|
+
const typeChecker = await this.getTypeChecker();
|
|
468
|
+
const { fileDiagnostics, fileErrors, fileWarnings } = typeChecker.check(path);
|
|
469
|
+
const message = typeChecker.formatDiagnostics(fileDiagnostics);
|
|
470
|
+
return { fileDiagnostics, fileErrors, fileWarnings, message };
|
|
471
|
+
}
|
|
472
|
+
async typeCheckAsync(filePath: string) {
|
|
473
|
+
const path = this.getPath(filePath);
|
|
474
|
+
const entry = await ProjectTypecheck.workerEntry(process.cwd());
|
|
475
|
+
const proc = Bun.spawn([process.execPath, entry], {
|
|
476
|
+
cwd: this.cwdPath,
|
|
477
|
+
env: {
|
|
478
|
+
...process.env,
|
|
479
|
+
AKAN_TYPECHECK_CWD: this.cwdPath,
|
|
480
|
+
AKAN_TYPECHECK_FILE: path,
|
|
481
|
+
},
|
|
482
|
+
stdout: "pipe",
|
|
483
|
+
stderr: "pipe",
|
|
484
|
+
});
|
|
485
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
486
|
+
new Response(proc.stdout).text(),
|
|
487
|
+
new Response(proc.stderr).text(),
|
|
488
|
+
proc.exited,
|
|
489
|
+
]);
|
|
490
|
+
if (exitCode !== 0) throw new Error((stderr || stdout).trim() || `Typecheck failed with exit code ${exitCode}`);
|
|
491
|
+
|
|
492
|
+
const result = JSON.parse(stdout) as {
|
|
493
|
+
fileDiagnosticsCount: number;
|
|
494
|
+
fileErrorsCount: number;
|
|
495
|
+
fileWarningsCount: number;
|
|
496
|
+
message: string;
|
|
497
|
+
};
|
|
498
|
+
return {
|
|
499
|
+
fileDiagnostics: Array.from({ length: result.fileDiagnosticsCount }),
|
|
500
|
+
fileErrors: Array.from({ length: result.fileErrorsCount }),
|
|
501
|
+
fileWarnings: Array.from({ length: result.fileWarningsCount }),
|
|
502
|
+
message: result.message,
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
getLinter() {
|
|
506
|
+
this.linter ??= new Linter(this.cwdPath);
|
|
507
|
+
return this.linter;
|
|
508
|
+
}
|
|
509
|
+
async lint(
|
|
510
|
+
filePath: string,
|
|
511
|
+
{ fix = false, dryRun = false }: { fix?: boolean; dryRun?: boolean } = {},
|
|
512
|
+
): Promise<{
|
|
513
|
+
results: unknown[];
|
|
514
|
+
message: string;
|
|
515
|
+
errors: unknown[];
|
|
516
|
+
warnings: unknown[];
|
|
517
|
+
}> {
|
|
518
|
+
const path = this.getPath(filePath);
|
|
519
|
+
const linter = this.getLinter();
|
|
520
|
+
const { results, errors, warnings } = await linter.lint(path, {
|
|
521
|
+
fix,
|
|
522
|
+
dryRun,
|
|
523
|
+
});
|
|
524
|
+
const message = linter.formatLintResults(results);
|
|
525
|
+
return { results, message, errors, warnings };
|
|
526
|
+
}
|
|
527
|
+
}
|
|
@@ -16,7 +16,7 @@ mock.module("node:fs/promises", () => ({
|
|
|
16
16
|
return await realSymlink(...args);
|
|
17
17
|
},
|
|
18
18
|
}));
|
|
19
|
-
const { AppExecutor, WorkspaceExecutor } = await import("./
|
|
19
|
+
const { AppExecutor, WorkspaceExecutor } = await import("./");
|
|
20
20
|
|
|
21
21
|
const { lstat, mkdir, mkdtemp, readFile, rm, writeFile } = fsPromises;
|
|
22
22
|
const originalEnv = { ...process.env };
|