@akanjs/devkit 3.3.0-rc.26 → 3.3.0-rc.28
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 +6 -0
- package/frontendBuild/routeHandoffs.test.ts +26 -0
- package/frontendBuild/routeHandoffs.ts +27 -6
- package/package.json +3 -3
- package/transforms/barrelAnalyzer.ts +7 -1
- package/transforms/barrelImportsPlugin.ts +1 -1
- package/transforms/transforms.test.ts +38 -0
- package/transforms/tsconfigPackageResolver.test.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -487,6 +487,11 @@
|
|
|
487
487
|
- 6ea7242: `akan build`, `akan verify` and `akan start` stop with an error naming the import chain when the server pages bundle would import `react-dom/server` as it loads, instead of building a bundle whose RSC worker throws "react-dom/server is not supported in React Server Components" at boot. A module in the page graph that dynamically imports the app's `server.ts` is the usual cause: it brings the whole server, SSR renderer included, into the pages bundle.
|
|
488
488
|
- 0d5e75e: A stylesheet whose imports use no Tailwind (no `@import "tailwindcss"`, Tailwind at-rule or `theme()` function anywhere in its import graph) is no longer run through the Tailwind compiler: its imports are inlined and it ships without the `/*! tailwindcss … */` banner. A stylesheet that uses Tailwind compiles exactly as before.
|
|
489
489
|
- 36408f1: The route JS budget report no longer counts, and the route build no longer emits, chunks for `"use client"` files that export only hooks, such as the `akanjs/store` field tools, which no page loads. Reported route sizes drop by about 21 KB brotli on every route of `apps/akan` and `apps/minimal`.
|
|
490
|
+
- eb1262f: Two readings that kept a whole app's routes on every model's runtime are gone, so those routes load per module again.
|
|
491
|
+
|
|
492
|
+
- A server file that takes `fetch` from the server barrel (`../useServer`, `@apps/<app>/server`) and only calls endpoints no longer counts every model on every route because some other line says `slice`, such as `ips.slice(0, 1)` on an array. The build now reads what the file does with `fetch` itself: `fetch.init<Model>`, `view<Model>`, `edit<Model>`, their `get` forms and `fetch.slice` still count every model, and so does a `fetch` that is indexed, passed on or taken apart. In a real workspace one such service held all 38 routes of an app.
|
|
493
|
+
- A name `akanjs/ui` re-exports from the package it carries (`SessionContext`, `useAgent`, `AgentProvider`, `httpRunner` and the rest of the agent client) is imported from the file that declares it in an installed `akanjs` too. Installed, those names sit in a folder beside `ui/`, which the import narrowing did not follow, so one import of them pulled the whole `akanjs/ui` barrel and, with it, every model's runtime into the route. A workspace that links the framework source was not affected.
|
|
494
|
+
|
|
490
495
|
- 02cc5db: `akan quality runtime` reports, for each app and library, how many client files read the generated client runtime (`st`, `fetch`, `sig`, a cast to `RootStore`) only by names one module answers, and prints a note, `akan.runtime.whole-scope`, at each file that reads it by a computed key, through a cast, hands it on, re-exports it or imports it whole, so a page that loads that file loads the scope's whole client runtime. The notes never fail a command and change no build: the file works as it is. Each line also says how long reading the scope took. The report reads every name from module source, the store, signal and constant files of the scope and the libraries it loads, and a test checks those names against the ones the generated runtime answers.
|
|
491
496
|
- 98931e4: `akan start` boots the backend while the first base build runs: the backend loads its server graph beside the build and mounts the web surface as soon as the build's artifact is on disk, so the dev server is ready sooner.
|
|
492
497
|
|
|
@@ -507,6 +512,7 @@
|
|
|
507
512
|
- Updated dependencies [e5d3cac]
|
|
508
513
|
- Updated dependencies [c44d068]
|
|
509
514
|
- Updated dependencies [43b44ca]
|
|
515
|
+
- Updated dependencies [6443972]
|
|
510
516
|
- Updated dependencies [af57986]
|
|
511
517
|
- Updated dependencies [f678e80]
|
|
512
518
|
- Updated dependencies [af09c4f]
|
|
@@ -99,6 +99,32 @@ describe("the models a route's server modules hand to client components", () =>
|
|
|
99
99
|
expect(read).toEqual({ referenceFiles: [], unread: null });
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
+
test("do not count a service that calls an endpoint through the server barrel and slices an array of its own", async () => {
|
|
103
|
+
const read = await readOf({
|
|
104
|
+
"apps/demo/lib/memo/memo.service.ts":
|
|
105
|
+
'import { fetch } from "../useServer";\nexport const scan = async (ips: string[]) => [ips.slice(0, 1), await fetch.memoNote(), { fetch: 1 }.fetch];\n',
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(read).toEqual({ referenceFiles: [], unread: null });
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("are every model once the server barrel's `fetch` is indexed, passed on or taken apart", async () => {
|
|
112
|
+
const taken = 'import { fetch } from "@apps/demo/server";\n';
|
|
113
|
+
const unreadOf = async (name: string, body: string) =>
|
|
114
|
+
(await readOf({ [`apps/demo/page/${name}.tsx`]: `${taken}${body}\n` })).unread?.file;
|
|
115
|
+
|
|
116
|
+
expect(
|
|
117
|
+
await unreadOf("indexed", "export const any = (name: string) => [name.slice(1), (fetch as never)[name]];"),
|
|
118
|
+
).toBe("apps/demo/page/indexed.tsx");
|
|
119
|
+
expect(
|
|
120
|
+
await unreadOf("passed", "export const all = (use: (api: unknown) => void) => [[].slice(), use(fetch)];"),
|
|
121
|
+
).toBe("apps/demo/page/passed.tsx");
|
|
122
|
+
expect(
|
|
123
|
+
await unreadOf("apart", "const { viewMemo } = fetch;\nexport const view = (id: string) => viewMemo(id);"),
|
|
124
|
+
).toBe("apps/demo/page/apart.tsx");
|
|
125
|
+
expect(await unreadOf("sliced", "export const tags = () => fetch.slice.tag;")).toBe("apps/demo/page/sliced.tsx");
|
|
126
|
+
});
|
|
127
|
+
|
|
102
128
|
test("name only models with a reference file, so a model the app's sync wrote none for adds nothing", async () => {
|
|
103
129
|
const { demo } = await runtimeFixtureTables();
|
|
104
130
|
const only = new RouteHandoffs(
|
|
@@ -19,6 +19,7 @@ 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
21
|
const handoffName = /\b(?:init|view|edit)[A-Z]|\bget[A-Z]\w*(?:Init|View|Edit)\b|\bslice\b/;
|
|
22
|
+
const handoffMember = /^(?:(?:init|view|edit)[A-Z]|get[A-Z]\w*(?:Init|View|Edit)$|slice$)/;
|
|
22
23
|
|
|
23
24
|
//? Only `fetch.init<Model>`, `view<Model>`, `edit<Model>`, their `get` forms and `fetch.slice` build a handoff object.
|
|
24
25
|
export class RouteHandoffs {
|
|
@@ -77,18 +78,38 @@ export class RouteHandoffs {
|
|
|
77
78
|
static #serverFetchLineOf(fileName: string, text: string): number | null {
|
|
78
79
|
if (!text.includes("fetch") || !handoffName.test(text)) return null;
|
|
79
80
|
const kind = fileName.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
|
|
80
|
-
const source = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest,
|
|
81
|
+
const source = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, kind);
|
|
81
82
|
for (const statement of source.statements) {
|
|
82
83
|
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) continue;
|
|
83
84
|
const clause = statement.importClause;
|
|
84
85
|
if (!clause || clause.isTypeOnly || !serverFetchSource.test(statement.moduleSpecifier.text)) continue;
|
|
85
86
|
const bindings = clause.namedBindings;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (
|
|
87
|
+
if (!bindings) continue;
|
|
88
|
+
const line = source.getLineAndCharacterOfPosition(statement.getStart(source)).line + 1;
|
|
89
|
+
if (ts.isNamespaceImport(bindings)) return line;
|
|
90
|
+
const taken = bindings.elements.find((el) => !el.isTypeOnly && (el.propertyName ?? el.name).text === "fetch");
|
|
91
|
+
if (taken && RouteHandoffs.#handsOver(source, taken.name.text)) return line;
|
|
91
92
|
}
|
|
92
93
|
return null;
|
|
93
94
|
}
|
|
95
|
+
|
|
96
|
+
//? Text alone took `ips.slice(0, 1)` in a service that calls an endpoint for a slice handed over, on every route.
|
|
97
|
+
static #handsOver(source: ts.SourceFile, local: string): boolean {
|
|
98
|
+
const visit = (node: ts.Node): boolean => {
|
|
99
|
+
if (ts.isImportDeclaration(node)) return false;
|
|
100
|
+
if (ts.isIdentifier(node) && node.text === local) {
|
|
101
|
+
const { parent } = node;
|
|
102
|
+
const named =
|
|
103
|
+
(ts.isPropertyAccessExpression(parent) && parent.name === node) ||
|
|
104
|
+
((ts.isPropertyAssignment(parent) || ts.isMethodDeclaration(parent) || ts.isPropertyDeclaration(parent)) &&
|
|
105
|
+
parent.name === node);
|
|
106
|
+
if (named) return false;
|
|
107
|
+
if (ts.isPropertyAccessExpression(parent) && parent.expression === node)
|
|
108
|
+
return handoffMember.test(parent.name.text);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
return ts.forEachChild(node, visit) ?? false;
|
|
112
|
+
};
|
|
113
|
+
return visit(source);
|
|
114
|
+
}
|
|
94
115
|
}
|
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.28",
|
|
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.28",
|
|
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.28",
|
|
63
63
|
"chalk": "^6.0.1",
|
|
64
64
|
"commander": "^15.0.0",
|
|
65
65
|
"dayjs": "^1.11.23",
|
|
@@ -20,6 +20,8 @@ export interface PackageEntry {
|
|
|
20
20
|
pkgDir: string;
|
|
21
21
|
/** Emit absolute file paths: an installed package's exports name its barrels, never the files behind them. */
|
|
22
22
|
preserveFilePath?: boolean;
|
|
23
|
+
/** The installed package's own folder: its entry may re-export a file beside the entry's folder (`../vendor/x`). */
|
|
24
|
+
rootDir?: string;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
export interface BarrelAnalyzerOptions {
|
|
@@ -216,7 +218,11 @@ export class BarrelAnalyzer {
|
|
|
216
218
|
|
|
217
219
|
#subpathFor(pkg: PackageEntry, absFile: string): string | null {
|
|
218
220
|
const rel = path.relative(pkg.pkgDir, absFile);
|
|
219
|
-
if (!rel ||
|
|
221
|
+
if (!rel || path.isAbsolute(rel)) return null;
|
|
222
|
+
if (rel.startsWith("..")) {
|
|
223
|
+
const inPackage = pkg.preserveFilePath && pkg.rootDir ? path.relative(pkg.rootDir, absFile) : "..";
|
|
224
|
+
if (inPackage.startsWith("..") || path.isAbsolute(inPackage)) return null;
|
|
225
|
+
}
|
|
220
226
|
if (pkg.preserveFilePath) return absFile.split(path.sep).join("/");
|
|
221
227
|
const ext = CANDIDATE_EXTS.find((candidate) => rel.endsWith(candidate));
|
|
222
228
|
const parts = (ext ? rel.slice(0, -ext.length) : rel).split(path.sep);
|
|
@@ -200,7 +200,7 @@ const resolveNodePackageExport = async (workspaceRoot: string, specifier: string
|
|
|
200
200
|
if (!rel?.startsWith(".")) return null;
|
|
201
201
|
const entryFile = await resolveFileCandidate(path.resolve(pkgDir, rel));
|
|
202
202
|
if (!entryFile) return null;
|
|
203
|
-
return { pkgName: specifier, entryFile, pkgDir: path.dirname(entryFile), preserveFilePath: true };
|
|
203
|
+
return { pkgName: specifier, entryFile, pkgDir: path.dirname(entryFile), preserveFilePath: true, rootDir: pkgDir };
|
|
204
204
|
} catch {
|
|
205
205
|
return null;
|
|
206
206
|
}
|
|
@@ -625,6 +625,44 @@ describe("BarrelAnalyzer and rewriteBarrelImports", () => {
|
|
|
625
625
|
);
|
|
626
626
|
});
|
|
627
627
|
|
|
628
|
+
test("maps a name an installed barrel re-exports from the package it carries beside its folder to that file", async () => {
|
|
629
|
+
const root = await makeTempRoot();
|
|
630
|
+
const akanjs = path.join(root, "node_modules/akanjs");
|
|
631
|
+
await write(
|
|
632
|
+
path.join(akanjs, "ui/index.ts"),
|
|
633
|
+
'export { SessionContext, useAgent } from "../vendor/use-agentic";\nexport { outside } from "../../other/index";\nexport { Link } from "./Link";\n',
|
|
634
|
+
);
|
|
635
|
+
await write(path.join(akanjs, "ui/Link/index.tsx"), "export const Link = () => null;\n");
|
|
636
|
+
await write(path.join(akanjs, "vendor/use-agentic/index.ts"), 'export * from "./useAgent";\n');
|
|
637
|
+
await write(
|
|
638
|
+
path.join(akanjs, "vendor/use-agentic/useAgent.ts"),
|
|
639
|
+
"export const SessionContext = {};\nexport const useAgent = () => null;\n",
|
|
640
|
+
);
|
|
641
|
+
await write(path.join(root, "node_modules/other/index.ts"), "export const outside = 1;\n");
|
|
642
|
+
const entry = {
|
|
643
|
+
pkgName: "akanjs/ui",
|
|
644
|
+
entryFile: path.join(akanjs, "ui/index.ts"),
|
|
645
|
+
pkgDir: path.join(akanjs, "ui"),
|
|
646
|
+
};
|
|
647
|
+
const carried = { subpath: path.join(akanjs, "vendor/use-agentic/useAgent.ts"), originalName: "SessionContext" };
|
|
648
|
+
|
|
649
|
+
const installed = await new BarrelAnalyzer({
|
|
650
|
+
resolvePackage: async () => ({ ...entry, preserveFilePath: true, rootDir: akanjs }),
|
|
651
|
+
}).analyze("akanjs/ui");
|
|
652
|
+
const rootless = await new BarrelAnalyzer({
|
|
653
|
+
resolvePackage: async () => ({ ...entry, preserveFilePath: true }),
|
|
654
|
+
}).analyze("akanjs/ui");
|
|
655
|
+
|
|
656
|
+
expect(installed?.get("SessionContext")).toEqual(carried);
|
|
657
|
+
expect(installed?.get("useAgent")?.subpath).toBe(carried.subpath);
|
|
658
|
+
expect(installed?.get("outside")).toEqual({ subpath: path.join(akanjs, "ui/index.ts"), originalName: "outside" });
|
|
659
|
+
expect(installed?.get("Link")?.subpath).toBe(path.join(akanjs, "ui/Link/index.tsx"));
|
|
660
|
+
expect(rootless?.get("SessionContext")).toEqual({
|
|
661
|
+
subpath: path.join(akanjs, "ui/index.ts"),
|
|
662
|
+
originalName: "SessionContext",
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
|
|
628
666
|
test("narrows a re-export of barrel names like an import when asked, and leaves a namespace of the barrel whole", async () => {
|
|
629
667
|
const analyzer = fakeAnalyzer([
|
|
630
668
|
["buttonRecipe", { subpath: "akanjs/ui/Recipe/button", originalName: "buttonRecipe" }],
|