@akanjs/devkit 1.0.20 → 2.1.0-rc.1
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/README.ko.md +65 -0
- package/README.md +62 -6
- package/aiEditor.ts +304 -0
- package/akanApp/akanApp.host.ts +393 -0
- package/akanApp/index.ts +1 -0
- package/akanConfig/akanConfig.test.ts +236 -0
- package/akanConfig/akanConfig.ts +384 -0
- package/akanConfig/index.ts +2 -0
- package/akanConfig/types.ts +23 -0
- package/applicationBuildReporter.ts +69 -0
- package/applicationBuildRunner.ts +302 -0
- package/applicationReleasePackager.ts +206 -0
- package/artifact/implicitRootLayout.ts +155 -0
- package/artifact/index.ts +1 -0
- package/artifact/routeSeedIndex.test.ts +98 -0
- package/artifact/routeSeedIndex.ts +130 -0
- package/auth.ts +41 -0
- package/builder.ts +164 -0
- package/capacitor.base.config.ts +88 -0
- package/capacitorApp.ts +440 -0
- package/commandDecorators/argMeta.ts +102 -0
- package/commandDecorators/command.ts +351 -0
- package/commandDecorators/commandBuilder.ts +224 -0
- package/commandDecorators/commandDecorators.test.ts +212 -0
- package/commandDecorators/commandMeta.ts +7 -0
- package/commandDecorators/dependencyBuilder.ts +100 -0
- package/{esm/src/commandDecorators/helpFormatter.js → commandDecorators/helpFormatter.ts} +100 -47
- package/{esm/src/commandDecorators/index.js → commandDecorators/index.ts} +4 -2
- package/commandDecorators/targetMeta.ts +31 -0
- package/commandDecorators/types.ts +10 -0
- package/constants.ts +25 -0
- package/createTunnel.ts +36 -0
- package/dependencyScanner.ts +357 -0
- package/devkitUtils.test.ts +259 -0
- package/executors.test.ts +315 -0
- package/executors.ts +1390 -0
- package/{esm/src/extractDeps.js → extractDeps.ts} +26 -20
- package/{esm/src/fileEditor.js → fileEditor.ts} +51 -32
- package/fileSys.ts +39 -0
- package/frontendBuild/allRoutesBuilder.ts +103 -0
- package/frontendBuild/buildRouteClient.test.ts +190 -0
- package/frontendBuild/clientBuildTypes.ts +114 -0
- package/frontendBuild/clientEntriesBundler.ts +303 -0
- package/frontendBuild/clientEntryDiscovery.ts +199 -0
- package/frontendBuild/csrArtifactBuilder.ts +237 -0
- package/frontendBuild/cssCompiler.ts +286 -0
- package/frontendBuild/cssImportResolver.ts +116 -0
- package/frontendBuild/fontOptimizer.ts +427 -0
- package/frontendBuild/frontendBuild.test.ts +204 -0
- package/frontendBuild/hmrChangeClassifier.ts +28 -0
- package/frontendBuild/hmrWatcher.ts +102 -0
- package/frontendBuild/index.ts +18 -0
- package/frontendBuild/pagesBundleBuilder.ts +137 -0
- package/frontendBuild/pagesEntrySourceGenerator.ts +37 -0
- package/frontendBuild/precompressArtifacts.ts +59 -0
- package/frontendBuild/routeClientBuilder.ts +290 -0
- package/frontendBuild/routesManifestArtifactSerializer.ts +62 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +139 -0
- package/frontendBuild/vendorSpecifiers.ts +16 -0
- package/frontendBuild/watchRootResolver.ts +28 -0
- package/getCredentials.ts +19 -0
- package/getDirname.ts +3 -0
- package/getModelFileData.ts +59 -0
- package/getRelatedCnsts.ts +313 -0
- package/guideline.ts +19 -0
- package/incrementalBuilder/incrementalBuilder.host.test.ts +51 -0
- package/incrementalBuilder/incrementalBuilder.host.ts +152 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +331 -0
- package/incrementalBuilder/index.ts +1 -0
- package/{esm/src/index.js → index.ts} +28 -15
- package/lint/no-deep-internal-import.grit +25 -0
- package/lint/no-import-client-functions.grit +32 -0
- package/lint/no-import-external-library.grit +21 -0
- package/lint/no-js-private-class-method.grit +42 -0
- package/lint/no-use-client-in-server.grit +7 -0
- package/lint/non-scalar-props-restricted.grit +13 -0
- package/linter.ts +271 -0
- package/mobile/index.ts +1 -0
- package/mobile/mobileTarget.test.ts +53 -0
- package/mobile/mobileTarget.ts +88 -0
- package/package.json +48 -31
- package/prompter.ts +72 -0
- package/scanInfo.ts +606 -0
- package/selectModel.ts +11 -0
- package/{esm/src/spinner.js → spinner.ts} +22 -28
- package/{esm/src/capacitorApp.js → src/capacitorApp.ts} +82 -81
- package/sshTunnel.ts +152 -0
- package/{esm/src/streamAi.js → streamAi.ts} +18 -12
- package/transforms/barrelAnalyzer.ts +278 -0
- package/transforms/barrelImportsPlugin.ts +504 -0
- package/transforms/externalizeFrameworkPlugin.ts +185 -0
- package/transforms/index.ts +5 -0
- package/transforms/rscUseClientTransform.ts +59 -0
- package/transforms/transforms.test.ts +208 -0
- package/transforms/useClientBundlePlugin.ts +47 -0
- package/tsconfig.json +37 -0
- package/typeChecker.ts +264 -0
- package/types.ts +44 -0
- package/ui/MultiScrollList.tsx +242 -0
- package/ui/ScrollList.tsx +107 -0
- package/ui/index.ts +2 -0
- package/{esm/src/uploadRelease.js → uploadRelease.ts} +50 -34
- package/{esm/src/useStdoutDimensions.js → useStdoutDimensions.ts} +5 -5
- package/cjs/index.js +0 -21
- package/cjs/src/aiEditor.js +0 -311
- package/cjs/src/auth.js +0 -72
- package/cjs/src/builder.js +0 -114
- package/cjs/src/capacitorApp.js +0 -313
- package/cjs/src/commandDecorators/argMeta.js +0 -88
- package/cjs/src/commandDecorators/command.js +0 -324
- package/cjs/src/commandDecorators/commandMeta.js +0 -30
- package/cjs/src/commandDecorators/helpFormatter.js +0 -211
- package/cjs/src/commandDecorators/index.js +0 -31
- package/cjs/src/commandDecorators/targetMeta.js +0 -57
- package/cjs/src/commandDecorators/types.js +0 -15
- package/cjs/src/constants.js +0 -46
- package/cjs/src/createTunnel.js +0 -49
- package/cjs/src/dependencyScanner.js +0 -220
- package/cjs/src/executors.js +0 -964
- package/cjs/src/extractDeps.js +0 -103
- package/cjs/src/fileEditor.js +0 -120
- package/cjs/src/getCredentials.js +0 -44
- package/cjs/src/getDirname.js +0 -38
- package/cjs/src/getModelFileData.js +0 -66
- package/cjs/src/getRelatedCnsts.js +0 -260
- package/cjs/src/guideline.js +0 -15
- package/cjs/src/index.js +0 -65
- package/cjs/src/linter.js +0 -238
- package/cjs/src/prompter.js +0 -85
- package/cjs/src/scanInfo.js +0 -491
- package/cjs/src/selectModel.js +0 -46
- package/cjs/src/spinner.js +0 -93
- package/cjs/src/streamAi.js +0 -62
- package/cjs/src/typeChecker.js +0 -207
- package/cjs/src/types.js +0 -15
- package/cjs/src/uploadRelease.js +0 -112
- package/cjs/src/useStdoutDimensions.js +0 -43
- package/esm/index.js +0 -1
- package/esm/src/aiEditor.js +0 -282
- package/esm/src/auth.js +0 -42
- package/esm/src/builder.js +0 -81
- package/esm/src/commandDecorators/argMeta.js +0 -54
- package/esm/src/commandDecorators/command.js +0 -290
- package/esm/src/commandDecorators/commandMeta.js +0 -7
- package/esm/src/commandDecorators/targetMeta.js +0 -33
- package/esm/src/commandDecorators/types.js +0 -0
- package/esm/src/constants.js +0 -17
- package/esm/src/createTunnel.js +0 -26
- package/esm/src/dependencyScanner.js +0 -187
- package/esm/src/executors.js +0 -928
- package/esm/src/getCredentials.js +0 -11
- package/esm/src/getDirname.js +0 -5
- package/esm/src/getModelFileData.js +0 -33
- package/esm/src/getRelatedCnsts.js +0 -221
- package/esm/src/guideline.js +0 -0
- package/esm/src/linter.js +0 -205
- package/esm/src/prompter.js +0 -51
- package/esm/src/scanInfo.js +0 -455
- package/esm/src/selectModel.js +0 -13
- package/esm/src/typeChecker.js +0 -174
- package/esm/src/types.js +0 -0
- package/index.d.ts +0 -1
- package/src/aiEditor.d.ts +0 -50
- package/src/auth.d.ts +0 -9
- package/src/builder.d.ts +0 -18
- package/src/capacitorApp.d.ts +0 -39
- package/src/commandDecorators/argMeta.d.ts +0 -67
- package/src/commandDecorators/command.d.ts +0 -2
- package/src/commandDecorators/commandMeta.d.ts +0 -2
- package/src/commandDecorators/helpFormatter.d.ts +0 -3
- package/src/commandDecorators/index.d.ts +0 -6
- package/src/commandDecorators/targetMeta.d.ts +0 -19
- package/src/commandDecorators/types.d.ts +0 -1
- package/src/constants.d.ts +0 -26
- package/src/createTunnel.d.ts +0 -8
- package/src/dependencyScanner.d.ts +0 -23
- package/src/executors.d.ts +0 -296
- package/src/extractDeps.d.ts +0 -7
- package/src/fileEditor.d.ts +0 -16
- package/src/getCredentials.d.ts +0 -12
- package/src/getDirname.d.ts +0 -1
- package/src/getModelFileData.d.ts +0 -16
- package/src/getRelatedCnsts.d.ts +0 -53
- package/src/guideline.d.ts +0 -19
- package/src/index.d.ts +0 -23
- package/src/linter.d.ts +0 -109
- package/src/prompter.d.ts +0 -14
- package/src/scanInfo.d.ts +0 -82
- package/src/selectModel.d.ts +0 -1
- package/src/spinner.d.ts +0 -20
- package/src/streamAi.d.ts +0 -6
- package/src/typeChecker.d.ts +0 -52
- package/src/types.d.ts +0 -31
- package/src/uploadRelease.d.ts +0 -10
- package/src/useStdoutDimensions.d.ts +0 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { PackageJson } from "./types";
|
|
2
|
+
|
|
3
|
+
const NODE_NATIVE_MODULE_SET = new Set([
|
|
2
4
|
"assert",
|
|
3
5
|
"async_hooks",
|
|
4
6
|
"buffer",
|
|
@@ -38,43 +40,47 @@ const NODE_NATIVE_MODULE_SET = /* @__PURE__ */ new Set([
|
|
|
38
40
|
"vm",
|
|
39
41
|
"wasi",
|
|
40
42
|
"worker_threads",
|
|
41
|
-
"zlib"
|
|
43
|
+
"zlib",
|
|
42
44
|
]);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
|
|
46
|
+
export const extractDependencies = (
|
|
47
|
+
filepaths: { path: string; text: string }[],
|
|
48
|
+
pacakgeJson: PackageJson,
|
|
49
|
+
defaultDependencies: string[] = [],
|
|
50
|
+
) => {
|
|
51
|
+
if (!pacakgeJson.dependencies) throw new Error("No dependencies found in package.json");
|
|
52
|
+
const dependencies = new Set<string>(defaultDependencies);
|
|
53
|
+
|
|
54
|
+
const existingDependencies = new Set<string>([
|
|
48
55
|
...Object.keys(pacakgeJson.dependencies ?? {}),
|
|
49
|
-
...Object.keys(pacakgeJson.devDependencies ?? {})
|
|
56
|
+
...Object.keys(pacakgeJson.devDependencies ?? {}),
|
|
50
57
|
]);
|
|
51
58
|
const versionObj = {
|
|
52
|
-
...pacakgeJson.dependencies ?? {},
|
|
53
|
-
...pacakgeJson.devDependencies ?? {}
|
|
59
|
+
...(pacakgeJson.dependencies ?? {}),
|
|
60
|
+
...(pacakgeJson.devDependencies ?? {}),
|
|
54
61
|
};
|
|
62
|
+
|
|
63
|
+
// Look for require statements: require('package-name') or import 'package-name'
|
|
55
64
|
const requireRegex = /(?:require\s*\(|import\s*(?:[\w\s{},*]*\s+from\s*)?|import\s*\()\s*['"`]([^'"`]+)['"`]/g;
|
|
56
65
|
for (const { text } of filepaths.filter(({ path }) => path.endsWith(".js") || path.endsWith(".ts"))) {
|
|
57
|
-
let requireMatch;
|
|
58
|
-
while (
|
|
66
|
+
let requireMatch = requireRegex.exec(text);
|
|
67
|
+
while (requireMatch !== null) {
|
|
59
68
|
const moduleName = requireMatch[1];
|
|
69
|
+
if (!moduleName) throw new Error(`No module name found in ${text}`);
|
|
60
70
|
const moduleNameParts = moduleName.split("/");
|
|
61
71
|
const subModuleLength = moduleNameParts.length;
|
|
62
72
|
for (let i = 0; i < subModuleLength; i++) {
|
|
63
73
|
const libName = moduleNameParts.slice(0, i + 1).join("/");
|
|
64
|
-
if (!NODE_NATIVE_MODULE_SET.has(libName) && existingDependencies.has(libName))
|
|
65
|
-
dependencies.add(libName);
|
|
74
|
+
if (!NODE_NATIVE_MODULE_SET.has(libName) && existingDependencies.has(libName)) dependencies.add(libName);
|
|
66
75
|
}
|
|
76
|
+
requireMatch = requireRegex.exec(text);
|
|
67
77
|
}
|
|
68
78
|
}
|
|
69
79
|
return Object.fromEntries(
|
|
70
80
|
[...dependencies].sort().map((dep) => {
|
|
71
81
|
const version = versionObj[dep];
|
|
72
|
-
if (!version)
|
|
73
|
-
throw new Error(`No version found for ${dep}`);
|
|
82
|
+
if (!version) throw new Error(`No version found for ${dep}`);
|
|
74
83
|
return [dep, version];
|
|
75
|
-
})
|
|
84
|
+
}),
|
|
76
85
|
);
|
|
77
86
|
};
|
|
78
|
-
export {
|
|
79
|
-
extractDependencies
|
|
80
|
-
};
|
|
@@ -1,87 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
constructor(filePath) {
|
|
1
|
+
export class FileEditor {
|
|
2
|
+
private filePath: string;
|
|
3
|
+
private content: string;
|
|
4
|
+
|
|
5
|
+
private constructor(filePath: string, content: string) {
|
|
6
6
|
this.filePath = filePath;
|
|
7
|
-
this.content =
|
|
7
|
+
this.content = content;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
static async create(filePath: string): Promise<FileEditor> {
|
|
10
11
|
try {
|
|
11
|
-
|
|
12
|
+
const content = await Bun.file(filePath).text();
|
|
13
|
+
return new FileEditor(filePath, content);
|
|
12
14
|
} catch (error) {
|
|
13
|
-
throw new Error(`Failed to read file: ${
|
|
15
|
+
throw new Error(`Failed to read file: ${filePath}`);
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
|
-
|
|
18
|
+
|
|
19
|
+
find(pattern: string | RegExp): number {
|
|
17
20
|
const lines = this.content.split("\n");
|
|
18
21
|
const regex = typeof pattern === "string" ? new RegExp(pattern) : pattern;
|
|
22
|
+
|
|
19
23
|
for (let i = 0; i < lines.length; i++) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
const line = lines[i];
|
|
25
|
+
if (!line) continue;
|
|
26
|
+
if (regex.test(line)) return i;
|
|
23
27
|
}
|
|
28
|
+
|
|
24
29
|
return -1;
|
|
25
30
|
}
|
|
26
|
-
|
|
31
|
+
|
|
32
|
+
findAll(pattern: string | RegExp): number[] {
|
|
27
33
|
const lines = this.content.split("\n");
|
|
28
34
|
const regex = typeof pattern === "string" ? new RegExp(pattern) : pattern;
|
|
29
|
-
const matches = [];
|
|
35
|
+
const matches: number[] = [];
|
|
36
|
+
|
|
30
37
|
for (let i = 0; i < lines.length; i++) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
const line = lines[i];
|
|
39
|
+
if (!line) continue;
|
|
40
|
+
if (regex.test(line)) matches.push(i);
|
|
34
41
|
}
|
|
42
|
+
|
|
35
43
|
return matches;
|
|
36
44
|
}
|
|
37
|
-
|
|
45
|
+
|
|
46
|
+
insertAfter(pattern: string | RegExp, data: string): this {
|
|
38
47
|
const lineIndex = this.find(pattern);
|
|
48
|
+
|
|
39
49
|
if (lineIndex === -1) {
|
|
40
50
|
throw new Error(`Pattern not found: ${pattern}`);
|
|
41
51
|
}
|
|
52
|
+
|
|
42
53
|
const lines = this.content.split("\n");
|
|
43
54
|
lines.splice(lineIndex + 1, 0, data);
|
|
44
55
|
this.content = lines.join("\n");
|
|
56
|
+
|
|
45
57
|
return this;
|
|
46
58
|
}
|
|
47
|
-
|
|
59
|
+
|
|
60
|
+
insertBefore(pattern: string | RegExp, data: string): this {
|
|
48
61
|
const lineIndex = this.find(pattern);
|
|
62
|
+
|
|
49
63
|
if (lineIndex === -1) {
|
|
50
64
|
throw new Error(`Pattern not found: ${pattern}`);
|
|
51
65
|
}
|
|
66
|
+
|
|
52
67
|
const lines = this.content.split("\n");
|
|
53
68
|
lines.splice(lineIndex, 0, data);
|
|
54
69
|
this.content = lines.join("\n");
|
|
70
|
+
|
|
55
71
|
return this;
|
|
56
72
|
}
|
|
57
|
-
|
|
73
|
+
|
|
74
|
+
replace(pattern: string | RegExp, replacement: string): this {
|
|
58
75
|
const regex = typeof pattern === "string" ? new RegExp(pattern, "g") : pattern;
|
|
59
76
|
this.content = this.content.replace(regex, replacement);
|
|
60
77
|
return this;
|
|
61
78
|
}
|
|
62
|
-
|
|
63
|
-
|
|
79
|
+
|
|
80
|
+
append(data: string): this {
|
|
81
|
+
this.content += `\n${data}`;
|
|
64
82
|
return this;
|
|
65
83
|
}
|
|
66
|
-
|
|
67
|
-
|
|
84
|
+
|
|
85
|
+
prepend(data: string): this {
|
|
86
|
+
this.content = `${data}\n${this.content}`;
|
|
68
87
|
return this;
|
|
69
88
|
}
|
|
70
|
-
|
|
89
|
+
|
|
90
|
+
async save(): Promise<void> {
|
|
71
91
|
try {
|
|
72
|
-
|
|
92
|
+
await Bun.write(this.filePath, this.content);
|
|
73
93
|
} catch (error) {
|
|
74
94
|
throw new Error(`Failed to save file: ${this.filePath}`);
|
|
75
95
|
}
|
|
76
96
|
}
|
|
77
|
-
|
|
97
|
+
|
|
98
|
+
getContent(): string {
|
|
78
99
|
return this.content;
|
|
79
100
|
}
|
|
80
|
-
|
|
101
|
+
|
|
102
|
+
setContent(content: string): this {
|
|
81
103
|
this.content = content;
|
|
82
104
|
return this;
|
|
83
105
|
}
|
|
84
106
|
}
|
|
85
|
-
export {
|
|
86
|
-
FileEditor
|
|
87
|
-
};
|
package/fileSys.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { Logger } from "akanjs/common";
|
|
3
|
+
|
|
4
|
+
export class FileSys {
|
|
5
|
+
static logger = new Logger("FileSys");
|
|
6
|
+
static async fileExists(path: string) {
|
|
7
|
+
return await Bun.file(path).exists();
|
|
8
|
+
}
|
|
9
|
+
static async dirExists(path: string) {
|
|
10
|
+
return await stat(path)
|
|
11
|
+
.then((stat) => stat.isDirectory())
|
|
12
|
+
.catch(() => false);
|
|
13
|
+
}
|
|
14
|
+
static async exists(path: string) {
|
|
15
|
+
return await stat(path)
|
|
16
|
+
.then(() => true)
|
|
17
|
+
.catch(() => false);
|
|
18
|
+
}
|
|
19
|
+
static async readText(path: string) {
|
|
20
|
+
return await Bun.file(path).text();
|
|
21
|
+
}
|
|
22
|
+
static async readJson<T>(path: string): Promise<T> {
|
|
23
|
+
try {
|
|
24
|
+
return (await Bun.file(path).json()) as T;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
FileSys.logger.error(`Failed to read JSON file: ${path}`);
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
static async delete(path: string) {
|
|
31
|
+
return await Bun.file(path).delete();
|
|
32
|
+
}
|
|
33
|
+
static async writeText(path: string, content: string) {
|
|
34
|
+
return await Bun.file(path).write(content);
|
|
35
|
+
}
|
|
36
|
+
static async writeJson(path: string, content: object) {
|
|
37
|
+
return await Bun.file(path).write(`${JSON.stringify(content, null, 2)}\n`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { BaseBuildArtifact, BuildRouteClientResult, RoutesManifest } from "akanjs/server";
|
|
3
|
+
import { resolveSsrPageEntriesForApp } from "../artifact/implicitRootLayout";
|
|
4
|
+
import { computeRouteSeedIndex, type RouteSeedIndex } from "../artifact/routeSeedIndex";
|
|
5
|
+
import type { App } from "../commandDecorators";
|
|
6
|
+
import type { ClientEntryDiscovery } from "./clientBuildTypes";
|
|
7
|
+
import { GraphClientEntryDiscovery } from "./clientEntryDiscovery";
|
|
8
|
+
import { RouteClientBuilder } from "./routeClientBuilder";
|
|
9
|
+
import { RoutesManifestArtifactSerializer } from "./routesManifestArtifactSerializer";
|
|
10
|
+
|
|
11
|
+
export interface BuildAllRoutesResult {
|
|
12
|
+
manifest: RoutesManifest;
|
|
13
|
+
manifestPath: string;
|
|
14
|
+
seedIndex: RouteSeedIndex;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Walk every route in `pages` and produce its client bundle up-front.
|
|
19
|
+
* Intended to run under `akan build` (production) so the serve path
|
|
20
|
+
* never needs to compile.
|
|
21
|
+
*/
|
|
22
|
+
export class AllRoutesBuilder {
|
|
23
|
+
#app: App;
|
|
24
|
+
#artifact: BaseBuildArtifact;
|
|
25
|
+
#command: "build" | "start";
|
|
26
|
+
#artifactDir: string;
|
|
27
|
+
#merged: Pick<RoutesManifest, "clientManifest" | "ssrManifest" | "knownEntries"> = {
|
|
28
|
+
clientManifest: {},
|
|
29
|
+
ssrManifest: { moduleLoading: null, moduleMap: {} },
|
|
30
|
+
knownEntries: [],
|
|
31
|
+
};
|
|
32
|
+
#knownSet = new Set<string>();
|
|
33
|
+
#routeIds: string[] = [];
|
|
34
|
+
#discovery: ClientEntryDiscovery | null = null;
|
|
35
|
+
|
|
36
|
+
constructor(app: App, artifact: BaseBuildArtifact, command: "build" | "start" = "start") {
|
|
37
|
+
this.#app = app;
|
|
38
|
+
this.#artifact = artifact;
|
|
39
|
+
this.#command = command;
|
|
40
|
+
this.#artifactDir = `${command === "build" ? app.dist.cwdPath : app.cwdPath}/.akan/artifact`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async build(): Promise<BuildAllRoutesResult> {
|
|
44
|
+
const pageKeys = await this.#app.getPageKeys();
|
|
45
|
+
const pageEntries = await resolveSsrPageEntriesForApp(this.#app, pageKeys);
|
|
46
|
+
const seedIndex = computeRouteSeedIndex(pageEntries);
|
|
47
|
+
this.#app.verbose(`[build-all] discovered ${seedIndex.entries.length} routes`);
|
|
48
|
+
this.#discovery = await GraphClientEntryDiscovery.create(this.#app);
|
|
49
|
+
|
|
50
|
+
for (const entry of seedIndex.entries) {
|
|
51
|
+
const seeds = Array.from(new Set([...seedIndex.globalLayoutFiles, ...entry.seeds]));
|
|
52
|
+
const delta = await this.#buildRoute(entry.routeId, seeds);
|
|
53
|
+
this.#mergeRoute(entry.routeId, delta);
|
|
54
|
+
}
|
|
55
|
+
this.#merged.knownEntries = Array.from(this.#knownSet);
|
|
56
|
+
|
|
57
|
+
const manifest: RoutesManifest = {
|
|
58
|
+
routeIds: this.#routeIds,
|
|
59
|
+
...this.#merged,
|
|
60
|
+
};
|
|
61
|
+
const manifestPath = path.join(path.resolve(this.#artifactDir), "routes-manifest.json");
|
|
62
|
+
await Bun.write(
|
|
63
|
+
manifestPath,
|
|
64
|
+
`${JSON.stringify(
|
|
65
|
+
RoutesManifestArtifactSerializer.serialize(manifest, this.#artifactDir, {
|
|
66
|
+
production: this.#command === "build",
|
|
67
|
+
}),
|
|
68
|
+
null,
|
|
69
|
+
2,
|
|
70
|
+
)}\n`,
|
|
71
|
+
);
|
|
72
|
+
this.#app.verbose(
|
|
73
|
+
`[build-all] wrote ${manifestPath} routes=${this.#routeIds.length} entries=${this.#merged.knownEntries.length}`,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return { manifest, manifestPath, seedIndex };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async #buildRoute(routeId: string, seeds: string[]): Promise<BuildRouteClientResult> {
|
|
80
|
+
if (!this.#discovery) throw new Error("[build-all] client entry discovery is not initialized");
|
|
81
|
+
const started = Date.now();
|
|
82
|
+
const delta = await new RouteClientBuilder({
|
|
83
|
+
app: this.#app,
|
|
84
|
+
routeId,
|
|
85
|
+
seeds,
|
|
86
|
+
artifact: this.#artifact,
|
|
87
|
+
knownEntries: this.#knownSet,
|
|
88
|
+
discovery: this.#discovery,
|
|
89
|
+
command: this.#command,
|
|
90
|
+
}).build();
|
|
91
|
+
this.#app.verbose(`[build-all] ${routeId} +${delta.newEntries.length} entries (${Date.now() - started}ms)`);
|
|
92
|
+
return delta;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#mergeRoute(routeId: string, delta: BuildRouteClientResult): void {
|
|
96
|
+
for (const [key, row] of Object.entries(delta.manifestDelta)) this.#merged.clientManifest[key] = row;
|
|
97
|
+
for (const [url, byName] of Object.entries(delta.ssrManifestDelta.moduleMap)) {
|
|
98
|
+
this.#merged.ssrManifest.moduleMap[url] = byName;
|
|
99
|
+
}
|
|
100
|
+
for (const abs of delta.newEntries) this.#knownSet.add(abs);
|
|
101
|
+
this.#routeIds.push(routeId);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { createTsconfigPackageResolver } from "../transforms/barrelImportsPlugin";
|
|
6
|
+
import { CLIENT_BUNDLE_NAMING } from "./clientBuildTypes";
|
|
7
|
+
import { ClientEntriesBundler } from "./clientEntriesBundler";
|
|
8
|
+
import { GraphClientEntryDiscovery } from "./clientEntryDiscovery";
|
|
9
|
+
import { RouteClientBuilder } from "./routeClientBuilder";
|
|
10
|
+
|
|
11
|
+
const tempRoots: string[] = [];
|
|
12
|
+
|
|
13
|
+
const makeTempRoot = async () => {
|
|
14
|
+
const root = await mkdtemp(path.join(os.tmpdir(), "akan-client-entry-"));
|
|
15
|
+
tempRoots.push(root);
|
|
16
|
+
return root;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const write = async (filePath: string, content: string) => {
|
|
20
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
21
|
+
await writeFile(filePath, content);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
afterEach(async () => {
|
|
25
|
+
await Promise.all(tempRoots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("route client store bootstrap", () => {
|
|
29
|
+
test("wraps client entries with app client bootstrap before re-exporting components", () => {
|
|
30
|
+
const original = "/repo/pkgs/akanjs/ui/Model/NewWrapper_Client.tsx";
|
|
31
|
+
const source = RouteClientBuilder.createStoreBootstrapEntrySource({
|
|
32
|
+
appName: "angelo",
|
|
33
|
+
originalEntry: original,
|
|
34
|
+
exportNames: ["NewWrapper_Client", "default"],
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(source).toBe(
|
|
38
|
+
[
|
|
39
|
+
'import "@apps/angelo/client";',
|
|
40
|
+
`export { NewWrapper_Client } from ${JSON.stringify(original)};`,
|
|
41
|
+
`export { default } from ${JSON.stringify(original)};`,
|
|
42
|
+
"",
|
|
43
|
+
].join("\n"),
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("remaps wrapper manifest keys back to original client entry paths", () => {
|
|
48
|
+
const wrapper = "/repo/apps/angelo/.akan/generated/client-entry-bootstrap/NewWrapper_Client.tsx";
|
|
49
|
+
const original = "/repo/pkgs/akanjs/ui/Model/NewWrapper_Client.tsx";
|
|
50
|
+
const remapped = RouteClientBuilder.resolveOriginalManifestEntry(
|
|
51
|
+
"apps/angelo/.akan/generated/client-entry-bootstrap/NewWrapper_Client.tsx#NewWrapper_Client",
|
|
52
|
+
new Map([[wrapper, original]]),
|
|
53
|
+
new Map([[wrapper, "apps/angelo/.akan/generated/client-entry-bootstrap/NewWrapper_Client.tsx"]]),
|
|
54
|
+
"/repo",
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
expect(remapped).toEqual({
|
|
58
|
+
buildEntry: wrapper,
|
|
59
|
+
originalEntry: original,
|
|
60
|
+
name: "NewWrapper_Client",
|
|
61
|
+
key: "pkgs/akanjs/ui/Model/NewWrapper_Client.tsx#NewWrapper_Client",
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("emits browser chunks and assets with hash-only names", () => {
|
|
66
|
+
expect(CLIENT_BUNDLE_NAMING).toEqual({
|
|
67
|
+
entry: "[name]-[hash].[ext]",
|
|
68
|
+
chunk: "chunks/[hash].[ext]",
|
|
69
|
+
asset: "assets/[hash].[ext]",
|
|
70
|
+
});
|
|
71
|
+
expect(CLIENT_BUNDLE_NAMING.chunk.includes("[name]")).toBe(false);
|
|
72
|
+
expect(CLIENT_BUNDLE_NAMING.asset.includes("[name]")).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("resolves SSR client runtime aliases from the server renderer package", () => {
|
|
76
|
+
const aliases = RouteClientBuilder.resolveSsrClientRuntimeAliases();
|
|
77
|
+
|
|
78
|
+
expect(Object.keys(aliases)).toEqual(
|
|
79
|
+
expect.arrayContaining(["react", "react-dom", "react-dom/client", "react/jsx-runtime", "react/jsx-dev-runtime"]),
|
|
80
|
+
);
|
|
81
|
+
expect(aliases.react).toBe(Bun.resolveSync("react", RouteClientBuilder.resolveAkanServerEntry()));
|
|
82
|
+
expect(aliases.react).not.toBe("react");
|
|
83
|
+
expect(aliases[Bun.resolveSync("akanjs/fetch", RouteClientBuilder.resolveAkanServerEntry())]).toBe("akanjs/fetch");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("bundles akan fetch into production SSR client chunks", () => {
|
|
87
|
+
expect(RouteClientBuilder.resolveSsrClientExternalOptions("start")).toMatchObject({
|
|
88
|
+
external: expect.arrayContaining(["akanjs/fetch"]),
|
|
89
|
+
externalSubpaths: ["akanjs/fetch"],
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(RouteClientBuilder.resolveSsrClientExternalOptions("build")).toEqual({
|
|
93
|
+
external: ["react", "react-dom", "react-dom/client", "react/jsx-runtime", "react/jsx-dev-runtime"],
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("rewrites SSR external imports to runtime aliases", () => {
|
|
98
|
+
const source = [
|
|
99
|
+
'import React, { useState } from "react";',
|
|
100
|
+
'import { jsxDEV } from "react/jsx-dev-runtime";',
|
|
101
|
+
'import { getRequest } from "/repo/pkgs/akanjs/fetch/index.ts";',
|
|
102
|
+
'import "react-dom/client";',
|
|
103
|
+
'import { clsx } from "clsx";',
|
|
104
|
+
"",
|
|
105
|
+
].join("\n");
|
|
106
|
+
|
|
107
|
+
expect(
|
|
108
|
+
ClientEntriesBundler.rewriteExternalImportSpecifiers(source, {
|
|
109
|
+
react: "/runtime/react.js",
|
|
110
|
+
"react/jsx-dev-runtime": "/runtime/jsx-dev-runtime.js",
|
|
111
|
+
"/repo/pkgs/akanjs/fetch/index.ts": "akanjs/fetch",
|
|
112
|
+
"react-dom/client": "/runtime/react-dom-client.js",
|
|
113
|
+
}),
|
|
114
|
+
).toBe(
|
|
115
|
+
[
|
|
116
|
+
'import React, { useState } from "/runtime/react.js";',
|
|
117
|
+
'import { jsxDEV } from "/runtime/jsx-dev-runtime.js";',
|
|
118
|
+
'import { getRequest } from "akanjs/fetch";',
|
|
119
|
+
'import "/runtime/react-dom-client.js";',
|
|
120
|
+
'import { clsx } from "clsx";',
|
|
121
|
+
"",
|
|
122
|
+
].join("\n"),
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("discovers client entries from installed akanjs package sources", async () => {
|
|
127
|
+
const root = await makeTempRoot();
|
|
128
|
+
const seed = path.join(root, "apps/demo/page/_index.tsx");
|
|
129
|
+
const uiEntry = path.join(root, "node_modules/akanjs/ui/index.ts");
|
|
130
|
+
const clientEntry = path.join(root, "node_modules/akanjs/ui/System/Client.tsx");
|
|
131
|
+
await write(
|
|
132
|
+
seed,
|
|
133
|
+
'import { ClientPathWrapper } from "akanjs/ui";\nexport default function Page() { return null; }\n',
|
|
134
|
+
);
|
|
135
|
+
await write(uiEntry, 'export { ClientPathWrapper } from "./System/Client";\n');
|
|
136
|
+
await write(clientEntry, '"use client";\nexport const ClientPathWrapper = () => null;\n');
|
|
137
|
+
|
|
138
|
+
const discovery = new GraphClientEntryDiscovery(
|
|
139
|
+
{ barrelImports: ["akanjs/ui"], externalLibs: [], optimizeImports: true },
|
|
140
|
+
async (specifier) => {
|
|
141
|
+
if (specifier === "akanjs/ui") {
|
|
142
|
+
return {
|
|
143
|
+
pkgName: "akanjs/ui",
|
|
144
|
+
entryFile: uiEntry,
|
|
145
|
+
pkgDir: path.dirname(uiEntry),
|
|
146
|
+
preserveFilePath: true,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (specifier === "akanjs/ui/System/Client.tsx") {
|
|
150
|
+
return {
|
|
151
|
+
pkgName: "akanjs/ui/System/Client.tsx",
|
|
152
|
+
entryFile: clientEntry,
|
|
153
|
+
pkgDir: path.dirname(clientEntry),
|
|
154
|
+
preserveFilePath: true,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
expect(await discovery.discover([seed])).toEqual([clientEntry]);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("resolves package export wildcard subpaths for installed akanjs sources", async () => {
|
|
165
|
+
const root = await makeTempRoot();
|
|
166
|
+
const clientEntry = path.join(root, "node_modules/akanjs/ui/System/Client.tsx");
|
|
167
|
+
await write(
|
|
168
|
+
path.join(root, "node_modules/akanjs/package.json"),
|
|
169
|
+
JSON.stringify({
|
|
170
|
+
name: "akanjs",
|
|
171
|
+
exports: {
|
|
172
|
+
"./ui": "./ui/index.ts",
|
|
173
|
+
"./ui/*": "./ui/*",
|
|
174
|
+
},
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
await write(path.join(root, "node_modules/akanjs/ui/index.ts"), "export {};\n");
|
|
178
|
+
await write(clientEntry, '"use client";\nexport const ClientPathWrapper = () => null;\n');
|
|
179
|
+
|
|
180
|
+
const resolvePackage = await createTsconfigPackageResolver({
|
|
181
|
+
workspace: { workspaceRoot: root },
|
|
182
|
+
getTsConfig: async () => ({ compilerOptions: { paths: {} } }),
|
|
183
|
+
} as never);
|
|
184
|
+
|
|
185
|
+
expect(await resolvePackage("akanjs/ui/System/Client.tsx")).toMatchObject({
|
|
186
|
+
entryFile: clientEntry,
|
|
187
|
+
preserveFilePath: true,
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { ClientManifest, ClientManifestEntry, SsrManifest } from "akanjs/server";
|
|
2
|
+
import type { BunPlugin } from "bun";
|
|
3
|
+
import type { App } from "../commandDecorators";
|
|
4
|
+
|
|
5
|
+
export type { ClientManifest, ClientManifestEntry };
|
|
6
|
+
|
|
7
|
+
export interface BuildClientOptions {
|
|
8
|
+
appDir: string;
|
|
9
|
+
rscClientEntry: string;
|
|
10
|
+
outputDir?: string;
|
|
11
|
+
servePrefix?: string;
|
|
12
|
+
mode?: "production" | "test";
|
|
13
|
+
/** Additional Bun plugins applied to the client bundle build. */
|
|
14
|
+
plugins?: BunPlugin[];
|
|
15
|
+
/**
|
|
16
|
+
* Legacy fallback: additional directories to filesystem-scan for
|
|
17
|
+
* `"use client"` entry points. Only used when `workspaceRoot` /
|
|
18
|
+
* `tsconfigPaths` are not provided (in which case we fall back to the old
|
|
19
|
+
* filesystem-scan strategy). Prefer the graph-based discovery.
|
|
20
|
+
*/
|
|
21
|
+
extraClientScanRoots?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* Environment variables to inline into the browser bundle via `define`.
|
|
24
|
+
* Keys are the original `process.env` names. Each key is emitted as
|
|
25
|
+
* `process.env.<KEY>` so existing server/client shared code that reads
|
|
26
|
+
* `process.env.AKAN_PUBLIC_*` keeps working unchanged.
|
|
27
|
+
*/
|
|
28
|
+
publicEnv?: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* Workspace root used by the graph-based client-entry discovery to resolve
|
|
31
|
+
* tsconfig-aliased specifiers (`@libs/shared/ui`, `@apps/<name>/client`,
|
|
32
|
+
* ...). When provided together with `tsconfigPaths`, discovery traverses
|
|
33
|
+
* the import graph starting from `appDir` instead of doing a filesystem
|
|
34
|
+
* scan, so `"use client"` files that no route transitively imports (e.g.
|
|
35
|
+
* unused editor components in a shared UI package) stay out of the client
|
|
36
|
+
* bundle.
|
|
37
|
+
*/
|
|
38
|
+
workspaceRoot?: string;
|
|
39
|
+
/** Workspace tsconfig `compilerOptions.paths`. See `workspaceRoot`. */
|
|
40
|
+
tsconfigPaths?: Record<string, string[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Barrel specifiers whose imports are flattened by `barrelImportsPlugin`.
|
|
43
|
+
* Discovery rewrites barrel imports with the same analyzer before scanning,
|
|
44
|
+
* so the traversal sees the same leaf files the bundler will see.
|
|
45
|
+
*/
|
|
46
|
+
barrelImports?: string[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface BuildClientResult {
|
|
50
|
+
manifest: ClientManifest;
|
|
51
|
+
ssrManifest: SsrManifest;
|
|
52
|
+
outputDir: string;
|
|
53
|
+
servePrefix: string;
|
|
54
|
+
entries: string[];
|
|
55
|
+
rscClientUrl: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const CLIENT_BUNDLE_NAMING = {
|
|
59
|
+
entry: "[name]-[hash].[ext]",
|
|
60
|
+
chunk: "chunks/[hash].[ext]",
|
|
61
|
+
asset: "assets/[hash].[ext]",
|
|
62
|
+
} as const;
|
|
63
|
+
|
|
64
|
+
export interface ClientEntryDiscovery {
|
|
65
|
+
discover(seeds: string[]): Promise<string[]>;
|
|
66
|
+
invalidate?(files: string[]): void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface BundleClientEntriesOptions {
|
|
70
|
+
app: App;
|
|
71
|
+
entries: string[];
|
|
72
|
+
plugins?: BunPlugin[];
|
|
73
|
+
outputSubdir?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Future Fast Refresh hook. Bun only injects the React Refresh transform;
|
|
76
|
+
* the browser runtime/update protocol still needs to be provided by Akan.
|
|
77
|
+
*/
|
|
78
|
+
reactFastRefresh?: boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface BundleClientEntriesInternalOptions extends BundleClientEntriesOptions {
|
|
82
|
+
external?: readonly string[];
|
|
83
|
+
externalSubpaths?: readonly string[];
|
|
84
|
+
externalAliases?: Partial<Record<string, string>>;
|
|
85
|
+
command?: "build" | "start";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface BundleClientEntriesResult {
|
|
89
|
+
manifest: ClientManifest;
|
|
90
|
+
ssrManifest: SsrManifest;
|
|
91
|
+
/** Absolute path → serve URL for every entry point we produced. */
|
|
92
|
+
entryUrlsByAbsPath: Map<string, string>;
|
|
93
|
+
/** Absolute source entry path → emitted entry file absolute path. */
|
|
94
|
+
entryOutputAbsByAbsPath: Map<string, string>;
|
|
95
|
+
/** Absolute source files that Bun included for each client entry bundle. */
|
|
96
|
+
entryDepsByAbsPath: Map<string, string[]>;
|
|
97
|
+
/** Absolute source entry path → workspace-relative client reference id. */
|
|
98
|
+
clientReferenceIdByAbsPath: Map<string, string>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type AkanConfig = Awaited<ReturnType<App["getConfig"]>>;
|
|
102
|
+
export type ScannedImport = { path: string; kind?: string };
|
|
103
|
+
export type MetafileOutput = {
|
|
104
|
+
imports: ScannedImport[];
|
|
105
|
+
entryPoint?: string;
|
|
106
|
+
exports?: string[];
|
|
107
|
+
inputs?: Record<string, unknown>;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export interface OpaqueEntryAliases {
|
|
111
|
+
entries: string[];
|
|
112
|
+
originalByAlias: Map<string, string>;
|
|
113
|
+
aliasDir: string;
|
|
114
|
+
}
|