@stacksjs/stx 0.2.189 → 0.2.191
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/browser-composables.d.ts +24 -7
- package/dist/browser-composables.js +58 -17
- package/dist/cli.js +741 -722
- package/dist/component-library.js +1 -1
- package/dist/composable-loader.d.ts +21 -7
- package/dist/composable-loader.js +77 -8
- package/dist/composables/use-cookie.d.ts +8 -3
- package/dist/craft.js +334 -316
- package/dist/dev-server/crosswind.d.ts +26 -0
- package/dist/dev-server/crosswind.js +50 -34
- package/dist/process.js +12 -8
- package/dist/pwa.js +327 -309
- package/dist/signals.js +21 -3
- package/dist/ssg.d.ts +13 -0
- package/dist/ssg.js +354 -336
- package/dist/stx.d.ts +37 -6
- package/dist/typecheck.js +47 -1
- package/dist/types/config-types.d.ts +11 -0
- package/dist/utils.js +14 -1
- package/package.json +5 -5
- package/stx.d.ts +37 -6
|
@@ -67,6 +67,32 @@ export declare function resetCrosswindCache(): void;
|
|
|
67
67
|
* without surfacing a "not found" warning to the user.
|
|
68
68
|
*/
|
|
69
69
|
export declare function loadCrosswindConfig(cwd: string): Promise<CrosswindConfig | null>;
|
|
70
|
+
/**
|
|
71
|
+
* Resolve the project's crosswind config the way CSS generation does.
|
|
72
|
+
*
|
|
73
|
+
* Priority: the `css` field of `stx.config.ts` (a path, or an inline object
|
|
74
|
+
* that may itself name a path), then auto-discovery of `crosswind.config.ts`.
|
|
75
|
+
*
|
|
76
|
+
* Extracted so the SSG's cache key can be built from the same resolution the
|
|
77
|
+
* stylesheet is. Two copies of this precedence would drift, and a cache key
|
|
78
|
+
* computed from a *different* config than the CSS is worse than no key at all —
|
|
79
|
+
* it would report freshness it has not checked.
|
|
80
|
+
*/
|
|
81
|
+
export declare function resolveUserCrosswindConfig(resolveRoot: string): Promise<CrosswindConfig | null>;
|
|
82
|
+
/**
|
|
83
|
+
* A short, stable digest of a resolved crosswind config.
|
|
84
|
+
*
|
|
85
|
+
* Hashes the resolved OBJECT rather than a file, so it covers a config
|
|
86
|
+
* assembled from several files, an inline `css` block in `stx.config.ts`, and a
|
|
87
|
+
* preflight imported from somewhere else — all cases a path mtime would miss.
|
|
88
|
+
*
|
|
89
|
+
* Functions are hashed by source text. `JSON.stringify` drops them entirely,
|
|
90
|
+
* which would make an edit to a function-valued plugin or preflight invisible —
|
|
91
|
+
* the exact silent-staleness this digest exists to prevent. Cycles are replaced
|
|
92
|
+
* rather than thrown on, because throwing here degrades to 'unhashable', and a
|
|
93
|
+
* constant digest is a cache key that never changes.
|
|
94
|
+
*/
|
|
95
|
+
export declare function fingerprintConfig(config: unknown): string;
|
|
70
96
|
/**
|
|
71
97
|
* Build Crosswind CSS using the build() API
|
|
72
98
|
* This scans content files and generates CSS for all used classes
|
|
@@ -193,6 +193,54 @@ export async function loadCrosswindConfig(cwd) {
|
|
|
193
193
|
return null;
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
+
export async function resolveUserCrosswindConfig(resolveRoot) {
|
|
197
|
+
let stxCssConfig = null;
|
|
198
|
+
try {
|
|
199
|
+
const { loadStxConfig } = await import("../config.js"), stxConfig = await loadStxConfig(resolveRoot);
|
|
200
|
+
if (stxConfig.css)
|
|
201
|
+
if (typeof stxConfig.css === "string") {
|
|
202
|
+
const configPath = path.isAbsolute(stxConfig.css) ? stxConfig.css : path.resolve(resolveRoot, stxConfig.css);
|
|
203
|
+
if (await Bun.file(configPath).exists()) {
|
|
204
|
+
const mod = await import(configPath);
|
|
205
|
+
stxCssConfig = mod.default || mod;
|
|
206
|
+
console.log(`${colors.green}[Crosswind]${colors.reset} Loaded config from stx.config.ts \u2192 ${stxConfig.css}`);
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
stxCssConfig = {
|
|
210
|
+
...stxConfig.css,
|
|
211
|
+
content: stxConfig.css.content || [],
|
|
212
|
+
preflight: stxConfig.css.preflight ?? !0,
|
|
213
|
+
minify: stxConfig.css.minify ?? !1
|
|
214
|
+
};
|
|
215
|
+
if (stxConfig.css.config) {
|
|
216
|
+
const configPath = path.isAbsolute(stxConfig.css.config) ? stxConfig.css.config : path.resolve(resolveRoot, stxConfig.css.config);
|
|
217
|
+
if (await Bun.file(configPath).exists()) {
|
|
218
|
+
const mod = await import(configPath);
|
|
219
|
+
stxCssConfig = { ...mod.default || mod, ...stxCssConfig };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
console.log(`${colors.green}[Crosswind]${colors.reset} Using inline CSS config from stx.config.ts`);
|
|
223
|
+
}
|
|
224
|
+
} catch {}
|
|
225
|
+
return stxCssConfig || await loadCrosswindConfig(resolveRoot);
|
|
226
|
+
}
|
|
227
|
+
export function fingerprintConfig(config) {
|
|
228
|
+
try {
|
|
229
|
+
const seen = new WeakSet;
|
|
230
|
+
return shortHash(JSON.stringify(config ?? {}, (_key, value) => {
|
|
231
|
+
if (typeof value === "function")
|
|
232
|
+
return `[fn]${String(value)}`;
|
|
233
|
+
if (typeof value === "object" && value !== null) {
|
|
234
|
+
if (seen.has(value))
|
|
235
|
+
return "[circular]";
|
|
236
|
+
seen.add(value);
|
|
237
|
+
}
|
|
238
|
+
return value;
|
|
239
|
+
}) ?? "");
|
|
240
|
+
} catch {
|
|
241
|
+
return "unhashable";
|
|
242
|
+
}
|
|
243
|
+
}
|
|
196
244
|
export async function buildCrosswindCSS(cwd) {
|
|
197
245
|
if (isBuilding)
|
|
198
246
|
return cachedCSS;
|
|
@@ -289,40 +337,8 @@ export async function generateCrosswindCSS(htmlContent, appDir) {
|
|
|
289
337
|
return onDisk;
|
|
290
338
|
}
|
|
291
339
|
if (!cachedConfig) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const { loadStxConfig } = await import("../config.js"), stxConfig = await loadStxConfig(resolveRoot);
|
|
295
|
-
if (stxConfig.css)
|
|
296
|
-
if (typeof stxConfig.css === "string") {
|
|
297
|
-
const configPath = path.isAbsolute(stxConfig.css) ? stxConfig.css : path.resolve(resolveRoot, stxConfig.css);
|
|
298
|
-
if (await Bun.file(configPath).exists()) {
|
|
299
|
-
const mod = await import(configPath);
|
|
300
|
-
stxCssConfig = mod.default || mod;
|
|
301
|
-
console.log(`${colors.green}[Crosswind]${colors.reset} Loaded config from stx.config.ts \u2192 ${stxConfig.css}`);
|
|
302
|
-
}
|
|
303
|
-
} else {
|
|
304
|
-
stxCssConfig = {
|
|
305
|
-
...stxConfig.css,
|
|
306
|
-
content: stxConfig.css.content || [],
|
|
307
|
-
preflight: stxConfig.css.preflight ?? !0,
|
|
308
|
-
minify: stxConfig.css.minify ?? !1
|
|
309
|
-
};
|
|
310
|
-
if (stxConfig.css.config) {
|
|
311
|
-
const configPath = path.isAbsolute(stxConfig.css.config) ? stxConfig.css.config : path.resolve(resolveRoot, stxConfig.css.config);
|
|
312
|
-
if (await Bun.file(configPath).exists()) {
|
|
313
|
-
const mod = await import(configPath);
|
|
314
|
-
stxCssConfig = { ...mod.default || mod, ...stxCssConfig };
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
console.log(`${colors.green}[Crosswind]${colors.reset} Using inline CSS config from stx.config.ts`);
|
|
318
|
-
}
|
|
319
|
-
} catch {}
|
|
320
|
-
cachedConfig = stxCssConfig || await loadCrosswindConfig(resolveRoot);
|
|
321
|
-
try {
|
|
322
|
-
configFingerprint = shortHash(JSON.stringify(cachedConfig ?? {}));
|
|
323
|
-
} catch {
|
|
324
|
-
configFingerprint = "unhashable";
|
|
325
|
-
}
|
|
340
|
+
cachedConfig = await resolveUserCrosswindConfig(resolveRoot);
|
|
341
|
+
configFingerprint = fingerprintConfig(cachedConfig);
|
|
326
342
|
}
|
|
327
343
|
const baseConfig = hw.defaultConfig || hw.config, userConfig = cachedConfig || {}, merged = mergeCrosswindConfig(baseConfig, userConfig), { safelist, includePreflight, minify, tokenCSS } = merged, crosswindConfig = merged.config, generator = new hw.CSSGenerator(crosswindConfig);
|
|
328
344
|
for (const cls of safelist)
|
package/dist/process.js
CHANGED
|
@@ -341,7 +341,7 @@ export async function processDirectives(template, context, filePath, options, de
|
|
|
341
341
|
} catch {}
|
|
342
342
|
if (isTopLevel)
|
|
343
343
|
try {
|
|
344
|
-
const { getComposableScript } = await importOnce("stx/composable-loader", () => import("./composable-loader.js")), resolvedComposablesDir = options.composablesDir, composableCode = await getComposableScript(resolvedComposablesDir);
|
|
344
|
+
const { getComposableScript } = await importOnce("stx/composable-loader", () => import("./composable-loader.js")), resolvedComposablesDir = options.composablesDir, composableCode = await getComposableScript(resolvedComposablesDir, result);
|
|
345
345
|
if (composableCode) {
|
|
346
346
|
const composableTag = `<script data-stx-composables>${composableCode}</script>`, anchor = findScriptBlockByAttribute(result, "data-stx-stores") || findScriptBlockByAttribute(result, "data-stx-runtime");
|
|
347
347
|
if (anchor)
|
|
@@ -500,15 +500,19 @@ ${joined}` : joined;
|
|
|
500
500
|
throw new StxRuntimeError(`Failed to resolve layout path: ${layoutPath}`, filePath, void 0, void 0, `Layout referenced from ${filePath}`);
|
|
501
501
|
});
|
|
502
502
|
if (!layoutFullPath) {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
503
|
+
const layoutsIn = (dir) => {
|
|
504
|
+
if (!dir)
|
|
505
|
+
return [];
|
|
506
|
+
try {
|
|
507
507
|
const abs = path.isAbsolute(dir) ? dir : path.resolve(process.cwd(), dir);
|
|
508
|
-
|
|
508
|
+
return fs.readdirSync(abs).filter((f) => f.endsWith(".stx")).map((f) => f.replace(/\.stx$/, ""));
|
|
509
|
+
} catch {
|
|
510
|
+
return [];
|
|
509
511
|
}
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
+
}, available = [
|
|
513
|
+
...layoutsIn(resolvedOptions.layoutsDir),
|
|
514
|
+
...layoutsIn(resolvedOptions.fallbackLayoutsDir)
|
|
515
|
+
].filter((name, index, all) => all.indexOf(name) === index).sort(), warning = `Layout not found: ${layoutPath} (referenced from ${filePath})` + (available.length > 0 ? `. Available layouts: ${available.join(", ")}` : resolvedOptions.layoutsDir ? `. No .stx layouts found in ${resolvedOptions.layoutsDir}` : "");
|
|
512
516
|
errorLogger.log(Error(warning), { layoutPath, filePath, available }, "error");
|
|
513
517
|
console.error(`[stx] ${warning}`);
|
|
514
518
|
if (resolvedOptions.debug)
|