@stacksjs/stx 0.2.187 → 0.2.189

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/utils.js CHANGED
@@ -805,6 +805,17 @@ function assertInsideRoot(resolvedAbsolute, root) {
805
805
  return p;
806
806
  return null;
807
807
  }
808
+ async function findLayoutIn(layoutsDir, templatePath, dependencies, debug) {
809
+ const stripped = templatePath.startsWith("layouts/") ? templatePath.slice(8) : templatePath, base = path.join(layoutsDir, stripped);
810
+ for (const candidate of base.endsWith(".stx") ? [base] : [base, `${base}.stx`])
811
+ if (await fileExists(candidate)) {
812
+ if (debug)
813
+ console.log(`Found layout in ${layoutsDir}: ${candidate}`);
814
+ dependencies?.add(candidate);
815
+ return candidate;
816
+ }
817
+ return null;
818
+ }
808
819
  export async function resolveTemplatePath(templatePath, currentFilePath, options, dependencies) {
809
820
  const result = await resolveTemplatePathInner(templatePath, currentFilePath, options, dependencies);
810
821
  if (result === null)
@@ -856,7 +867,10 @@ async function resolveTemplatePathInner(templatePath, currentFilePath, options,
856
867
  return pathWithExt;
857
868
  }
858
869
  }
859
- let layoutsDir = "", searchDir = path.resolve(dirPath);
870
+ const layoutSearchDirs = [];
871
+ if (options.layoutsDir)
872
+ layoutSearchDirs.push(path.isAbsolute(options.layoutsDir) ? options.layoutsDir : path.resolve(process.cwd(), options.layoutsDir));
873
+ let searchDir = path.resolve(dirPath);
860
874
  const rootDir = process.cwd();
