@akanjs/devkit 3.3.0-rc.9 → 4.0.0-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 +269 -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 +212 -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 +358 -5
- package/app/applicationBuildRunner.ts +221 -31
- 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 +4 -1
- 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 +8 -3
- 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/executors/appExecutor.ts +26 -12
- package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
- package/executors/clientRuntimeKeys.fixture.json +393 -0
- package/executors/clientRuntimeKeys.test.ts +1690 -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.ts +49 -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/devBarrelImports.test.ts +124 -0
- package/frontendBuild/devBarrelImports.ts +81 -21
- package/frontendBuild/devChangePlanner.ts +0 -1
- package/frontendBuild/devRegistryBundler.ts +4 -2
- package/frontendBuild/devRouteRuntime.test.ts +492 -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/pagesBundleBuilder.test.ts +84 -0
- package/frontendBuild/pagesBundleBuilder.ts +78 -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/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/devStability.integration.test.ts +46 -21
- 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 +162 -0
- package/lint/biomeCheck.ts +131 -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 +7 -5
- package/mobile/nativeApp.ts +2 -2
- package/mobile/nativeConfig.test.ts +17 -1
- package/mobile/nativeConfig.ts +11 -6
- 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 +25 -3
- package/quality/dictionaryKeys.test.ts +356 -0
- package/quality/dictionaryKeys.ts +488 -0
- 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 +84 -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 +134 -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 +54 -0
- package/transforms/modelReference.test.ts +196 -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 +633 -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 +187 -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 +835 -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 +208 -0
- package/transforms/secretEnvDeclaration.ts +213 -0
- package/transforms/secretEnvFile.test.ts +117 -0
- package/transforms/secretEnvFile.ts +113 -0
- package/transforms/secretEnvName.test.ts +54 -0
- package/transforms/secretEnvName.ts +29 -0
- package/transforms/secretEnvSource.test.ts +148 -0
- package/transforms/secretEnvSource.ts +166 -0
- package/transforms/serverEnvEvaluationError.ts +11 -0
- package/transforms/serverEnvPlugin.test.ts +2 -1
- package/transforms/serverEnvPlugin.ts +13 -0
- package/transforms/serverEnvProfile.test.ts +129 -2
- package/transforms/serverEnvProfile.ts +126 -40
- package/transforms/serverEnvSecrets.test.ts +292 -0
- package/transforms/signalDescriptors.test.ts +280 -0
- package/transforms/signalDescriptors.ts +227 -0
- package/transforms/thisFreeExports.ts +87 -0
- package/transforms/transforms.test.ts +177 -0
- 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 +49 -0
- package/typecheck/typeChecker.ts +9 -7
- package/typecheck/withheldDiagnostics.ts +41 -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"]>>;
|
|
@@ -2,14 +2,18 @@ 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,
|
|
@@ -102,9 +106,51 @@ export class ClientEntriesBundler {
|
|
|
102
106
|
entryChunkUrlsByAbsPath: this.#entryChunkUrlsByAbsPath,
|
|
103
107
|
externalsByChunkUrl: this.#collectExternalsByChunkUrl(),
|
|
104
108
|
clientReferenceIdByAbsPath: this.#clientReferenceIdByAbsPath,
|
|
109
|
+
graph: this.#graph(),
|
|
105
110
|
};
|
|
106
111
|
}
|
|
107
112
|
|
|
113
|
+
#graph(): ClientBundleGraph {
|
|
114
|
+
const absByInput = new Map<string, string>();
|
|
115
|
+
const absOf = (input: string) => {
|
|
116
|
+
const known = absByInput.get(input);
|
|
117
|
+
if (known) return known;
|
|
118
|
+
const abs = this.#absFromEntryPoint(input);
|
|
119
|
+
absByInput.set(input, abs);
|
|
120
|
+
return abs;
|
|
121
|
+
};
|
|
122
|
+
const importsByModule = new Map<string, ClientModuleImport[]>();
|
|
123
|
+
const linkedByInput = new Map<string, ClientLinkedInput>();
|
|
124
|
+
for (const [input, { imports = [] }] of Object.entries(this.#metafileInputs)) {
|
|
125
|
+
const module = absOf(input);
|
|
126
|
+
const own = imports
|
|
127
|
+
.filter((imported) => !imported.external)
|
|
128
|
+
.map((imported) => ({ path: absOf(imported.path), lazy: imported.kind === "dynamic-import" }))
|
|
129
|
+
.filter((imported) => imported.path !== module);
|
|
130
|
+
linkedByInput.set(input, { module, imports: own, chunks: [] });
|
|
131
|
+
const held = importsByModule.getOrInsert(module, []);
|
|
132
|
+
for (const imported of own)
|
|
133
|
+
if (!held.some((known) => known.path === imported.path && known.lazy === imported.lazy)) held.push(imported);
|
|
134
|
+
}
|
|
135
|
+
const chunksByModule = new Map<string, string[]>();
|
|
136
|
+
const importsByChunk = new Map<string, string[]>();
|
|
137
|
+
for (const [chunk, info] of this.#metafileOutputsByAbs) {
|
|
138
|
+
if (!chunk.endsWith(".js")) continue;
|
|
139
|
+
for (const input of Object.keys(info.inputs ?? {})) {
|
|
140
|
+
const chunks = chunksByModule.getOrInsert(absOf(input), []);
|
|
141
|
+
if (!chunks.includes(chunk)) chunks.push(chunk);
|
|
142
|
+
linkedByInput.get(input)?.chunks.push(chunk);
|
|
143
|
+
}
|
|
144
|
+
importsByChunk.set(
|
|
145
|
+
chunk,
|
|
146
|
+
info.imports
|
|
147
|
+
.filter((imported) => imported.kind !== "dynamic-import" && imported.path.endsWith(".js"))
|
|
148
|
+
.map((imported) => this.#absFromOutdir(imported.path)),
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return { importsByModule, chunksByModule, importsByChunk, linked: [...linkedByInput.values()] };
|
|
152
|
+
}
|
|
153
|
+
|
|
108
154
|
async #createOpaqueEntryAliases(): Promise<OpaqueEntryAliases> {
|
|
109
155
|
const aliasDir = path.join(this.#app.cwdPath, ".akan", "generated", "client-entry-alias", this.#outputSubdir);
|
|
110
156
|
fs.mkdirSync(aliasDir, { recursive: true });
|
|
@@ -233,7 +279,9 @@ export class ClientEntriesBundler {
|
|
|
233
279
|
return path.isAbsolute(p) ? p : path.resolve(this.#outdir, p);
|
|
234
280
|
}
|
|
235
281
|
|
|
236
|
-
|
|
282
|
+
//? A file taken apart by export is linked as several inputs, each named by the file's path and its part.
|
|
283
|
+
#absFromEntryPoint(input: string): string {
|
|
284
|
+
const p = input.replace(ModuleParts.specifier, "");
|
|
237
285
|
if (path.isAbsolute(p)) return path.resolve(p);
|
|
238
286
|
const candidates = [path.resolve(process.cwd(), p), path.resolve(this.#app.cwdPath, p)];
|
|
239
287
|
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
|
});
|
|
@@ -4,19 +4,21 @@ 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 { ExportReach } from "../transforms/exportReach";
|
|
8
|
+
import { ObjectMemberImports } from "../transforms/objectMemberImports";
|
|
7
9
|
import type { AkanConfig, ClientEntryDiscovery, DiscoverOptions, ScannedImport } from "./clientBuildTypes";
|
|
10
|
+
import { RenderedEntries, type RenderedFile } from "./renderedEntries";
|
|
8
11
|
|
|
9
12
|
const USE_CLIENT_RE = /^\s*(?:\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\/\s*|\/\/[^\n]*\n\s*)*["']use client["']/;
|
|
13
|
+
const EXPORT_STAR_RE = /^\s*export\s*\*/m;
|
|
14
|
+
const HOOK_NAME_RE = /^use[A-Z0-9]/;
|
|
10
15
|
const NODE_MODULES_RE = /[\\/]node_modules[\\/]/;
|
|
11
16
|
const AKANJS_NODE_MODULE_RE = /[\\/]node_modules[\\/]akanjs[\\/]/;
|
|
12
17
|
// Bun's scanImports also surfaces CSS and asset imports, none of which can be a client component.
|
|
13
18
|
const NON_SOURCE_EXT_RE = /\.(css|scss|sass|less|json|svg|png|jpe?g|webp|gif|avif|ico|woff2?|ttf|otf|mp3|mp4|wav)$/i;
|
|
14
19
|
type PackageResolver = Awaited<ReturnType<typeof createTsconfigPackageResolver>>;
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
isClientEntry: boolean;
|
|
18
|
-
imports: ScannedImport[];
|
|
19
|
-
}
|
|
21
|
+
type FileFacts = RenderedFile;
|
|
20
22
|
|
|
21
23
|
interface Lookup<T> {
|
|
22
24
|
epoch: number;
|
|
@@ -56,6 +58,8 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
56
58
|
#swappedEntriesCaches = new WeakMap<object, Map<string, Set<string>>>();
|
|
57
59
|
#readFiles = new Set<string>();
|
|
58
60
|
#barrelImporters = new Map<string, Set<string>>();
|
|
61
|
+
#objects: ObjectMemberImports | null;
|
|
62
|
+
#objectReaders = new Map<string, Set<string>>();
|
|
59
63
|
//? Barrels a save went beside, by the analysis before it: a save of any component re-reads its barrel, and only an
|
|
60
64
|
//? export that moved sends that barrel's importers back to the disk.
|
|
61
65
|
#reread = new Map<string, Promise<BarrelExportMap | null>>();
|
|
@@ -63,15 +67,38 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
63
67
|
//? Bumped by every invalidation: a walk that began before one computed from facts it may have read stale, so it
|
|
64
68
|
//? answers its caller but caches nothing (a registry check walks this instance beside the slow lane's route builds).
|
|
65
69
|
#epoch = 0;
|
|
70
|
+
#rendered: RenderedEntries | null;
|
|
66
71
|
|
|
67
|
-
constructor(
|
|
72
|
+
constructor(
|
|
73
|
+
akanConfig: Pick<AkanConfig, "barrelImports">,
|
|
74
|
+
resolvePackage: PackageResolver,
|
|
75
|
+
{ packageRoot, byExport = false }: { packageRoot?: string; byExport?: boolean } = {},
|
|
76
|
+
) {
|
|
68
77
|
this.#akanConfig = akanConfig;
|
|
69
78
|
this.#resolvePackage = resolvePackage;
|
|
70
|
-
this.#
|
|
79
|
+
this.#rendered = byExport
|
|
80
|
+
? new RenderedEntries({
|
|
81
|
+
fileOf: async (file) => (shouldSkipNodeModule(file) ? null : await this.#facts(file)),
|
|
82
|
+
resolve: async (spec, fromDir) =>
|
|
83
|
+
NON_SOURCE_EXT_RE.test(spec) ? null : await this.#resolveSpecifier(spec, fromDir),
|
|
84
|
+
epoch: () => this.#epoch,
|
|
85
|
+
})
|
|
86
|
+
: null;
|
|
87
|
+
this.#analyzer = new BarrelAnalyzer({ resolvePackage, ...(packageRoot ? { packageRoot } : {}) });
|
|
88
|
+
this.#objects = packageRoot
|
|
89
|
+
? new ObjectMemberImports({
|
|
90
|
+
resolve: ObjectMemberImports.resolverOf(resolvePackage),
|
|
91
|
+
barrels: { names: akanConfig.barrelImports, analyzer: this.#analyzer },
|
|
92
|
+
})
|
|
93
|
+
: null;
|
|
71
94
|
}
|
|
72
95
|
|
|
73
|
-
|
|
74
|
-
|
|
96
|
+
//? An app narrows as its bundles do, so discovery reaches the member files they load.
|
|
97
|
+
static async create(app: App, { byExport = false } = {}): Promise<GraphClientEntryDiscovery> {
|
|
98
|
+
return new GraphClientEntryDiscovery(await app.getConfig(), await createTsconfigPackageResolver(app), {
|
|
99
|
+
packageRoot: app.workspace.workspaceRoot,
|
|
100
|
+
byExport,
|
|
101
|
+
});
|
|
75
102
|
}
|
|
76
103
|
|
|
77
104
|
async discover(seeds: string[], { importsAs }: DiscoverOptions = {}): Promise<string[]> {
|
|
@@ -83,7 +110,49 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
83
110
|
const walk: DiscoveryWalk = { visiting: new Set(), partial: new Set(), memo: new Map(), importsAs, reachable };
|
|
84
111
|
for (const entry of await this.#discoverFromFile(seed, walk)) entries.add(entry);
|
|
85
112
|
}
|
|
86
|
-
return Array.from(entries).sort();
|
|
113
|
+
return Array.from(entries).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//? Without `byExport`, and never beyond it, this is what `discover` answers.
|
|
117
|
+
async discoverRendered(
|
|
118
|
+
seeds: string[],
|
|
119
|
+
{ importsAs, serverModules }: DiscoverOptions & { serverModules?: string[] } = {},
|
|
120
|
+
): Promise<string[]> {
|
|
121
|
+
return [...(await this.discoverAsked(seeds, { importsAs, serverModules })).keys()].sort();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//? The same entries, each with the export names asked of it: null for all of them.
|
|
125
|
+
async discoverAsked(
|
|
126
|
+
seeds: string[],
|
|
127
|
+
{ importsAs, serverModules }: DiscoverOptions & { serverModules?: string[] } = {},
|
|
128
|
+
): Promise<Map<string, string[] | null>> {
|
|
129
|
+
const within = await this.discover(seeds, { importsAs });
|
|
130
|
+
if (!this.#rendered) return new Map(within.map((entry) => [entry, null]));
|
|
131
|
+
return await this.#rendered.asked(seeds, {
|
|
132
|
+
serverModules: serverModules ?? (await this.serverModules(seeds, { importsAs })),
|
|
133
|
+
within,
|
|
134
|
+
importsAs,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async serverModules(seeds: string[], { importsAs }: DiscoverOptions = {}): Promise<string[]> {
|
|
139
|
+
const seen = new Set<string>();
|
|
140
|
+
const queue = seeds.map((seed) => path.resolve(seed));
|
|
141
|
+
for (const absPath of queue) {
|
|
142
|
+
if (seen.has(absPath) || shouldSkipNodeModule(absPath)) continue;
|
|
143
|
+
const facts = await this.#facts(absPath);
|
|
144
|
+
if (!facts || facts.isClientEntry) continue;
|
|
145
|
+
seen.add(absPath);
|
|
146
|
+
const swaps = importsAs?.get(absPath);
|
|
147
|
+
for (const imp of facts.imports) {
|
|
148
|
+
const swapped = swaps?.get(imp.path);
|
|
149
|
+
const spec = swapped === undefined ? imp.path : swapped;
|
|
150
|
+
if (!spec || NON_SOURCE_EXT_RE.test(spec)) continue;
|
|
151
|
+
const resolved = await this.#resolveSpecifier(spec, path.dirname(absPath));
|
|
152
|
+
if (resolved) queue.push(path.resolve(resolved));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return [...seen].sort();
|
|
87
156
|
}
|
|
88
157
|
|
|
89
158
|
async resolveImport(spec: string, importerDir: string): Promise<string | null> {
|
|
@@ -112,8 +181,10 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
112
181
|
// Reachable-entry results are transitive, so a changed child invalidates every ancestor.
|
|
113
182
|
this.#reachableEntriesCache.clear();
|
|
114
183
|
this.#swappedEntriesCaches = new WeakMap();
|
|
184
|
+
this.#rendered?.forget();
|
|
115
185
|
for (const [barrel, before] of this.#analyzer.forget(files))
|
|
116
186
|
if (!this.#reread.has(barrel)) this.#reread.set(barrel, before);
|
|
187
|
+
this.#forgetObjects(files);
|
|
117
188
|
//? A file gone, or one never read, can leave a found resolution on its old target (`Chart.tsx` to
|
|
118
189
|
//? `Chart/index.tsx`), so a move drops them all; a save of a file already read keeps them (a walk re-resolving
|
|
119
190
|
//? every package cost 3x). Misses lapse with the epoch on their own (#lookup).
|
|
@@ -123,6 +194,18 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
123
194
|
this.#resolvedSpecifierCache.clear();
|
|
124
195
|
}
|
|
125
196
|
|
|
197
|
+
//? An importer's facts hold the member files its object imports narrowed to: a save of the object module or of a
|
|
198
|
+
//? member file can move them.
|
|
199
|
+
#forgetObjects(files: string[]) {
|
|
200
|
+
if (!this.#objects) return;
|
|
201
|
+
this.#objects.modules.forget(files);
|
|
202
|
+
for (const file of files) {
|
|
203
|
+
const absPath = path.resolve(file);
|
|
204
|
+
for (const importer of this.#objectReaders.get(absPath) ?? []) this.#factsCache.delete(importer);
|
|
205
|
+
this.#objectReaders.delete(absPath);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
126
209
|
//? An importer's facts hold the files its barrel imports narrowed to, which an export moved between them changes.
|
|
127
210
|
async #dropRenarrowed(): Promise<void> {
|
|
128
211
|
const reread = [...this.#reread];
|
|
@@ -172,8 +255,12 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
172
255
|
.catch(() => null);
|
|
173
256
|
if (content === null) return null;
|
|
174
257
|
this.#readFiles.add(absPath);
|
|
175
|
-
if (USE_CLIENT_RE.test(content)) return { isClientEntry:
|
|
176
|
-
|
|
258
|
+
if (USE_CLIENT_RE.test(content)) return { isClientEntry: !this.#exportsOnlyHooks(content), imports: [] };
|
|
259
|
+
const rewritten = await this.#rewrite(content, absPath);
|
|
260
|
+
const imports = this.#scanImports(rewritten);
|
|
261
|
+
return this.#rendered
|
|
262
|
+
? { isClientEntry: false, imports, reach: ExportReach.read(rewritten, absPath) }
|
|
263
|
+
: { isClientEntry: false, imports };
|
|
177
264
|
})();
|
|
178
265
|
this.#factsCache.set(absPath, cached);
|
|
179
266
|
}
|
|
@@ -181,16 +268,51 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
181
268
|
}
|
|
182
269
|
|
|
183
270
|
async #rewrite(content: string, absPath: string): Promise<string> {
|
|
271
|
+
const rewritten = await this.#rewriteBarrels(content, absPath);
|
|
272
|
+
return (await this.#narrowObjects(rewritten, absPath)) ?? rewritten;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async #rewriteBarrels(content: string, absPath: string): Promise<string> {
|
|
184
276
|
if (this.#akanConfig.barrelImports.length === 0) return content;
|
|
185
277
|
for (const barrel of this.#akanConfig.barrelImports.filter((barrel) => content.includes(barrel)))
|
|
186
278
|
this.#barrelImporters.set(barrel, (this.#barrelImporters.get(barrel) ?? new Set()).add(absPath));
|
|
187
279
|
try {
|
|
188
|
-
|
|
280
|
+
const reexports = this.#objects !== null;
|
|
281
|
+
return (
|
|
282
|
+
(await rewriteBarrelImports(content, this.#akanConfig.barrelImports, this.#analyzer, { reexports })) ?? content
|
|
283
|
+
);
|
|
189
284
|
} catch {
|
|
190
285
|
return content;
|
|
191
286
|
}
|
|
192
287
|
}
|
|
193
288
|
|
|
289
|
+
async #narrowObjects(content: string, absPath: string): Promise<string | null> {
|
|
290
|
+
if (!this.#objects) return null;
|
|
291
|
+
try {
|
|
292
|
+
const narrowed = await this.#objects.rewrite(content, absPath);
|
|
293
|
+
for (const file of narrowed?.read ?? []) {
|
|
294
|
+
const absFile = path.resolve(file);
|
|
295
|
+
this.#objectReaders.set(absFile, (this.#objectReaders.get(absFile) ?? new Set()).add(absPath));
|
|
296
|
+
}
|
|
297
|
+
for (const barrel of narrowed?.barrels ?? [])
|
|
298
|
+
this.#barrelImporters.set(barrel, (this.#barrelImporters.get(barrel) ?? new Set()).add(absPath));
|
|
299
|
+
return narrowed?.contents ?? null;
|
|
300
|
+
} catch {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
//? A hook is never rendered, so no flight row names its file; `export *` hides names from the scan, so it stays an entry.
|
|
306
|
+
#exportsOnlyHooks(content: string): boolean {
|
|
307
|
+
if (EXPORT_STAR_RE.test(content)) return false;
|
|
308
|
+
try {
|
|
309
|
+
const { exports } = this.#tsTranspiler.scan(content);
|
|
310
|
+
return exports.length > 0 && exports.every((name) => HOOK_NAME_RE.test(name));
|
|
311
|
+
} catch {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
194
316
|
#scanImports(source: string): ScannedImport[] {
|
|
195
317
|
try {
|
|
196
318
|
return this.#tsTranspiler.scanImports(source);
|