@akanjs/cli 3.2.0-rc.9 → 3.2.1-rc.0
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/.build-stamp +2 -2
- package/CodeAgent-xdw73nbz.js +11 -0
- package/{CodeTui-qstk5vpj.js → CodeTui-0gewm71c.js} +822 -666
- package/README.ko.md +7 -0
- package/README.md +7 -0
- package/TunnelShare-cccfdgbm.js +16 -0
- package/agent.command-g1mj34wz.js +59 -0
- package/akanCode.js +12 -12
- package/appExecutor-rrx10jya.js +11 -0
- package/{application.command-m4rq4wc2.js → application.command-3w4v7t40.js} +84 -40
- package/{applicationBuildRunner-df7rx3ra.js → applicationBuildRunner-y5xbetyz.js} +51 -20
- package/buildBatch.proc.js +31 -16
- package/{cloud.command-a0gy0qq2.js → cloud.command-ph0rz6sw.js} +28 -29
- package/cloud.script-8bs9tp4j.js +30 -0
- package/{code.command-5rsdqw8s.js → code.command-9b967qpg.js} +13 -9
- package/context.command-ndzs5rbf.js +62 -0
- package/context.runner-bmstpng2.js +32 -0
- package/csrArtifactBuilder-gtvff6k7.js +10 -0
- package/{index-qd7xn2bk.js → dependencyScanner-93g8tk0r.js} +7 -6
- package/{devTui-h77zrjv5.js → devTui-rf374y2w.js} +1 -1
- package/{fileSys-zpvt5gtf.js → fileSys-e5mwt73x.js} +1 -1
- package/frameworkGraph-aneq2nwy.js +8 -0
- package/{guideline.command-mffxknbr.js → guideline.command-y8qz9kxy.js} +9 -5
- package/guidelines/agentRule/agentRule.instruction.md +25 -9
- package/guidelines/akanApi/akanApi.instruction.md +6 -4
- package/guidelines/conventions/core.md +23 -5
- package/guidelines/conventions/rules/app.md +4 -1
- package/guidelines/conventions/rules/page.md +5 -4
- package/guidelines/conventions/rules/ts.md +3 -3
- package/guidelines/errorCodes/errorCodes.instruction.md +165 -0
- package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
- package/guidelines/mcpRule/mcpRule.instruction.md +225 -5
- package/guidelines/pageRule/pageRule.instruction.md +10 -1
- package/guidelines/queryRule/queryRule.instruction.md +3 -1
- package/guidelines/runtimeRule/runtimeRule.instruction.md +14 -8
- package/guidelines/transportRule/transportRule.instruction.md +31 -1
- package/incrementalBuilder.proc.js +609 -437
- package/{index-skmtj8rm.js → index-02v45hh9.js} +27 -10
- package/{index-j6gc8n14.js → index-0csk6jqm.js} +11 -9
- package/{index-2r9ff9qm.js → index-0wa5z6rm.js} +2 -2
- package/{index-nmvhjn8c.js → index-0z8sbdme.js} +93 -82
- package/{index-2vgv7fs7.js → index-1c2807kg.js} +727 -693
- package/{index-hj6w4ka1.js → index-1p81ecbz.js} +1 -1
- package/{index-2mf1aen9.js → index-1p9bxjmt.js} +2 -2
- package/{index-an76bdrv.js → index-2kh4xj3m.js} +1 -1
- package/{index-99qvtff2.js → index-2vn0m9z5.js} +5 -5
- package/{index-rp4yf32g.js → index-3569fr49.js} +36 -29
- package/{index-xvk2a75m.js → index-38x8ynrx.js} +25 -25
- package/{index-cmg5ngqa.js → index-3fmzz9sf.js} +20 -20
- package/{index-rfzp4pqs.js → index-45aprybg.js} +3 -3
- package/{index-k92x3vne.js → index-4a1n0nym.js} +1 -1
- package/{index-ra9fvn7s.js → index-4zgm54wf.js} +76 -40
- package/{index-exn38bzx.js → index-652f3bs8.js} +116 -54
- package/{index-grxs6fts.js → index-6gepp8yn.js} +57 -31
- package/{index-vm0dn0mt.js → index-6j351de4.js} +294 -157
- package/{index-w15mg3km.js → index-7ssr7wq4.js} +1 -1
- package/{index-gxav1bjz.js → index-82cmbpxc.js} +9 -9
- package/{index-2mrn1mrg.js → index-9f3reh2y.js} +1 -1
- package/{index-gcx48get.js → index-9rymt8d6.js} +2 -2
- package/{index-swwjakt0.js → index-ankyx6dj.js} +14 -18
- package/{index-28x1aszt.js → index-b0t92k71.js} +154 -58
- package/index-b372rck5.js +799 -0
- package/{index-yf9wc28h.js → index-bejy9zyc.js} +1 -1
- package/{index-r0a604h4.js → index-c669pbyb.js} +5 -4
- package/{index-xyn02k0w.js → index-cm9rb480.js} +662 -433
- package/{index-j9790rhk.js → index-d0n78fzc.js} +1635 -1139
- package/{index-hqv34wzq.js → index-dr1carpr.js} +10 -10
- package/index-f2arv0mv.js +30 -0
- package/{index-5radqwn2.js → index-gtydr9qc.js} +12 -12
- package/{index-j6eeh5d7.js → index-j3fqs8rc.js} +5 -5
- package/{index-yckz5t8b.js → index-jdw9m5c4.js} +516 -434
- package/{index-ny2k80mv.js → index-jf4vk1s0.js} +9 -2
- package/{index-x40bdsca.js → index-jg5rwrf7.js} +77 -115
- package/{index-5zwr4n6k.js → index-ktxdfqg5.js} +65 -8
- package/index-mnhrqjjq.js +127 -0
- package/{index-3ghdb7p5.js → index-pc42gxa5.js} +2777 -3676
- package/{index-0hbtve0a.js → index-q8h4eg5y.js} +32 -28
- package/{index-j3v29pq7.js → index-qh81drde.js} +219 -175
- package/{index-b4qq3rq0.js → index-rwgqba9p.js} +1 -1
- package/{index-w8yasvpc.js → index-scfsqen7.js} +2136 -2175
- package/{index-9p260r4e.js → index-trffs83s.js} +538 -250
- package/{index-0gg15zwa.js → index-twjgmryg.js} +6 -6
- package/index-whvhsb5f.js +80 -0
- package/{index-h7hehkw6.js → index-xczjdng6.js} +3 -1
- package/{index-39jz41jb.js → index-xs9a3ddt.js} +3 -3
- package/{index-35j83zkd.js → index-xv3pvdw4.js} +2 -2
- package/{index-34792nh7.js → index-y2g0s9tn.js} +1 -1
- package/{index-43f4h4cm.js → index-ymgsvhc5.js} +7 -8
- package/{index-ygdbn9jn.js → index-zyb0ebm4.js} +1 -1
- package/{index-bns3wcpc.js → index-zyjztrvc.js} +2 -2
- package/index.js +30 -24
- package/libExecutor-nstr00s7.js +10 -0
- package/{library.command-bmd7zc5m.js → library.command-b02aw1hm.js} +12 -5
- package/{localRegistry.command-y6en1599.js → localRegistry.command-3hg1p4aj.js} +24 -24
- package/{module.command-7exfffqw.js → module.command-bd9gz6cv.js} +11 -7
- package/{package.command-adskw2rj.js → package.command-xmr0mxze.js} +11 -10
- package/package.json +8 -8
- package/{page.command-dw01272p.js → page.command-x94qf58g.js} +8 -4
- package/{pipeline.command-0b1r3y5r.js → pipeline.command-n2843k6t.js} +15 -9
- package/pkgExecutor-cka27e3c.js +10 -0
- package/{primitive.command-byw6vc04.js → primitive.command-cs7v376h.js} +12 -8
- package/{projectTypecheck-kkrpq60a.js → projectTypecheck-za2n3nbr.js} +1 -1
- package/{prompter-qrwx1p17.js → prompter-d33wmdpa.js} +2 -2
- package/{quality.command-6rqnhzct.js → quality.command-nqngh1jd.js} +25 -16
- package/{recipeScanner-4b69ybe0.js → recipeScanner-rrx69awy.js} +1 -1
- package/{repair.command-rw5zymak.js → repair.command-v2medwsm.js} +12 -8
- package/{routeSourceValidator-4h947v7c.js → routeSourceValidator-8n6j1vn7.js} +4 -2
- package/{scalar.command-2dyp9nh9.js → scalar.command-61cjmxn1.js} +10 -6
- package/skills/akan-debug/SKILL.md +8 -5
- package/skills/akan-err/SKILL.md +7 -0
- package/skills/akan-mcp/SKILL.md +19 -1
- package/skills/akan-scaffold/SKILL.md +1 -1
- package/skills/akan-validate/SKILL.md +3 -3
- package/{subspace.command-111ynwv1.js → subspace.command-dtv8nfh7.js} +30 -24
- package/templates/app/page/_layout.tsx +13 -0
- package/templates/app/page/styles.css.template +40 -0
- package/templates/appSample/page/_index.tsx +9 -9
- package/templates/appSample/page/_layout.tsx +1 -0
- package/templates/appSample/page/styles.css.template +40 -5
- package/templates/appSample/ui/Recipe/jellyButton.ts +1 -1
- package/templates/biomeForm.ts +1 -1
- package/templates/env/_env.server.type.ts +1 -1
- package/templates/facetIndex/index.ts +2 -37
- package/templates/lib/sig.ts +0 -4
- package/templates/lib/useClient.ts +1 -1
- package/templates/workspaceRoot/.devcontainer/devcontainer.json.template +1 -1
- package/templates/workspaceRoot/AGENTS.md.template +2 -1
- package/templates/workspaceRoot/README.ts +4 -2
- package/{tunnel.command-2gcpfbdj.js → tunnel.command-fmwm5fgb.js} +15 -13
- package/{typeChecker-s640r6c0.js → typeChecker-7jt6abrs.js} +1 -1
- package/typecheck.proc.js +3 -2
- package/{verify.command-djgs86ma.js → verify.command-4f260t53.js} +19 -17
- package/{workflow.command-n0k2mxr5.js → workflow.command-tm5q9xsm.js} +21 -14
- package/{workspace.command-fh1qwxfx.js → workspace.command-75gc280j.js} +56 -54
- package/CodeAgent-x2p3a3e0.js +0 -11
- package/TunnelShare-c4xsfzg5.js +0 -15
- package/agent.command-9et2e27p.js +0 -52
- package/cloud.script-xze4zh7n.js +0 -31
- package/context.command-rk1dwrg4.js +0 -57
- package/context.runner-83ky5m1b.js +0 -30
- package/dependencyScanner-78sq8m4q.js +0 -8
- /package/templates/{appSample → app}/public/fonts/Pretendard-Bold.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-Medium.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-Regular.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-SemiBold.woff2 +0 -0
|
@@ -1,26 +1,45 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
} from "./index-
|
|
3
|
+
FileSys2
|
|
4
|
+
} from "./index-zyjztrvc.js";
|
|
5
|
+
import {
|
|
6
|
+
JsonFormatter,
|
|
7
|
+
AkanAppConfig
|
|
8
|
+
} from "./index-pc42gxa5.js";
|
|
9
|
+
import {
|
|
10
|
+
ErrorReport
|
|
11
|
+
} from "./index-whvhsb5f.js";
|
|
5
12
|
|
|
6
|
-
// pkgs/@akanjs/devkit/applicationBuildReporter.ts
|
|
7
|
-
import { realpathSync } from "fs";
|
|
8
|
-
import path4 from "path";
|
|
13
|
+
// pkgs/@akanjs/devkit/app/applicationBuildReporter.ts
|
|
9
14
|
import { Logger } from "akanjs/common";
|
|
10
15
|
|
|
11
|
-
// pkgs/@akanjs/devkit/routeJsBudget.ts
|
|
12
|
-
import
|
|
16
|
+
// pkgs/@akanjs/devkit/app/routeJsBudget.ts
|
|
17
|
+
import path4 from "path";
|
|
13
18
|
import { toError } from "akanjs/common";
|
|
14
19
|
|
|
15
20
|
// pkgs/@akanjs/devkit/frontendBuild/fontPruner.ts
|
|
16
|
-
import { rm, rmdir, stat as stat2 } from "fs/promises";
|
|
21
|
+
import { rm as rm2, rmdir, stat as stat2 } from "fs/promises";
|
|
17
22
|
import path2 from "path";
|
|
18
23
|
import { isFontOptimizationEnabled } from "akanjs/client";
|
|
19
24
|
|
|
20
25
|
// pkgs/@akanjs/devkit/frontendBuild/fontOptimizer.ts
|
|
21
|
-
import { mkdir, stat } from "fs/promises";
|
|
26
|
+
import { mkdir, readdir, rm, stat } from "fs/promises";
|
|
22
27
|
import path from "path";
|
|
23
28
|
import ts from "typescript";
|
|
29
|
+
|
|
30
|
+
// pkgs/@akanjs/devkit/frontendBuild/buildCacheStamp.ts
|
|
31
|
+
import { statSync } from "fs";
|
|
32
|
+
var buildCacheStamp = (producers) => ({
|
|
33
|
+
akanjs: AkanAppConfig.akanVersion,
|
|
34
|
+
bun: `${Bun.version}+${Bun.revision}`,
|
|
35
|
+
code: producers.map((file) => {
|
|
36
|
+
const stats = statSync(file, { throwIfNoEntry: false });
|
|
37
|
+
return stats ? `${stats.mtimeMs}:${stats.size}` : "missing";
|
|
38
|
+
}).join(",")
|
|
39
|
+
});
|
|
40
|
+
var isBuildCacheStamp = (value, stamp) => value?.akanjs === stamp.akanjs && value.bun === stamp.bun && value.code === stamp.code;
|
|
41
|
+
|
|
42
|
+
// pkgs/@akanjs/devkit/frontendBuild/fontOptimizer.ts
|
|
24
43
|
var FONT_URL_PREFIX = "/_akan/fonts";
|
|
25
44
|
var DEFAULT_FONT_SUBSETS = ["latin"];
|
|
26
45
|
|
|
@@ -28,15 +47,18 @@ class FontOptimizer {
|
|
|
28
47
|
#app;
|
|
29
48
|
#command;
|
|
30
49
|
#artifactRoot;
|
|
50
|
+
#cacheRoot;
|
|
51
|
+
#stamp = buildCacheStamp([import.meta.path]);
|
|
31
52
|
#files = [];
|
|
32
53
|
#cssParts = [];
|
|
33
54
|
#woff2Ready = null;
|
|
34
55
|
static #ksX1001Text = null;
|
|
35
|
-
static #cacheVersion =
|
|
56
|
+
static #cacheVersion = 4;
|
|
36
57
|
constructor(app, command = "start") {
|
|
37
58
|
this.#app = app;
|
|
38
59
|
this.#command = command;
|
|
39
60
|
this.#artifactRoot = path.join(command === "build" ? app.dist.cwdPath : app.cwdPath, ".akan/artifact");
|
|
61
|
+
this.#cacheRoot = command === "build" ? this.#artifactRoot : path.join(app.cwdPath, ".akan/cache");
|
|
40
62
|
}
|
|
41
63
|
async optimize() {
|
|
42
64
|
const fonts = await this.discoverFonts();
|
|
@@ -57,11 +79,13 @@ class FontOptimizer {
|
|
|
57
79
|
const result = { css: this.#cssParts.join(`
|
|
58
80
|
`), fonts, files: this.#files };
|
|
59
81
|
if (cacheKey)
|
|
60
|
-
await this.#writeCache(cacheKey, result)
|
|
82
|
+
await this.#writeCache(cacheKey, result).catch(() => {
|
|
83
|
+
return;
|
|
84
|
+
});
|
|
61
85
|
return result;
|
|
62
86
|
}
|
|
63
87
|
get #cachePath() {
|
|
64
|
-
return path.join(this.#
|
|
88
|
+
return path.join(this.#cacheRoot, "fontCache.json");
|
|
65
89
|
}
|
|
66
90
|
async#buildCacheKey(fonts) {
|
|
67
91
|
const sources = [];
|
|
@@ -70,10 +94,10 @@ class FontOptimizer {
|
|
|
70
94
|
continue;
|
|
71
95
|
for (const face of this.#getFontFaces(font)) {
|
|
72
96
|
const sourcePath = await this.#resolveFontSourcePath(face.src);
|
|
73
|
-
const
|
|
74
|
-
if (!
|
|
97
|
+
const digest = sourcePath ? await this.#fileDigest(sourcePath) : null;
|
|
98
|
+
if (!digest)
|
|
75
99
|
return null;
|
|
76
|
-
sources.push({ optimizedSrc: face.optimizedSrc, ...
|
|
100
|
+
sources.push({ optimizedSrc: face.optimizedSrc, sourcePath, ...digest });
|
|
77
101
|
}
|
|
78
102
|
for (const filePath of font.subsetFiles ?? []) {
|
|
79
103
|
const abs = path.isAbsolute(filePath) ? filePath : path.join(this.#app.cwdPath, filePath);
|
|
@@ -85,11 +109,30 @@ class FontOptimizer {
|
|
|
85
109
|
if (this.#getFontSubsets(font).includes("auto"))
|
|
86
110
|
sources.push({ autoSubsetText: this.#cacheDigest(await this.#collectAutoSubsetText()) });
|
|
87
111
|
}
|
|
88
|
-
|
|
112
|
+
const lockfile = await this.#lockfileDigest();
|
|
113
|
+
return this.#cacheDigest({
|
|
114
|
+
version: FontOptimizer.#cacheVersion,
|
|
115
|
+
command: this.#command,
|
|
116
|
+
lockfile,
|
|
117
|
+
fonts,
|
|
118
|
+
sources
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async#lockfileDigest() {
|
|
122
|
+
const root = this.#app.workspace.workspaceRoot;
|
|
123
|
+
const lockfiles = await Promise.all(["bun.lock", "bun.lockb"].map((name) => Bun.file(path.join(root, name)).bytes().catch(() => null)));
|
|
124
|
+
return lockfiles.map((bytes) => bytes ? this.#sha256(bytes) : null);
|
|
125
|
+
}
|
|
126
|
+
#sha256(bytes) {
|
|
127
|
+
return new Bun.CryptoHasher("sha256").update(bytes).digest("hex");
|
|
89
128
|
}
|
|
90
129
|
#cacheDigest(value) {
|
|
91
130
|
return new Bun.CryptoHasher("sha256").update(this.#stableStringify(value)).digest("hex");
|
|
92
131
|
}
|
|
132
|
+
async#fileDigest(filePath) {
|
|
133
|
+
const bytes = await Bun.file(filePath).bytes().catch(() => null);
|
|
134
|
+
return bytes ? { size: bytes.byteLength, sha256: this.#sha256(bytes) } : null;
|
|
135
|
+
}
|
|
93
136
|
async#fileStamp(filePath) {
|
|
94
137
|
try {
|
|
95
138
|
const stats = await stat(filePath);
|
|
@@ -100,23 +143,56 @@ class FontOptimizer {
|
|
|
100
143
|
}
|
|
101
144
|
async#readCache(key) {
|
|
102
145
|
const cache = await Bun.file(this.#cachePath).json().catch(() => null);
|
|
103
|
-
if (cache?.version !== FontOptimizer.#cacheVersion || cache.key !== key)
|
|
146
|
+
if (cache?.version !== FontOptimizer.#cacheVersion || cache.key !== key || typeof cache.css !== "string")
|
|
147
|
+
return null;
|
|
148
|
+
if (!isBuildCacheStamp(cache, this.#stamp) || !Array.isArray(cache.files))
|
|
104
149
|
return null;
|
|
105
|
-
const files =
|
|
106
|
-
for (const
|
|
107
|
-
|
|
150
|
+
const files = [];
|
|
151
|
+
for (const file of cache.files) {
|
|
152
|
+
const bytes = await this.#readIntact(this.#cacheRoot, file);
|
|
153
|
+
if (!bytes)
|
|
108
154
|
return null;
|
|
155
|
+
if (this.#cacheRoot !== this.#artifactRoot && !await this.#readIntact(this.#artifactRoot, file))
|
|
156
|
+
await Bun.write(path.join(this.#artifactRoot, file.path), bytes);
|
|
157
|
+
files.push(path.join(this.#artifactRoot, file.path));
|
|
109
158
|
}
|
|
110
159
|
return { css: cache.css, files };
|
|
111
160
|
}
|
|
161
|
+
async#readIntact(root, file) {
|
|
162
|
+
if (typeof file?.path !== "string" || typeof file.size !== "number")
|
|
163
|
+
return null;
|
|
164
|
+
const bytes = await Bun.file(path.join(root, file.path)).bytes().catch(() => null);
|
|
165
|
+
if (!bytes || bytes.byteLength !== file.size || this.#sha256(bytes) !== file.sha256)
|
|
166
|
+
return null;
|
|
167
|
+
return bytes;
|
|
168
|
+
}
|
|
112
169
|
async#writeCache(key, result) {
|
|
170
|
+
const files = [];
|
|
171
|
+
for (const filePath of result.files) {
|
|
172
|
+
const bytes = await Bun.file(filePath).bytes();
|
|
173
|
+
const relativePath = path.relative(this.#artifactRoot, filePath);
|
|
174
|
+
const cachedPath = path.join(this.#cacheRoot, relativePath);
|
|
175
|
+
if (cachedPath !== filePath)
|
|
176
|
+
await FileSys2.writeTextAtomic(cachedPath, bytes);
|
|
177
|
+
files.push({ path: relativePath, size: bytes.byteLength, sha256: this.#sha256(bytes) });
|
|
178
|
+
}
|
|
113
179
|
const cache = {
|
|
114
180
|
version: FontOptimizer.#cacheVersion,
|
|
181
|
+
...this.#stamp,
|
|
115
182
|
key,
|
|
116
183
|
css: result.css,
|
|
117
|
-
files
|
|
184
|
+
files
|
|
118
185
|
};
|
|
119
|
-
await
|
|
186
|
+
await FileSys2.writeTextAtomic(this.#cachePath, JSON.stringify(cache));
|
|
187
|
+
await this.#pruneCachedFonts(files);
|
|
188
|
+
}
|
|
189
|
+
async#pruneCachedFonts(kept) {
|
|
190
|
+
if (this.#cacheRoot === this.#artifactRoot)
|
|
191
|
+
return;
|
|
192
|
+
const dir = path.join(this.#cacheRoot, FONT_URL_PREFIX.replace(/^\/_akan\//, ""));
|
|
193
|
+
const keep = new Set(kept.map((file) => path.join(this.#cacheRoot, file.path)));
|
|
194
|
+
const names = await readdir(dir).catch(() => []);
|
|
195
|
+
await Promise.all(names.filter((name) => !name.endsWith(".tmp")).map((name) => path.join(dir, name)).filter((filePath) => !keep.has(filePath)).map((filePath) => rm(filePath, { force: true })));
|
|
120
196
|
}
|
|
121
197
|
async discoverFonts() {
|
|
122
198
|
const pageKeys = await this.#app.getPageKeys();
|
|
@@ -619,7 +695,7 @@ class FontPruner {
|
|
|
619
695
|
}
|
|
620
696
|
}
|
|
621
697
|
async#remove(files) {
|
|
622
|
-
await Promise.all(files.map((file) =>
|
|
698
|
+
await Promise.all(files.map((file) => rm2(path2.join(this.#publicRoot, file), { force: true })));
|
|
623
699
|
const dirs = [...new Set(files.map((file) => path2.posix.dirname(file)))].filter((dir) => dir !== "." && dir !== "/").sort((a, b) => b.length - a.length);
|
|
624
700
|
for (const dir of dirs)
|
|
625
701
|
await rmdir(path2.join(this.#publicRoot, dir)).catch(() => {
|
|
@@ -668,7 +744,85 @@ class FontPruner {
|
|
|
668
744
|
}
|
|
669
745
|
}
|
|
670
746
|
|
|
671
|
-
// pkgs/@akanjs/devkit/
|
|
747
|
+
// pkgs/@akanjs/devkit/frontendBuild/precompressArtifacts.ts
|
|
748
|
+
import fs from "fs";
|
|
749
|
+
import path3 from "path";
|
|
750
|
+
import zlib from "zlib";
|
|
751
|
+
var COMPRESSIBLE_EXTS = new Set([".css", ".html", ".js", ".json", ".svg"]);
|
|
752
|
+
var MIN_COMPRESS_BYTES = 1024;
|
|
753
|
+
var MAX_BROTLI_QUALITY = 11;
|
|
754
|
+
var BROTLI_QUALITY_BY_EXT = { ".css": MAX_BROTLI_QUALITY };
|
|
755
|
+
var DEFAULT_BROTLI_QUALITY = 9;
|
|
756
|
+
var GZIP_LEVEL = 9;
|
|
757
|
+
var ROOT_BROTLI_QUALITY = {
|
|
758
|
+
client: undefined,
|
|
759
|
+
styles: undefined,
|
|
760
|
+
dict: MAX_BROTLI_QUALITY
|
|
761
|
+
};
|
|
762
|
+
var { formatBytes } = FontPruner;
|
|
763
|
+
async function precompressArtifacts(app) {
|
|
764
|
+
const artifactDir = path3.join(app.dist.cwdPath, ".akan/artifact");
|
|
765
|
+
const roots = Object.entries(ROOT_BROTLI_QUALITY).map(([dir, brotliQuality]) => ({
|
|
766
|
+
root: path3.join(artifactDir, dir),
|
|
767
|
+
brotliQuality
|
|
768
|
+
}));
|
|
769
|
+
const result = { files: 0, inputBytes: 0, outputBytes: 0, brotliBytes: 0 };
|
|
770
|
+
await Promise.all(roots.map(({ root, brotliQuality }) => precompressRoot(root, result, brotliQuality)));
|
|
771
|
+
if (result.files > 0) {
|
|
772
|
+
app.verbose(`[precompress] wrote ${result.files} sidecars (${formatBytes(result.inputBytes)} -> gzip ${formatBytes(result.outputBytes)} / br ${formatBytes(result.brotliBytes)})`);
|
|
773
|
+
}
|
|
774
|
+
return result;
|
|
775
|
+
}
|
|
776
|
+
async function precompressRoot(root, result, brotliQuality) {
|
|
777
|
+
if (!fs.existsSync(root) || !fs.statSync(root).isDirectory())
|
|
778
|
+
return;
|
|
779
|
+
const glob = new Bun.Glob("**/*");
|
|
780
|
+
for await (const filePath of glob.scan({ cwd: root, absolute: true })) {
|
|
781
|
+
if (!await shouldPrecompress(filePath))
|
|
782
|
+
continue;
|
|
783
|
+
const bytes = await Bun.file(filePath).bytes();
|
|
784
|
+
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
785
|
+
const gz = Bun.gzipSync(buffer, { level: GZIP_LEVEL });
|
|
786
|
+
const br = brotliCompress(buffer, brotliQuality ?? brotliQualityOf(path3.extname(filePath).toLowerCase()));
|
|
787
|
+
await Promise.all([Bun.write(`${filePath}.gz`, gz), Bun.write(`${filePath}.br`, br)]);
|
|
788
|
+
result.files += 1;
|
|
789
|
+
result.inputBytes += bytes.byteLength;
|
|
790
|
+
result.outputBytes += gz.byteLength;
|
|
791
|
+
result.brotliBytes += br.byteLength;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
async function servedBrotliBytesOf(artifactDir, filePath) {
|
|
795
|
+
const root = path3.relative(artifactDir, filePath).split(path3.sep)[0] ?? "";
|
|
796
|
+
if (!Object.hasOwn(ROOT_BROTLI_QUALITY, root) || !await shouldPrecompress(filePath))
|
|
797
|
+
return Bun.file(filePath).size;
|
|
798
|
+
const bytes = await Bun.file(filePath).bytes();
|
|
799
|
+
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
800
|
+
const quality = ROOT_BROTLI_QUALITY[root] ?? brotliQualityOf(path3.extname(filePath).toLowerCase());
|
|
801
|
+
return brotliCompress(buffer, quality).byteLength;
|
|
802
|
+
}
|
|
803
|
+
function brotliQualityOf(ext) {
|
|
804
|
+
return BROTLI_QUALITY_BY_EXT[ext] ?? DEFAULT_BROTLI_QUALITY;
|
|
805
|
+
}
|
|
806
|
+
function brotliCompress(buffer, quality) {
|
|
807
|
+
return zlib.brotliCompressSync(buffer, {
|
|
808
|
+
params: {
|
|
809
|
+
[zlib.constants.BROTLI_PARAM_QUALITY]: quality,
|
|
810
|
+
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: buffer.byteLength
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
async function shouldPrecompress(filePath) {
|
|
815
|
+
if (filePath.endsWith(".gz") || filePath.endsWith(".br"))
|
|
816
|
+
return false;
|
|
817
|
+
if (!COMPRESSIBLE_EXTS.has(path3.extname(filePath).toLowerCase()))
|
|
818
|
+
return false;
|
|
819
|
+
const file = Bun.file(filePath);
|
|
820
|
+
if (!await file.exists())
|
|
821
|
+
return false;
|
|
822
|
+
return file.size >= MIN_COMPRESS_BYTES;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// pkgs/@akanjs/devkit/app/routeJsBudget.ts
|
|
672
826
|
class RouteJsBudget {
|
|
673
827
|
kbByRoute;
|
|
674
828
|
env;
|
|
@@ -677,11 +831,13 @@ class RouteJsBudget {
|
|
|
677
831
|
static tableRows = 10;
|
|
678
832
|
static #relativeSlack = 0.01;
|
|
679
833
|
static #absoluteSlack = 4096;
|
|
680
|
-
static async measure(artifactDir, modulesByRoute) {
|
|
834
|
+
static async measure(artifactDir, modulesByRoute, { precompressed = true } = {}) {
|
|
681
835
|
const sizeByUrl = new Map;
|
|
682
836
|
const sizeOf = async (url) => {
|
|
683
|
-
const file =
|
|
837
|
+
const file = path4.join(artifactDir, url.replace(/^\/_akan\//, ""));
|
|
684
838
|
const raw = Bun.file(file).size;
|
|
839
|
+
if (!precompressed)
|
|
840
|
+
return { raw, brotli: await servedBrotliBytesOf(artifactDir, file) };
|
|
685
841
|
const sidecar = Bun.file(`${file}.br`);
|
|
686
842
|
return { raw, brotli: await sidecar.exists() ? sidecar.size : raw };
|
|
687
843
|
};
|
|
@@ -863,7 +1019,7 @@ class RouteJsBudget {
|
|
|
863
1019
|
}
|
|
864
1020
|
}
|
|
865
1021
|
|
|
866
|
-
// pkgs/@akanjs/devkit/applicationBuildReporter.ts
|
|
1022
|
+
// pkgs/@akanjs/devkit/app/applicationBuildReporter.ts
|
|
867
1023
|
class ApplicationBuildReporter {
|
|
868
1024
|
static create() {
|
|
869
1025
|
return {
|
|
@@ -893,45 +1049,7 @@ class ApplicationBuildReporter {
|
|
|
893
1049
|
}
|
|
894
1050
|
static localBuildNotice = "Built for local: the server runs without endpoint rate limits, and boots on local defaults (Redis on localhost, the first database mode) where a deployment would stop to ask. For a host others can reach, run `akan build <app> --env main` with AKAN_PUBLIC_REPO_NAME and AKAN_PUBLIC_SERVE_DOMAIN set in the shell or the workspace .env.";
|
|
895
1051
|
static formatError(error, workspaceRoot = process.cwd()) {
|
|
896
|
-
|
|
897
|
-
const nestedMessages = error.errors.map((nestedError, index) => ApplicationBuildReporter.formatError(nestedError, workspaceRoot).trim() || `Unknown error ${index + 1}`).map((message) => message.replace(/^/gm, " ")).join(`
|
|
898
|
-
`);
|
|
899
|
-
return nestedMessages ? `${error.message}
|
|
900
|
-
${nestedMessages}` : error.message;
|
|
901
|
-
}
|
|
902
|
-
if (error instanceof Error) {
|
|
903
|
-
const causeMessage = error.cause ? `
|
|
904
|
-
Caused by: ${ApplicationBuildReporter.formatError(error.cause, workspaceRoot)}` : "";
|
|
905
|
-
return `${ApplicationBuildReporter.#withLocation(error.message, error, workspaceRoot)}${causeMessage}`;
|
|
906
|
-
}
|
|
907
|
-
if (typeof error === "object" && error !== null && "message" in error)
|
|
908
|
-
return ApplicationBuildReporter.#withLocation(String(error.message), error, workspaceRoot);
|
|
909
|
-
return String(error);
|
|
910
|
-
}
|
|
911
|
-
static #withLocation(message, error, workspaceRoot) {
|
|
912
|
-
const { position } = error;
|
|
913
|
-
if (!position?.file)
|
|
914
|
-
return message;
|
|
915
|
-
const file = ApplicationBuildReporter.#relativeToWorkspace(position.file, workspaceRoot);
|
|
916
|
-
const location = position.line > 0 ? `${file}:${position.line}:${position.column}` : file;
|
|
917
|
-
return message.includes(location) ? message : message.replace(/^.*/, (headline) => `${headline} (${location})`);
|
|
918
|
-
}
|
|
919
|
-
static #relativeToWorkspace(file, workspaceRoot) {
|
|
920
|
-
if (!path4.isAbsolute(file))
|
|
921
|
-
return file;
|
|
922
|
-
for (const root of [workspaceRoot, ApplicationBuildReporter.#realpathOf(workspaceRoot)]) {
|
|
923
|
-
const relative = path4.relative(root, file);
|
|
924
|
-
if (!relative.startsWith(`..${path4.sep}`) && !path4.isAbsolute(relative))
|
|
925
|
-
return relative.replaceAll(path4.sep, "/");
|
|
926
|
-
}
|
|
927
|
-
return file;
|
|
928
|
-
}
|
|
929
|
-
static #realpathOf(dir) {
|
|
930
|
-
try {
|
|
931
|
-
return realpathSync(dir);
|
|
932
|
-
} catch {
|
|
933
|
-
return dir;
|
|
934
|
-
}
|
|
1052
|
+
return ErrorReport.format(error, workspaceRoot);
|
|
935
1053
|
}
|
|
936
1054
|
static formatDuration(ms) {
|
|
937
1055
|
if (ms < 1000)
|
|
@@ -1161,83 +1279,12 @@ var mergeInvalidateMessages = (current, next) => {
|
|
|
1161
1279
|
var buildStatusReplaySequence = (pendingReplay, latestByPhase) => [...pendingReplay, ...latestByPhase.values()];
|
|
1162
1280
|
var filesChangedSince = (before, after) => [...before].filter(([file, stamp]) => after.get(file) !== stamp).map(([file]) => file);
|
|
1163
1281
|
|
|
1164
|
-
// pkgs/@akanjs/devkit/frontendBuild/watchRootResolver.ts
|
|
1165
|
-
import fs from "fs";
|
|
1166
|
-
import { readFile } from "fs/promises";
|
|
1167
|
-
import path6 from "path";
|
|
1168
|
-
|
|
1169
|
-
class WatchRootResolver {
|
|
1170
|
-
#app;
|
|
1171
|
-
constructor(app) {
|
|
1172
|
-
this.#app = app;
|
|
1173
|
-
}
|
|
1174
|
-
async resolve() {
|
|
1175
|
-
const tsconfig = await this.#app.getTsConfig();
|
|
1176
|
-
const appDir = path6.resolve(this.#app.cwdPath);
|
|
1177
|
-
const appsContainer = path6.dirname(appDir);
|
|
1178
|
-
const libsContainer = path6.resolve(this.#app.workspace.workspaceRoot, "libs");
|
|
1179
|
-
const libRoots = (await this.#resolveLibDeps(libsContainer))?.map((name) => path6.join(libsContainer, name)).filter((dir) => fs.existsSync(dir));
|
|
1180
|
-
const set = new Set;
|
|
1181
|
-
set.add(path6.resolve(`${this.#app.cwdPath}/page`));
|
|
1182
|
-
for (const targets of Object.values(tsconfig.compilerOptions.paths ?? {})) {
|
|
1183
|
-
for (const target of targets) {
|
|
1184
|
-
if (!target)
|
|
1185
|
-
continue;
|
|
1186
|
-
if (path6.isAbsolute(target))
|
|
1187
|
-
continue;
|
|
1188
|
-
const cleaned = target.replace(/\/?\*+.*$/, "").replace(/\/[^/]+\.[^/]+$/, "");
|
|
1189
|
-
const resolved = path6.resolve(this.#app.workspace.workspaceRoot, cleaned);
|
|
1190
|
-
if (resolved === libsContainer && libRoots) {
|
|
1191
|
-
for (const root of libRoots)
|
|
1192
|
-
set.add(root);
|
|
1193
|
-
continue;
|
|
1194
|
-
}
|
|
1195
|
-
const root = resolved === appsContainer ? appDir : resolved;
|
|
1196
|
-
if (fs.existsSync(root))
|
|
1197
|
-
set.add(root);
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
return [...set];
|
|
1201
|
-
}
|
|
1202
|
-
async#resolveLibDeps(libsContainer) {
|
|
1203
|
-
const scanInfo = this.#app.getScanInfo({ allowEmpty: true });
|
|
1204
|
-
if (scanInfo?.type === "app")
|
|
1205
|
-
return scanInfo.libDeps;
|
|
1206
|
-
const direct = await WatchRootResolver.#readManifestLibDeps(path6.join(this.#app.cwdPath, "akan.app.json"));
|
|
1207
|
-
if (!direct)
|
|
1208
|
-
return null;
|
|
1209
|
-
const closure = new Set;
|
|
1210
|
-
const queue = [...direct];
|
|
1211
|
-
while (queue.length > 0) {
|
|
1212
|
-
const name = queue.shift();
|
|
1213
|
-
if (!name || closure.has(name))
|
|
1214
|
-
continue;
|
|
1215
|
-
closure.add(name);
|
|
1216
|
-
const nested = await WatchRootResolver.#readManifestLibDeps(path6.join(libsContainer, name, "akan.lib.json"));
|
|
1217
|
-
if (!nested)
|
|
1218
|
-
return null;
|
|
1219
|
-
queue.push(...nested);
|
|
1220
|
-
}
|
|
1221
|
-
return [...closure];
|
|
1222
|
-
}
|
|
1223
|
-
static async#readManifestLibDeps(manifestPath) {
|
|
1224
|
-
try {
|
|
1225
|
-
const parsed = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
1226
|
-
if (!Array.isArray(parsed.libDeps))
|
|
1227
|
-
return null;
|
|
1228
|
-
return parsed.libDeps.filter((name) => typeof name === "string" && name.length > 0);
|
|
1229
|
-
} catch {
|
|
1230
|
-
return null;
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
1282
|
// pkgs/@akanjs/devkit/frontendBuild/hmrWatcher.ts
|
|
1236
1283
|
import fs2 from "fs";
|
|
1237
|
-
import
|
|
1284
|
+
import path8 from "path";
|
|
1238
1285
|
|
|
1239
1286
|
// pkgs/@akanjs/devkit/frontendBuild/hmrChangeClassifier.ts
|
|
1240
|
-
import
|
|
1287
|
+
import path6 from "path";
|
|
1241
1288
|
var CSS_EXTS = new Set([".css"]);
|
|
1242
1289
|
var CONFIG_BASENAMES = new Set(["akan.config.ts", "bunfig.toml", "tsconfig.json", "package.json"]);
|
|
1243
1290
|
|
|
@@ -1245,10 +1292,10 @@ class HmrChangeClassifier {
|
|
|
1245
1292
|
classify(abs) {
|
|
1246
1293
|
if (this.#isUninteresting(abs))
|
|
1247
1294
|
return "ignore";
|
|
1248
|
-
const base =
|
|
1295
|
+
const base = path6.basename(abs);
|
|
1249
1296
|
if (CONFIG_BASENAMES.has(base))
|
|
1250
1297
|
return "config";
|
|
1251
|
-
const ext =
|
|
1298
|
+
const ext = path6.extname(abs).toLowerCase();
|
|
1252
1299
|
if (CSS_EXTS.has(ext))
|
|
1253
1300
|
return "css";
|
|
1254
1301
|
if (SOURCE_EXTS.has(ext))
|
|
@@ -1256,24 +1303,24 @@ class HmrChangeClassifier {
|
|
|
1256
1303
|
return "ignore";
|
|
1257
1304
|
}
|
|
1258
1305
|
#isUninteresting(abs) {
|
|
1259
|
-
const base =
|
|
1306
|
+
const base = path6.basename(abs);
|
|
1260
1307
|
if (!base)
|
|
1261
1308
|
return true;
|
|
1262
1309
|
if (base.startsWith("."))
|
|
1263
1310
|
return true;
|
|
1264
1311
|
if (base.endsWith("~") || base.endsWith(".swp") || base.endsWith(".swx") || base.endsWith(".tmp"))
|
|
1265
1312
|
return true;
|
|
1266
|
-
if (abs.includes(`${
|
|
1313
|
+
if (abs.includes(`${path6.sep}node_modules${path6.sep}`))
|
|
1267
1314
|
return true;
|
|
1268
|
-
if (abs.includes(`${
|
|
1315
|
+
if (abs.includes(`${path6.sep}.akan${path6.sep}`))
|
|
1269
1316
|
return true;
|
|
1270
1317
|
return false;
|
|
1271
1318
|
}
|
|
1272
1319
|
}
|
|
1273
1320
|
|
|
1274
1321
|
// pkgs/@akanjs/devkit/frontendBuild/sourceMtimeIndex.ts
|
|
1275
|
-
import { readdir, stat as stat3 } from "fs/promises";
|
|
1276
|
-
import
|
|
1322
|
+
import { readdir as readdir2, stat as stat3 } from "fs/promises";
|
|
1323
|
+
import path7 from "path";
|
|
1277
1324
|
var UNREADABLE = Number.NaN;
|
|
1278
1325
|
|
|
1279
1326
|
class SourceMtimeIndex {
|
|
@@ -1336,7 +1383,7 @@ class SourceMtimeIndex {
|
|
|
1336
1383
|
if (!this.#primed)
|
|
1337
1384
|
return;
|
|
1338
1385
|
await Promise.all(paths.map(async (file) => {
|
|
1339
|
-
const abs =
|
|
1386
|
+
const abs = path7.resolve(file);
|
|
1340
1387
|
const stats = await stat3(abs).catch(() => null);
|
|
1341
1388
|
if (!stats?.isFile()) {
|
|
1342
1389
|
this.#files.delete(abs);
|
|
@@ -1422,7 +1469,7 @@ class SourceMtimeIndex {
|
|
|
1422
1469
|
for (const entry of entries) {
|
|
1423
1470
|
if (SourceMtimeIndex.#skipDirent(entry.name))
|
|
1424
1471
|
continue;
|
|
1425
|
-
const abs =
|
|
1472
|
+
const abs = path7.join(dir, entry.name);
|
|
1426
1473
|
if (entry.isDirectory()) {
|
|
1427
1474
|
descend.push(abs);
|
|
1428
1475
|
continue;
|
|
@@ -1449,7 +1496,7 @@ class SourceMtimeIndex {
|
|
|
1449
1496
|
}
|
|
1450
1497
|
if (known) {
|
|
1451
1498
|
for (const abs of [...this.#files.keys()]) {
|
|
1452
|
-
if (present.has(abs) ||
|
|
1499
|
+
if (present.has(abs) || path7.dirname(abs) !== dir)
|
|
1453
1500
|
continue;
|
|
1454
1501
|
this.#files.delete(abs);
|
|
1455
1502
|
changed?.add(abs);
|
|
@@ -1467,7 +1514,7 @@ class SourceMtimeIndex {
|
|
|
1467
1514
|
this.#unsettled.delete(dir);
|
|
1468
1515
|
}
|
|
1469
1516
|
#forget(dir) {
|
|
1470
|
-
const prefix = `${dir}${
|
|
1517
|
+
const prefix = `${dir}${path7.sep}`;
|
|
1471
1518
|
this.#dirs.delete(dir);
|
|
1472
1519
|
this.#unreadable.delete(dir);
|
|
1473
1520
|
this.#unsettled.delete(dir);
|
|
@@ -1493,7 +1540,7 @@ class SourceMtimeIndex {
|
|
|
1493
1540
|
}
|
|
1494
1541
|
static async#readdirPath(dir) {
|
|
1495
1542
|
try {
|
|
1496
|
-
return { entries: await
|
|
1543
|
+
return { entries: await readdir2(dir, { withFileTypes: true }), err: null };
|
|
1497
1544
|
} catch (err) {
|
|
1498
1545
|
return { entries: null, err };
|
|
1499
1546
|
}
|
|
@@ -1505,8 +1552,8 @@ class SourceMtimeIndex {
|
|
|
1505
1552
|
return !name || name.startsWith(".") || name === "node_modules";
|
|
1506
1553
|
}
|
|
1507
1554
|
static #pruneNestedRoots(roots) {
|
|
1508
|
-
const resolved = [...new Set(roots.map((root) =>
|
|
1509
|
-
return resolved.filter((root) => !resolved.some((other) => other !== root && root.startsWith(`${other}${
|
|
1555
|
+
const resolved = [...new Set(roots.map((root) => path7.resolve(root)))].sort();
|
|
1556
|
+
return resolved.filter((root) => !resolved.some((other) => other !== root && root.startsWith(`${other}${path7.sep}`)));
|
|
1510
1557
|
}
|
|
1511
1558
|
}
|
|
1512
1559
|
|
|
@@ -1522,6 +1569,7 @@ class HmrWatcher {
|
|
|
1522
1569
|
#hinted = new Set;
|
|
1523
1570
|
#classifier = new HmrChangeClassifier;
|
|
1524
1571
|
#index;
|
|
1572
|
+
#scans = new Set;
|
|
1525
1573
|
#timer = null;
|
|
1526
1574
|
#verifyTimer = null;
|
|
1527
1575
|
#windowStartedAt = null;
|
|
@@ -1531,7 +1579,7 @@ class HmrWatcher {
|
|
|
1531
1579
|
#reportedCompensating = false;
|
|
1532
1580
|
#reportedGaps = "";
|
|
1533
1581
|
constructor(opts) {
|
|
1534
|
-
this.#roots = [...new Set(opts.roots.map((r) =>
|
|
1582
|
+
this.#roots = [...new Set(opts.roots.map((r) => path8.resolve(r)))];
|
|
1535
1583
|
this.#debounceMs = opts.debounceMs ?? HmrWatcher.#envDebounceMs() ?? 30;
|
|
1536
1584
|
this.#verifyDelayMs = opts.verifyDelayMs ?? 250;
|
|
1537
1585
|
this.#onBatch = opts.onBatch;
|
|
@@ -1547,7 +1595,7 @@ class HmrWatcher {
|
|
|
1547
1595
|
const w = fs2.watch(root, { recursive: true, persistent: false }, (_event, filename) => {
|
|
1548
1596
|
if (!filename)
|
|
1549
1597
|
return;
|
|
1550
|
-
const abs =
|
|
1598
|
+
const abs = path8.resolve(root, filename.toString());
|
|
1551
1599
|
this.#queue(abs);
|
|
1552
1600
|
});
|
|
1553
1601
|
w.on("error", (err) => {
|
|
@@ -1582,6 +1630,17 @@ class HmrWatcher {
|
|
|
1582
1630
|
} catch {}
|
|
1583
1631
|
}
|
|
1584
1632
|
}
|
|
1633
|
+
async close() {
|
|
1634
|
+
this.stop();
|
|
1635
|
+
await Promise.all(this.#scans);
|
|
1636
|
+
await this.#mergeDetectedChanges();
|
|
1637
|
+
if (this.#pending.size === 0)
|
|
1638
|
+
return null;
|
|
1639
|
+
const batch = { files: Array.from(this.#pending.keys()), kinds: new Set(this.#pending.values()) };
|
|
1640
|
+
this.#pending.clear();
|
|
1641
|
+
this.#hinted.clear();
|
|
1642
|
+
return batch;
|
|
1643
|
+
}
|
|
1585
1644
|
async absorb(paths) {
|
|
1586
1645
|
if (paths.length === 0)
|
|
1587
1646
|
return;
|
|
@@ -1622,6 +1681,8 @@ class HmrWatcher {
|
|
|
1622
1681
|
try {
|
|
1623
1682
|
while (!this.#stopped) {
|
|
1624
1683
|
await this.#mergeDetectedChanges();
|
|
1684
|
+
if (this.#stopped)
|
|
1685
|
+
break;
|
|
1625
1686
|
if (this.#pending.size === 0) {
|
|
1626
1687
|
this.#windowStartedAt = null;
|
|
1627
1688
|
break;
|
|
@@ -1647,7 +1708,12 @@ class HmrWatcher {
|
|
|
1647
1708
|
this.#scheduleVerify();
|
|
1648
1709
|
}
|
|
1649
1710
|
}
|
|
1650
|
-
|
|
1711
|
+
#mergeDetectedChanges() {
|
|
1712
|
+
const scan = this.#collectDetectedChanges().finally(() => this.#scans.delete(scan));
|
|
1713
|
+
this.#scans.add(scan);
|
|
1714
|
+
return scan;
|
|
1715
|
+
}
|
|
1716
|
+
async#collectDetectedChanges() {
|
|
1651
1717
|
const detected = await this.#index.collectChanges().catch((err) => {
|
|
1652
1718
|
this.#logger.error(`[hmr] mtime scan failed: ${err.message}`);
|
|
1653
1719
|
return [];
|
|
@@ -1711,4 +1777,75 @@ class HmrWatcher {
|
|
|
1711
1777
|
}
|
|
1712
1778
|
}
|
|
1713
1779
|
|
|
1714
|
-
|
|
1780
|
+
// pkgs/@akanjs/devkit/frontendBuild/watchRootResolver.ts
|
|
1781
|
+
import fs3 from "fs";
|
|
1782
|
+
import { readFile } from "fs/promises";
|
|
1783
|
+
import path9 from "path";
|
|
1784
|
+
|
|
1785
|
+
class WatchRootResolver {
|
|
1786
|
+
#app;
|
|
1787
|
+
constructor(app) {
|
|
1788
|
+
this.#app = app;
|
|
1789
|
+
}
|
|
1790
|
+
async resolve() {
|
|
1791
|
+
const tsconfig = await this.#app.getTsConfig();
|
|
1792
|
+
const appDir = path9.resolve(this.#app.cwdPath);
|
|
1793
|
+
const appsContainer = path9.dirname(appDir);
|
|
1794
|
+
const libsContainer = path9.resolve(this.#app.workspace.workspaceRoot, "libs");
|
|
1795
|
+
const libRoots = (await this.#resolveLibDeps(libsContainer))?.map((name) => path9.join(libsContainer, name)).filter((dir) => fs3.existsSync(dir));
|
|
1796
|
+
const set = new Set;
|
|
1797
|
+
set.add(path9.resolve(`${this.#app.cwdPath}/page`));
|
|
1798
|
+
for (const targets of Object.values(tsconfig.compilerOptions.paths ?? {})) {
|
|
1799
|
+
for (const target of targets) {
|
|
1800
|
+
if (!target)
|
|
1801
|
+
continue;
|
|
1802
|
+
if (path9.isAbsolute(target))
|
|
1803
|
+
continue;
|
|
1804
|
+
const cleaned = target.replace(/\/?\*+.*$/, "").replace(/\/[^/]+\.[^/]+$/, "");
|
|
1805
|
+
const resolved = path9.resolve(this.#app.workspace.workspaceRoot, cleaned);
|
|
1806
|
+
if (resolved === libsContainer && libRoots) {
|
|
1807
|
+
for (const root of libRoots)
|
|
1808
|
+
set.add(root);
|
|
1809
|
+
continue;
|
|
1810
|
+
}
|
|
1811
|
+
const root = resolved === appsContainer ? appDir : resolved;
|
|
1812
|
+
if (fs3.existsSync(root))
|
|
1813
|
+
set.add(root);
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
return [...set];
|
|
1817
|
+
}
|
|
1818
|
+
async#resolveLibDeps(libsContainer) {
|
|
1819
|
+
const scanInfo = this.#app.getScanInfo({ allowEmpty: true });
|
|
1820
|
+
if (scanInfo?.type === "app")
|
|
1821
|
+
return scanInfo.libDeps;
|
|
1822
|
+
const direct = await WatchRootResolver.#readManifestLibDeps(path9.join(this.#app.cwdPath, "akan.app.json"));
|
|
1823
|
+
if (!direct)
|
|
1824
|
+
return null;
|
|
1825
|
+
const closure = new Set;
|
|
1826
|
+
const queue = [...direct];
|
|
1827
|
+
while (queue.length > 0) {
|
|
1828
|
+
const name = queue.shift();
|
|
1829
|
+
if (!name || closure.has(name))
|
|
1830
|
+
continue;
|
|
1831
|
+
closure.add(name);
|
|
1832
|
+
const nested = await WatchRootResolver.#readManifestLibDeps(path9.join(libsContainer, name, "akan.lib.json"));
|
|
1833
|
+
if (!nested)
|
|
1834
|
+
return null;
|
|
1835
|
+
queue.push(...nested);
|
|
1836
|
+
}
|
|
1837
|
+
return [...closure];
|
|
1838
|
+
}
|
|
1839
|
+
static async#readManifestLibDeps(manifestPath) {
|
|
1840
|
+
try {
|
|
1841
|
+
const parsed = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
1842
|
+
if (!Array.isArray(parsed.libDeps))
|
|
1843
|
+
return null;
|
|
1844
|
+
return parsed.libDeps.filter((name) => typeof name === "string" && name.length > 0);
|
|
1845
|
+
} catch {
|
|
1846
|
+
return null;
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
export { UNAVAILABLE_REDIS_HOST, redisTunnelPolicy, backendRecoveryPolicy, BUILDER_MIN_RSS_RECYCLE_INTERVAL_MS, SOURCE_EXTS, shouldRestartBackendByDevPlan, shouldRestartBuilderByDevPlan, normalizeBackendReportedGeneration, shouldRestartDevHostByDevPlan, devHostStateOf, isLegacyBackendFallbackFile, shouldMarkBuildPhaseRecovered, shouldKeepBuildFailure, createBackendBuildStatus, backendRestartReasonFromMessage, mergeBackendRestartReasons, shouldReplaceLastGoodMessage, shouldQueueBuildStatusReplay, hasBuildFailureForGeneration, decideBuilderRssRecycle, decideBuilderRssSettle, decideIdleSuspend, resolveIdleSuspendMs, hasAnyBuildFailure, shouldRefreshConfigOnIdleWake, shouldHoldForReturningBuilder, shouldWarnBuilderRssCeilingTight, isRssCeilingUnreachable, shouldRelayRecycledFrontendState, mergeInvalidateMessages, buildStatusReplaySequence, filesChangedSince, HmrWatcher, WatchRootResolver, buildCacheStamp, isBuildCacheStamp, FontOptimizer, FontPruner, precompressArtifacts, RouteJsBudget, ApplicationBuildReporter };
|