@barefootjs/cli 0.10.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +63 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -16990,8 +16990,36 @@ function extractSsrDefaults(metadata) {
16990
16990
  out[memo.name] = { value: resultToJsonable(value) };
16991
16991
  bindings[memo.name] = value;
16992
16992
  }
16993
+ if (metadata.propsObjectName !== null) {
16994
+ const referenced = /* @__PURE__ */ new Set();
16995
+ for (const sig of metadata.signals) {
16996
+ if (!sig.getter || sig.isModule) continue;
16997
+ collectPropRefs(sig.initialValue, metadata.propsObjectName, referenced);
16998
+ }
16999
+ for (const memo of metadata.memos) {
17000
+ if (memo.isModule) continue;
17001
+ collectPropRefs(memo.computation, metadata.propsObjectName, referenced);
17002
+ }
17003
+ for (const name of referenced) {
17004
+ if (name in out) continue;
17005
+ out[name] = { propName: name, value: null };
17006
+ }
17007
+ }
16993
17008
  return Object.keys(out).length === 0 ? void 0 : out;
16994
17009
  }
17010
+ function collectPropRefs(expr, propsObjectName, out) {
17011
+ if (!expr || !expr.trim()) return;
17012
+ const node = parseExpression2(expr);
17013
+ if (!node) return;
17014
+ const visit3 = (n) => {
17015
+ if (ts16.isPropertyAccessExpression(n) && ts16.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts16.isIdentifier(n.name)) {
17016
+ out.add(n.name.text);
17017
+ return;
17018
+ }
17019
+ ts16.forEachChild(n, visit3);
17020
+ };
17021
+ visit3(node);
17022
+ }
16995
17023
  function resultToJsonable(v) {
16996
17024
  if (v === UNRESOLVED) return null;
16997
17025
  if (v === void 0) return null;
@@ -25693,12 +25721,46 @@ my $backend = BarefootJS::Backend::Xslate->new(
25693
25721
  xslate_options => { cache => $DEV ? 0 : 1 },
25694
25722
  );
25695
25723
 
25724
+ # Load the build manifest (\`bf build\` writes dist/templates/manifest.json).
25725
+ # It carries each component's \`ssrDefaults\` \u2014 the static fallback for every
25726
+ # template variable (signals, memos, and the props they read). A plain PSGI
25727
+ # app has no plugin to seed those automatically (unlike the Mojolicious
25728
+ # integration), so we read them here and bind them as render vars. Without
25729
+ # this, \`<: $count :>\` / \`<: my $count = ($initial // 0) :>\` reference
25730
+ # unbound variables.
25731
+ sub load_manifest () {
25732
+ open my $fh, '<:raw', 'dist/templates/manifest.json' or return {};
25733
+ local $/;
25734
+ my $json = <$fh>;
25735
+ close $fh;
25736
+ my $m = eval { $J->decode($json) };
25737
+ return (ref $m eq 'HASH') ? $m : {};
25738
+ }
25739
+ # Cache the manifest in production; re-read each request in dev so a
25740
+ # \`bf build --watch\` rebuild surfaces new defaults without a restart.
25741
+ my $MANIFEST = $DEV ? undef : load_manifest();
25742
+ sub manifest () { return $DEV ? load_manifest() : $MANIFEST }
25743
+
25744
+ # Build the SSR stash for a component from its manifest \`ssrDefaults\`.
25745
+ sub ssr_defaults ($component) {
25746
+ my $entry = manifest()->{$component} or return ();
25747
+ my $defaults = $entry->{ssrDefaults} or return ();
25748
+ my %stash;
25749
+ for my $name (keys %$defaults) {
25750
+ my $d = $defaults->{$name};
25751
+ $stash{$name} = ref($d) eq 'HASH' ? $d->{value} : $d;
25752
+ }
25753
+ return %stash;
25754
+ }
25755
+
25696
25756
  sub rand_suffix () { return substr(sprintf('%f', rand()) =~ s/^0\\.//r, 0, 6) }
25697
25757
 
25698
25758
  # Render a top-level component template and wrap it in the page layout.
25699
- sub render_component ($component, %stash) {
25759
+ # Manifest defaults seed the stash; any caller-supplied \`%override\` wins.
25760
+ sub render_component ($component, %override) {
25700
25761
  my $bf = BarefootJS->new(undef, { backend => $backend });
25701
25762
  $bf->_scope_id($component . '_' . rand_suffix());
25763
+ my %stash = (ssr_defaults($component), %override);
25702
25764
  my $body = $backend->render_named($component, $bf, \\%stash);
25703
25765
  return layout(body => $body, scripts => $bf->scripts);
25704
25766
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/cli",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
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.10.0",
34
+ "@barefootjs/jsx": "0.10.1",
35
35
  "@types/node": "^22.0.0"
36
36
  }
37
37
  }