@barefootjs/cli 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs/core/adapters/hono-adapter.md +21 -0
- package/dist/index.js +223 -107
- package/package.json +2 -2
|
@@ -197,3 +197,24 @@ Ternaries with element branches use `bf-c` markers. Text-only ternaries use comm
|
|
|
197
197
|
```
|
|
198
198
|
|
|
199
199
|
Loop markers (`<!--bf-loop-->...<!--bf-/loop-->`) are used for reconciliation. For child components in loops, the adapter generates unique instance IDs per iteration using the loop index or `key`.
|
|
200
|
+
|
|
201
|
+
## Deploying to Cloudflare Workers
|
|
202
|
+
|
|
203
|
+
`bf build` writes browser-served files (`barefoot.js`, `*.client.js`, vendor chunks) and server/build-only files (the SSR `.tsx` templates, `manifest.json`, `barefoot-externals.json`, `.bfemit.json`, `.buildcache.json`, `.dev/`) into the same `outDir`. With Workers Assets, `assets.directory` serves that whole directory, so a naive `wrangler deploy` would upload the server-only files too — shipping the SSR template source and build internals as publicly fetchable assets.
|
|
204
|
+
|
|
205
|
+
To prevent this, `bf build` maintains a [`.assetsignore`](https://developers.cloudflare.com/workers/static-assets/#ignoring-assets) in `outDir` whenever the project targets Workers (detected by a `wrangler.toml` / `wrangler.json` / `wrangler.jsonc` next to `barefoot.config.ts`). The server/build-only outputs are listed in a managed block that's regenerated on every build:
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
# >>> barefoot managed block (generated by `bf build`) >>>
|
|
209
|
+
# Server/build-only barefoot outputs — not browser-served. Regenerated on
|
|
210
|
+
# every `bf build`; add your own entries outside this block.
|
|
211
|
+
.bfemit.json
|
|
212
|
+
.buildcache.json
|
|
213
|
+
.dev/
|
|
214
|
+
barefoot-externals.json
|
|
215
|
+
components/Counter.tsx
|
|
216
|
+
components/manifest.json
|
|
217
|
+
# <<< barefoot managed block <<<
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Anything you add outside the managed markers is preserved across rebuilds. The browser-served outputs (`barefoot.js`, `*.client.js`, vendor chunks) are intentionally left out so they still deploy.
|
package/dist/index.js
CHANGED
|
@@ -1885,6 +1885,9 @@ function irToComponentTemplateWithOpts(node, opts) {
|
|
|
1885
1885
|
}
|
|
1886
1886
|
return `\${${transformExpr(node.expr, node.templateExpr)}}`;
|
|
1887
1887
|
case "conditional": {
|
|
1888
|
+
if (node.clientOnly && node.slotId) {
|
|
1889
|
+
return `<!--bf-cond-start:${node.slotId}--><!--bf-cond-end:${node.slotId}-->`;
|
|
1890
|
+
}
|
|
1888
1891
|
const trueBranch = recurse(node.whenTrue);
|
|
1889
1892
|
const falseBranch = recurse(node.whenFalse);
|
|
1890
1893
|
const trueHtml = node.slotId ? addCondAttrToTemplate(trueBranch, node.slotId) : trueBranch;
|
|
@@ -2103,6 +2106,9 @@ function generateCsrTemplateWithOpts(node, opts) {
|
|
|
2103
2106
|
return `\${${expr}}`;
|
|
2104
2107
|
}
|
|
2105
2108
|
case "conditional": {
|
|
2109
|
+
if (node.clientOnly && node.slotId) {
|
|
2110
|
+
return `<!--bf-cond-start:${node.slotId}--><!--bf-cond-end:${node.slotId}-->`;
|
|
2111
|
+
}
|
|
2106
2112
|
const trueBranch = recurse(node.whenTrue);
|
|
2107
2113
|
const falseBranch = recurse(node.whenFalse);
|
|
2108
2114
|
const trueHtml = node.slotId ? addCondAttrToTemplate(trueBranch, node.slotId) : trueBranch;
|
|
@@ -8221,11 +8227,11 @@ function transformMapCall(node, ctx2, isClientOnly = false, method = "map") {
|
|
|
8221
8227
|
if (stmt === returnStmt) break;
|
|
8222
8228
|
const js = ctx2.getJS(stmt);
|
|
8223
8229
|
const tjs = ctx2.getTemplateJS(stmt);
|
|
8224
|
-
const
|
|
8230
|
+
const ts20 = stmt.getText(ctx2.sourceFile);
|
|
8225
8231
|
preambleStmts.push(js.endsWith(";") ? js : js + ";");
|
|
8226
8232
|
templatePreambleStmts.push(tjs.endsWith(";") ? tjs : tjs + ";");
|
|
8227
|
-
typedPreambleStmts.push(
|
|
8228
|
-
if (js !==
|
|
8233
|
+
typedPreambleStmts.push(ts20.endsWith(";") ? ts20 : ts20 + ";");
|
|
8234
|
+
if (js !== ts20) hasTypeDiff = true;
|
|
8229
8235
|
if (js !== tjs) hasTemplateDiff = true;
|
|
8230
8236
|
}
|
|
8231
8237
|
if (preambleStmts.length > 0) {
|
|
@@ -9033,10 +9039,10 @@ function hasDynamicContent(children) {
|
|
|
9033
9039
|
function inferExpressionType(_node, _ctx) {
|
|
9034
9040
|
return null;
|
|
9035
9041
|
}
|
|
9036
|
-
function replaceBranchLocalRefs(text, branchNames,
|
|
9042
|
+
function replaceBranchLocalRefs(text, branchNames, resolve11) {
|
|
9037
9043
|
if (branchNames.length === 0) return text;
|
|
9038
9044
|
const pattern = new RegExp(`(?<![\\w$])(${branchNames.join("|")})(?![\\w$])`, "g");
|
|
9039
|
-
return replaceInExprContexts(text, pattern, (_match, name) =>
|
|
9045
|
+
return replaceInExprContexts(text, pattern, (_match, name) => resolve11(name));
|
|
9040
9046
|
}
|
|
9041
9047
|
function buildIfStatementChain(analyzer, ctx2) {
|
|
9042
9048
|
const conditionalReturns = analyzer.conditionalReturns;
|
|
@@ -17503,7 +17509,7 @@ function buildLocalFunctionSetterMap(meta, setterToSignal) {
|
|
|
17503
17509
|
}
|
|
17504
17510
|
directCalls.set(name, calls);
|
|
17505
17511
|
}
|
|
17506
|
-
const
|
|
17512
|
+
const resolve11 = (name, stack) => {
|
|
17507
17513
|
const out = [];
|
|
17508
17514
|
const seen = /* @__PURE__ */ new Set();
|
|
17509
17515
|
for (const setter of directSetters.get(name) ?? []) {
|
|
@@ -17514,7 +17520,7 @@ function buildLocalFunctionSetterMap(meta, setterToSignal) {
|
|
|
17514
17520
|
}
|
|
17515
17521
|
for (const callee of directCalls.get(name) ?? []) {
|
|
17516
17522
|
if (stack.has(callee)) continue;
|
|
17517
|
-
const sub2 =
|
|
17523
|
+
const sub2 = resolve11(callee, /* @__PURE__ */ new Set([...stack, callee]));
|
|
17518
17524
|
for (const r of sub2) {
|
|
17519
17525
|
if (!seen.has(r.setter)) {
|
|
17520
17526
|
out.push({ setter: r.setter, chain: [callee, ...r.chain] });
|
|
@@ -17526,7 +17532,7 @@ function buildLocalFunctionSetterMap(meta, setterToSignal) {
|
|
|
17526
17532
|
};
|
|
17527
17533
|
const result = /* @__PURE__ */ new Map();
|
|
17528
17534
|
for (const name of bodies.keys()) {
|
|
17529
|
-
const resolved =
|
|
17535
|
+
const resolved = resolve11(name, /* @__PURE__ */ new Set([name]));
|
|
17530
17536
|
if (resolved.length > 0) result.set(name, resolved);
|
|
17531
17537
|
}
|
|
17532
17538
|
return result;
|
|
@@ -19461,9 +19467,78 @@ var init_emit_ledger = __esm({
|
|
|
19461
19467
|
}
|
|
19462
19468
|
});
|
|
19463
19469
|
|
|
19470
|
+
// src/lib/assets-ignore.ts
|
|
19471
|
+
import { resolve as resolve5 } from "node:path";
|
|
19472
|
+
async function isCloudflareWorkersProject(projectDir) {
|
|
19473
|
+
for (const name of WRANGLER_CONFIG_NAMES) {
|
|
19474
|
+
if (await fileExists(resolve5(projectDir, name))) return true;
|
|
19475
|
+
}
|
|
19476
|
+
return false;
|
|
19477
|
+
}
|
|
19478
|
+
function collectServerOnlyAssets(input) {
|
|
19479
|
+
const entries = /* @__PURE__ */ new Set();
|
|
19480
|
+
entries.add(`${input.devSentinelSubdir}/`);
|
|
19481
|
+
entries.add(EMIT_LEDGER_FILENAME);
|
|
19482
|
+
entries.add(CACHE_FILENAME);
|
|
19483
|
+
if (input.hasExternals) entries.add("barefoot-externals.json");
|
|
19484
|
+
if (!input.clientOnly) {
|
|
19485
|
+
entries.add(`${input.templatesSubdir}/manifest.json`);
|
|
19486
|
+
for (const row of Object.values(input.manifest)) {
|
|
19487
|
+
if (row.markedTemplate) entries.add(row.markedTemplate);
|
|
19488
|
+
}
|
|
19489
|
+
}
|
|
19490
|
+
return [...entries].sort();
|
|
19491
|
+
}
|
|
19492
|
+
function stripManagedBlock(content) {
|
|
19493
|
+
const lines = content.split("\n");
|
|
19494
|
+
const begin = lines.indexOf(BLOCK_BEGIN);
|
|
19495
|
+
const end = lines.indexOf(BLOCK_END);
|
|
19496
|
+
if (begin !== -1 && end !== -1 && end > begin) {
|
|
19497
|
+
const kept = [...lines.slice(0, begin), ...lines.slice(end + 1)];
|
|
19498
|
+
return kept.join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
19499
|
+
}
|
|
19500
|
+
return content.trim();
|
|
19501
|
+
}
|
|
19502
|
+
function buildManagedBlock(entries) {
|
|
19503
|
+
return [
|
|
19504
|
+
BLOCK_BEGIN,
|
|
19505
|
+
"# Server/build-only barefoot outputs \u2014 not browser-served. Regenerated on",
|
|
19506
|
+
"# every `bf build`; add your own entries outside this block.",
|
|
19507
|
+
...entries,
|
|
19508
|
+
BLOCK_END
|
|
19509
|
+
].join("\n");
|
|
19510
|
+
}
|
|
19511
|
+
async function writeAssetsIgnore(outDir, entries) {
|
|
19512
|
+
const path23 = resolve5(outDir, ASSETS_IGNORE_FILENAME);
|
|
19513
|
+
const existing = await fileExists(path23) ? await readText(path23) : "";
|
|
19514
|
+
const userContent = stripManagedBlock(existing);
|
|
19515
|
+
const block = buildManagedBlock(entries);
|
|
19516
|
+
const merged = userContent.length > 0 ? `${userContent}
|
|
19517
|
+
|
|
19518
|
+
${block}
|
|
19519
|
+
` : `${block}
|
|
19520
|
+
`;
|
|
19521
|
+
return writeIfChanged(path23, merged);
|
|
19522
|
+
}
|
|
19523
|
+
var ASSETS_IGNORE_FILENAME, BLOCK_BEGIN, BLOCK_END, WRANGLER_CONFIG_NAMES;
|
|
19524
|
+
var init_assets_ignore = __esm({
|
|
19525
|
+
"src/lib/assets-ignore.ts"() {
|
|
19526
|
+
"use strict";
|
|
19527
|
+
init_runtime();
|
|
19528
|
+
init_fs_utils();
|
|
19529
|
+
init_build_cache();
|
|
19530
|
+
init_emit_ledger();
|
|
19531
|
+
ASSETS_IGNORE_FILENAME = ".assetsignore";
|
|
19532
|
+
BLOCK_BEGIN = "# >>> barefoot managed block (generated by `bf build`) >>>";
|
|
19533
|
+
BLOCK_END = "# <<< barefoot managed block <<<";
|
|
19534
|
+
WRANGLER_CONFIG_NAMES = ["wrangler.toml", "wrangler.json", "wrangler.jsonc"];
|
|
19535
|
+
}
|
|
19536
|
+
});
|
|
19537
|
+
|
|
19464
19538
|
// src/lib/build.ts
|
|
19539
|
+
import ts19 from "typescript";
|
|
19465
19540
|
import { mkdir, readdir, stat, unlink } from "node:fs/promises";
|
|
19466
|
-
import { resolve as
|
|
19541
|
+
import { resolve as resolve6, basename, relative as relative2, dirname as dirname3, isAbsolute as isAbsolute2 } from "node:path";
|
|
19467
19542
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
19468
19543
|
import { build as esbuildBuild } from "esbuild";
|
|
19469
19544
|
function detectMissingUseClient(content) {
|
|
@@ -19503,7 +19578,7 @@ async function discoverComponentFiles(dir, options) {
|
|
|
19503
19578
|
return results;
|
|
19504
19579
|
}
|
|
19505
19580
|
for (const entry of entries) {
|
|
19506
|
-
const fullPath =
|
|
19581
|
+
const fullPath = resolve6(dir, String(entry.name));
|
|
19507
19582
|
if (entry.isDirectory()) {
|
|
19508
19583
|
if (skipDirs?.has(String(entry.name))) continue;
|
|
19509
19584
|
results.push(...await discoverComponentFiles(fullPath, options));
|
|
@@ -19518,9 +19593,9 @@ function generateHash(content) {
|
|
|
19518
19593
|
}
|
|
19519
19594
|
function resolveBuildConfigFromTs(projectDir, tsConfig, overrides) {
|
|
19520
19595
|
const componentDirs = (tsConfig.components ?? ["components"]).map(
|
|
19521
|
-
(dir) =>
|
|
19596
|
+
(dir) => resolve6(projectDir, dir)
|
|
19522
19597
|
);
|
|
19523
|
-
const outDir =
|
|
19598
|
+
const outDir = resolve6(projectDir, tsConfig.outDir ?? "dist");
|
|
19524
19599
|
return {
|
|
19525
19600
|
projectDir,
|
|
19526
19601
|
adapter: tsConfig.adapter,
|
|
@@ -19535,7 +19610,7 @@ function resolveBuildConfigFromTs(projectDir, tsConfig, overrides) {
|
|
|
19535
19610
|
externals: tsConfig.externals,
|
|
19536
19611
|
externalsBasePath: tsConfig.externalsBasePath,
|
|
19537
19612
|
bundleEntries: tsConfig.bundleEntries?.map((e) => ({
|
|
19538
|
-
entry:
|
|
19613
|
+
entry: resolve6(projectDir, e.entry),
|
|
19539
19614
|
outfile: e.outfile,
|
|
19540
19615
|
externals: e.externals
|
|
19541
19616
|
})),
|
|
@@ -19545,9 +19620,9 @@ function resolveBuildConfigFromTs(projectDir, tsConfig, overrides) {
|
|
|
19545
19620
|
async function findCliPackageJson() {
|
|
19546
19621
|
const here = dirname3(fileURLToPath2(import.meta.url));
|
|
19547
19622
|
const candidates = [
|
|
19548
|
-
|
|
19623
|
+
resolve6(here, "../package.json"),
|
|
19549
19624
|
// bundled dist/index.js
|
|
19550
|
-
|
|
19625
|
+
resolve6(here, "../../package.json")
|
|
19551
19626
|
// source src/lib/build.ts
|
|
19552
19627
|
];
|
|
19553
19628
|
for (const cand of candidates) {
|
|
@@ -19559,7 +19634,7 @@ async function findNearestLockfile(projectDir) {
|
|
|
19559
19634
|
let dir = projectDir;
|
|
19560
19635
|
while (true) {
|
|
19561
19636
|
for (const name of LOCKFILE_NAMES) {
|
|
19562
|
-
const candidate =
|
|
19637
|
+
const candidate = resolve6(dir, name);
|
|
19563
19638
|
if (await fileExists(candidate)) return candidate;
|
|
19564
19639
|
}
|
|
19565
19640
|
const parent = dirname3(dir);
|
|
@@ -19580,9 +19655,9 @@ async function computeGlobalHash(config) {
|
|
|
19580
19655
|
parts.push(await readText(cliPkgPath));
|
|
19581
19656
|
}
|
|
19582
19657
|
const configCandidates = [
|
|
19583
|
-
|
|
19584
|
-
|
|
19585
|
-
|
|
19658
|
+
resolve6(config.projectDir, "barefoot.config.ts"),
|
|
19659
|
+
resolve6(config.projectDir, "barefoot.config.js"),
|
|
19660
|
+
resolve6(config.projectDir, "barefoot.config.mjs")
|
|
19586
19661
|
];
|
|
19587
19662
|
for (const cand of configCandidates) {
|
|
19588
19663
|
if (await fileExists(cand)) {
|
|
@@ -19603,9 +19678,9 @@ async function build(config, options = {}) {
|
|
|
19603
19678
|
const templatesSubdir = layout?.templates ?? "components";
|
|
19604
19679
|
const clientJsSubdir = layout?.clientJs ?? "components";
|
|
19605
19680
|
const runtimeSubdir = layout?.runtime ?? clientJsSubdir;
|
|
19606
|
-
const templatesOutDir =
|
|
19607
|
-
const clientJsOutDir =
|
|
19608
|
-
const runtimeOutDir =
|
|
19681
|
+
const templatesOutDir = resolve6(config.outDir, templatesSubdir);
|
|
19682
|
+
const clientJsOutDir = resolve6(config.outDir, clientJsSubdir);
|
|
19683
|
+
const runtimeOutDir = resolve6(config.outDir, runtimeSubdir);
|
|
19609
19684
|
await Promise.all([
|
|
19610
19685
|
mkdir(templatesOutDir, { recursive: true }),
|
|
19611
19686
|
mkdir(clientJsOutDir, { recursive: true }),
|
|
@@ -19619,14 +19694,14 @@ async function build(config, options = {}) {
|
|
|
19619
19694
|
let anyOutputChanged = false;
|
|
19620
19695
|
const loadedLedger = await loadEmitLedger(config.outDir, config.projectDir);
|
|
19621
19696
|
const previousEmitEntries = loadedLedger?.entries ?? extractLedgerFromCache(onDiskCache);
|
|
19622
|
-
const domPkgDir =
|
|
19697
|
+
const domPkgDir = resolve6(config.projectDir, "node_modules/@barefootjs/client");
|
|
19623
19698
|
const domDistCandidates = [
|
|
19624
|
-
|
|
19625
|
-
|
|
19699
|
+
resolve6(config.projectDir, "../../packages/client/dist/runtime/standalone.js"),
|
|
19700
|
+
resolve6(domPkgDir, "dist/runtime/standalone.js"),
|
|
19626
19701
|
// Legacy fallback for older @barefootjs/client dists that only shipped
|
|
19627
19702
|
// the single runtime entry.
|
|
19628
|
-
|
|
19629
|
-
|
|
19703
|
+
resolve6(config.projectDir, "../../packages/client/dist/runtime/index.js"),
|
|
19704
|
+
resolve6(domPkgDir, "dist/runtime/index.js")
|
|
19630
19705
|
];
|
|
19631
19706
|
let domDistFile = null;
|
|
19632
19707
|
for (const candidate of domDistCandidates) {
|
|
@@ -19638,7 +19713,7 @@ async function build(config, options = {}) {
|
|
|
19638
19713
|
}
|
|
19639
19714
|
}
|
|
19640
19715
|
if (domDistFile) {
|
|
19641
|
-
const runtimeOutPath =
|
|
19716
|
+
const runtimeOutPath = resolve6(runtimeOutDir, "barefoot.js");
|
|
19642
19717
|
let runtimeContent;
|
|
19643
19718
|
if (config.minify) {
|
|
19644
19719
|
runtimeContent = transpile(await readText(domDistFile), { loader: "js", minify: true });
|
|
@@ -19811,9 +19886,9 @@ async function build(config, options = {}) {
|
|
|
19811
19886
|
if (!currentEmitSet.has(output)) orphanedOutputs.add(output);
|
|
19812
19887
|
}
|
|
19813
19888
|
}
|
|
19814
|
-
const outDirAbs =
|
|
19889
|
+
const outDirAbs = resolve6(config.outDir);
|
|
19815
19890
|
for (const output of orphanedOutputs) {
|
|
19816
|
-
const abs =
|
|
19891
|
+
const abs = resolve6(config.outDir, output);
|
|
19817
19892
|
const rel = relative2(outDirAbs, abs);
|
|
19818
19893
|
const escapes = rel === "" || rel === "." || rel.startsWith("..") || isAbsolute2(rel);
|
|
19819
19894
|
if (escapes) {
|
|
@@ -19841,7 +19916,7 @@ async function build(config, options = {}) {
|
|
|
19841
19916
|
if (!entry.clientJs) continue;
|
|
19842
19917
|
let raw = compiledClientJsByKey.get(name);
|
|
19843
19918
|
if (!raw) {
|
|
19844
|
-
const filePath =
|
|
19919
|
+
const filePath = resolve6(config.outDir, entry.clientJs);
|
|
19845
19920
|
try {
|
|
19846
19921
|
raw = await readText(filePath);
|
|
19847
19922
|
} catch {
|
|
@@ -19856,7 +19931,7 @@ async function build(config, options = {}) {
|
|
|
19856
19931
|
for (const [name, content] of combined) {
|
|
19857
19932
|
const entry = manifest[name];
|
|
19858
19933
|
if (!entry?.clientJs) continue;
|
|
19859
|
-
const filePath =
|
|
19934
|
+
const filePath = resolve6(config.outDir, entry.clientJs);
|
|
19860
19935
|
if (await writeIfChanged(filePath, content)) {
|
|
19861
19936
|
anyOutputChanged = true;
|
|
19862
19937
|
console.log(`Combined: ${entry.clientJs}`);
|
|
@@ -19909,10 +19984,10 @@ async function build(config, options = {}) {
|
|
|
19909
19984
|
}
|
|
19910
19985
|
}
|
|
19911
19986
|
{
|
|
19912
|
-
const runtimeAbs =
|
|
19987
|
+
const runtimeAbs = resolve6(config.outDir, runtimeSubdir, "barefoot.js");
|
|
19913
19988
|
for (const [name, entry] of Object.entries(manifest)) {
|
|
19914
19989
|
if (!entry.clientJs || name === "__barefoot__") continue;
|
|
19915
|
-
const filePath =
|
|
19990
|
+
const filePath = resolve6(config.outDir, entry.clientJs);
|
|
19916
19991
|
let rel = relative2(dirname3(filePath), runtimeAbs);
|
|
19917
19992
|
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
19918
19993
|
try {
|
|
@@ -19935,7 +20010,7 @@ async function build(config, options = {}) {
|
|
|
19935
20010
|
if (config.minify) {
|
|
19936
20011
|
for (const [name, entry] of Object.entries(manifest)) {
|
|
19937
20012
|
if (!entry.clientJs || name === "__barefoot__") continue;
|
|
19938
|
-
const filePath =
|
|
20013
|
+
const filePath = resolve6(config.outDir, entry.clientJs);
|
|
19939
20014
|
try {
|
|
19940
20015
|
const content = await readText(filePath);
|
|
19941
20016
|
if (content) {
|
|
@@ -19960,8 +20035,8 @@ async function build(config, options = {}) {
|
|
|
19960
20035
|
});
|
|
19961
20036
|
}
|
|
19962
20037
|
if (!config.clientOnly) {
|
|
19963
|
-
const manifestDir =
|
|
19964
|
-
const manifestPath =
|
|
20038
|
+
const manifestDir = resolve6(config.outDir, templatesSubdir);
|
|
20039
|
+
const manifestPath = resolve6(manifestDir, "manifest.json");
|
|
19965
20040
|
const manifestContent = JSON.stringify(manifest, null, 2);
|
|
19966
20041
|
if (await writeIfChanged(manifestPath, manifestContent)) {
|
|
19967
20042
|
anyOutputChanged = true;
|
|
@@ -19989,6 +20064,18 @@ async function build(config, options = {}) {
|
|
|
19989
20064
|
saveCache(config.outDir, nextCache),
|
|
19990
20065
|
saveEmitLedger(config.outDir, config.projectDir, nextLedger)
|
|
19991
20066
|
]);
|
|
20067
|
+
if (await isCloudflareWorkersProject(config.projectDir)) {
|
|
20068
|
+
const ignored = collectServerOnlyAssets({
|
|
20069
|
+
devSentinelSubdir: DEV_SENTINEL_SUBDIR,
|
|
20070
|
+
templatesSubdir,
|
|
20071
|
+
manifest,
|
|
20072
|
+
hasExternals: !!config.externals && Object.keys(config.externals).length > 0,
|
|
20073
|
+
clientOnly: config.clientOnly
|
|
20074
|
+
});
|
|
20075
|
+
if (await writeAssetsIgnore(config.outDir, ignored)) {
|
|
20076
|
+
console.log(`Generated: ${ASSETS_IGNORE_FILENAME}`);
|
|
20077
|
+
}
|
|
20078
|
+
}
|
|
19992
20079
|
return {
|
|
19993
20080
|
compiledCount,
|
|
19994
20081
|
skippedCount,
|
|
@@ -19999,6 +20086,28 @@ async function build(config, options = {}) {
|
|
|
19999
20086
|
sharedProgram
|
|
20000
20087
|
};
|
|
20001
20088
|
}
|
|
20089
|
+
function extractBareImports(code) {
|
|
20090
|
+
const { importedFiles } = ts19.preProcessFile(code, true, true);
|
|
20091
|
+
const specifiers = /* @__PURE__ */ new Set();
|
|
20092
|
+
for (const { fileName } of importedFiles) {
|
|
20093
|
+
if (!fileName.startsWith(".") && !fileName.startsWith("/") && !fileName.includes("://")) {
|
|
20094
|
+
specifiers.add(fileName);
|
|
20095
|
+
}
|
|
20096
|
+
}
|
|
20097
|
+
return [...specifiers];
|
|
20098
|
+
}
|
|
20099
|
+
function unresolvedBareImports(code, externals) {
|
|
20100
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(externals), ...BF_CLIENT_DEDUP_KEYS]);
|
|
20101
|
+
const isResolved = (spec) => keys.has(spec) || [...keys].some((k) => k.endsWith("/") && spec.startsWith(k));
|
|
20102
|
+
return extractBareImports(code).filter((spec) => !isResolved(spec));
|
|
20103
|
+
}
|
|
20104
|
+
function rebundleExternalsFor(pkgName, externals) {
|
|
20105
|
+
return [.../* @__PURE__ */ new Set([
|
|
20106
|
+
...Object.keys(externals).filter((k) => k !== pkgName),
|
|
20107
|
+
...BF_CLIENT_DEDUP_KEYS,
|
|
20108
|
+
"@barefootjs/client/*"
|
|
20109
|
+
])];
|
|
20110
|
+
}
|
|
20002
20111
|
function vendorChunkFilename(pkgName) {
|
|
20003
20112
|
const base = pkgName.includes("/") ? pkgName.split("/").pop() : pkgName;
|
|
20004
20113
|
return `${base}.js`;
|
|
@@ -20007,7 +20116,7 @@ function effectiveNamesFor(entryPath, componentDirs) {
|
|
|
20007
20116
|
const bn = basename(entryPath);
|
|
20008
20117
|
if (componentDirs && componentDirs.length > 0) {
|
|
20009
20118
|
for (const dir of componentDirs) {
|
|
20010
|
-
const root =
|
|
20119
|
+
const root = resolve6(dir);
|
|
20011
20120
|
if (entryPath !== root && entryPath.startsWith(root + "/")) {
|
|
20012
20121
|
const rel = entryPath.slice(root.length + 1);
|
|
20013
20122
|
const noExt2 = rel.replace(/\.[^.]+$/, "");
|
|
@@ -20021,14 +20130,14 @@ function effectiveNamesFor(entryPath, componentDirs) {
|
|
|
20021
20130
|
function buildRelativeImportRewriter(sourcePath, outputPath, componentDirs, templatesOutDir) {
|
|
20022
20131
|
const sourceDir = dirname3(sourcePath);
|
|
20023
20132
|
const outputDir = dirname3(outputPath);
|
|
20024
|
-
const resolvedComponentDirs = componentDirs.map((d) =>
|
|
20133
|
+
const resolvedComponentDirs = componentDirs.map((d) => resolve6(d));
|
|
20025
20134
|
return (importPath) => {
|
|
20026
|
-
const srcAbs =
|
|
20135
|
+
const srcAbs = resolve6(sourceDir, importPath);
|
|
20027
20136
|
let targetAbs = srcAbs;
|
|
20028
20137
|
for (const componentDir of resolvedComponentDirs) {
|
|
20029
20138
|
if (srcAbs === componentDir || srcAbs.startsWith(componentDir + "/")) {
|
|
20030
20139
|
const relUnderComponentDir = srcAbs.slice(componentDir.length + 1);
|
|
20031
|
-
targetAbs = relUnderComponentDir ?
|
|
20140
|
+
targetAbs = relUnderComponentDir ? resolve6(templatesOutDir, relUnderComponentDir) : templatesOutDir;
|
|
20032
20141
|
break;
|
|
20033
20142
|
}
|
|
20034
20143
|
}
|
|
@@ -20081,7 +20190,7 @@ function mergeDuplicateNamedImports(content) {
|
|
|
20081
20190
|
return out.join("\n");
|
|
20082
20191
|
}
|
|
20083
20192
|
async function resolvePkgBrowserEntry(pkgDir) {
|
|
20084
|
-
const pkgJsonPath =
|
|
20193
|
+
const pkgJsonPath = resolve6(pkgDir, "package.json");
|
|
20085
20194
|
if (!await fileExists(pkgJsonPath)) return null;
|
|
20086
20195
|
const pkg = JSON.parse(await readText(pkgJsonPath));
|
|
20087
20196
|
const browserCandidates = [
|
|
@@ -20090,7 +20199,7 @@ async function resolvePkgBrowserEntry(pkgDir) {
|
|
|
20090
20199
|
pkg.jsdelivr
|
|
20091
20200
|
].filter((v) => typeof v === "string");
|
|
20092
20201
|
for (const rel of browserCandidates) {
|
|
20093
|
-
const abs =
|
|
20202
|
+
const abs = resolve6(pkgDir, rel);
|
|
20094
20203
|
if (await fileExists(abs)) return { path: abs, isBrowserReady: true };
|
|
20095
20204
|
}
|
|
20096
20205
|
const fallbackCandidates = [
|
|
@@ -20098,7 +20207,7 @@ async function resolvePkgBrowserEntry(pkgDir) {
|
|
|
20098
20207
|
pkg.main
|
|
20099
20208
|
].filter((v) => typeof v === "string");
|
|
20100
20209
|
for (const rel of fallbackCandidates) {
|
|
20101
|
-
const abs =
|
|
20210
|
+
const abs = resolve6(pkgDir, rel);
|
|
20102
20211
|
if (await fileExists(abs)) return { path: abs, isBrowserReady: false };
|
|
20103
20212
|
}
|
|
20104
20213
|
return null;
|
|
@@ -20121,35 +20230,41 @@ async function processExternals(config, runtimeSubdir, runtimeOutDir) {
|
|
|
20121
20230
|
continue;
|
|
20122
20231
|
}
|
|
20123
20232
|
if (isChunk) {
|
|
20124
|
-
const pkgDir =
|
|
20233
|
+
const pkgDir = resolve6(config.projectDir, "node_modules", pkgName);
|
|
20125
20234
|
const entry = await resolvePkgBrowserEntry(pkgDir);
|
|
20126
20235
|
if (!entry) {
|
|
20127
20236
|
console.warn(`Warning: externals \u2014 could not resolve browser entry for "${pkgName}". Skipping.`);
|
|
20128
20237
|
continue;
|
|
20129
20238
|
}
|
|
20130
20239
|
const wantRebundle = typeof spec === "object" && !("url" in spec) && spec.rebundle === true;
|
|
20131
|
-
if (!entry.isBrowserReady && !wantRebundle) {
|
|
20132
|
-
console.warn(
|
|
20133
|
-
`Warning: externals \u2014 "${pkgName}" resolved via import/main entry (no umd/unpkg/jsdelivr found). The copied file may contain external imports that are not browser-ready. Set rebundle: true to re-bundle it into a self-contained ESM file.`
|
|
20134
|
-
);
|
|
20135
|
-
}
|
|
20136
20240
|
const srcFile = entry.path;
|
|
20137
20241
|
const filename = vendorChunkFilename(pkgName);
|
|
20138
|
-
const destPath =
|
|
20242
|
+
const destPath = resolve6(runtimeOutDir, filename);
|
|
20139
20243
|
if (wantRebundle) {
|
|
20140
20244
|
await esbuildBuild({
|
|
20141
20245
|
entryPoints: [srcFile],
|
|
20142
20246
|
outfile: destPath,
|
|
20143
20247
|
format: "esm",
|
|
20144
20248
|
bundle: true,
|
|
20145
|
-
minify: config.minify ?? false
|
|
20249
|
+
minify: config.minify ?? false,
|
|
20250
|
+
external: rebundleExternalsFor(pkgName, config.externals)
|
|
20146
20251
|
});
|
|
20147
20252
|
anyChanged = true;
|
|
20148
20253
|
console.log(`Generated (bundled): ${runtimeSubdir}/${filename}`);
|
|
20149
20254
|
} else {
|
|
20150
|
-
|
|
20255
|
+
const bytes = await readBytes(srcFile);
|
|
20256
|
+
const text = new TextDecoder().decode(bytes);
|
|
20257
|
+
if (!entry.isBrowserReady) {
|
|
20258
|
+
const unresolved = unresolvedBareImports(text, config.externals);
|
|
20259
|
+
if (unresolved.length > 0) {
|
|
20260
|
+
console.warn(
|
|
20261
|
+
`Warning: externals \u2014 "${pkgName}" resolved via import/main entry (no umd/unpkg/jsdelivr found) and imports packages not in the importmap: ${unresolved.join(", ")}. These are not browser-ready. Set rebundle: true to re-bundle it into a self-contained ESM file.`
|
|
20262
|
+
);
|
|
20263
|
+
}
|
|
20264
|
+
}
|
|
20265
|
+
let content = bytes;
|
|
20151
20266
|
if (config.minify) {
|
|
20152
|
-
content = transpile(
|
|
20267
|
+
content = transpile(text, { loader: "js", minify: true });
|
|
20153
20268
|
}
|
|
20154
20269
|
if (await writeIfChanged(destPath, content)) {
|
|
20155
20270
|
anyChanged = true;
|
|
@@ -20174,7 +20289,7 @@ async function processExternals(config, runtimeSubdir, runtimeOutDir) {
|
|
|
20174
20289
|
preloads,
|
|
20175
20290
|
externals: allExternals
|
|
20176
20291
|
};
|
|
20177
|
-
const manifestPath =
|
|
20292
|
+
const manifestPath = resolve6(config.outDir, "barefoot-externals.json");
|
|
20178
20293
|
if (await writeIfChanged(manifestPath, JSON.stringify(manifest, null, 2))) {
|
|
20179
20294
|
anyChanged = true;
|
|
20180
20295
|
console.log("Generated: barefoot-externals.json");
|
|
@@ -20186,8 +20301,8 @@ async function processBundleEntries(config, clientJsOutDir, clientJsSubdir, allE
|
|
|
20186
20301
|
let anyChanged = false;
|
|
20187
20302
|
for (const entry of config.bundleEntries) {
|
|
20188
20303
|
const entryExternals = [...allExternals, ...entry.externals ?? []];
|
|
20189
|
-
const outfilePath =
|
|
20190
|
-
const absEntry =
|
|
20304
|
+
const outfilePath = resolve6(clientJsOutDir, entry.outfile);
|
|
20305
|
+
const absEntry = resolve6(entry.entry);
|
|
20191
20306
|
const cacheKey = `${BUNDLE_KEY_PREFIX}${absEntry}`;
|
|
20192
20307
|
const sourceContent = await readText(absEntry);
|
|
20193
20308
|
const sourceHash = hashContent(sourceContent);
|
|
@@ -20227,7 +20342,7 @@ async function processBundleEntries(config, clientJsOutDir, clientJsSubdir, allE
|
|
|
20227
20342
|
if (metafile) {
|
|
20228
20343
|
for (const inputPath of Object.keys(metafile.inputs)) {
|
|
20229
20344
|
if (externalsSet.has(inputPath)) continue;
|
|
20230
|
-
const abs =
|
|
20345
|
+
const abs = resolve6(absWorkingDir, inputPath);
|
|
20231
20346
|
if (abs === absEntry) continue;
|
|
20232
20347
|
if (abs.includes("/node_modules/")) continue;
|
|
20233
20348
|
if (await fileExists(abs)) {
|
|
@@ -20252,7 +20367,7 @@ async function collectRelativeImportDeps(entryPath, sourceContent) {
|
|
|
20252
20367
|
for (const match of sourceContent.matchAll(RELATIVE_IMPORT_SCAN_RE)) {
|
|
20253
20368
|
const rel = match[1];
|
|
20254
20369
|
if (!rel.startsWith(".")) continue;
|
|
20255
|
-
const base =
|
|
20370
|
+
const base = resolve6(baseDir, rel);
|
|
20256
20371
|
const candidates = [base, ...EXT_CANDIDATES.map((ext) => base + ext)];
|
|
20257
20372
|
for (const cand of candidates) {
|
|
20258
20373
|
if (seen.has(cand)) continue;
|
|
@@ -20286,7 +20401,7 @@ async function compileEntry(args2) {
|
|
|
20286
20401
|
for (const depPath of await collectRelativeImportDeps(entryPath, sourceContent)) {
|
|
20287
20402
|
deps[depPath] = hashContent(await readText(depPath));
|
|
20288
20403
|
}
|
|
20289
|
-
const presumedOutputPath =
|
|
20404
|
+
const presumedOutputPath = resolve6(
|
|
20290
20405
|
templatesOutDir,
|
|
20291
20406
|
baseFileName.replace(/\.tsx?$/, config.adapter.extension)
|
|
20292
20407
|
);
|
|
@@ -20352,7 +20467,7 @@ async function compileEntry(args2) {
|
|
|
20352
20467
|
if (hasClientJs) {
|
|
20353
20468
|
const rel = `${clientJsSubdir}/${clientJsFilename}`;
|
|
20354
20469
|
outputs.push(rel);
|
|
20355
|
-
const target =
|
|
20470
|
+
const target = resolve6(clientJsOutDir, clientJsFilename);
|
|
20356
20471
|
await mkdir(dirname3(target), { recursive: true });
|
|
20357
20472
|
if (await writeIfChanged(target, clientJsContent)) {
|
|
20358
20473
|
wroteAny = true;
|
|
@@ -20369,7 +20484,7 @@ async function compileEntry(args2) {
|
|
|
20369
20484
|
}
|
|
20370
20485
|
const rel = `${templatesSubdir}/${outName}`;
|
|
20371
20486
|
outputs.push(rel);
|
|
20372
|
-
const target =
|
|
20487
|
+
const target = resolve6(templatesOutDir, outName);
|
|
20373
20488
|
await mkdir(dirname3(target), { recursive: true });
|
|
20374
20489
|
if (await writeIfChanged(target, outputContent)) {
|
|
20375
20490
|
wroteAny = true;
|
|
@@ -20414,9 +20529,9 @@ async function compileEntry(args2) {
|
|
|
20414
20529
|
}
|
|
20415
20530
|
async function writeBuildId(outDir, result) {
|
|
20416
20531
|
if (!result.changed) return;
|
|
20417
|
-
const devDir =
|
|
20532
|
+
const devDir = resolve6(outDir, DEV_SENTINEL_SUBDIR);
|
|
20418
20533
|
await mkdir(devDir, { recursive: true });
|
|
20419
|
-
const path23 =
|
|
20534
|
+
const path23 = resolve6(devDir, DEV_SENTINEL_FILENAME);
|
|
20420
20535
|
await writeIfChanged(path23, String(Date.now()));
|
|
20421
20536
|
}
|
|
20422
20537
|
async function watch(config, options = {}) {
|
|
@@ -20559,6 +20674,7 @@ var init_build = __esm({
|
|
|
20559
20674
|
init_build_cache();
|
|
20560
20675
|
init_emit_ledger();
|
|
20561
20676
|
init_fs_utils();
|
|
20677
|
+
init_assets_ignore();
|
|
20562
20678
|
init_runtime();
|
|
20563
20679
|
init_resolve_imports();
|
|
20564
20680
|
BF001_TRIPWIRE_IMPORTS = /* @__PURE__ */ new Set([
|
|
@@ -23875,7 +23991,7 @@ async function select(args2) {
|
|
|
23875
23991
|
output.write(`\x1B[33m?\x1B[0m \x1B[1m${args2.message}\x1B[0m
|
|
23876
23992
|
`);
|
|
23877
23993
|
render(true);
|
|
23878
|
-
return new Promise((
|
|
23994
|
+
return new Promise((resolve11, reject) => {
|
|
23879
23995
|
readline.emitKeypressEvents(input);
|
|
23880
23996
|
input.setRawMode?.(true);
|
|
23881
23997
|
input.resume();
|
|
@@ -23920,7 +24036,7 @@ async function select(args2) {
|
|
|
23920
24036
|
output.write(`\x1B[${totalLines}A`);
|
|
23921
24037
|
output.write(`\u2714 ${args2.message} \x1B[1;32m${shortLabel}\x1B[0m
|
|
23922
24038
|
`);
|
|
23923
|
-
|
|
24039
|
+
resolve11(args2.options[cursor].value);
|
|
23924
24040
|
return;
|
|
23925
24041
|
}
|
|
23926
24042
|
};
|
|
@@ -24823,21 +24939,21 @@ var init_scaffold_layout = __esm({
|
|
|
24823
24939
|
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
24824
24940
|
import { existsSync as existsSync12 } from "node:fs";
|
|
24825
24941
|
import { execFileSync } from "node:child_process";
|
|
24826
|
-
import { resolve as
|
|
24942
|
+
import { resolve as resolve7, relative as relative3 } from "node:path";
|
|
24827
24943
|
import { build as build2 } from "esbuild";
|
|
24828
24944
|
async function compile(options) {
|
|
24829
24945
|
const { assets, previewsPath, previewNames, componentName, liveReload } = options;
|
|
24830
24946
|
const { rootDir, srcComponentsDir, tokensCss, globalsCss, runtimeStandalone, uno } = assets;
|
|
24831
|
-
const DIST_DIR =
|
|
24832
|
-
const MODULES_DIR =
|
|
24947
|
+
const DIST_DIR = resolve7(rootDir, ".preview-dist");
|
|
24948
|
+
const MODULES_DIR = resolve7(DIST_DIR, "_modules");
|
|
24833
24949
|
await mkdir2(MODULES_DIR, { recursive: true });
|
|
24834
24950
|
console.log("Generating CSS...");
|
|
24835
|
-
await writeFile2(
|
|
24951
|
+
await writeFile2(resolve7(DIST_DIR, "globals.css"), tokensCss + "\n" + globalsCss);
|
|
24836
24952
|
console.log("Generated: .preview-dist/globals.css");
|
|
24837
24953
|
console.log("Generating UnoCSS...");
|
|
24838
24954
|
let unoConfigPath = uno.configPath;
|
|
24839
24955
|
if (uno.configIsBundled) {
|
|
24840
|
-
unoConfigPath =
|
|
24956
|
+
unoConfigPath = resolve7(DIST_DIR, "uno.config.ts");
|
|
24841
24957
|
await writeFile2(unoConfigPath, await readFile2(uno.configPath, "utf-8"));
|
|
24842
24958
|
}
|
|
24843
24959
|
execFileSync(uno.bin, [
|
|
@@ -24845,7 +24961,7 @@ async function compile(options) {
|
|
|
24845
24961
|
"--config",
|
|
24846
24962
|
unoConfigPath,
|
|
24847
24963
|
"-o",
|
|
24848
|
-
|
|
24964
|
+
resolve7(DIST_DIR, "uno.css")
|
|
24849
24965
|
], { cwd: uno.cwd, stdio: "inherit" });
|
|
24850
24966
|
console.log("Generated: .preview-dist/uno.css");
|
|
24851
24967
|
const previewSource = await readFile2(previewsPath, "utf-8");
|
|
@@ -24855,7 +24971,7 @@ async function compile(options) {
|
|
|
24855
24971
|
const componentFiles = resolveDependenciesFromSource(
|
|
24856
24972
|
[componentName, ...previewSiblings],
|
|
24857
24973
|
srcComponentsDir
|
|
24858
|
-
).map((name) =>
|
|
24974
|
+
).map((name) => resolve7(srcComponentsDir, name, "index.tsx")).filter(existsSync12);
|
|
24859
24975
|
console.log(`Compiling ${componentFiles.length + 1} files...`);
|
|
24860
24976
|
const allFiles = [...componentFiles, previewsPath];
|
|
24861
24977
|
const adapter = new PreviewCsrAdapter();
|
|
@@ -24891,16 +25007,16 @@ async function compile(options) {
|
|
|
24891
25007
|
const allModules = new Map([...clientJsByKey, ...combined]);
|
|
24892
25008
|
for (const [key, content] of allModules) {
|
|
24893
25009
|
const safeName = key.replace(/[/\\]/g, "__") + ".js";
|
|
24894
|
-
await writeFile2(
|
|
25010
|
+
await writeFile2(resolve7(MODULES_DIR, safeName), content);
|
|
24895
25011
|
}
|
|
24896
25012
|
const previewModuleFile = previewKey.replace(/[/\\]/g, "__") + ".js";
|
|
24897
25013
|
const entrySource = generateEntryScript(previewModuleFile, previewNames);
|
|
24898
|
-
const entryPath =
|
|
25014
|
+
const entryPath = resolve7(DIST_DIR, "_entry.js");
|
|
24899
25015
|
await writeFile2(entryPath, entrySource);
|
|
24900
25016
|
console.log("Bundling for browser...");
|
|
24901
25017
|
await build2({
|
|
24902
25018
|
entryPoints: [entryPath],
|
|
24903
|
-
outfile:
|
|
25019
|
+
outfile: resolve7(DIST_DIR, "_bundle.js"),
|
|
24904
25020
|
bundle: true,
|
|
24905
25021
|
format: "esm",
|
|
24906
25022
|
platform: "browser",
|
|
@@ -24911,7 +25027,7 @@ async function compile(options) {
|
|
|
24911
25027
|
define: { "process.env.NODE_ENV": '"development"' }
|
|
24912
25028
|
});
|
|
24913
25029
|
console.log("Generated: .preview-dist/_bundle.js");
|
|
24914
|
-
await writeFile2(
|
|
25030
|
+
await writeFile2(resolve7(DIST_DIR, "index.html"), generateHTML(componentName, liveReload));
|
|
24915
25031
|
console.log("Generated: .preview-dist/index.html");
|
|
24916
25032
|
return { distDir: DIST_DIR };
|
|
24917
25033
|
}
|
|
@@ -25077,7 +25193,7 @@ var init_compile = __esm({
|
|
|
25077
25193
|
// src/lib/tokens.ts
|
|
25078
25194
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
25079
25195
|
import { existsSync as existsSync13 } from "node:fs";
|
|
25080
|
-
import { resolve as
|
|
25196
|
+
import { resolve as resolve8, dirname as dirname4 } from "node:path";
|
|
25081
25197
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
25082
25198
|
async function loadTokens(jsonPath) {
|
|
25083
25199
|
const content = await readFile3(jsonPath, "utf-8");
|
|
@@ -25152,15 +25268,15 @@ ${darkLines.join("\n")}
|
|
|
25152
25268
|
return css;
|
|
25153
25269
|
}
|
|
25154
25270
|
function findBaseTokensJson(ctx2) {
|
|
25155
|
-
const monorepoTokens =
|
|
25271
|
+
const monorepoTokens = resolve8(ctx2.root, "site/shared/tokens/tokens.json");
|
|
25156
25272
|
if (existsSync13(monorepoTokens)) return monorepoTokens;
|
|
25157
|
-
const bundledTokens =
|
|
25273
|
+
const bundledTokens = resolve8(dirname4(thisFile2), "tokens.json");
|
|
25158
25274
|
if (existsSync13(bundledTokens)) return bundledTokens;
|
|
25159
25275
|
return null;
|
|
25160
25276
|
}
|
|
25161
25277
|
async function loadTokenSet(ctx2) {
|
|
25162
25278
|
if (ctx2.projectDir && ctx2.config?.paths.tokens) {
|
|
25163
|
-
const userTokens =
|
|
25279
|
+
const userTokens = resolve8(ctx2.projectDir, ctx2.config.paths.tokens, "tokens.json");
|
|
25164
25280
|
if (await fileExists(userTokens)) return loadTokens(userTokens);
|
|
25165
25281
|
}
|
|
25166
25282
|
const basePath = findBaseTokensJson(ctx2);
|
|
@@ -25170,7 +25286,7 @@ async function loadTokenSet(ctx2) {
|
|
|
25170
25286
|
);
|
|
25171
25287
|
}
|
|
25172
25288
|
const base = await loadTokens(basePath);
|
|
25173
|
-
const uiJsonPath =
|
|
25289
|
+
const uiJsonPath = resolve8(ctx2.root, "site/ui/tokens.json");
|
|
25174
25290
|
if (await fileExists(uiJsonPath)) {
|
|
25175
25291
|
return mergeTokenSets(base, await loadTokens(uiJsonPath));
|
|
25176
25292
|
}
|
|
@@ -25201,33 +25317,33 @@ var init_errors2 = __esm({
|
|
|
25201
25317
|
// src/lib/preview/assets.ts
|
|
25202
25318
|
import { existsSync as existsSync14 } from "node:fs";
|
|
25203
25319
|
import { readFile as readFile4 } from "node:fs/promises";
|
|
25204
|
-
import { resolve as
|
|
25320
|
+
import { resolve as resolve9, dirname as dirname5 } from "node:path";
|
|
25205
25321
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
25206
25322
|
function firstExisting(...candidates) {
|
|
25207
25323
|
return candidates.find((c) => !!c && existsSync14(c));
|
|
25208
25324
|
}
|
|
25209
25325
|
function unoBinCandidates(dir) {
|
|
25210
|
-
return ["unocss", "unocss.cmd", "unocss.CMD"].map((n) =>
|
|
25326
|
+
return ["unocss", "unocss.cmd", "unocss.CMD"].map((n) => resolve9(dir, "node_modules/.bin", n));
|
|
25211
25327
|
}
|
|
25212
25328
|
async function resolvePreviewAssets(ctx2) {
|
|
25213
25329
|
const monorepo = ctx2.config === null;
|
|
25214
25330
|
const projectDir = ctx2.projectDir;
|
|
25215
25331
|
const rootDir = projectDir ?? ctx2.root;
|
|
25216
|
-
const srcComponentsDir = monorepo ?
|
|
25332
|
+
const srcComponentsDir = monorepo ? resolve9(ctx2.root, "ui/components/ui") : resolve9(projectDir, ctx2.config.paths.components);
|
|
25217
25333
|
const tokensCss = await loadTokensCss(ctx2);
|
|
25218
25334
|
const globalsPath = firstExisting(
|
|
25219
|
-
projectDir &&
|
|
25220
|
-
projectDir &&
|
|
25221
|
-
projectDir &&
|
|
25222
|
-
monorepo ?
|
|
25223
|
-
|
|
25335
|
+
projectDir && resolve9(projectDir, "styles/globals.css"),
|
|
25336
|
+
projectDir && resolve9(projectDir, "globals.css"),
|
|
25337
|
+
projectDir && resolve9(projectDir, "app/globals.css"),
|
|
25338
|
+
monorepo ? resolve9(ctx2.root, "site/ui/styles/globals.css") : void 0,
|
|
25339
|
+
resolve9(assetDir, "preview-globals.css")
|
|
25224
25340
|
);
|
|
25225
25341
|
const globalsCss = globalsPath ? await readFile4(globalsPath, "utf-8") : "";
|
|
25226
|
-
const bundledUnoConfig =
|
|
25342
|
+
const bundledUnoConfig = resolve9(assetDir, "preview-uno.config.ts");
|
|
25227
25343
|
const configPath = firstExisting(
|
|
25228
|
-
projectDir &&
|
|
25229
|
-
projectDir &&
|
|
25230
|
-
monorepo ?
|
|
25344
|
+
projectDir && resolve9(projectDir, "uno.config.ts"),
|
|
25345
|
+
projectDir && resolve9(projectDir, "uno.config.js"),
|
|
25346
|
+
monorepo ? resolve9(ctx2.root, "site/ui/uno.config.ts") : void 0,
|
|
25231
25347
|
bundledUnoConfig
|
|
25232
25348
|
);
|
|
25233
25349
|
if (!configPath) {
|
|
@@ -25235,11 +25351,11 @@ async function resolvePreviewAssets(ctx2) {
|
|
|
25235
25351
|
"No UnoCSS config found and the bundled default is missing \u2014 reinstall @barefootjs/cli."
|
|
25236
25352
|
);
|
|
25237
25353
|
}
|
|
25238
|
-
const unoCwd = monorepo ?
|
|
25239
|
-
const globs = monorepo ? ["../../ui/components/**/*.tsx", "./**/*.tsx", "./dist/**/*.tsx"] : [
|
|
25354
|
+
const unoCwd = monorepo ? resolve9(ctx2.root, "site/ui") : rootDir;
|
|
25355
|
+
const globs = monorepo ? ["../../ui/components/**/*.tsx", "./**/*.tsx", "./dist/**/*.tsx"] : [resolve9(srcComponentsDir, "**/*.tsx")];
|
|
25240
25356
|
const unoBin = firstExisting(
|
|
25241
25357
|
...unoBinCandidates(rootDir),
|
|
25242
|
-
...monorepo ? unoBinCandidates(
|
|
25358
|
+
...monorepo ? unoBinCandidates(resolve9(ctx2.root, "site/ui")) : [],
|
|
25243
25359
|
...monorepo ? unoBinCandidates(ctx2.root) : []
|
|
25244
25360
|
);
|
|
25245
25361
|
if (!unoBin) {
|
|
@@ -25248,9 +25364,9 @@ async function resolvePreviewAssets(ctx2) {
|
|
|
25248
25364
|
);
|
|
25249
25365
|
}
|
|
25250
25366
|
const runtimeStandalone = firstExisting(
|
|
25251
|
-
monorepo ?
|
|
25252
|
-
|
|
25253
|
-
|
|
25367
|
+
monorepo ? resolve9(ctx2.root, "packages/client/dist/runtime/standalone.js") : void 0,
|
|
25368
|
+
resolve9(rootDir, "node_modules/@barefootjs/client/dist/runtime/standalone.js"),
|
|
25369
|
+
resolve9(rootDir, "node_modules/@barefootjs/client/dist/runtime/index.js")
|
|
25254
25370
|
);
|
|
25255
25371
|
if (!runtimeStandalone) {
|
|
25256
25372
|
throw new PreviewError(
|
|
@@ -25549,11 +25665,11 @@ var init_preview_generate = __esm({
|
|
|
25549
25665
|
});
|
|
25550
25666
|
|
|
25551
25667
|
// src/lib/preview/run.ts
|
|
25552
|
-
import { resolve as
|
|
25668
|
+
import { resolve as resolve10, relative as relative4 } from "node:path";
|
|
25553
25669
|
import { readFileSync as readFileSync6, writeFileSync as writeFileSync4, existsSync as existsSync15 } from "node:fs";
|
|
25554
25670
|
async function runPreview(componentName, ctx2, opts = {}) {
|
|
25555
25671
|
const assets = await resolvePreviewAssets(ctx2);
|
|
25556
|
-
const previewsPath =
|
|
25672
|
+
const previewsPath = resolve10(assets.srcComponentsDir, componentName, "index.preview.tsx");
|
|
25557
25673
|
if (!existsSync15(previewsPath)) {
|
|
25558
25674
|
try {
|
|
25559
25675
|
const meta = loadComponent(ctx2.metaDir, componentName);
|
|
@@ -25725,7 +25841,7 @@ async function run8(args2, ctx2) {
|
|
|
25725
25841
|
Serving ${server.url}`);
|
|
25726
25842
|
if (!opts.watch) {
|
|
25727
25843
|
console.log(" Press Ctrl+C to stop.");
|
|
25728
|
-
await new Promise((
|
|
25844
|
+
await new Promise((resolve11) => process.on("SIGINT", resolve11));
|
|
25729
25845
|
server.close();
|
|
25730
25846
|
return;
|
|
25731
25847
|
}
|
|
@@ -25775,7 +25891,7 @@ async function run8(args2, ctx2) {
|
|
|
25775
25891
|
const watchers = watchTargets.map(
|
|
25776
25892
|
(target) => fsWatch(target, { recursive: true }, schedule)
|
|
25777
25893
|
);
|
|
25778
|
-
await new Promise((
|
|
25894
|
+
await new Promise((resolve11) => process.on("SIGINT", resolve11));
|
|
25779
25895
|
for (const w of watchers) w.close();
|
|
25780
25896
|
server.close();
|
|
25781
25897
|
}
|
|
@@ -27259,9 +27375,9 @@ function findProjectConfig(startDir) {
|
|
|
27259
27375
|
let dir = path.resolve(startDir);
|
|
27260
27376
|
const { root: fsRoot } = path.parse(dir);
|
|
27261
27377
|
while (true) {
|
|
27262
|
-
const
|
|
27263
|
-
if (existsSync2(
|
|
27264
|
-
return { dir, tsConfigPath:
|
|
27378
|
+
const ts20 = path.join(dir, "barefoot.config.ts");
|
|
27379
|
+
if (existsSync2(ts20)) {
|
|
27380
|
+
return { dir, tsConfigPath: ts20 };
|
|
27265
27381
|
}
|
|
27266
27382
|
if (dir === fsRoot) return null;
|
|
27267
27383
|
dir = path.dirname(dir);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "CLI for agent-driven UI component discovery and scaffolding",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"typescript": "^5.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@barefootjs/jsx": "0.
|
|
34
|
+
"@barefootjs/jsx": "0.4.0",
|
|
35
35
|
"@types/node": "^22.0.0"
|
|
36
36
|
}
|
|
37
37
|
}
|