@stacksjs/stx 0.2.161 → 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.
- package/dist/cli.js +4407 -1325
- package/dist/craft.js +2516 -864
- package/dist/pwa.js +2479 -827
- package/dist/ssg.js +2400 -748
- package/dist/variable-extractor.d.ts +22 -0
- package/dist/variable-extractor.js +68 -4
- package/package.json +5 -5
|
@@ -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";
|
|
@@ -409,7 +458,12 @@ export async function extractVariables(scriptContent, context, filePath, options
|
|
|
409
458
|
removeEventListener: () => {}
|
|
410
459
|
}, mockConsole = console;
|
|
411
460
|
try {
|
|
412
|
-
const convertedScript = convertToCommonJS(jsContent, filePath), propsKeys = new Set(Object.keys(propsObj)), isIdentifier = (key) => /^[a-z_$][\w$]*$/i.test(key), filteredContextKeys = Object.keys(context).filter((key) => !propsKeys.has(key) && key !== "props" && isIdentifier(key)), filteredContextValues = filteredContextKeys.map((key) => context[key])
|
|
461
|
+
const convertedScript = convertToCommonJS(jsContent, filePath), propsKeys = new Set(Object.keys(propsObj)), isIdentifier = (key) => /^[a-z_$][\w$]*$/i.test(key), filteredContextKeys = Object.keys(context).filter((key) => !propsKeys.has(key) && key !== "props" && isIdentifier(key)), filteredContextValues = filteredContextKeys.map((key) => context[key]);
|
|
462
|
+
if (!filteredContextKeys.includes("__stxServeContext")) {
|
|
463
|
+
filteredContextKeys.push("__stxServeContext");
|
|
464
|
+
filteredContextValues.push(void 0);
|
|
465
|
+
}
|
|
466
|
+
const jsReserved = new Set([
|
|
413
467
|
"break",
|
|
414
468
|
"case",
|
|
415
469
|
"catch",
|
|
@@ -476,7 +530,7 @@ export async function extractVariables(scriptContent, context, filePath, options
|
|
|
476
530
|
scriptContextKeys.push(filteredContextKeys[i]);
|
|
477
531
|
scriptContextValues.push(filteredContextValues[i]);
|
|
478
532
|
}
|
|
479
|
-
const result = await Function(
|
|
533
|
+
const result = await Function(...STX_ENGINE_BINDING_NAMES, ...propArgNames, ...scriptContextKeys, `return (async () => {
|
|
480
534
|
${convertedScript}
|
|
481
535
|
${reSyncCode}
|
|
482
536
|
return module.exports
|
|
@@ -624,7 +678,7 @@ export function convertToCommonJS(scriptContent, filePath) {
|
|
|
624
678
|
convertedLines.push(`const ${name} = await import('${resolved}')`);
|
|
625
679
|
convertedLines.push(`module.exports.${name} = ${name};`);
|
|
626
680
|
} else if (namedImportMatch) {
|
|
627
|
-
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);
|
|
628
682
|
for (const raw of names.split(",")) {
|
|
629
683
|
const specifier = raw.trim();
|
|
630
684
|
if (!specifier)
|
|
@@ -632,14 +686,24 @@ export function convertToCommonJS(scriptContent, filePath) {
|
|
|
632
686
|
const aliased = specifier.split(/\s+as\s+/);
|
|
633
687
|
if (aliased.length === 2) {
|
|
634
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
|
+
}
|
|
635
694
|
specifiers.push(`${imported}: ${local}`);
|
|
636
695
|
exported.push(local);
|
|
637
696
|
} else {
|
|
697
|
+
if (isStxRuntime && ENGINE_BINDINGS.has(specifier)) {
|
|
698
|
+
exported.push(specifier);
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
638
701
|
specifiers.push(specifier);
|
|
639
702
|
exported.push(specifier);
|
|
640
703
|
}
|
|
641
704
|
}
|
|
642
|
-
|
|
705
|
+
if (specifiers.length > 0)
|
|
706
|
+
convertedLines.push(`const { ${specifiers.join(", ")} } = await import('${resolved}')`);
|
|
643
707
|
for (const local of exported)
|
|
644
708
|
convertedLines.push(`module.exports.${local} = ${local};`);
|
|
645
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.
|
|
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.
|
|
121
|
-
"@stacksjs/sanitizer": "0.2.
|
|
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.
|
|
123
|
+
"bun-plugin-stx": "0.2.163",
|
|
124
124
|
"bunfig": "^0.15.17",
|
|
125
|
-
"stx-router": "0.2.
|
|
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"
|