@akanjs/devkit 3.3.0-rc.37 → 3.3.0-rc.39
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 +65 -0
- package/app/applicationBuildRunner.ts +7 -1
- package/app/dictionarySizes.ts +2 -5
- package/app/routeFilesReport.test.ts +59 -0
- package/app/routeFilesReport.ts +46 -0
- package/app/routeJsBudget.ts +18 -4
- package/artifact/storeBootstrap.ts +5 -1
- package/biome.base.json +1 -3
- package/codeAgent/skills/akan-page/SKILL.md +28 -7
- package/executors/clientRuntimeKeys.test.ts +72 -1
- package/executors/sysExecutor.ts +10 -8
- package/frontendBuild/allRoutesBuilder.ts +20 -8
- package/frontendBuild/buildRouteClient.test.ts +65 -0
- package/frontendBuild/clientBuildTypes.ts +11 -0
- package/frontendBuild/clientEntriesBundler.ts +21 -11
- package/frontendBuild/clientEntryDiscovery.test.ts +213 -0
- package/frontendBuild/clientEntryDiscovery.ts +49 -8
- package/frontendBuild/devBarrelImports.test.ts +54 -0
- package/frontendBuild/devBarrelImports.ts +1 -0
- package/frontendBuild/dictionaryAssetBuilder.test.ts +12 -4
- package/frontendBuild/dictionaryAssetBuilder.ts +20 -7
- package/frontendBuild/dictionaryConstants.ts +55 -1
- package/frontendBuild/dictionaryPacking.test.ts +58 -0
- package/frontendBuild/dictionaryPacking.ts +43 -0
- package/frontendBuild/dictionaryRoutes.test.ts +65 -0
- package/frontendBuild/dictionaryRoutes.ts +3 -1
- package/frontendBuild/precompressArtifacts.test.ts +22 -0
- package/frontendBuild/precompressArtifacts.ts +18 -11
- package/frontendBuild/renderedEntries.ts +144 -0
- package/frontendBuild/routeClientBuilder.ts +65 -27
- package/frontendBuild/routeHandoffs.test.ts +10 -0
- package/frontendBuild/routeHandoffs.ts +3 -1
- package/frontendBuild/routeModulePreloads.test.ts +32 -0
- package/frontendBuild/routeModulePreloads.ts +20 -11
- package/frontendBuild/routeRuntimeCheck.test.ts +23 -0
- package/frontendBuild/routeRuntimeCheck.ts +10 -3
- package/frontendBuild/routeRuntimePays.test.ts +7 -1
- package/lint/biomeBase.test.ts +23 -3
- package/package.json +3 -3
- package/quality/dictionaryKeys.test.ts +185 -2
- package/quality/dictionaryKeys.ts +82 -9
- package/quality/objectImportReport.ts +6 -3
- package/quality/translatorBindings.ts +187 -0
- package/transforms/barrelImportsPlugin.ts +56 -35
- package/transforms/exportReach.test.ts +162 -0
- package/transforms/exportReach.ts +308 -0
- package/transforms/moduleParts.test.ts +225 -0
- package/transforms/moduleParts.ts +418 -0
- package/transforms/objectMemberImports.test.ts +289 -7
- package/transforms/objectMemberImports.ts +92 -58
- package/transforms/objectMemberLookup.ts +150 -0
- package/transforms/objectModule.test.ts +72 -2
- package/transforms/objectModule.ts +31 -7
- 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/workspace/scanInfo.ts +24 -0
|
@@ -6,13 +6,15 @@ import { type ClientRuntimeScope, StoreBootstrap } from "../artifact/storeBootst
|
|
|
6
6
|
import type { App } from "../commandDecorators";
|
|
7
7
|
import { type RouteRuntimeBuildReport, RouteRuntimeReport } from "../quality/routeRuntimeReport";
|
|
8
8
|
import { createBarrelImportsPlugin } from "../transforms/barrelImportsPlugin";
|
|
9
|
+
import { ModuleParts } from "../transforms/moduleParts";
|
|
9
10
|
import { loaderFor } from "../transforms/moduleSyntax";
|
|
11
|
+
import { PartModules } from "../transforms/partModules";
|
|
10
12
|
import { ReactIconImports } from "../transforms/reactIconImports";
|
|
11
13
|
import { RouteRuntime } from "../transforms/routeRuntime";
|
|
12
14
|
import type { RouteRuntimeBundle } from "../transforms/routeRuntimeGraph";
|
|
13
15
|
import { scanUseClientExports, toClientReferencePath } from "../transforms/rscUseClientTransform";
|
|
14
16
|
import { SignalDescriptors } from "../transforms/signalDescriptors";
|
|
15
|
-
import type { ClientBundleTarget, ClientEntryDiscovery, ClientModuleImport } from "./clientBuildTypes";
|
|
17
|
+
import type { AskedExports, ClientBundleTarget, ClientEntryDiscovery, ClientModuleImport } from "./clientBuildTypes";
|
|
16
18
|
import { ClientEntriesBundler } from "./clientEntriesBundler";
|
|
17
19
|
import { GraphClientEntryDiscovery } from "./clientEntryDiscovery";
|
|
18
20
|
import { CsrDevPaths } from "./csrDevPaths";
|
|
@@ -47,6 +49,8 @@ export interface BuildRouteClientOptions {
|
|
|
47
49
|
entriesByRoute?: ReadonlyMap<string, readonly string[]>;
|
|
48
50
|
/** The entries each route loads first, which its size is measured over. Defaults to `entriesByRoute`. */
|
|
49
51
|
sizedEntriesByRoute?: ReadonlyMap<string, readonly string[]>;
|
|
52
|
+
/** The exports each route asks of an entry it loads first; an entry left out, or null, is asked for all of them. */
|
|
53
|
+
askedByRoute?: ReadonlyMap<string, AskedExports>;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
export interface BuildRouteClientResult {
|
|
@@ -67,6 +71,8 @@ export interface BuildRouteClientResult {
|
|
|
67
71
|
interface BootstrapEntries {
|
|
68
72
|
buildEntries: string[];
|
|
69
73
|
originalByBuildEntry: Map<string, string>;
|
|
74
|
+
//? Only for an entry built as several: the export names each of its build entries holds.
|
|
75
|
+
namesByBuildEntry?: Map<string, readonly string[]>;
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
interface NarrowedBuild {
|
|
@@ -94,6 +100,8 @@ export class RouteClientBuilder {
|
|
|
94
100
|
#browser: "chunks" | "registry";
|
|
95
101
|
#entriesByRoute?: ReadonlyMap<string, readonly string[]>;
|
|
96
102
|
#sizedEntriesByRoute?: ReadonlyMap<string, readonly string[]>;
|
|
103
|
+
#askedByRoute?: ReadonlyMap<string, AskedExports>;
|
|
104
|
+
readonly #parts = new Map<string, ModuleParts | null>();
|
|
97
105
|
|
|
98
106
|
constructor(options: BuildRouteClientOptions) {
|
|
99
107
|
this.#app = options.app;
|
|
@@ -106,6 +114,7 @@ export class RouteClientBuilder {
|
|
|
106
114
|
this.#browser = options.browser ?? (this.#command === "start" ? "registry" : "chunks");
|
|
107
115
|
this.#entriesByRoute = options.entriesByRoute;
|
|
108
116
|
this.#sizedEntriesByRoute = options.sizedEntriesByRoute;
|
|
117
|
+
this.#askedByRoute = options.askedByRoute;
|
|
109
118
|
}
|
|
110
119
|
|
|
111
120
|
async build(): Promise<BuildRouteClientResult> {
|
|
@@ -176,7 +185,7 @@ export class RouteClientBuilder {
|
|
|
176
185
|
const buildEntry = path.resolve(entry);
|
|
177
186
|
const originalEntry = path.resolve(bootstrapEntries.originalByBuildEntry.get(buildEntry) ?? buildEntry);
|
|
178
187
|
if (!acceptedEntries.has(originalEntry)) continue;
|
|
179
|
-
const deps = new Set<string>([originalEntry]);
|
|
188
|
+
const deps = new Set<string>(clientDepsByEntry[originalEntry] ?? [originalEntry]);
|
|
180
189
|
for (const dep of referenceBundle.entryDepsByAbsPath.get(buildEntry) ?? []) deps.add(path.resolve(dep));
|
|
181
190
|
const sortedDeps = [...deps].sort();
|
|
182
191
|
clientDepsByEntry[originalEntry] = sortedDeps;
|
|
@@ -355,21 +364,33 @@ export class RouteClientBuilder {
|
|
|
355
364
|
return path.join(this.#command === "build" ? this.#app.dist.cwdPath : this.#app.cwdPath, ".akan/artifact");
|
|
356
365
|
}
|
|
357
366
|
|
|
358
|
-
#sizedBuildEntries(
|
|
359
|
-
const
|
|
367
|
+
#sizedBuildEntries(entries: BootstrapEntries): Map<string, string[]> {
|
|
368
|
+
const buildEntriesOf = RouteClientBuilder.#buildEntriesOf(entries);
|
|
360
369
|
return new Map(
|
|
361
|
-
[...(this.#sizedEntriesByRoute ?? this.#entriesByRoute ?? [])].map(([route, held]) =>
|
|
362
|
-
route
|
|
363
|
-
held.
|
|
364
|
-
|
|
370
|
+
[...(this.#sizedEntriesByRoute ?? this.#entriesByRoute ?? [])].map(([route, held]) => {
|
|
371
|
+
const asked = this.#askedByRoute?.get(route);
|
|
372
|
+
return [route, held.flatMap((entry) => buildEntriesOf(entry, asked?.get(path.resolve(entry))))];
|
|
373
|
+
}),
|
|
365
374
|
);
|
|
366
375
|
}
|
|
367
376
|
|
|
377
|
+
//? An entry built as several answers with the ones holding a name asked, and with all of them asked for none.
|
|
378
|
+
static #buildEntriesOf({ originalByBuildEntry, namesByBuildEntry }: BootstrapEntries) {
|
|
379
|
+
const built = new Map<string, string[]>();
|
|
380
|
+
for (const [buildEntry, original] of originalByBuildEntry) built.getOrInsert(original, []).push(buildEntry);
|
|
381
|
+
return (entry: string, asked?: readonly string[] | null): string[] => {
|
|
382
|
+
const buildEntries = built.get(path.resolve(entry)) ?? [path.resolve(entry)];
|
|
383
|
+
if (!asked) return buildEntries;
|
|
384
|
+
return buildEntries.filter((buildEntry) => {
|
|
385
|
+
const names = namesByBuildEntry?.get(buildEntry);
|
|
386
|
+
return !names || names.some((name) => asked.includes(name));
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
368
391
|
#check({ entries, kept, bundle, runtime: routeRuntime }: NarrowedBuild): boolean {
|
|
369
392
|
const { workspaceRoot } = this.#app.workspace;
|
|
370
|
-
const
|
|
371
|
-
[...entries.originalByBuildEntry].map(([buildEntry, original]) => [original, buildEntry]),
|
|
372
|
-
);
|
|
393
|
+
const buildEntriesOf = RouteClientBuilder.#buildEntriesOf(entries);
|
|
373
394
|
const check = new RouteRuntimeCheck(workspaceRoot, bundle.graph, {
|
|
374
395
|
entries: new Map([...entries.originalByBuildEntry].filter(([, entry]) => !kept.has(entry))),
|
|
375
396
|
wholeReaders: routeRuntime.wholeReaders,
|
|
@@ -377,7 +398,7 @@ export class RouteClientBuilder {
|
|
|
377
398
|
routes: new Map(
|
|
378
399
|
[...(this.#entriesByRoute ?? [])].map(([route, held]) => [
|
|
379
400
|
route,
|
|
380
|
-
held.
|
|
401
|
+
held.flatMap((entry) => buildEntriesOf(entry)),
|
|
381
402
|
]),
|
|
382
403
|
),
|
|
383
404
|
});
|
|
@@ -419,6 +440,7 @@ export class RouteClientBuilder {
|
|
|
419
440
|
),
|
|
420
441
|
external: vendorFiles.specifiers,
|
|
421
442
|
routeRuntime,
|
|
443
|
+
...(this.#command === "build" ? { parts: this.#parts } : {}),
|
|
422
444
|
}),
|
|
423
445
|
],
|
|
424
446
|
external: vendorFiles.specifiers,
|
|
@@ -468,37 +490,53 @@ export class RouteClientBuilder {
|
|
|
468
490
|
await mkdir(outdir, { recursive: true });
|
|
469
491
|
|
|
470
492
|
const originalByBuildEntry = new Map<string, string>();
|
|
493
|
+
const namesByBuildEntry = new Map<string, readonly string[]>();
|
|
494
|
+
const { workspaceRoot } = this.#app.workspace;
|
|
471
495
|
const buildEntries = await Promise.all(
|
|
472
496
|
entries.map(async (entry) => {
|
|
473
497
|
const absEntry = path.resolve(entry);
|
|
474
498
|
const whole = narrowed?.kept.has(absEntry) ? wholeByOriginal.get(absEntry) : undefined;
|
|
475
499
|
if (whole) {
|
|
476
500
|
originalByBuildEntry.set(whole, absEntry);
|
|
477
|
-
return whole;
|
|
501
|
+
return [whole];
|
|
478
502
|
}
|
|
479
503
|
const hash = Bun.hash(`${this.#app.name}\n${absEntry}`).toString(36);
|
|
480
504
|
const base = path.basename(absEntry).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
481
|
-
const
|
|
482
|
-
const exportNames =
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
505
|
+
const source = await Bun.file(absEntry).text();
|
|
506
|
+
const exportNames = scanUseClientExports(source, absEntry, workspaceRoot);
|
|
507
|
+
const byExport = scope === "page" && this.#command === "build" && PartModules.splits(workspaceRoot, absEntry);
|
|
508
|
+
const groups = byExport ? RouteClientBuilder.#exportGroups(source, absEntry, exportNames) : [exportNames];
|
|
509
|
+
return await Promise.all(
|
|
510
|
+
groups.map(async (names, index) => {
|
|
511
|
+
const wrapperEntry = path.join(outdir, `${base}-${hash}${groups.length > 1 ? `-${index}` : ""}.tsx`);
|
|
512
|
+
await Bun.write(
|
|
513
|
+
wrapperEntry,
|
|
514
|
+
RouteClientBuilder.createStoreBootstrapEntrySource({
|
|
515
|
+
appName: this.#app.name,
|
|
516
|
+
originalEntry: absEntry,
|
|
517
|
+
exportNames: names,
|
|
518
|
+
scope,
|
|
519
|
+
}),
|
|
520
|
+
);
|
|
521
|
+
originalByBuildEntry.set(path.resolve(wrapperEntry), absEntry);
|
|
522
|
+
if (groups.length > 1) namesByBuildEntry.set(path.resolve(wrapperEntry), names);
|
|
523
|
+
return wrapperEntry;
|
|
490
524
|
}),
|
|
491
525
|
);
|
|
492
|
-
originalByBuildEntry.set(path.resolve(wrapperEntry), absEntry);
|
|
493
|
-
return wrapperEntry;
|
|
494
526
|
}),
|
|
495
527
|
);
|
|
496
528
|
|
|
497
|
-
return { buildEntries, originalByBuildEntry };
|
|
529
|
+
return { buildEntries: buildEntries.flat(), originalByBuildEntry, namesByBuildEntry };
|
|
498
530
|
}
|
|
499
531
|
|
|
500
|
-
|
|
501
|
-
|
|
532
|
+
//? Names one part of the file holds share a build entry. The parts are read from the file as written, and a bundle
|
|
533
|
+
//? may place a name elsewhere after its rewrites: then a build entry only loads more than the names it holds need.
|
|
534
|
+
static #exportGroups(source: string, absEntry: string, names: string[]): string[][] {
|
|
535
|
+
const parts = names.length > 0 ? ModuleParts.read(source, absEntry) : null;
|
|
536
|
+
if (!parts) return [names];
|
|
537
|
+
const groups = new Map<string, string[]>();
|
|
538
|
+
for (const name of names) groups.getOrInsert(parts.partOf(name) ?? "", []).push(name);
|
|
539
|
+
return [...groups.values()];
|
|
502
540
|
}
|
|
503
541
|
|
|
504
542
|
static normalizeNamedDefaultFunctionForFastRefresh(
|
|
@@ -108,6 +108,16 @@ describe("the models a route's server modules hand to client components", () =>
|
|
|
108
108
|
expect(read).toEqual({ referenceFiles: [], unread: null });
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
+
test("do not count a store, whose actions name and pick models only in the browser", async () => {
|
|
112
|
+
const read = await readOf({
|
|
113
|
+
"apps/demo/page/board.tsx": `${client}export const Board = () => fetch.initMemoInBoard();\n`,
|
|
114
|
+
"apps/demo/lib/note/note.store.ts": `${client}export const open = (id: string) => [fetch.viewNote(id), fetch.slice.tag];\n`,
|
|
115
|
+
"apps/demo/lib/tag/tag.store.ts": `${client}export const any = (name: string) => (fetch as never)[name];\n`,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(read).toEqual({ referenceFiles: [referenceOf("memo")], unread: null });
|
|
119
|
+
});
|
|
120
|
+
|
|
111
121
|
test("are every model once the server barrel's `fetch` is indexed, passed on or taken apart", async () => {
|
|
112
122
|
const taken = 'import { fetch } from "@apps/demo/server";\n';
|
|
113
123
|
const unreadOf = async (name: string, body: string) =>
|
|
@@ -18,6 +18,8 @@ const capitalize = (name: string) => name.charAt(0).toUpperCase() + name.slice(1
|
|
|
18
18
|
const serverFetchSource =
|
|
19
19
|
/^(?:@(?:apps|libs)\/[^/]+\/(?:server|lib\/(?:sig|useServer))|\.{1,2}\/(?:.+\/)?(?:server|sig|useServer))$/;
|
|
20
20
|
const generatedFile = /^(?:apps|libs)\/[^/]+\/(?:(?:server|client)\.ts$|lib\/[^/]+\.ts$|lib\/__client\/)/;
|
|
21
|
+
//? A store's actions run in the browser, so what one names is never handed over while the server renders.
|
|
22
|
+
const storeFile = /\.store\.ts$/;
|
|
21
23
|
const handoffName = /\b(?:init|view|edit)[A-Z]|\bget[A-Z]\w*(?:Init|View|Edit)\b|\bslice\b/;
|
|
22
24
|
const handoffMember = /^(?:(?:init|view|edit)[A-Z]|get[A-Z]\w*(?:Init|View|Edit)$|slice$)/;
|
|
23
25
|
|
|
@@ -53,7 +55,7 @@ export class RouteHandoffs {
|
|
|
53
55
|
if (known) return known;
|
|
54
56
|
const read = (async (): Promise<FileRead> => {
|
|
55
57
|
const fileName = this.#runtime.fileNameOf(absPath);
|
|
56
|
-
if (!fileName || generatedFile.test(fileName)) return { models: [], unread: null };
|
|
58
|
+
if (!fileName || generatedFile.test(fileName) || storeFile.test(fileName)) return { models: [], unread: null };
|
|
57
59
|
const text = await Bun.file(absPath).text();
|
|
58
60
|
const serverFetchLine = RouteHandoffs.#serverFetchLineOf(fileName, text);
|
|
59
61
|
if (serverFetchLine)
|
|
@@ -56,4 +56,36 @@ describe("RouteModulePreloads", () => {
|
|
|
56
56
|
],
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
|
+
|
|
60
|
+
test("a route asking an entry for some exports lists the chunks of those alone, and of them all when it asks for the file", () => {
|
|
61
|
+
const pair = entry("Pair");
|
|
62
|
+
const byExport = new RouteModulePreloads({
|
|
63
|
+
runtimeChunks: { runtime: [], vendors: {} },
|
|
64
|
+
entriesByRoute: new Map([
|
|
65
|
+
["/a", [pair]],
|
|
66
|
+
["/b", [pair]],
|
|
67
|
+
["/whole", [pair]],
|
|
68
|
+
["/unasked", [pair]],
|
|
69
|
+
]),
|
|
70
|
+
askedByRoute: new Map<string, Map<string, string[] | null>>([
|
|
71
|
+
["/a", new Map([[pair, ["A"]]])],
|
|
72
|
+
["/b", new Map([[pair, ["B", "Missing"]]])],
|
|
73
|
+
["/whole", new Map([[pair, null]])],
|
|
74
|
+
]),
|
|
75
|
+
clientManifest: {
|
|
76
|
+
"apps/demo/ui/Pair.tsx#A": { ...row("/_akan/client/a.js", "/_akan/client/chunks/s.js"), name: "A" },
|
|
77
|
+
"apps/demo/ui/Pair.tsx#B": { ...row("/_akan/client/b.js", "/_akan/client/chunks/s.js"), name: "B" },
|
|
78
|
+
},
|
|
79
|
+
externalsByChunkUrl: {},
|
|
80
|
+
workspaceRoot: root,
|
|
81
|
+
});
|
|
82
|
+
const both = ["/_akan/client/a.js", "/_akan/client/chunks/s.js", "/_akan/client/b.js"];
|
|
83
|
+
|
|
84
|
+
expect(byExport.modulesByRoute()).toEqual({
|
|
85
|
+
"/a": ["/_akan/client/a.js", "/_akan/client/chunks/s.js"],
|
|
86
|
+
"/b": ["/_akan/client/b.js", "/_akan/client/chunks/s.js"],
|
|
87
|
+
"/whole": both,
|
|
88
|
+
"/unasked": both,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
59
91
|
});
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { ClientManifest } from "akanjs/server";
|
|
2
2
|
import { ModulePreloadPlan, type ModulePreloadTable } from "akanjs/server/artifact/modulePreloadPlan";
|
|
3
3
|
import { toClientReferencePath } from "../transforms/rscUseClientTransform";
|
|
4
|
+
import type { AskedExports } from "./clientBuildTypes";
|
|
4
5
|
|
|
5
6
|
export type RuntimeChunks = Pick<ModulePreloadTable, "runtime" | "vendors">;
|
|
6
7
|
|
|
7
8
|
export interface RouteModulePreloadsInput {
|
|
8
9
|
runtimeChunks: RuntimeChunks;
|
|
9
10
|
entriesByRoute: Map<string, string[]>;
|
|
11
|
+
/** The exports each route asks of its entries; an entry left out, or null, is preloaded with all of them. */
|
|
12
|
+
askedByRoute?: ReadonlyMap<string, AskedExports>;
|
|
10
13
|
clientManifest: ClientManifest;
|
|
11
14
|
externalsByChunkUrl: Record<string, string[]>;
|
|
12
15
|
workspaceRoot: string;
|
|
@@ -15,13 +18,13 @@ export interface RouteModulePreloadsInput {
|
|
|
15
18
|
export class RouteModulePreloads {
|
|
16
19
|
readonly table: ModulePreloadTable;
|
|
17
20
|
#input: RouteModulePreloadsInput;
|
|
18
|
-
#chunksByReferenceId = new Map<string,
|
|
21
|
+
#chunksByReferenceId = new Map<string, Map<string, string[]>>();
|
|
19
22
|
|
|
20
23
|
constructor(input: RouteModulePreloadsInput) {
|
|
21
24
|
this.#input = input;
|
|
22
25
|
for (const [key, row] of Object.entries(input.clientManifest)) {
|
|
23
|
-
const
|
|
24
|
-
|
|
26
|
+
const hash = key.lastIndexOf("#");
|
|
27
|
+
this.#chunksByReferenceId.getOrInsert(key.slice(0, hash), new Map()).set(key.slice(hash + 1), row.chunks);
|
|
25
28
|
}
|
|
26
29
|
this.table = {
|
|
27
30
|
...input.runtimeChunks,
|
|
@@ -39,14 +42,20 @@ export class RouteModulePreloads {
|
|
|
39
42
|
modulesByRoute(): Record<string, string[]> {
|
|
40
43
|
const plan = new ModulePreloadPlan(this.table);
|
|
41
44
|
return Object.fromEntries(
|
|
42
|
-
[...this.#input.entriesByRoute].map(([routeId, entries]) =>
|
|
43
|
-
routeId
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
]),
|
|
45
|
+
[...this.#input.entriesByRoute].map(([routeId, entries]) => {
|
|
46
|
+
const asked = this.#input.askedByRoute?.get(routeId);
|
|
47
|
+
return [
|
|
48
|
+
routeId,
|
|
49
|
+
plan.urlsOf([...new Set(entries.flatMap((entry) => this.#chunksOf(entry, asked?.get(entry))))]),
|
|
50
|
+
];
|
|
51
|
+
}),
|
|
50
52
|
);
|
|
51
53
|
}
|
|
54
|
+
|
|
55
|
+
#chunksOf(entry: string, names?: readonly string[] | null): string[] {
|
|
56
|
+
const chunksByName = this.#chunksByReferenceId.get(toClientReferencePath(entry, this.#input.workspaceRoot));
|
|
57
|
+
if (!chunksByName) return [];
|
|
58
|
+
const rows = names ? names.map((name) => chunksByName.get(name) ?? []) : [...chunksByName.values()];
|
|
59
|
+
return rows.flat();
|
|
60
|
+
}
|
|
52
61
|
}
|
|
@@ -72,6 +72,29 @@ describe("what a build loading per module checks in its own output", () => {
|
|
|
72
72
|
expect(failuresOf({ imports: lazy, chunks: apart })).toEqual([]);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
+
test("a file bundled in parts is checked part by part: only the chunk of the part importing a piece has to reach it", () => {
|
|
76
|
+
const graph = graphOf({
|
|
77
|
+
imports: { [card]: [storePiece], [storePiece]: [] },
|
|
78
|
+
chunks: { [card]: ["/out/naming.js", "/out/plain.js"], [storePiece]: ["/out/piece.js"] },
|
|
79
|
+
chunkImports: { "/out/naming.js": ["/out/piece.js"] },
|
|
80
|
+
});
|
|
81
|
+
const part = (id: string) => `${abs(card)}?akan-part=${id}`;
|
|
82
|
+
const linked = [
|
|
83
|
+
{ module: part("p0"), imports: [{ path: abs(storePiece), lazy: false }], chunks: ["/out/naming.js"] },
|
|
84
|
+
{ module: part("p1"), imports: [], chunks: ["/out/plain.js"] },
|
|
85
|
+
{ module: abs(storePiece), imports: [], chunks: ["/out/piece.js"] },
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
expect(new RouteRuntimeCheck(root, graph, null).failures).toHaveLength(1);
|
|
89
|
+
expect(new RouteRuntimeCheck(root, { ...graph, linked }, null).failures).toEqual([]);
|
|
90
|
+
const misplaced = linked.map((input) =>
|
|
91
|
+
input.module === part("p0") ? { ...input, chunks: ["/out/plain.js"] } : input,
|
|
92
|
+
);
|
|
93
|
+
expect(new RouteRuntimeCheck(root, { ...graph, linked: misplaced }, null).failures).toEqual([
|
|
94
|
+
"apps/demo/ui/Card.tsx?akan-part=p0 needs apps/demo/lib/__client/memo.st.ts loaded first, but its chunk plain.js does not import the chunk holding that piece",
|
|
95
|
+
]);
|
|
96
|
+
});
|
|
97
|
+
|
|
75
98
|
test("no store file is imported back by a runtime piece that a file it imports loads", () => {
|
|
76
99
|
const helper = "apps/demo/webkit/relabel.ts";
|
|
77
100
|
const cycle = { [storeFile]: [helper], [helper]: [storePiece], [storePiece]: [storeFile] };
|
|
@@ -119,9 +119,16 @@ export class RouteRuntimeCheck {
|
|
|
119
119
|
|
|
120
120
|
#unordered(): string[] {
|
|
121
121
|
const failures: string[] = [];
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
const linked =
|
|
123
|
+
this.#graph.linked ??
|
|
124
|
+
[...this.#graph.chunksByModule].map(([module, chunks]) => ({
|
|
125
|
+
module,
|
|
126
|
+
chunks,
|
|
127
|
+
imports: this.#graph.importsByModule.get(module) ?? [],
|
|
128
|
+
}));
|
|
129
|
+
for (const { module, chunks, imports } of linked)
|
|
130
|
+
for (const { path: piece, lazy } of imports) {
|
|
131
|
+
if (lazy || !this.#isPiece(piece)) continue;
|
|
125
132
|
const holdersOf = this.#loadedFirstFor(piece).map((first) => this.#graph.chunksByModule.get(first) ?? []);
|
|
126
133
|
const unlinked = chunks.find((chunk) =>
|
|
127
134
|
holdersOf.some((holders) => !holders.some((holder) => this.#reachedBy(chunk).has(holder))),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { tempDirs, writeText } from "../test/testHelpers";
|
|
4
|
+
import { chunkBrotliBytesOf } from "./precompressArtifacts";
|
|
4
5
|
import { RouteRuntimePays } from "./routeRuntimePays";
|
|
5
6
|
|
|
6
7
|
const makeTempRoot = tempDirs("akan-devkit-route-pays-");
|
|
@@ -132,6 +133,11 @@ describe("which entries keep the whole runtime because per module made a page no
|
|
|
132
133
|
["/memo", ["Memo"]],
|
|
133
134
|
]),
|
|
134
135
|
);
|
|
135
|
-
|
|
136
|
+
const served = (bytes: number) => chunkBrotliBytesOf(new TextEncoder().encode("x".repeat(bytes)));
|
|
137
|
+
expect(served(100)).toBeLessThan(100);
|
|
138
|
+
expect(Object.fromEntries(sizes)).toEqual({
|
|
139
|
+
"/both": served(100) + served(200) + served(400),
|
|
140
|
+
"/memo": served(200) + served(400),
|
|
141
|
+
});
|
|
136
142
|
});
|
|
137
143
|
});
|
package/lint/biomeBase.test.ts
CHANGED
|
@@ -20,6 +20,13 @@ export const Branch = ({ open }: { open: boolean }) => {
|
|
|
20
20
|
};
|
|
21
21
|
`;
|
|
22
22
|
|
|
23
|
+
const execProbe = `export const idOf = (url: string) => {
|
|
24
|
+
const match = /\\/(\\d+)\\/?$/.exec(url);
|
|
25
|
+
return match ? Number(match[1]) : 0;
|
|
26
|
+
};
|
|
27
|
+
export const idOfChained = (url: string) => Number(/\\/(\\d+)\\/?$/.exec(url)?.[1] ?? 0);
|
|
28
|
+
`;
|
|
29
|
+
|
|
23
30
|
const tempDirs: string[] = [];
|
|
24
31
|
|
|
25
32
|
afterAll(async () => {
|
|
@@ -37,17 +44,17 @@ const runBiome = (args: string[], cwd: string) =>
|
|
|
37
44
|
proc.on("close", () => resolve(stdout || stderr));
|
|
38
45
|
});
|
|
39
46
|
|
|
40
|
-
const lintWorkspace = async (files: string[]) => {
|
|
47
|
+
const lintWorkspace = async (files: string[], probe = hookProbe, config: object = { extends: [biomeBaseConfig] }) => {
|
|
41
48
|
const dir = await mkdtemp(path.join(os.tmpdir(), "biome-base-"));
|
|
42
49
|
tempDirs.push(dir);
|
|
43
50
|
//? The base config names its plugins as `./node_modules/@akanjs/devkit/…`, resolved from the extending config's
|
|
44
51
|
//? folder. A junction needs no privilege on Windows, and the type is ignored elsewhere.
|
|
45
52
|
await mkdir(path.join(dir, "node_modules", "@akanjs"), { recursive: true });
|
|
46
53
|
await symlink(devkitDir, path.join(dir, "node_modules", "@akanjs", "devkit"), "junction");
|
|
47
|
-
await writeFile(path.join(dir, "biome.json"), JSON.stringify(
|
|
54
|
+
await writeFile(path.join(dir, "biome.json"), JSON.stringify(config));
|
|
48
55
|
for (const file of files) {
|
|
49
56
|
await mkdir(path.dirname(path.join(dir, file)), { recursive: true });
|
|
50
|
-
await writeFile(path.join(dir, file),
|
|
57
|
+
await writeFile(path.join(dir, file), probe);
|
|
51
58
|
}
|
|
52
59
|
const output = await runBiome(["lint", "--reporter=json", "--max-diagnostics=none", ...files], dir);
|
|
53
60
|
return parseBiomeReport(output).diagnostics ?? [];
|
|
@@ -75,4 +82,17 @@ describe("biome.base.json", () => {
|
|
|
75
82
|
"libs/demo/ui/Probe.tsx:7 error",
|
|
76
83
|
]);
|
|
77
84
|
});
|
|
85
|
+
|
|
86
|
+
test("leaves a null check on RegExp.exec alone, which Biome reads as never null", async () => {
|
|
87
|
+
const unnecessary = (diagnostics: Awaited<ReturnType<typeof lintWorkspace>>) =>
|
|
88
|
+
diagnostics.filter((diagnostic) => diagnostic.category === "lint/suspicious/noUnnecessaryConditions").length;
|
|
89
|
+
|
|
90
|
+
expect(unnecessary(await lintWorkspace(["apps/demo/common/idOf.ts"], execProbe))).toBe(0);
|
|
91
|
+
|
|
92
|
+
//? Pins the Biome 2.5.14 misreading: once this is 0, the base config can turn the rule back on.
|
|
93
|
+
const ruleOnly = {
|
|
94
|
+
linter: { rules: { recommended: false, suspicious: { noUnnecessaryConditions: "warn" } } },
|
|
95
|
+
};
|
|
96
|
+
expect(unnecessary(await lintWorkspace(["apps/demo/common/idOf.ts"], execProbe, ruleOnly))).toBe(2);
|
|
97
|
+
});
|
|
78
98
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/devkit",
|
|
3
|
-
"version": "3.3.0-rc.
|
|
3
|
+
"version": "3.3.0-rc.39",
|
|
4
4
|
"sourceType": "module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"./workspace/getRelatedCnsts": "./workspace/getRelatedCnsts.ts"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@akanjs/language": "3.3.0-rc.
|
|
53
|
+
"@akanjs/language": "3.3.0-rc.39",
|
|
54
54
|
"@earendil-works/pi-agent-core": "1.5.2",
|
|
55
55
|
"@earendil-works/pi-ai": "1.5.2",
|
|
56
56
|
"@earendil-works/pi-codemode": "1.5.2",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@earendil-works/pi-tui": "1.5.2",
|
|
60
60
|
"@inquirer/prompts": "^8.7.3",
|
|
61
61
|
"@tailwindcss/node": "^4.3.3",
|
|
62
|
-
"akanjs": "3.3.0-rc.
|
|
62
|
+
"akanjs": "3.3.0-rc.39",
|
|
63
63
|
"chalk": "^6.0.1",
|
|
64
64
|
"commander": "^15.0.0",
|
|
65
65
|
"dayjs": "^1.11.23",
|