861
875
  for (let i = 0;i < 10; i++) {
862
876
  const candidate = path.join(searchDir, "layouts");
@@ -865,7 +879,7 @@ async function resolveTemplatePathInner(templatePath, currentFilePath, options,
865
879
  candidateExists = fs.statSync(candidate, { throwIfNoEntry: !1 })?.isDirectory() ?? !1;
866
880
  } catch {}
867
881
  if (candidateExists) {
868
- layoutsDir = candidate;
882
+ layoutSearchDirs.push(candidate);
869
883
  break;
870
884
  }
871
885
  const parent = path.dirname(searchDir);
@@ -873,45 +887,10 @@ async function resolveTemplatePathInner(templatePath, currentFilePath, options,
873
887
  break;
874
888
  searchDir = parent;
875
889
  }
876
- if (layoutsDir) {
877
- const layoutTemplatePath = templatePath.startsWith("layouts/") ? templatePath.slice(8) : templatePath, fromCurrentLayouts = path.join(layoutsDir, layoutTemplatePath);
878
- if (await fileExists(fromCurrentLayouts)) {
879
- if (options.debug)
880
- console.log(`Found in current layouts dir: ${fromCurrentLayouts}`);
881
- if (dependencies)
882
- dependencies.add(fromCurrentLayouts);
883
- return fromCurrentLayouts;
884
- }
885
- if (!layoutTemplatePath.endsWith(".stx")) {
886
- const fromCurrentLayoutsWithExt = `${fromCurrentLayouts}.stx`;
887
- if (await fileExists(fromCurrentLayoutsWithExt)) {
888
- if (options.debug)
889
- console.log(`Found in current layouts dir with extension: ${fromCurrentLayoutsWithExt}`);
890
- if (dependencies)
891
- dependencies.add(fromCurrentLayoutsWithExt);
892
- return fromCurrentLayoutsWithExt;
893
- }
894
- }
895
- }
896
- if (options.layoutsDir) {
897
- const resolvedLayoutsDir = path.isAbsolute(options.layoutsDir) ? options.layoutsDir : path.resolve(process.cwd(), options.layoutsDir), strippedPath = templatePath.startsWith("layouts/") ? templatePath.slice(8) : templatePath, fromLayoutsDir = path.join(resolvedLayoutsDir, strippedPath);
898
- if (await fileExists(fromLayoutsDir)) {
899
- if (options.debug)
900
- console.log(`Found in options.layoutsDir: ${fromLayoutsDir}`);
901
- if (dependencies)
902
- dependencies.add(fromLayoutsDir);
903
- return fromLayoutsDir;
904
- }
905
- if (!templatePath.endsWith(".stx")) {
906
- const fromLayoutsDirWithExt = `${fromLayoutsDir}.stx`;
907
- if (await fileExists(fromLayoutsDirWithExt)) {
908
- if (options.debug)
909
- console.log(`Found in options.layoutsDir with extension: ${fromLayoutsDirWithExt}`);
910
- if (dependencies)
911
- dependencies.add(fromLayoutsDirWithExt);
912
- return fromLayoutsDirWithExt;
913
- }
914
- }
890
+ for (const dir of layoutSearchDirs) {
891
+ const found = await findLayoutIn(dir, templatePath, dependencies, options.debug);
892
+ if (found)
893
+ return found;
915
894
  }
916
895
  if (templatePath.startsWith("layouts/") || templatePath.includes("/layouts/")) {
917
896
  const parts = templatePath.split("layouts/"), layoutsPath = path.join(options.partialsDir || dirPath, "layouts", parts[1]);
@@ -934,9 +913,9 @@ async function resolveTemplatePathInner(templatePath, currentFilePath, options,
934
913
  }
935
914
  }
936
915
  if (options.partialsDir) {
937
- layoutsDir = path.join(options.partialsDir, "layouts");
938
- if (await fileExists(layoutsDir)) {
939
- const fromPartialsLayouts = path.join(layoutsDir, templatePath);
916
+ const partialsLayoutsDir = path.join(options.partialsDir, "layouts");
917
+ if (await fileExists(partialsLayoutsDir)) {
918
+ const fromPartialsLayouts = path.join(partialsLayoutsDir, templatePath);
940
919
  if (await fileExists(fromPartialsLayouts)) {
941
920
  if (options.debug)
942
921
  console.log(`Found in partials layouts dir: ${fromPartialsLayouts}`);
@@ -49,7 +49,7 @@ export const STX_ENGINE_BINDING_NAMES = [
49
49
  "fetch",
50
50
  "params"
51
51
  ];
52
- const ENGINE_BINDINGS = new Set(STX_ENGINE_BINDING_NAMES), STX_RUNTIME_SPECIFIERS = new Set(["stx", "@stacksjs/stx"]);
52
+ const ENGINE_BINDINGS = new Set(STX_ENGINE_BINDING_NAMES), CONTEXT_RESERVED_BINDINGS = new Set(["props", "$props", "defineProps"]), STX_RUNTIME_SPECIFIERS = new Set(["stx", "@stacksjs/stx"]);
53
53
  import { findMatchingDelimiter } from "./parser/tokenizer.js";
54
54
  import { mergeHeadConfigs, seoMetaToHeadConfig } from "./head.js";
55
55
  import { getPublicEnvDefine } from "./public-env.js";
@@ -459,7 +459,7 @@ export async function extractVariables(scriptContent, context, filePath, options
459
459
  removeEventListener: () => {}
460
460
  }, mockConsole = console;
461
461
  try {
462
- 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
+ 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) && !CONTEXT_RESERVED_BINDINGS.has(key) && isIdentifier(key)), filteredContextValues = filteredContextKeys.map((key) => context[key]);
463
463
  if (!filteredContextKeys.includes("__stxServeContext")) {
464
464
  filteredContextKeys.push("__stxServeContext");
465
465
  filteredContextValues.push(void 0);
@@ -690,16 +690,13 @@ export function convertToCommonJS(scriptContent, filePath) {
690
690
  const [imported, local] = [aliased[0].trim(), aliased[1].trim()];
691
691
  if (isStxRuntime && ENGINE_BINDINGS.has(imported)) {
692
692
  convertedLines.push(`const ${local} = ${imported};`);
693
- exported.push(local);
694
693
  continue;
695
694
  }
696
695
  specifiers.push(`${imported}: ${local}`);
697
696
  exported.push(local);
698
697
  } else {
699
- if (isStxRuntime && ENGINE_BINDINGS.has(specifier)) {
700
- exported.push(specifier);
698
+ if (isStxRuntime && ENGINE_BINDINGS.has(specifier))
701
699
  continue;
702
- }
703
700
  specifiers.push(specifier);
704
701
  exported.push(specifier);
705
702
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.187",
4
+ "version": "0.2.189",
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.187",
121
- "@stacksjs/sanitizer": "0.2.187",
120
+ "@stacksjs/desktop": "0.2.189",
121
+ "@stacksjs/sanitizer": "0.2.189",
122
122
  "@stacksjs/ts-i18n": "^0.1.11",
123
- "bun-plugin-stx": "0.2.187",
123
+ "bun-plugin-stx": "0.2.189",
124
124
  "bunfig": "^0.15.17",
125
- "stx-router": "0.2.187",
125
+ "stx-router": "0.2.189",
126
126
  "ts-broadcasting": "^0.0.9",
127
127
  "ts-images": "^0.2.11",
128
128
  "ts-syntax-highlighter": "^0.2.1"