@akanjs/devkit 3.3.0-rc.4 → 3.3.0-rc.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +618 -0
- package/DEV_RUNTIME_KNOBS.md +1 -1
- package/README.ko.md +3 -2
- package/README.md +3 -3
- package/akanApp/akanApp.host.test.ts +1 -1
- package/akanApp/akanApp.host.ts +11 -0
- package/akanConfig/akanBin.ts +4 -0
- package/akanConfig/akanConfig.test.ts +66 -7
- package/akanConfig/akanConfig.ts +53 -204
- package/akanConfig/akanWorkers.test.ts +39 -0
- package/akanConfig/akanWorkers.ts +32 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +37 -0
- package/akanConfig/nativeKeys.ts +52 -0
- package/akanConfig/types.ts +1 -0
- package/app/appBin.test.ts +63 -0
- package/app/appBin.ts +50 -0
- package/app/applicationBuildReporter.test.ts +32 -0
- package/app/applicationBuildReporter.ts +4 -0
- package/app/applicationBuildRunner.test.ts +275 -0
- package/app/applicationBuildRunner.ts +133 -6
- package/app/dictionarySizes.ts +91 -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 +6 -4
- package/codeAgent/agent/CodeAgent.ts +36 -16
- package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
- package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
- package/codeAgent/agent/CodeAgentGate.ts +23 -4
- package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +62 -0
- package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
- package/codeAgent/agent/codeAgentContract.test.ts +117 -5
- package/codeAgent/skills/akan-agent/SKILL.md +8 -1
- package/codeAgent/skills/akan-code/SKILL.md +38 -3
- package/codeAgent/skills/akan-deps/SKILL.md +3 -2
- 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 +31 -20
- package/codeAgent/skills/akan-query/SKILL.md +13 -20
- package/codeAgent/skills/akan-runtime/SKILL.md +20 -0
- package/codeAgent/skills/akan-service/SKILL.md +2 -5
- package/codeAgent/skills/akan-transport/SKILL.md +5 -14
- package/codeAgent/skills/akan-ui/SKILL.md +2 -5
- package/context/akanContext.ts +2 -0
- package/docs/apiReference.test.ts +9 -0
- package/docs/apiReference.ts +14 -0
- package/executors/appExecutor.ts +3 -1
- package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
- package/executors/clientRuntimeKeys.fixture.json +393 -0
- package/executors/clientRuntimeKeys.test.ts +1690 -0
- package/executors/executors.test.ts +2 -0
- package/executors/sysExecutor.ts +70 -4
- package/executors/workspaceExecutor.ts +7 -4
- package/frontendBuild/allRoutesBuilder.ts +88 -7
- package/frontendBuild/autoImportSync.ts +3 -2
- package/frontendBuild/buildRouteClient.test.ts +580 -12
- package/frontendBuild/clientBuildTypes.ts +26 -0
- package/frontendBuild/clientEntriesBundler.ts +49 -1
- package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
- package/frontendBuild/clientEntryDiscovery.ts +135 -13
- package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
- package/frontendBuild/csrDevModuleCompiler.ts +44 -8
- package/frontendBuild/csrDevPatcher.ts +33 -7
- package/frontendBuild/csrDevTypes.ts +9 -0
- package/frontendBuild/devBarrelImports.test.ts +154 -0
- package/frontendBuild/devBarrelImports.ts +83 -23
- package/frontendBuild/devRegistryBundler.ts +4 -2
- package/frontendBuild/devRouteRuntime.test.ts +492 -0
- package/frontendBuild/devRouteRuntime.ts +167 -0
- package/frontendBuild/dictionaryAssetBuilder.test.ts +324 -0
- package/frontendBuild/dictionaryAssetBuilder.ts +165 -16
- package/frontendBuild/dictionaryConstants.ts +136 -0
- package/frontendBuild/dictionaryPacking.test.ts +142 -0
- package/frontendBuild/dictionaryPacking.ts +135 -0
- package/frontendBuild/dictionaryRoutes.test.ts +251 -0
- package/frontendBuild/dictionaryRoutes.ts +227 -0
- package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
- package/frontendBuild/pagesBundleBuilder.ts +81 -3
- package/frontendBuild/precompressArtifacts.test.ts +22 -0
- package/frontendBuild/precompressArtifacts.ts +22 -8
- package/frontendBuild/registryMetadataFingerprint.ts +3 -3
- package/frontendBuild/renderedEntries.ts +144 -0
- package/frontendBuild/routeClientBuilder.ts +340 -29
- 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/rscServerRendererGuard.test.ts +60 -0
- package/frontendBuild/rscServerRendererGuard.ts +68 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +24 -34
- 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.ts +28 -0
- package/frontendBuild/vendorSpecifiers.ts +2 -0
- package/incrementalBuilder/buildBatch.proc.ts +9 -9
- package/incrementalBuilder/buildBatchProtocol.ts +1 -1
- package/incrementalBuilder/builderBoot.ts +5 -5
- package/incrementalBuilder/builderGraphPayloads.ts +4 -4
- package/incrementalBuilder/builderLanes.ts +2 -2
- package/incrementalBuilder/builderWatch.ts +8 -8
- package/incrementalBuilder/csrRegistry.ts +4 -4
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +79 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +27 -8
- package/incrementalBuilder/ssrRegistry.ts +6 -6
- package/index.ts +1 -1
- package/integration/renderAdmissionSoak.test.ts +99 -0
- package/integration/renderAdmissionSoak.ts +609 -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 +23 -3
- package/lint/biomeCheck.test.ts +145 -0
- package/lint/biomeCheck.ts +131 -0
- 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.ts +1 -0
- package/mobile/nativeApp.test.ts +7 -5
- package/mobile/nativeApp.ts +2 -2
- package/mobile/nativeConfig.test.ts +96 -1
- package/mobile/nativeConfig.ts +46 -12
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +15 -169
- package/packageExports.test.ts +38 -24
- 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/secretEnvFixture.ts +134 -0
- package/test/testHelpers.ts +11 -0
- package/transforms/barrelAnalyzer.ts +26 -4
- 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 +629 -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 +115 -2
- package/transforms/serverEnvProfile.ts +117 -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 +180 -3
- package/transforms/tsconfigPackageResolver.test.ts +1 -0
- package/tunnel/createTunnel.test.ts +29 -8
- package/tunnel/createTunnel.ts +18 -11
- package/typecheck/projectTypecheck.test.ts +29 -0
- package/typecheck/typeChecker.test.ts +49 -0
- package/typecheck/typeChecker.ts +9 -7
- package/typecheck/withheldDiagnostics.ts +41 -0
- package/util/fileEditor.ts +1 -0
- package/util/selectModel.ts +1 -0
- 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/getRelatedCnsts.ts +7 -0
- package/workspace/scanInfo.test.ts +39 -0
- package/workspace/scanInfo.ts +48 -5
- package/workspace/workspaceLayout.ts +1 -0
|
@@ -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[]> {
|
|
@@ -86,6 +113,48 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
86
113
|
return Array.from(entries).sort();
|
|
87
114
|
}
|
|
88
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();
|
|
156
|
+
}
|
|
157
|
+
|
|
89
158
|
async resolveImport(spec: string, importerDir: string): Promise<string | null> {
|
|
90
159
|
const resolved = await this.#resolveSpecifier(spec, importerDir);
|
|
91
160
|
return resolved ? path.resolve(resolved) : 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);
|
|
@@ -226,8 +348,8 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
226
348
|
this.#resolvedSpecifierCache,
|
|
227
349
|
cacheKey,
|
|
228
350
|
async () => {
|
|
229
|
-
if (spec.startsWith(".") ||
|
|
230
|
-
const abs =
|
|
351
|
+
if (spec.startsWith(".") || path.isAbsolute(spec)) {
|
|
352
|
+
const abs = path.resolve(importerDir, spec);
|
|
231
353
|
return await this.#resolveFileCandidate(abs);
|
|
232
354
|
}
|
|
233
355
|
const pkg = await this.#resolvePackage(spec);
|
|
@@ -3,6 +3,7 @@ import { mkdtemp, rm } from "node:fs/promises";
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import type { App } from "../commandDecorators";
|
|
6
|
+
import { printedInOwnProcess, tempDirs } from "../test/testHelpers";
|
|
6
7
|
import { CsrDevModuleCompiler } from "./csrDevModuleCompiler";
|
|
7
8
|
import { CsrDevPaths } from "./csrDevPaths";
|
|
8
9
|
import { CsrDevResolver } from "./csrDevResolver";
|
|
@@ -189,6 +190,28 @@ describe("CsrDevModuleCompiler", () => {
|
|
|
189
190
|
await rm(root, { recursive: true, force: true });
|
|
190
191
|
});
|
|
191
192
|
|
|
193
|
+
test("answers the model runtime marker with the context's source, in an installed package and in app code", async () => {
|
|
194
|
+
const markers = ["node_modules/akanjs/ui/modelRuntime.ts", "pkgs/akanjs/ui/modelRuntime.ts"].map(file);
|
|
195
|
+
for (const marker of markers) await Bun.write(marker, "export {};\n");
|
|
196
|
+
await Bun.write(file("apps/demo/lib/st.ts"), 'export const st = "store";\n');
|
|
197
|
+
const paths = new CsrDevPaths(root);
|
|
198
|
+
const modelRuntime = `import ${JSON.stringify(file("apps/demo/lib/st.ts"))};\n`;
|
|
199
|
+
const compiler = new CsrDevModuleCompiler({
|
|
200
|
+
app: { verbose: () => undefined, logger: { error: (message: string) => logged.push(message) } } as unknown as App,
|
|
201
|
+
paths,
|
|
202
|
+
resolver: new CsrDevResolver({ paths, context, entryFiles: [] }),
|
|
203
|
+
context: { ...context, modelRuntime },
|
|
204
|
+
outDir: file("out"),
|
|
205
|
+
routePrefix: "/_akan/registry/",
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const { modules } = await compiler.compile(markers, new Set());
|
|
209
|
+
|
|
210
|
+
for (const marker of markers)
|
|
211
|
+
expect(modules.find((module) => module.file === marker)?.deps).toEqual([file("apps/demo/lib/st.ts")]);
|
|
212
|
+
expect(modules.map((module) => module.file)).toContain(file("apps/demo/lib/st.ts"));
|
|
213
|
+
});
|
|
214
|
+
|
|
192
215
|
test("a pre-bundled file keeps its own __reExport and __toESM, which Bun leaves in place of its own", async () => {
|
|
193
216
|
const { modules } = await compile("node_modules/prebundled/chunk.mjs");
|
|
194
217
|
const [module] = modules;
|
|
@@ -388,3 +411,66 @@ describe("CsrDevModuleCompiler barrel narrowing", () => {
|
|
|
388
411
|
]);
|
|
389
412
|
});
|
|
390
413
|
});
|
|
414
|
+
|
|
415
|
+
describe("CsrDevModuleCompiler loading per module", () => {
|
|
416
|
+
const makeTempRoot = tempDirs("akan-csr-dev-descriptors-");
|
|
417
|
+
|
|
418
|
+
test("answers a module piece's macro with descriptors read from the signal, in a process of its own", async () => {
|
|
419
|
+
const root = CsrDevPaths.realpath(await makeTempRoot());
|
|
420
|
+
await Bun.write(
|
|
421
|
+
path.join(root, "apps/demo/lib/sig.ts"),
|
|
422
|
+
`const serialized = { draft: { endpoint: { draftOf: { type: "query", args: [], returns: { refName: "draft-descriptor-ref" } } } } };
|
|
423
|
+
export const fetch = { ownSerializedSignal: serialized };
|
|
424
|
+
export const getSerializedSignalOf = (name: string) => (name === "base" ? {} : { [name]: serialized[name as "draft"] });
|
|
425
|
+
`,
|
|
426
|
+
);
|
|
427
|
+
const piece = path.join(root, "apps/demo/lib/__client/draft.fetch.ts");
|
|
428
|
+
await Bun.write(
|
|
429
|
+
piece,
|
|
430
|
+
'import { getSerializedSignalOf } from "../sig" with { type: "macro" };\nexport const descriptors = getSerializedSignalOf("draft");\n',
|
|
431
|
+
);
|
|
432
|
+
const dir = JSON.stringify(import.meta.dir);
|
|
433
|
+
|
|
434
|
+
const compiled = (await printedInOwnProcess(
|
|
435
|
+
`
|
|
436
|
+
const path = await import("node:path");
|
|
437
|
+
const { CsrDevModuleCompiler } = await import(path.join(${dir}, "csrDevModuleCompiler.ts"));
|
|
438
|
+
const { CsrDevPaths } = await import(path.join(${dir}, "csrDevPaths.ts"));
|
|
439
|
+
const { CsrDevResolver } = await import(path.join(${dir}, "csrDevResolver.ts"));
|
|
440
|
+
const { SignalDescriptors } = await import(path.join(${dir}, "../transforms/signalDescriptors.ts"));
|
|
441
|
+
const [root, piece] = ${JSON.stringify([root, piece])};
|
|
442
|
+
let answered = 0;
|
|
443
|
+
const inline = SignalDescriptors.prototype.inline;
|
|
444
|
+
SignalDescriptors.prototype.inline = async function (...args) {
|
|
445
|
+
const contents = await inline.apply(this, args);
|
|
446
|
+
if (contents !== null) answered += 1;
|
|
447
|
+
return contents;
|
|
448
|
+
};
|
|
449
|
+
const logged = [];
|
|
450
|
+
const context = {
|
|
451
|
+
...${JSON.stringify(context)},
|
|
452
|
+
routeRuntime: { scopes: ["apps/demo"], redirectOf: () => null, transform: () => null },
|
|
453
|
+
};
|
|
454
|
+
const paths = new CsrDevPaths(root);
|
|
455
|
+
const compiler = new CsrDevModuleCompiler({
|
|
456
|
+
app: {
|
|
457
|
+
verbose: () => undefined,
|
|
458
|
+
logger: { error: (message) => logged.push(message), warn: (message) => logged.push(message) },
|
|
459
|
+
workspace: { workspaceRoot: root },
|
|
460
|
+
},
|
|
461
|
+
paths,
|
|
462
|
+
resolver: new CsrDevResolver({ paths, context, entryFiles: [] }),
|
|
463
|
+
context,
|
|
464
|
+
outDir: path.join(root, "out"),
|
|
465
|
+
routePrefix: "/_akan/registry/",
|
|
466
|
+
});
|
|
467
|
+
const { modules } = await compiler.compile([piece], new Set());
|
|
468
|
+
console.log(JSON.stringify({ answered, logged, factories: modules.map(({ factory }) => factory) }));
|
|
469
|
+
`,
|
|
470
|
+
root,
|
|
471
|
+
)) as { answered: number; logged: string[]; factories: string[] };
|
|
472
|
+
|
|
473
|
+
expect({ answered: compiled.answered, logged: compiled.logged }).toEqual({ answered: 1, logged: [] });
|
|
474
|
+
expect(compiled.factories.join("\n")).toContain("draft-descriptor-ref");
|
|
475
|
+
}, 30_000);
|
|
476
|
+
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { SSR_DEV_DIRNAME } from "akanjs/server/hmr/csrDevManifest";
|
|
2
3
|
import type { BunPlugin } from "bun";
|
|
4
|
+
import { StoreBootstrap } from "../artifact/storeBootstrap";
|
|
3
5
|
import type { App } from "../commandDecorators";
|
|
4
6
|
import { loaderFor } from "../transforms/moduleSyntax";
|
|
7
|
+
import { SignalDescriptors } from "../transforms/signalDescriptors";
|
|
5
8
|
import { CsrDevFactoryCheck } from "./csrDevFactoryCheck";
|
|
6
9
|
import { CsrDevPaths } from "./csrDevPaths";
|
|
7
10
|
import { CsrDevResolver } from "./csrDevResolver";
|
|
@@ -13,6 +16,7 @@ import type {
|
|
|
13
16
|
CsrDevSharedHelpers,
|
|
14
17
|
} from "./csrDevTypes";
|
|
15
18
|
import { DevBarrelImports } from "./devBarrelImports";
|
|
19
|
+
import { DevRouteRuntime } from "./devRouteRuntime";
|
|
16
20
|
import { RouteClientBuilder } from "./routeClientBuilder";
|
|
17
21
|
|
|
18
22
|
interface OutputMetafile {
|
|
@@ -52,7 +56,8 @@ export interface CsrDevCompileResult {
|
|
|
52
56
|
//* Every module becomes its own CJS factory: one Bun.build with each import external, so a save re-runs only the
|
|
53
57
|
//* modules it changed instead of reloading one scope-hoisted file.
|
|
54
58
|
export class CsrDevModuleCompiler {
|
|
55
|
-
static readonly #storeRoot = /(?:^|\/)lib\/st\.ts$/;
|
|
59
|
+
static readonly #storeRoot = /(?:^|\/)lib\/(?:st|__client\/(?:_st|[^/]+\.st))\.ts$/;
|
|
60
|
+
static readonly #storeOwners = `/.akan/generated/${SSR_DEV_DIRNAME}/${DevRouteRuntime.ownersModule}.ts`;
|
|
56
61
|
static readonly #macroImport = /\b(?:with|assert)\s*\{\s*type\s*:\s*["']macro["']/;
|
|
57
62
|
static readonly #factoryArgument =
|
|
58
63
|
/(?<![\w$.])(?:require|module|exports|__akanImport|\$RefreshReg\$|\$RefreshSig\$)(?![\w$]|\s*:)/;
|
|
@@ -69,6 +74,7 @@ export class CsrDevModuleCompiler {
|
|
|
69
74
|
readonly #assets = new Set<string>();
|
|
70
75
|
#barrels: Promise<DevBarrelImports | null> | null = null;
|
|
71
76
|
readonly #narrowed = new Map<string, Record<string, CsrDevNarrowedImport>>();
|
|
77
|
+
readonly #routed = new Map<string, string>();
|
|
72
78
|
|
|
73
79
|
constructor({ app, paths, resolver, context, outDir, routePrefix }: CsrDevModuleCompilerOptions) {
|
|
74
80
|
this.#app = app;
|
|
@@ -216,6 +222,7 @@ export class CsrDevModuleCompiler {
|
|
|
216
222
|
}
|
|
217
223
|
const sourceMap = sourceMaps.get(`${artifact.path}.map`);
|
|
218
224
|
const narrowed = this.#narrowed.get(file);
|
|
225
|
+
const routed = this.#routed.get(file);
|
|
219
226
|
modules.push({
|
|
220
227
|
id,
|
|
221
228
|
file,
|
|
@@ -226,6 +233,7 @@ export class CsrDevModuleCompiler {
|
|
|
226
233
|
mtimeMs: mtimes.get(file) ?? CsrDevPaths.mtimeOf(file),
|
|
227
234
|
hash: hashes.get(file) ?? "",
|
|
228
235
|
...(narrowed && Object.keys(narrowed).length > 0 ? { narrowed } : {}),
|
|
236
|
+
...(routed ? { routed } : {}),
|
|
229
237
|
});
|
|
230
238
|
}
|
|
231
239
|
return { modules, misses, tangled };
|
|
@@ -279,8 +287,18 @@ export class CsrDevModuleCompiler {
|
|
|
279
287
|
//? rewrite leaves a free `__akanMeta` that no factory header declares. So a file importing a macro has its macros run
|
|
280
288
|
//? first by a build of its own, with every other import left as written, and the module build reads that output.
|
|
281
289
|
async #evaluateMacros(files: string[]): Promise<Map<string, string>> {
|
|
282
|
-
const
|
|
290
|
+
const { routeRuntime } = this.#context;
|
|
291
|
+
const sources = await Promise.all(
|
|
292
|
+
files
|
|
293
|
+
.filter((file) => !routeRuntime?.redirectOf(file))
|
|
294
|
+
.map(async (file) => [file, await Bun.file(file).text()] as const),
|
|
295
|
+
);
|
|
283
296
|
const importers = sources.filter(([, source]) => CsrDevModuleCompiler.#macroImport.test(source));
|
|
297
|
+
const descriptors = routeRuntime
|
|
298
|
+
? new SignalDescriptors(this.#app.workspace.workspaceRoot, routeRuntime.scopes, {
|
|
299
|
+
onUnread: (reason) => this.#app.logger.warn(`[csr-dev] ${reason}, so their pieces run the macro`),
|
|
300
|
+
}).plugin
|
|
301
|
+
: null;
|
|
284
302
|
const outputs = await Promise.all(
|
|
285
303
|
importers.map(async ([file]) => {
|
|
286
304
|
const result = await Bun.build({
|
|
@@ -288,6 +306,7 @@ export class CsrDevModuleCompiler {
|
|
|
288
306
|
target: "browser",
|
|
289
307
|
format: "esm",
|
|
290
308
|
plugins: [
|
|
309
|
+
...(descriptors ? [descriptors] : []),
|
|
291
310
|
{
|
|
292
311
|
name: "akan-csr-macro-pass",
|
|
293
312
|
setup: (build) =>
|
|
@@ -314,6 +333,14 @@ export class CsrDevModuleCompiler {
|
|
|
314
333
|
name: "akan-csr-registry",
|
|
315
334
|
setup: (build) => {
|
|
316
335
|
build.onLoad({ filter: /\.css$/ }, () => ({ contents: "", loader: "js" }));
|
|
336
|
+
const { modelRuntime, routeRuntime } = this.#context;
|
|
337
|
+
if (modelRuntime !== undefined)
|
|
338
|
+
build.onLoad({ filter: StoreBootstrap.modelRuntimeFilter }, () => ({ contents: modelRuntime, loader: "ts" }));
|
|
339
|
+
if (routeRuntime && !vendor)
|
|
340
|
+
build.onLoad({ filter: /[\\/]lib[\\/](?:useClient|st)\.ts$/ }, (args) => {
|
|
341
|
+
const contents = routeRuntime.redirectOf(args.path);
|
|
342
|
+
return contents === null ? undefined : { contents, loader: "ts" };
|
|
343
|
+
});
|
|
317
344
|
if (macroOutputs.size > 0) {
|
|
318
345
|
const exact = [...macroOutputs.keys()].map((file) => file.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
319
346
|
build.onLoad({ filter: new RegExp(`^(?:${exact.join("|")})$`) }, (args) => {
|
|
@@ -325,9 +352,16 @@ export class CsrDevModuleCompiler {
|
|
|
325
352
|
build.onLoad({ filter: /\.(?:tsx?|jsx?)$/ }, async (args) => {
|
|
326
353
|
if (CsrDevPaths.isVendorFile(args.path)) return undefined;
|
|
327
354
|
const source = await Bun.file(args.path).text();
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
355
|
+
const file = CsrDevPaths.realpath(args.path);
|
|
356
|
+
const routed = routeRuntime?.transform(source, args.path) ?? null;
|
|
357
|
+
if (routed) this.#routed.set(file, routed.stamp);
|
|
358
|
+
else this.#routed.delete(file);
|
|
359
|
+
const input = routed?.contents ?? source;
|
|
360
|
+
const rewrite = await (await this.#barrelImports())?.rewrite(input, args.path, {
|
|
361
|
+
perModule: routed?.perModule,
|
|
362
|
+
});
|
|
363
|
+
if (rewrite) this.#narrowed.set(file, rewrite.narrowed);
|
|
364
|
+
const narrowed = rewrite?.contents ?? input;
|
|
331
365
|
const normalized = args.path.endsWith(".tsx")
|
|
332
366
|
? RouteClientBuilder.normalizeNamedDefaultFunctionForFastRefresh(narrowed, { path: args.path })
|
|
333
367
|
: null;
|
|
@@ -359,7 +393,7 @@ export class CsrDevModuleCompiler {
|
|
|
359
393
|
}
|
|
360
394
|
|
|
361
395
|
#barrelImports(): Promise<DevBarrelImports | null> {
|
|
362
|
-
this.#barrels ??= DevBarrelImports.create(this.#app, this.#context
|
|
396
|
+
this.#barrels ??= DevBarrelImports.create(this.#app, this.#context);
|
|
363
397
|
return this.#barrels;
|
|
364
398
|
}
|
|
365
399
|
|
|
@@ -413,8 +447,10 @@ export class CsrDevModuleCompiler {
|
|
|
413
447
|
);
|
|
414
448
|
}
|
|
415
449
|
// StoreRegistry.build merges into one global store instance, so every importer already holds the updated `st`:
|
|
416
|
-
// re-running the store root is the whole update
|
|
417
|
-
|
|
450
|
+
// re-running the store root, or a module's store piece, is the whole update: bubbling past it would only reach the
|
|
451
|
+
// page modules.
|
|
452
|
+
if (CsrDevModuleCompiler.#storeRoot.test(id) || id.endsWith(CsrDevModuleCompiler.#storeOwners))
|
|
453
|
+
patched += "\nmodule.hot.accept();";
|
|
418
454
|
const shared = CsrDevModuleCompiler.#shareHelpers(patched);
|
|
419
455
|
//? What `import.meta` is in a browser module: a `url` and no `env`, so `import.meta.env` checks (jotai, zustand)
|
|
420
456
|
//? branch as they do in the ESM bundle. On the header line, outside the preamble that modules share.
|
|
@@ -75,7 +75,7 @@ export class CsrDevPatcher {
|
|
|
75
75
|
if (state.graph.configKey !== context.configKey)
|
|
76
76
|
return this.#handBack("the dev bundle config changed", generation, context);
|
|
77
77
|
const metadataFile = changedFiles.find((file) => this.#bundler.isMetadataFile(file));
|
|
78
|
-
// `lib/useClient.ts`
|
|
78
|
+
// `lib/useClient.ts` and `lib/usePage.ts` inline signal and dictionary metadata through macros at build time.
|
|
79
79
|
if (metadataFile) return this.#handBack(`${path.basename(metadataFile)} changed`, generation, context);
|
|
80
80
|
//? Only a registry read from disk: one held in memory saw every save since, and a metadata save was handed back.
|
|
81
81
|
if (!resident && state.graph.metadata !== (await this.#bundler.metadataFingerprint()))
|
|
@@ -110,6 +110,8 @@ export class CsrDevPatcher {
|
|
|
110
110
|
const forgotten = this.#forgetDeletedModules(state, present);
|
|
111
111
|
const changed = onlyRoots ? new Set<string>() : await this.#changedModules(graph, changedFiles, present);
|
|
112
112
|
const restamped = onlyRoots ? null : await this.#renarrowed(context, graph, changedFiles, changed);
|
|
113
|
+
const routeTable = onlyRoots ? undefined : await this.#rerouted(context, graph, changed);
|
|
114
|
+
for (const id of CsrDevPatcher.#extendingAppStores(context, graph, changed)) changed.add(id);
|
|
113
115
|
for (const id of this.#withoutFactory(state, present)) changed.add(id);
|
|
114
116
|
for (const file of entries.changed) changed.add(paths.idOf(file));
|
|
115
117
|
const rootFiles = [...Object.values(entries.files), ...roots.filter((file) => fs.existsSync(file))];
|
|
@@ -124,6 +126,7 @@ export class CsrDevPatcher {
|
|
|
124
126
|
if (changed.size === 0) {
|
|
125
127
|
//? No importer moved (none compiles), so the restamped barrels already hold.
|
|
126
128
|
if (restamped) graph.barrels = { ...graph.barrels, ...restamped };
|
|
129
|
+
if (routeTable !== undefined) graph.routeTable = routeTable;
|
|
127
130
|
if (carried.length === 0) return { kind: "unchanged" };
|
|
128
131
|
return await this.#retryCarried(context, state, carried, { announce, allowWholeAppBuilds });
|
|
129
132
|
}
|
|
@@ -161,12 +164,7 @@ export class CsrDevPatcher {
|
|
|
161
164
|
await writer.writeJson("graph.json", graph);
|
|
162
165
|
throw error;
|
|
163
166
|
}
|
|
164
|
-
const refusal =
|
|
165
|
-
result.refusedVendors.length > 0
|
|
166
|
-
? "an npm module joined the graph"
|
|
167
|
-
: result.unresolved.length > 0
|
|
168
|
-
? `a new import needs the resolution build: ${result.unresolved[0]}`
|
|
169
|
-
: null;
|
|
167
|
+
const refusal = CsrDevPatcher.#refusalOf(result);
|
|
170
168
|
if (refusal) {
|
|
171
169
|
//? The entry files are already rewritten, so the worker would see them unchanged and patch a moved route table:
|
|
172
170
|
//? a graph whose entries name none makes it reload instead.
|
|
@@ -192,6 +190,7 @@ export class CsrDevPatcher {
|
|
|
192
190
|
}
|
|
193
191
|
graph.pending = graph.pending.filter((id) => !orphans.includes(id));
|
|
194
192
|
this.#bundler.merge(graph, resolver, compiled, { ...restamped, ...result.barrels });
|
|
193
|
+
if (routeTable !== undefined) graph.routeTable = routeTable;
|
|
195
194
|
if (!this.#resident) delete graph.failed;
|
|
196
195
|
for (const module of compiled) this.#delegated.delete(module.id);
|
|
197
196
|
graph.entries = entryIds;
|
|
@@ -261,6 +260,11 @@ export class CsrDevPatcher {
|
|
|
261
260
|
return retried.kind === "delegate" ? retried : outcome;
|
|
262
261
|
}
|
|
263
262
|
|
|
263
|
+
static #refusalOf(result: CsrDevCompileResult): string | null {
|
|
264
|
+
if (result.refusedVendors.length > 0) return "an npm module joined the graph";
|
|
265
|
+
return result.unresolved.length > 0 ? `a new import needs the resolution build: ${result.unresolved[0]}` : null;
|
|
266
|
+
}
|
|
267
|
+
|
|
264
268
|
//? Compiled apart from the save: a new root that failed to compile, and that no module imports, must not fail every
|
|
265
269
|
//? later save's round with it. Its error still reaches the overlay (this throws after the save's patch went out).
|
|
266
270
|
async #retryCarried(
|
|
@@ -540,6 +544,28 @@ export class CsrDevPatcher {
|
|
|
540
544
|
return barrels;
|
|
541
545
|
}
|
|
542
546
|
|
|
547
|
+
//? A store, signal or constant save can move a name to another module, or make one known: a module whose own text
|
|
548
|
+
//? did not change may then need other pieces. Each module the route runtime rewrote is rewritten again, and compiles
|
|
549
|
+
//? when it comes out different. The digest is recorded like a barrel stamp, with the compile that follows.
|
|
550
|
+
async #rerouted(context: CsrDevContext, graph: CsrDevGraph, changed: Set<string>): Promise<string | undefined> {
|
|
551
|
+
const { routeRuntime } = context;
|
|
552
|
+
if (!routeRuntime || graph.routeTable === routeRuntime.digest) return undefined;
|
|
553
|
+
const { paths } = this.#bundler;
|
|
554
|
+
for (const [id, module] of Object.entries(graph.modules)) {
|
|
555
|
+
if (!module.routed || changed.has(id)) continue;
|
|
556
|
+
const file = paths.fileOf(id);
|
|
557
|
+
if (!fs.existsSync(file)) continue;
|
|
558
|
+
if (routeRuntime.transform(await Bun.file(file).text(), file)?.stamp !== module.routed) changed.add(id);
|
|
559
|
+
}
|
|
560
|
+
return routeRuntime.digest;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
static #extendingAppStores(context: CsrDevContext, graph: CsrDevGraph, changed: Set<string>): string[] {
|
|
564
|
+
const { routeRuntime } = context;
|
|
565
|
+
if (!routeRuntime) return [];
|
|
566
|
+
return [...changed].flatMap((id) => routeRuntime.appStoresAfter(id, (module) => graph.modules[module]?.deps));
|
|
567
|
+
}
|
|
568
|
+
|
|
543
569
|
static #remember(code: CsrDevCode, compiled: CsrDevCompileResult["modules"]) {
|
|
544
570
|
for (const module of compiled) {
|
|
545
571
|
if (module.vendor) continue;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PageEntry } from "../artifact/implicitRootLayout";
|
|
2
|
+
import type { DevRouteRuntime } from "./devRouteRuntime";
|
|
2
3
|
|
|
3
4
|
export interface CsrDevNarrowedImport {
|
|
4
5
|
names: string[];
|
|
@@ -19,6 +20,7 @@ export interface CsrDevGraphModule {
|
|
|
19
20
|
deps: string[];
|
|
20
21
|
helpers?: string;
|
|
21
22
|
narrowed?: Record<string, CsrDevNarrowedImport>;
|
|
23
|
+
routed?: string;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export interface CsrDevGraph {
|
|
@@ -36,6 +38,8 @@ export interface CsrDevGraph {
|
|
|
36
38
|
/** The stamp of the signal and dictionary sources the last whole build inlined; see `RegistryMetadataFingerprint`. */
|
|
37
39
|
metadata?: string;
|
|
38
40
|
barrels?: Record<string, CsrDevBarrelStamp>;
|
|
41
|
+
/** The `DevRouteRuntime` digest every module's `routed` stamp was taken under. */
|
|
42
|
+
routeTable?: string;
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
export interface CsrDevContext {
|
|
@@ -50,6 +54,10 @@ export interface CsrDevContext {
|
|
|
50
54
|
/** Bare specifiers the page already loads (an SSR page's import map): required as `vendor:<specifier>`, not compiled. */
|
|
51
55
|
externals?: readonly string[];
|
|
52
56
|
barrelImports?: readonly string[];
|
|
57
|
+
/** What `akanjs/ui/modelRuntime` holds instead of its empty source, when the bootstrap loads only the page runtime. */
|
|
58
|
+
modelRuntime?: string;
|
|
59
|
+
/** Where pages load per module: what each client module imports, as the production build decides it. */
|
|
60
|
+
routeRuntime?: DevRouteRuntime;
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
export interface CsrDevSharedHelpers {
|
|
@@ -68,6 +76,7 @@ export interface CsrDevCompiledModule {
|
|
|
68
76
|
mtimeMs: number;
|
|
69
77
|
hash: string;
|
|
70
78
|
narrowed?: Record<string, CsrDevNarrowedImport>;
|
|
79
|
+
routed?: string;
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
/** Module factories by id and helper definitions by hash, kept in memory so app.js is written without a pass over the disk. */
|