@akanjs/devkit 3.3.0-rc.9 → 3.3.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/DEV_RUNTIME_KNOBS.md +1 -1
- package/README.ko.md +7 -1
- package/README.md +7 -1
- package/akanApp/akanApp.host.test.ts +3 -1
- package/akanApp/akanApp.host.ts +26 -2
- package/akanApp/akanApp.host.wiring.test.ts +111 -0
- package/akanApp/devHostPolicy.ts +5 -0
- package/akanApp/devMetadataRestart.ts +93 -0
- package/akanApp/devRecycler.test.ts +2 -0
- package/akanApp/devRecycler.ts +9 -0
- package/akanConfig/akanBin.ts +4 -0
- package/akanConfig/akanConfig.test.ts +307 -18
- package/akanConfig/akanConfig.ts +104 -210
- package/akanConfig/akanPreview.test.ts +28 -0
- package/akanConfig/akanPreview.ts +24 -0
- package/akanConfig/akanWorkers.test.ts +73 -0
- package/akanConfig/akanWorkers.ts +61 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +233 -0
- package/akanConfig/index.ts +3 -0
- package/akanConfig/nativeFileSettings.ts +33 -0
- package/akanConfig/types.ts +4 -0
- package/app/appBin.test.ts +63 -0
- package/app/appBin.ts +50 -0
- package/app/applicationBuildReporter.test.ts +51 -1
- package/app/applicationBuildReporter.ts +6 -1
- package/app/applicationBuildRunner.test.ts +438 -7
- package/app/applicationBuildRunner.ts +237 -37
- package/app/clientServerBoundary.test.ts +115 -0
- package/app/clientServerBoundary.ts +89 -0
- package/app/dictionarySizes.test.ts +40 -0
- package/app/dictionarySizes.ts +95 -0
- package/app/routeFilesReport.test.ts +59 -0
- package/app/routeFilesReport.ts +46 -0
- package/app/routeJsBudget.ts +18 -4
- package/artifact/implicitRootLayout.test.ts +19 -0
- package/artifact/implicitRootLayout.ts +16 -2
- package/artifact/implicitRootLayoutRender.test.tsx +7 -2
- package/artifact/storeBootstrap.test.ts +28 -0
- package/artifact/storeBootstrap.ts +64 -8
- package/biome.base.json +7 -5
- package/codeAgent/index.ts +1 -34
- package/codeAgent/skills/akan-agent/SKILL.md +2 -2
- package/codeAgent/skills/akan-debug/SKILL.md +11 -5
- package/codeAgent/skills/akan-deps/SKILL.md +10 -3
- package/codeAgent/skills/akan-err/SKILL.md +13 -8
- package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
- package/codeAgent/skills/akan-module/SKILL.md +2 -2
- package/codeAgent/skills/akan-page/SKILL.md +65 -30
- package/codeAgent/skills/akan-query/SKILL.md +13 -20
- package/codeAgent/skills/akan-runtime/SKILL.md +21 -1
- package/codeAgent/skills/akan-service/SKILL.md +21 -20
- package/codeAgent/skills/akan-transport/SKILL.md +5 -14
- package/codeAgent/skills/akan-ui/SKILL.md +16 -21
- package/codeAgent/skills/akan-validate/SKILL.md +8 -2
- package/commandDecorators/command.ts +28 -12
- package/commandDecorators/commandBuilder.ts +8 -1
- package/commandDecorators/commandDecorators.test.ts +70 -3
- package/commandDecorators/helpFormatter.ts +14 -12
- package/context/akanContext.ts +2 -0
- package/csrE2e/devHmrLatency.e2e.test.ts +1 -1
- package/csrE2e/ssrRegistry.e2e.test.ts +108 -22
- package/docs/apiReference.test.ts +25 -0
- package/docs/apiReference.ts +38 -5
- package/docs/declarationReader.ts +30 -0
- package/docs/errorCodeReference.test.ts +26 -0
- package/docs/errorCodeScan.ts +23 -6
- package/executors/appExecutor.ts +26 -12
- package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
- package/executors/clientRuntimeKeys.fixture.json +393 -0
- package/executors/clientRuntimeKeys.test.ts +1692 -0
- package/executors/executor.ts +14 -6
- package/executors/executors.test.ts +155 -1
- package/executors/pkgExecutor.ts +2 -1
- package/executors/sysExecutor.ts +112 -8
- package/executors/workspaceExecutor.ts +7 -4
- package/frontendBuild/allRoutesBuilder.ts +99 -7
- package/frontendBuild/autoImportSync.ts +3 -2
- package/frontendBuild/buildRouteClient.test.ts +684 -6
- package/frontendBuild/clientBuildTypes.ts +26 -0
- package/frontendBuild/clientEntriesBundler.test.ts +79 -0
- package/frontendBuild/clientEntriesBundler.ts +70 -1
- package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
- package/frontendBuild/clientEntryDiscovery.ts +134 -12
- package/frontendBuild/clientEntryGroups.test.ts +77 -0
- package/frontendBuild/clientEntryGroups.ts +61 -0
- package/frontendBuild/csrDevArtifactWriter.ts +2 -2
- package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
- package/frontendBuild/csrDevModuleCompiler.ts +44 -8
- package/frontendBuild/csrDevPatcher.test.ts +4 -5
- package/frontendBuild/csrDevPatcher.ts +37 -11
- package/frontendBuild/csrDevTypes.ts +9 -0
- package/frontendBuild/cssCandidateCache.test.ts +12 -0
- package/frontendBuild/cssCandidateCache.ts +5 -3
- package/frontendBuild/cssCompiler.test.ts +14 -0
- package/frontendBuild/devBarrelImports.test.ts +127 -0
- package/frontendBuild/devBarrelImports.ts +81 -21
- package/frontendBuild/devChangePlanner.ts +0 -1
- package/frontendBuild/devRegistryBundler.ts +4 -2
- package/frontendBuild/devRouteRuntime.test.ts +493 -0
- package/frontendBuild/devRouteRuntime.ts +167 -0
- package/frontendBuild/dictionaryAssetBuilder.test.ts +408 -0
- package/frontendBuild/dictionaryAssetBuilder.ts +185 -17
- package/frontendBuild/dictionaryConstants.ts +136 -0
- package/frontendBuild/dictionaryOwnParts.ts +88 -0
- package/frontendBuild/dictionaryPackState.ts +131 -0
- package/frontendBuild/dictionaryPacking.test.ts +207 -0
- package/frontendBuild/dictionaryPacking.ts +160 -0
- package/frontendBuild/dictionaryRoutes.test.ts +251 -0
- package/frontendBuild/dictionaryRoutes.ts +227 -0
- package/frontendBuild/frontendBuild.test.ts +5 -3
- package/frontendBuild/hmrWatcher.test.ts +3 -1
- package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
- package/frontendBuild/pagesBundleBuilder.ts +78 -2
- package/frontendBuild/plainStylesheet.test.ts +2 -2
- package/frontendBuild/precompressArtifacts.test.ts +22 -0
- package/frontendBuild/precompressArtifacts.ts +34 -8
- package/frontendBuild/registryMetadataFingerprint.ts +3 -3
- package/frontendBuild/renderedEntries.ts +144 -0
- package/frontendBuild/routeClientBuilder.ts +407 -43
- package/frontendBuild/routeHandoffs.test.ts +155 -0
- package/frontendBuild/routeHandoffs.ts +117 -0
- package/frontendBuild/routeModulePreloads.test.ts +32 -0
- package/frontendBuild/routeModulePreloads.ts +20 -11
- package/frontendBuild/routeRuntimeCheck.test.ts +280 -0
- package/frontendBuild/routeRuntimeCheck.ts +248 -0
- package/frontendBuild/routeRuntimePays.test.ts +143 -0
- package/frontendBuild/routeRuntimePays.ts +117 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +30 -35
- package/frontendBuild/ssrDevBundler.test.ts +150 -1
- package/frontendBuild/ssrDevBundler.ts +66 -11
- package/frontendBuild/vendorFileImports.test.ts +254 -0
- package/frontendBuild/vendorFileImports.ts +163 -0
- package/frontendBuild/vendorNarrowing.test.ts +47 -3
- package/frontendBuild/vendorNarrowing.ts +38 -2
- package/frontendBuild/vendorSpecifiers.ts +2 -0
- package/frontendBuild/workerChunks.ts +61 -0
- package/guideline/agentAssets.ts +1 -1
- package/incrementalBuilder/buildBatch.proc.ts +27 -1
- package/incrementalBuilder/buildBatchProtocol.ts +1 -0
- package/incrementalBuilder/builderWatch.ts +11 -1
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +159 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +31 -3
- package/incrementalBuilder/pendingMetadata.test.ts +27 -0
- package/incrementalBuilder/pendingMetadata.ts +19 -0
- package/integration/devResourceProbe.ts +14 -0
- package/integration/devStability.integration.test.ts +46 -21
- package/integration/renderAdmissionSoak.test.ts +39 -34
- package/integration/renderAdmissionSoak.ts +6 -0
- package/integration/ssrMemoryProbe.ts +5 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
- package/lint/biomeBase.test.ts +50 -3
- package/lint/biomeBase.ts +1 -1
- package/lint/biomeCheck.test.ts +173 -0
- package/lint/biomeCheck.ts +132 -0
- package/lint/linter.test.ts +16 -11
- package/lint/no-arbitrary-color.grit +5 -0
- package/lint/no-conditional-st-hook.grit +5 -1
- package/lint/no-daisyui-legacy-class.grit +8 -0
- package/lint/no-document-cookie.grit +3 -0
- package/lint/no-inline-color.grit +10 -2
- package/lint/no-oversized-list-limit.grit +2 -0
- package/lint/no-raw-palette-class.grit +7 -0
- package/lint/no-unpublished-form-setter.grit +2 -0
- package/lint/no-web-only-api-outside-webkit.grit +5 -0
- package/lint/no-web-storage.grit +3 -0
- package/lint/withheldEnvFile.ts +17 -0
- package/mobile/desktopBin.ts +2 -2
- package/mobile/desktopServerStage.test.ts +18 -3
- package/mobile/desktopServerStage.ts +7 -2
- package/mobile/nativeApp.test.ts +13 -5
- package/mobile/nativeApp.ts +9 -4
- package/mobile/nativeConfig.test.ts +27 -7
- package/mobile/nativeConfig.ts +19 -9
- package/mobile/nativePublicEnv.ts +1 -1
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +11 -12
- package/packageExports.test.ts +3 -2
- package/preview/PreviewView.ts +43 -6
- package/preview/previewView.test.ts +31 -0
- package/quality/dictionaryKeys.test.ts +356 -0
- package/quality/dictionaryKeys.ts +488 -0
- package/quality/maintainabilityContract.test.ts +4 -1
- package/quality/objectImportReport.test.ts +36 -0
- package/quality/objectImportReport.ts +105 -0
- package/quality/qualityScanner.ts +1 -1
- package/quality/routeRuntimeReport.test.ts +91 -0
- package/quality/routeRuntimeReport.ts +121 -0
- package/quality/runtimeConstantFacts.ts +71 -0
- package/quality/runtimeConstantGraph.ts +123 -0
- package/quality/runtimeConstantReads.ts +116 -0
- package/quality/runtimeImports.test.ts +190 -0
- package/quality/runtimeImports.ts +233 -0
- package/quality/runtimeKeyNames.ts +46 -0
- package/quality/runtimeLexicalScope.ts +132 -0
- package/quality/runtimeMarkerReach.test.ts +86 -0
- package/quality/runtimeMarkerReach.ts +255 -0
- package/quality/runtimeModuleFacts.ts +290 -0
- package/quality/runtimeNameTable.test.ts +172 -0
- package/quality/runtimeNameTable.ts +477 -0
- package/quality/runtimeScopeReport.test.ts +123 -0
- package/quality/runtimeScopeReport.ts +167 -0
- package/quality/runtimeSliceKey.ts +269 -0
- package/quality/runtimeSyntax.ts +133 -0
- package/quality/runtimeTable.fixture.ts +189 -0
- package/quality/runtimeUse.test.ts +737 -0
- package/quality/runtimeUse.ts +696 -0
- package/quality/runtimeUseReadable.test.ts +393 -0
- package/quality/ssrScanner.test.ts +13 -0
- package/quality/ssrScanner.ts +1 -1
- package/quality/translatorBindings.ts +187 -0
- package/test/fakeTerminal.ts +45 -0
- package/test/secretEnvFixture.ts +147 -0
- package/test/testHelpers.ts +11 -0
- package/transforms/barrelAnalyzer.ts +24 -2
- package/transforms/barrelImportsPlugin.ts +121 -32
- package/transforms/exportReach.test.ts +162 -0
- package/transforms/exportReach.ts +308 -0
- package/transforms/frameworkObjects.fixture.tsx +58 -0
- package/transforms/frameworkObjects.test.ts +57 -0
- package/transforms/modelReference.test.ts +197 -0
- package/transforms/modelReference.ts +39 -0
- package/transforms/moduleParts.test.ts +225 -0
- package/transforms/moduleParts.ts +418 -0
- package/transforms/objectImportEdits.ts +150 -0
- package/transforms/objectMemberImports.test.ts +631 -0
- package/transforms/objectMemberImports.ts +571 -0
- package/transforms/objectMemberLookup.ts +150 -0
- package/transforms/objectModule.test.ts +307 -0
- package/transforms/objectModule.ts +482 -0
- package/transforms/objectModuleAnalyzer.ts +104 -0
- package/transforms/partImports.test.ts +76 -0
- package/transforms/partImports.ts +110 -0
- package/transforms/partModules.test.ts +189 -0
- package/transforms/partModules.ts +90 -0
- package/transforms/partPurity.ts +124 -0
- package/transforms/reactIconImports.test.ts +231 -0
- package/transforms/reactIconImports.ts +325 -0
- package/transforms/routeConstants.ts +122 -0
- package/transforms/routeRuntime.test.ts +834 -0
- package/transforms/routeRuntime.ts +703 -0
- package/transforms/routeRuntimeEdits.ts +92 -0
- package/transforms/routeRuntimeGraph.ts +66 -0
- package/transforms/routeRuntimePlan.ts +244 -0
- package/transforms/secretEnvDeclaration.test.ts +211 -0
- package/transforms/secretEnvDeclaration.ts +219 -0
- package/transforms/secretEnvFile.test.ts +117 -0
- package/transforms/secretEnvFile.ts +132 -0
- package/transforms/secretEnvName.test.ts +54 -0
- package/transforms/secretEnvName.ts +29 -0
- package/transforms/secretEnvSource.test.ts +152 -0
- package/transforms/secretEnvSource.ts +197 -0
- package/transforms/serverEnvEvaluationError.ts +11 -0
- package/transforms/serverEnvPlugin.test.ts +157 -1
- package/transforms/serverEnvPlugin.ts +123 -19
- package/transforms/serverEnvProfile.test.ts +129 -2
- package/transforms/serverEnvProfile.ts +133 -43
- package/transforms/serverEnvSecrets.test.ts +268 -0
- package/transforms/signalDescriptors.test.ts +280 -0
- package/transforms/signalDescriptors.ts +230 -0
- package/transforms/thisFreeExports.ts +87 -0
- package/transforms/transforms.test.ts +184 -2
- package/transforms/tsconfigPackageResolver.test.ts +1 -0
- package/tunnel/createTunnel.ts +5 -1
- package/tunnel/ssh2Module.test.ts +37 -0
- package/tunnel/ssh2Module.ts +28 -0
- package/tunnel/sshTunnel.ts +4 -2
- package/typecheck/projectTypecheck.test.ts +32 -1
- package/typecheck/projectTypecheck.ts +3 -3
- package/typecheck/typeChecker.test.ts +50 -0
- package/typecheck/typeChecker.ts +14 -8
- package/typecheck/withheldDiagnostics.ts +44 -0
- package/util/devInstallCommand.ts +7 -0
- package/util/jsonFormatter.test.ts +13 -9
- package/workflow/executor.ts +6 -2
- package/workflow/index.ts +1 -0
- package/workflow/plan.ts +36 -7
- package/workflow/types.ts +1 -1
- package/workflow/uiTarget.ts +50 -0
- package/workspace/envSeed.test.ts +30 -1
- package/workspace/envSeed.ts +30 -1
- package/workspace/mainCheckout.test.ts +55 -0
- package/workspace/mainCheckout.ts +38 -0
- package/workspace/scanInfo.test.ts +39 -0
- package/workspace/scanInfo.ts +55 -6
- package/workspace/slicePlanner.ts +2 -1
- package/workspace/workspaceLayout.test.ts +22 -1
- package/workspace/workspaceLayout.ts +3 -3
- package/CHANGELOG.md +0 -2904
- package/codeAgent/agent/AkanCodeCompaction.ts +0 -49
- package/codeAgent/agent/AkanCodeServices.ts +0 -122
- package/codeAgent/agent/AkanContextFiles.ts +0 -94
- package/codeAgent/agent/CodeAgent.ts +0 -626
- package/codeAgent/agent/CodeAgentAllowed.ts +0 -35
- package/codeAgent/agent/CodeAgentAsks.ts +0 -66
- package/codeAgent/agent/CodeAgentCommandLine.ts +0 -372
- package/codeAgent/agent/CodeAgentEventMapper.ts +0 -225
- package/codeAgent/agent/CodeAgentGate.ts +0 -258
- package/codeAgent/agent/CodeAgentProxy.ts +0 -83
- package/codeAgent/agent/CodeAgentRpcHost.ts +0 -109
- package/codeAgent/agent/CodeAgentRpcListener.ts +0 -195
- package/codeAgent/agent/CodeAgentStreamPrinter.ts +0 -86
- package/codeAgent/agent/CodeAgentSuspended.ts +0 -85
- package/codeAgent/agent/CodeAgentUi.ts +0 -47
- package/codeAgent/agent/CodeMailbox.ts +0 -148
- package/codeAgent/agent/CodeSessionFork.ts +0 -56
- package/codeAgent/agent/CodeSessionIndex.ts +0 -78
- package/codeAgent/agent/SubagentPool.ts +0 -219
- package/codeAgent/agent/WorkspaceTrust.ts +0 -200
- package/codeAgent/agent/akanCodeCompaction.test.ts +0 -36
- package/codeAgent/agent/akanCodeModel.ts +0 -47
- package/codeAgent/agent/akanCodeServices.test.ts +0 -54
- package/codeAgent/agent/akanContextFiles.test.ts +0 -116
- package/codeAgent/agent/akanSystemPrompt.ts +0 -50
- package/codeAgent/agent/codeAgent.test.ts +0 -337
- package/codeAgent/agent/codeAgentCommandLine.test.ts +0 -212
- package/codeAgent/agent/codeAgentContract.test.ts +0 -755
- package/codeAgent/agent/codeAgentHosts.ts +0 -30
- package/codeAgent/agent/codeAgentProxy.test.ts +0 -126
- package/codeAgent/agent/codeAgentRpcListener.test.ts +0 -215
- package/codeAgent/agent/codeAgentSuspended.test.ts +0 -47
- package/codeAgent/agent/codeMailbox.test.ts +0 -76
- package/codeAgent/agent/codeSessionFork.test.ts +0 -58
- package/codeAgent/agent/codeSessionIndex.test.ts +0 -77
- package/codeAgent/agent/consoleToStderr.ts +0 -8
- package/codeAgent/agent/jsonLines.ts +0 -29
- package/codeAgent/agent/stringArg.ts +0 -5
- package/codeAgent/feedback/DevLogFeedback.ts +0 -82
- package/codeAgent/feedback/PreviewFeedback.ts +0 -46
- package/codeAgent/feedback/TurnFeedback.ts +0 -98
- package/codeAgent/feedback/VerifyFeedback.ts +0 -39
- package/codeAgent/tools/AkanCli.ts +0 -51
- package/codeAgent/tools/AkanCodePlugins.ts +0 -142
- package/codeAgent/tools/AkanEditScope.ts +0 -53
- package/codeAgent/tools/AkanEnvKeys.ts +0 -50
- package/codeAgent/tools/AkanToolPack.ts +0 -86
- package/codeAgent/tools/AkanVerifier.ts +0 -30
- package/codeAgent/tools/AskToolPack.ts +0 -99
- package/codeAgent/tools/DeepSeekWeb.ts +0 -127
- package/codeAgent/tools/MailToolPack.ts +0 -76
- package/codeAgent/tools/McpClient.ts +0 -209
- package/codeAgent/tools/McpOAuth.ts +0 -233
- package/codeAgent/tools/McpOAuthLoopback.ts +0 -64
- package/codeAgent/tools/McpServerConfig.ts +0 -131
- package/codeAgent/tools/McpSignIn.ts +0 -158
- package/codeAgent/tools/McpTokenStore.ts +0 -128
- package/codeAgent/tools/McpToolPack.ts +0 -206
- package/codeAgent/tools/SessionToolPack.ts +0 -91
- package/codeAgent/tools/WebToolPack.ts +0 -315
- package/codeAgent/tools/akanCodePlugins.test.ts +0 -954
- package/codeAgent/tools/askToolPack.test.ts +0 -116
- package/codeAgent/tools/deepSeekWeb.test.ts +0 -113
- package/codeAgent/tools/mcpOAuth.test.ts +0 -648
- package/codeAgent/tools/mcpServerConfig.test.ts +0 -341
- package/piDependencyPins.test.ts +0 -45
|
@@ -77,6 +77,32 @@ export interface BundleClientEntriesResult {
|
|
|
77
77
|
externalsByChunkUrl: Map<string, string[]>;
|
|
78
78
|
/** Workspace-relative client reference id per absolute source entry. */
|
|
79
79
|
clientReferenceIdByAbsPath: Map<string, string>;
|
|
80
|
+
graph: ClientBundleGraph;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** What one bundle linked, by absolute path: no import the bundle left external. */
|
|
84
|
+
export interface ClientBundleGraph {
|
|
85
|
+
importsByModule: Map<string, ClientModuleImport[]>;
|
|
86
|
+
chunksByModule: Map<string, string[]>;
|
|
87
|
+
/** Static imports only: a chunk loaded by `import()` runs after the chunk asking for it. */
|
|
88
|
+
importsByChunk: Map<string, string[]>;
|
|
89
|
+
/** What the bundler placed on its own: a file taken apart by export is several, held together in the maps above. */
|
|
90
|
+
linked?: ClientLinkedInput[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** By client entry, the export names asked of it; null for all of them. */
|
|
94
|
+
export type AskedExports = ReadonlyMap<string, readonly string[] | null>;
|
|
95
|
+
|
|
96
|
+
export interface ClientLinkedInput {
|
|
97
|
+
module: string;
|
|
98
|
+
imports: ClientModuleImport[];
|
|
99
|
+
chunks: string[];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface ClientModuleImport {
|
|
103
|
+
path: string;
|
|
104
|
+
/** Asked for by `import()`, so it loads when that call runs. */
|
|
105
|
+
lazy: boolean;
|
|
80
106
|
}
|
|
81
107
|
|
|
82
108
|
export type AkanConfig = Awaited<ReturnType<App["getConfig"]>>;
|
|
@@ -80,3 +80,82 @@ describe("ClientEntriesBundler", () => {
|
|
|
80
80
|
expect(await bundle("start")).toContain("switch-build");
|
|
81
81
|
});
|
|
82
82
|
});
|
|
83
|
+
|
|
84
|
+
describe("ClientEntriesBundler worker chunks", () => {
|
|
85
|
+
const drawApp = async () => {
|
|
86
|
+
const root = await realpath(await makeTempRoot());
|
|
87
|
+
const lib = (file: string, source: string) => writeText(path.join(root, "node_modules/drawlib", file), source);
|
|
88
|
+
await lib("package.json", '{ "name": "drawlib", "type": "module", "exports": "./index.js" }\n');
|
|
89
|
+
await lib("shared.js", "export const scale = (value) => value * 2;\n");
|
|
90
|
+
await lib(
|
|
91
|
+
"index.js",
|
|
92
|
+
[
|
|
93
|
+
'import { useState } from "react";',
|
|
94
|
+
'import { scale } from "./shared.js";',
|
|
95
|
+
"const ratio = window.devicePixelRatio;",
|
|
96
|
+
"export const useRatio = () => useState(scale(ratio));",
|
|
97
|
+
'export const loadWorker = () => import("./worker.js");',
|
|
98
|
+
'export const loadLazy = () => import("./lazy.js");',
|
|
99
|
+
"",
|
|
100
|
+
].join("\n"),
|
|
101
|
+
);
|
|
102
|
+
await lib(
|
|
103
|
+
"worker.js",
|
|
104
|
+
[
|
|
105
|
+
'import { scale } from "./shared.js";',
|
|
106
|
+
"export const WorkerUrl = new URL(import.meta.url);",
|
|
107
|
+
'if (typeof window === "undefined") self.onmessage = (event) => self.postMessage(scale(event.data));',
|
|
108
|
+
"",
|
|
109
|
+
].join("\n"),
|
|
110
|
+
);
|
|
111
|
+
await lib(
|
|
112
|
+
"lazy.js",
|
|
113
|
+
'import { scale } from "./shared.js";\nexport const own = new URL(import.meta.url);\nexport const big = scale(4);\n',
|
|
114
|
+
);
|
|
115
|
+
const entry = path.join(root, "Draw.tsx");
|
|
116
|
+
await writeText(
|
|
117
|
+
entry,
|
|
118
|
+
'"use client";\nimport { loadLazy, loadWorker, useRatio } from "drawlib";\nexport const Draw = () => [useRatio, loadLazy, loadWorker];\n',
|
|
119
|
+
);
|
|
120
|
+
const app = {
|
|
121
|
+
name: "probe",
|
|
122
|
+
cwdPath: path.join(root, "app"),
|
|
123
|
+
dist: { cwdPath: path.join(root, "dist") },
|
|
124
|
+
workspace: { workspaceRoot: root },
|
|
125
|
+
getConfig: async () => ({ optimizeImports: [] }),
|
|
126
|
+
getPublicEnv: () => ({}),
|
|
127
|
+
};
|
|
128
|
+
const result = await new ClientEntriesBundler({
|
|
129
|
+
app: app as never,
|
|
130
|
+
entries: [entry],
|
|
131
|
+
command: "build",
|
|
132
|
+
external: ["react"],
|
|
133
|
+
}).bundle();
|
|
134
|
+
const outdir = path.join(root, "dist/.akan/artifact/client");
|
|
135
|
+
const chunks = await Promise.all(
|
|
136
|
+
[...new Bun.Glob("chunks/*.js").scanSync(outdir)].map(async (file) => ({
|
|
137
|
+
file: path.join(outdir, file),
|
|
138
|
+
text: await Bun.file(path.join(outdir, file)).text(),
|
|
139
|
+
})),
|
|
140
|
+
);
|
|
141
|
+
return { result, chunks };
|
|
142
|
+
};
|
|
143
|
+
const staticImportsOf = (text: string) =>
|
|
144
|
+
[...text.matchAll(/(?:\bfrom|\bimport)\s*["']([^"']+)["']/g)].map((m) => m[1]);
|
|
145
|
+
|
|
146
|
+
test("rebuilds a module that hands its own URL to a worker into its chunk alone, so a worker can load it", async () => {
|
|
147
|
+
const { result, chunks } = await drawApp();
|
|
148
|
+
const worker = chunks.find((chunk) => chunk.text.includes("onmessage"));
|
|
149
|
+
expect(worker && staticImportsOf(worker.text)).toEqual([]);
|
|
150
|
+
expect(result.graph.importsByChunk.get(worker?.file ?? "")).toEqual([]);
|
|
151
|
+
const loaded = (await import(worker?.file ?? "")) as { WorkerUrl: URL };
|
|
152
|
+
expect(loaded.WorkerUrl.href).toEndWith(path.basename(worker?.file ?? ""));
|
|
153
|
+
expect(typeof (globalThis as { onmessage?: unknown }).onmessage).toBe("function");
|
|
154
|
+
}, 30_000);
|
|
155
|
+
|
|
156
|
+
test("leaves a lazy chunk that only reads its own URL sharing what the page loaded", async () => {
|
|
157
|
+
const { chunks } = await drawApp();
|
|
158
|
+
const lazy = chunks.find((chunk) => chunk.text.includes("own"));
|
|
159
|
+
expect(lazy && staticImportsOf(lazy.text).length).toBeGreaterThan(0);
|
|
160
|
+
}, 30_000);
|
|
161
|
+
});
|
|
@@ -2,18 +2,23 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import type { SsrManifest, SsrManifestEntry } from "akanjs/server";
|
|
4
4
|
import type { BunPlugin } from "bun";
|
|
5
|
+
import { ModuleParts } from "../transforms/moduleParts";
|
|
5
6
|
import { scanUseClientExports, toClientReferencePath } from "../transforms/rscUseClientTransform";
|
|
6
7
|
import { bundleConditions, bundleDefine } from "./bundleDefine";
|
|
7
8
|
import {
|
|
8
9
|
type BundleClientEntriesInternalOptions,
|
|
9
10
|
type BundleClientEntriesResult,
|
|
10
11
|
CLIENT_BUNDLE_NAMING,
|
|
12
|
+
type ClientBundleGraph,
|
|
11
13
|
type ClientBundleTarget,
|
|
14
|
+
type ClientLinkedInput,
|
|
12
15
|
type ClientManifest,
|
|
16
|
+
type ClientModuleImport,
|
|
13
17
|
type MetafileInput,
|
|
14
18
|
type MetafileOutput,
|
|
15
19
|
type OpaqueEntryAliases,
|
|
16
20
|
} from "./clientBuildTypes";
|
|
21
|
+
import { WorkerChunks } from "./workerChunks";
|
|
17
22
|
|
|
18
23
|
export class ClientEntriesBundler {
|
|
19
24
|
#app: BundleClientEntriesInternalOptions["app"];
|
|
@@ -88,6 +93,7 @@ export class ClientEntriesBundler {
|
|
|
88
93
|
Object.entries(metafile.outputs).map(([k, v]) => [this.#absFromOutdir(k), v as MetafileOutput]),
|
|
89
94
|
);
|
|
90
95
|
this.#metafileInputs = metafile.inputs as Record<string, MetafileInput>;
|
|
96
|
+
if (this.#target === "browser") await this.#sealWorkerChunks();
|
|
91
97
|
|
|
92
98
|
for (const artifact of result.outputs.filter((a) => a.kind === "entry-point"))
|
|
93
99
|
this.#addEntryArtifact(artifact.path);
|
|
@@ -102,9 +108,70 @@ export class ClientEntriesBundler {
|
|
|
102
108
|
entryChunkUrlsByAbsPath: this.#entryChunkUrlsByAbsPath,
|
|
103
109
|
externalsByChunkUrl: this.#collectExternalsByChunkUrl(),
|
|
104
110
|
clientReferenceIdByAbsPath: this.#clientReferenceIdByAbsPath,
|
|
111
|
+
graph: this.#graph(),
|
|
105
112
|
};
|
|
106
113
|
}
|
|
107
114
|
|
|
115
|
+
async #sealWorkerChunks(): Promise<void> {
|
|
116
|
+
const entries = new Set(this.#opaqueEntries?.entries.map((entry) => path.resolve(entry)));
|
|
117
|
+
const sealed = await WorkerChunks.seal(
|
|
118
|
+
this.#metafileOutputsByAbs,
|
|
119
|
+
entries,
|
|
120
|
+
(entryPoint) => this.#absFromEntryPoint(entryPoint),
|
|
121
|
+
{
|
|
122
|
+
outdir: this.#outdir,
|
|
123
|
+
define: bundleDefine(this.#app, this.#command, "ssr"),
|
|
124
|
+
conditions: bundleConditions(this.#command),
|
|
125
|
+
minify: this.#command === "build",
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
for (const chunk of sealed) {
|
|
129
|
+
const info = this.#metafileOutputsByAbs.get(chunk);
|
|
130
|
+
if (info) this.#metafileOutputsByAbs.set(chunk, { ...info, imports: [] });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#graph(): ClientBundleGraph {
|
|
135
|
+
const absByInput = new Map<string, string>();
|
|
136
|
+
const absOf = (input: string) => {
|
|
137
|
+
const known = absByInput.get(input);
|
|
138
|
+
if (known) return known;
|
|
139
|
+
const abs = this.#absFromEntryPoint(input);
|
|
140
|
+
absByInput.set(input, abs);
|
|
141
|
+
return abs;
|
|
142
|
+
};
|
|
143
|
+
const importsByModule = new Map<string, ClientModuleImport[]>();
|
|
144
|
+
const linkedByInput = new Map<string, ClientLinkedInput>();
|
|
145
|
+
for (const [input, { imports = [] }] of Object.entries(this.#metafileInputs)) {
|
|
146
|
+
const module = absOf(input);
|
|
147
|
+
const own = imports
|
|
148
|
+
.filter((imported) => !imported.external)
|
|
149
|
+
.map((imported) => ({ path: absOf(imported.path), lazy: imported.kind === "dynamic-import" }))
|
|
150
|
+
.filter((imported) => imported.path !== module);
|
|
151
|
+
linkedByInput.set(input, { module, imports: own, chunks: [] });
|
|
152
|
+
const held = importsByModule.getOrInsert(module, []);
|
|
153
|
+
for (const imported of own)
|
|
154
|
+
if (!held.some((known) => known.path === imported.path && known.lazy === imported.lazy)) held.push(imported);
|
|
155
|
+
}
|
|
156
|
+
const chunksByModule = new Map<string, string[]>();
|
|
157
|
+
const importsByChunk = new Map<string, string[]>();
|
|
158
|
+
for (const [chunk, info] of this.#metafileOutputsByAbs) {
|
|
159
|
+
if (!chunk.endsWith(".js")) continue;
|
|
160
|
+
for (const input of Object.keys(info.inputs ?? {})) {
|
|
161
|
+
const chunks = chunksByModule.getOrInsert(absOf(input), []);
|
|
162
|
+
if (!chunks.includes(chunk)) chunks.push(chunk);
|
|
163
|
+
linkedByInput.get(input)?.chunks.push(chunk);
|
|
164
|
+
}
|
|
165
|
+
importsByChunk.set(
|
|
166
|
+
chunk,
|
|
167
|
+
info.imports
|
|
168
|
+
.filter((imported) => imported.kind !== "dynamic-import" && imported.path.endsWith(".js"))
|
|
169
|
+
.map((imported) => this.#absFromOutdir(imported.path)),
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
return { importsByModule, chunksByModule, importsByChunk, linked: [...linkedByInput.values()] };
|
|
173
|
+
}
|
|
174
|
+
|
|
108
175
|
async #createOpaqueEntryAliases(): Promise<OpaqueEntryAliases> {
|
|
109
176
|
const aliasDir = path.join(this.#app.cwdPath, ".akan", "generated", "client-entry-alias", this.#outputSubdir);
|
|
110
177
|
fs.mkdirSync(aliasDir, { recursive: true });
|
|
@@ -233,7 +300,9 @@ export class ClientEntriesBundler {
|
|
|
233
300
|
return path.isAbsolute(p) ? p : path.resolve(this.#outdir, p);
|
|
234
301
|
}
|
|
235
302
|
|
|
236
|
-
|
|
303
|
+
//? A file taken apart by export is linked as several inputs, each named by the file's path and its part.
|
|
304
|
+
#absFromEntryPoint(input: string): string {
|
|
305
|
+
const p = input.replace(ModuleParts.specifier, "");
|
|
237
306
|
if (path.isAbsolute(p)) return path.resolve(p);
|
|
238
307
|
const candidates = [path.resolve(process.cwd(), p), path.resolve(this.#app.cwdPath, p)];
|
|
239
308
|
return candidates.find((candidate) => fs.existsSync(candidate)) ?? candidates[0];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { afterAll, describe, expect, test } from "bun:test";
|
|
2
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
+
import { mkdtemp, realpath, rm } from "node:fs/promises";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { createTsconfigPackageResolver } from "../transforms/barrelImportsPlugin";
|
|
@@ -189,4 +189,311 @@ describe("GraphClientEntryDiscovery", () => {
|
|
|
189
189
|
fresh.invalidate([file("Server.tsx")]);
|
|
190
190
|
expect(await fresh.discover([file("Page.tsx")], { importsAs })).toEqual([]);
|
|
191
191
|
});
|
|
192
|
+
|
|
193
|
+
test("the server modules of a walk are every file it reads before a client entry, with the same imports swapped or dropped", async () => {
|
|
194
|
+
const file = await tempDir();
|
|
195
|
+
await Bun.write(file("Page.tsx"), 'import "./Layout";\nimport "./Card";\n');
|
|
196
|
+
await Bun.write(file("Layout.tsx"), 'import "./Registry";\nimport "./Helper";\n');
|
|
197
|
+
await Bun.write(file("Helper.ts"), 'import "./Page";\nexport const helper = 1;\n');
|
|
198
|
+
await Bun.write(file("Registry.ts"), 'import "./Reference";\n');
|
|
199
|
+
await Bun.write(file("Reference.ts"), '"use client";\nexport const reference = "memo";\n');
|
|
200
|
+
await Bun.write(file("Card.tsx"), '"use client";\nimport "./Inner";\nexport const Card = () => null;\n');
|
|
201
|
+
await Bun.write(file("Inner.ts"), "export const inner = 1;\n");
|
|
202
|
+
const discovery = new GraphClientEntryDiscovery({ barrelImports: [] }, (async () => null) as never);
|
|
203
|
+
const names = (files: string[]) => files.map((each) => path.basename(each));
|
|
204
|
+
|
|
205
|
+
expect(names(await discovery.serverModules([file("Page.tsx")]))).toEqual([
|
|
206
|
+
"Helper.ts",
|
|
207
|
+
"Layout.tsx",
|
|
208
|
+
"Page.tsx",
|
|
209
|
+
"Registry.ts",
|
|
210
|
+
]);
|
|
211
|
+
const dropped = new Map([[file("Layout.tsx"), new Map([["./Registry", null]])]]);
|
|
212
|
+
expect(names(await discovery.serverModules([file("Page.tsx")], { importsAs: dropped }))).toEqual([
|
|
213
|
+
"Helper.ts",
|
|
214
|
+
"Layout.tsx",
|
|
215
|
+
"Page.tsx",
|
|
216
|
+
]);
|
|
217
|
+
expect(names(await discovery.serverModules([file("Card.tsx")]))).toEqual([]);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("a client file exporting only hooks is no entry of a server graph that imports it, one with a component still is", async () => {
|
|
221
|
+
const file = await tempDir();
|
|
222
|
+
await Bun.write(file("Layout.tsx"), 'import "./store";\nimport "./Panel";\n');
|
|
223
|
+
await Bun.write(
|
|
224
|
+
file("store.ts"),
|
|
225
|
+
'import { useForm } from "./useForm";\nimport { useEffect } from "./reactHooks";\nimport "./useMixed";\nexport const st = { useForm, useEffect };\n',
|
|
226
|
+
);
|
|
227
|
+
await Bun.write(
|
|
228
|
+
file("useForm.ts"),
|
|
229
|
+
'"use client";\nimport "./Inner";\nexport interface FormShape {}\nexport const useForm = () => null;\nexport function useOther() {}\n',
|
|
230
|
+
);
|
|
231
|
+
await Bun.write(file("reactHooks.ts"), '"use client";\nexport { useContext, useEffect } from "react";\n');
|
|
232
|
+
await Bun.write(
|
|
233
|
+
file("useMixed.ts"),
|
|
234
|
+
'"use client";\nexport const useMixed = () => null;\nexport const Mixed = () => null;\n',
|
|
235
|
+
);
|
|
236
|
+
await Bun.write(file("Inner.tsx"), '"use client";\nexport const Inner = () => null;\n');
|
|
237
|
+
await Bun.write(
|
|
238
|
+
file("Panel.tsx"),
|
|
239
|
+
'"use client";\nimport { useForm } from "./useForm";\nexport const Panel = () => useForm();\n',
|
|
240
|
+
);
|
|
241
|
+
const discovery = new GraphClientEntryDiscovery({ barrelImports: [] }, (async () => null) as never);
|
|
242
|
+
expect(await discovery.discover([file("Layout.tsx")])).toEqual([file("Panel.tsx"), file("useMixed.ts")]);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test("a client file with a default export or a star re-export stays an entry", async () => {
|
|
246
|
+
const file = await tempDir();
|
|
247
|
+
await Bun.write(file("S.tsx"), 'import "./A";\nimport "./B";\nimport "./C";\n');
|
|
248
|
+
await Bun.write(file("A.ts"), '"use client";\nexport default function useA() {}\n');
|
|
249
|
+
await Bun.write(file("B.ts"), '"use client";\nexport * from "./C";\nexport const useB = () => null;\n');
|
|
250
|
+
await Bun.write(file("C.ts"), '"use client";\nexport const C = () => null;\n');
|
|
251
|
+
const discovery = new GraphClientEntryDiscovery({ barrelImports: [] }, (async () => null) as never);
|
|
252
|
+
expect(await discovery.discover([file("S.tsx")])).toEqual([file("A.ts"), file("B.ts"), file("C.ts")]);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test("a page writing out an object's part reaches only that part's file under a route runtime, until the object moves it", async () => {
|
|
256
|
+
const dir = await realpath(await mkdtemp(path.join(os.tmpdir(), "akan-discovery-")));
|
|
257
|
+
dirs.push(dir);
|
|
258
|
+
const file = (name: string) => path.join(dir, name);
|
|
259
|
+
await Bun.write(
|
|
260
|
+
file("lib/memo/index.ts"),
|
|
261
|
+
'import * as Template from "./Memo.Template";\nimport * as Zone from "./Memo.Zone";\nexport const Memo = { Template, Zone };\n',
|
|
262
|
+
);
|
|
263
|
+
for (const part of ["Template", "Zone", "Panel"])
|
|
264
|
+
await Bun.write(file(`lib/memo/Memo.${part}.tsx`), '"use client";\nexport const View = () => null;\n');
|
|
265
|
+
await Bun.write(
|
|
266
|
+
file("S.tsx"),
|
|
267
|
+
'import { Memo } from "./lib/memo";\nexport const Page = () => <Memo.Zone.View />;\n',
|
|
268
|
+
);
|
|
269
|
+
const discoveryOf = (options?: { packageRoot: string }) =>
|
|
270
|
+
new GraphClientEntryDiscovery({ barrelImports: [] }, (async () => null) as never, options);
|
|
271
|
+
const route = discoveryOf({ packageRoot: dir });
|
|
272
|
+
|
|
273
|
+
expect(await discoveryOf().discover([file("S.tsx")])).toEqual([
|
|
274
|
+
file("lib/memo/Memo.Template.tsx"),
|
|
275
|
+
file("lib/memo/Memo.Zone.tsx"),
|
|
276
|
+
]);
|
|
277
|
+
expect(await route.discover([file("S.tsx")])).toEqual([file("lib/memo/Memo.Zone.tsx")]);
|
|
278
|
+
|
|
279
|
+
await Bun.write(
|
|
280
|
+
file("lib/memo/index.ts"),
|
|
281
|
+
'import * as Template from "./Memo.Template";\nimport * as Zone from "./Memo.Panel";\nexport const Memo = { Template, Zone };\n',
|
|
282
|
+
);
|
|
283
|
+
route.invalidate([file("lib/memo/index.ts")]);
|
|
284
|
+
expect(await route.discover([file("S.tsx")])).toEqual([file("lib/memo/Memo.Panel.tsx")]);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe("read by export", () => {
|
|
288
|
+
const byExport = () =>
|
|
289
|
+
new GraphClientEntryDiscovery({ barrelImports: [] }, (async () => null) as never, { byExport: true });
|
|
290
|
+
const client = (name: string) => `"use client";\nexport const ${name} = () => null;\n`;
|
|
291
|
+
const writeView = async (file: (name: string) => string) => {
|
|
292
|
+
for (const name of ["Remove", "Chart", "Editor", "Panel", "Badge"])
|
|
293
|
+
await Bun.write(file(`ui/${name}.tsx`), client(name));
|
|
294
|
+
await Bun.write(
|
|
295
|
+
file("Memo.View.tsx"),
|
|
296
|
+
[
|
|
297
|
+
'import { Badge } from "./ui/Badge";',
|
|
298
|
+
'import { Chart } from "./ui/Chart";',
|
|
299
|
+
'import { Remove } from "./ui/Remove";',
|
|
300
|
+
"const Title = () => <Badge />;",
|
|
301
|
+
"export const General = () => [<Title />, <Remove />];",
|
|
302
|
+
"export const Stats = () => <Chart />;",
|
|
303
|
+
'export const Rich = async () => (await import("./ui/Editor")).Editor;',
|
|
304
|
+
"",
|
|
305
|
+
].join("\n"),
|
|
306
|
+
);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
test("a route reaches the client files of the export its page names, not of the whole server file", async () => {
|
|
310
|
+
const file = await tempDir();
|
|
311
|
+
await writeView(file);
|
|
312
|
+
await Bun.write(file("general.tsx"), 'import { General } from "./Memo.View";\nexport default General;\n');
|
|
313
|
+
await Bun.write(file("stats.tsx"), 'import { Stats as S } from "./Memo.View";\nexport default () => <S />;\n');
|
|
314
|
+
await Bun.write(file("rich.tsx"), 'import * as View from "./Memo.View";\nexport default View.Rich;\n');
|
|
315
|
+
await Bun.write(file("all.tsx"), 'import * as View from "./Memo.View";\nexport default () => View;\n');
|
|
316
|
+
const discovery = byExport();
|
|
317
|
+
const whole = ["Badge", "Chart", "Editor", "Remove"].map((name) => file(`ui/${name}.tsx`));
|
|
318
|
+
|
|
319
|
+
expect(await discovery.discover([file("general.tsx")])).toEqual(whole);
|
|
320
|
+
expect(await discovery.discoverRendered([file("general.tsx")])).toEqual([
|
|
321
|
+
file("ui/Badge.tsx"),
|
|
322
|
+
file("ui/Remove.tsx"),
|
|
323
|
+
]);
|
|
324
|
+
expect(await discovery.discoverRendered([file("stats.tsx")])).toEqual([file("ui/Chart.tsx")]);
|
|
325
|
+
expect(await discovery.discoverRendered([file("rich.tsx")])).toEqual([file("ui/Editor.tsx")]);
|
|
326
|
+
expect(await discovery.discoverRendered([file("all.tsx")])).toEqual(whole);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
test("each entry comes with the exports the route's server files ask of it, and with none named when one asks for the file", async () => {
|
|
330
|
+
const file = await tempDir();
|
|
331
|
+
const pair = file("ui/Pair.tsx");
|
|
332
|
+
await Bun.write(pair, `${client("A")}export const B = () => null;\nexport const C = () => null;\n`);
|
|
333
|
+
await Bun.write(file("a.tsx"), 'import { A } from "./ui/Pair";\nexport default () => <A />;\n');
|
|
334
|
+
await Bun.write(
|
|
335
|
+
file("ab.tsx"),
|
|
336
|
+
'import { A } from "./ui/Pair";\nimport { B as Bee } from "./ui/Pair";\nexport default () => [A, Bee];\n',
|
|
337
|
+
);
|
|
338
|
+
await Bun.write(file("all.tsx"), 'import * as Pair from "./ui/Pair";\nexport default () => Pair;\n');
|
|
339
|
+
const discovery = byExport();
|
|
340
|
+
|
|
341
|
+
expect(await discovery.discoverAsked([file("a.tsx")])).toEqual(new Map([[pair, ["A"]]]));
|
|
342
|
+
expect(await discovery.discoverAsked([file("ab.tsx")])).toEqual(new Map([[pair, ["A", "B"]]]));
|
|
343
|
+
expect(await discovery.discoverAsked([file("all.tsx")])).toEqual(new Map([[pair, null]]));
|
|
344
|
+
expect(await discovery.discoverAsked([file("a.tsx"), file("all.tsx")])).toEqual(new Map([[pair, null]]));
|
|
345
|
+
const whole = new GraphClientEntryDiscovery({ barrelImports: [] }, (async () => null) as never);
|
|
346
|
+
expect(await whole.discoverAsked([file("a.tsx")])).toEqual(new Map([[pair, null]]));
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
test("a second route asking the same export gets the same answer, and a saved file is read again", async () => {
|
|
350
|
+
const file = await tempDir();
|
|
351
|
+
await writeView(file);
|
|
352
|
+
await Bun.write(file("stats.tsx"), 'import { Stats } from "./Memo.View";\nexport default Stats;\n');
|
|
353
|
+
await Bun.write(file("board.tsx"), 'import { Stats } from "./Memo.View";\nexport default () => <Stats />;\n');
|
|
354
|
+
const discovery = byExport();
|
|
355
|
+
|
|
356
|
+
expect(await discovery.discoverRendered([file("stats.tsx")])).toEqual([file("ui/Chart.tsx")]);
|
|
357
|
+
expect(await discovery.discoverRendered([file("board.tsx")])).toEqual([file("ui/Chart.tsx")]);
|
|
358
|
+
|
|
359
|
+
await Bun.write(
|
|
360
|
+
file("Memo.View.tsx"),
|
|
361
|
+
'import { Panel } from "./ui/Panel";\nexport const Stats = () => <Panel />;\n',
|
|
362
|
+
);
|
|
363
|
+
discovery.invalidate([file("Memo.View.tsx")]);
|
|
364
|
+
expect(await discovery.discoverRendered([file("board.tsx")])).toEqual([file("ui/Panel.tsx")]);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test("without the setting, a route reaches what the whole server file imports", async () => {
|
|
368
|
+
const file = await tempDir();
|
|
369
|
+
await writeView(file);
|
|
370
|
+
await Bun.write(file("stats.tsx"), 'import { Stats } from "./Memo.View";\nexport default Stats;\n');
|
|
371
|
+
const discovery = new GraphClientEntryDiscovery({ barrelImports: [] }, (async () => null) as never);
|
|
372
|
+
|
|
373
|
+
expect(await discovery.discoverRendered([file("stats.tsx")])).toEqual(
|
|
374
|
+
["Badge", "Chart", "Editor", "Remove"].map((name) => file(`ui/${name}.tsx`)),
|
|
375
|
+
);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test("a client file registered by a top-level statement is reached by every route evaluating the module", async () => {
|
|
379
|
+
const file = await tempDir();
|
|
380
|
+
await writeView(file);
|
|
381
|
+
await Bun.write(file("registry.ts"), "export const parts: unknown[] = [];\n");
|
|
382
|
+
await Bun.write(
|
|
383
|
+
file("Memo.Zone.tsx"),
|
|
384
|
+
[
|
|
385
|
+
'import { parts } from "./registry";',
|
|
386
|
+
'import { Chart } from "./ui/Chart";',
|
|
387
|
+
'import { Panel } from "./ui/Panel";',
|
|
388
|
+
"parts.push(Panel);",
|
|
389
|
+
"export const Stats = () => <Chart />;",
|
|
390
|
+
"export const Plain = () => null;",
|
|
391
|
+
"",
|
|
392
|
+
].join("\n"),
|
|
393
|
+
);
|
|
394
|
+
await Bun.write(file("plain.tsx"), 'import { Plain } from "./Memo.Zone";\nexport default Plain;\n');
|
|
395
|
+
|
|
396
|
+
expect(await byExport().discoverRendered([file("plain.tsx")])).toEqual([file("ui/Panel.tsx")]);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
test("a name asked through `export *` is followed into the file that holds it, and an unknown name takes the whole file", async () => {
|
|
400
|
+
const file = await tempDir();
|
|
401
|
+
await writeView(file);
|
|
402
|
+
await Bun.write(file("index.ts"), 'export * from "./Memo.View";\nexport * from "./other";\n');
|
|
403
|
+
await Bun.write(file("other.tsx"), 'import { Panel } from "./ui/Panel";\nexport const Side = () => <Panel />;\n');
|
|
404
|
+
await Bun.write(
|
|
405
|
+
file("legacy.js"),
|
|
406
|
+
'const { Panel } = require("./ui/Panel");\nmodule.exports = { Old: Panel };\n',
|
|
407
|
+
);
|
|
408
|
+
await Bun.write(file("stats.tsx"), 'import { Stats } from "./index";\nexport default Stats;\n');
|
|
409
|
+
await Bun.write(file("old.tsx"), 'import { Old } from "./legacy";\nexport default Old;\n');
|
|
410
|
+
const discovery = byExport();
|
|
411
|
+
|
|
412
|
+
expect(await discovery.discoverRendered([file("stats.tsx")])).toEqual([file("ui/Chart.tsx")]);
|
|
413
|
+
expect(await discovery.discoverRendered([file("old.tsx")])).toEqual([file("ui/Panel.tsx")]);
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test("an import swapped or dropped for the walk is swapped or dropped by export too", async () => {
|
|
417
|
+
const file = await tempDir();
|
|
418
|
+
await writeView(file);
|
|
419
|
+
await Bun.write(
|
|
420
|
+
file("Shell.tsx"),
|
|
421
|
+
'import { Panel } from "./ui/Panel";\nexport const General = () => <Panel />;\n',
|
|
422
|
+
);
|
|
423
|
+
await Bun.write(
|
|
424
|
+
file("page.tsx"),
|
|
425
|
+
'import { General } from "./Memo.View";\nimport { Chart } from "./ui/Chart";\nexport default () => [<General />, <Chart />];\n',
|
|
426
|
+
);
|
|
427
|
+
const discovery = byExport();
|
|
428
|
+
const importsAs = new Map([
|
|
429
|
+
[
|
|
430
|
+
file("page.tsx"),
|
|
431
|
+
new Map<string, string | null>([
|
|
432
|
+
["./Memo.View", "./Shell"],
|
|
433
|
+
["./ui/Chart", null],
|
|
434
|
+
]),
|
|
435
|
+
],
|
|
436
|
+
]);
|
|
437
|
+
|
|
438
|
+
expect(await discovery.discoverRendered([file("page.tsx")], { importsAs })).toEqual([file("ui/Panel.tsx")]);
|
|
439
|
+
expect(await discovery.discoverRendered([file("page.tsx")])).toEqual(
|
|
440
|
+
["Badge", "Chart", "Remove"].map((name) => file(`ui/${name}.tsx`)),
|
|
441
|
+
);
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
test("a page naming a part of the object a wrapper copies in reaches that part's file and none of the wrapper's own, until the copied object or its barrel moves it", async () => {
|
|
446
|
+
const dir = await realpath(await mkdtemp(path.join(os.tmpdir(), "akan-discovery-")));
|
|
447
|
+
dirs.push(dir);
|
|
448
|
+
const file = (name: string) => path.join(dir, name);
|
|
449
|
+
const client = (name: string) => `"use client";\nexport const ${name} = () => null;\n`;
|
|
450
|
+
const fieldIndex = (text: string) =>
|
|
451
|
+
`import { Text } from "./${text}";\nexport const Field = Object.assign(() => null, { Text });\n`;
|
|
452
|
+
const wrapper = [
|
|
453
|
+
'import { memo } from "react";',
|
|
454
|
+
'import { Field as BaseField } from "@demo/ui";',
|
|
455
|
+
'import { Editor } from "./Editor";',
|
|
456
|
+
"const Rich = memo(() => <Editor />);",
|
|
457
|
+
"export const Field = Object.assign(() => null, BaseField, { Rich });",
|
|
458
|
+
].join("\n");
|
|
459
|
+
const pageOf = (wrap: string, member: string) =>
|
|
460
|
+
`import { Field } from "./wrap/${wrap}";\nexport const Page = () => <Field.${member} />;\n`;
|
|
461
|
+
await Bun.write(file("ui/index.ts"), 'export * from "./Field";\n');
|
|
462
|
+
await Bun.write(file("ui/Field/index.tsx"), fieldIndex("Text"));
|
|
463
|
+
await Bun.write(file("ui/FieldNext/index.tsx"), fieldIndex("TextLast"));
|
|
464
|
+
for (const text of ["Field/Text", "Field/TextNext", "FieldNext/TextLast"])
|
|
465
|
+
await Bun.write(file(`ui/${text}.tsx`), client("Text"));
|
|
466
|
+
await Bun.write(file("wrap/Field.tsx"), wrapper);
|
|
467
|
+
await Bun.write(file("wrap/ClientField.tsx"), `"use client";\n${wrapper}`);
|
|
468
|
+
await Bun.write(file("wrap/Editor.tsx"), client("Editor"));
|
|
469
|
+
await Bun.write(file("Text.tsx"), pageOf("Field", "Text"));
|
|
470
|
+
await Bun.write(file("Rich.tsx"), pageOf("Field", "Rich"));
|
|
471
|
+
await Bun.write(file("ClientText.tsx"), pageOf("ClientField", "Text"));
|
|
472
|
+
await Bun.write(file("ClientRich.tsx"), pageOf("ClientField", "Rich"));
|
|
473
|
+
const entries: Record<string, string> = {
|
|
474
|
+
"@demo/ui": "ui/index.ts",
|
|
475
|
+
"@demo/ui/Field": "ui/Field/index.tsx",
|
|
476
|
+
"@demo/ui/FieldNext": "ui/FieldNext/index.tsx",
|
|
477
|
+
};
|
|
478
|
+
const resolvePackage = async (pkgName: string) => {
|
|
479
|
+
const entry = entries[pkgName];
|
|
480
|
+
return entry ? { pkgName, entryFile: file(entry), pkgDir: file("ui") } : null;
|
|
481
|
+
};
|
|
482
|
+
const route = new GraphClientEntryDiscovery({ barrelImports: ["@demo/ui"] }, resolvePackage as never, {
|
|
483
|
+
packageRoot: dir,
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
expect(await route.discover([file("Text.tsx")])).toEqual([file("ui/Field/Text.tsx")]);
|
|
487
|
+
expect(await route.discover([file("Rich.tsx")])).toEqual([file("ui/Field/Text.tsx"), file("wrap/Editor.tsx")]);
|
|
488
|
+
expect(await route.discover([file("ClientText.tsx")])).toEqual([file("ui/Field/Text.tsx")]);
|
|
489
|
+
expect(await route.discover([file("ClientRich.tsx")])).toEqual([file("wrap/ClientField.tsx")]);
|
|
490
|
+
|
|
491
|
+
await Bun.write(file("ui/Field/index.tsx"), fieldIndex("TextNext"));
|
|
492
|
+
route.invalidate([file("ui/Field/index.tsx")]);
|
|
493
|
+
expect(await route.discover([file("Text.tsx")])).toEqual([file("ui/Field/TextNext.tsx")]);
|
|
494
|
+
|
|
495
|
+
await Bun.write(file("ui/index.ts"), 'export * from "./FieldNext";\n');
|
|
496
|
+
route.invalidate([file("ui/index.ts")]);
|
|
497
|
+
expect(await route.discover([file("Text.tsx")])).toEqual([file("ui/FieldNext/TextLast.tsx")]);
|
|
498
|
+
});
|
|
192
499
|
});
|