@akanjs/cli 3.2.0-rc.0 → 3.2.0-rc.10
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 -1
- package/{CodeAgent-h6g8dg3a.js → CodeAgent-fk66n37w.js} +3 -3
- package/{CodeTui-n9gacepn.js → CodeTui-4rf1mqmv.js} +1 -1
- package/README.ko.md +26 -1
- package/README.md +26 -1
- package/TunnelShare-44er4e29.js +15 -0
- package/{agent.command-2f657613.js → agent.command-7g9czkkd.js} +20 -19
- package/akanCode.js +6 -6
- package/{application.command-yb8v177e.js → application.command-00spg55s.js} +31 -24
- package/{applicationBuildRunner-sctcmkyx.js → applicationBuildRunner-f4yf0qyc.js} +9 -7
- package/buildBatch.proc.js +7 -6
- package/{cloud.command-et06ja22.js → cloud.command-ab704p0g.js} +24 -25
- package/cloud.script-4p4y0s7e.js +31 -0
- package/{code.command-7m67c7zc.js → code.command-m6c9xk56.js} +7 -6
- package/{context.command-569z0rqf.js → context.command-hgcgxtdk.js} +20 -19
- package/context.runner-w071gmc3.js +30 -0
- package/{devTui-evr3b35y.js → devTui-h77zrjv5.js} +1 -1
- package/{guideline.command-gnv3e8p8.js → guideline.command-6yz6d4hf.js} +3 -2
- package/guidelines/agentRule/agentRule.instruction.md +4 -3
- package/guidelines/conventions/core.md +1 -1
- package/guidelines/conventions/rules/app.md +3 -0
- package/guidelines/conventions/rules/page.md +5 -0
- package/guidelines/errorCodes/errorCodes.instruction.md +140 -0
- package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
- package/guidelines/mcpRule/mcpRule.instruction.md +28 -0
- package/guidelines/pageRule/pageRule.instruction.md +5 -0
- package/guidelines/runtimeRule/runtimeRule.instruction.md +5 -1
- package/guidelines/transportRule/transportRule.instruction.md +5 -0
- package/incrementalBuilder.proc.js +8 -7
- package/{index-vkzfk7qt.js → index-097bjwvm.js} +40 -30
- package/{index-93ewzmp6.js → index-23d8gw08.js} +165 -102
- package/{index-p6hjwt2d.js → index-41mfhgq0.js} +72 -26
- package/{index-ktb3wcqz.js → index-4k9nv4m3.js} +71 -81
- package/{index-ryrm5z2c.js → index-5jwx4bf2.js} +69 -33
- package/{index-5w9my9qe.js → index-6eptmk8z.js} +30 -20
- package/{index-d4n1wmrz.js → index-6fnrhpn1.js} +8 -4
- package/{index-kpdv34rq.js → index-6qtxs86x.js} +10 -7
- package/{index-ed6ea0qp.js → index-6z57w95f.js} +1 -1
- package/{index-drz9e84d.js → index-7ky4brfy.js} +2 -2
- package/{index-8g7tdsk4.js → index-849qvd7t.js} +58 -29
- package/{index-1q1cjn8s.js → index-9xh4zvw3.js} +94 -53
- package/{index-48d5qsj3.js → index-adj7qmz9.js} +23 -15
- package/{index-fjr4d6yd.js → index-apcr1qgk.js} +458 -304
- package/{index-8ts9774g.js → index-aybfcx58.js} +9 -4
- package/{index-3wjbhj2n.js → index-b3pr4ee6.js} +1 -1
- package/{index-tenw3mah.js → index-b4qq3rq0.js} +32 -7
- package/{index-thckcabc.js → index-bper31wr.js} +24 -6
- package/{index-jdamtr7e.js → index-bxkx0x03.js} +17 -10
- package/{index-0fb3cpbt.js → index-c3r23w24.js} +9 -7
- package/{index-8pb9yvp8.js → index-dfsa009c.js} +148 -31
- package/{index-zpv14wpy.js → index-dsg50er9.js} +3 -3
- package/{index-hqrkqxx2.js → index-e5f6czck.js} +46 -7
- package/{index-sy481q2x.js → index-frvjq1rd.js} +1 -1
- package/{index-abgh0jve.js → index-grt0e6kk.js} +1 -1
- package/{index-e3vmjtph.js → index-hf9nvwam.js} +7 -2
- package/{index-zxsygkda.js → index-hhagjhkh.js} +7 -7
- package/index-j4yvgfhr.js +70 -0
- package/{index-s2grpzef.js → index-k2r3hmbz.js} +6 -4
- package/{index-7y5yghjg.js → index-nd39rssn.js} +1162 -435
- package/{index-6wpaq392.js → index-p4htjyvk.js} +44 -5
- package/{index-aj3ehkcx.js → index-p54s83sz.js} +1 -1
- package/{index-7xdpww43.js → index-rdx8cyv2.js} +342 -134
- package/{index-sr5da35e.js → index-sq9d0jhj.js} +21 -18
- package/{index-eajbmk10.js → index-t4d0ckde.js} +2 -2
- package/{index-mqntfzv5.js → index-t8h09yjs.js} +7 -2
- package/index-va90m8nd.js +25 -0
- package/{index-rc5fvqj2.js → index-xfv2p7b5.js} +95 -58
- package/{index-w639tvkd.js → index-xgqz3kak.js} +29 -8
- package/{index-9tbgb4d8.js → index-xy70tcv4.js} +1 -1
- package/{index-mmym5xmb.js → index-z43wddce.js} +5 -3
- package/index.js +24 -23
- package/{library.command-1gp5qe3r.js → library.command-kc1zahcg.js} +5 -4
- package/{localRegistry.command-v3g21rex.js → localRegistry.command-bz2df40m.js} +19 -18
- package/{module.command-4xz9he6h.js → module.command-cchwzz9r.js} +12 -7
- package/{package.command-s7qpnn1g.js → package.command-qcjajpv8.js} +8 -7
- package/package.json +2 -2
- package/{page.command-fan34c49.js → page.command-1t86dx8a.js} +4 -3
- package/{pipeline.command-ph4fnn9w.js → pipeline.command-2xx9z3d0.js} +3 -2
- package/{primitive.command-3fqh8emf.js → primitive.command-mc0x8txr.js} +8 -7
- package/{projectTypecheck-vkb40hjc.js → projectTypecheck-tz497yx7.js} +2 -1
- package/{quality.command-ecj6exsh.js → quality.command-11rayf5c.js} +7 -6
- package/{repair.command-fe9jw719.js → repair.command-8w41vy78.js} +7 -6
- package/{scalar.command-cnvfhk0n.js → scalar.command-rvwh98ny.js} +7 -6
- package/skills/akan-debug/SKILL.md +7 -3
- package/skills/akan-err/SKILL.md +7 -0
- package/skills/akan-mcp/SKILL.md +7 -1
- package/skills/akan-scaffold/SKILL.md +3 -2
- package/skills/akan-transport/SKILL.md +2 -0
- package/skills/akan-validate/SKILL.md +1 -0
- package/{subspace.command-yxtt3v3e.js → subspace.command-0970n7kd.js} +9 -8
- package/{tunnel.command-ggj38mqf.js → tunnel.command-bcy0rtmh.js} +8 -7
- package/typecheck.proc.js +5 -2
- package/{verify.command-w9ttxkdz.js → verify.command-ynaztxr2.js} +18 -16
- package/{workflow.command-ss8devj0.js → workflow.command-yp9ajthb.js} +45 -16
- package/{workspace.command-rw1p0xeq.js → workspace.command-e4wfxm86.js} +39 -34
- package/TunnelShare-k3ja4w9x.js +0 -14
- package/cloud.script-s6rbrwer.js +0 -30
- package/context.runner-ms8v1rxy.js +0 -29
|
@@ -5,12 +5,13 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
SOURCE_EXTS,
|
|
7
7
|
WatchRootResolver
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-41mfhgq0.js";
|
|
9
9
|
import {
|
|
10
10
|
loaderFor,
|
|
11
11
|
BarrelAnalyzer,
|
|
12
12
|
createBarrelImportsPlugin,
|
|
13
13
|
createTsconfigPackageResolver,
|
|
14
|
+
workspaceBarrels,
|
|
14
15
|
rewriteBarrelImports,
|
|
15
16
|
bundleConditions,
|
|
16
17
|
bundleDefine,
|
|
@@ -20,12 +21,12 @@ import {
|
|
|
20
21
|
CsrDevPaths,
|
|
21
22
|
PagesEntrySourceGenerator,
|
|
22
23
|
PagesBundleBuilder
|
|
23
|
-
} from "./index-
|
|
24
|
+
} from "./index-9xh4zvw3.js";
|
|
24
25
|
import {
|
|
25
26
|
AsyncDefaultExportDetector,
|
|
26
27
|
StoreBootstrap,
|
|
27
28
|
resolveSsrPageEntriesForApp
|
|
28
|
-
} from "./index-
|
|
29
|
+
} from "./index-sq9d0jhj.js";
|
|
29
30
|
|
|
30
31
|
// pkgs/@akanjs/devkit/frontendBuild/autoImportSync.ts
|
|
31
32
|
import { readdir, readFile, stat } from "fs/promises";
|
|
@@ -576,6 +577,7 @@ var USE_CLIENT_RE = /^\s*(?:\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\/\s*|\/\/[^\n]*\n\s*)
|
|
|
576
577
|
var NODE_MODULES_RE = /[\\/]node_modules[\\/]/;
|
|
577
578
|
var AKANJS_NODE_MODULE_RE = /[\\/]node_modules[\\/]akanjs[\\/]/;
|
|
578
579
|
var NON_SOURCE_EXT_RE = /\.(css|scss|sass|less|json|svg|png|jpe?g|webp|gif|avif|ico|woff2?|ttf|otf|mp3|mp4|wav)$/i;
|
|
580
|
+
var exportsKeyOf = (map) => JSON.stringify(map ? [...map].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0) : null);
|
|
579
581
|
var shouldSkipNodeModule = (absPath) => NODE_MODULES_RE.test(absPath) && !AKANJS_NODE_MODULE_RE.test(absPath);
|
|
580
582
|
|
|
581
583
|
class GraphClientEntryDiscovery {
|
|
@@ -588,7 +590,11 @@ class GraphClientEntryDiscovery {
|
|
|
588
590
|
#resolvedFileCache = new Map;
|
|
589
591
|
#resolvedSpecifierCache = new Map;
|
|
590
592
|
#reachableEntriesCache = new Map;
|
|
593
|
+
#swappedEntriesCaches = new WeakMap;
|
|
591
594
|
#readFiles = new Set;
|
|
595
|
+
#barrelImporters = new Map;
|
|
596
|
+
#reread = new Map;
|
|
597
|
+
#settled = Promise.resolve();
|
|
592
598
|
#epoch = 0;
|
|
593
599
|
constructor(akanConfig, resolvePackage) {
|
|
594
600
|
this.#akanConfig = akanConfig;
|
|
@@ -598,15 +604,27 @@ class GraphClientEntryDiscovery {
|
|
|
598
604
|
static async create(app) {
|
|
599
605
|
return new GraphClientEntryDiscovery(await app.getConfig(), await createTsconfigPackageResolver(app));
|
|
600
606
|
}
|
|
601
|
-
async discover(seeds) {
|
|
607
|
+
async discover(seeds, { importsAs } = {}) {
|
|
608
|
+
this.#settled = this.#settled.then(() => this.#dropRenarrowed());
|
|
609
|
+
await this.#settled;
|
|
602
610
|
const entries = new Set;
|
|
611
|
+
const reachable = importsAs ? this.#swappedEntriesCache(importsAs) : this.#reachableEntriesCache;
|
|
603
612
|
for (const seed of seeds) {
|
|
604
|
-
const walk = { visiting: new Set, partial: new Set, memo: new Map };
|
|
613
|
+
const walk = { visiting: new Set, partial: new Set, memo: new Map, importsAs, reachable };
|
|
605
614
|
for (const entry of await this.#discoverFromFile(seed, walk))
|
|
606
615
|
entries.add(entry);
|
|
607
616
|
}
|
|
608
617
|
return Array.from(entries).sort();
|
|
609
618
|
}
|
|
619
|
+
async resolveImport(spec, importerDir) {
|
|
620
|
+
const resolved = await this.#resolveSpecifier(spec, importerDir);
|
|
621
|
+
return resolved ? path2.resolve(resolved) : null;
|
|
622
|
+
}
|
|
623
|
+
#swappedEntriesCache(importsAs) {
|
|
624
|
+
const cache = this.#swappedEntriesCaches.get(importsAs) ?? new Map;
|
|
625
|
+
this.#swappedEntriesCaches.set(importsAs, cache);
|
|
626
|
+
return cache;
|
|
627
|
+
}
|
|
610
628
|
invalidate(files) {
|
|
611
629
|
if (files.length === 0)
|
|
612
630
|
return;
|
|
@@ -623,12 +641,27 @@ class GraphClientEntryDiscovery {
|
|
|
623
641
|
}
|
|
624
642
|
this.#epoch += 1;
|
|
625
643
|
this.#reachableEntriesCache.clear();
|
|
644
|
+
this.#swappedEntriesCaches = new WeakMap;
|
|
645
|
+
for (const [barrel, before] of this.#analyzer.forget(files))
|
|
646
|
+
if (!this.#reread.has(barrel))
|
|
647
|
+
this.#reread.set(barrel, before);
|
|
626
648
|
if (!moved)
|
|
627
649
|
return;
|
|
628
650
|
this.#fileExistsCache.clear();
|
|
629
651
|
this.#resolvedFileCache.clear();
|
|
630
652
|
this.#resolvedSpecifierCache.clear();
|
|
631
653
|
}
|
|
654
|
+
async#dropRenarrowed() {
|
|
655
|
+
const reread = [...this.#reread];
|
|
656
|
+
this.#reread.clear();
|
|
657
|
+
for (const [barrel, before] of reread) {
|
|
658
|
+
const [was, now] = await Promise.all([before, this.#analyzer.analyze(barrel)]);
|
|
659
|
+
if (exportsKeyOf(was) === exportsKeyOf(now))
|
|
660
|
+
continue;
|
|
661
|
+
for (const importer of this.#barrelImporters.get(barrel) ?? [])
|
|
662
|
+
this.#factsCache.delete(importer);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
632
665
|
#lookup(cache, key, run, isFound) {
|
|
633
666
|
const cached = cache.get(key);
|
|
634
667
|
if (cached && (cached.found || cached.epoch === this.#epoch))
|
|
@@ -657,15 +690,17 @@ class GraphClientEntryDiscovery {
|
|
|
657
690
|
this.#readFiles.add(absPath);
|
|
658
691
|
if (USE_CLIENT_RE.test(content))
|
|
659
692
|
return { isClientEntry: true, imports: [] };
|
|
660
|
-
return { isClientEntry: false, imports: this.#scanImports(await this.#rewrite(content)) };
|
|
693
|
+
return { isClientEntry: false, imports: this.#scanImports(await this.#rewrite(content, absPath)) };
|
|
661
694
|
})();
|
|
662
695
|
this.#factsCache.set(absPath, cached);
|
|
663
696
|
}
|
|
664
697
|
return cached;
|
|
665
698
|
}
|
|
666
|
-
async#rewrite(content) {
|
|
699
|
+
async#rewrite(content, absPath) {
|
|
667
700
|
if (this.#akanConfig.barrelImports.length === 0)
|
|
668
701
|
return content;
|
|
702
|
+
for (const barrel of this.#akanConfig.barrelImports.filter((barrel) => content.includes(barrel)))
|
|
703
|
+
this.#barrelImporters.set(barrel, (this.#barrelImporters.get(barrel) ?? new Set).add(absPath));
|
|
669
704
|
try {
|
|
670
705
|
return await rewriteBarrelImports(content, this.#akanConfig.barrelImports, this.#analyzer) ?? content;
|
|
671
706
|
} catch {
|
|
@@ -711,7 +746,8 @@ class GraphClientEntryDiscovery {
|
|
|
711
746
|
async#discoverFromFile(file, walk) {
|
|
712
747
|
const epoch = this.#epoch;
|
|
713
748
|
const absPath = path2.resolve(file);
|
|
714
|
-
const
|
|
749
|
+
const importsAs = walk.importsAs?.get(absPath);
|
|
750
|
+
const cached = walk.reachable.get(absPath);
|
|
715
751
|
if (cached)
|
|
716
752
|
return new Set(cached);
|
|
717
753
|
const memo = walk.memo.get(absPath);
|
|
@@ -744,7 +780,8 @@ class GraphClientEntryDiscovery {
|
|
|
744
780
|
}
|
|
745
781
|
const importerDir = path2.dirname(absPath);
|
|
746
782
|
for (const imp of facts.imports) {
|
|
747
|
-
const
|
|
783
|
+
const swapped = importsAs?.get(imp.path);
|
|
784
|
+
const spec = swapped === undefined ? imp.path : swapped;
|
|
748
785
|
if (!spec)
|
|
749
786
|
continue;
|
|
750
787
|
if (NON_SOURCE_EXT_RE.test(spec))
|
|
@@ -763,19 +800,19 @@ class GraphClientEntryDiscovery {
|
|
|
763
800
|
walk.visiting.delete(absPath);
|
|
764
801
|
walk.memo.set(absPath, entries);
|
|
765
802
|
if (epoch === this.#epoch && !walk.partial.has(absPath))
|
|
766
|
-
|
|
803
|
+
walk.reachable.set(absPath, entries);
|
|
767
804
|
return new Set(entries);
|
|
768
805
|
}
|
|
769
806
|
}
|
|
770
807
|
|
|
771
808
|
// pkgs/@akanjs/devkit/frontendBuild/csrDevBundler.ts
|
|
772
809
|
import { mkdir as mkdir3 } from "fs/promises";
|
|
773
|
-
import
|
|
810
|
+
import path12 from "path";
|
|
774
811
|
import { CSR_DEV_DIRNAME, CSR_DEV_ROUTE_PREFIX } from "akanjs/server/hmr/csrDevManifest";
|
|
775
812
|
|
|
776
813
|
// pkgs/@akanjs/devkit/frontendBuild/devRegistryBundler.ts
|
|
777
814
|
import fs7 from "fs";
|
|
778
|
-
import
|
|
815
|
+
import path11 from "path";
|
|
779
816
|
import { isAkanRuntimeMetadataFile } from "akanjs/server/hmr/runtimeMetadataFile";
|
|
780
817
|
|
|
781
818
|
// pkgs/@akanjs/devkit/frontendBuild/csrDevArtifactWriter.ts
|
|
@@ -992,7 +1029,7 @@ class CsrDevArtifactWriter {
|
|
|
992
1029
|
}
|
|
993
1030
|
|
|
994
1031
|
// pkgs/@akanjs/devkit/frontendBuild/csrDevModuleCompiler.ts
|
|
995
|
-
import
|
|
1032
|
+
import path8 from "path";
|
|
996
1033
|
|
|
997
1034
|
// pkgs/@akanjs/devkit/frontendBuild/csrDevFactoryCheck.ts
|
|
998
1035
|
class CsrDevFactoryCheck {
|
|
@@ -1307,14 +1344,112 @@ class CsrDevResolver {
|
|
|
1307
1344
|
}
|
|
1308
1345
|
}
|
|
1309
1346
|
|
|
1347
|
+
// pkgs/@akanjs/devkit/frontendBuild/devBarrelImports.ts
|
|
1348
|
+
import path5 from "path";
|
|
1349
|
+
class DevBarrelImports {
|
|
1350
|
+
#barrels;
|
|
1351
|
+
#resolvePackage;
|
|
1352
|
+
#analyzer;
|
|
1353
|
+
#packages = new Map;
|
|
1354
|
+
constructor(barrels, resolvePackage) {
|
|
1355
|
+
this.#barrels = [...barrels];
|
|
1356
|
+
this.#resolvePackage = resolvePackage;
|
|
1357
|
+
this.#analyzer = new BarrelAnalyzer({ resolvePackage });
|
|
1358
|
+
}
|
|
1359
|
+
static async create(app, barrels) {
|
|
1360
|
+
if (barrels.length === 0)
|
|
1361
|
+
return null;
|
|
1362
|
+
return new DevBarrelImports(barrels, await createTsconfigPackageResolver(app));
|
|
1363
|
+
}
|
|
1364
|
+
async rewrite(source, importer) {
|
|
1365
|
+
const named = this.#barrels.filter((barrel) => source.includes(barrel));
|
|
1366
|
+
if (named.length === 0)
|
|
1367
|
+
return null;
|
|
1368
|
+
const packages = await this.#packagesOf(named);
|
|
1369
|
+
const from = path5.dirname(CsrDevPaths.realpath(importer));
|
|
1370
|
+
const names = new Map;
|
|
1371
|
+
const contents = await rewriteBarrelImports(source, named, this.#analyzer, {
|
|
1372
|
+
keepLines: true,
|
|
1373
|
+
specifierOf: (subpath) => DevBarrelImports.#relative(subpath, from, packages),
|
|
1374
|
+
onImport: (barrel, imported) => names.set(barrel, new Set([...names.get(barrel) ?? [], ...imported]))
|
|
1375
|
+
});
|
|
1376
|
+
const narrowed = await Promise.all([...names].map(async ([barrel, set]) => {
|
|
1377
|
+
const sorted = [...set].sort();
|
|
1378
|
+
return [barrel, { names: sorted, hash: await this.fingerprint(barrel, sorted) }];
|
|
1379
|
+
}));
|
|
1380
|
+
return { contents, narrowed: Object.fromEntries(narrowed) };
|
|
1381
|
+
}
|
|
1382
|
+
async fingerprint(barrel, names) {
|
|
1383
|
+
const packages = await this.#packagesOf([barrel]);
|
|
1384
|
+
const aliased = names.map((name, index) => `${name} as _${index}`).join(", ");
|
|
1385
|
+
const narrowed = await rewriteBarrelImports(`import { ${aliased} } from ${JSON.stringify(barrel)};`, [barrel], this.#analyzer, { specifierOf: (subpath) => DevBarrelImports.#fileOf(subpath, packages) ?? subpath });
|
|
1386
|
+
return Bun.hash(narrowed ?? "").toString(36);
|
|
1387
|
+
}
|
|
1388
|
+
async stamps(barrels, idOf) {
|
|
1389
|
+
const stamped = await Promise.all([...barrels].map(async (barrel) => {
|
|
1390
|
+
const files = await this.#analyzer.filesOf(barrel);
|
|
1391
|
+
const read = [...new Set([...files, ...files.map((file) => path5.dirname(file))])];
|
|
1392
|
+
const stamp = {
|
|
1393
|
+
read: Object.fromEntries(read.map((file) => [idOf(file), CsrDevPaths.mtimeOf(file)])),
|
|
1394
|
+
digest: await this.#digest(barrel)
|
|
1395
|
+
};
|
|
1396
|
+
return [barrel, stamp];
|
|
1397
|
+
}));
|
|
1398
|
+
return Object.fromEntries(stamped);
|
|
1399
|
+
}
|
|
1400
|
+
async#digest(barrel) {
|
|
1401
|
+
const map = await this.#analyzer.analyze(barrel);
|
|
1402
|
+
const packages = await this.#packagesOf([barrel]);
|
|
1403
|
+
const files = new Map;
|
|
1404
|
+
const fileOf = (subpath) => {
|
|
1405
|
+
let file = files.get(subpath);
|
|
1406
|
+
if (file === undefined) {
|
|
1407
|
+
file = DevBarrelImports.#fileOf(subpath, packages) ?? subpath;
|
|
1408
|
+
files.set(subpath, file);
|
|
1409
|
+
}
|
|
1410
|
+
return file;
|
|
1411
|
+
};
|
|
1412
|
+
const exports = [...map ?? []].map(([name, target]) => [name, target.originalName, !!target.namespace, fileOf(target.subpath)]).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
1413
|
+
return Bun.hash(JSON.stringify([fileOf(barrel), map === null, exports])).toString(36);
|
|
1414
|
+
}
|
|
1415
|
+
async#packagesOf(barrels) {
|
|
1416
|
+
return (await Promise.all(barrels.map((barrel) => this.#packageOf(barrel)))).filter((pkg) => pkg !== null).sort((a, b) => b.pkgName.length - a.pkgName.length);
|
|
1417
|
+
}
|
|
1418
|
+
#packageOf(barrel) {
|
|
1419
|
+
let pkg = this.#packages.get(barrel);
|
|
1420
|
+
if (!pkg) {
|
|
1421
|
+
pkg = this.#resolvePackage(barrel);
|
|
1422
|
+
this.#packages.set(barrel, pkg);
|
|
1423
|
+
}
|
|
1424
|
+
return pkg;
|
|
1425
|
+
}
|
|
1426
|
+
static #fileOf(subpath, packages) {
|
|
1427
|
+
const pkg = packages.find(({ pkgName }) => subpath === pkgName || subpath.startsWith(`${pkgName}/`));
|
|
1428
|
+
if (!pkg)
|
|
1429
|
+
return null;
|
|
1430
|
+
const file = CsrDevPaths.resolveOnDisk(path5.join(pkg.pkgDir, subpath.slice(pkg.pkgName.length)));
|
|
1431
|
+
return file ? CsrDevPaths.realpath(file) : null;
|
|
1432
|
+
}
|
|
1433
|
+
static #relative(subpath, from, packages) {
|
|
1434
|
+
const file = DevBarrelImports.#fileOf(subpath, packages);
|
|
1435
|
+
if (!file)
|
|
1436
|
+
return subpath;
|
|
1437
|
+
const relative = path5.relative(from, file);
|
|
1438
|
+
if (path5.isAbsolute(relative))
|
|
1439
|
+
return file.split(path5.sep).join("/");
|
|
1440
|
+
const posix = relative.split(path5.sep).join("/");
|
|
1441
|
+
return posix.startsWith("../") ? posix : `./${posix}`;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1310
1445
|
// pkgs/@akanjs/devkit/frontendBuild/routeClientBuilder.ts
|
|
1311
1446
|
import { mkdir as mkdir2 } from "fs/promises";
|
|
1312
|
-
import
|
|
1447
|
+
import path7 from "path";
|
|
1313
1448
|
import { SSR_DEV_CHUNK, SSR_DEV_ID_PREFIX } from "akanjs/server/hmr/csrDevManifest";
|
|
1314
1449
|
|
|
1315
1450
|
// pkgs/@akanjs/devkit/frontendBuild/clientEntriesBundler.ts
|
|
1316
1451
|
import fs4 from "fs";
|
|
1317
|
-
import
|
|
1452
|
+
import path6 from "path";
|
|
1318
1453
|
|
|
1319
1454
|
// pkgs/@akanjs/devkit/frontendBuild/clientBuildTypes.ts
|
|
1320
1455
|
var CLIENT_BUNDLE_NAMING = {
|
|
@@ -1405,25 +1540,25 @@ class ClientEntriesBundler {
|
|
|
1405
1540
|
};
|
|
1406
1541
|
}
|
|
1407
1542
|
async#createOpaqueEntryAliases() {
|
|
1408
|
-
const aliasDir =
|
|
1543
|
+
const aliasDir = path6.join(this.#app.cwdPath, ".akan", "generated", "client-entry-alias", this.#outputSubdir);
|
|
1409
1544
|
fs4.mkdirSync(aliasDir, { recursive: true });
|
|
1410
1545
|
const originalByAlias = new Map;
|
|
1411
1546
|
const aliasedEntries = await Promise.all(this.#entries.map(async (entry) => {
|
|
1412
|
-
const absEntry =
|
|
1547
|
+
const absEntry = path6.resolve(entry);
|
|
1413
1548
|
const narrowed = this.#entryExports[absEntry];
|
|
1414
1549
|
const key = `${this.#app.name}
|
|
1415
1550
|
${this.#outputSubdir}
|
|
1416
1551
|
${absEntry}${narrowed ? `
|
|
1417
1552
|
narrowed` : ""}`;
|
|
1418
|
-
const aliasPath =
|
|
1553
|
+
const aliasPath = path6.join(aliasDir, `${Bun.hash(key).toString(36)}.tsx`);
|
|
1419
1554
|
await Bun.write(aliasPath, narrowed ? ClientEntriesBundler.narrowedAliasSource(absEntry, narrowed) : this.#createOpaqueEntryAliasSource(absEntry, await this.#scanEntryExportNames(absEntry)));
|
|
1420
|
-
originalByAlias.set(
|
|
1555
|
+
originalByAlias.set(path6.resolve(aliasPath), absEntry);
|
|
1421
1556
|
return aliasPath;
|
|
1422
1557
|
}));
|
|
1423
1558
|
return { entries: aliasedEntries, originalByAlias, aliasDir };
|
|
1424
1559
|
}
|
|
1425
1560
|
#createOpaqueEntryAliasSource(absEntry, exportNames) {
|
|
1426
|
-
const entryLit = JSON.stringify(
|
|
1561
|
+
const entryLit = JSON.stringify(path6.resolve(absEntry));
|
|
1427
1562
|
if (exportNames.length === 0)
|
|
1428
1563
|
return `export * from ${entryLit};
|
|
1429
1564
|
`;
|
|
@@ -1437,17 +1572,17 @@ narrowed` : ""}`;
|
|
|
1437
1572
|
}
|
|
1438
1573
|
static narrowedAliasSource(absEntry, names) {
|
|
1439
1574
|
const list = names.length > 0 ? `{ ${names.join(", ")} }` : "{}";
|
|
1440
|
-
return `export ${list} from ${JSON.stringify(
|
|
1575
|
+
return `export ${list} from ${JSON.stringify(path6.resolve(absEntry))};
|
|
1441
1576
|
`;
|
|
1442
1577
|
}
|
|
1443
1578
|
#assertNarrowedExports() {
|
|
1444
1579
|
const missing = Object.entries(this.#entryExports).flatMap(([absEntry, names = []]) => {
|
|
1445
1580
|
const absOut = this.#entryOutputAbsByAbsPath.get(absEntry);
|
|
1446
1581
|
if (!absOut)
|
|
1447
|
-
return [`${
|
|
1582
|
+
return [`${path6.basename(absEntry)}: no output`];
|
|
1448
1583
|
const exported = new Set(this.#metafileOutputsByAbs.get(absOut)?.exports);
|
|
1449
1584
|
const absent = names.filter((name) => !exported.has(name));
|
|
1450
|
-
return absent.length > 0 ? [`${
|
|
1585
|
+
return absent.length > 0 ? [`${path6.basename(absEntry)}: ${absent.join(", ")}`] : [];
|
|
1451
1586
|
});
|
|
1452
1587
|
if (missing.length > 0)
|
|
1453
1588
|
throw new Error(`[ClientEntriesBundler] client code imports names its vendor does not export (${missing.join("; ")})`);
|
|
@@ -1509,16 +1644,16 @@ narrowed` : ""}`;
|
|
|
1509
1644
|
return rewritten;
|
|
1510
1645
|
}
|
|
1511
1646
|
#toServeUrl(absOutPath) {
|
|
1512
|
-
const rel =
|
|
1647
|
+
const rel = path6.relative(this.#outdir, absOutPath).split(path6.sep).join("/");
|
|
1513
1648
|
return `${this.#servePrefix}/${rel}`;
|
|
1514
1649
|
}
|
|
1515
1650
|
#absFromOutdir(p) {
|
|
1516
|
-
return
|
|
1651
|
+
return path6.isAbsolute(p) ? p : path6.resolve(this.#outdir, p);
|
|
1517
1652
|
}
|
|
1518
1653
|
#absFromEntryPoint(p) {
|
|
1519
|
-
if (
|
|
1520
|
-
return
|
|
1521
|
-
const candidates = [
|
|
1654
|
+
if (path6.isAbsolute(p))
|
|
1655
|
+
return path6.resolve(p);
|
|
1656
|
+
const candidates = [path6.resolve(process.cwd(), p), path6.resolve(this.#app.cwdPath, p)];
|
|
1522
1657
|
return candidates.find((candidate) => fs4.existsSync(candidate)) ?? candidates[0];
|
|
1523
1658
|
}
|
|
1524
1659
|
#collectChunkUrls(absOutPath, visited = new Set) {
|
|
@@ -1699,13 +1834,13 @@ class RouteClientBuilder {
|
|
|
1699
1834
|
ssrModuleMap[row.id][row.name] = { id: ssrOutput, chunks: [ssrOutput, ssrOutput], name: row.name, async: true };
|
|
1700
1835
|
}
|
|
1701
1836
|
for (const entry of bootstrapEntries.buildEntries) {
|
|
1702
|
-
const buildEntry =
|
|
1703
|
-
const originalEntry =
|
|
1837
|
+
const buildEntry = path7.resolve(entry);
|
|
1838
|
+
const originalEntry = path7.resolve(bootstrapEntries.originalByBuildEntry.get(buildEntry) ?? buildEntry);
|
|
1704
1839
|
if (!acceptedEntries.has(originalEntry))
|
|
1705
1840
|
continue;
|
|
1706
1841
|
const deps = new Set([originalEntry]);
|
|
1707
1842
|
for (const dep of referenceBundle.entryDepsByAbsPath.get(buildEntry) ?? [])
|
|
1708
|
-
deps.add(
|
|
1843
|
+
deps.add(path7.resolve(dep));
|
|
1709
1844
|
const sortedDeps = [...deps].sort();
|
|
1710
1845
|
clientDepsByEntry[originalEntry] = sortedDeps;
|
|
1711
1846
|
if (routeEntries.has(originalEntry))
|
|
@@ -1772,25 +1907,25 @@ class RouteClientBuilder {
|
|
|
1772
1907
|
}).bundle();
|
|
1773
1908
|
}
|
|
1774
1909
|
async#createBootstrapEntries(entries) {
|
|
1775
|
-
if (!await Bun.file(
|
|
1910
|
+
if (!await Bun.file(path7.join(this.#app.cwdPath, "lib", "st.ts")).exists()) {
|
|
1776
1911
|
return { buildEntries: entries, originalByBuildEntry: new Map };
|
|
1777
1912
|
}
|
|
1778
|
-
const outdir =
|
|
1913
|
+
const outdir = path7.join(this.#app.cwdPath, ".akan", "generated", "client-entry-bootstrap");
|
|
1779
1914
|
await mkdir2(outdir, { recursive: true });
|
|
1780
1915
|
const originalByBuildEntry = new Map;
|
|
1781
1916
|
const buildEntries = await Promise.all(entries.map(async (entry) => {
|
|
1782
|
-
const absEntry =
|
|
1917
|
+
const absEntry = path7.resolve(entry);
|
|
1783
1918
|
const hash = Bun.hash(`${this.#app.name}
|
|
1784
1919
|
${absEntry}`).toString(36);
|
|
1785
|
-
const base =
|
|
1786
|
-
const wrapperEntry =
|
|
1920
|
+
const base = path7.basename(absEntry).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
1921
|
+
const wrapperEntry = path7.join(outdir, `${base}-${hash}.tsx`);
|
|
1787
1922
|
const exportNames = await this.#scanExportNames(absEntry);
|
|
1788
1923
|
await Bun.write(wrapperEntry, RouteClientBuilder.createStoreBootstrapEntrySource({
|
|
1789
1924
|
appName: this.#app.name,
|
|
1790
1925
|
originalEntry: absEntry,
|
|
1791
1926
|
exportNames
|
|
1792
1927
|
}));
|
|
1793
|
-
originalByBuildEntry.set(
|
|
1928
|
+
originalByBuildEntry.set(path7.resolve(wrapperEntry), absEntry);
|
|
1794
1929
|
return wrapperEntry;
|
|
1795
1930
|
}));
|
|
1796
1931
|
return { buildEntries, originalByBuildEntry };
|
|
@@ -1864,11 +1999,11 @@ ${declared.map(({ name }) => `export default ${name};`).join(`
|
|
|
1864
1999
|
try {
|
|
1865
2000
|
return Bun.resolveSync("akanjs/server", import.meta.dir);
|
|
1866
2001
|
} catch {
|
|
1867
|
-
return
|
|
2002
|
+
return path7.resolve(import.meta.dir, "../../../server/index.ts");
|
|
1868
2003
|
}
|
|
1869
2004
|
}
|
|
1870
2005
|
static createStoreBootstrapEntrySource(args) {
|
|
1871
|
-
const originalEntry = JSON.stringify(
|
|
2006
|
+
const originalEntry = JSON.stringify(path7.resolve(args.originalEntry));
|
|
1872
2007
|
const namedExports = args.exportNames.filter((name) => name !== "default");
|
|
1873
2008
|
const lines = [
|
|
1874
2009
|
...StoreBootstrap.importLines(args.appName),
|
|
@@ -1909,6 +2044,8 @@ class CsrDevModuleCompiler {
|
|
|
1909
2044
|
#outDir;
|
|
1910
2045
|
#routePrefix;
|
|
1911
2046
|
#assets = new Set;
|
|
2047
|
+
#barrels = null;
|
|
2048
|
+
#narrowed = new Map;
|
|
1912
2049
|
constructor({ app, paths, resolver, context, outDir, routePrefix }) {
|
|
1913
2050
|
this.#app = app;
|
|
1914
2051
|
this.#paths = paths;
|
|
@@ -1952,7 +2089,13 @@ class CsrDevModuleCompiler {
|
|
|
1952
2089
|
const { fallbacks } = this.#resolver;
|
|
1953
2090
|
if (fallbacks.size > 0)
|
|
1954
2091
|
this.#app.verbose(`[csr-dev] ${fallbacks.size} import(s) outside the browser build's graph resolved with Bun's runtime resolver: ${[...fallbacks].slice(0, 5).join(", ")}${fallbacks.size > 5 ? ", ..." : ""}`);
|
|
1955
|
-
|
|
2092
|
+
const modules = [...compiled.values()];
|
|
2093
|
+
return { modules, refusedVendors: [], unresolved: [], barrels: await this.#barrelStamps(modules) };
|
|
2094
|
+
}
|
|
2095
|
+
async#barrelStamps(modules) {
|
|
2096
|
+
const barrels = new Set(modules.flatMap((module) => Object.keys(module.narrowed ?? {})));
|
|
2097
|
+
const barrelImports = barrels.size > 0 ? await this.#barrelImports() : null;
|
|
2098
|
+
return barrelImports ? await barrelImports.stamps(barrels, (file) => this.#paths.idOf(file)) : {};
|
|
1956
2099
|
}
|
|
1957
2100
|
async#compileRound(files) {
|
|
1958
2101
|
const appFiles = files.filter((file) => !CsrDevPaths.isVendorFile(file));
|
|
@@ -2004,7 +2147,7 @@ class CsrDevModuleCompiler {
|
|
|
2004
2147
|
const tangled = [];
|
|
2005
2148
|
for (const artifact of result.outputs) {
|
|
2006
2149
|
if (artifact.kind === "asset") {
|
|
2007
|
-
const assetPath =
|
|
2150
|
+
const assetPath = path8.join(this.#outDir, artifact.path);
|
|
2008
2151
|
await Bun.write(assetPath, artifact);
|
|
2009
2152
|
this.#assets.add(assetPath);
|
|
2010
2153
|
continue;
|
|
@@ -2014,8 +2157,8 @@ class CsrDevModuleCompiler {
|
|
|
2014
2157
|
const meta = outputs[artifact.path];
|
|
2015
2158
|
if (!meta?.entryPoint)
|
|
2016
2159
|
throw new Error(`[csr-dev] no entry point recorded for ${artifact.path}`);
|
|
2017
|
-
const file = CsrDevPaths.realpath(
|
|
2018
|
-
const inputs = Object.keys(meta.inputs).map((input) => CsrDevPaths.realpath(
|
|
2160
|
+
const file = CsrDevPaths.realpath(path8.resolve(meta.entryPoint));
|
|
2161
|
+
const inputs = Object.keys(meta.inputs).map((input) => CsrDevPaths.realpath(path8.resolve(input)));
|
|
2019
2162
|
if (inputs.some((input) => input !== file && this.#resolver.isRegistryModule(input))) {
|
|
2020
2163
|
tangled.push(file);
|
|
2021
2164
|
continue;
|
|
@@ -2031,6 +2174,7 @@ class CsrDevModuleCompiler {
|
|
|
2031
2174
|
continue;
|
|
2032
2175
|
}
|
|
2033
2176
|
const sourceMap = sourceMaps.get(`${artifact.path}.map`);
|
|
2177
|
+
const narrowed = this.#narrowed.get(file);
|
|
2034
2178
|
modules.push({
|
|
2035
2179
|
id,
|
|
2036
2180
|
file,
|
|
@@ -2039,7 +2183,8 @@ class CsrDevModuleCompiler {
|
|
|
2039
2183
|
sourceMap: sourceMap ? this.#rebaseSourceMap(await sourceMap.text()) : undefined,
|
|
2040
2184
|
deps: this.#emittedDeps(code),
|
|
2041
2185
|
mtimeMs: mtimes.get(file) ?? CsrDevPaths.mtimeOf(file),
|
|
2042
|
-
hash: hashes.get(file) ?? ""
|
|
2186
|
+
hash: hashes.get(file) ?? "",
|
|
2187
|
+
...narrowed && Object.keys(narrowed).length > 0 ? { narrowed } : {}
|
|
2043
2188
|
});
|
|
2044
2189
|
}
|
|
2045
2190
|
return { modules, misses, tangled };
|
|
@@ -2048,7 +2193,7 @@ class CsrDevModuleCompiler {
|
|
|
2048
2193
|
const reasons = new Map;
|
|
2049
2194
|
for (const message of error.errors) {
|
|
2050
2195
|
const file = message.position?.file;
|
|
2051
|
-
if (typeof file !== "string" || !
|
|
2196
|
+
if (typeof file !== "string" || !path8.isAbsolute(file))
|
|
2052
2197
|
continue;
|
|
2053
2198
|
const real = CsrDevPaths.realpath(file);
|
|
2054
2199
|
const at = message.position?.line ? `:${message.position.line}` : "";
|
|
@@ -2120,11 +2265,17 @@ class CsrDevModuleCompiler {
|
|
|
2120
2265
|
});
|
|
2121
2266
|
}
|
|
2122
2267
|
if (!vendor)
|
|
2123
|
-
build.onLoad({ filter: /\.tsx$/ }, async (args) => {
|
|
2268
|
+
build.onLoad({ filter: /\.(?:tsx?|jsx?)$/ }, async (args) => {
|
|
2124
2269
|
if (CsrDevPaths.isVendorFile(args.path))
|
|
2125
2270
|
return;
|
|
2126
|
-
const
|
|
2127
|
-
|
|
2271
|
+
const source = await Bun.file(args.path).text();
|
|
2272
|
+
const rewrite = await (await this.#barrelImports())?.rewrite(source, args.path);
|
|
2273
|
+
if (rewrite)
|
|
2274
|
+
this.#narrowed.set(CsrDevPaths.realpath(args.path), rewrite.narrowed);
|
|
2275
|
+
const narrowed = rewrite?.contents ?? source;
|
|
2276
|
+
const normalized = args.path.endsWith(".tsx") ? RouteClientBuilder.normalizeNamedDefaultFunctionForFastRefresh(narrowed, { path: args.path }) : null;
|
|
2277
|
+
const contents = normalized ?? narrowed;
|
|
2278
|
+
return contents === source ? undefined : { contents, loader: loaderFor(args.path) };
|
|
2128
2279
|
});
|
|
2129
2280
|
build.onResolve({ filter: /.*/ }, (args) => {
|
|
2130
2281
|
if (args.kind === "entry-point-build" || !args.importer)
|
|
@@ -2145,9 +2296,13 @@ class CsrDevModuleCompiler {
|
|
|
2145
2296
|
}
|
|
2146
2297
|
};
|
|
2147
2298
|
}
|
|
2299
|
+
#barrelImports() {
|
|
2300
|
+
this.#barrels ??= DevBarrelImports.create(this.#app, this.#context.barrelImports ?? []);
|
|
2301
|
+
return this.#barrels;
|
|
2302
|
+
}
|
|
2148
2303
|
#rebaseSourceMap(text) {
|
|
2149
2304
|
const map = JSON.parse(text);
|
|
2150
|
-
const files = map.sources.map((source) =>
|
|
2305
|
+
const files = map.sources.map((source) => path8.resolve(source));
|
|
2151
2306
|
map.sources = files.map((file) => `/${this.#paths.idOf(file)}`);
|
|
2152
2307
|
map.sourcesContent = files.map((file, index) => CsrDevPaths.isVendorFile(file) ? null : map.sourcesContent?.[index] ?? null);
|
|
2153
2308
|
return JSON.stringify(map);
|
|
@@ -2212,7 +2367,7 @@ ${preamble}return { ${names.join(", ")} };
|
|
|
2212
2367
|
|
|
2213
2368
|
// pkgs/@akanjs/devkit/frontendBuild/csrDevPatcher.ts
|
|
2214
2369
|
import fs5 from "fs";
|
|
2215
|
-
import
|
|
2370
|
+
import path9 from "path";
|
|
2216
2371
|
import { appGenerationOf as appGenerationOf2, CSR_DEV_MANIFEST_FILE as CSR_DEV_MANIFEST_FILE2 } from "akanjs/server/hmr/csrDevManifest";
|
|
2217
2372
|
class CsrDevPatcher {
|
|
2218
2373
|
#bundler;
|
|
@@ -2247,7 +2402,7 @@ class CsrDevPatcher {
|
|
|
2247
2402
|
return this.#handBack("the dev bundle config changed", generation, context);
|
|
2248
2403
|
const metadataFile = changedFiles.find((file) => this.#bundler.isMetadataFile(file));
|
|
2249
2404
|
if (metadataFile)
|
|
2250
|
-
return this.#handBack(`${
|
|
2405
|
+
return this.#handBack(`${path9.basename(metadataFile)} changed`, generation, context);
|
|
2251
2406
|
if (!resident && state.graph.metadata !== await this.#bundler.metadataFingerprint())
|
|
2252
2407
|
return this.#handBack("signal or dictionary metadata changed since the registry was built", generation, context);
|
|
2253
2408
|
this.#state = this.#resident ? state : null;
|
|
@@ -2269,6 +2424,7 @@ class CsrDevPatcher {
|
|
|
2269
2424
|
const present = CsrDevPatcher.#presence(changedFiles);
|
|
2270
2425
|
const forgotten = this.#forgetDeletedModules(state, present);
|
|
2271
2426
|
const changed = onlyRoots ? new Set : await this.#changedModules(graph, changedFiles, present);
|
|
2427
|
+
const restamped = onlyRoots ? null : await this.#renarrowed(context, graph, changedFiles, changed);
|
|
2272
2428
|
for (const id of this.#withoutFactory(state, present))
|
|
2273
2429
|
changed.add(id);
|
|
2274
2430
|
for (const file of entries.changed)
|
|
@@ -2282,6 +2438,8 @@ class CsrDevPatcher {
|
|
|
2282
2438
|
const carried = onlyRoots ? [] : await this.#carriedRoots(graph, changed, present);
|
|
2283
2439
|
const routesMoved = this.#bundler.reloadsOnEntryChange && (entries.changed.length > 0 || JSON.stringify(entryIds) !== JSON.stringify(graph.entries));
|
|
2284
2440
|
if (changed.size === 0) {
|
|
2441
|
+
if (restamped)
|
|
2442
|
+
graph.barrels = { ...graph.barrels, ...restamped };
|
|
2285
2443
|
if (carried.length === 0)
|
|
2286
2444
|
return { kind: "unchanged" };
|
|
2287
2445
|
return await this.#retryCarried(context, state, carried, { announce, allowWholeAppBuilds });
|
|
@@ -2336,22 +2494,17 @@ class CsrDevPatcher {
|
|
|
2336
2494
|
forgotten.push(id);
|
|
2337
2495
|
}
|
|
2338
2496
|
graph.pending = graph.pending.filter((id) => !orphans.includes(id));
|
|
2339
|
-
this.#bundler.merge(graph, resolver, compiled);
|
|
2497
|
+
this.#bundler.merge(graph, resolver, compiled, { ...restamped, ...result.barrels });
|
|
2340
2498
|
if (!this.#resident)
|
|
2341
2499
|
delete graph.failed;
|
|
2342
2500
|
for (const module of compiled)
|
|
2343
2501
|
this.#delegated.delete(module.id);
|
|
2344
2502
|
graph.entries = entryIds;
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
continue;
|
|
2348
|
-
code.modules.set(module.id, module.factory);
|
|
2349
|
-
if (module.helpers)
|
|
2350
|
-
code.helpers.set(module.helpers.hash, module.helpers.definition);
|
|
2351
|
-
}
|
|
2503
|
+
if (code)
|
|
2504
|
+
CsrDevPatcher.#remember(code, compiled);
|
|
2352
2505
|
const changedIds = compiled.filter((module) => !module.vendor).map((module) => module.id);
|
|
2353
2506
|
const constantId = changedIds.find((id) => id.endsWith(".constant.ts"));
|
|
2354
|
-
const reason = vendorJoined ? "an npm module joined the graph" : routesMoved ? "the route table changed" : constantId ? `${
|
|
2507
|
+
const reason = vendorJoined ? "an npm module joined the graph" : routesMoved ? "the route table changed" : constantId ? `${path9.basename(constantId)} changed` : undefined;
|
|
2355
2508
|
if (compiled.length === 0 && !reason) {
|
|
2356
2509
|
await writer.writeJson("graph.json", graph);
|
|
2357
2510
|
await writer.forgetModules(forgotten);
|
|
@@ -2457,7 +2610,8 @@ class CsrDevPatcher {
|
|
|
2457
2610
|
return {
|
|
2458
2611
|
modules: [...result.modules, ...more.modules],
|
|
2459
2612
|
refusedVendors: [...result.refusedVendors, ...more.refusedVendors],
|
|
2460
|
-
unresolved: [...result.unresolved, ...more.unresolved]
|
|
2613
|
+
unresolved: [...result.unresolved, ...more.unresolved],
|
|
2614
|
+
barrels: { ...result.barrels, ...more.barrels }
|
|
2461
2615
|
};
|
|
2462
2616
|
}
|
|
2463
2617
|
static #implicatedFiles(error) {
|
|
@@ -2465,9 +2619,9 @@ class CsrDevPatcher {
|
|
|
2465
2619
|
const messages = error instanceof AggregateError ? error.errors : [];
|
|
2466
2620
|
const named = messages.flatMap((message) => {
|
|
2467
2621
|
const text = String(message.message ?? "");
|
|
2468
|
-
const bases = [process.cwd(), ...failing.map((file) =>
|
|
2622
|
+
const bases = [process.cwd(), ...failing.map((file) => path9.dirname(file))];
|
|
2469
2623
|
return [...text.matchAll(/"([^"\n]+)"/g)].flatMap(([, quoted = ""]) => {
|
|
2470
|
-
const found = bases.map((base) =>
|
|
2624
|
+
const found = bases.map((base) => path9.resolve(base, quoted)).find((file) => CsrDevPaths.isScript(file) && fs5.existsSync(file));
|
|
2471
2625
|
return found ? [CsrDevPaths.realpath(found)] : [];
|
|
2472
2626
|
});
|
|
2473
2627
|
});
|
|
@@ -2475,7 +2629,7 @@ class CsrDevPatcher {
|
|
|
2475
2629
|
}
|
|
2476
2630
|
static #failingFiles(error) {
|
|
2477
2631
|
const messages = error instanceof AggregateError ? error.errors : [];
|
|
2478
|
-
return messages.map((message) => message.position?.file).filter((file) => typeof file === "string" &&
|
|
2632
|
+
return messages.map((message) => message.position?.file).filter((file) => typeof file === "string" && path9.isAbsolute(file)).map((file) => CsrDevPaths.realpath(file));
|
|
2479
2633
|
}
|
|
2480
2634
|
async#carriedRoots(graph, changed, present) {
|
|
2481
2635
|
const { paths } = this.#bundler;
|
|
@@ -2572,19 +2726,48 @@ class CsrDevPatcher {
|
|
|
2572
2726
|
}
|
|
2573
2727
|
return changed;
|
|
2574
2728
|
}
|
|
2729
|
+
async#renarrowed(context, graph, changedFiles, changed) {
|
|
2730
|
+
const { paths } = this.#bundler;
|
|
2731
|
+
const saved = new Set(changedFiles.map((file) => paths.idOf(file)));
|
|
2732
|
+
const stale = Object.entries(graph.barrels ?? {}).filter(([, { read }]) => Object.entries(read).some(([id, mtimeMs]) => saved.has(id) || CsrDevPaths.mtimeOf(paths.fileOf(id)) !== mtimeMs)).map(([barrel]) => barrel);
|
|
2733
|
+
const barrelImports = stale.length > 0 ? await this.#bundler.barrelImports(context) : null;
|
|
2734
|
+
if (!barrelImports)
|
|
2735
|
+
return {};
|
|
2736
|
+
const barrels = await barrelImports.stamps(stale, (file) => paths.idOf(file));
|
|
2737
|
+
const moved = stale.filter((barrel) => barrels[barrel]?.digest !== graph.barrels?.[barrel]?.digest);
|
|
2738
|
+
for (const [id, module] of Object.entries(graph.modules)) {
|
|
2739
|
+
for (const barrel of moved) {
|
|
2740
|
+
const narrowed = module.narrowed?.[barrel];
|
|
2741
|
+
if (!narrowed || await barrelImports.fingerprint(barrel, narrowed.names) === narrowed.hash)
|
|
2742
|
+
continue;
|
|
2743
|
+
changed.add(id);
|
|
2744
|
+
break;
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
return barrels;
|
|
2748
|
+
}
|
|
2749
|
+
static #remember(code, compiled) {
|
|
2750
|
+
for (const module of compiled) {
|
|
2751
|
+
if (module.vendor)
|
|
2752
|
+
continue;
|
|
2753
|
+
code.modules.set(module.id, module.factory);
|
|
2754
|
+
if (module.helpers)
|
|
2755
|
+
code.helpers.set(module.helpers.hash, module.helpers.definition);
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2575
2758
|
#shadowedImporters(graph, changedFiles) {
|
|
2576
2759
|
const { paths } = this.#bundler;
|
|
2577
2760
|
const bases = new Set(changedFiles.map((file) => CsrDevPaths.realpath(file)).filter((file) => !graph.modules[paths.idOf(file)] && CsrDevPaths.isScript(file) && fs5.existsSync(file)).flatMap((file) => {
|
|
2578
|
-
const stem = file.slice(0, file.length -
|
|
2579
|
-
return
|
|
2761
|
+
const stem = file.slice(0, file.length - path9.extname(file).length);
|
|
2762
|
+
return path9.basename(stem) === "index" ? [stem, path9.dirname(stem)] : [stem];
|
|
2580
2763
|
}));
|
|
2581
2764
|
if (bases.size === 0)
|
|
2582
2765
|
return [];
|
|
2583
2766
|
return Object.entries(graph.resolution).filter(([importer, bySpecifier]) => {
|
|
2584
2767
|
if (!graph.modules[importer] || graph.modules[importer]?.vendor)
|
|
2585
2768
|
return false;
|
|
2586
|
-
const dir =
|
|
2587
|
-
return Object.keys(bySpecifier).some((specifier) => specifier.startsWith(".") && bases.has(
|
|
2769
|
+
const dir = path9.dirname(paths.fileOf(importer));
|
|
2770
|
+
return Object.keys(bySpecifier).some((specifier) => specifier.startsWith(".") && bases.has(path9.resolve(dir, specifier)));
|
|
2588
2771
|
}).map(([importer]) => importer);
|
|
2589
2772
|
}
|
|
2590
2773
|
#forgetDeletedModules({ graph, code }, present) {
|
|
@@ -2600,7 +2783,7 @@ class CsrDevPatcher {
|
|
|
2600
2783
|
|
|
2601
2784
|
// pkgs/@akanjs/devkit/frontendBuild/registryMetadataFingerprint.ts
|
|
2602
2785
|
import fs6 from "fs";
|
|
2603
|
-
import
|
|
2786
|
+
import path10 from "path";
|
|
2604
2787
|
|
|
2605
2788
|
class RegistryMetadataFingerprint {
|
|
2606
2789
|
static #sources = new Bun.Glob("**/*.{signal,dictionary}.ts");
|
|
@@ -2608,12 +2791,12 @@ class RegistryMetadataFingerprint {
|
|
|
2608
2791
|
static async of(roots, isMetadataFile) {
|
|
2609
2792
|
const stamps = [];
|
|
2610
2793
|
for (const root of new Set(roots)) {
|
|
2611
|
-
const libDir =
|
|
2794
|
+
const libDir = path10.join(root, "lib");
|
|
2612
2795
|
if (!fs6.existsSync(libDir))
|
|
2613
2796
|
continue;
|
|
2614
|
-
const files = RegistryMetadataFingerprint.#libFiles.map((name) =>
|
|
2797
|
+
const files = RegistryMetadataFingerprint.#libFiles.map((name) => path10.join(libDir, name));
|
|
2615
2798
|
for await (const relative of RegistryMetadataFingerprint.#sources.scan({ cwd: libDir, onlyFiles: true }))
|
|
2616
|
-
files.push(
|
|
2799
|
+
files.push(path10.join(libDir, relative));
|
|
2617
2800
|
for (const file of files) {
|
|
2618
2801
|
if (!isMetadataFile(file))
|
|
2619
2802
|
continue;
|
|
@@ -2639,8 +2822,8 @@ class DevRegistryBundler {
|
|
|
2639
2822
|
this.app = app;
|
|
2640
2823
|
this.routePrefix = routePrefix;
|
|
2641
2824
|
this.paths = new CsrDevPaths(app.workspace.workspaceRoot);
|
|
2642
|
-
this.outDir =
|
|
2643
|
-
this.entryDir =
|
|
2825
|
+
this.outDir = path11.join(app.cwdPath, ".akan/artifact", dirName);
|
|
2826
|
+
this.entryDir = path11.join(app.cwdPath, ".akan/generated", dirName);
|
|
2644
2827
|
this.writer = new CsrDevArtifactWriter(this.outDir, { routePrefix, library });
|
|
2645
2828
|
}
|
|
2646
2829
|
async update(changedFiles = [], options = {}) {
|
|
@@ -2678,10 +2861,10 @@ class DevRegistryBundler {
|
|
|
2678
2861
|
return isAkanRuntimeMetadataFile(file);
|
|
2679
2862
|
}
|
|
2680
2863
|
async metadataFingerprint() {
|
|
2681
|
-
const libsContainer =
|
|
2864
|
+
const libsContainer = path11.resolve(this.app.workspace.workspaceRoot, "libs");
|
|
2682
2865
|
const roots = await new WatchRootResolver(this.app).resolve();
|
|
2683
|
-
const libRoots = roots.includes(libsContainer) ? fs7.readdirSync(libsContainer).map((name) =>
|
|
2684
|
-
return await RegistryMetadataFingerprint.of([
|
|
2866
|
+
const libRoots = roots.includes(libsContainer) ? fs7.readdirSync(libsContainer).map((name) => path11.join(libsContainer, name)) : roots.filter((root) => path11.dirname(root) === libsContainer);
|
|
2867
|
+
return await RegistryMetadataFingerprint.of([path11.resolve(this.app.cwdPath), ...libRoots], (file) => this.isMetadataFile(file));
|
|
2685
2868
|
}
|
|
2686
2869
|
async fullBuild(context, generation, reason) {
|
|
2687
2870
|
const metadata = await this.metadataFingerprint();
|
|
@@ -2690,7 +2873,7 @@ class DevRegistryBundler {
|
|
|
2690
2873
|
const resolver = new CsrDevResolver({ paths: this.paths, context, entryFiles: roots });
|
|
2691
2874
|
await resolver.prepass();
|
|
2692
2875
|
const compiler = this.compiler(context, resolver);
|
|
2693
|
-
const { modules: compiled } = await compiler.compile([...roots, ...context.refreshFile ? [context.refreshFile] : []], new Set);
|
|
2876
|
+
const { modules: compiled, barrels } = await compiler.compile([...roots, ...context.refreshFile ? [context.refreshFile] : []], new Set);
|
|
2694
2877
|
const graph = {
|
|
2695
2878
|
version: 1,
|
|
2696
2879
|
configKey: context.configKey,
|
|
@@ -2701,7 +2884,7 @@ class DevRegistryBundler {
|
|
|
2701
2884
|
pending: [],
|
|
2702
2885
|
metadata
|
|
2703
2886
|
};
|
|
2704
|
-
this.merge(graph, resolver, compiled);
|
|
2887
|
+
this.merge(graph, resolver, compiled, barrels);
|
|
2705
2888
|
await this.writer.markBuilding();
|
|
2706
2889
|
await this.writer.writeModules(compiled);
|
|
2707
2890
|
const vendorFile = await this.writer.writeVendor(graph);
|
|
@@ -2722,15 +2905,21 @@ class DevRegistryBundler {
|
|
|
2722
2905
|
routePrefix: this.routePrefix
|
|
2723
2906
|
});
|
|
2724
2907
|
}
|
|
2725
|
-
|
|
2908
|
+
async barrelImports(context) {
|
|
2909
|
+
return await DevBarrelImports.create(this.app, context.barrelImports ?? []);
|
|
2910
|
+
}
|
|
2911
|
+
merge(graph, resolver, compiled, barrels = {}) {
|
|
2726
2912
|
for (const module of compiled)
|
|
2727
2913
|
graph.modules[module.id] = {
|
|
2728
2914
|
vendor: module.vendor,
|
|
2729
2915
|
mtimeMs: module.mtimeMs,
|
|
2730
2916
|
hash: module.hash,
|
|
2731
2917
|
deps: module.deps.map((dep) => CsrDevPaths.isStub(dep) ? dep : this.paths.idOf(dep)),
|
|
2732
|
-
...module.helpers ? { helpers: module.helpers.hash } : {}
|
|
2918
|
+
...module.helpers ? { helpers: module.helpers.hash } : {},
|
|
2919
|
+
...module.narrowed ? { narrowed: module.narrowed } : {}
|
|
2733
2920
|
};
|
|
2921
|
+
const narrowing = new Set(Object.values(graph.modules).flatMap((module) => Object.keys(module.narrowed ?? {})));
|
|
2922
|
+
graph.barrels = Object.fromEntries(Object.entries({ ...graph.barrels, ...barrels }).filter(([barrel]) => narrowing.has(barrel)));
|
|
2734
2923
|
const compiledIds = new Set(compiled.map((module) => module.id));
|
|
2735
2924
|
graph.pending = graph.pending.filter((id) => !compiledIds.has(id));
|
|
2736
2925
|
graph.resolution = resolver.serialize();
|
|
@@ -2743,7 +2932,7 @@ class DevRegistryBundler {
|
|
|
2743
2932
|
|
|
2744
2933
|
// pkgs/@akanjs/devkit/frontendBuild/csrDevBundler.ts
|
|
2745
2934
|
class CsrDevBundler extends DevRegistryBundler {
|
|
2746
|
-
static #formatVersion =
|
|
2935
|
+
static #formatVersion = 6;
|
|
2747
2936
|
reloadsOnEntryChange = true;
|
|
2748
2937
|
#asyncDefaults = new Map;
|
|
2749
2938
|
constructor(app) {
|
|
@@ -2758,7 +2947,15 @@ class CsrDevBundler extends DevRegistryBundler {
|
|
|
2758
2947
|
const htmlBasePaths = basePaths.length > 0 ? basePaths : [""];
|
|
2759
2948
|
const define = bundleDefine(this.app, "start", "csr");
|
|
2760
2949
|
const optimizeImports = [...akanConfig.optimizeImports];
|
|
2761
|
-
const
|
|
2950
|
+
const barrelImports = workspaceBarrels(akanConfig.barrelImports);
|
|
2951
|
+
const configKey = Bun.hash(JSON.stringify([
|
|
2952
|
+
CsrDevBundler.#formatVersion,
|
|
2953
|
+
Bun.version,
|
|
2954
|
+
define,
|
|
2955
|
+
optimizeImports,
|
|
2956
|
+
htmlBasePaths,
|
|
2957
|
+
barrelImports
|
|
2958
|
+
])).toString(36);
|
|
2762
2959
|
return {
|
|
2763
2960
|
pageEntries,
|
|
2764
2961
|
basePaths,
|
|
@@ -2766,7 +2963,8 @@ class CsrDevBundler extends DevRegistryBundler {
|
|
|
2766
2963
|
define,
|
|
2767
2964
|
optimizeImports,
|
|
2768
2965
|
configKey,
|
|
2769
|
-
refreshFile: this.#resolveRefreshRuntime()
|
|
2966
|
+
refreshFile: this.#resolveRefreshRuntime(),
|
|
2967
|
+
barrelImports
|
|
2770
2968
|
};
|
|
2771
2969
|
}
|
|
2772
2970
|
async writeEntries(context) {
|
|
@@ -2774,7 +2972,7 @@ class CsrDevBundler extends DevRegistryBundler {
|
|
|
2774
2972
|
const files = {};
|
|
2775
2973
|
const changed = [];
|
|
2776
2974
|
for (const basePath of context.htmlBasePaths) {
|
|
2777
|
-
const file =
|
|
2975
|
+
const file = path12.join(this.entryDir, CsrEntryFiles.entryFilename(basePath));
|
|
2778
2976
|
const entryPages = CsrEntryFiles.pageEntriesForBasePath(context.pageEntries, basePath, context.basePaths);
|
|
2779
2977
|
const generator = new PagesEntrySourceGenerator(entryPages, {
|
|
2780
2978
|
isAsyncDefault: (moduleAbsPath) => this.#isAsyncDefault(moduleAbsPath)
|
|
@@ -2813,7 +3011,7 @@ ${hot}`;
|
|
|
2813
3011
|
}
|
|
2814
3012
|
#resolveRefreshRuntime() {
|
|
2815
3013
|
const akanWebkit = CsrDevPaths.tryResolve("akanjs/webkit", this.app.cwdPath);
|
|
2816
|
-
const bases = [this.app.cwdPath, this.paths.root, ...akanWebkit ? [
|
|
3014
|
+
const bases = [this.app.cwdPath, this.paths.root, ...akanWebkit ? [path12.dirname(path12.dirname(akanWebkit))] : []];
|
|
2817
3015
|
for (const base of bases) {
|
|
2818
3016
|
const resolved = CsrDevPaths.tryResolve("react-refresh/runtime", base);
|
|
2819
3017
|
if (resolved)
|
|
@@ -2824,7 +3022,7 @@ ${hot}`;
|
|
|
2824
3022
|
}
|
|
2825
3023
|
|
|
2826
3024
|
// pkgs/@akanjs/devkit/frontendBuild/devChangePlanner.ts
|
|
2827
|
-
import
|
|
3025
|
+
import path13 from "path";
|
|
2828
3026
|
var CONFIG_BASENAMES = new Set(["akan.config.ts", "bunfig.toml", "tsconfig.json", "package.json"]);
|
|
2829
3027
|
var BARREL_FACETS = new Set(["common", "srvkit", "ui", "webkit", "plugin"]);
|
|
2830
3028
|
var CLIENT_SUFFIXES = [".Template.tsx", ".Unit.tsx", ".Util.tsx", ".View.tsx", ".Zone.tsx", ".store.ts"];
|
|
@@ -2835,11 +3033,11 @@ var RUNTIME_METADATA_BASENAMES = new Set(["dict.ts", "sig.ts", "useClient.ts", "
|
|
|
2835
3033
|
class DevChangePlanner {
|
|
2836
3034
|
#workspaceRoot;
|
|
2837
3035
|
constructor({ workspaceRoot }) {
|
|
2838
|
-
this.#workspaceRoot =
|
|
3036
|
+
this.#workspaceRoot = path13.resolve(workspaceRoot);
|
|
2839
3037
|
}
|
|
2840
3038
|
plan({ generation, files, kinds, generatedFiles = [] }) {
|
|
2841
3039
|
const fileList = uniqueResolved([...files, ...generatedFiles]);
|
|
2842
|
-
const generatedSet = new Set(generatedFiles.map((file) =>
|
|
3040
|
+
const generatedSet = new Set(generatedFiles.map((file) => path13.resolve(file)));
|
|
2843
3041
|
const kindSet = new Set(kinds);
|
|
2844
3042
|
const roles = new Set;
|
|
2845
3043
|
const actions = new Set;
|
|
@@ -2856,13 +3054,13 @@ class DevChangePlanner {
|
|
|
2856
3054
|
}
|
|
2857
3055
|
for (const file of fileList) {
|
|
2858
3056
|
const reasons = new Set;
|
|
2859
|
-
const fileRoles = this.#rolesForFile(file, { isGenerated: generatedSet.has(
|
|
3057
|
+
const fileRoles = this.#rolesForFile(file, { isGenerated: generatedSet.has(path13.resolve(file)), reasons });
|
|
2860
3058
|
for (const role of fileRoles)
|
|
2861
3059
|
roles.add(role);
|
|
2862
3060
|
if (reasons.has("runtime-metadata"))
|
|
2863
3061
|
actions.add("restart-builder");
|
|
2864
3062
|
if (reasons.size > 0)
|
|
2865
|
-
reasonByFile[
|
|
3063
|
+
reasonByFile[path13.resolve(file)] = [...reasons].sort();
|
|
2866
3064
|
}
|
|
2867
3065
|
if (roles.has("barrel"))
|
|
2868
3066
|
actions.add("sync-generated");
|
|
@@ -2883,12 +3081,12 @@ class DevChangePlanner {
|
|
|
2883
3081
|
}
|
|
2884
3082
|
#rolesForFile(file, { isGenerated, reasons }) {
|
|
2885
3083
|
const roles = new Set;
|
|
2886
|
-
const abs =
|
|
2887
|
-
const base =
|
|
2888
|
-
const ext =
|
|
3084
|
+
const abs = path13.resolve(file);
|
|
3085
|
+
const base = path13.basename(abs);
|
|
3086
|
+
const ext = path13.extname(abs).toLowerCase();
|
|
2889
3087
|
const isSource = SOURCE_EXTS.has(ext);
|
|
2890
|
-
const rel =
|
|
2891
|
-
const parts = rel.split(
|
|
3088
|
+
const rel = path13.relative(this.#workspaceRoot, abs);
|
|
3089
|
+
const parts = rel.split(path13.sep).filter(Boolean);
|
|
2892
3090
|
if (CONFIG_BASENAMES.has(base)) {
|
|
2893
3091
|
roles.add("config");
|
|
2894
3092
|
reasons.add("config-file");
|
|
@@ -2959,17 +3157,17 @@ class DevChangePlanner {
|
|
|
2959
3157
|
return true;
|
|
2960
3158
|
}
|
|
2961
3159
|
#isWorkspaceSource(rel) {
|
|
2962
|
-
if (!rel || rel.startsWith("..") ||
|
|
3160
|
+
if (!rel || rel.startsWith("..") || path13.isAbsolute(rel))
|
|
2963
3161
|
return false;
|
|
2964
|
-
const [scope] = rel.split(
|
|
3162
|
+
const [scope] = rel.split(path13.sep);
|
|
2965
3163
|
return scope === "apps" || scope === "libs" || scope === "pkgs";
|
|
2966
3164
|
}
|
|
2967
3165
|
}
|
|
2968
|
-
var uniqueResolved = (files) => [...new Set(files.map((file) =>
|
|
3166
|
+
var uniqueResolved = (files) => [...new Set(files.map((file) => path13.resolve(file)))].sort();
|
|
2969
3167
|
|
|
2970
3168
|
// pkgs/@akanjs/devkit/frontendBuild/devGeneratedIndexSync.ts
|
|
2971
3169
|
import { mkdir as mkdir4, readdir as readdir3, readFile as readFile2, rm as rm2, stat as stat2 } from "fs/promises";
|
|
2972
|
-
import
|
|
3170
|
+
import path14 from "path";
|
|
2973
3171
|
import { capitalize } from "akanjs/common";
|
|
2974
3172
|
var BARREL_FACETS2 = new Set(["common", "srvkit", "ui", "webkit", "plugin"]);
|
|
2975
3173
|
var FACET_SOURCE_FILE_RE = /\.(ts|tsx)$/;
|
|
@@ -2983,7 +3181,7 @@ var SCALAR_UI_TYPES = ["Template", "Unit"];
|
|
|
2983
3181
|
class DevGeneratedIndexSync {
|
|
2984
3182
|
#workspaceRoot;
|
|
2985
3183
|
constructor({ workspaceRoot }) {
|
|
2986
|
-
this.#workspaceRoot =
|
|
3184
|
+
this.#workspaceRoot = path14.resolve(workspaceRoot);
|
|
2987
3185
|
}
|
|
2988
3186
|
async syncForBatch(files) {
|
|
2989
3187
|
const indexPaths = new Set;
|
|
@@ -3012,11 +3210,11 @@ class DevGeneratedIndexSync {
|
|
|
3012
3210
|
return { changedFiles, errors };
|
|
3013
3211
|
}
|
|
3014
3212
|
#facetIndexFor(file) {
|
|
3015
|
-
const abs =
|
|
3016
|
-
const rel =
|
|
3017
|
-
if (rel.startsWith("..") ||
|
|
3213
|
+
const abs = path14.resolve(file);
|
|
3214
|
+
const rel = path14.relative(this.#workspaceRoot, abs);
|
|
3215
|
+
if (rel.startsWith("..") || path14.isAbsolute(rel))
|
|
3018
3216
|
return null;
|
|
3019
|
-
const parts = rel.split(
|
|
3217
|
+
const parts = rel.split(path14.sep).filter(Boolean);
|
|
3020
3218
|
if (parts.length < 4)
|
|
3021
3219
|
return null;
|
|
3022
3220
|
const [scope, project, facet, child] = parts;
|
|
@@ -3024,32 +3222,32 @@ class DevGeneratedIndexSync {
|
|
|
3024
3222
|
return null;
|
|
3025
3223
|
if (!child || child.startsWith(".") || child === "index.ts" || child === "index.tsx")
|
|
3026
3224
|
return null;
|
|
3027
|
-
return
|
|
3225
|
+
return path14.join(this.#workspaceRoot, scope, project, facet, "index.ts");
|
|
3028
3226
|
}
|
|
3029
3227
|
async#moduleIndexForDirectoryEvent(file) {
|
|
3030
|
-
const abs =
|
|
3031
|
-
const rel =
|
|
3032
|
-
if (rel.startsWith("..") ||
|
|
3228
|
+
const abs = path14.resolve(file);
|
|
3229
|
+
const rel = path14.relative(this.#workspaceRoot, abs);
|
|
3230
|
+
if (rel.startsWith("..") || path14.isAbsolute(rel))
|
|
3033
3231
|
return null;
|
|
3034
|
-
const parts = rel.split(
|
|
3232
|
+
const parts = rel.split(path14.sep).filter(Boolean);
|
|
3035
3233
|
if (parts.length !== 4 && parts.length !== 5)
|
|
3036
3234
|
return null;
|
|
3037
3235
|
const [scope, project, libSegment, moduleSegment, scalarSegment] = parts;
|
|
3038
3236
|
if (scope !== "apps" && scope !== "libs" || !project || libSegment !== "lib")
|
|
3039
3237
|
return null;
|
|
3040
3238
|
const isExistingDirectory = await stat2(abs).then((s) => s.isDirectory()).catch(() => false);
|
|
3041
|
-
const looksLikeDeletedDirectory = !
|
|
3239
|
+
const looksLikeDeletedDirectory = !path14.extname(abs);
|
|
3042
3240
|
if (!isExistingDirectory && !looksLikeDeletedDirectory)
|
|
3043
3241
|
return null;
|
|
3044
3242
|
if (moduleSegment === "__scalar" && scalarSegment) {
|
|
3045
|
-
return
|
|
3243
|
+
return path14.join(this.#workspaceRoot, scope, project, "lib", "__scalar", scalarSegment, "index.ts");
|
|
3046
3244
|
}
|
|
3047
3245
|
if (!moduleSegment || moduleSegment === "__scalar")
|
|
3048
3246
|
return null;
|
|
3049
|
-
return
|
|
3247
|
+
return path14.join(this.#workspaceRoot, scope, project, "lib", moduleSegment, "index.ts");
|
|
3050
3248
|
}
|
|
3051
3249
|
async#syncIndex(indexPath) {
|
|
3052
|
-
const dir =
|
|
3250
|
+
const dir = path14.dirname(indexPath);
|
|
3053
3251
|
const content = await this.#contentForIndex(indexPath);
|
|
3054
3252
|
if (content === null) {
|
|
3055
3253
|
if (!await exists(indexPath))
|
|
@@ -3065,14 +3263,14 @@ class DevGeneratedIndexSync {
|
|
|
3065
3263
|
return true;
|
|
3066
3264
|
}
|
|
3067
3265
|
async#contentForIndex(indexPath) {
|
|
3068
|
-
const parts =
|
|
3266
|
+
const parts = path14.relative(this.#workspaceRoot, indexPath).split(path14.sep).filter(Boolean);
|
|
3069
3267
|
const facet = parts.at(-2);
|
|
3070
3268
|
if (facet && BARREL_FACETS2.has(facet))
|
|
3071
|
-
return this.#facetContent(
|
|
3072
|
-
return this.#moduleContent(
|
|
3269
|
+
return this.#facetContent(path14.dirname(indexPath));
|
|
3270
|
+
return this.#moduleContent(path14.dirname(indexPath));
|
|
3073
3271
|
}
|
|
3074
3272
|
async#facetContent(dir) {
|
|
3075
|
-
const nameCasePattern =
|
|
3273
|
+
const nameCasePattern = path14.basename(dir) === "ui" ? FACET_PASCAL_CASE_RE : FACET_CAMEL_CASE_RE;
|
|
3076
3274
|
const entries = await readdir3(dir, { withFileTypes: true }).catch(() => null);
|
|
3077
3275
|
if (!entries)
|
|
3078
3276
|
return null;
|
|
@@ -3097,8 +3295,8 @@ class DevGeneratedIndexSync {
|
|
|
3097
3295
|
`;
|
|
3098
3296
|
}
|
|
3099
3297
|
async#moduleContent(dir) {
|
|
3100
|
-
const rel =
|
|
3101
|
-
const parts = rel.split(
|
|
3298
|
+
const rel = path14.relative(this.#workspaceRoot, dir);
|
|
3299
|
+
const parts = rel.split(path14.sep).filter(Boolean);
|
|
3102
3300
|
const moduleSegment = parts.at(-1);
|
|
3103
3301
|
if (!moduleSegment)
|
|
3104
3302
|
return null;
|
|
@@ -3110,7 +3308,7 @@ class DevGeneratedIndexSync {
|
|
|
3110
3308
|
const allowedTypes = isScalar ? SCALAR_UI_TYPES : moduleSegment.startsWith("_") ? SERVICE_UI_TYPES : MODULE_UI_TYPES;
|
|
3111
3309
|
const fileTypes = [];
|
|
3112
3310
|
for (const type of allowedTypes) {
|
|
3113
|
-
if (await exists(
|
|
3311
|
+
if (await exists(path14.join(dir, `${modelName}.${type}.tsx`)))
|
|
3114
3312
|
fileTypes.push(type);
|
|
3115
3313
|
}
|
|
3116
3314
|
if (fileTypes.length === 0)
|
|
@@ -3145,11 +3343,11 @@ var formatError2 = (err) => err instanceof Error ? err.message : String(err);
|
|
|
3145
3343
|
|
|
3146
3344
|
// pkgs/@akanjs/devkit/frontendBuild/ssrDevBundler.ts
|
|
3147
3345
|
import { mkdir as mkdir5 } from "fs/promises";
|
|
3148
|
-
import
|
|
3346
|
+
import path16 from "path";
|
|
3149
3347
|
import { SSR_DEV_DIRNAME, SSR_DEV_ROUTE_PREFIX } from "akanjs/server/hmr/csrDevManifest";
|
|
3150
3348
|
|
|
3151
3349
|
// pkgs/@akanjs/devkit/artifact/routeSeedIndex.ts
|
|
3152
|
-
import
|
|
3350
|
+
import path15 from "path";
|
|
3153
3351
|
import { assertUniqueRoutePatterns, compareRouteSpecificity, parseRouteModuleKey } from "akanjs/common";
|
|
3154
3352
|
import {
|
|
3155
3353
|
ROUTE_SEED_INDEX_JSON
|
|
@@ -3159,7 +3357,7 @@ function computeRouteSeedIndex(pageEntries) {
|
|
|
3159
3357
|
const pagesBySegments = [];
|
|
3160
3358
|
for (const { key, moduleAbsPath, seedAbsPaths } of pageEntries) {
|
|
3161
3359
|
const parsed = parseRouteModuleKey(key);
|
|
3162
|
-
const files = [
|
|
3360
|
+
const files = [path15.resolve(moduleAbsPath), ...(seedAbsPaths ?? []).map((seed) => path15.resolve(seed))];
|
|
3163
3361
|
if (parsed.kind === "layout" || parsed.kind === "overrides") {
|
|
3164
3362
|
layoutsByPrefix.getOrInsert(parsed.routeSegments.join("/"), []).push(...files);
|
|
3165
3363
|
} else if (parsed.kind === "page") {
|
|
@@ -3192,7 +3390,7 @@ function computeRouteSeedIndex(pageEntries) {
|
|
|
3192
3390
|
return { entries: seedEntries, globalLayoutFiles };
|
|
3193
3391
|
}
|
|
3194
3392
|
function serializeRouteSeedIndexForArtifact(index, artifactDir, options = {}) {
|
|
3195
|
-
const normalizedArtifactDir =
|
|
3393
|
+
const normalizedArtifactDir = path15.resolve(artifactDir);
|
|
3196
3394
|
if (options.production)
|
|
3197
3395
|
return { entries: index.entries.map((entry) => ({ routeId: entry.routeId })) };
|
|
3198
3396
|
return {
|
|
@@ -3204,20 +3402,20 @@ function serializeRouteSeedIndexForArtifact(index, artifactDir, options = {}) {
|
|
|
3204
3402
|
};
|
|
3205
3403
|
}
|
|
3206
3404
|
async function saveRouteSeedIndex(artifactDir, index, options = {}) {
|
|
3207
|
-
const absPath =
|
|
3405
|
+
const absPath = path15.join(path15.resolve(artifactDir), ROUTE_SEED_INDEX_JSON);
|
|
3208
3406
|
await Bun.write(absPath, `${JSON.stringify(serializeRouteSeedIndexForArtifact(index, artifactDir, options), null, 2)}
|
|
3209
3407
|
`);
|
|
3210
3408
|
return absPath;
|
|
3211
3409
|
}
|
|
3212
3410
|
function serializeArtifactPath(artifactPath, artifactDir) {
|
|
3213
|
-
if (!
|
|
3411
|
+
if (!path15.isAbsolute(artifactPath))
|
|
3214
3412
|
return artifactPath;
|
|
3215
|
-
return
|
|
3413
|
+
return path15.relative(artifactDir, artifactPath).split(path15.sep).join("/");
|
|
3216
3414
|
}
|
|
3217
3415
|
|
|
3218
3416
|
// pkgs/@akanjs/devkit/frontendBuild/ssrDevBundler.ts
|
|
3219
3417
|
class SsrDevBundler extends DevRegistryBundler {
|
|
3220
|
-
static #formatVersion =
|
|
3418
|
+
static #formatVersion = 4;
|
|
3221
3419
|
static bootstrapKey = "";
|
|
3222
3420
|
reloadsOnEntryChange = false;
|
|
3223
3421
|
#discovery = null;
|
|
@@ -3230,7 +3428,16 @@ class SsrDevBundler extends DevRegistryBundler {
|
|
|
3230
3428
|
const akanConfig = await this.app.getConfig();
|
|
3231
3429
|
const define = bundleDefine(this.app, "start", "ssr");
|
|
3232
3430
|
const optimizeImports = [...akanConfig.optimizeImports];
|
|
3233
|
-
const
|
|
3431
|
+
const barrelImports = workspaceBarrels(akanConfig.barrelImports);
|
|
3432
|
+
const configKey = Bun.hash(JSON.stringify([
|
|
3433
|
+
"ssr",
|
|
3434
|
+
SsrDevBundler.#formatVersion,
|
|
3435
|
+
Bun.version,
|
|
3436
|
+
define,
|
|
3437
|
+
optimizeImports,
|
|
3438
|
+
VENDOR_SPECIFIERS,
|
|
3439
|
+
barrelImports
|
|
3440
|
+
])).toString(36);
|
|
3234
3441
|
return {
|
|
3235
3442
|
pageEntries: [],
|
|
3236
3443
|
basePaths: [...akanConfig.basePaths],
|
|
@@ -3239,16 +3446,17 @@ class SsrDevBundler extends DevRegistryBundler {
|
|
|
3239
3446
|
optimizeImports,
|
|
3240
3447
|
configKey,
|
|
3241
3448
|
refreshFile: null,
|
|
3242
|
-
externals: VENDOR_SPECIFIERS
|
|
3449
|
+
externals: VENDOR_SPECIFIERS,
|
|
3450
|
+
barrelImports
|
|
3243
3451
|
};
|
|
3244
3452
|
}
|
|
3245
3453
|
isMetadataFile(file) {
|
|
3246
|
-
return super.isMetadataFile(file) && !file.endsWith(".dictionary.ts") &&
|
|
3454
|
+
return super.isMetadataFile(file) && !file.endsWith(".dictionary.ts") && path16.basename(file) !== "dict.ts";
|
|
3247
3455
|
}
|
|
3248
3456
|
async writeEntries() {
|
|
3249
3457
|
await mkdir5(this.entryDir, { recursive: true });
|
|
3250
|
-
const file =
|
|
3251
|
-
const hasStore = await Bun.file(
|
|
3458
|
+
const file = path16.join(this.entryDir, "bootstrap.ts");
|
|
3459
|
+
const hasStore = await Bun.file(path16.join(this.app.cwdPath, "lib", "st.ts")).exists();
|
|
3252
3460
|
const source = hasStore ? StoreBootstrap.source(this.app.name) : `export {};
|
|
3253
3461
|
`;
|
|
3254
3462
|
const unchanged = await Bun.file(file).exists() && await Bun.file(file).text() === source;
|