@stacksjs/stx 0.2.101 → 0.2.102

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,4 +1,19 @@
1
1
  import type { BuiltinComponentDef } from '../component-registry';
2
+ /**
3
+ * Resolve the on-disk path of an icon collection JSON.
4
+ *
5
+ * Two packaging conventions are accepted. `@iconify/json` ships every
6
+ * collection in one ~120MB dependency; `@iconify-json/<prefix>` ships a single
7
+ * collection in about a megabyte and is what most projects actually install.
8
+ * Supporting only the monolith meant an app with `@iconify-json/lucide`
9
+ * installed rendered nothing at all for every icon on every page, with no
10
+ * error to explain it.
11
+ *
12
+ * Each convention is checked through the package resolver first, then against
13
+ * `node_modules/` and Stacks-style `pantry/` (which sits parallel to
14
+ * node_modules in apps that vendor there).
15
+ */
16
+ export declare function resolveCollectionPath(prefix: string): string | null;
2
17
  /**
3
18
  * Pre-load icon collections so they're available synchronously during render.
4
19
  * Call this before template processing starts.
@@ -1,25 +1,39 @@
1
1
  var {require}=import.meta;import { escapeAttr } from "./escape.js";
2
2
  import { existsSync, readFileSync } from "node:fs";
3
- const collectionCache = new Map;
4
- function resolveCollectionPath(prefix) {
5
- try {
6
- return require.resolve(`@iconify/json/json/${prefix}.json`);
7
- } catch {}
3
+ const collectionCache = new Map, warnedMissingCollections = new Set;
4
+ function warnMissingCollection(prefix) {
5
+ if (warnedMissingCollections.has(prefix))
6
+ return;
7
+ warnedMissingCollections.add(prefix);
8
+ console.warn(`[stx] icon collection "${prefix}" is not installed, so its icons render as nothing. Install it with \`bun add -d @iconify-json/${prefix}\`.`);
9
+ }
10
+ export function resolveCollectionPath(prefix) {
8
11
  const cwd = process.cwd();
9
12
  for (const candidate of [
13
+ `${cwd}/node_modules/@iconify-json/${prefix}/icons.json`,
14
+ `${cwd}/pantry/@iconify-json/${prefix}/icons.json`,
10
15
  `${cwd}/node_modules/@iconify/json/json/${prefix}.json`,
11
16
  `${cwd}/pantry/@iconify/json/json/${prefix}.json`
12
17
  ])
13
18
  if (existsSync(candidate))
14
19
  return candidate;
20
+ for (const specifier of [
21
+ `@iconify-json/${prefix}/icons.json`,
22
+ `@iconify/json/json/${prefix}.json`
23
+ ])
24
+ try {
25
+ return require.resolve(specifier);
26
+ } catch {}
15
27
  return null;
16
28
  }
17
29
  function loadCollectionSync(prefix) {
18
30
  if (collectionCache.has(prefix))
19
31
  return collectionCache.get(prefix);
20
32
  const jsonPath = resolveCollectionPath(prefix);
21
- if (!jsonPath)
33
+ if (!jsonPath) {
34
+ warnMissingCollection(prefix);
22
35
  return null;
36
+ }
23
37
  try {
24
38
  const data = JSON.parse(readFileSync(jsonPath, "utf8"));
25
39
  collectionCache.set(prefix, data.icons);
@@ -32,8 +46,10 @@ async function loadCollection(prefix) {
32
46
  if (collectionCache.has(prefix))
33
47
  return collectionCache.get(prefix);
34
48
  const jsonPath = resolveCollectionPath(prefix);
35
- if (!jsonPath)
49
+ if (!jsonPath) {
50
+ warnMissingCollection(prefix);
36
51
  return null;
52
+ }
37
53
  try {
38
54
  const data = await Bun.file(jsonPath).json();
39
55
  collectionCache.set(prefix, data.icons);