@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
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { realpath } from "node:fs/promises";
|
|
1
|
+
import { describe, expect, spyOn, test } from "bun:test";
|
|
2
|
+
import { readdir, realpath } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { StoreBootstrap } from "../artifact/storeBootstrap";
|
|
5
|
+
import { RouteRuntimeReport } from "../quality/routeRuntimeReport";
|
|
6
|
+
import { printedInOwnProcess, tempDirs, writeText as write } from "../test/testHelpers";
|
|
5
7
|
import { createTsconfigPackageResolver } from "../transforms/barrelImportsPlugin";
|
|
8
|
+
import { ModelReference } from "../transforms/modelReference";
|
|
9
|
+
import { RouteRuntime } from "../transforms/routeRuntime";
|
|
6
10
|
import { CLIENT_BUNDLE_NAMING } from "./clientBuildTypes";
|
|
7
11
|
import { ClientEntriesBundler } from "./clientEntriesBundler";
|
|
8
12
|
import { GraphClientEntryDiscovery } from "./clientEntryDiscovery";
|
|
9
13
|
import { RouteClientBuilder } from "./routeClientBuilder";
|
|
14
|
+
import { RouteModulePreloads } from "./routeModulePreloads";
|
|
10
15
|
|
|
11
16
|
const makeTempRoot = tempDirs("akan-client-entry-");
|
|
12
17
|
|
|
13
18
|
const fixtureBarrels = ["@apps/demo/client", "@libs/kit/client"];
|
|
14
19
|
|
|
15
|
-
const writeBarrelFixture = async () => {
|
|
16
|
-
const root = await makeTempRoot();
|
|
20
|
+
const writeBarrelFixture = async (rootDir?: string) => {
|
|
21
|
+
const root = rootDir ?? (await makeTempRoot());
|
|
17
22
|
const appDir = path.join(root, "apps/demo");
|
|
18
23
|
const libDir = path.join(root, "libs/kit");
|
|
19
24
|
const paths = { "@apps/*": ["./apps/*"], "@libs/*": ["./libs/*"] };
|
|
@@ -79,10 +84,20 @@ const writeBarrelFixture = async () => {
|
|
|
79
84
|
getConfig: async () => ({ barrelImports: fixtureBarrels, optimizeImports: [] }),
|
|
80
85
|
getTsConfig: async () => ({ compilerOptions: { paths } }),
|
|
81
86
|
getPublicEnv: () => ({}),
|
|
87
|
+
logger: { warn: () => undefined },
|
|
82
88
|
} as never;
|
|
83
89
|
return { root, appDir, app };
|
|
84
90
|
};
|
|
85
91
|
|
|
92
|
+
const signalFixture = `const serialized = { draft: { endpoint: { draftOf: { type: "query", args: [], returns: { refName: "draft-descriptor-ref" } } } } };
|
|
93
|
+
export const fetch = { ownSerializedSignal: serialized };
|
|
94
|
+
export const getSerializedSignalOf = (name: string) => (name === "base" ? {} : { [name]: serialized[name as "draft"] });
|
|
95
|
+
`;
|
|
96
|
+
|
|
97
|
+
const signalPiece = `import { getSerializedSignalOf } from "../sig" with { type: "macro" };
|
|
98
|
+
export const descriptors = getSerializedSignalOf("draft");
|
|
99
|
+
`;
|
|
100
|
+
|
|
86
101
|
const bundledText = async (dir: string) =>
|
|
87
102
|
(
|
|
88
103
|
await Promise.all([...new Bun.Glob("**/*.js").scanSync(dir)].map((file) => Bun.file(path.join(dir, file)).text()))
|
|
@@ -232,6 +247,7 @@ describe("route client store bootstrap", () => {
|
|
|
232
247
|
getConfig: async () => ({ barrelImports: [], optimizeImports: [] }),
|
|
233
248
|
getTsConfig: async () => ({ compilerOptions: { paths: {} } }),
|
|
234
249
|
getPublicEnv: () => ({}),
|
|
250
|
+
logger: { warn: () => undefined },
|
|
235
251
|
} as never;
|
|
236
252
|
const discovery = new GraphClientEntryDiscovery({ barrelImports: [] }, async () => null);
|
|
237
253
|
const build = (seeds: string[], knownEntries: Set<string>) =>
|
|
@@ -386,6 +402,563 @@ describe("route client store bootstrap", () => {
|
|
|
386
402
|
]);
|
|
387
403
|
});
|
|
388
404
|
|
|
405
|
+
describe("loading per module", () => {
|
|
406
|
+
const routeFixture = async () => {
|
|
407
|
+
const fixture = await writeBarrelFixture(await realpath(await makeTempRoot()));
|
|
408
|
+
await write(
|
|
409
|
+
path.join(fixture.appDir, `lib/${StoreBootstrap.pageRuntime}.ts`),
|
|
410
|
+
'export const mark = Object.freeze({ mark: "page-runtime-only" });\n',
|
|
411
|
+
);
|
|
412
|
+
await write(
|
|
413
|
+
path.join(fixture.appDir, `lib/${StoreBootstrap.baseDescriptors}.ts`),
|
|
414
|
+
'export const base = Object.freeze({ mark: "base-descriptors" });\n',
|
|
415
|
+
);
|
|
416
|
+
await write(path.join(fixture.appDir, `lib/${ModelReference.registry}.ts`), "export {};\n");
|
|
417
|
+
for (const file of StoreBootstrap.assembled)
|
|
418
|
+
await write(
|
|
419
|
+
path.join(fixture.appDir, `lib/${file}.ts`),
|
|
420
|
+
`export const st = Object.freeze({ mark: "assembled:${file}" });\nexport const { fetch, sig } = st as never;\n`,
|
|
421
|
+
);
|
|
422
|
+
const akanjsRoot = path.dirname(Bun.resolveSync("akanjs/package.json", import.meta.dir));
|
|
423
|
+
for (const file of ["package.json", "store/baseSt.ts", "signal/base.signal.ts", "signal/agent.signal.ts"])
|
|
424
|
+
await write(
|
|
425
|
+
path.join(fixture.root, "node_modules/akanjs", file),
|
|
426
|
+
await Bun.file(path.join(akanjsRoot, file)).text(),
|
|
427
|
+
);
|
|
428
|
+
const warnings: string[] = [];
|
|
429
|
+
const said: string[] = [];
|
|
430
|
+
const app = {
|
|
431
|
+
...(fixture.app as object),
|
|
432
|
+
logger: { warn: (message: string) => warnings.push(message) },
|
|
433
|
+
log: (message: string) => said.push(message),
|
|
434
|
+
verbose: () => undefined,
|
|
435
|
+
} as never;
|
|
436
|
+
return { ...fixture, app, warnings, said };
|
|
437
|
+
};
|
|
438
|
+
const build = (app: never, entry: string) =>
|
|
439
|
+
new RouteClientBuilder({ app, seeds: [], entries: [entry], artifact: {} as never, browser: "chunks" }).build();
|
|
440
|
+
|
|
441
|
+
test("a store-free route's browser chunks carry the page runtime and the framework's own descriptors, its SSR chunks the whole runtime", async () => {
|
|
442
|
+
const { appDir, app, warnings } = await routeFixture();
|
|
443
|
+
const entry = path.join(appDir, "ui/A.tsx");
|
|
444
|
+
|
|
445
|
+
const result = await build(app, entry);
|
|
446
|
+
|
|
447
|
+
const browser = await bundledText(path.join(appDir, ".akan/artifact/client"));
|
|
448
|
+
const ssr = await bundledText(path.join(appDir, ".akan/artifact/client-ssr"));
|
|
449
|
+
for (const marker of ["page-runtime-only", "base-descriptors"]) expect(browser).toContain(marker);
|
|
450
|
+
for (const marker of ['"runtime-marker"', '"store-marker"', "lib-store-marker"])
|
|
451
|
+
expect(browser).not.toContain(marker);
|
|
452
|
+
for (const marker of ['"runtime-marker"', '"store-marker"', "lib-store-marker"]) expect(ssr).toContain(marker);
|
|
453
|
+
expect(warnings).toEqual([]);
|
|
454
|
+
expect(Object.keys(result.manifestDelta)).toEqual(["apps/demo/ui/A.tsx#A"]);
|
|
455
|
+
const row = result.manifestDelta["apps/demo/ui/A.tsx#A"];
|
|
456
|
+
expect(result.ssrManifestDelta.moduleMap[row?.id ?? ""]?.A?.id).toContain(`${path.sep}client-ssr${path.sep}`);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
const assembledMarkers = StoreBootstrap.assembled.map((file) => `assembled:${file}`);
|
|
460
|
+
|
|
461
|
+
test("a framework file importing the model runtime marker keeps the whole runtime a build of every module loads", async () => {
|
|
462
|
+
const { root, appDir, app } = await routeFixture();
|
|
463
|
+
const entry = path.join(root, "node_modules/akanjs/ui/Data/List.tsx");
|
|
464
|
+
await write(path.join(root, "node_modules/akanjs/ui/modelRuntime.ts"), "export {};\n");
|
|
465
|
+
await write(entry, '"use client";\nimport "../modelRuntime";\nexport const List = () => "list-marker";\n');
|
|
466
|
+
|
|
467
|
+
await build(app, entry);
|
|
468
|
+
|
|
469
|
+
const browser = await bundledText(path.join(appDir, ".akan/artifact/client"));
|
|
470
|
+
for (const marker of ["list-marker", '"runtime-marker"', '"store-marker"']) expect(browser).toContain(marker);
|
|
471
|
+
for (const marker of assembledMarkers) expect(browser).not.toContain(marker);
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
test("a file reading a store by a name picked at run time keeps the whole runtime, with no copy assembled from pieces", async () => {
|
|
475
|
+
const { appDir, app } = await routeFixture();
|
|
476
|
+
const entry = path.join(appDir, "ui/Pick.tsx");
|
|
477
|
+
await write(
|
|
478
|
+
entry,
|
|
479
|
+
'"use client";\nimport { st } from "@apps/demo/client";\nexport const Pick = (name: string) => [st.use[name], "pick-marker"];\n',
|
|
480
|
+
);
|
|
481
|
+
|
|
482
|
+
await build(app, entry);
|
|
483
|
+
|
|
484
|
+
const browser = await bundledText(path.join(appDir, ".akan/artifact/client"));
|
|
485
|
+
for (const marker of ["pick-marker", '"runtime-marker"', '"store-marker"']) expect(browser).toContain(marker);
|
|
486
|
+
for (const marker of assembledMarkers) expect(browser).not.toContain(marker);
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
const writeStorePieces = async (appDir: string) => {
|
|
490
|
+
for (const [name, key] of [
|
|
491
|
+
["draft", "draftText"],
|
|
492
|
+
["tally", "tallyCount"],
|
|
493
|
+
]) {
|
|
494
|
+
await write(
|
|
495
|
+
path.join(appDir, `lib/_${name}/${name}.store.ts`),
|
|
496
|
+
`import { store } from "akanjs/store";\nexport class ${name}Store extends store("${name}" as const, () => ({ ${key}: 0 })) {}\n`,
|
|
497
|
+
);
|
|
498
|
+
await write(
|
|
499
|
+
path.join(appDir, `lib/__client/${name}.st.ts`),
|
|
500
|
+
`export const ${name} = Object.freeze({ mark: "piece:${name}.st" });\n(globalThis as { pieces?: unknown[] }).pieces?.push(${name});\n`,
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
await write(
|
|
504
|
+
path.join(appDir, `lib/${StoreBootstrap.pageRuntime}.ts`),
|
|
505
|
+
'export const st = Object.freeze({ mark: "page-runtime-only", use: { draftText: () => 0 } });\n',
|
|
506
|
+
);
|
|
507
|
+
};
|
|
508
|
+
const writeDraftEntry = async (appDir: string) => {
|
|
509
|
+
const entry = path.join(appDir, "ui/Draft.tsx");
|
|
510
|
+
await write(
|
|
511
|
+
entry,
|
|
512
|
+
'"use client";\nimport { st } from "@apps/demo/client";\nexport const Draft = () => [st.use.draftText(), "draft-ui-marker"];\n',
|
|
513
|
+
);
|
|
514
|
+
return entry;
|
|
515
|
+
};
|
|
516
|
+
const wholeOrOtherPieces = ["piece:tally.st", ...assembledMarkers, '"runtime-marker"', '"store-marker"'];
|
|
517
|
+
|
|
518
|
+
test("a file naming one module's state brings that module's store piece, no other module's and no assembled runtime", async () => {
|
|
519
|
+
const { appDir, app } = await routeFixture();
|
|
520
|
+
await writeStorePieces(appDir);
|
|
521
|
+
|
|
522
|
+
await build(app, await writeDraftEntry(appDir));
|
|
523
|
+
|
|
524
|
+
const browser = await bundledText(path.join(appDir, ".akan/artifact/client"));
|
|
525
|
+
for (const marker of ["draft-ui-marker", "page-runtime-only", "piece:draft.st"])
|
|
526
|
+
expect(browser).toContain(marker);
|
|
527
|
+
for (const marker of wholeOrOtherPieces) expect(browser).not.toContain(marker);
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
test("a file importing one module's store piece by hand brings that piece and keeps the whole runtime", async () => {
|
|
531
|
+
const { appDir, app } = await routeFixture();
|
|
532
|
+
await writeStorePieces(appDir);
|
|
533
|
+
const entry = path.join(appDir, "ui/Hand.tsx");
|
|
534
|
+
await write(
|
|
535
|
+
entry,
|
|
536
|
+
'"use client";\nimport "@apps/demo/lib/__client/draft.st";\nexport const Hand = () => "hand-ui-marker";\n',
|
|
537
|
+
);
|
|
538
|
+
|
|
539
|
+
await build(app, entry);
|
|
540
|
+
|
|
541
|
+
const browser = await bundledText(path.join(appDir, ".akan/artifact/client"));
|
|
542
|
+
for (const marker of ["hand-ui-marker", "piece:draft.st", '"runtime-marker"', '"store-marker"'])
|
|
543
|
+
expect(browser).toContain(marker);
|
|
544
|
+
for (const marker of ["piece:tally.st", ...assembledMarkers]) expect(browser).not.toContain(marker);
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
describe("a build told which entries each route loads", () => {
|
|
548
|
+
const seen = "((globalThis as { __akanSeen?: string[] }).__akanSeen ??= [])";
|
|
549
|
+
const weightOf = (hashes: number, salt: string) =>
|
|
550
|
+
hashes > 0
|
|
551
|
+
? `(globalThis as { __akanWeight?: string[] }).__akanWeight = ["${Array.from({ length: hashes }, (_, index) => Bun.hash(`${salt}-${index}`).toString(36)).join("")}"];\n`
|
|
552
|
+
: "";
|
|
553
|
+
const describedSignal = `const serialized = {
|
|
554
|
+
draft: { endpoint: { draftOf: { type: "query", args: [], returns: { refName: "draft-descriptor-ref" } } } },
|
|
555
|
+
tally: { endpoint: { tallyOf: { type: "query", args: [], returns: { refName: "tally-descriptor-ref" } } } },
|
|
556
|
+
};
|
|
557
|
+
export const fetch = { ownSerializedSignal: serialized };
|
|
558
|
+
export const getSerializedSignal = () => serialized;
|
|
559
|
+
export const getSerializedSignalOf = (name: string) => (name === "base" ? {} : { [name]: serialized[name as "draft"] });
|
|
560
|
+
`;
|
|
561
|
+
const picking =
|
|
562
|
+
'"use client";\nimport { st } from "@apps/demo/client";\nexport const Pick = (name: string) => [st.use[name], "pick-marker"];\n';
|
|
563
|
+
const namingDraft =
|
|
564
|
+
'import { st } from "@apps/demo/client";\nexport const shared = () => [st.use.draftText(), "shared-marker"];\n';
|
|
565
|
+
const describedFixture = async ({ whole = 600, draft = 0, tally = 0 } = {}) => {
|
|
566
|
+
const fixture = await routeFixture();
|
|
567
|
+
const { appDir } = fixture;
|
|
568
|
+
await writeStorePieces(appDir);
|
|
569
|
+
await write(path.join(appDir, "lib/sig.ts"), describedSignal);
|
|
570
|
+
await write(path.join(fixture.root, "libs/kit/lib/sig.ts"), signalFixture);
|
|
571
|
+
for (const [facet, source] of [
|
|
572
|
+
["base", "export const loadedAfter = (..._modules: unknown[]): void => {};\n"],
|
|
573
|
+
["store", "export const st = { use: {} };\nexport const store = (..._args: unknown[]) => class {};\n"],
|
|
574
|
+
])
|
|
575
|
+
await write(path.join(fixture.root, `node_modules/akanjs/${facet}/index.ts`), source);
|
|
576
|
+
for (const [file, name] of [
|
|
577
|
+
["_base", "base"],
|
|
578
|
+
["draft", "draft"],
|
|
579
|
+
["tally", "tally"],
|
|
580
|
+
])
|
|
581
|
+
await write(
|
|
582
|
+
path.join(appDir, `lib/__client/${file}.fetch.ts`),
|
|
583
|
+
`import { getSerializedSignalOf } from "../sig" with { type: "macro" };\nexport const loaded = getSerializedSignalOf("${name}");\n${seen}.push(...Object.keys(loaded).map((key) => "piece:" + key));\n`,
|
|
584
|
+
);
|
|
585
|
+
await write(
|
|
586
|
+
path.join(appDir, "lib/useClient.ts"),
|
|
587
|
+
`import { getSerializedSignal } from "./sig" with { type: "macro" };\nconst whole = getSerializedSignal();\n${seen}.push(...Object.keys(whole).map((key) => "whole:" + key));\nexport const { msg, Err, usePage, fetch, sig } = { usePage: () => "page" } as Record<string, unknown>;\n`,
|
|
588
|
+
);
|
|
589
|
+
await write(
|
|
590
|
+
path.join(appDir, "lib/st.ts"),
|
|
591
|
+
`export class RootStore {}\nexport const st = Object.freeze({ mark: "store-marker" });\n${weightOf(whole, "whole")}`,
|
|
592
|
+
);
|
|
593
|
+
for (const [name, hashes] of Object.entries({ draft, tally }))
|
|
594
|
+
await write(
|
|
595
|
+
path.join(appDir, `lib/__client/${name}.st.ts`),
|
|
596
|
+
`export const ${name} = Object.freeze({ mark: "piece:${name}.st" });\n${weightOf(hashes, name)}`,
|
|
597
|
+
);
|
|
598
|
+
const file = (name: string) => path.join(appDir, `ui/${name}.tsx`);
|
|
599
|
+
const buildRoutes = async (routes: Record<string, string[]>) => {
|
|
600
|
+
const entriesByRoute = new Map(Object.entries(routes));
|
|
601
|
+
const entries = [...new Set(Object.values(routes).flat())];
|
|
602
|
+
const result = await new RouteClientBuilder({
|
|
603
|
+
app: fixture.app,
|
|
604
|
+
seeds: [],
|
|
605
|
+
entries,
|
|
606
|
+
artifact: {} as never,
|
|
607
|
+
browser: "chunks",
|
|
608
|
+
entriesByRoute,
|
|
609
|
+
}).build();
|
|
610
|
+
const clientOut = path.join(appDir, ".akan/artifact/client");
|
|
611
|
+
const state = globalThis as { __akanSeen?: string[]; $RefreshReg$?: unknown; $RefreshSig$?: unknown };
|
|
612
|
+
const seenNow = () => [...(state.__akanSeen ?? [])].sort();
|
|
613
|
+
const load = async (route: string) => {
|
|
614
|
+
state.__akanSeen = [];
|
|
615
|
+
state.$RefreshReg$ ??= () => undefined;
|
|
616
|
+
state.$RefreshSig$ ??= () => (type: unknown) => type;
|
|
617
|
+
const ids = new Set(
|
|
618
|
+
(routes[route] ?? []).map((entry) => `${path.relative(fixture.root, entry).split(path.sep).join("/")}#`),
|
|
619
|
+
);
|
|
620
|
+
const exported: Record<string, unknown> = {};
|
|
621
|
+
for (const [key, row] of Object.entries(result.manifestDelta))
|
|
622
|
+
if ([...ids].some((id) => key.startsWith(id)))
|
|
623
|
+
Object.assign(exported, await import(path.join(clientOut, path.basename(row.chunks[0] ?? ""))));
|
|
624
|
+
return exported;
|
|
625
|
+
};
|
|
626
|
+
const run = async (route: string) => {
|
|
627
|
+
await load(route);
|
|
628
|
+
return seenNow();
|
|
629
|
+
};
|
|
630
|
+
return { browser: await bundledText(clientOut), run, load, seenNow };
|
|
631
|
+
};
|
|
632
|
+
return { ...fixture, file, buildRoutes };
|
|
633
|
+
};
|
|
634
|
+
const timesIn = (text: string, marker: string) => text.split(marker).length - 1;
|
|
635
|
+
const mixed =
|
|
636
|
+
"[client-runtime] 1 route loads per module, 0 keep the whole runtime because per module would not be smaller, 1 keeps it for a reason `akan quality runtime` names";
|
|
637
|
+
|
|
638
|
+
test("a route with an entry keeping the whole runtime and a narrowed entry sharing a file holds each module's descriptors once, and runs them once", async () => {
|
|
639
|
+
const { file, buildRoutes, warnings, said } = await describedFixture();
|
|
640
|
+
await write(file("Shared"), namingDraft);
|
|
641
|
+
await write(file("Pick"), `${picking}export { shared } from "./Shared";\n`);
|
|
642
|
+
await write(
|
|
643
|
+
file("Draft"),
|
|
644
|
+
'"use client";\nimport { shared } from "./Shared";\nexport const Draft = () => [shared, "draft-ui-marker"];\n',
|
|
645
|
+
);
|
|
646
|
+
|
|
647
|
+
const { browser, run } = await buildRoutes({
|
|
648
|
+
"/pick": [file("Pick"), file("Draft")],
|
|
649
|
+
"/draft": [file("Draft")],
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
expect(said).toEqual([mixed]);
|
|
653
|
+
expect(warnings).toEqual([]);
|
|
654
|
+
for (const marker of ["draft-descriptor-ref", "tally-descriptor-ref"]) expect(timesIn(browser, marker)).toBe(1);
|
|
655
|
+
expect(await run("/pick")).toEqual(["piece:draft", "whole:tally"]);
|
|
656
|
+
expect(await run("/draft")).toEqual([]);
|
|
657
|
+
}, 30_000);
|
|
658
|
+
|
|
659
|
+
test("a page loading per module that asks with import() for a file needing every module gets the whole runtime then, and no module's descriptors twice", async () => {
|
|
660
|
+
const { file, buildRoutes, warnings, said } = await describedFixture();
|
|
661
|
+
await write(file("Shared"), namingDraft);
|
|
662
|
+
await write(
|
|
663
|
+
file("Later"),
|
|
664
|
+
'import { st } from "@apps/demo/client";\nexport const later = (name: string) => [st.use[name], "later-marker"];\n',
|
|
665
|
+
);
|
|
666
|
+
await write(
|
|
667
|
+
file("Draft"),
|
|
668
|
+
'"use client";\nimport { shared } from "./Shared";\nexport const Draft = () => [shared, "draft-ui-marker"];\nexport const ask = () => import("./Later");\n',
|
|
669
|
+
);
|
|
670
|
+
|
|
671
|
+
const { browser, load, seenNow } = await buildRoutes({ "/draft": [file("Draft")] });
|
|
672
|
+
|
|
673
|
+
expect(said).toEqual([
|
|
674
|
+
"[client-runtime] 1 route loads per module, 0 keep the whole runtime because per module would not be smaller",
|
|
675
|
+
]);
|
|
676
|
+
expect(warnings).toEqual([]);
|
|
677
|
+
for (const marker of ["draft-descriptor-ref", "tally-descriptor-ref"]) expect(timesIn(browser, marker)).toBe(1);
|
|
678
|
+
const { ask } = (await load("/draft")) as { ask: () => Promise<unknown> };
|
|
679
|
+
expect(seenNow()).toEqual(["piece:draft"]);
|
|
680
|
+
await ask();
|
|
681
|
+
expect(seenNow()).toEqual(["piece:draft", "whole:tally"]);
|
|
682
|
+
}, 30_000);
|
|
683
|
+
|
|
684
|
+
test("a reference handed over on a whole page and on a page loading per module brings no second copy to the whole page", async () => {
|
|
685
|
+
const { appDir, file, buildRoutes, warnings, said } = await describedFixture();
|
|
686
|
+
await write(
|
|
687
|
+
path.join(appDir, "lib/_draft/draft.store.ts"),
|
|
688
|
+
'import { store } from "akanjs/store";\nexport class draftStore extends store("draft" as const, () => ({ draftText: 0, draft: null })) {}\n',
|
|
689
|
+
);
|
|
690
|
+
const reference = path.join(appDir, "lib/__client/draft.ref.ts");
|
|
691
|
+
await write(reference, '"use client";\n\nexport const reference = "draft";\n');
|
|
692
|
+
await write(file("Pick"), picking);
|
|
693
|
+
await write(file("Plain"), '"use client";\nexport const Plain = () => "plain-ui-marker";\n');
|
|
694
|
+
|
|
695
|
+
const { browser } = await buildRoutes({
|
|
696
|
+
"/pick": [file("Pick"), reference],
|
|
697
|
+
"/plain": [file("Plain"), reference],
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
expect(said).toEqual([mixed]);
|
|
701
|
+
expect(warnings).toEqual([]);
|
|
702
|
+
expect(browser).toContain("piece:draft.st");
|
|
703
|
+
expect(timesIn(browser, "draft-descriptor-ref")).toBe(1);
|
|
704
|
+
}, 30_000);
|
|
705
|
+
|
|
706
|
+
test("a route that would be no smaller loading per module keeps the whole runtime, and the build it was measured against leaves nothing behind", async () => {
|
|
707
|
+
const { appDir, file, buildRoutes, warnings, said } = await describedFixture({ whole: 0, draft: 600 });
|
|
708
|
+
await write(file("Draft"), `"use client";\n${namingDraft}`);
|
|
709
|
+
|
|
710
|
+
const { browser, run } = await buildRoutes({ "/draft": [file("Draft")] });
|
|
711
|
+
|
|
712
|
+
expect(said).toEqual([
|
|
713
|
+
"[client-runtime] 0 routes load per module, 1 keeps the whole runtime because per module would not be smaller",
|
|
714
|
+
]);
|
|
715
|
+
expect(warnings).toEqual([]);
|
|
716
|
+
expect(browser).toContain("shared-marker");
|
|
717
|
+
expect(browser).not.toContain("piece:draft.st");
|
|
718
|
+
expect(await run("/draft")).toEqual(["whole:draft", "whole:tally"]);
|
|
719
|
+
expect(await Bun.file(path.join(appDir, ".akan/artifact/client-whole")).exists()).toBe(false);
|
|
720
|
+
expect((await readdir(path.join(appDir, ".akan/artifact"))).sort()).toEqual(["client", "client-ssr"]);
|
|
721
|
+
}, 30_000);
|
|
722
|
+
|
|
723
|
+
test("a route no smaller per module than where every page is whole, yet larger still keeping the whole runtime beside a page that loads per module, loads per module", async () => {
|
|
724
|
+
const { appDir, file, buildRoutes, warnings, said } = await describedFixture({
|
|
725
|
+
whole: 500,
|
|
726
|
+
draft: 450,
|
|
727
|
+
tally: 100,
|
|
728
|
+
});
|
|
729
|
+
await write(file("Shared"), namingDraft);
|
|
730
|
+
await write(file("Draft"), '"use client";\nexport { shared } from "./Shared";\n');
|
|
731
|
+
await write(
|
|
732
|
+
file("Board"),
|
|
733
|
+
'"use client";\nimport { st } from "@apps/demo/client";\nimport { shared } from "./Shared";\nexport const Board = () => [shared, st.use.tallyCount(), "board-marker"];\n',
|
|
734
|
+
);
|
|
735
|
+
|
|
736
|
+
const { browser } = await buildRoutes({ "/draft": [file("Draft")], "/board": [file("Board")] });
|
|
737
|
+
|
|
738
|
+
expect(said).toEqual([
|
|
739
|
+
"[client-runtime] 2 routes load per module, 0 keep the whole runtime because per module would not be smaller",
|
|
740
|
+
]);
|
|
741
|
+
expect(warnings).toEqual([]);
|
|
742
|
+
for (const marker of ["piece:draft.st", "piece:tally.st", "board-marker"]) expect(browser).toContain(marker);
|
|
743
|
+
expect(browser).not.toContain("store-marker");
|
|
744
|
+
const report = await Bun.file(path.join(appDir, RouteRuntimeReport.file)).json();
|
|
745
|
+
expect(report).toMatchObject({ perModule: ["/draft", "/board"], notSmaller: [], refused: ["/board"] });
|
|
746
|
+
}, 30_000);
|
|
747
|
+
|
|
748
|
+
test("a production build answers each export of a client file from its own entry, so a route asking one loads no import of the other; under start the file is one entry", async () => {
|
|
749
|
+
const { root, appDir, app, file, warnings } = await describedFixture();
|
|
750
|
+
for (const name of ["a", "b"])
|
|
751
|
+
await write(file(`heavy-${name}`), `export const heavy = { mark: "heavy-${name}-marker" };\n`);
|
|
752
|
+
const pair = file("Pair");
|
|
753
|
+
await write(
|
|
754
|
+
pair,
|
|
755
|
+
'"use client";\nimport { heavy as a } from "./heavy-a";\nimport { heavy as b } from "./heavy-b";\nexport const A = () => a.mark;\nexport const B = () => b.mark;\n',
|
|
756
|
+
);
|
|
757
|
+
const entriesByRoute = new Map([
|
|
758
|
+
["/a", [pair]],
|
|
759
|
+
["/b", [pair]],
|
|
760
|
+
]);
|
|
761
|
+
const askedByRoute = new Map([
|
|
762
|
+
["/a", new Map([[pair, ["A"]]])],
|
|
763
|
+
["/b", new Map([[pair, ["B"]]])],
|
|
764
|
+
]);
|
|
765
|
+
const buildAs = async (command: "build" | "start") => {
|
|
766
|
+
const { manifestDelta } = await new RouteClientBuilder({
|
|
767
|
+
app,
|
|
768
|
+
seeds: [],
|
|
769
|
+
entries: [pair],
|
|
770
|
+
artifact: {} as never,
|
|
771
|
+
browser: "chunks",
|
|
772
|
+
command,
|
|
773
|
+
entriesByRoute,
|
|
774
|
+
askedByRoute,
|
|
775
|
+
}).build();
|
|
776
|
+
const artifact = path.join(
|
|
777
|
+
command === "build" ? path.join(root, "dist/apps/demo") : appDir,
|
|
778
|
+
".akan/artifact",
|
|
779
|
+
);
|
|
780
|
+
const sized = new RouteModulePreloads({
|
|
781
|
+
runtimeChunks: { runtime: [], vendors: {} },
|
|
782
|
+
entriesByRoute,
|
|
783
|
+
askedByRoute,
|
|
784
|
+
clientManifest: manifestDelta,
|
|
785
|
+
externalsByChunkUrl: {},
|
|
786
|
+
workspaceRoot: root,
|
|
787
|
+
}).modulesByRoute();
|
|
788
|
+
const loadedBy = async (route: string) =>
|
|
789
|
+
(
|
|
790
|
+
await Promise.all(
|
|
791
|
+
(sized[route] ?? []).map((url) => Bun.file(path.join(artifact, url.replace(/^\/_akan\//, ""))).text()),
|
|
792
|
+
)
|
|
793
|
+
).join("\n");
|
|
794
|
+
const idOf = (name: string) => manifestDelta[`apps/demo/ui/Pair.tsx#${name}`]?.id;
|
|
795
|
+
return { rows: Object.keys(manifestDelta).sort(), idOf, a: await loadedBy("/a"), b: await loadedBy("/b") };
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
const built = await buildAs("build");
|
|
799
|
+
expect(built.rows).toEqual(["apps/demo/ui/Pair.tsx#A", "apps/demo/ui/Pair.tsx#B"]);
|
|
800
|
+
expect(built.idOf("A")).not.toBe(built.idOf("B"));
|
|
801
|
+
expect(built.a).toContain("heavy-a-marker");
|
|
802
|
+
expect(built.a).not.toContain("heavy-b-marker");
|
|
803
|
+
expect(built.b).toContain("heavy-b-marker");
|
|
804
|
+
expect(built.b).not.toContain("heavy-a-marker");
|
|
805
|
+
|
|
806
|
+
const started = await buildAs("start");
|
|
807
|
+
expect(started.rows).toEqual(built.rows);
|
|
808
|
+
expect(started.idOf("A")).toBe(started.idOf("B"));
|
|
809
|
+
for (const marker of ["heavy-a-marker", "heavy-b-marker"]) expect(started.a).toContain(marker);
|
|
810
|
+
expect(warnings).toEqual([]);
|
|
811
|
+
}, 30_000);
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
test("the files a route is sized by hold the store piece of the module its client code names, and no assembled runtime", async () => {
|
|
815
|
+
const { root, appDir, app } = await routeFixture();
|
|
816
|
+
await writeStorePieces(appDir);
|
|
817
|
+
const entry = await writeDraftEntry(appDir);
|
|
818
|
+
|
|
819
|
+
const { manifestDelta } = await build(app, entry);
|
|
820
|
+
|
|
821
|
+
const sizedUrls = new RouteModulePreloads({
|
|
822
|
+
runtimeChunks: { runtime: [], vendors: {} },
|
|
823
|
+
entriesByRoute: new Map([["/:lang/draft", [entry]]]),
|
|
824
|
+
clientManifest: manifestDelta,
|
|
825
|
+
externalsByChunkUrl: {},
|
|
826
|
+
workspaceRoot: root,
|
|
827
|
+
}).modulesByRoute()["/:lang/draft"];
|
|
828
|
+
const sized = (
|
|
829
|
+
await Promise.all(
|
|
830
|
+
(sizedUrls ?? []).map((url) =>
|
|
831
|
+
Bun.file(path.join(appDir, ".akan/artifact", url.replace(/^\/_akan\//, ""))).text(),
|
|
832
|
+
),
|
|
833
|
+
)
|
|
834
|
+
).join("\n");
|
|
835
|
+
for (const marker of ["draft-ui-marker", "page-runtime-only", "piece:draft.st"]) expect(sized).toContain(marker);
|
|
836
|
+
for (const marker of wholeOrOtherPieces) expect(sized).not.toContain(marker);
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
test.each([
|
|
840
|
+
["the object first", "Memo, cnst"],
|
|
841
|
+
["the constants first", "cnst, Memo"],
|
|
842
|
+
])(
|
|
843
|
+
"a file naming one component of an object and one constant, %s, brings that component's file and that model's registration, never every constant",
|
|
844
|
+
async (_, names) => {
|
|
845
|
+
const { appDir, app } = await routeFixture();
|
|
846
|
+
await write(
|
|
847
|
+
path.join(appDir, "client.ts"),
|
|
848
|
+
[
|
|
849
|
+
'export * as cnst from "./lib/cnst";',
|
|
850
|
+
'export { msg, Err, usePage } from "./lib/usePage";',
|
|
851
|
+
'export { fetch, sig } from "./lib/useClient";',
|
|
852
|
+
'export { st, RootStore } from "./lib/st";',
|
|
853
|
+
'export { Memo } from "./lib/memo";',
|
|
854
|
+
"",
|
|
855
|
+
].join("\n"),
|
|
856
|
+
);
|
|
857
|
+
await write(
|
|
858
|
+
path.join(appDir, "lib/memo/Memo.Zone.tsx"),
|
|
859
|
+
'"use client";\nexport const View = Object.freeze({ mark: "memo-view-marker" });\n',
|
|
860
|
+
);
|
|
861
|
+
await write(
|
|
862
|
+
path.join(appDir, "lib/memo/memo.constant.ts"),
|
|
863
|
+
'export const MemoStatus = Object.freeze({ mark: "memo-status-marker" });\n',
|
|
864
|
+
);
|
|
865
|
+
await write(
|
|
866
|
+
path.join(appDir, "lib/__client/memo.cnst.ts"),
|
|
867
|
+
'import * as cnst from "../memo/memo.constant";\nexport const memo = Object.freeze({ mark: "piece:memo.cnst", cnst });\n',
|
|
868
|
+
);
|
|
869
|
+
const entry = path.join(appDir, "ui/Status.tsx");
|
|
870
|
+
await write(
|
|
871
|
+
entry,
|
|
872
|
+
`"use client";\nimport { ${names} } from "@apps/demo/client";\nexport const Status = () => [Memo.Zone.View, cnst.MemoStatus, "status-ui-marker"];\n`,
|
|
873
|
+
);
|
|
874
|
+
await build(app, entry);
|
|
875
|
+
|
|
876
|
+
const browser = await bundledText(path.join(appDir, ".akan/artifact/client"));
|
|
877
|
+
for (const marker of ["status-ui-marker", "memo-view-marker", "memo-status-marker", "piece:memo.cnst"])
|
|
878
|
+
expect(browser).toContain(marker);
|
|
879
|
+
for (const marker of ["cnst-marker", "other-ui-marker", ...assembledMarkers, '"runtime-marker"'])
|
|
880
|
+
expect(browser).not.toContain(marker);
|
|
881
|
+
},
|
|
882
|
+
);
|
|
883
|
+
|
|
884
|
+
for (const file of [StoreBootstrap.pageRuntime, StoreBootstrap.baseDescriptors, ...StoreBootstrap.assembled])
|
|
885
|
+
test(`an app not synced to lib/${file}.ts keeps the whole runtime in its browser chunks and is told to sync`, async () => {
|
|
886
|
+
const { appDir, app, warnings } = await routeFixture();
|
|
887
|
+
await Bun.file(path.join(appDir, `lib/${file}.ts`)).delete();
|
|
888
|
+
|
|
889
|
+
await build(app, path.join(appDir, "ui/A.tsx"));
|
|
890
|
+
|
|
891
|
+
const browser = await bundledText(path.join(appDir, ".akan/artifact/client"));
|
|
892
|
+
for (const marker of ['"runtime-marker"', '"store-marker"']) expect(browser).toContain(marker);
|
|
893
|
+
expect(warnings).toEqual([expect.stringContaining("Run `akan sync demo`")]);
|
|
894
|
+
expect(warnings[0]).toContain("runtime files of demo or a lib it mounts are missing");
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
test("a route's browser build answers a module piece with descriptors read from the signal, not by its macro", async () => {
|
|
898
|
+
const { root, appDir } = await routeFixture();
|
|
899
|
+
for (const scope of ["apps/demo", "libs/kit"]) await write(path.join(root, scope, "lib/sig.ts"), signalFixture);
|
|
900
|
+
await write(path.join(appDir, "lib/__client/draft.fetch.ts"), signalPiece);
|
|
901
|
+
const entry = path.join(appDir, "ui/Fetch.tsx");
|
|
902
|
+
await write(
|
|
903
|
+
entry,
|
|
904
|
+
'"use client";\nimport { descriptors } from "@apps/demo/lib/__client/draft.fetch";\nexport const Fetch = () => descriptors;\n',
|
|
905
|
+
);
|
|
906
|
+
|
|
907
|
+
const built = await printedInOwnProcess(
|
|
908
|
+
`
|
|
909
|
+
const { RouteClientBuilder } = await import(${JSON.stringify(path.join(import.meta.dir, "routeClientBuilder.ts"))});
|
|
910
|
+
const { SignalDescriptors } = await import(${JSON.stringify(path.join(import.meta.dir, "../transforms/signalDescriptors.ts"))});
|
|
911
|
+
const [root, entry, barrelImports] = ${JSON.stringify([root, entry, fixtureBarrels])};
|
|
912
|
+
let answered = 0;
|
|
913
|
+
const inline = SignalDescriptors.prototype.inline;
|
|
914
|
+
SignalDescriptors.prototype.inline = async function (...args) {
|
|
915
|
+
const contents = await inline.apply(this, args);
|
|
916
|
+
if (contents !== null) answered += 1;
|
|
917
|
+
return contents;
|
|
918
|
+
};
|
|
919
|
+
const warnings = [];
|
|
920
|
+
const app = {
|
|
921
|
+
name: "demo",
|
|
922
|
+
cwdPath: root + "/apps/demo",
|
|
923
|
+
dist: { cwdPath: root + "/dist/apps/demo" },
|
|
924
|
+
workspace: { workspaceRoot: root },
|
|
925
|
+
getConfig: async () => ({ barrelImports, optimizeImports: [] }),
|
|
926
|
+
getTsConfig: async () => ({ compilerOptions: { paths: { "@apps/*": ["./apps/*"], "@libs/*": ["./libs/*"] } } }),
|
|
927
|
+
getPublicEnv: () => ({}),
|
|
928
|
+
logger: { warn: (message) => warnings.push(message) },
|
|
929
|
+
verbose: () => undefined,
|
|
930
|
+
};
|
|
931
|
+
await new RouteClientBuilder({ app, seeds: [], entries: [entry], artifact: {}, browser: "chunks" }).build();
|
|
932
|
+
console.log(JSON.stringify({ answered, warnings }));
|
|
933
|
+
`,
|
|
934
|
+
root,
|
|
935
|
+
);
|
|
936
|
+
|
|
937
|
+
expect(built).toEqual({ answered: 1, warnings: [] });
|
|
938
|
+
expect(await bundledText(path.join(appDir, ".akan/artifact/client"))).toContain("draft-descriptor-ref");
|
|
939
|
+
}, 30_000);
|
|
940
|
+
|
|
941
|
+
test("an app whose modules cannot be read keeps the whole runtime in its browser chunks and is told what failed", async () => {
|
|
942
|
+
const { appDir, app, warnings } = await routeFixture();
|
|
943
|
+
const read = spyOn(RouteRuntime, "read").mockRejectedValue(new Error("memo.store.ts is unreadable"));
|
|
944
|
+
try {
|
|
945
|
+
await build(app, path.join(appDir, "ui/A.tsx"));
|
|
946
|
+
} finally {
|
|
947
|
+
read.mockRestore();
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
const browser = await bundledText(path.join(appDir, ".akan/artifact/client"));
|
|
951
|
+
for (const marker of ['"runtime-marker"', '"store-marker"']) expect(browser).toContain(marker);
|
|
952
|
+
expect(warnings).toEqual([
|
|
953
|
+
expect.stringContaining(
|
|
954
|
+
"the modules of demo or a lib it mounts could not be read (memo.store.ts is unreadable)",
|
|
955
|
+
),
|
|
956
|
+
]);
|
|
957
|
+
expect(warnings[0]).toContain("Fix that, then run `akan sync demo` and build again.");
|
|
958
|
+
expect(warnings[0]).not.toContain("missing");
|
|
959
|
+
});
|
|
960
|
+
});
|
|
961
|
+
|
|
389
962
|
test("a route reaching a lib's cnst through its client barrel carries no module UI", async () => {
|
|
390
963
|
const { root, appDir, app } = await writeBarrelFixture();
|
|
391
964
|
|
|
@@ -428,14 +1001,9 @@ describe("route client store bootstrap", () => {
|
|
|
428
1001
|
await write(uiEntry, 'export { ClientPathWrapper } from "./System/Client";\n');
|
|
429
1002
|
await write(clientEntry, '"use client";\nexport const ClientPathWrapper = () => null;\n');
|
|
430
1003
|
|
|
431
|
-
const entryFiles = new Map([
|
|
432
|
-
["akanjs/ui", uiEntry],
|
|
433
|
-
["akanjs/ui/System/Client.tsx", clientEntry],
|
|
434
|
-
]);
|
|
435
1004
|
const discovery = new GraphClientEntryDiscovery({ barrelImports: ["akanjs/ui"] }, async (specifier) => {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
return { pkgName: specifier, entryFile, pkgDir: path.dirname(entryFile), preserveFilePath: true };
|
|
1005
|
+
if (specifier !== "akanjs/ui") return null;
|
|
1006
|
+
return { pkgName: specifier, entryFile: uiEntry, pkgDir: path.dirname(uiEntry), preserveFilePath: true };
|
|
439
1007
|
});
|
|
440
1008
|
|
|
441
1009
|
expect(await discovery.discover([seed])).toEqual([clientEntry]);
|