@stacksjs/stx 0.2.98 → 0.2.100

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.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Records the `stateDir` coming from `stx.config.ts`.
3
+ *
4
+ * Called by the config loader. A nullish or blank value clears it, so a config
5
+ * without `stateDir` cannot inherit a stale value from a previously loaded one
6
+ * (the dev server loads a config per app directory).
7
+ */
8
+ export declare function setStateDir(dir?: string | null): void;
9
+ /**
10
+ * The configured state directory, as written — relative or absolute.
11
+ */
12
+ export declare function stateDirName(): string;
13
+ /**
14
+ * Absolute path to a file or directory inside the state directory.
15
+ *
16
+ * An absolute state directory wins over `root`, so a framework can pin every
17
+ * cache to one place no matter which directory a given code path happens to
18
+ * resolve against.
19
+ */
20
+ export declare function stateDir(root?: string, ...segments: string[]): string;
21
+ /**
22
+ * Rewrites a config path that still carries the default `.stx/` prefix onto the
23
+ * configured state directory.
24
+ *
25
+ * The path-shaped config options (`cachePath`, `build.cacheDir`,
26
+ * `media.cache.directory`, `story.outDir`) default to somewhere under `.stx/`.
27
+ * Rather than make each one separately configurable, `stateDir` moves the whole
28
+ * family: anything under the default prefix follows it, and a path the user
29
+ * pointed somewhere else entirely is left alone.
30
+ */
31
+ export declare function rebaseOntoStateDir(value: string): string;
32
+ export declare function rebaseOntoStateDir(value: string | undefined): string | undefined;
33
+ /** The directory used when nothing configures one. */
34
+ export declare const DEFAULT_STATE_DIR: '.stx';
35
+ /** Environment variable that overrides both the config and the default. */
36
+ export declare const STATE_DIR_ENV_VAR: 'STX_DIR';
@@ -0,0 +1,22 @@
1
+ import path from "node:path";
2
+ export const DEFAULT_STATE_DIR = ".stx", STATE_DIR_ENV_VAR = "STX_DIR";
3
+ let configuredStateDir = null;
4
+ export function setStateDir(dir) {
5
+ configuredStateDir = dir?.trim() || null;
6
+ }
7
+ export function stateDirName() {
8
+ return process.env[STATE_DIR_ENV_VAR]?.trim() || configuredStateDir || DEFAULT_STATE_DIR;
9
+ }
10
+ export function stateDir(root = process.cwd(), ...segments) {
11
+ const dir = stateDirName();
12
+ return path.isAbsolute(dir) ? path.join(dir, ...segments) : path.join(root, dir, ...segments);
13
+ }
14
+ export function rebaseOntoStateDir(value) {
15
+ if (!value || path.isAbsolute(value))
16
+ return value;
17
+ const normalized = value.replace(/\\/g, "/");
18
+ if (normalized !== DEFAULT_STATE_DIR && !normalized.startsWith(`${DEFAULT_STATE_DIR}/`))
19
+ return value;
20
+ const suffix = normalized.slice(DEFAULT_STATE_DIR.length + 1);
21
+ return suffix ? path.join(stateDirName(), suffix) : stateDirName();
22
+ }
@@ -1,7 +1,8 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
+ import { stateDir } from "../state-dir.js";
3
4
  export async function generateStoryDocs(ctx, components, options = {}) {
4
- const outDir = options.outDir || path.join(ctx.root, ".stx", "docs");
5
+ const outDir = options.outDir || stateDir(ctx.root, "docs");
5
6
  await fs.promises.mkdir(outDir, { recursive: !0 });
6
7
  const indexContent = generateDocsIndex(components);
7
8
  await fs.promises.writeFile(path.join(outDir, "README.md"), indexContent);
@@ -1,7 +1,8 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
+ import { stateDir } from "../state-dir.js";
3
4
  export function getSnapshotDir(ctx) {
4
- return path.join(ctx.root, ".stx", "story", "snapshots");
5
+ return stateDir(ctx.root, "story", "snapshots");
5
6
  }
6
7
  function getVersionFilePath(snapshotDir, storyId) {
7
8
  return path.join(snapshotDir, `${storyId}.versions.json`);
@@ -1,6 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { checkA11y } from "../a11y.js";
4
+ import { stateDir } from "../state-dir.js";
4
5
  export async function runVisualTests(ctx, options = {}) {
5
6
  const startTime = Date.now(), result = {
6
7
  total: 0,
@@ -9,7 +10,7 @@ export async function runVisualTests(ctx, options = {}) {
9
10
  new: 0,
10
11
  failures: [],
11
12
  duration: 0
12
- }, snapshotDir = options.snapshotDir || path.join(ctx.root, ".stx", "story", "snapshots");
13
+ }, snapshotDir = options.snapshotDir || stateDir(ctx.root, "story", "snapshots");
13
14
  await fs.promises.mkdir(snapshotDir, { recursive: !0 });
14
15
  let storyFiles = ctx.storyFiles;
15
16
  if (options.filter && options.filter.length > 0)
@@ -1,10 +1,11 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
+ import { stateDir } from "../state-dir.js";
3
4
  export async function runScreenshotTests(ctx, options = {}) {
4
5
  const startTime = performance.now(), {
5
6
  update = !1,
6
7
  threshold = 0.1,
7
- snapshotDir = path.join(ctx.root, ".stx", "story", "snapshots"),
8
+ snapshotDir = stateDir(ctx.root, "story", "snapshots"),
8
9
  width = 800,
9
10
  height = 600,
10
11
  deviceScaleFactor = 1,
@@ -85,7 +86,7 @@ export async function runScreenshotTests(ctx, options = {}) {
85
86
  async function runHtmlComparisonTests(ctx, options) {
86
87
  const startTime = performance.now(), {
87
88
  update = !1,
88
- snapshotDir = path.join(ctx.root, ".stx", "story", "snapshots"),
89
+ snapshotDir = stateDir(ctx.root, "story", "snapshots"),
89
90
  filter
90
91
  } = options, result = {
91
92
  total: 0,
@@ -38,7 +38,7 @@ function blankKeepingLines(s) {
38
38
  return s.replace(/[^\n]/g, " ");
39
39
  }
40
40
  export function findUnbalancedTags(template) {
41
- const stripped = template.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, blankKeepingLines).replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, blankKeepingLines).replace(/<!--[\s\S]*?-->/g, blankKeepingLines).replace(/\{\{\{[\s\S]*?\}\}\}/g, blankKeepingLines).replace(/\{\{[\s\S]*?\}\}/g, blankKeepingLines).replace(/\{!![\s\S]*?!!\}/g, blankKeepingLines).replace(/"[^"]*"/g, blankKeepingLines).replace(/'[^']*'/g, blankKeepingLines), opens = new Map, closes = new Map, tagRe = /<(\/?)([A-Za-z][\w-]*)\b[^>]*?(\/?)>/g;
41
+ const stripped = template.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, blankKeepingLines).replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, blankKeepingLines).replace(/<!--[\s\S]*?-->/g, blankKeepingLines).replace(/\{\{\{[\s\S]*?\}\}\}/g, blankKeepingLines).replace(/\{\{[\s\S]*?\}\}/g, blankKeepingLines).replace(/\{!![\s\S]*?!!\}/g, blankKeepingLines), opens = new Map, closes = new Map, tagRe = /<(\/?)([A-Za-z][\w-]*)\b(?:[^>"']|"[^"]*"|'[^']*')*?(\/?)>/g;
42
42
  let m;
43
43
  while ((m = tagRe.exec(stripped)) !== null) {
44
44
  const isClose = m[1] === "/", name = m[2], selfClose = m[3] === "/";
@@ -258,6 +258,7 @@ export declare interface StxConfig {
258
258
  }
259
259
  }
260
260
  root?: string
261
+ stateDir?: string
261
262
  pagesDir?: string
262
263
  templatesDir?: string
263
264
  defaultTitle?: string
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.98",
4
+ "version": "0.2.100",
5
5
  "description": "A performant UI Framework. Powered by Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -117,16 +117,16 @@
117
117
  "dependencies": {
118
118
  "@cwcss/crosswind": "^0.2.6",
119
119
  "@stacksjs/clapp": "^0.2.0",
120
- "@stacksjs/sanitizer": "0.2.98",
120
+ "@stacksjs/sanitizer": "0.2.100",
121
121
  "@stacksjs/ts-i18n": "^0.1.11",
122
- "bun-plugin-stx": "0.2.98",
122
+ "bun-plugin-stx": "0.2.100",
123
123
  "bunfig": "^0.15.15",
124
- "stx-router": "0.2.98",
124
+ "stx-router": "0.2.100",
125
125
  "ts-broadcasting": "^0.0.8",
126
126
  "ts-images": "^0.1.9",
127
127
  "ts-syntax-highlighter": "^0.2.1"
128
128
  },
129
129
  "optionalDependencies": {
130
- "@stacksjs/desktop": "0.2.98"
130
+ "@stacksjs/desktop": "0.2.100"
131
131
  }
132
132
  }