@stacksjs/stx 0.2.162 → 0.2.163

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.
@@ -1,3 +1,25 @@
1
+ /**
2
+ * The runtime bindings the engine hands a `<script server>` block as function
3
+ * parameters, in the order the parameters are declared.
4
+ *
5
+ * This drives the `new Function` parameter list rather than sitting beside it,
6
+ * because the two must not drift: the value list below it is positional, so a
7
+ * name added in one place and not the other silently rebinds every argument
8
+ * after it.
9
+ *
10
+ * It is also the set a `from 'stx'` import must not redeclare. A server script
11
+ * writing the documented `import { defineProps } from 'stx'` was rewritten to
12
+ * `const { defineProps } = await import('stx')`, and that `const` shadows the
13
+ * parameter of the same name. The package's own `defineProps` reads
14
+ * `globalThis.__STX_CURRENT_PROPS__`, which nothing on the server path ever
15
+ * sets — so props came back `{}` and every component rendered empty.
16
+ *
17
+ * It went unnoticed because `stx` does not resolve inside this repo (the
18
+ * published package is `@stacksjs/stx`; the root `stx` is private), so the
19
+ * generated `await import('stx')` rejected and the shadowing binding was never
20
+ * created. The failure needed a real install to appear.
21
+ */
22
+ export declare const STX_ENGINE_BINDING_NAMES: readonly ['module', 'exports', 'require', 'props', '$props', 'defineProps', 'withDefaults', 'defineClientPayload', 'state', 'derived', 'effect', 'batch', 'onMount', 'onDestroy', 'definePageMeta', 'useRoute', 'useRouter', 'useHead', 'useSeoMeta', 'ref', 'reactive', 'computed', 'watch', 'onMounted', 'onUnmounted', 'nextTick', 'defineEmits', 'defineExpose', 'defineSlots', 'provide', 'inject', 'useColorMode', 'useDark', 'useMediaQuery', 'useScrollLock', 'usePreferredDark', 'usePreferredLight', 'usePreferredReducedMotion', 'usePreferredContrast', 'window', 'document', 'console', 'confirm', 'alert', 'fetch', 'params'];
1
23
  /**
2
24
  * Strip TypeScript-specific syntax to make it executable as JavaScript
3
25
  *
@@ -1,5 +1,54 @@
1
1
  var {require}=import.meta;import path from "node:path";
2
2
  import process from "node:process";
3
+ export const STX_ENGINE_BINDING_NAMES = [
4
+ "module",
5
+ "exports",
6
+ "require",
7
+ "props",
8
+ "$props",
9
+ "defineProps",
10
+ "withDefaults",
11
+ "defineClientPayload",
12
+ "state",
13
+ "derived",
14
+ "effect",
15
+ "batch",
16
+ "onMount",
17
+ "onDestroy",
18
+ "definePageMeta",
19
+ "useRoute",
20
+ "useRouter",
21
+ "useHead",
22
+ "useSeoMeta",
23
+ "ref",
24
+ "reactive",
25
+ "computed",
26
+ "watch",
27
+ "onMounted",
28
+ "onUnmounted",
29
+ "nextTick",
30
+ "defineEmits",
31
+ "defineExpose",
32
+ "defineSlots",
33
+ "provide",
34
+ "inject",
35
+ "useColorMode",
36
+ "useDark",
37
+ "useMediaQuery",
38
+ "useScrollLock",
39
+ "usePreferredDark",
40
+ "usePreferredLight",
41
+ "usePreferredReducedMotion",
42
+ "usePreferredContrast",
43
+ "window",
44
+ "document",
45
+ "console",
46
+ "confirm",
47
+ "alert",
48
+ "fetch",
49
+ "params"
50
+ ];
51
+ const ENGINE_BINDINGS = new Set(STX_ENGINE_BINDING_NAMES), STX_RUNTIME_SPECIFIERS = new Set(["stx", "@stacksjs/stx"]);
3
52
  import { findMatchingDelimiter } from "./parser/tokenizer.js";
4
53
  import { mergeHeadConfigs, seoMetaToHeadConfig } from "./head.js";
5
54
  import { getPublicEnvDefine } from "./public-env.js";
@@ -481,7 +530,7 @@ export async function extractVariables(scriptContent, context, filePath, options
481
530
  scriptContextKeys.push(filteredContextKeys[i]);
482
531
  scriptContextValues.push(filteredContextValues[i]);
483
532
  }
484
- const result = await Function("module", "exports", "require", "props", "$props", "defineProps", "withDefaults", "defineClientPayload", "state", "derived", "effect", "batch", "onMount", "onDestroy", "definePageMeta", "useRoute", "useRouter", "useHead", "useSeoMeta", "ref", "reactive", "computed", "watch", "onMounted", "onUnmounted", "nextTick", "defineEmits", "defineExpose", "defineSlots", "provide", "inject", "useColorMode", "useDark", "useMediaQuery", "useScrollLock", "usePreferredDark", "usePreferredLight", "usePreferredReducedMotion", "usePreferredContrast", "window", "document", "console", "confirm", "alert", "fetch", "params", ...propArgNames, ...scriptContextKeys, `return (async () => {
533
+ const result = await Function(...STX_ENGINE_BINDING_NAMES, ...propArgNames, ...scriptContextKeys, `return (async () => {
485
534
  ${convertedScript}
486
535
  ${reSyncCode}
487
536
  return module.exports
@@ -629,7 +678,7 @@ export function convertToCommonJS(scriptContent, filePath) {
629
678
  convertedLines.push(`const ${name} = await import('${resolved}')`);
630
679
  convertedLines.push(`module.exports.${name} = ${name};`);
631
680
  } else if (namedImportMatch) {
632
- const [, names, source] = namedImportMatch, resolved = resolveSource(source), specifiers = [], exported = [];
681
+ const [, names, source] = namedImportMatch, resolved = resolveSource(source), specifiers = [], exported = [], isStxRuntime = STX_RUNTIME_SPECIFIERS.has(source);
633
682
  for (const raw of names.split(",")) {
634
683
  const specifier = raw.trim();
635
684
  if (!specifier)
@@ -637,14 +686,24 @@ export function convertToCommonJS(scriptContent, filePath) {
637
686
  const aliased = specifier.split(/\s+as\s+/);
638
687
  if (aliased.length === 2) {
639
688
  const [imported, local] = [aliased[0].trim(), aliased[1].trim()];
689
+ if (isStxRuntime && ENGINE_BINDINGS.has(imported)) {
690
+ convertedLines.push(`const ${local} = ${imported};`);
691
+ exported.push(local);
692
+ continue;
693
+ }
640
694
  specifiers.push(`${imported}: ${local}`);
641
695
  exported.push(local);
642
696
  } else {
697
+ if (isStxRuntime && ENGINE_BINDINGS.has(specifier)) {
698
+ exported.push(specifier);
699
+ continue;
700
+ }
643
701
  specifiers.push(specifier);
644
702
  exported.push(specifier);
645
703
  }
646
704
  }
647
- convertedLines.push(`const { ${specifiers.join(", ")} } = await import('${resolved}')`);
705
+ if (specifiers.length > 0)
706
+ convertedLines.push(`const { ${specifiers.join(", ")} } = await import('${resolved}')`);
648
707
  for (const local of exported)
649
708
  convertedLines.push(`module.exports.${local} = ${local};`);
650
709
  } else if (sideEffectMatch) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.162",
4
+ "version": "0.2.163",
5
5
  "description": "A performant UI Framework. Powered by Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -117,12 +117,12 @@
117
117
  "dependencies": {
118
118
  "@cwcss/crosswind": "^0.2.14",
119
119
  "@stacksjs/clapp": "^0.2.0",
120
- "@stacksjs/desktop": "0.2.162",
121
- "@stacksjs/sanitizer": "0.2.162",
120
+ "@stacksjs/desktop": "0.2.163",
121
+ "@stacksjs/sanitizer": "0.2.163",
122
122
  "@stacksjs/ts-i18n": "^0.1.11",
123
- "bun-plugin-stx": "0.2.162",
123
+ "bun-plugin-stx": "0.2.163",
124
124
  "bunfig": "^0.15.17",
125
- "stx-router": "0.2.162",
125
+ "stx-router": "0.2.163",
126
126
  "ts-broadcasting": "^0.0.9",
127
127
  "ts-images": "^0.1.9",
128
128
  "ts-syntax-highlighter": "^0.2.1"