@akanjs/devkit 3.2.0-rc.2 → 3.2.0-rc.21
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 +350 -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 +13 -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} +33 -263
- 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 +58 -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 -11
- package/preview/previewView.test.ts +76 -9
- 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} +9 -3
- 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 +26 -8
- 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 +29 -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 +2 -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 +28 -0
- package/workflow/plan.ts +15 -9
- 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} +85 -1
- package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +41 -6
- 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,277 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { AkanWorkspaceConfig } from "../akanConfig";
|
|
4
|
+
import { FileSys } from "../util/fileSys";
|
|
5
|
+
import { resolveRepoName } from "../workspace/repoIdentity";
|
|
6
|
+
import { WorkspaceInfo } from "../workspace/scanInfo";
|
|
7
|
+
import type { BaseDevEnv, TsConfigJson } from "../workspace/types";
|
|
8
|
+
import { Executor, execEmoji } from "./executor";
|
|
9
|
+
import { SysExecutor } from "./sysExecutor";
|
|
10
|
+
|
|
11
|
+
//? As Bun's own .env loader reads it (1.4.4), which fills process.env too: `#` ends an unquoted value even mid-word.
|
|
12
|
+
const parseEnvValue = (value: string) => {
|
|
13
|
+
const [, quote, inner] = value.match(/^(["'`])((?:\\.|(?!\1)[^\\])*)\1/) ?? [];
|
|
14
|
+
if (!quote) return value.replace(/#.*/, "").trim();
|
|
15
|
+
if (quote !== '"') return inner;
|
|
16
|
+
return inner.replace(/\\(.)/g, (pair, char: string) => (char === "n" ? "\n" : char === "r" ? "\r" : pair));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const parseEnvFile = (envPath: string): Record<string, string> => {
|
|
20
|
+
const env: Record<string, string> = {};
|
|
21
|
+
const content = (() => {
|
|
22
|
+
try {
|
|
23
|
+
return readFileSync(envPath, "utf8");
|
|
24
|
+
} catch {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
})();
|
|
28
|
+
for (const line of content.split(/\r?\n/)) {
|
|
29
|
+
const trimmed = line.trim();
|
|
30
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
31
|
+
const normalized = trimmed.startsWith("export ") ? trimmed.slice("export ".length).trim() : trimmed;
|
|
32
|
+
const separatorIndex = normalized.indexOf("=");
|
|
33
|
+
if (separatorIndex <= 0) continue;
|
|
34
|
+
const key = normalized.slice(0, separatorIndex).trim();
|
|
35
|
+
env[key] = parseEnvValue(normalized.slice(separatorIndex + 1).trim());
|
|
36
|
+
}
|
|
37
|
+
return env;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
interface ExecutorOptions {
|
|
41
|
+
workspaceRoot: string;
|
|
42
|
+
repoName: string;
|
|
43
|
+
}
|
|
44
|
+
export class WorkspaceExecutor extends Executor {
|
|
45
|
+
workspaceRoot: string;
|
|
46
|
+
repoName: string;
|
|
47
|
+
override emoji = execEmoji.workspace;
|
|
48
|
+
constructor({ workspaceRoot, repoName }: ExecutorOptions) {
|
|
49
|
+
super("workspace", workspaceRoot);
|
|
50
|
+
this.workspaceRoot = workspaceRoot;
|
|
51
|
+
this.repoName = repoName;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static fromRoot({
|
|
55
|
+
workspaceRoot = process.cwd(),
|
|
56
|
+
repoName = resolveRepoName(workspaceRoot),
|
|
57
|
+
}: {
|
|
58
|
+
workspaceRoot?: string;
|
|
59
|
+
repoName?: string;
|
|
60
|
+
} = {}) {
|
|
61
|
+
return new WorkspaceExecutor({ workspaceRoot, repoName });
|
|
62
|
+
}
|
|
63
|
+
/** The public env a native build was told to reproduce (`--public-env`): it outranks the shell, which outranks `.env`. */
|
|
64
|
+
static publicEnvPin: Record<string, string> | null = null;
|
|
65
|
+
static readonly localServeDomain = "localhost";
|
|
66
|
+
static getBaseDevEnv(envPath?: string) {
|
|
67
|
+
// Bun auto-loads .env, so we use process.env directly
|
|
68
|
+
const sourceEnv = {
|
|
69
|
+
...(envPath ? parseEnvFile(envPath) : {}),
|
|
70
|
+
//? An empty export reads as unset, unlike in dotenv, so it can't blank a key the .env sets.
|
|
71
|
+
...Object.fromEntries(Object.entries(process.env).filter(([, value]) => value)),
|
|
72
|
+
...WorkspaceExecutor.publicEnvPin,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const appName = sourceEnv.AKAN_PUBLIC_APP_NAME;
|
|
76
|
+
const workspaceRoot = sourceEnv.AKAN_WORKSPACE_ROOT;
|
|
77
|
+
const workspaceId = sourceEnv.AKAN_WORKSPACE_ID;
|
|
78
|
+
|
|
79
|
+
const repoName =
|
|
80
|
+
sourceEnv.AKAN_PUBLIC_REPO_NAME ||
|
|
81
|
+
resolveRepoName(envPath ? path.dirname(envPath) : (workspaceRoot ?? process.cwd()));
|
|
82
|
+
const serveDomain = sourceEnv.AKAN_PUBLIC_SERVE_DOMAIN || WorkspaceExecutor.localServeDomain;
|
|
83
|
+
const defaulted = (["AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const).filter((key) => !sourceEnv[key]);
|
|
84
|
+
|
|
85
|
+
const portOffset = parseInt(sourceEnv.PORT_OFFSET ?? "0");
|
|
86
|
+
|
|
87
|
+
const env = (sourceEnv.AKAN_PUBLIC_ENV ?? "debug") as
|
|
88
|
+
| "testing"
|
|
89
|
+
| "debug"
|
|
90
|
+
| "develop"
|
|
91
|
+
| "main"
|
|
92
|
+
| "local"
|
|
93
|
+
| undefined;
|
|
94
|
+
if (!env) throw new Error("AKAN_PUBLIC_ENV is not set");
|
|
95
|
+
return {
|
|
96
|
+
...(appName ? { appName } : {}),
|
|
97
|
+
workspaceRoot,
|
|
98
|
+
repoName,
|
|
99
|
+
serveDomain,
|
|
100
|
+
env,
|
|
101
|
+
portOffset,
|
|
102
|
+
workspaceId,
|
|
103
|
+
defaulted,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//? A clone has no `.env` (gitignored for its secrets): it runs local, as a new workspace and env.server.ts do, not debug.
|
|
107
|
+
static defaultCloneToLocalEnv(workspaceRoot: string) {
|
|
108
|
+
if (!existsSync(path.join(workspaceRoot, ".env"))) process.env.AKAN_PUBLIC_ENV ??= "local";
|
|
109
|
+
}
|
|
110
|
+
//? A build or tunnel for a real environment carries these into an image, a bundle or a host name it dials.
|
|
111
|
+
static assertDeployableEnv(baseDevEnv: BaseDevEnv, environment: string, purpose: string) {
|
|
112
|
+
const defaulted = environment === "local" ? [] : (baseDevEnv.defaulted ?? []);
|
|
113
|
+
if (!defaulted.length) return;
|
|
114
|
+
const values = { AKAN_PUBLIC_REPO_NAME: baseDevEnv.repoName, AKAN_PUBLIC_SERVE_DOMAIN: baseDevEnv.serveDomain };
|
|
115
|
+
const standIns = defaulted.map((key) => `${key} (would be "${values[key]}")`).join(" and ");
|
|
116
|
+
throw new Error(
|
|
117
|
+
`${purpose} for the "${environment}" environment needs ${standIns} set, not a local default. ` +
|
|
118
|
+
`Set ${defaulted.length > 1 ? "them" : "it"} in the workspace .env or the shell, or use AKAN_PUBLIC_ENV=local.`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
getWorkspaceId<AllowEmpty extends boolean = false>({
|
|
122
|
+
allowEmpty,
|
|
123
|
+
}: {
|
|
124
|
+
allowEmpty?: AllowEmpty;
|
|
125
|
+
} = {}): AllowEmpty extends true ? string | undefined : string {
|
|
126
|
+
const { workspaceId } = WorkspaceExecutor.getBaseDevEnv();
|
|
127
|
+
if (!workspaceId && !allowEmpty) throw new Error("Workspace ID is not found");
|
|
128
|
+
return workspaceId as AllowEmpty extends true ? string | undefined : string;
|
|
129
|
+
}
|
|
130
|
+
async scan(): Promise<WorkspaceInfo> {
|
|
131
|
+
return await WorkspaceInfo.fromExecutor(this);
|
|
132
|
+
}
|
|
133
|
+
#akanConfig: AkanWorkspaceConfig | null = null;
|
|
134
|
+
async getConfig({ refresh }: { refresh?: boolean } = {}) {
|
|
135
|
+
if (this.#akanConfig && !refresh) return this.#akanConfig;
|
|
136
|
+
this.#akanConfig = await AkanWorkspaceConfig.from(this, { bustImportCache: refresh });
|
|
137
|
+
return this.#akanConfig;
|
|
138
|
+
}
|
|
139
|
+
async getApps() {
|
|
140
|
+
return await this.#getDirHasFile(`${this.workspaceRoot}/apps`, "akan.config.ts");
|
|
141
|
+
}
|
|
142
|
+
async getLibs() {
|
|
143
|
+
return await this.#getDirHasFile(`${this.workspaceRoot}/libs`, "akan.config.ts");
|
|
144
|
+
}
|
|
145
|
+
async getSyss() {
|
|
146
|
+
const [appNames, libNames] = await Promise.all([this.getApps(), this.getLibs()]);
|
|
147
|
+
return [appNames, libNames] as [string[], string[]];
|
|
148
|
+
}
|
|
149
|
+
async getPkgs() {
|
|
150
|
+
return await this.#getDirHasFile(`${this.workspaceRoot}/pkgs`, "package.json");
|
|
151
|
+
}
|
|
152
|
+
async getExecs() {
|
|
153
|
+
const [appNames, libNames, pkgNames] = await Promise.all([this.getApps(), this.getLibs(), this.getPkgs()]);
|
|
154
|
+
return [appNames, libNames, pkgNames] as [string[], string[], string[]];
|
|
155
|
+
}
|
|
156
|
+
async setPkgTsPaths(name: string) {
|
|
157
|
+
const rootTsConfig = (await this.readJson("tsconfig.json")) as TsConfigJson;
|
|
158
|
+
rootTsConfig.compilerOptions.paths ??= {};
|
|
159
|
+
rootTsConfig.compilerOptions.paths[name] = [`./pkgs/${name}/index.ts`];
|
|
160
|
+
rootTsConfig.compilerOptions.paths[`${name}/*`] = [`./pkgs/${name}/*`];
|
|
161
|
+
if (rootTsConfig.references) {
|
|
162
|
+
if (!rootTsConfig.references.some((ref) => ref.path === `./pkgs/${name}/tsconfig.json`))
|
|
163
|
+
rootTsConfig.references.push({ path: `./pkgs/${name}/tsconfig.json` });
|
|
164
|
+
}
|
|
165
|
+
await this.writeJson("tsconfig.json", rootTsConfig);
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
async unsetPkgTsPaths(name: string) {
|
|
169
|
+
const rootTsConfig = (await this.readJson("tsconfig.json")) as TsConfigJson;
|
|
170
|
+
const filteredKeys = Object.keys(rootTsConfig.compilerOptions.paths ?? {}).filter(
|
|
171
|
+
(key) => key !== name && key !== `${name}/*`,
|
|
172
|
+
);
|
|
173
|
+
rootTsConfig.compilerOptions.paths = Object.fromEntries(
|
|
174
|
+
filteredKeys.map((key) => [key, rootTsConfig.compilerOptions.paths?.[key] ?? []]),
|
|
175
|
+
);
|
|
176
|
+
if (rootTsConfig.references) {
|
|
177
|
+
rootTsConfig.references = rootTsConfig.references.filter(
|
|
178
|
+
(ref) => ref.path !== `./pkgs/${name}/tsconfig.json`,
|
|
179
|
+
) as TsConfigJson["references"];
|
|
180
|
+
}
|
|
181
|
+
await this.writeJson("tsconfig.json", rootTsConfig);
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
async getDirInModule(basePath: string, name: string) {
|
|
185
|
+
const AVOID_DIRS = ["__lib", "__scalar", `_`, `_${name}`];
|
|
186
|
+
const getDirs = async (dirname: string, maxDepth = 3, results: string[] = [], prefix = "") => {
|
|
187
|
+
const dirs = await this.readdir(dirname);
|
|
188
|
+
await Promise.all(
|
|
189
|
+
dirs.map(async (dir) => {
|
|
190
|
+
if (dir.includes("_") || AVOID_DIRS.includes(dir)) return;
|
|
191
|
+
const dirPath = path.join(dirname, dir);
|
|
192
|
+
if (await FileSys.dirExists(this.getPath(dirPath))) {
|
|
193
|
+
results.push(`${prefix}${dir}`);
|
|
194
|
+
if (maxDepth > 0) await getDirs(dirPath, maxDepth - 1, results, `${prefix}${dir}/`);
|
|
195
|
+
}
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
return results;
|
|
199
|
+
};
|
|
200
|
+
return await getDirs(basePath);
|
|
201
|
+
}
|
|
202
|
+
async commit(
|
|
203
|
+
message: string,
|
|
204
|
+
{
|
|
205
|
+
init = false,
|
|
206
|
+
add = true,
|
|
207
|
+
identity,
|
|
208
|
+
}: { init?: boolean; add?: boolean; identity?: { name: string; email: string } } = {},
|
|
209
|
+
) {
|
|
210
|
+
if (init) await this.spawn("git", ["init", "--quiet"]);
|
|
211
|
+
if (add) await this.spawn("git", ["add", "."]);
|
|
212
|
+
const author = identity ? ["-c", `user.name=${identity.name}`, "-c", `user.email=${identity.email}`] : [];
|
|
213
|
+
// Argument vector, not a shell string: a message carrying a double quote breaks the interpolated form.
|
|
214
|
+
await this.spawn("git", [...author, "commit", "--quiet", "-m", message]);
|
|
215
|
+
}
|
|
216
|
+
/** `git commit` exits non-zero on an empty index, so a re-runnable caller has to ask first. */
|
|
217
|
+
async hasChanges() {
|
|
218
|
+
return !!(await this.spawn("git", ["status", "--porcelain"])).trim();
|
|
219
|
+
}
|
|
220
|
+
/** Sorted workspace-relative paths; `untracked` adds uncommitted files, still honoring `.gitignore`. */
|
|
221
|
+
async listGitFiles(paths: string[], { untracked = false }: { untracked?: boolean } = {}) {
|
|
222
|
+
if (!paths.length) return [];
|
|
223
|
+
const mode = untracked ? ["--cached", "--others", "--exclude-standard"] : ["--cached"];
|
|
224
|
+
const stdout = await this.spawn("git", ["ls-files", "-z", ...mode, "--", ...paths]);
|
|
225
|
+
return stdout
|
|
226
|
+
.split("\0")
|
|
227
|
+
.filter((file) => !!file)
|
|
228
|
+
.sort();
|
|
229
|
+
}
|
|
230
|
+
async #getDirHasFile(basePath: string, targetFilename: string) {
|
|
231
|
+
if (!(await FileSys.dirExists(basePath))) return [];
|
|
232
|
+
//? `local/` is gitignored scratch: a test's temporary workspace there has a package.json of its own.
|
|
233
|
+
const AVOID_DIRS = ["node_modules", "dist", "public", "webkit", "local"];
|
|
234
|
+
const getDirs = async (dirname: string, maxDepth = 3, results: string[] = [], prefix = "") => {
|
|
235
|
+
const dirs = await this.readdir(dirname);
|
|
236
|
+
await Promise.all(
|
|
237
|
+
dirs.map(async (dir) => {
|
|
238
|
+
if (AVOID_DIRS.includes(dir)) return;
|
|
239
|
+
const dirPath = path.join(dirname, dir);
|
|
240
|
+
//* Not `stat`: a dangling symlink would throw, and this walk backs `getApps`, i.e. every command.
|
|
241
|
+
if (await FileSys.dirExists(dirPath)) {
|
|
242
|
+
const hasTargetFile = await FileSys.fileExists(path.join(dirPath, targetFilename));
|
|
243
|
+
if (hasTargetFile) results.push(`${prefix}${dir}`);
|
|
244
|
+
if (maxDepth > 0) await getDirs(dirPath, maxDepth - 1, results, `${prefix}${dir}/`);
|
|
245
|
+
}
|
|
246
|
+
}),
|
|
247
|
+
);
|
|
248
|
+
return results;
|
|
249
|
+
};
|
|
250
|
+
return (await getDirs(basePath)).sort((a, b) => a.localeCompare(b));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async #fromEverySys<T>(read: (sys: SysExecutor) => Promise<T[]>): Promise<T[]> {
|
|
254
|
+
const [appNames, libNames] = await this.getSyss();
|
|
255
|
+
//? Plain SysExecutors: AppExecutor and LibExecutor extend SysExecutor, which imports this file, so importing them here
|
|
256
|
+
//? would load a subclass before its base. None of the readers below is overridden there.
|
|
257
|
+
const fromApps = await Promise.all(
|
|
258
|
+
appNames.map((name) => read(new SysExecutor({ workspace: this, name, type: "app" }))),
|
|
259
|
+
);
|
|
260
|
+
const fromLibs = await Promise.all(
|
|
261
|
+
libNames.map((name) => read(new SysExecutor({ workspace: this, name, type: "lib" }))),
|
|
262
|
+
);
|
|
263
|
+
return [...fromApps.flat(), ...fromLibs.flat()];
|
|
264
|
+
}
|
|
265
|
+
async getScalarConstantFiles() {
|
|
266
|
+
return await this.#fromEverySys((sys) => sys.getScalarConstantFiles());
|
|
267
|
+
}
|
|
268
|
+
async getConstantFiles() {
|
|
269
|
+
return await this.#fromEverySys((sys) => sys.getConstantFiles());
|
|
270
|
+
}
|
|
271
|
+
async getDictionaryFiles() {
|
|
272
|
+
return await this.#fromEverySys((sys) => sys.getDictionaryFiles());
|
|
273
|
+
}
|
|
274
|
+
async getViewFiles() {
|
|
275
|
+
return await this.#fromEverySys((sys) => sys.getViewsSourceCode());
|
|
276
|
+
}
|
|
277
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import { mkdir, realpath, symlink } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { tempDirs, writeText as write } from "../testHelpers";
|
|
4
|
+
import { tempDirs, writeText as write } from "../test/testHelpers";
|
|
5
5
|
import { AllRoutesBuilder } from "./allRoutesBuilder";
|
|
6
6
|
|
|
7
7
|
const makeTempRoot = tempDirs("akan-all-routes-");
|
|
@@ -32,14 +32,18 @@ const writeApp = async () => {
|
|
|
32
32
|
);
|
|
33
33
|
await write(
|
|
34
34
|
path.join(appDir, "page/memo.tsx"),
|
|
35
|
-
'import { Memo } from "../ui/Memo";\nexport default function Page() {\n return
|
|
35
|
+
'import { System } from "akanjs/ui/System";\nimport { Memo } from "../ui/Memo";\nexport default function Page() {\n return <><Memo /><System.ThemeToggle /></>;\n}\n',
|
|
36
|
+
);
|
|
37
|
+
await write(
|
|
38
|
+
path.join(appDir, "page/shell.tsx"),
|
|
39
|
+
'import { CSR } from "akanjs/ui/System/CSR";\nexport default function Page() {\n return <CSR />;\n}\n',
|
|
36
40
|
);
|
|
37
41
|
const app = {
|
|
38
42
|
name: "demo",
|
|
39
43
|
cwdPath: appDir,
|
|
40
44
|
dist: { cwdPath: path.join(root, "dist/apps/demo") },
|
|
41
45
|
workspace: { workspaceRoot: root },
|
|
42
|
-
getPageKeys: async () => ["./_index.tsx", "./memo.tsx"],
|
|
46
|
+
getPageKeys: async () => ["./_index.tsx", "./memo.tsx", "./shell.tsx"],
|
|
43
47
|
getConfig: async () => ({ basePaths: [], optimizeImports: [], barrelImports: [] }),
|
|
44
48
|
getTsConfig: async () => ({ compilerOptions: { paths } }),
|
|
45
49
|
getPublicEnv: () => ({}),
|
|
@@ -51,12 +55,12 @@ const writeApp = async () => {
|
|
|
51
55
|
};
|
|
52
56
|
|
|
53
57
|
describe("AllRoutesBuilder", () => {
|
|
54
|
-
test("writes the route manifest, then the preload table once the runtime chunks are known, and each route's modules", async () => {
|
|
58
|
+
test("writes the route manifest, then the preload table once the runtime chunks are known, and each route's modules without System's CSR and MCP App providers unless the page imports one", async () => {
|
|
55
59
|
const app = await writeApp();
|
|
56
60
|
const routes = new AllRoutesBuilder(app as never, "build");
|
|
57
61
|
const { manifest, manifestPath } = await routes.build();
|
|
58
62
|
|
|
59
|
-
expect(new Set(manifest.routeIds)).toEqual(new Set(["/:lang", "/:lang/memo"]));
|
|
63
|
+
expect(new Set(manifest.routeIds)).toEqual(new Set(["/:lang", "/:lang/memo", "/:lang/shell"]));
|
|
60
64
|
expect(await Bun.file(manifestPath).json()).not.toHaveProperty("modulePreloads");
|
|
61
65
|
|
|
62
66
|
const runtimeChunks = { runtime: ["/_akan/client/rsc.js"], vendors: { react: ["/_akan/client/react.js"] } };
|
|
@@ -70,8 +74,14 @@ describe("AllRoutesBuilder", () => {
|
|
|
70
74
|
const [home] = chunksOf("apps/demo/ui/Home.tsx#Home");
|
|
71
75
|
const [memo] = chunksOf("apps/demo/ui/Memo.tsx#Memo");
|
|
72
76
|
const shell = chunksOf("akanjs/ui/System/Client.tsx#Client");
|
|
77
|
+
const [csrShell] = chunksOf("akanjs/ui/System/CSR.tsx#CSR");
|
|
78
|
+
const [mcpAppShell] = chunksOf("akanjs/ui/System/App.tsx#AppProvider");
|
|
79
|
+
const [themeToggle] = chunksOf("akanjs/ui/System/ThemeToggle.tsx#ThemeToggle");
|
|
73
80
|
const modules = preloads.modulesByRoute();
|
|
74
81
|
expect(shell.length).toBeGreaterThan(0);
|
|
82
|
+
expect([csrShell, mcpAppShell, themeToggle]).not.toContain(undefined);
|
|
83
|
+
expect(modules["/:lang/memo"]).toContain(themeToggle);
|
|
84
|
+
expect(modules["/:lang/shell"]).toContain(csrShell);
|
|
75
85
|
for (const [routeId, own, other] of [
|
|
76
86
|
["/:lang", home, memo],
|
|
77
87
|
["/:lang/memo", memo, home],
|
|
@@ -79,6 +89,8 @@ describe("AllRoutesBuilder", () => {
|
|
|
79
89
|
expect(modules[routeId]?.slice(0, 2)).toEqual(["/_akan/client/rsc.js", "/_akan/client/react.js"]);
|
|
80
90
|
expect(modules[routeId]).toEqual(expect.arrayContaining([own, ...shell]));
|
|
81
91
|
expect(modules[routeId]).not.toContain(other);
|
|
92
|
+
expect(modules[routeId]).not.toContain(csrShell);
|
|
93
|
+
expect(modules[routeId]).not.toContain(mcpAppShell);
|
|
82
94
|
}
|
|
83
95
|
}, 30_000);
|
|
84
96
|
});
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import type { RoutesManifest } from "akanjs/server";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
isImplicitRootLayoutKey,
|
|
5
|
+
type PageEntry,
|
|
6
|
+
ROOT_LAYOUT_SYSTEM,
|
|
7
|
+
resolveSsrPageEntriesForApp,
|
|
8
|
+
} from "../artifact/implicitRootLayout";
|
|
4
9
|
import { computeRouteSeedIndex, type RouteSeedIndex } from "../artifact/routeSeedIndex";
|
|
5
10
|
import type { App } from "../commandDecorators";
|
|
6
11
|
import type { ClientEntryDiscovery } from "./clientBuildTypes";
|
|
@@ -26,7 +31,7 @@ export class AllRoutesBuilder {
|
|
|
26
31
|
};
|
|
27
32
|
#knownSet = new Set<string>();
|
|
28
33
|
#routeIds: string[] = [];
|
|
29
|
-
#
|
|
34
|
+
#ssrEntriesByRoute = new Map<string, string[]>();
|
|
30
35
|
#externalsByChunkUrl: Record<string, string[]> = {};
|
|
31
36
|
#discovery: ClientEntryDiscovery | null = null;
|
|
32
37
|
|
|
@@ -41,15 +46,17 @@ export class AllRoutesBuilder {
|
|
|
41
46
|
const pageEntries = await resolveSsrPageEntriesForApp(this.#app, pageKeys);
|
|
42
47
|
const seedIndex = computeRouteSeedIndex(pageEntries);
|
|
43
48
|
this.#app.verbose(`[build-all] discovered ${seedIndex.entries.length} routes`);
|
|
44
|
-
|
|
49
|
+
const discovery = await GraphClientEntryDiscovery.create(this.#app);
|
|
50
|
+
this.#discovery = discovery;
|
|
51
|
+
const importsAs = await this.#ssrImportsAs(discovery, pageEntries);
|
|
45
52
|
|
|
46
53
|
// Every route's entries go into one Bun.build: chunk splitting only dedupes within a single build.
|
|
47
54
|
const allEntries = new Set<string>();
|
|
48
55
|
for (const entry of seedIndex.entries) {
|
|
49
56
|
const seeds = Array.from(new Set([...seedIndex.globalLayoutFiles, ...entry.seeds]));
|
|
50
|
-
const routeEntries = await
|
|
57
|
+
const routeEntries = await discovery.discover(seeds);
|
|
51
58
|
for (const discovered of routeEntries) allEntries.add(discovered);
|
|
52
|
-
this.#
|
|
59
|
+
this.#ssrEntriesByRoute.set(entry.routeId, await discovery.discover(seeds, { importsAs }));
|
|
53
60
|
this.#routeIds.push(entry.routeId);
|
|
54
61
|
}
|
|
55
62
|
this.#app.verbose(`[build-all] ${allEntries.size} client entries across ${this.#routeIds.length} routes`);
|
|
@@ -71,10 +78,21 @@ export class AllRoutesBuilder {
|
|
|
71
78
|
return { manifest, manifestPath, seedIndex };
|
|
72
79
|
}
|
|
73
80
|
|
|
81
|
+
async #ssrImportsAs(discovery: GraphClientEntryDiscovery, pageEntries: PageEntry[]) {
|
|
82
|
+
const { specifier, ssrShell, importsNoSsrPageRenders } = ROOT_LAYOUT_SYSTEM;
|
|
83
|
+
const importsAs = new Map<string, ReadonlyMap<string, string | null>>();
|
|
84
|
+
const toShell = new Map([[specifier, ssrShell]]);
|
|
85
|
+
for (const { key, moduleAbsPath } of pageEntries)
|
|
86
|
+
if (isImplicitRootLayoutKey(key)) importsAs.set(path.resolve(moduleAbsPath), toShell);
|
|
87
|
+
const system = await discovery.resolveImport(specifier, this.#app.cwdPath);
|
|
88
|
+
if (system) importsAs.set(system, new Map(importsNoSsrPageRenders.map((spec) => [spec, null])));
|
|
89
|
+
return importsAs;
|
|
90
|
+
}
|
|
91
|
+
|
|
74
92
|
async writeModulePreloads(runtimeChunks: RuntimeChunks): Promise<RouteModulePreloads> {
|
|
75
93
|
const preloads = new RouteModulePreloads({
|
|
76
94
|
runtimeChunks,
|
|
77
|
-
entriesByRoute: this.#
|
|
95
|
+
entriesByRoute: this.#ssrEntriesByRoute,
|
|
78
96
|
clientManifest: this.#merged.clientManifest,
|
|
79
97
|
externalsByChunkUrl: this.#externalsByChunkUrl,
|
|
80
98
|
workspaceRoot: this.#app.workspace.workspaceRoot,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { tempDirs } from "../testHelpers";
|
|
4
|
+
import { tempDirs } from "../test/testHelpers";
|
|
5
5
|
import { AutoImportSync, transformSource } from "./autoImportSync";
|
|
6
6
|
|
|
7
7
|
const makeTempRoot = tempDirs("akan-auto-import-");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import ts from "typescript";
|
|
4
|
-
import { FileSys } from "../fileSys";
|
|
4
|
+
import { FileSys } from "../util/fileSys";
|
|
5
5
|
|
|
6
6
|
//* Closed-registry scan (no type information); writes only on a real diff, or the watcher loops on its own edits.
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import { realpath } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { tempDirs, writeText as write } from "../testHelpers";
|
|
4
|
+
import { tempDirs, writeText as write } from "../test/testHelpers";
|
|
5
5
|
import { createTsconfigPackageResolver } from "../transforms/barrelImportsPlugin";
|
|
6
6
|
import { CLIENT_BUNDLE_NAMING } from "./clientBuildTypes";
|
|
7
7
|
import { ClientEntriesBundler } from "./clientEntriesBundler";
|
|
@@ -9,6 +9,8 @@ export const bundleDefine = (app: App, command: "build" | "start", renderEnv: "s
|
|
|
9
9
|
return {
|
|
10
10
|
"process.env.NODE_ENV": JSON.stringify(nodeEnv),
|
|
11
11
|
"process.env.AKAN_PUBLIC_RENDER_ENV": JSON.stringify(renderEnv),
|
|
12
|
+
//? NODE_ENV is production under `NODE_ENV=production akan start` too; this says the page's vendors were narrowed.
|
|
13
|
+
"process.env.AKAN_BUNDLE_COMMAND": JSON.stringify(command),
|
|
12
14
|
//? Sorted: Windows hands a child its environment sorted, while keys the config sets at runtime trail the parent's,
|
|
13
15
|
//? and the dev registries hash this object to tell a worker's build from the builder's.
|
|
14
16
|
...Object.fromEntries(
|
|
@@ -38,8 +38,12 @@ export const CLIENT_BUNDLE_NAMING = {
|
|
|
38
38
|
asset: "assets/[hash].[ext]",
|
|
39
39
|
} as const;
|
|
40
40
|
|
|
41
|
+
export interface DiscoverOptions {
|
|
42
|
+
importsAs?: ReadonlyMap<string, ReadonlyMap<string, string | null>>;
|
|
43
|
+
}
|
|
44
|
+
|
|
41
45
|
export interface ClientEntryDiscovery {
|
|
42
|
-
discover(seeds: string[]): Promise<string[]>;
|
|
46
|
+
discover(seeds: string[], options?: DiscoverOptions): Promise<string[]>;
|
|
43
47
|
invalidate?(files: string[]): void;
|
|
44
48
|
}
|
|
45
49
|
|
|
@@ -59,7 +63,6 @@ export interface BundleClientEntriesInternalOptions extends BundleClientEntriesO
|
|
|
59
63
|
externalSubpaths?: readonly string[];
|
|
60
64
|
externalAliases?: Partial<Record<string, string>>;
|
|
61
65
|
command?: "build" | "start";
|
|
62
|
-
/** Per absolute entry, the only names its alias re-exports, in place of every name the entry declares. */
|
|
63
66
|
entryExports?: Partial<Record<string, readonly string[]>>;
|
|
64
67
|
}
|
|
65
68
|
|
|
@@ -2,7 +2,7 @@ import { describe, expect, test } from "bun:test";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import { realpath } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { tempDirs, writeText } from "../testHelpers";
|
|
5
|
+
import { tempDirs, writeText } from "../test/testHelpers";
|
|
6
6
|
import { ClientEntriesBundler } from "./clientEntriesBundler";
|
|
7
7
|
|
|
8
8
|
const makeTempRoot = tempDirs("akan-client-entries-");
|
|
@@ -2,6 +2,7 @@ import { afterAll, describe, expect, test } from "bun:test";
|
|
|
2
2
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { createTsconfigPackageResolver } from "../transforms/barrelImportsPlugin";
|
|
5
6
|
import { GraphClientEntryDiscovery } from "./clientEntryDiscovery";
|
|
6
7
|
|
|
7
8
|
const dirs: string[] = [];
|
|
@@ -122,6 +123,35 @@ describe("GraphClientEntryDiscovery", () => {
|
|
|
122
123
|
expect(await discovery.discover([file("M5.tsx")])).toEqual([file("C.tsx")]);
|
|
123
124
|
});
|
|
124
125
|
|
|
126
|
+
test("a root layout importing System by its file under a tsconfig wildcard reaches System's client entries", async () => {
|
|
127
|
+
const file = await tempDir();
|
|
128
|
+
const workspaceRoot = path.dirname(file("x"));
|
|
129
|
+
await Bun.write(
|
|
130
|
+
file("pkgs/akanjs/ui/System/index.tsx"),
|
|
131
|
+
'import SSR from "./SSR";\nexport const System = { SSR };\n',
|
|
132
|
+
);
|
|
133
|
+
await Bun.write(
|
|
134
|
+
file("pkgs/akanjs/ui/System/SSR.tsx"),
|
|
135
|
+
'import { ClientWrapper } from "./Client";\nexport default ClientWrapper;\n',
|
|
136
|
+
);
|
|
137
|
+
await Bun.write(
|
|
138
|
+
file("pkgs/akanjs/ui/System/Client.tsx"),
|
|
139
|
+
'"use client";\nexport const ClientWrapper = () => null;\n',
|
|
140
|
+
);
|
|
141
|
+
await Bun.write(
|
|
142
|
+
file("root/__root_layout.tsx"),
|
|
143
|
+
'import { System } from "akanjs/ui/System/index.tsx";\nexport default System;\n',
|
|
144
|
+
);
|
|
145
|
+
const resolvePackage = await createTsconfigPackageResolver({
|
|
146
|
+
workspace: { workspaceRoot },
|
|
147
|
+
getTsConfig: async () => ({ compilerOptions: { paths: { "akanjs/ui/*": ["./pkgs/akanjs/ui/*"] } } }),
|
|
148
|
+
} as never);
|
|
149
|
+
const discovery = new GraphClientEntryDiscovery({ barrelImports: [] }, resolvePackage);
|
|
150
|
+
expect(await discovery.discover([file("root/__root_layout.tsx")])).toEqual([
|
|
151
|
+
file("pkgs/akanjs/ui/System/Client.tsx"),
|
|
152
|
+
]);
|
|
153
|
+
});
|
|
154
|
+
|
|
125
155
|
test("a file walked inside an import cycle keeps no partial result for a walk that starts at it", async () => {
|
|
126
156
|
const file = await tempDir();
|
|
127
157
|
await Bun.write(file("A.tsx"), 'import "./B";\nimport "./C";\n');
|
|
@@ -131,4 +161,32 @@ describe("GraphClientEntryDiscovery", () => {
|
|
|
131
161
|
expect(await discovery.discover([file("A.tsx")])).toEqual([file("C.tsx")]);
|
|
132
162
|
expect(await discovery.discover([file("B.tsx")])).toEqual([file("C.tsx")]);
|
|
133
163
|
});
|
|
164
|
+
|
|
165
|
+
test("a file walked with its imports swapped or dropped keeps that walk's answer out of every other walk", async () => {
|
|
166
|
+
const file = await tempDir();
|
|
167
|
+
await Bun.write(file("Layout.tsx"), 'import "./Both";\n');
|
|
168
|
+
await Bun.write(file("Page.tsx"), 'import "./Layout";\n');
|
|
169
|
+
await Bun.write(file("Both.tsx"), 'import "./Server";\nimport "./Browser";\n');
|
|
170
|
+
await Bun.write(file("Server.tsx"), 'import "./S";\n');
|
|
171
|
+
await Bun.write(file("Browser.tsx"), '"use client";\nexport const Browser = () => null;\n');
|
|
172
|
+
await Bun.write(file("S.tsx"), '"use client";\nexport const S = () => null;\n');
|
|
173
|
+
const discovery = new GraphClientEntryDiscovery({ barrelImports: [] }, (async () => null) as never);
|
|
174
|
+
const importsAs = new Map([[file("Layout.tsx"), new Map([["./Both", "./Server"]])]]);
|
|
175
|
+
|
|
176
|
+
expect(await discovery.discover([file("Page.tsx")])).toEqual([file("Browser.tsx"), file("S.tsx")]);
|
|
177
|
+
expect(await discovery.discover([file("Page.tsx")], { importsAs })).toEqual([file("S.tsx")]);
|
|
178
|
+
expect(await discovery.discover([file("Layout.tsx")], { importsAs })).toEqual([file("S.tsx")]);
|
|
179
|
+
expect(await discovery.discover([file("Page.tsx")])).toEqual([file("Browser.tsx"), file("S.tsx")]);
|
|
180
|
+
const dropped = new Map([[file("Both.tsx"), new Map([["./Browser", null]])]]);
|
|
181
|
+
expect(await discovery.discover([file("Page.tsx")], { importsAs: dropped })).toEqual([file("S.tsx")]);
|
|
182
|
+
|
|
183
|
+
const fresh = new GraphClientEntryDiscovery({ barrelImports: [] }, (async () => null) as never);
|
|
184
|
+
expect(await fresh.discover([file("Page.tsx")], { importsAs })).toEqual([file("S.tsx")]);
|
|
185
|
+
expect(await fresh.discover([file("Page.tsx")])).toEqual([file("Browser.tsx"), file("S.tsx")]);
|
|
186
|
+
expect(await fresh.discover([file("Layout.tsx")])).toEqual([file("Browser.tsx"), file("S.tsx")]);
|
|
187
|
+
|
|
188
|
+
await Bun.write(file("Server.tsx"), "export const server = 1;\n");
|
|
189
|
+
fresh.invalidate([file("Server.tsx")]);
|
|
190
|
+
expect(await fresh.discover([file("Page.tsx")], { importsAs })).toEqual([]);
|
|
191
|
+
});
|
|
134
192
|
});
|
|
@@ -4,7 +4,7 @@ import { SOURCE_EXTS } from "../akanApp/devHostPolicy";
|
|
|
4
4
|
import type { App } from "../commandDecorators";
|
|
5
5
|
import { BarrelAnalyzer, type BarrelExportMap } from "../transforms/barrelAnalyzer";
|
|
6
6
|
import { createTsconfigPackageResolver, rewriteBarrelImports } from "../transforms/barrelImportsPlugin";
|
|
7
|
-
import type { AkanConfig, ClientEntryDiscovery, ScannedImport } from "./clientBuildTypes";
|
|
7
|
+
import type { AkanConfig, ClientEntryDiscovery, DiscoverOptions, ScannedImport } from "./clientBuildTypes";
|
|
8
8
|
|
|
9
9
|
const USE_CLIENT_RE = /^\s*(?:\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\/\s*|\/\/[^\n]*\n\s*)*["']use client["']/;
|
|
10
10
|
const NODE_MODULES_RE = /[\\/]node_modules[\\/]/;
|
|
@@ -31,6 +31,8 @@ interface DiscoveryWalk {
|
|
|
31
31
|
//? Every file's result within this walk, partial ones included: the file the cycle went back to is an ancestor here
|
|
32
32
|
//? and brings the rest itself, and re-walking each path through a dense cycle grows exponentially.
|
|
33
33
|
memo: Map<string, Set<string>>;
|
|
34
|
+
importsAs?: DiscoverOptions["importsAs"];
|
|
35
|
+
reachable: Map<string, Set<string>>;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
const exportsKeyOf = (map: BarrelExportMap | null): string =>
|
|
@@ -50,6 +52,8 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
50
52
|
#resolvedFileCache = new Map<string, Lookup<string | null>>();
|
|
51
53
|
#resolvedSpecifierCache = new Map<string, Lookup<string | null>>();
|
|
52
54
|
#reachableEntriesCache = new Map<string, Set<string>>();
|
|
55
|
+
//? Keyed by a walk's `importsAs`: a file's answer under swapped imports holds only for walks swapping the same ones.
|
|
56
|
+
#swappedEntriesCaches = new WeakMap<object, Map<string, Set<string>>>();
|
|
53
57
|
#readFiles = new Set<string>();
|
|
54
58
|
#barrelImporters = new Map<string, Set<string>>();
|
|
55
59
|
//? Barrels a save went beside, by the analysis before it: a save of any component re-reads its barrel, and only an
|
|
@@ -70,17 +74,29 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
70
74
|
return new GraphClientEntryDiscovery(await app.getConfig(), await createTsconfigPackageResolver(app));
|
|
71
75
|
}
|
|
72
76
|
|
|
73
|
-
async discover(seeds: string[]): Promise<string[]> {
|
|
77
|
+
async discover(seeds: string[], { importsAs }: DiscoverOptions = {}): Promise<string[]> {
|
|
74
78
|
this.#settled = this.#settled.then(() => this.#dropRenarrowed());
|
|
75
79
|
await this.#settled;
|
|
76
80
|
const entries = new Set<string>();
|
|
81
|
+
const reachable = importsAs ? this.#swappedEntriesCache(importsAs) : this.#reachableEntriesCache;
|
|
77
82
|
for (const seed of seeds) {
|
|
78
|
-
const walk: DiscoveryWalk = { visiting: new Set(), partial: new Set(), memo: new Map() };
|
|
83
|
+
const walk: DiscoveryWalk = { visiting: new Set(), partial: new Set(), memo: new Map(), importsAs, reachable };
|
|
79
84
|
for (const entry of await this.#discoverFromFile(seed, walk)) entries.add(entry);
|
|
80
85
|
}
|
|
81
86
|
return Array.from(entries).sort();
|
|
82
87
|
}
|
|
83
88
|
|
|
89
|
+
async resolveImport(spec: string, importerDir: string): Promise<string | null> {
|
|
90
|
+
const resolved = await this.#resolveSpecifier(spec, importerDir);
|
|
91
|
+
return resolved ? path.resolve(resolved) : null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
#swappedEntriesCache(importsAs: object): Map<string, Set<string>> {
|
|
95
|
+
const cache = this.#swappedEntriesCaches.get(importsAs) ?? new Map<string, Set<string>>();
|
|
96
|
+
this.#swappedEntriesCaches.set(importsAs, cache);
|
|
97
|
+
return cache;
|
|
98
|
+
}
|
|
99
|
+
|
|
84
100
|
invalidate(files: string[]): void {
|
|
85
101
|
if (files.length === 0) return;
|
|
86
102
|
let moved = false;
|
|
@@ -95,6 +111,7 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
95
111
|
this.#epoch += 1;
|
|
96
112
|
// Reachable-entry results are transitive, so a changed child invalidates every ancestor.
|
|
97
113
|
this.#reachableEntriesCache.clear();
|
|
114
|
+
this.#swappedEntriesCaches = new WeakMap();
|
|
98
115
|
for (const [barrel, before] of this.#analyzer.forget(files))
|
|
99
116
|
if (!this.#reread.has(barrel)) this.#reread.set(barrel, before);
|
|
100
117
|
//? A file gone, or one never read, can leave a found resolution on its old target (`Chart.tsx` to
|
|
@@ -223,7 +240,8 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
223
240
|
async #discoverFromFile(file: string, walk: DiscoveryWalk): Promise<Set<string>> {
|
|
224
241
|
const epoch = this.#epoch;
|
|
225
242
|
const absPath = path.resolve(file);
|
|
226
|
-
const
|
|
243
|
+
const importsAs = walk.importsAs?.get(absPath);
|
|
244
|
+
const cached = walk.reachable.get(absPath);
|
|
227
245
|
if (cached) return new Set(cached);
|
|
228
246
|
const memo = walk.memo.get(absPath);
|
|
229
247
|
if (memo) {
|
|
@@ -253,7 +271,8 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
253
271
|
|
|
254
272
|
const importerDir = path.dirname(absPath);
|
|
255
273
|
for (const imp of facts.imports) {
|
|
256
|
-
const
|
|
274
|
+
const swapped = importsAs?.get(imp.path);
|
|
275
|
+
const spec = swapped === undefined ? imp.path : swapped;
|
|
257
276
|
if (!spec) continue;
|
|
258
277
|
if (NON_SOURCE_EXT_RE.test(spec)) continue;
|
|
259
278
|
const resolved = await this.#resolveSpecifier(spec, importerDir);
|
|
@@ -268,7 +287,7 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
268
287
|
#finishDiscovery(absPath: string, walk: DiscoveryWalk, entries: Set<string>, epoch: number): Set<string> {
|
|
269
288
|
walk.visiting.delete(absPath);
|
|
270
289
|
walk.memo.set(absPath, entries);
|
|
271
|
-
if (epoch === this.#epoch && !walk.partial.has(absPath))
|
|
290
|
+
if (epoch === this.#epoch && !walk.partial.has(absPath)) walk.reachable.set(absPath, entries);
|
|
272
291
|
return new Set(entries);
|
|
273
292
|
}
|
|
274
293
|
}
|