@akanjs/cli 3.2.0-rc.1 → 3.2.0-rc.2
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 +1 -1
- package/{CodeAgent-vmd9k4ak.js → CodeAgent-6cpjtj25.js} +2 -2
- package/{CodeTui-zka44v52.js → CodeTui-zyc7zaq6.js} +1 -1
- package/TunnelShare-zkfkrw8w.js +14 -0
- package/{agent.command-2f657613.js → agent.command-kf1g3nh4.js} +17 -17
- package/akanCode.js +2 -2
- package/{application.command-q6skd3am.js → application.command-vb278qnq.js} +12 -12
- package/{applicationBuildRunner-sctcmkyx.js → applicationBuildRunner-bqbyeg84.js} +6 -6
- package/buildBatch.proc.js +6 -6
- package/{cloud.command-7642pks6.js → cloud.command-ca777ee2.js} +18 -18
- package/cloud.script-agpxzq6j.js +30 -0
- package/{code.command-7s4ndq2k.js → code.command-j08txqcd.js} +6 -6
- package/{context.command-569z0rqf.js → context.command-2fa6egp9.js} +19 -19
- package/context.runner-ftv8373t.js +29 -0
- package/{guideline.command-gnv3e8p8.js → guideline.command-w6yqpdec.js} +2 -2
- package/incrementalBuilder.proc.js +7 -7
- package/{index-a8a9ede9.js → index-0fj9ra3q.js} +3 -3
- package/{index-thckcabc.js → index-0mqga3h9.js} +18 -3
- package/{index-abgh0jve.js → index-1cb9apzn.js} +1 -1
- package/{index-ed6ea0qp.js → index-20wvskt8.js} +1 -1
- package/{index-5w9my9qe.js → index-2gees180.js} +8 -8
- package/{index-93ewzmp6.js → index-386canwe.js} +21 -14
- package/{index-fjr4d6yd.js → index-466z5931.js} +5 -5
- package/{index-d4n1wmrz.js → index-65b6ms4c.js} +4 -4
- package/{index-6wpaq392.js → index-6h775rv3.js} +4 -4
- package/{index-aj3ehkcx.js → index-7kmbqp0b.js} +1 -1
- package/{index-1q1cjn8s.js → index-84c2pgak.js} +93 -53
- package/{index-sy481q2x.js → index-8jpc5fqv.js} +1 -1
- package/{index-vr68mxj5.js → index-8nbx607g.js} +8 -8
- package/{index-8kczhnmv.js → index-abfbf01s.js} +1 -1
- package/{index-v4p1zye8.js → index-annxfpgz.js} +7 -7
- package/{index-8g7tdsk4.js → index-bdmgqzb5.js} +4 -4
- package/{index-vkzfk7qt.js → index-c5ymqb05.js} +40 -30
- package/{index-0fb3cpbt.js → index-cbcwxp5v.js} +5 -5
- package/{index-zpv14wpy.js → index-djc5nxpy.js} +3 -3
- package/{index-s2grpzef.js → index-dk4g0x0d.js} +3 -3
- package/{index-drz9e84d.js → index-e22zedc2.js} +2 -2
- package/{index-w639tvkd.js → index-ebwkh7bt.js} +7 -4
- package/{index-8ts9774g.js → index-htxck0pn.js} +4 -4
- package/{index-9tbgb4d8.js → index-j1hjb477.js} +1 -1
- package/{index-kpdv34rq.js → index-j7p0jgaq.js} +10 -7
- package/{index-ktb3wcqz.js → index-kcpk2d20.js} +8 -8
- package/{index-7y5yghjg.js → index-m5sg5spm.js} +932 -431
- package/{index-rc5fvqj2.js → index-mvwvxgtd.js} +28 -26
- package/{index-e3vmjtph.js → index-pq5rjkch.js} +2 -2
- package/{index-48d5qsj3.js → index-qgazn58x.js} +4 -4
- package/{index-eajbmk10.js → index-v50xjbbe.js} +1 -1
- package/{index-7xdpww43.js → index-vbhx60x5.js} +323 -129
- package/{index-sr5da35e.js → index-wfmpxke3.js} +2 -2
- package/{index-mmym5xmb.js → index-wr9magsr.js} +5 -3
- package/{index-mqntfzv5.js → index-xa0289eg.js} +2 -2
- package/{index-8pb9yvp8.js → index-xq97me1h.js} +49 -12
- package/{index-p6hjwt2d.js → index-y725zb1a.js} +1 -1
- package/{index-hqrkqxx2.js → index-ygrdw6jw.js} +1 -1
- package/index.js +23 -23
- package/{library.command-1gp5qe3r.js → library.command-8d03a0pq.js} +4 -4
- package/{localRegistry.command-x7jptkd3.js → localRegistry.command-vyv5k6t0.js} +17 -17
- package/{module.command-4xz9he6h.js → module.command-vy3kg965.js} +7 -7
- package/{package.command-s7qpnn1g.js → package.command-qjh13rs9.js} +7 -7
- package/package.json +2 -2
- package/{page.command-fan34c49.js → page.command-t0nx1jat.js} +3 -3
- package/{pipeline.command-ph4fnn9w.js → pipeline.command-2yjeas7m.js} +2 -2
- package/{primitive.command-3fqh8emf.js → primitive.command-8vm49279.js} +7 -7
- package/{projectTypecheck-vkb40hjc.js → projectTypecheck-s9hhe5sa.js} +1 -1
- package/{quality.command-ecj6exsh.js → quality.command-v76fev72.js} +6 -6
- package/{repair.command-fe9jw719.js → repair.command-fp4m3w03.js} +6 -6
- package/{scalar.command-cnvfhk0n.js → scalar.command-hxe6try8.js} +6 -6
- package/skills/akan-scaffold/SKILL.md +2 -1
- package/{subspace.command-qw5ddd6y.js → subspace.command-q42n1844.js} +8 -8
- package/{tunnel.command-ggj38mqf.js → tunnel.command-22g11n0x.js} +7 -7
- package/{verify.command-w9ttxkdz.js → verify.command-rx43bha1.js} +14 -14
- package/{workflow.command-ss8devj0.js → workflow.command-yg0d8mmq.js} +30 -15
- package/{workspace.command-6z2rh8ze.js → workspace.command-fcfztvn5.js} +33 -33
- package/TunnelShare-k3ja4w9x.js +0 -14
- package/cloud.script-1sfseznn.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-y725zb1a.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-84c2pgak.js";
|
|
24
25
|
import {
|
|
25
26
|
AsyncDefaultExportDetector,
|
|
26
27
|
StoreBootstrap,
|
|
27
28
|
resolveSsrPageEntriesForApp
|
|
28
|
-
} from "./index-
|
|
29
|
+
} from "./index-wfmpxke3.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 {
|
|
@@ -589,6 +591,9 @@ class GraphClientEntryDiscovery {
|
|
|
589
591
|
#resolvedSpecifierCache = new Map;
|
|
590
592
|
#reachableEntriesCache = new Map;
|
|
591
593
|
#readFiles = new Set;
|
|
594
|
+
#barrelImporters = new Map;
|
|
595
|
+
#reread = new Map;
|
|
596
|
+
#settled = Promise.resolve();
|
|
592
597
|
#epoch = 0;
|
|
593
598
|
constructor(akanConfig, resolvePackage) {
|
|
594
599
|
this.#akanConfig = akanConfig;
|
|
@@ -599,6 +604,8 @@ class GraphClientEntryDiscovery {
|
|
|
599
604
|
return new GraphClientEntryDiscovery(await app.getConfig(), await createTsconfigPackageResolver(app));
|
|
600
605
|
}
|
|
601
606
|
async discover(seeds) {
|
|
607
|
+
this.#settled = this.#settled.then(() => this.#dropRenarrowed());
|
|
608
|
+
await this.#settled;
|
|
602
609
|
const entries = new Set;
|
|
603
610
|
for (const seed of seeds) {
|
|
604
611
|
const walk = { visiting: new Set, partial: new Set, memo: new Map };
|
|
@@ -623,12 +630,26 @@ class GraphClientEntryDiscovery {
|
|
|
623
630
|
}
|
|
624
631
|
this.#epoch += 1;
|
|
625
632
|
this.#reachableEntriesCache.clear();
|
|
633
|
+
for (const [barrel, before] of this.#analyzer.forget(files))
|
|
634
|
+
if (!this.#reread.has(barrel))
|
|
635
|
+
this.#reread.set(barrel, before);
|
|
626
636
|
if (!moved)
|
|
627
637
|
return;
|
|
628
638
|
this.#fileExistsCache.clear();
|
|
629
639
|
this.#resolvedFileCache.clear();
|
|
630
640
|
this.#resolvedSpecifierCache.clear();
|
|
631
641
|
}
|
|
642
|
+
async#dropRenarrowed() {
|
|
643
|
+
const reread = [...this.#reread];
|
|
644
|
+
this.#reread.clear();
|
|
645
|
+
for (const [barrel, before] of reread) {
|
|
646
|
+
const [was, now] = await Promise.all([before, this.#analyzer.analyze(barrel)]);
|
|
647
|
+
if (exportsKeyOf(was) === exportsKeyOf(now))
|
|
648
|
+
continue;
|
|
649
|
+
for (const importer of this.#barrelImporters.get(barrel) ?? [])
|
|
650
|
+
this.#factsCache.delete(importer);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
632
653
|
#lookup(cache, key, run, isFound) {
|
|
633
654
|
const cached = cache.get(key);
|
|
634
655
|
if (cached && (cached.found || cached.epoch === this.#epoch))
|
|
@@ -657,15 +678,17 @@ class GraphClientEntryDiscovery {
|
|
|
657
678
|
this.#readFiles.add(absPath);
|
|
658
679
|
if (USE_CLIENT_RE.test(content))
|
|
659
680
|
return { isClientEntry: true, imports: [] };
|
|
660
|
-
return { isClientEntry: false, imports: this.#scanImports(await this.#rewrite(content)) };
|
|
681
|
+
return { isClientEntry: false, imports: this.#scanImports(await this.#rewrite(content, absPath)) };
|
|
661
682
|
})();
|
|
662
683
|
this.#factsCache.set(absPath, cached);
|
|
663
684
|
}
|
|
664
685
|
return cached;
|
|
665
686
|
}
|
|
666
|
-
async#rewrite(content) {
|
|
687
|
+
async#rewrite(content, absPath) {
|
|
667
688
|
if (this.#akanConfig.barrelImports.length === 0)
|
|
668
689
|
return content;
|
|
690
|
+
for (const barrel of this.#akanConfig.barrelImports.filter((barrel) => content.includes(barrel)))
|
|
691
|
+
this.#barrelImporters.set(barrel, (this.#barrelImporters.get(barrel) ?? new Set).add(absPath));
|
|
669
692
|
try {
|
|
670
693
|
return await rewriteBarrelImports(content, this.#akanConfig.barrelImports, this.#analyzer) ?? content;
|
|
671
694
|
} catch {
|
|
@@ -770,12 +793,12 @@ class GraphClientEntryDiscovery {
|
|
|
770
793
|
|
|
771
794
|
// pkgs/@akanjs/devkit/frontendBuild/csrDevBundler.ts
|
|
772
795
|
import { mkdir as mkdir3 } from "fs/promises";
|
|
773
|
-
import
|
|
796
|
+
import path12 from "path";
|
|
774
797
|
import { CSR_DEV_DIRNAME, CSR_DEV_ROUTE_PREFIX } from "akanjs/server/hmr/csrDevManifest";
|
|
775
798
|
|
|
776
799
|
// pkgs/@akanjs/devkit/frontendBuild/devRegistryBundler.ts
|
|
777
800
|
import fs7 from "fs";
|
|
778
|
-
import
|
|
801
|
+
import path11 from "path";
|
|
779
802
|
import { isAkanRuntimeMetadataFile } from "akanjs/server/hmr/runtimeMetadataFile";
|
|
780
803
|
|
|
781
804
|
// pkgs/@akanjs/devkit/frontendBuild/csrDevArtifactWriter.ts
|
|
@@ -992,7 +1015,7 @@ class CsrDevArtifactWriter {
|
|
|
992
1015
|
}
|
|
993
1016
|
|
|
994
1017
|
// pkgs/@akanjs/devkit/frontendBuild/csrDevModuleCompiler.ts
|
|
995
|
-
import
|
|
1018
|
+
import path8 from "path";
|
|
996
1019
|
|
|
997
1020
|
// pkgs/@akanjs/devkit/frontendBuild/csrDevFactoryCheck.ts
|
|
998
1021
|
class CsrDevFactoryCheck {
|
|
@@ -1307,14 +1330,112 @@ class CsrDevResolver {
|
|
|
1307
1330
|
}
|
|
1308
1331
|
}
|
|
1309
1332
|
|
|
1333
|
+
// pkgs/@akanjs/devkit/frontendBuild/devBarrelImports.ts
|
|
1334
|
+
import path5 from "path";
|
|
1335
|
+
class DevBarrelImports {
|
|
1336
|
+
#barrels;
|
|
1337
|
+
#resolvePackage;
|
|
1338
|
+
#analyzer;
|
|
1339
|
+
#packages = new Map;
|
|
1340
|
+
constructor(barrels, resolvePackage) {
|
|
1341
|
+
this.#barrels = [...barrels];
|
|
1342
|
+
this.#resolvePackage = resolvePackage;
|
|
1343
|
+
this.#analyzer = new BarrelAnalyzer({ resolvePackage });
|
|
1344
|
+
}
|
|
1345
|
+
static async create(app, barrels) {
|
|
1346
|
+
if (barrels.length === 0)
|
|
1347
|
+
return null;
|
|
1348
|
+
return new DevBarrelImports(barrels, await createTsconfigPackageResolver(app));
|
|
1349
|
+
}
|
|
1350
|
+
async rewrite(source, importer) {
|
|
1351
|
+
const named = this.#barrels.filter((barrel) => source.includes(barrel));
|
|
1352
|
+
if (named.length === 0)
|
|
1353
|
+
return null;
|
|
1354
|
+
const packages = await this.#packagesOf(named);
|
|
1355
|
+
const from = path5.dirname(CsrDevPaths.realpath(importer));
|
|
1356
|
+
const names = new Map;
|
|
1357
|
+
const contents = await rewriteBarrelImports(source, named, this.#analyzer, {
|
|
1358
|
+
keepLines: true,
|
|
1359
|
+
specifierOf: (subpath) => DevBarrelImports.#relative(subpath, from, packages),
|
|
1360
|
+
onImport: (barrel, imported) => names.set(barrel, new Set([...names.get(barrel) ?? [], ...imported]))
|
|
1361
|
+
});
|
|
1362
|
+
const narrowed = await Promise.all([...names].map(async ([barrel, set]) => {
|
|
1363
|
+
const sorted = [...set].sort();
|
|
1364
|
+
return [barrel, { names: sorted, hash: await this.fingerprint(barrel, sorted) }];
|
|
1365
|
+
}));
|
|
1366
|
+
return { contents, narrowed: Object.fromEntries(narrowed) };
|
|
1367
|
+
}
|
|
1368
|
+
async fingerprint(barrel, names) {
|
|
1369
|
+
const packages = await this.#packagesOf([barrel]);
|
|
1370
|
+
const aliased = names.map((name, index) => `${name} as _${index}`).join(", ");
|
|
1371
|
+
const narrowed = await rewriteBarrelImports(`import { ${aliased} } from ${JSON.stringify(barrel)};`, [barrel], this.#analyzer, { specifierOf: (subpath) => DevBarrelImports.#fileOf(subpath, packages) ?? subpath });
|
|
1372
|
+
return Bun.hash(narrowed ?? "").toString(36);
|
|
1373
|
+
}
|
|
1374
|
+
async stamps(barrels, idOf) {
|
|
1375
|
+
const stamped = await Promise.all([...barrels].map(async (barrel) => {
|
|
1376
|
+
const files = await this.#analyzer.filesOf(barrel);
|
|
1377
|
+
const read = [...new Set([...files, ...files.map((file) => path5.dirname(file))])];
|
|
1378
|
+
const stamp = {
|
|
1379
|
+
read: Object.fromEntries(read.map((file) => [idOf(file), CsrDevPaths.mtimeOf(file)])),
|
|
1380
|
+
digest: await this.#digest(barrel)
|
|
1381
|
+
};
|
|
1382
|
+
return [barrel, stamp];
|
|
1383
|
+
}));
|
|
1384
|
+
return Object.fromEntries(stamped);
|
|
1385
|
+
}
|
|
1386
|
+
async#digest(barrel) {
|
|
1387
|
+
const map = await this.#analyzer.analyze(barrel);
|
|
1388
|
+
const packages = await this.#packagesOf([barrel]);
|
|
1389
|
+
const files = new Map;
|
|
1390
|
+
const fileOf = (subpath) => {
|
|
1391
|
+
let file = files.get(subpath);
|
|
1392
|
+
if (file === undefined) {
|
|
1393
|
+
file = DevBarrelImports.#fileOf(subpath, packages) ?? subpath;
|
|
1394
|
+
files.set(subpath, file);
|
|
1395
|
+
}
|
|
1396
|
+
return file;
|
|
1397
|
+
};
|
|
1398
|
+
const exports = [...map ?? []].map(([name, target]) => [name, target.originalName, !!target.namespace, fileOf(target.subpath)]).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
1399
|
+
return Bun.hash(JSON.stringify([fileOf(barrel), map === null, exports])).toString(36);
|
|
1400
|
+
}
|
|
1401
|
+
async#packagesOf(barrels) {
|
|
1402
|
+
return (await Promise.all(barrels.map((barrel) => this.#packageOf(barrel)))).filter((pkg) => pkg !== null).sort((a, b) => b.pkgName.length - a.pkgName.length);
|
|
1403
|
+
}
|
|
1404
|
+
#packageOf(barrel) {
|
|
1405
|
+
let pkg = this.#packages.get(barrel);
|
|
1406
|
+
if (!pkg) {
|
|
1407
|
+
pkg = this.#resolvePackage(barrel);
|
|
1408
|
+
this.#packages.set(barrel, pkg);
|
|
1409
|
+
}
|
|
1410
|
+
return pkg;
|
|
1411
|
+
}
|
|
1412
|
+
static #fileOf(subpath, packages) {
|
|
1413
|
+
const pkg = packages.find(({ pkgName }) => subpath === pkgName || subpath.startsWith(`${pkgName}/`));
|
|
1414
|
+
if (!pkg)
|
|
1415
|
+
return null;
|
|
1416
|
+
const file = CsrDevPaths.resolveOnDisk(path5.join(pkg.pkgDir, subpath.slice(pkg.pkgName.length)));
|
|
1417
|
+
return file ? CsrDevPaths.realpath(file) : null;
|
|
1418
|
+
}
|
|
1419
|
+
static #relative(subpath, from, packages) {
|
|
1420
|
+
const file = DevBarrelImports.#fileOf(subpath, packages);
|
|
1421
|
+
if (!file)
|
|
1422
|
+
return subpath;
|
|
1423
|
+
const relative = path5.relative(from, file);
|
|
1424
|
+
if (path5.isAbsolute(relative))
|
|
1425
|
+
return file.split(path5.sep).join("/");
|
|
1426
|
+
const posix = relative.split(path5.sep).join("/");
|
|
1427
|
+
return posix.startsWith("../") ? posix : `./${posix}`;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1310
1431
|
// pkgs/@akanjs/devkit/frontendBuild/routeClientBuilder.ts
|
|
1311
1432
|
import { mkdir as mkdir2 } from "fs/promises";
|
|
1312
|
-
import
|
|
1433
|
+
import path7 from "path";
|
|
1313
1434
|
import { SSR_DEV_CHUNK, SSR_DEV_ID_PREFIX } from "akanjs/server/hmr/csrDevManifest";
|
|
1314
1435
|
|
|
1315
1436
|
// pkgs/@akanjs/devkit/frontendBuild/clientEntriesBundler.ts
|
|
1316
1437
|
import fs4 from "fs";
|
|
1317
|
-
import
|
|
1438
|
+
import path6 from "path";
|
|
1318
1439
|
|
|
1319
1440
|
// pkgs/@akanjs/devkit/frontendBuild/clientBuildTypes.ts
|
|
1320
1441
|
var CLIENT_BUNDLE_NAMING = {
|
|
@@ -1405,25 +1526,25 @@ class ClientEntriesBundler {
|
|
|
1405
1526
|
};
|
|
1406
1527
|
}
|
|
1407
1528
|
async#createOpaqueEntryAliases() {
|
|
1408
|
-
const aliasDir =
|
|
1529
|
+
const aliasDir = path6.join(this.#app.cwdPath, ".akan", "generated", "client-entry-alias", this.#outputSubdir);
|
|
1409
1530
|
fs4.mkdirSync(aliasDir, { recursive: true });
|
|
1410
1531
|
const originalByAlias = new Map;
|
|
1411
1532
|
const aliasedEntries = await Promise.all(this.#entries.map(async (entry) => {
|
|
1412
|
-
const absEntry =
|
|
1533
|
+
const absEntry = path6.resolve(entry);
|
|
1413
1534
|
const narrowed = this.#entryExports[absEntry];
|
|
1414
1535
|
const key = `${this.#app.name}
|
|
1415
1536
|
${this.#outputSubdir}
|
|
1416
1537
|
${absEntry}${narrowed ? `
|
|
1417
1538
|
narrowed` : ""}`;
|
|
1418
|
-
const aliasPath =
|
|
1539
|
+
const aliasPath = path6.join(aliasDir, `${Bun.hash(key).toString(36)}.tsx`);
|
|
1419
1540
|
await Bun.write(aliasPath, narrowed ? ClientEntriesBundler.narrowedAliasSource(absEntry, narrowed) : this.#createOpaqueEntryAliasSource(absEntry, await this.#scanEntryExportNames(absEntry)));
|
|
1420
|
-
originalByAlias.set(
|
|
1541
|
+
originalByAlias.set(path6.resolve(aliasPath), absEntry);
|
|
1421
1542
|
return aliasPath;
|
|
1422
1543
|
}));
|
|
1423
1544
|
return { entries: aliasedEntries, originalByAlias, aliasDir };
|
|
1424
1545
|
}
|
|
1425
1546
|
#createOpaqueEntryAliasSource(absEntry, exportNames) {
|
|
1426
|
-
const entryLit = JSON.stringify(
|
|
1547
|
+
const entryLit = JSON.stringify(path6.resolve(absEntry));
|
|
1427
1548
|
if (exportNames.length === 0)
|
|
1428
1549
|
return `export * from ${entryLit};
|
|
1429
1550
|
`;
|
|
@@ -1437,17 +1558,17 @@ narrowed` : ""}`;
|
|
|
1437
1558
|
}
|
|
1438
1559
|
static narrowedAliasSource(absEntry, names) {
|
|
1439
1560
|
const list = names.length > 0 ? `{ ${names.join(", ")} }` : "{}";
|
|
1440
|
-
return `export ${list} from ${JSON.stringify(
|
|
1561
|
+
return `export ${list} from ${JSON.stringify(path6.resolve(absEntry))};
|
|
1441
1562
|
`;
|
|
1442
1563
|
}
|
|
1443
1564
|
#assertNarrowedExports() {
|
|
1444
1565
|
const missing = Object.entries(this.#entryExports).flatMap(([absEntry, names = []]) => {
|
|
1445
1566
|
const absOut = this.#entryOutputAbsByAbsPath.get(absEntry);
|
|
1446
1567
|
if (!absOut)
|
|
1447
|
-
return [`${
|
|
1568
|
+
return [`${path6.basename(absEntry)}: no output`];
|
|
1448
1569
|
const exported = new Set(this.#metafileOutputsByAbs.get(absOut)?.exports);
|
|
1449
1570
|
const absent = names.filter((name) => !exported.has(name));
|
|
1450
|
-
return absent.length > 0 ? [`${
|
|
1571
|
+
return absent.length > 0 ? [`${path6.basename(absEntry)}: ${absent.join(", ")}`] : [];
|
|
1451
1572
|
});
|
|
1452
1573
|
if (missing.length > 0)
|
|
1453
1574
|
throw new Error(`[ClientEntriesBundler] client code imports names its vendor does not export (${missing.join("; ")})`);
|
|
@@ -1509,16 +1630,16 @@ narrowed` : ""}`;
|
|
|
1509
1630
|
return rewritten;
|
|
1510
1631
|
}
|
|
1511
1632
|
#toServeUrl(absOutPath) {
|
|
1512
|
-
const rel =
|
|
1633
|
+
const rel = path6.relative(this.#outdir, absOutPath).split(path6.sep).join("/");
|
|
1513
1634
|
return `${this.#servePrefix}/${rel}`;
|
|
1514
1635
|
}
|
|
1515
1636
|
#absFromOutdir(p) {
|
|
1516
|
-
return
|
|
1637
|
+
return path6.isAbsolute(p) ? p : path6.resolve(this.#outdir, p);
|
|
1517
1638
|
}
|
|
1518
1639
|
#absFromEntryPoint(p) {
|
|
1519
|
-
if (
|
|
1520
|
-
return
|
|
1521
|
-
const candidates = [
|
|
1640
|
+
if (path6.isAbsolute(p))
|
|
1641
|
+
return path6.resolve(p);
|
|
1642
|
+
const candidates = [path6.resolve(process.cwd(), p), path6.resolve(this.#app.cwdPath, p)];
|
|
1522
1643
|
return candidates.find((candidate) => fs4.existsSync(candidate)) ?? candidates[0];
|
|
1523
1644
|
}
|
|
1524
1645
|
#collectChunkUrls(absOutPath, visited = new Set) {
|
|
@@ -1699,13 +1820,13 @@ class RouteClientBuilder {
|
|
|
1699
1820
|
ssrModuleMap[row.id][row.name] = { id: ssrOutput, chunks: [ssrOutput, ssrOutput], name: row.name, async: true };
|
|
1700
1821
|
}
|
|
1701
1822
|
for (const entry of bootstrapEntries.buildEntries) {
|
|
1702
|
-
const buildEntry =
|
|
1703
|
-
const originalEntry =
|
|
1823
|
+
const buildEntry = path7.resolve(entry);
|
|
1824
|
+
const originalEntry = path7.resolve(bootstrapEntries.originalByBuildEntry.get(buildEntry) ?? buildEntry);
|
|
1704
1825
|
if (!acceptedEntries.has(originalEntry))
|
|
1705
1826
|
continue;
|
|
1706
1827
|
const deps = new Set([originalEntry]);
|
|
1707
1828
|
for (const dep of referenceBundle.entryDepsByAbsPath.get(buildEntry) ?? [])
|
|
1708
|
-
deps.add(
|
|
1829
|
+
deps.add(path7.resolve(dep));
|
|
1709
1830
|
const sortedDeps = [...deps].sort();
|
|
1710
1831
|
clientDepsByEntry[originalEntry] = sortedDeps;
|
|
1711
1832
|
if (routeEntries.has(originalEntry))
|
|
@@ -1772,25 +1893,25 @@ class RouteClientBuilder {
|
|
|
1772
1893
|
}).bundle();
|
|
1773
1894
|
}
|
|
1774
1895
|
async#createBootstrapEntries(entries) {
|
|
1775
|
-
if (!await Bun.file(
|
|
1896
|
+
if (!await Bun.file(path7.join(this.#app.cwdPath, "lib", "st.ts")).exists()) {
|
|
1776
1897
|
return { buildEntries: entries, originalByBuildEntry: new Map };
|
|
1777
1898
|
}
|
|
1778
|
-
const outdir =
|
|
1899
|
+
const outdir = path7.join(this.#app.cwdPath, ".akan", "generated", "client-entry-bootstrap");
|
|
1779
1900
|
await mkdir2(outdir, { recursive: true });
|
|
1780
1901
|
const originalByBuildEntry = new Map;
|
|
1781
1902
|
const buildEntries = await Promise.all(entries.map(async (entry) => {
|
|
1782
|
-
const absEntry =
|
|
1903
|
+
const absEntry = path7.resolve(entry);
|
|
1783
1904
|
const hash = Bun.hash(`${this.#app.name}
|
|
1784
1905
|
${absEntry}`).toString(36);
|
|
1785
|
-
const base =
|
|
1786
|
-
const wrapperEntry =
|
|
1906
|
+
const base = path7.basename(absEntry).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
1907
|
+
const wrapperEntry = path7.join(outdir, `${base}-${hash}.tsx`);
|
|
1787
1908
|
const exportNames = await this.#scanExportNames(absEntry);
|
|
1788
1909
|
await Bun.write(wrapperEntry, RouteClientBuilder.createStoreBootstrapEntrySource({
|
|
1789
1910
|
appName: this.#app.name,
|
|
1790
1911
|
originalEntry: absEntry,
|
|
1791
1912
|
exportNames
|
|
1792
1913
|
}));
|
|
1793
|
-
originalByBuildEntry.set(
|
|
1914
|
+
originalByBuildEntry.set(path7.resolve(wrapperEntry), absEntry);
|
|
1794
1915
|
return wrapperEntry;
|
|
1795
1916
|
}));
|
|
1796
1917
|
return { buildEntries, originalByBuildEntry };
|
|
@@ -1864,11 +1985,11 @@ ${declared.map(({ name }) => `export default ${name};`).join(`
|
|
|
1864
1985
|
try {
|
|
1865
1986
|
return Bun.resolveSync("akanjs/server", import.meta.dir);
|
|
1866
1987
|
} catch {
|
|
1867
|
-
return
|
|
1988
|
+
return path7.resolve(import.meta.dir, "../../../server/index.ts");
|
|
1868
1989
|
}
|
|
1869
1990
|
}
|
|
1870
1991
|
static createStoreBootstrapEntrySource(args) {
|
|
1871
|
-
const originalEntry = JSON.stringify(
|
|
1992
|
+
const originalEntry = JSON.stringify(path7.resolve(args.originalEntry));
|
|
1872
1993
|
const namedExports = args.exportNames.filter((name) => name !== "default");
|
|
1873
1994
|
const lines = [
|
|
1874
1995
|
...StoreBootstrap.importLines(args.appName),
|
|
@@ -1909,6 +2030,8 @@ class CsrDevModuleCompiler {
|
|
|
1909
2030
|
#outDir;
|
|
1910
2031
|
#routePrefix;
|
|
1911
2032
|
#assets = new Set;
|
|
2033
|
+
#barrels = null;
|
|
2034
|
+
#narrowed = new Map;
|
|
1912
2035
|
constructor({ app, paths, resolver, context, outDir, routePrefix }) {
|
|
1913
2036
|
this.#app = app;
|
|
1914
2037
|
this.#paths = paths;
|
|
@@ -1952,7 +2075,13 @@ class CsrDevModuleCompiler {
|
|
|
1952
2075
|
const { fallbacks } = this.#resolver;
|
|
1953
2076
|
if (fallbacks.size > 0)
|
|
1954
2077
|
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
|
-
|
|
2078
|
+
const modules = [...compiled.values()];
|
|
2079
|
+
return { modules, refusedVendors: [], unresolved: [], barrels: await this.#barrelStamps(modules) };
|
|
2080
|
+
}
|
|
2081
|
+
async#barrelStamps(modules) {
|
|
2082
|
+
const barrels = new Set(modules.flatMap((module) => Object.keys(module.narrowed ?? {})));
|
|
2083
|
+
const barrelImports = barrels.size > 0 ? await this.#barrelImports() : null;
|
|
2084
|
+
return barrelImports ? await barrelImports.stamps(barrels, (file) => this.#paths.idOf(file)) : {};
|
|
1956
2085
|
}
|
|
1957
2086
|
async#compileRound(files) {
|
|
1958
2087
|
const appFiles = files.filter((file) => !CsrDevPaths.isVendorFile(file));
|
|
@@ -2004,7 +2133,7 @@ class CsrDevModuleCompiler {
|
|
|
2004
2133
|
const tangled = [];
|
|
2005
2134
|
for (const artifact of result.outputs) {
|
|
2006
2135
|
if (artifact.kind === "asset") {
|
|
2007
|
-
const assetPath =
|
|
2136
|
+
const assetPath = path8.join(this.#outDir, artifact.path);
|
|
2008
2137
|
await Bun.write(assetPath, artifact);
|
|
2009
2138
|
this.#assets.add(assetPath);
|
|
2010
2139
|
continue;
|
|
@@ -2014,8 +2143,8 @@ class CsrDevModuleCompiler {
|
|
|
2014
2143
|
const meta = outputs[artifact.path];
|
|
2015
2144
|
if (!meta?.entryPoint)
|
|
2016
2145
|
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(
|
|
2146
|
+
const file = CsrDevPaths.realpath(path8.resolve(meta.entryPoint));
|
|
2147
|
+
const inputs = Object.keys(meta.inputs).map((input) => CsrDevPaths.realpath(path8.resolve(input)));
|
|
2019
2148
|
if (inputs.some((input) => input !== file && this.#resolver.isRegistryModule(input))) {
|
|
2020
2149
|
tangled.push(file);
|
|
2021
2150
|
continue;
|
|
@@ -2031,6 +2160,7 @@ class CsrDevModuleCompiler {
|
|
|
2031
2160
|
continue;
|
|
2032
2161
|
}
|
|
2033
2162
|
const sourceMap = sourceMaps.get(`${artifact.path}.map`);
|
|
2163
|
+
const narrowed = this.#narrowed.get(file);
|
|
2034
2164
|
modules.push({
|
|
2035
2165
|
id,
|
|
2036
2166
|
file,
|
|
@@ -2039,7 +2169,8 @@ class CsrDevModuleCompiler {
|
|
|
2039
2169
|
sourceMap: sourceMap ? this.#rebaseSourceMap(await sourceMap.text()) : undefined,
|
|
2040
2170
|
deps: this.#emittedDeps(code),
|
|
2041
2171
|
mtimeMs: mtimes.get(file) ?? CsrDevPaths.mtimeOf(file),
|
|
2042
|
-
hash: hashes.get(file) ?? ""
|
|
2172
|
+
hash: hashes.get(file) ?? "",
|
|
2173
|
+
...narrowed && Object.keys(narrowed).length > 0 ? { narrowed } : {}
|
|
2043
2174
|
});
|
|
2044
2175
|
}
|
|
2045
2176
|
return { modules, misses, tangled };
|
|
@@ -2048,7 +2179,7 @@ class CsrDevModuleCompiler {
|
|
|
2048
2179
|
const reasons = new Map;
|
|
2049
2180
|
for (const message of error.errors) {
|
|
2050
2181
|
const file = message.position?.file;
|
|
2051
|
-
if (typeof file !== "string" || !
|
|
2182
|
+
if (typeof file !== "string" || !path8.isAbsolute(file))
|
|
2052
2183
|
continue;
|
|
2053
2184
|
const real = CsrDevPaths.realpath(file);
|
|
2054
2185
|
const at = message.position?.line ? `:${message.position.line}` : "";
|
|
@@ -2120,11 +2251,17 @@ class CsrDevModuleCompiler {
|
|
|
2120
2251
|
});
|
|
2121
2252
|
}
|
|
2122
2253
|
if (!vendor)
|
|
2123
|
-
build.onLoad({ filter: /\.tsx$/ }, async (args) => {
|
|
2254
|
+
build.onLoad({ filter: /\.(?:tsx?|jsx?)$/ }, async (args) => {
|
|
2124
2255
|
if (CsrDevPaths.isVendorFile(args.path))
|
|
2125
2256
|
return;
|
|
2126
|
-
const
|
|
2127
|
-
|
|
2257
|
+
const source = await Bun.file(args.path).text();
|
|
2258
|
+
const rewrite = await (await this.#barrelImports())?.rewrite(source, args.path);
|
|
2259
|
+
if (rewrite)
|
|
2260
|
+
this.#narrowed.set(CsrDevPaths.realpath(args.path), rewrite.narrowed);
|
|
2261
|
+
const narrowed = rewrite?.contents ?? source;
|
|
2262
|
+
const normalized = args.path.endsWith(".tsx") ? RouteClientBuilder.normalizeNamedDefaultFunctionForFastRefresh(narrowed, { path: args.path }) : null;
|
|
2263
|
+
const contents = normalized ?? narrowed;
|
|
2264
|
+
return contents === source ? undefined : { contents, loader: loaderFor(args.path) };
|
|
2128
2265
|
});
|
|
2129
2266
|
build.onResolve({ filter: /.*/ }, (args) => {
|
|
2130
2267
|
if (args.kind === "entry-point-build" || !args.importer)
|
|
@@ -2145,9 +2282,13 @@ class CsrDevModuleCompiler {
|
|
|
2145
2282
|
}
|
|
2146
2283
|
};
|
|
2147
2284
|
}
|
|
2285
|
+
#barrelImports() {
|
|
2286
|
+
this.#barrels ??= DevBarrelImports.create(this.#app, this.#context.barrelImports ?? []);
|
|
2287
|
+
return this.#barrels;
|
|
2288
|
+
}
|
|
2148
2289
|
#rebaseSourceMap(text) {
|
|
2149
2290
|
const map = JSON.parse(text);
|
|
2150
|
-
const files = map.sources.map((source) =>
|
|
2291
|
+
const files = map.sources.map((source) => path8.resolve(source));
|
|
2151
2292
|
map.sources = files.map((file) => `/${this.#paths.idOf(file)}`);
|
|
2152
2293
|
map.sourcesContent = files.map((file, index) => CsrDevPaths.isVendorFile(file) ? null : map.sourcesContent?.[index] ?? null);
|
|
2153
2294
|
return JSON.stringify(map);
|
|
@@ -2212,7 +2353,7 @@ ${preamble}return { ${names.join(", ")} };
|
|
|
2212
2353
|
|
|
2213
2354
|
// pkgs/@akanjs/devkit/frontendBuild/csrDevPatcher.ts
|
|
2214
2355
|
import fs5 from "fs";
|
|
2215
|
-
import
|
|
2356
|
+
import path9 from "path";
|
|
2216
2357
|
import { appGenerationOf as appGenerationOf2, CSR_DEV_MANIFEST_FILE as CSR_DEV_MANIFEST_FILE2 } from "akanjs/server/hmr/csrDevManifest";
|
|
2217
2358
|
class CsrDevPatcher {
|
|
2218
2359
|
#bundler;
|
|
@@ -2247,7 +2388,7 @@ class CsrDevPatcher {
|
|
|
2247
2388
|
return this.#handBack("the dev bundle config changed", generation, context);
|
|
2248
2389
|
const metadataFile = changedFiles.find((file) => this.#bundler.isMetadataFile(file));
|
|
2249
2390
|
if (metadataFile)
|
|
2250
|
-
return this.#handBack(`${
|
|
2391
|
+
return this.#handBack(`${path9.basename(metadataFile)} changed`, generation, context);
|
|
2251
2392
|
if (!resident && state.graph.metadata !== await this.#bundler.metadataFingerprint())
|
|
2252
2393
|
return this.#handBack("signal or dictionary metadata changed since the registry was built", generation, context);
|
|
2253
2394
|
this.#state = this.#resident ? state : null;
|
|
@@ -2269,6 +2410,7 @@ class CsrDevPatcher {
|
|
|
2269
2410
|
const present = CsrDevPatcher.#presence(changedFiles);
|
|
2270
2411
|
const forgotten = this.#forgetDeletedModules(state, present);
|
|
2271
2412
|
const changed = onlyRoots ? new Set : await this.#changedModules(graph, changedFiles, present);
|
|
2413
|
+
const restamped = onlyRoots ? null : await this.#renarrowed(context, graph, changedFiles, changed);
|
|
2272
2414
|
for (const id of this.#withoutFactory(state, present))
|
|
2273
2415
|
changed.add(id);
|
|
2274
2416
|
for (const file of entries.changed)
|
|
@@ -2282,6 +2424,8 @@ class CsrDevPatcher {
|
|
|
2282
2424
|
const carried = onlyRoots ? [] : await this.#carriedRoots(graph, changed, present);
|
|
2283
2425
|
const routesMoved = this.#bundler.reloadsOnEntryChange && (entries.changed.length > 0 || JSON.stringify(entryIds) !== JSON.stringify(graph.entries));
|
|
2284
2426
|
if (changed.size === 0) {
|
|
2427
|
+
if (restamped)
|
|
2428
|
+
graph.barrels = { ...graph.barrels, ...restamped };
|
|
2285
2429
|
if (carried.length === 0)
|
|
2286
2430
|
return { kind: "unchanged" };
|
|
2287
2431
|
return await this.#retryCarried(context, state, carried, { announce, allowWholeAppBuilds });
|
|
@@ -2336,22 +2480,17 @@ class CsrDevPatcher {
|
|
|
2336
2480
|
forgotten.push(id);
|
|
2337
2481
|
}
|
|
2338
2482
|
graph.pending = graph.pending.filter((id) => !orphans.includes(id));
|
|
2339
|
-
this.#bundler.merge(graph, resolver, compiled);
|
|
2483
|
+
this.#bundler.merge(graph, resolver, compiled, { ...restamped, ...result.barrels });
|
|
2340
2484
|
if (!this.#resident)
|
|
2341
2485
|
delete graph.failed;
|
|
2342
2486
|
for (const module of compiled)
|
|
2343
2487
|
this.#delegated.delete(module.id);
|
|
2344
2488
|
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
|
-
}
|
|
2489
|
+
if (code)
|
|
2490
|
+
CsrDevPatcher.#remember(code, compiled);
|
|
2352
2491
|
const changedIds = compiled.filter((module) => !module.vendor).map((module) => module.id);
|
|
2353
2492
|
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 ? `${
|
|
2493
|
+
const reason = vendorJoined ? "an npm module joined the graph" : routesMoved ? "the route table changed" : constantId ? `${path9.basename(constantId)} changed` : undefined;
|
|
2355
2494
|
if (compiled.length === 0 && !reason) {
|
|
2356
2495
|
await writer.writeJson("graph.json", graph);
|
|
2357
2496
|
await writer.forgetModules(forgotten);
|
|
@@ -2457,7 +2596,8 @@ class CsrDevPatcher {
|
|
|
2457
2596
|
return {
|
|
2458
2597
|
modules: [...result.modules, ...more.modules],
|
|
2459
2598
|
refusedVendors: [...result.refusedVendors, ...more.refusedVendors],
|
|
2460
|
-
unresolved: [...result.unresolved, ...more.unresolved]
|
|
2599
|
+
unresolved: [...result.unresolved, ...more.unresolved],
|
|
2600
|
+
barrels: { ...result.barrels, ...more.barrels }
|
|
2461
2601
|
};
|
|
2462
2602
|
}
|
|
2463
2603
|
static #implicatedFiles(error) {
|
|
@@ -2465,9 +2605,9 @@ class CsrDevPatcher {
|
|
|
2465
2605
|
const messages = error instanceof AggregateError ? error.errors : [];
|
|
2466
2606
|
const named = messages.flatMap((message) => {
|
|
2467
2607
|
const text = String(message.message ?? "");
|
|
2468
|
-
const bases = [process.cwd(), ...failing.map((file) =>
|
|
2608
|
+
const bases = [process.cwd(), ...failing.map((file) => path9.dirname(file))];
|
|
2469
2609
|
return [...text.matchAll(/"([^"\n]+)"/g)].flatMap(([, quoted = ""]) => {
|
|
2470
|
-
const found = bases.map((base) =>
|
|
2610
|
+
const found = bases.map((base) => path9.resolve(base, quoted)).find((file) => CsrDevPaths.isScript(file) && fs5.existsSync(file));
|
|
2471
2611
|
return found ? [CsrDevPaths.realpath(found)] : [];
|
|
2472
2612
|
});
|
|
2473
2613
|
});
|
|
@@ -2475,7 +2615,7 @@ class CsrDevPatcher {
|
|
|
2475
2615
|
}
|
|
2476
2616
|
static #failingFiles(error) {
|
|
2477
2617
|
const messages = error instanceof AggregateError ? error.errors : [];
|
|
2478
|
-
return messages.map((message) => message.position?.file).filter((file) => typeof file === "string" &&
|
|
2618
|
+
return messages.map((message) => message.position?.file).filter((file) => typeof file === "string" && path9.isAbsolute(file)).map((file) => CsrDevPaths.realpath(file));
|
|
2479
2619
|
}
|
|
2480
2620
|
async#carriedRoots(graph, changed, present) {
|
|
2481
2621
|
const { paths } = this.#bundler;
|
|
@@ -2572,19 +2712,48 @@ class CsrDevPatcher {
|
|
|
2572
2712
|
}
|
|
2573
2713
|
return changed;
|
|
2574
2714
|
}
|
|
2715
|
+
async#renarrowed(context, graph, changedFiles, changed) {
|
|
2716
|
+
const { paths } = this.#bundler;
|
|
2717
|
+
const saved = new Set(changedFiles.map((file) => paths.idOf(file)));
|
|
2718
|
+
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);
|
|
2719
|
+
const barrelImports = stale.length > 0 ? await this.#bundler.barrelImports(context) : null;
|
|
2720
|
+
if (!barrelImports)
|
|
2721
|
+
return {};
|
|
2722
|
+
const barrels = await barrelImports.stamps(stale, (file) => paths.idOf(file));
|
|
2723
|
+
const moved = stale.filter((barrel) => barrels[barrel]?.digest !== graph.barrels?.[barrel]?.digest);
|
|
2724
|
+
for (const [id, module] of Object.entries(graph.modules)) {
|
|
2725
|
+
for (const barrel of moved) {
|
|
2726
|
+
const narrowed = module.narrowed?.[barrel];
|
|
2727
|
+
if (!narrowed || await barrelImports.fingerprint(barrel, narrowed.names) === narrowed.hash)
|
|
2728
|
+
continue;
|
|
2729
|
+
changed.add(id);
|
|
2730
|
+
break;
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
return barrels;
|
|
2734
|
+
}
|
|
2735
|
+
static #remember(code, compiled) {
|
|
2736
|
+
for (const module of compiled) {
|
|
2737
|
+
if (module.vendor)
|
|
2738
|
+
continue;
|
|
2739
|
+
code.modules.set(module.id, module.factory);
|
|
2740
|
+
if (module.helpers)
|
|
2741
|
+
code.helpers.set(module.helpers.hash, module.helpers.definition);
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2575
2744
|
#shadowedImporters(graph, changedFiles) {
|
|
2576
2745
|
const { paths } = this.#bundler;
|
|
2577
2746
|
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
|
|
2747
|
+
const stem = file.slice(0, file.length - path9.extname(file).length);
|
|
2748
|
+
return path9.basename(stem) === "index" ? [stem, path9.dirname(stem)] : [stem];
|
|
2580
2749
|
}));
|
|
2581
2750
|
if (bases.size === 0)
|
|
2582
2751
|
return [];
|
|
2583
2752
|
return Object.entries(graph.resolution).filter(([importer, bySpecifier]) => {
|
|
2584
2753
|
if (!graph.modules[importer] || graph.modules[importer]?.vendor)
|
|
2585
2754
|
return false;
|
|
2586
|
-
const dir =
|
|
2587
|
-
return Object.keys(bySpecifier).some((specifier) => specifier.startsWith(".") && bases.has(
|
|
2755
|
+
const dir = path9.dirname(paths.fileOf(importer));
|
|
2756
|
+
return Object.keys(bySpecifier).some((specifier) => specifier.startsWith(".") && bases.has(path9.resolve(dir, specifier)));
|
|
2588
2757
|
}).map(([importer]) => importer);
|
|
2589
2758
|
}
|
|
2590
2759
|
#forgetDeletedModules({ graph, code }, present) {
|
|
@@ -2600,7 +2769,7 @@ class CsrDevPatcher {
|
|
|
2600
2769
|
|
|
2601
2770
|
// pkgs/@akanjs/devkit/frontendBuild/registryMetadataFingerprint.ts
|
|
2602
2771
|
import fs6 from "fs";
|
|
2603
|
-
import
|
|
2772
|
+
import path10 from "path";
|
|
2604
2773
|
|
|
2605
2774
|
class RegistryMetadataFingerprint {
|
|
2606
2775
|
static #sources = new Bun.Glob("**/*.{signal,dictionary}.ts");
|
|
@@ -2608,12 +2777,12 @@ class RegistryMetadataFingerprint {
|
|
|
2608
2777
|
static async of(roots, isMetadataFile) {
|
|
2609
2778
|
const stamps = [];
|
|
2610
2779
|
for (const root of new Set(roots)) {
|
|
2611
|
-
const libDir =
|
|
2780
|
+
const libDir = path10.join(root, "lib");
|
|
2612
2781
|
if (!fs6.existsSync(libDir))
|
|
2613
2782
|
continue;
|
|
2614
|
-
const files = RegistryMetadataFingerprint.#libFiles.map((name) =>
|
|
2783
|
+
const files = RegistryMetadataFingerprint.#libFiles.map((name) => path10.join(libDir, name));
|
|
2615
2784
|
for await (const relative of RegistryMetadataFingerprint.#sources.scan({ cwd: libDir, onlyFiles: true }))
|
|
2616
|
-
files.push(
|
|
2785
|
+
files.push(path10.join(libDir, relative));
|
|
2617
2786
|
for (const file of files) {
|
|
2618
2787
|
if (!isMetadataFile(file))
|
|
2619
2788
|
continue;
|
|
@@ -2639,8 +2808,8 @@ class DevRegistryBundler {
|
|
|
2639
2808
|
this.app = app;
|
|
2640
2809
|
this.routePrefix = routePrefix;
|
|
2641
2810
|
this.paths = new CsrDevPaths(app.workspace.workspaceRoot);
|
|
2642
|
-
this.outDir =
|
|
2643
|
-
this.entryDir =
|
|
2811
|
+
this.outDir = path11.join(app.cwdPath, ".akan/artifact", dirName);
|
|
2812
|
+
this.entryDir = path11.join(app.cwdPath, ".akan/generated", dirName);
|
|
2644
2813
|
this.writer = new CsrDevArtifactWriter(this.outDir, { routePrefix, library });
|
|
2645
2814
|
}
|
|
2646
2815
|
async update(changedFiles = [], options = {}) {
|
|
@@ -2678,10 +2847,10 @@ class DevRegistryBundler {
|
|
|
2678
2847
|
return isAkanRuntimeMetadataFile(file);
|
|
2679
2848
|
}
|
|
2680
2849
|
async metadataFingerprint() {
|
|
2681
|
-
const libsContainer =
|
|
2850
|
+
const libsContainer = path11.resolve(this.app.workspace.workspaceRoot, "libs");
|
|
2682
2851
|
const roots = await new WatchRootResolver(this.app).resolve();
|
|
2683
|
-
const libRoots = roots.includes(libsContainer) ? fs7.readdirSync(libsContainer).map((name) =>
|
|
2684
|
-
return await RegistryMetadataFingerprint.of([
|
|
2852
|
+
const libRoots = roots.includes(libsContainer) ? fs7.readdirSync(libsContainer).map((name) => path11.join(libsContainer, name)) : roots.filter((root) => path11.dirname(root) === libsContainer);
|
|
2853
|
+
return await RegistryMetadataFingerprint.of([path11.resolve(this.app.cwdPath), ...libRoots], (file) => this.isMetadataFile(file));
|
|
2685
2854
|
}
|
|
2686
2855
|
async fullBuild(context, generation, reason) {
|
|
2687
2856
|
const metadata = await this.metadataFingerprint();
|
|
@@ -2690,7 +2859,7 @@ class DevRegistryBundler {
|
|
|
2690
2859
|
const resolver = new CsrDevResolver({ paths: this.paths, context, entryFiles: roots });
|
|
2691
2860
|
await resolver.prepass();
|
|
2692
2861
|
const compiler = this.compiler(context, resolver);
|
|
2693
|
-
const { modules: compiled } = await compiler.compile([...roots, ...context.refreshFile ? [context.refreshFile] : []], new Set);
|
|
2862
|
+
const { modules: compiled, barrels } = await compiler.compile([...roots, ...context.refreshFile ? [context.refreshFile] : []], new Set);
|
|
2694
2863
|
const graph = {
|
|
2695
2864
|
version: 1,
|
|
2696
2865
|
configKey: context.configKey,
|
|
@@ -2701,7 +2870,7 @@ class DevRegistryBundler {
|
|
|
2701
2870
|
pending: [],
|
|
2702
2871
|
metadata
|
|
2703
2872
|
};
|
|
2704
|
-
this.merge(graph, resolver, compiled);
|
|
2873
|
+
this.merge(graph, resolver, compiled, barrels);
|
|
2705
2874
|
await this.writer.markBuilding();
|
|
2706
2875
|
await this.writer.writeModules(compiled);
|
|
2707
2876
|
const vendorFile = await this.writer.writeVendor(graph);
|
|
@@ -2722,15 +2891,21 @@ class DevRegistryBundler {
|
|
|
2722
2891
|
routePrefix: this.routePrefix
|
|
2723
2892
|
});
|
|
2724
2893
|
}
|
|
2725
|
-
|
|
2894
|
+
async barrelImports(context) {
|
|
2895
|
+
return await DevBarrelImports.create(this.app, context.barrelImports ?? []);
|
|
2896
|
+
}
|
|
2897
|
+
merge(graph, resolver, compiled, barrels = {}) {
|
|
2726
2898
|
for (const module of compiled)
|
|
2727
2899
|
graph.modules[module.id] = {
|
|
2728
2900
|
vendor: module.vendor,
|
|
2729
2901
|
mtimeMs: module.mtimeMs,
|
|
2730
2902
|
hash: module.hash,
|
|
2731
2903
|
deps: module.deps.map((dep) => CsrDevPaths.isStub(dep) ? dep : this.paths.idOf(dep)),
|
|
2732
|
-
...module.helpers ? { helpers: module.helpers.hash } : {}
|
|
2904
|
+
...module.helpers ? { helpers: module.helpers.hash } : {},
|
|
2905
|
+
...module.narrowed ? { narrowed: module.narrowed } : {}
|
|
2733
2906
|
};
|
|
2907
|
+
const narrowing = new Set(Object.values(graph.modules).flatMap((module) => Object.keys(module.narrowed ?? {})));
|
|
2908
|
+
graph.barrels = Object.fromEntries(Object.entries({ ...graph.barrels, ...barrels }).filter(([barrel]) => narrowing.has(barrel)));
|
|
2734
2909
|
const compiledIds = new Set(compiled.map((module) => module.id));
|
|
2735
2910
|
graph.pending = graph.pending.filter((id) => !compiledIds.has(id));
|
|
2736
2911
|
graph.resolution = resolver.serialize();
|
|
@@ -2743,7 +2918,7 @@ class DevRegistryBundler {
|
|
|
2743
2918
|
|
|
2744
2919
|
// pkgs/@akanjs/devkit/frontendBuild/csrDevBundler.ts
|
|
2745
2920
|
class CsrDevBundler extends DevRegistryBundler {
|
|
2746
|
-
static #formatVersion =
|
|
2921
|
+
static #formatVersion = 6;
|
|
2747
2922
|
reloadsOnEntryChange = true;
|
|
2748
2923
|
#asyncDefaults = new Map;
|
|
2749
2924
|
constructor(app) {
|
|
@@ -2758,7 +2933,15 @@ class CsrDevBundler extends DevRegistryBundler {
|
|
|
2758
2933
|
const htmlBasePaths = basePaths.length > 0 ? basePaths : [""];
|
|
2759
2934
|
const define = bundleDefine(this.app, "start", "csr");
|
|
2760
2935
|
const optimizeImports = [...akanConfig.optimizeImports];
|
|
2761
|
-
const
|
|
2936
|
+
const barrelImports = workspaceBarrels(akanConfig.barrelImports);
|
|
2937
|
+
const configKey = Bun.hash(JSON.stringify([
|
|
2938
|
+
CsrDevBundler.#formatVersion,
|
|
2939
|
+
Bun.version,
|
|
2940
|
+
define,
|
|
2941
|
+
optimizeImports,
|
|
2942
|
+
htmlBasePaths,
|
|
2943
|
+
barrelImports
|
|
2944
|
+
])).toString(36);
|
|
2762
2945
|
return {
|
|
2763
2946
|
pageEntries,
|
|
2764
2947
|
basePaths,
|
|
@@ -2766,7 +2949,8 @@ class CsrDevBundler extends DevRegistryBundler {
|
|
|
2766
2949
|
define,
|
|
2767
2950
|
optimizeImports,
|
|
2768
2951
|
configKey,
|
|
2769
|
-
refreshFile: this.#resolveRefreshRuntime()
|
|
2952
|
+
refreshFile: this.#resolveRefreshRuntime(),
|
|
2953
|
+
barrelImports
|
|
2770
2954
|
};
|
|
2771
2955
|
}
|
|
2772
2956
|
async writeEntries(context) {
|
|
@@ -2774,7 +2958,7 @@ class CsrDevBundler extends DevRegistryBundler {
|
|
|
2774
2958
|
const files = {};
|
|
2775
2959
|
const changed = [];
|
|
2776
2960
|
for (const basePath of context.htmlBasePaths) {
|
|
2777
|
-
const file =
|
|
2961
|
+
const file = path12.join(this.entryDir, CsrEntryFiles.entryFilename(basePath));
|
|
2778
2962
|
const entryPages = CsrEntryFiles.pageEntriesForBasePath(context.pageEntries, basePath, context.basePaths);
|
|
2779
2963
|
const generator = new PagesEntrySourceGenerator(entryPages, {
|
|
2780
2964
|
isAsyncDefault: (moduleAbsPath) => this.#isAsyncDefault(moduleAbsPath)
|
|
@@ -2813,7 +2997,7 @@ ${hot}`;
|
|
|
2813
2997
|
}
|
|
2814
2998
|
#resolveRefreshRuntime() {
|
|
2815
2999
|
const akanWebkit = CsrDevPaths.tryResolve("akanjs/webkit", this.app.cwdPath);
|
|
2816
|
-
const bases = [this.app.cwdPath, this.paths.root, ...akanWebkit ? [
|
|
3000
|
+
const bases = [this.app.cwdPath, this.paths.root, ...akanWebkit ? [path12.dirname(path12.dirname(akanWebkit))] : []];
|
|
2817
3001
|
for (const base of bases) {
|
|
2818
3002
|
const resolved = CsrDevPaths.tryResolve("react-refresh/runtime", base);
|
|
2819
3003
|
if (resolved)
|
|
@@ -2824,7 +3008,7 @@ ${hot}`;
|
|
|
2824
3008
|
}
|
|
2825
3009
|
|
|
2826
3010
|
// pkgs/@akanjs/devkit/frontendBuild/devChangePlanner.ts
|
|
2827
|
-
import
|
|
3011
|
+
import path13 from "path";
|
|
2828
3012
|
var CONFIG_BASENAMES = new Set(["akan.config.ts", "bunfig.toml", "tsconfig.json", "package.json"]);
|
|
2829
3013
|
var BARREL_FACETS = new Set(["common", "srvkit", "ui", "webkit", "plugin"]);
|
|
2830
3014
|
var CLIENT_SUFFIXES = [".Template.tsx", ".Unit.tsx", ".Util.tsx", ".View.tsx", ".Zone.tsx", ".store.ts"];
|
|
@@ -2835,11 +3019,11 @@ var RUNTIME_METADATA_BASENAMES = new Set(["dict.ts", "sig.ts", "useClient.ts", "
|
|
|
2835
3019
|
class DevChangePlanner {
|
|
2836
3020
|
#workspaceRoot;
|
|
2837
3021
|
constructor({ workspaceRoot }) {
|
|
2838
|
-
this.#workspaceRoot =
|
|
3022
|
+
this.#workspaceRoot = path13.resolve(workspaceRoot);
|
|
2839
3023
|
}
|
|
2840
3024
|
plan({ generation, files, kinds, generatedFiles = [] }) {
|
|
2841
3025
|
const fileList = uniqueResolved([...files, ...generatedFiles]);
|
|
2842
|
-
const generatedSet = new Set(generatedFiles.map((file) =>
|
|
3026
|
+
const generatedSet = new Set(generatedFiles.map((file) => path13.resolve(file)));
|
|
2843
3027
|
const kindSet = new Set(kinds);
|
|
2844
3028
|
const roles = new Set;
|
|
2845
3029
|
const actions = new Set;
|
|
@@ -2856,13 +3040,13 @@ class DevChangePlanner {
|
|
|
2856
3040
|
}
|
|
2857
3041
|
for (const file of fileList) {
|
|
2858
3042
|
const reasons = new Set;
|
|
2859
|
-
const fileRoles = this.#rolesForFile(file, { isGenerated: generatedSet.has(
|
|
3043
|
+
const fileRoles = this.#rolesForFile(file, { isGenerated: generatedSet.has(path13.resolve(file)), reasons });
|
|
2860
3044
|
for (const role of fileRoles)
|
|
2861
3045
|
roles.add(role);
|
|
2862
3046
|
if (reasons.has("runtime-metadata"))
|
|
2863
3047
|
actions.add("restart-builder");
|
|
2864
3048
|
if (reasons.size > 0)
|
|
2865
|
-
reasonByFile[
|
|
3049
|
+
reasonByFile[path13.resolve(file)] = [...reasons].sort();
|
|
2866
3050
|
}
|
|
2867
3051
|
if (roles.has("barrel"))
|
|
2868
3052
|
actions.add("sync-generated");
|
|
@@ -2883,12 +3067,12 @@ class DevChangePlanner {
|
|
|
2883
3067
|
}
|
|
2884
3068
|
#rolesForFile(file, { isGenerated, reasons }) {
|
|
2885
3069
|
const roles = new Set;
|
|
2886
|
-
const abs =
|
|
2887
|
-
const base =
|
|
2888
|
-
const ext =
|
|
3070
|
+
const abs = path13.resolve(file);
|
|
3071
|
+
const base = path13.basename(abs);
|
|
3072
|
+
const ext = path13.extname(abs).toLowerCase();
|
|
2889
3073
|
const isSource = SOURCE_EXTS.has(ext);
|
|
2890
|
-
const rel =
|
|
2891
|
-
const parts = rel.split(
|
|
3074
|
+
const rel = path13.relative(this.#workspaceRoot, abs);
|
|
3075
|
+
const parts = rel.split(path13.sep).filter(Boolean);
|
|
2892
3076
|
if (CONFIG_BASENAMES.has(base)) {
|
|
2893
3077
|
roles.add("config");
|
|
2894
3078
|
reasons.add("config-file");
|
|
@@ -2959,17 +3143,17 @@ class DevChangePlanner {
|
|
|
2959
3143
|
return true;
|
|
2960
3144
|
}
|
|
2961
3145
|
#isWorkspaceSource(rel) {
|
|
2962
|
-
if (!rel || rel.startsWith("..") ||
|
|
3146
|
+
if (!rel || rel.startsWith("..") || path13.isAbsolute(rel))
|
|
2963
3147
|
return false;
|
|
2964
|
-
const [scope] = rel.split(
|
|
3148
|
+
const [scope] = rel.split(path13.sep);
|
|
2965
3149
|
return scope === "apps" || scope === "libs" || scope === "pkgs";
|
|
2966
3150
|
}
|
|
2967
3151
|
}
|
|
2968
|
-
var uniqueResolved = (files) => [...new Set(files.map((file) =>
|
|
3152
|
+
var uniqueResolved = (files) => [...new Set(files.map((file) => path13.resolve(file)))].sort();
|
|
2969
3153
|
|
|
2970
3154
|
// pkgs/@akanjs/devkit/frontendBuild/devGeneratedIndexSync.ts
|
|
2971
3155
|
import { mkdir as mkdir4, readdir as readdir3, readFile as readFile2, rm as rm2, stat as stat2 } from "fs/promises";
|
|
2972
|
-
import
|
|
3156
|
+
import path14 from "path";
|
|
2973
3157
|
import { capitalize } from "akanjs/common";
|
|
2974
3158
|
var BARREL_FACETS2 = new Set(["common", "srvkit", "ui", "webkit", "plugin"]);
|
|
2975
3159
|
var FACET_SOURCE_FILE_RE = /\.(ts|tsx)$/;
|
|
@@ -2983,7 +3167,7 @@ var SCALAR_UI_TYPES = ["Template", "Unit"];
|
|
|
2983
3167
|
class DevGeneratedIndexSync {
|
|
2984
3168
|
#workspaceRoot;
|
|
2985
3169
|
constructor({ workspaceRoot }) {
|
|
2986
|
-
this.#workspaceRoot =
|
|
3170
|
+
this.#workspaceRoot = path14.resolve(workspaceRoot);
|
|
2987
3171
|
}
|
|
2988
3172
|
async syncForBatch(files) {
|
|
2989
3173
|
const indexPaths = new Set;
|
|
@@ -3012,11 +3196,11 @@ class DevGeneratedIndexSync {
|
|
|
3012
3196
|
return { changedFiles, errors };
|
|
3013
3197
|
}
|
|
3014
3198
|
#facetIndexFor(file) {
|
|
3015
|
-
const abs =
|
|
3016
|
-
const rel =
|
|
3017
|
-
if (rel.startsWith("..") ||
|
|
3199
|
+
const abs = path14.resolve(file);
|
|
3200
|
+
const rel = path14.relative(this.#workspaceRoot, abs);
|
|
3201
|
+
if (rel.startsWith("..") || path14.isAbsolute(rel))
|
|
3018
3202
|
return null;
|
|
3019
|
-
const parts = rel.split(
|
|
3203
|
+
const parts = rel.split(path14.sep).filter(Boolean);
|
|
3020
3204
|
if (parts.length < 4)
|
|
3021
3205
|
return null;
|
|
3022
3206
|
const [scope, project, facet, child] = parts;
|
|
@@ -3024,32 +3208,32 @@ class DevGeneratedIndexSync {
|
|
|
3024
3208
|
return null;
|
|
3025
3209
|
if (!child || child.startsWith(".") || child === "index.ts" || child === "index.tsx")
|
|
3026
3210
|
return null;
|
|
3027
|
-
return
|
|
3211
|
+
return path14.join(this.#workspaceRoot, scope, project, facet, "index.ts");
|
|
3028
3212
|
}
|
|
3029
3213
|
async#moduleIndexForDirectoryEvent(file) {
|
|
3030
|
-
const abs =
|
|
3031
|
-
const rel =
|
|
3032
|
-
if (rel.startsWith("..") ||
|
|
3214
|
+
const abs = path14.resolve(file);
|
|
3215
|
+
const rel = path14.relative(this.#workspaceRoot, abs);
|
|
3216
|
+
if (rel.startsWith("..") || path14.isAbsolute(rel))
|
|
3033
3217
|
return null;
|
|
3034
|
-
const parts = rel.split(
|
|
3218
|
+
const parts = rel.split(path14.sep).filter(Boolean);
|
|
3035
3219
|
if (parts.length !== 4 && parts.length !== 5)
|
|
3036
3220
|
return null;
|
|
3037
3221
|
const [scope, project, libSegment, moduleSegment, scalarSegment] = parts;
|
|
3038
3222
|
if (scope !== "apps" && scope !== "libs" || !project || libSegment !== "lib")
|
|
3039
3223
|
return null;
|
|
3040
3224
|
const isExistingDirectory = await stat2(abs).then((s) => s.isDirectory()).catch(() => false);
|
|
3041
|
-
const looksLikeDeletedDirectory = !
|
|
3225
|
+
const looksLikeDeletedDirectory = !path14.extname(abs);
|
|
3042
3226
|
if (!isExistingDirectory && !looksLikeDeletedDirectory)
|
|
3043
3227
|
return null;
|
|
3044
3228
|
if (moduleSegment === "__scalar" && scalarSegment) {
|
|
3045
|
-
return
|
|
3229
|
+
return path14.join(this.#workspaceRoot, scope, project, "lib", "__scalar", scalarSegment, "index.ts");
|
|
3046
3230
|
}
|
|
3047
3231
|
if (!moduleSegment || moduleSegment === "__scalar")
|
|
3048
3232
|
return null;
|
|
3049
|
-
return
|
|
3233
|
+
return path14.join(this.#workspaceRoot, scope, project, "lib", moduleSegment, "index.ts");
|
|
3050
3234
|
}
|
|
3051
3235
|
async#syncIndex(indexPath) {
|
|
3052
|
-
const dir =
|
|
3236
|
+
const dir = path14.dirname(indexPath);
|
|
3053
3237
|
const content = await this.#contentForIndex(indexPath);
|
|
3054
3238
|
if (content === null) {
|
|
3055
3239
|
if (!await exists(indexPath))
|
|
@@ -3065,14 +3249,14 @@ class DevGeneratedIndexSync {
|
|
|
3065
3249
|
return true;
|
|
3066
3250
|
}
|
|
3067
3251
|
async#contentForIndex(indexPath) {
|
|
3068
|
-
const parts =
|
|
3252
|
+
const parts = path14.relative(this.#workspaceRoot, indexPath).split(path14.sep).filter(Boolean);
|
|
3069
3253
|
const facet = parts.at(-2);
|
|
3070
3254
|
if (facet && BARREL_FACETS2.has(facet))
|
|
3071
|
-
return this.#facetContent(
|
|
3072
|
-
return this.#moduleContent(
|
|
3255
|
+
return this.#facetContent(path14.dirname(indexPath));
|
|
3256
|
+
return this.#moduleContent(path14.dirname(indexPath));
|
|
3073
3257
|
}
|
|
3074
3258
|
async#facetContent(dir) {
|
|
3075
|
-
const nameCasePattern =
|
|
3259
|
+
const nameCasePattern = path14.basename(dir) === "ui" ? FACET_PASCAL_CASE_RE : FACET_CAMEL_CASE_RE;
|
|
3076
3260
|
const entries = await readdir3(dir, { withFileTypes: true }).catch(() => null);
|
|
3077
3261
|
if (!entries)
|
|
3078
3262
|
return null;
|
|
@@ -3097,8 +3281,8 @@ class DevGeneratedIndexSync {
|
|
|
3097
3281
|
`;
|
|
3098
3282
|
}
|
|
3099
3283
|
async#moduleContent(dir) {
|
|
3100
|
-
const rel =
|
|
3101
|
-
const parts = rel.split(
|
|
3284
|
+
const rel = path14.relative(this.#workspaceRoot, dir);
|
|
3285
|
+
const parts = rel.split(path14.sep).filter(Boolean);
|
|
3102
3286
|
const moduleSegment = parts.at(-1);
|
|
3103
3287
|
if (!moduleSegment)
|
|
3104
3288
|
return null;
|
|
@@ -3110,7 +3294,7 @@ class DevGeneratedIndexSync {
|
|
|
3110
3294
|
const allowedTypes = isScalar ? SCALAR_UI_TYPES : moduleSegment.startsWith("_") ? SERVICE_UI_TYPES : MODULE_UI_TYPES;
|
|
3111
3295
|
const fileTypes = [];
|
|
3112
3296
|
for (const type of allowedTypes) {
|
|
3113
|
-
if (await exists(
|
|
3297
|
+
if (await exists(path14.join(dir, `${modelName}.${type}.tsx`)))
|
|
3114
3298
|
fileTypes.push(type);
|
|
3115
3299
|
}
|
|
3116
3300
|
if (fileTypes.length === 0)
|
|
@@ -3145,11 +3329,11 @@ var formatError2 = (err) => err instanceof Error ? err.message : String(err);
|
|
|
3145
3329
|
|
|
3146
3330
|
// pkgs/@akanjs/devkit/frontendBuild/ssrDevBundler.ts
|
|
3147
3331
|
import { mkdir as mkdir5 } from "fs/promises";
|
|
3148
|
-
import
|
|
3332
|
+
import path16 from "path";
|
|
3149
3333
|
import { SSR_DEV_DIRNAME, SSR_DEV_ROUTE_PREFIX } from "akanjs/server/hmr/csrDevManifest";
|
|
3150
3334
|
|
|
3151
3335
|
// pkgs/@akanjs/devkit/artifact/routeSeedIndex.ts
|
|
3152
|
-
import
|
|
3336
|
+
import path15 from "path";
|
|
3153
3337
|
import { assertUniqueRoutePatterns, compareRouteSpecificity, parseRouteModuleKey } from "akanjs/common";
|
|
3154
3338
|
import {
|
|
3155
3339
|
ROUTE_SEED_INDEX_JSON
|
|
@@ -3159,7 +3343,7 @@ function computeRouteSeedIndex(pageEntries) {
|
|
|
3159
3343
|
const pagesBySegments = [];
|
|
3160
3344
|
for (const { key, moduleAbsPath, seedAbsPaths } of pageEntries) {
|
|
3161
3345
|
const parsed = parseRouteModuleKey(key);
|
|
3162
|
-
const files = [
|
|
3346
|
+
const files = [path15.resolve(moduleAbsPath), ...(seedAbsPaths ?? []).map((seed) => path15.resolve(seed))];
|
|
3163
3347
|
if (parsed.kind === "layout" || parsed.kind === "overrides") {
|
|
3164
3348
|
layoutsByPrefix.getOrInsert(parsed.routeSegments.join("/"), []).push(...files);
|
|
3165
3349
|
} else if (parsed.kind === "page") {
|
|
@@ -3192,7 +3376,7 @@ function computeRouteSeedIndex(pageEntries) {
|
|
|
3192
3376
|
return { entries: seedEntries, globalLayoutFiles };
|
|
3193
3377
|
}
|
|
3194
3378
|
function serializeRouteSeedIndexForArtifact(index, artifactDir, options = {}) {
|
|
3195
|
-
const normalizedArtifactDir =
|
|
3379
|
+
const normalizedArtifactDir = path15.resolve(artifactDir);
|
|
3196
3380
|
if (options.production)
|
|
3197
3381
|
return { entries: index.entries.map((entry) => ({ routeId: entry.routeId })) };
|
|
3198
3382
|
return {
|
|
@@ -3204,20 +3388,20 @@ function serializeRouteSeedIndexForArtifact(index, artifactDir, options = {}) {
|
|
|
3204
3388
|
};
|
|
3205
3389
|
}
|
|
3206
3390
|
async function saveRouteSeedIndex(artifactDir, index, options = {}) {
|
|
3207
|
-
const absPath =
|
|
3391
|
+
const absPath = path15.join(path15.resolve(artifactDir), ROUTE_SEED_INDEX_JSON);
|
|
3208
3392
|
await Bun.write(absPath, `${JSON.stringify(serializeRouteSeedIndexForArtifact(index, artifactDir, options), null, 2)}
|
|
3209
3393
|
`);
|
|
3210
3394
|
return absPath;
|
|
3211
3395
|
}
|
|
3212
3396
|
function serializeArtifactPath(artifactPath, artifactDir) {
|
|
3213
|
-
if (!
|
|
3397
|
+
if (!path15.isAbsolute(artifactPath))
|
|
3214
3398
|
return artifactPath;
|
|
3215
|
-
return
|
|
3399
|
+
return path15.relative(artifactDir, artifactPath).split(path15.sep).join("/");
|
|
3216
3400
|
}
|
|
3217
3401
|
|
|
3218
3402
|
// pkgs/@akanjs/devkit/frontendBuild/ssrDevBundler.ts
|
|
3219
3403
|
class SsrDevBundler extends DevRegistryBundler {
|
|
3220
|
-
static #formatVersion =
|
|
3404
|
+
static #formatVersion = 4;
|
|
3221
3405
|
static bootstrapKey = "";
|
|
3222
3406
|
reloadsOnEntryChange = false;
|
|
3223
3407
|
#discovery = null;
|
|
@@ -3230,7 +3414,16 @@ class SsrDevBundler extends DevRegistryBundler {
|
|
|
3230
3414
|
const akanConfig = await this.app.getConfig();
|
|
3231
3415
|
const define = bundleDefine(this.app, "start", "ssr");
|
|
3232
3416
|
const optimizeImports = [...akanConfig.optimizeImports];
|
|
3233
|
-
const
|
|
3417
|
+
const barrelImports = workspaceBarrels(akanConfig.barrelImports);
|
|
3418
|
+
const configKey = Bun.hash(JSON.stringify([
|
|
3419
|
+
"ssr",
|
|
3420
|
+
SsrDevBundler.#formatVersion,
|
|
3421
|
+
Bun.version,
|
|
3422
|
+
define,
|
|
3423
|
+
optimizeImports,
|
|
3424
|
+
VENDOR_SPECIFIERS,
|
|
3425
|
+
barrelImports
|
|
3426
|
+
])).toString(36);
|
|
3234
3427
|
return {
|
|
3235
3428
|
pageEntries: [],
|
|
3236
3429
|
basePaths: [...akanConfig.basePaths],
|
|
@@ -3239,16 +3432,17 @@ class SsrDevBundler extends DevRegistryBundler {
|
|
|
3239
3432
|
optimizeImports,
|
|
3240
3433
|
configKey,
|
|
3241
3434
|
refreshFile: null,
|
|
3242
|
-
externals: VENDOR_SPECIFIERS
|
|
3435
|
+
externals: VENDOR_SPECIFIERS,
|
|
3436
|
+
barrelImports
|
|
3243
3437
|
};
|
|
3244
3438
|
}
|
|
3245
3439
|
isMetadataFile(file) {
|
|
3246
|
-
return super.isMetadataFile(file) && !file.endsWith(".dictionary.ts") &&
|
|
3440
|
+
return super.isMetadataFile(file) && !file.endsWith(".dictionary.ts") && path16.basename(file) !== "dict.ts";
|
|
3247
3441
|
}
|
|
3248
3442
|
async writeEntries() {
|
|
3249
3443
|
await mkdir5(this.entryDir, { recursive: true });
|
|
3250
|
-
const file =
|
|
3251
|
-
const hasStore = await Bun.file(
|
|
3444
|
+
const file = path16.join(this.entryDir, "bootstrap.ts");
|
|
3445
|
+
const hasStore = await Bun.file(path16.join(this.app.cwdPath, "lib", "st.ts")).exists();
|
|
3252
3446
|
const source = hasStore ? StoreBootstrap.source(this.app.name) : `export {};
|
|
3253
3447
|
`;
|
|
3254
3448
|
const unchanged = await Bun.file(file).exists() && await Bun.file(file).text() === source;
|