@velastack/patterns 0.4.3 → 0.5.0
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/README.md +22 -2
- package/dist/chunks/{_page-e_I-fdSR.js → _page-DoPdZgZv.js} +2 -2
- package/dist/chunks/_page-DoPdZgZv.js.map +1 -0
- package/dist/chunks/collections-Cpjo2OiQ.js +203 -0
- package/dist/chunks/collections-Cpjo2OiQ.js.map +1 -0
- package/dist/chunks/dispatch-BIvOwbKN.js +6 -0
- package/dist/chunks/dispatch-BIvOwbKN.js.map +1 -0
- package/dist/chunks/{env-vars-CcE6ODqC.js → env-vars-Bj41Nccm.js} +32 -20
- package/dist/chunks/env-vars-Bj41Nccm.js.map +1 -0
- package/dist/chunks/generate-BClgUH4J.js +137 -0
- package/dist/chunks/generate-BClgUH4J.js.map +1 -0
- package/dist/chunks/{generate-CZGHByV3.js → generate-DjBMRzsB.js} +6 -6
- package/dist/chunks/{generate-CZGHByV3.js.map → generate-DjBMRzsB.js.map} +1 -1
- package/dist/chunks/{generate-DetW_gbr.js → generate-DyV5R8NP.js} +7 -7
- package/dist/chunks/{generate-DetW_gbr.js.map → generate-DyV5R8NP.js.map} +1 -1
- package/dist/chunks/generate-ZIOVLH6Q.js +72 -0
- package/dist/chunks/generate-ZIOVLH6Q.js.map +1 -0
- package/dist/chunks/{generate-Bg0E3eWm.js → generate-dNlBII84.js} +4 -4
- package/dist/chunks/{generate-Bg0E3eWm.js.map → generate-dNlBII84.js.map} +1 -1
- package/dist/chunks/{generate-CFqpRi9D.js → generate-yi8AP3xH.js} +4 -4
- package/dist/chunks/{generate-CFqpRi9D.js.map → generate-yi8AP3xH.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CpMKXBkn.js → generate.runtime-B4QoBn5v.js} +6 -6
- package/dist/chunks/{generate.runtime-CpMKXBkn.js.map → generate.runtime-B4QoBn5v.js.map} +1 -1
- package/dist/chunks/{generate.runtime-aQnBmH8D.js → generate.runtime-BKINIJ2c.js} +3 -3
- package/dist/chunks/{generate.runtime-aQnBmH8D.js.map → generate.runtime-BKINIJ2c.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Dl6OQ7pe.js → generate.runtime-BKTkVCEm.js} +4 -4
- package/dist/chunks/{generate.runtime-Dl6OQ7pe.js.map → generate.runtime-BKTkVCEm.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CAn1qIQ_.js → generate.runtime-BXZDKLbA.js} +3 -3
- package/dist/chunks/{generate.runtime-CAn1qIQ_.js.map → generate.runtime-BXZDKLbA.js.map} +1 -1
- package/dist/chunks/{generate.runtime-hTKzxH2M.js → generate.runtime-BYfyZHhs.js} +7 -7
- package/dist/chunks/{generate.runtime-hTKzxH2M.js.map → generate.runtime-BYfyZHhs.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DoZJHtZh.js → generate.runtime-BavEh01F.js} +6 -6
- package/dist/chunks/{generate.runtime-DoZJHtZh.js.map → generate.runtime-BavEh01F.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DJ9MVVPC.js → generate.runtime-BcgjZJug.js} +123 -110
- package/dist/chunks/generate.runtime-BcgjZJug.js.map +1 -0
- package/dist/chunks/generate.runtime-BdHv7Jp1.js +82 -0
- package/dist/chunks/generate.runtime-BdHv7Jp1.js.map +1 -0
- package/dist/chunks/{generate.runtime-CqncBFNg.js → generate.runtime-BdmoAVJK.js} +4 -4
- package/dist/chunks/{generate.runtime-CqncBFNg.js.map → generate.runtime-BdmoAVJK.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BpMN5Uq-.js → generate.runtime-Bdpu4rX0.js} +3 -3
- package/dist/chunks/{generate.runtime-BpMN5Uq-.js.map → generate.runtime-Bdpu4rX0.js.map} +1 -1
- package/dist/chunks/{generate.runtime-uLUiPgqx.js → generate.runtime-C7s1Mx5L.js} +6 -6
- package/dist/chunks/{generate.runtime-uLUiPgqx.js.map → generate.runtime-C7s1Mx5L.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CEqLgLT9.js → generate.runtime-CCV4O6_I.js} +3 -3
- package/dist/chunks/{generate.runtime-CEqLgLT9.js.map → generate.runtime-CCV4O6_I.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CK10Mum5.js → generate.runtime-CSUnP0l-.js} +10 -10
- package/dist/chunks/{generate.runtime-CK10Mum5.js.map → generate.runtime-CSUnP0l-.js.map} +1 -1
- package/dist/chunks/{generate.runtime-koQxLywh.js → generate.runtime-CV4soy2n.js} +6 -6
- package/dist/chunks/{generate.runtime-koQxLywh.js.map → generate.runtime-CV4soy2n.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Db0HZyj3.js → generate.runtime-CWgZhxQt.js} +2 -2
- package/dist/chunks/{generate.runtime-Db0HZyj3.js.map → generate.runtime-CWgZhxQt.js.map} +1 -1
- package/dist/chunks/{generate.runtime-IWEhGhWY.js → generate.runtime-CcPCAEV0.js} +6 -6
- package/dist/chunks/{generate.runtime-IWEhGhWY.js.map → generate.runtime-CcPCAEV0.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DJHUBL4Z.js → generate.runtime-D-qtaVdq.js} +2 -2
- package/dist/chunks/{generate.runtime-DJHUBL4Z.js.map → generate.runtime-D-qtaVdq.js.map} +1 -1
- package/dist/chunks/{generate.runtime-E-zoeSKW.js → generate.runtime-DBBtYTAa.js} +7 -7
- package/dist/chunks/{generate.runtime-E-zoeSKW.js.map → generate.runtime-DBBtYTAa.js.map} +1 -1
- package/dist/chunks/{generate.runtime-5rIc-RNL.js → generate.runtime-DRRyPa-e.js} +6 -6
- package/dist/chunks/{generate.runtime-5rIc-RNL.js.map → generate.runtime-DRRyPa-e.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BK3mR0Rj.js → generate.runtime-DaRVyiSg.js} +148 -127
- package/dist/chunks/generate.runtime-DaRVyiSg.js.map +1 -0
- package/dist/chunks/{generate.runtime-DVB7uuht.js → generate.runtime-DetYynf4.js} +3 -3
- package/dist/chunks/{generate.runtime-DVB7uuht.js.map → generate.runtime-DetYynf4.js.map} +1 -1
- package/dist/chunks/{generate.runtime-a3R4hqFy.js → generate.runtime-DjCzW3zU.js} +12 -12
- package/dist/chunks/{generate.runtime-a3R4hqFy.js.map → generate.runtime-DjCzW3zU.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Djas9UNy.js → generate.runtime-DlbG-8Xm.js} +4 -4
- package/dist/chunks/{generate.runtime-Djas9UNy.js.map → generate.runtime-DlbG-8Xm.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CbE9RHcf.js → generate.runtime-DmsOEsJV.js} +5 -5
- package/dist/chunks/generate.runtime-DmsOEsJV.js.map +1 -0
- package/dist/chunks/{generate.runtime-axm9wcQv.js → generate.runtime-MjWwR2Bd.js} +3 -3
- package/dist/chunks/{generate.runtime-axm9wcQv.js.map → generate.runtime-MjWwR2Bd.js.map} +1 -1
- package/dist/chunks/generate.runtime-NaSIZlP5.js +48 -0
- package/dist/chunks/generate.runtime-NaSIZlP5.js.map +1 -0
- package/dist/chunks/{generate.runtime-CZ46nkSL.js → generate.runtime-OEgsdWRP.js} +2 -2
- package/dist/chunks/{generate.runtime-CZ46nkSL.js.map → generate.runtime-OEgsdWRP.js.map} +1 -1
- package/dist/chunks/{generate.runtime-rs1ZOIET.js → generate.runtime-QbmCPT42.js} +3 -3
- package/dist/chunks/{generate.runtime-rs1ZOIET.js.map → generate.runtime-QbmCPT42.js.map} +1 -1
- package/dist/chunks/generate.runtime-azOvp6tl.js +106 -0
- package/dist/chunks/generate.runtime-azOvp6tl.js.map +1 -0
- package/dist/chunks/{generate.runtime-kciwaXxh.js → generate.runtime-b2RtuPy4.js} +4 -4
- package/dist/chunks/{generate.runtime-kciwaXxh.js.map → generate.runtime-b2RtuPy4.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Bcrht4M9.js → generate.runtime-pMpn0Pbf.js} +2 -2
- package/dist/chunks/{generate.runtime-Bcrht4M9.js.map → generate.runtime-pMpn0Pbf.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DHHlYfTD.js → generate.runtime-utFLS6Jz.js} +3 -3
- package/dist/chunks/{generate.runtime-DHHlYfTD.js.map → generate.runtime-utFLS6Jz.js.map} +1 -1
- package/dist/chunks/modify-file-Bbhyfiy_.js +53 -0
- package/dist/chunks/modify-file-Bbhyfiy_.js.map +1 -0
- package/dist/chunks/{modify-nav-user-BLyrW2sK.js → modify-nav-user-B8h8WTrM.js} +2 -2
- package/dist/chunks/{modify-nav-user-BLyrW2sK.js.map → modify-nav-user-B8h8WTrM.js.map} +1 -1
- package/dist/chunks/providers-CL9kQ4hp.js +98 -0
- package/dist/chunks/providers-CL9kQ4hp.js.map +1 -0
- package/dist/chunks/providers-DwbwccSW.js +38 -0
- package/dist/chunks/providers-DwbwccSW.js.map +1 -0
- package/dist/chunks/{shared-Cc_ns5-y.js → shared-D5GOS97l.js} +2 -2
- package/dist/chunks/{shared-Cc_ns5-y.js.map → shared-D5GOS97l.js.map} +1 -1
- package/dist/chunks/shopify-page-D-VFwGxI.js +11 -0
- package/dist/chunks/shopify-page-D-VFwGxI.js.map +1 -0
- package/dist/chunks/stripe-customer-B3tP8gtD.js +6 -0
- package/dist/chunks/stripe-customer-B3tP8gtD.js.map +1 -0
- package/dist/chunks/{svelte-file-B3RfgVdt.js → svelte-file-Dv5-bl79.js} +37 -2
- package/dist/chunks/svelte-file-Dv5-bl79.js.map +1 -0
- package/dist/chunks/{test-setup-B9fQ5L_-.js → test-setup-DZoyF8Ak.js} +2 -2
- package/dist/chunks/{test-setup-B9fQ5L_-.js.map → test-setup-DZoyF8Ak.js.map} +1 -1
- package/dist/chunks/{ui-CuCsupFq.js → ui-BuocThuh.js} +2 -2
- package/dist/chunks/{ui-CuCsupFq.js.map → ui-BuocThuh.js.map} +1 -1
- package/dist/chunks/{write-result-DiZsCS_y.js → write-result-Cq-9A7Zy.js} +2 -2
- package/dist/chunks/write-result-Cq-9A7Zy.js.map +1 -0
- package/dist/index.d.ts +283 -22
- package/dist/index.js +2199 -2035
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/_page-e_I-fdSR.js.map +0 -1
- package/dist/chunks/collections-zzZ_HQxB.js +0 -192
- package/dist/chunks/collections-zzZ_HQxB.js.map +0 -1
- package/dist/chunks/dispatch-D4TN9pdW.js +0 -6
- package/dist/chunks/dispatch-D4TN9pdW.js.map +0 -1
- package/dist/chunks/env-vars-CcE6ODqC.js.map +0 -1
- package/dist/chunks/env-vars-De0Xs0L2.js +0 -20
- package/dist/chunks/env-vars-De0Xs0L2.js.map +0 -1
- package/dist/chunks/generate.runtime-BK3mR0Rj.js.map +0 -1
- package/dist/chunks/generate.runtime-CbE9RHcf.js.map +0 -1
- package/dist/chunks/generate.runtime-DJ9MVVPC.js.map +0 -1
- package/dist/chunks/generate.runtime-EQnytCFL.js +0 -122
- package/dist/chunks/generate.runtime-EQnytCFL.js.map +0 -1
- package/dist/chunks/modify-file-DK-tCH9k.js +0 -46
- package/dist/chunks/modify-file-DK-tCH9k.js.map +0 -1
- package/dist/chunks/providers-BHR6-XZ7.js +0 -76
- package/dist/chunks/providers-BHR6-XZ7.js.map +0 -1
- package/dist/chunks/svelte-file-B3RfgVdt.js.map +0 -1
- package/dist/chunks/write-result-DiZsCS_y.js.map +0 -1
|
@@ -36,7 +36,7 @@ var r = class r {
|
|
|
36
36
|
return n !== e.content && (this.s.overwrite(e.start, e.end, n), !0);
|
|
37
37
|
}
|
|
38
38
|
findElement(e) {
|
|
39
|
-
return
|
|
39
|
+
return a(this.ast.fragment, (t) => (t.type === "Component" || t.type === "RegularElement") && t.name === e);
|
|
40
40
|
}
|
|
41
41
|
hasElement(e) {
|
|
42
42
|
return this.findElement(e) !== null;
|
|
@@ -58,6 +58,38 @@ var r = class r {
|
|
|
58
58
|
removeElement(e) {
|
|
59
59
|
return this.replaceElement(e, "");
|
|
60
60
|
}
|
|
61
|
+
findElementContaining(e, t) {
|
|
62
|
+
return a(this.ast.fragment, (n) => i(n, e) && a(n.fragment, (e) => i(e, t)) !== null);
|
|
63
|
+
}
|
|
64
|
+
childElements(e, t) {
|
|
65
|
+
return (this.findElement(e)?.fragment?.nodes ?? []).filter((e) => i(e, t));
|
|
66
|
+
}
|
|
67
|
+
insertBeforeElement(e, t) {
|
|
68
|
+
let n = this.indentOf(e.start);
|
|
69
|
+
this.s.appendLeft(e.start, `${this.reindent(t, n)}\n${n}`);
|
|
70
|
+
}
|
|
71
|
+
insertAfterElement(e, t) {
|
|
72
|
+
let n = this.indentOf(e.start);
|
|
73
|
+
this.s.appendLeft(e.end, `\n${n}${this.reindent(t, n)}`);
|
|
74
|
+
}
|
|
75
|
+
removeElementContaining(e, t) {
|
|
76
|
+
let n = this.findElementContaining(e, t);
|
|
77
|
+
if (!n) return !1;
|
|
78
|
+
let r = n.start;
|
|
79
|
+
for (; r > 0 && /[ \t]/.test(this.source[r - 1]);) r--;
|
|
80
|
+
return r > 0 && this.source[r - 1] === "\n" && r--, this.s.remove(r, n.end), !0;
|
|
81
|
+
}
|
|
82
|
+
indentOf(e) {
|
|
83
|
+
let t = this.source.lastIndexOf("\n", e - 1) + 1, n = this.source.slice(t, e);
|
|
84
|
+
return /^[ \t]*$/.test(n) ? n : "";
|
|
85
|
+
}
|
|
86
|
+
reindent(e, t) {
|
|
87
|
+
let n = t.includes(" ") ? " " : " ";
|
|
88
|
+
return e.split("\n").map((e, r) => {
|
|
89
|
+
let i = e.replace(/^\t+/, (e) => n.repeat(e.length));
|
|
90
|
+
return r === 0 ? i : `${t}${i}`;
|
|
91
|
+
}).join("\n");
|
|
92
|
+
}
|
|
61
93
|
appendMarkup(e) {
|
|
62
94
|
this.s.append(e);
|
|
63
95
|
}
|
|
@@ -97,6 +129,9 @@ var r = class r {
|
|
|
97
129
|
}
|
|
98
130
|
};
|
|
99
131
|
function i(e, t) {
|
|
132
|
+
return (e?.type === "Component" || e?.type === "RegularElement") && e.name === t;
|
|
133
|
+
}
|
|
134
|
+
function a(e, t) {
|
|
100
135
|
let n = /* @__PURE__ */ new WeakSet();
|
|
101
136
|
function r(e) {
|
|
102
137
|
if (!e || typeof e != "object" || n.has(e)) return null;
|
|
@@ -120,4 +155,4 @@ function i(e, t) {
|
|
|
120
155
|
//#endregion
|
|
121
156
|
export { r as t };
|
|
122
157
|
|
|
123
|
-
//# sourceMappingURL=svelte-file-
|
|
158
|
+
//# sourceMappingURL=svelte-file-Dv5-bl79.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte-file-Dv5-bl79.js","names":["fs","MagicString","SvelteFile","source","parse","filePath","script","start","end","fn","block","next","findNode","node","name","componentName","attr","attrName","closingTag","closingPos","content","newContent","isElement","outer","child","inner","candidate","indent","lineStart","pos","lead","unit","nested","line","tabs","i","nodes","index","trimmed","prev","last","insertAt","attrs","a","seen","visit","predicate","key","item","found","root"],"sources":["../../src/runtime/svelte-file.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { parse, type AST } from \"svelte/compiler\";\nimport MagicString from \"magic-string\";\n\ntype SvelteAst = AST.Root;\ntype SvelteNode = any;\n\ninterface ScriptBlock {\n content: string;\n start: number;\n end: number;\n}\n\n/**\n * Surgical, AST-aware editing of .svelte files.\n *\n * Parses the source with svelte/compiler to discover precise character offsets,\n * then applies edits via magic-string so untouched regions remain byte-for-byte\n * identical to the original. Script-block contents are exposed as plain strings\n * so callers can hand them to ts-morph.\n */\nexport class SvelteFile {\n private readonly source: string;\n private readonly ast: SvelteAst;\n private readonly s: MagicString;\n\n constructor(source: string) {\n this.source = source;\n this.ast = parse(source, { modern: true });\n this.s = new MagicString(source);\n }\n\n static fromPath(filePath: string): SvelteFile {\n return new SvelteFile(fs.readFileSync(filePath, \"utf8\"));\n }\n\n getScript(): ScriptBlock | null {\n return this.scriptInner((this.ast as any).instance);\n }\n\n getModuleScript(): ScriptBlock | null {\n return this.scriptInner((this.ast as any).module);\n }\n\n private scriptInner(script: SvelteNode | null): ScriptBlock | null {\n if (!script) return null;\n const start = script.content.start as number;\n const end = script.content.end as number;\n return { content: this.source.slice(start, end), start, end };\n }\n\n /**\n * Replace the inner contents of <script>. Use for ts-morph round-trips.\n * Returns true when an edit was made.\n */\n modifyScript(fn: (content: string) => string): boolean {\n return this.modifyScriptBlock(this.getScript(), fn);\n }\n\n modifyModuleScript(fn: (content: string) => string): boolean {\n return this.modifyScriptBlock(this.getModuleScript(), fn);\n }\n\n private modifyScriptBlock(\n block: ScriptBlock | null,\n fn: (content: string) => string,\n ): boolean {\n if (!block) return false;\n const next = fn(block.content);\n if (next === block.content) return false;\n this.s.overwrite(block.start, block.end, next);\n return true;\n }\n\n /** First Component or RegularElement node with the given name. */\n findElement(name: string): SvelteNode | null {\n return findNode(\n (this.ast as any).fragment,\n (node) =>\n (node.type === \"Component\" || node.type === \"RegularElement\") &&\n node.name === name,\n );\n }\n\n hasElement(name: string): boolean {\n return this.findElement(name) !== null;\n }\n\n hasAttribute(componentName: string, attrName: string): boolean {\n const node = this.findElement(componentName);\n if (!node) return false;\n return (node.attributes ?? []).some(\n (attr: SvelteNode) => attr.type === \"Attribute\" && attr.name === attrName,\n );\n }\n\n /**\n * Insert content at the end of <ComponentName>'s children, just before the\n * closing tag. No-op if the element is not found.\n */\n insertBeforeClosingTag(name: string, content: string): boolean {\n const node = this.findElement(name);\n if (!node) return false;\n const closingTag = `</${name}>`;\n const closingPos = this.source.lastIndexOf(closingTag, node.end);\n if (closingPos === -1) return false;\n this.s.appendLeft(closingPos, content);\n return true;\n }\n\n /** Replace the element entirely (start tag through close tag). */\n replaceElement(name: string, newContent: string): boolean {\n const node = this.findElement(name);\n if (!node) return false;\n this.s.overwrite(node.start, node.end, newContent);\n return true;\n }\n\n /** Remove the element (start tag through close tag). */\n removeElement(name: string): boolean {\n return this.replaceElement(name, \"\");\n }\n\n /**\n * The first <outer> element with an <inner> element somewhere inside it:\n * the `Navbar.Item` that holds `AuthMenu.Root`, among several items.\n */\n findElementContaining(outer: string, inner: string): SvelteNode | null {\n return findNode(\n (this.ast as any).fragment,\n (node) =>\n isElement(node, outer) &&\n findNode(node.fragment, (child) => isElement(child, inner)) !== null,\n );\n }\n\n /** The <child> elements directly inside the first <name> element, in order. */\n childElements(name: string, child: string): SvelteNode[] {\n const node = this.findElement(name);\n const nodes: SvelteNode[] = node?.fragment?.nodes ?? [];\n return nodes.filter((candidate) => isElement(candidate, child));\n }\n\n /**\n * Put `content` on its own line directly before `node`, at `node`'s\n * indentation. Lines after the first are indented to match too, with their\n * leading tabs turned into the file's indent unit.\n */\n insertBeforeElement(node: SvelteNode, content: string): void {\n const indent = this.indentOf(node.start as number);\n this.s.appendLeft(\n node.start as number,\n `${this.reindent(content, indent)}\\n${indent}`,\n );\n }\n\n /** Like `insertBeforeElement`, on the line after `node`. */\n insertAfterElement(node: SvelteNode, content: string): void {\n const indent = this.indentOf(node.start as number);\n this.s.appendLeft(\n node.end as number,\n `\\n${indent}${this.reindent(content, indent)}`,\n );\n }\n\n /**\n * Remove the first <outer> containing <inner>, and the line it stood on\n * when nothing else shared it. Returns false when there is none.\n */\n removeElementContaining(outer: string, inner: string): boolean {\n const node = this.findElementContaining(outer, inner);\n if (!node) return false;\n let start = node.start as number;\n while (start > 0 && /[ \\t]/.test(this.source[start - 1]!)) start--;\n if (start > 0 && this.source[start - 1] === \"\\n\") start--;\n this.s.remove(start, node.end as number);\n return true;\n }\n\n /** The whitespace between the start of `pos`'s line and `pos`. */\n private indentOf(pos: number): string {\n const lineStart = this.source.lastIndexOf(\"\\n\", pos - 1) + 1;\n const lead = this.source.slice(lineStart, pos);\n return /^[ \\t]*$/.test(lead) ? lead : \"\";\n }\n\n private reindent(content: string, indent: string): string {\n const unit = indent.includes(\" \") ? \" \" : \"\\t\";\n return content\n .split(\"\\n\")\n .map((line, i) => {\n const nested = line.replace(/^\\t+/, (tabs) => unit.repeat(tabs.length));\n return i === 0 ? nested : `${indent}${nested}`;\n })\n .join(\"\\n\");\n }\n\n /** Append raw markup to the end of the source file. */\n appendMarkup(content: string): void {\n this.s.append(content);\n }\n\n /**\n * Insert markup so it renders before the layout's children — i.e. ahead of\n * the top-level `{@render children()}` (or legacy `<slot />`). The markup\n * lands on its own line directly after the preceding sibling, so\n *\n * <Toaster />\n *\n * {@render children?.()}\n *\n * becomes `<Toaster />\\n<AdminBar />\\n\\n{@render children?.()}`. When the\n * render tag is the first node the markup goes immediately before it.\n * Returns false (and changes nothing) if no such tag exists.\n */\n insertBeforeChildren(content: string): boolean {\n const nodes: SvelteNode[] = (this.ast as any).fragment?.nodes ?? [];\n const index = nodes.findIndex(\n (node) =>\n node.type === \"RenderTag\" ||\n node.type === \"SlotElement\" ||\n (node.type === \"RegularElement\" && node.name === \"slot\"),\n );\n if (index === -1) return false;\n\n const trimmed = content.trim();\n for (let i = index - 1; i >= 0; i--) {\n const prev = nodes[i]!;\n if (prev.type === \"Text\" && prev.data.trim() === \"\") continue;\n this.s.appendLeft(prev.end as number, `\\n${trimmed}`);\n return true;\n }\n this.s.appendLeft(nodes[index]!.start as number, `${trimmed}\\n\\n`);\n return true;\n }\n\n /**\n * Append attribute text (e.g. \" team={data.team}\") just after the last\n * existing attribute on the element's start tag.\n */\n appendToAttributes(name: string, attrs: string): boolean {\n const node = this.findElement(name);\n if (!node) return false;\n const last = (node.attributes ?? []).at(-1) as SvelteNode | undefined;\n const insertAt = last\n ? (last.end as number)\n : (node.start as number) + `<${name}`.length;\n this.s.appendLeft(insertAt, attrs);\n return true;\n }\n\n /**\n * Remove a named attribute from a component's start tag, including the\n * leading whitespace. No-op if the element or attribute isn't present.\n */\n removeAttribute(name: string, attrName: string): boolean {\n const node = this.findElement(name);\n if (!node) return false;\n const attr = (node.attributes ?? []).find(\n (a: SvelteNode) => a.type === \"Attribute\" && a.name === attrName,\n );\n if (!attr) return false;\n // Extend the removal backwards over the whitespace between the previous\n // token and this attribute so the tag doesn't collapse `<Foo />`.\n let start = attr.start as number;\n while (start > 0 && /\\s/.test(this.source[start - 1]!)) start--;\n this.s.remove(start, attr.end as number);\n return true;\n }\n\n hasChanged(): boolean {\n return this.s.hasChanged();\n }\n\n toString(): string {\n return this.s.toString();\n }\n\n writeTo(filePath: string): void {\n if (this.hasChanged()) {\n fs.writeFileSync(filePath, this.toString(), \"utf8\");\n }\n }\n}\n\nfunction isElement(node: any, name: string): boolean {\n return (\n (node?.type === \"Component\" || node?.type === \"RegularElement\") &&\n node.name === name\n );\n}\n\nfunction findNode(\n root: unknown,\n predicate: (node: any) => boolean,\n): any | null {\n const seen = new WeakSet<object>();\n function visit(node: unknown): any | null {\n if (!node || typeof node !== \"object\" || seen.has(node as object)) {\n return null;\n }\n seen.add(node as object);\n if (predicate(node as any)) return node;\n for (const key of Object.keys(node as Record<string, unknown>)) {\n if (key === \"parent\") continue;\n const child = (node as Record<string, unknown>)[key];\n if (Array.isArray(child)) {\n for (const item of child) {\n const found = visit(item);\n if (found) return found;\n }\n } else if (\n child &&\n typeof child === \"object\" &&\n \"type\" in (child as object)\n ) {\n const found = visit(child);\n if (found) return found;\n }\n }\n return null;\n }\n return visit(root);\n}\n"],"mappings":";;;;AAqBA,IAAaE,IAAb,MAAaA,EAAW;CAKtB,YAAY,GAAgB;EAG1B,AAFA,KAAK,SAASC,GACd,KAAK,MAAMC,EAAMD,GAAQ,EAAE,QAAQ,GAAK,CAAC,GACzC,KAAK,IAAI,IAAIF,EAAYE,CAAM;CACjC;CAEA,OAAO,SAAS,GAA8B;EAC5C,OAAO,IAAID,EAAWF,EAAG,aAAaK,GAAU,MAAM,CAAC;CACzD;CAEA,YAAgC;EAC9B,OAAO,KAAK,YAAa,KAAK,IAAY,QAAQ;CACpD;CAEA,kBAAsC;EACpC,OAAO,KAAK,YAAa,KAAK,IAAY,MAAM;CAClD;CAEA,YAAoB,GAA+C;EACjE,IAAI,CAACC,GAAQ,OAAO;EACpB,IAAMC,IAAQD,EAAO,QAAQ,OACvBE,IAAMF,EAAO,QAAQ;EAC3B,OAAO;GAAE,SAAS,KAAK,OAAO,MAAMC,GAAOC,CAAG;GAAG;GAAO;EAA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
|
1
1
|
import { n as e, t } from "./constants-Rq8SCXwH.js";
|
|
2
2
|
import { t as n } from "./dedent-Gq6Krl4n.js";
|
|
3
3
|
import { o as r, s as i } from "./config-target-rHgjaA8u.js";
|
|
4
|
-
import { c as a } from "./write-result-
|
|
4
|
+
import { c as a } from "./write-result-Cq-9A7Zy.js";
|
|
5
5
|
import o from "node:fs";
|
|
6
6
|
import s from "node:path";
|
|
7
7
|
import { SyntaxKind as c } from "ts-morph";
|
|
@@ -176,4 +176,4 @@ function O(e) {
|
|
|
176
176
|
//#endregion
|
|
177
177
|
export { O as a, g as c, D as i, _ as l, S as n, b as o, E as r, x as s, w as t };
|
|
178
178
|
|
|
179
|
-
//# sourceMappingURL=test-setup-
|
|
179
|
+
//# sourceMappingURL=test-setup-DZoyF8Ak.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-setup-B9fQ5L_-.js","names":["ADAPTER_NODE_SPEC","ADAPTER_STATIC_SPEC","NOT_FOUND_HINT","ADAPTER_STATIC$1","dedent","resolveConfigTarget","saveTarget","packageName","fs","path","ADAPTER_NODE","ADAPTER_NODE$1","ADAPTER_STATIC","ADAPTER_AUTO","FAILURE_HINT","NOT_FOUND_HINT$1","findAdapterImport","sourceFile","decl","adapterCalls","SyntaxKind","ce","modifySvelteConfig","res","root","adapterImport","target","call","args","i","unmodifySvelteConfig","POCKETBASE_BLOCK","NOT_FOUND_HINT","modifyGitignore","gitignorePath","original","next","unmodifyGitignore","cleaned","WITH_BACKEND","WITHOUT_BACKEND","VITEST_CONFIG","VITEST_CONFIG_NAMES","ext","hasVitestConfig","name","viteConfig","modifyTestSetup","testSetupPath","unmodifyTestSetup"],"sources":["../../src/patterns/enable/backend/modifies/svelte-config.ts","../../src/patterns/enable/backend/modifies/gitignore.ts","../../src/patterns/enable/backend/modifies/test-setup.ts"],"sourcesContent":["import dedent from \"dedent\";\nimport { SyntaxKind } from \"ts-morph\";\nimport {\n resolveConfigTarget,\n saveTarget,\n type ConfigModifyResult,\n type ConfigTarget,\n} from \"../../../../runtime/config-target\";\nimport { packageName } from \"../../../../runtime/write-result\";\nimport {\n ADAPTER_NODE as ADAPTER_NODE_SPEC,\n ADAPTER_STATIC as ADAPTER_STATIC_SPEC,\n} from \"../../../../core/constants\";\n\n// Imports name the package, not the versioned spec the constants install.\nconst ADAPTER_NODE = packageName(ADAPTER_NODE_SPEC);\nconst ADAPTER_STATIC = packageName(ADAPTER_STATIC_SPEC);\nconst ADAPTER_AUTO = \"@sveltejs/adapter-auto\";\n\nconst FAILURE_HINT = dedent`\n Switch the SvelteKit adapter to ${ADAPTER_NODE}:\n\n import adapter from '${ADAPTER_NODE}';\n\n // ...\n adapter: adapter()\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Configure ${ADAPTER_NODE} via the sveltekit() plugin in vite.config.ts.\n`;\n\n/**\n * The adapters this pattern moves between. adapter-auto is included because\n * that is what `sv create` ships, and a project that never chose is one the\n * backend is free to decide for.\n */\nfunction findAdapterImport(sourceFile: ConfigTarget[\"sourceFile\"]) {\n return sourceFile\n .getImportDeclarations()\n .find((decl) =>\n [ADAPTER_STATIC, ADAPTER_AUTO, ADAPTER_NODE].includes(\n decl.getModuleSpecifierValue(),\n ),\n );\n}\n\nfunction adapterCalls(sourceFile: ConfigTarget[\"sourceFile\"]) {\n return sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((ce) => ce.getExpression().getText() === \"adapter\");\n}\n\n/**\n * Switch the adapter to `@sveltejs/adapter-node` and drop its arguments in\n * vite.config, which holds the adapter import + `adapter()` call. A project with a\n * backend is served from a Node process, which is what `vela deploy` runs.\n * Operates on the import and call expression directly, so it never needs the\n * config object.\n */\nexport function modifySvelteConfig(root: string): ConfigModifyResult {\n const res = resolveConfigTarget(root, {\n notFound: NOT_FOUND_HINT,\n failed: FAILURE_HINT,\n });\n if (res.status !== \"resolved\") {\n return {\n filePath: res.filePath,\n outcome: { status: res.status, message: res.message },\n };\n }\n const { target } = res;\n const adapterImport = findAdapterImport(target.sourceFile);\n if (!adapterImport) {\n return {\n filePath: target.filePath,\n outcome: { status: \"failed\", message: FAILURE_HINT },\n };\n }\n\n if (adapterImport.getModuleSpecifierValue() !== ADAPTER_NODE) {\n adapterImport.setModuleSpecifier(ADAPTER_NODE);\n }\n\n for (const call of adapterCalls(target.sourceFile)) {\n const args = call.getArguments();\n for (let i = args.length - 1; i >= 0; i--) {\n call.removeArgument(i);\n }\n }\n\n return { filePath: target.filePath, outcome: saveTarget(target) };\n}\n\n/**\n * Reverse of {@link modifySvelteConfig}: switch back to\n * `@sveltejs/adapter-static` and restore the `{ fallback: '200.html' }` arg.\n * Lenient when there is no config or no adapter import: a no-op success. A\n * config that can't be edited (a leftover svelte.config) still fails.\n */\nexport function unmodifySvelteConfig(root: string): ConfigModifyResult {\n const res = resolveConfigTarget(root, {\n notFound: NOT_FOUND_HINT,\n failed: FAILURE_HINT,\n });\n if (res.status === \"not-found\") {\n // Nothing to revert.\n return {\n filePath: res.filePath,\n outcome: { status: \"success\", changed: false },\n };\n }\n if (res.status === \"failed\") {\n return {\n filePath: res.filePath,\n outcome: { status: \"failed\", message: res.message },\n };\n }\n const { target } = res;\n const adapterImport = findAdapterImport(target.sourceFile);\n if (!adapterImport) {\n return {\n filePath: target.filePath,\n outcome: { status: \"success\", changed: false },\n };\n }\n\n if (adapterImport.getModuleSpecifierValue() !== ADAPTER_STATIC) {\n adapterImport.setModuleSpecifier(ADAPTER_STATIC);\n }\n\n for (const call of adapterCalls(target.sourceFile)) {\n if (call.getArguments().length === 0) {\n call.addArgument(\"{ fallback: '200.html' }\");\n }\n }\n\n return { filePath: target.filePath, outcome: saveTarget(target) };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst POCKETBASE_BLOCK = `# PocketBase\n/data/*\n!/data/fixtures\n!/data/seeds\n!/data/hooks\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create a .gitignore at the project root with the PocketBase block:\n\n # PocketBase\n /data/*\n !/data/fixtures\n !/data/seeds\n !/data/hooks\n`;\n\nexport function modifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n\n if (original.includes(\"# PocketBase\") && original.includes(\"/data/*\")) {\n return { status: \"success\", changed: false };\n }\n\n const separator = original.endsWith(\"\\n\") ? \"\\n\" : \"\\n\\n\";\n const next = original + separator + POCKETBASE_BLOCK;\n fs.writeFileSync(gitignorePath, next, \"utf8\");\n\n return { status: \"success\", changed: true };\n}\n\nexport function unmodifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n\n if (!original.includes(\"# PocketBase\")) {\n return { status: \"success\", changed: false };\n }\n\n const withBlockRemoved = original.replace(\n /\\n*# PocketBase\\n\\/data\\/\\*\\n!\\/data\\/fixtures\\n!\\/data\\/seeds\\n!\\/data\\/hooks\\n?/,\n \"\\n\",\n );\n\n const cleaned = withBlockRemoved.replace(/\\n{3,}$/, \"\\n\");\n\n if (cleaned === original) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(gitignorePath, cleaned, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n// Source of truth: velastack-cli/templates/minimal/test/setup.ts\nexport const WITH_BACKEND = `import { beforeEach, afterEach, beforeAll } from 'vitest';\nimport supertest, { type Agent } from 'supertest';\nimport PocketBase from 'pocketbase-sveltekit';\nimport type { TestContext } from '@velastack/pocketbase/testing';\n\nconst admin = new PocketBase(process.env.POCKETBASE_URL!) as App.Locals['admin'];\nconst pb = new PocketBase(process.env.POCKETBASE_URL!) as App.Locals['pb'];\n\nconst testUserPassword = 'password';\n\nasync function authenticateUser(agent: Agent, user: { email?: string }) {\n\\t// Logs in with the password, so it needs the email (made optional by\n\\t// enable-whatsapp, for accounts that sign in with a phone number).\n\\tif (!user.email) {\n\\t\\tthrow new Error('authenticateUser needs a user with an email');\n\\t}\n\\tawait agent.post('/login').type('form').send({\n\\t\\ttype: 'password',\n\\t\\temail: user.email,\n\\t\\tpassword: testUserPassword\n\\t});\n}\n\nbeforeAll(async () => {\n\\tawait admin\n\\t\\t// @ts-ignore\n\\t\\t.collection('_superusers')\n\\t\\t.authWithPassword(\n\\t\\t\\tprocess.env.POCKETBASE_SUPERUSER_EMAIL!,\n\\t\\t\\tprocess.env.POCKETBASE_SUPERUSER_PASSWORD!\n\\t\\t);\n});\n\nbeforeEach(async (context: TestContext) => {\n\\tcontext.request = supertest(process.env.VITE_TEST_URL!);\n\\tcontext.agent = supertest.agent(process.env.VITE_TEST_URL!) as TestContext['agent'];\n\\tcontext.admin = admin;\n\\tcontext.pb = pb;\n\\tconst email = \\`test-\\${Math.random().toString(36).slice(2)}@example.com\\`;\n\\tcontext.user = await context.admin.collection('users').create({\n\\t\\temail,\n\\t\\tpassword: testUserPassword,\n\\t\\tpasswordConfirm: testUserPassword\n\\t});\n\\tcontext.agent.authenticateUser = () => authenticateUser(context.agent, context.user);\n\\tawait context.pb.collection('users').authWithPassword(email, testUserPassword);\n});\n\nafterEach(async (context: TestContext) => {\n\\tawait context.pb.authStore.clear();\n\\tawait context.admin.collection('users').delete(context.user.id);\n});\n`;\n\n// The static template ships no test setup at all; this is the backend-free\n// subset of the minimal one, kept so existing tests keep their agents.\nconst WITHOUT_BACKEND = `import { beforeEach } from 'vitest';\nimport supertest from 'supertest';\n\nbeforeEach(async (context: any) => {\n\\tcontext.request = supertest(process.env.VITE_TEST_URL!);\n\\tcontext.agent = supertest.agent(process.env.VITE_TEST_URL!);\n});\n`;\n\n// Source of truth: velastack-cli/templates/minimal/vitest.config.ts\nexport const VITEST_CONFIG = `import { defineConfig, mergeConfig } from 'vitest/config';\nimport viteConfig from './vite.config';\n\nexport default mergeConfig(\n\\tviteConfig,\n\\tdefineConfig({\n\\t\\ttest: {\n\\t\\t\\texpect: {\n\\t\\t\\t\\trequireAssertions: true\n\\t\\t\\t},\n\\t\\t\\tname: 'server',\n\\t\\t\\tenvironment: 'node',\n\\t\\t\\tinclude: ['src/**/*.{test,spec}.{js,ts}'],\n\\t\\t\\texclude: ['src/**/*.svelte.{test,spec}.{js,ts}'],\n\\t\\t\\tsetupFiles: ['test/setup.ts']\n\\t\\t}\n\\t})\n);\n`;\n\nconst VITEST_CONFIG_NAMES = [\"ts\", \"mts\", \"js\", \"mjs\"].flatMap((ext) => [\n `vitest.config.${ext}`,\n `vitest.workspace.${ext}`,\n]);\n\n/**\n * Whether the project already configures vitest, in a file of its own or a\n * `test` block in its vite config. Without either, `test/setup.ts` is never\n * loaded and every generated `server.test.ts` fails on its missing context.\n */\nexport function hasVitestConfig(root: string): boolean {\n if (\n VITEST_CONFIG_NAMES.some((name) => fs.existsSync(path.join(root, name)))\n ) {\n return true;\n }\n return [\"ts\", \"mts\", \"js\", \"mjs\"].some((ext) => {\n const viteConfig = path.join(root, `vite.config.${ext}`);\n return (\n fs.existsSync(viteConfig) &&\n /\\btest\\s*:/.test(fs.readFileSync(viteConfig, \"utf8\"))\n );\n });\n}\n\n/**\n * Brings an existing `test/setup.ts` up to the backend one. A project without\n * the file gets it as a create instead (see `generate.runtime.ts`), so it is\n * reported as created rather than modified.\n */\nexport function modifyTestSetup(testSetupPath: string): ModifyOutcome {\n if (!fs.existsSync(testSetupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(testSetupPath, \"utf8\");\n if (original === WITH_BACKEND) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(testSetupPath, WITH_BACKEND, \"utf8\");\n return { status: \"success\", changed: true };\n}\n\nexport function unmodifyTestSetup(testSetupPath: string): ModifyOutcome {\n if (!fs.existsSync(testSetupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(testSetupPath, \"utf8\");\n if (original === WITHOUT_BACKEND) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(testSetupPath, WITHOUT_BACKEND, \"utf8\");\n return { status: \"success\", changed: true };\n}\n"],"mappings":";;;;;;;;AAeA,IAAMU,IAAeH,EAAYP,CAAiB,GAC5CY,IAAiBL,EAAYN,CAAmB,GAChDY,IAAe,0BAEfC,IAAe,CAAM;oCACSJ,EAAa;;yBAExBA,EAAa;;;;GAMhCR,IAAiB,CAAM;cACfQ,EAAa;;AAQ3B,SAASM,EAAkB,GAAwC;CACjE,OAAOC,EACJ,sBAAsB,CAAC,CACvB,MAAM,MACL;EAACL;EAAgBC;EAAcH;CAAY,CAAC,CAAC,SAC3CQ,EAAK,wBAAwB,CAC/B,CACF;AACJ;AAEA,SAASC,EAAa,GAAwC;CAC5D,OAAOF,EACJ,qBAAqBG,EAAW,cAAc,CAAC,CAC/C,QAAQ,MAAOC,EAAG,cAAc,CAAC,CAAC,QAAQ,MAAM,SAAS;AAC9D;AASA,SAAgBC,EAAmB,GAAkC;CACnE,IAAMC,IAAMlB,EAAoBmB,GAAM;EACpC,UAAUtB;EACV,QAAQY;CACV,CAAC;CACD,IAAIS,EAAI,WAAW,YACjB,OAAO;EACL,UAAUA,EAAI;EACd,SAAS;GAAE,QAAQA,EAAI;GAAQ,SAASA,EAAI;EAAQ;CACtD;CAEF,IAAM,EAAE,cAAWA,GACbE,IAAgBT,EAAkBU,EAAO,UAAU;CACzD,IAAI,CAACD,GACH,OAAO;EACL,UAAUC,EAAO;EACjB,SAAS;GAAE,QAAQ;GAAU,SAASZ;EAAa;CACrD;CAGF,AAAIW,EAAc,wBAAwB,MAAMf,KAC9Ce,EAAc,mBAAmBf,CAAY;CAG/C,KAAK,IAAMiB,KAAQR,EAAaO,EAAO,UAAU,GAAG;EAClD,IAAME,IAAOD,EAAK,aAAa;EAC/B,KAAK,IAAIE,IAAID,EAA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AAS;CAAM,KAG7C/B,EAAG,cAAcwC,GAAeT,GAAc,MAAM,GAC7C;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C;AAEA,SAAgBU,EAAkB,GAAsC;CAWtE,OAVI,CAACzC,EAAG,WAAWwC,CAAa,KAIfxC,EAAG,aAAawC,GAAe,MAC5C,MAAaR,IACR;EAAE,QAAQ;EAAW,SAAS;CAAM,KAG7ChC,EAAG,cAAcwC,GAAeR,GAAiB,MAAM,GAChD;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C"}
|
|
1
|
+
{"version":3,"file":"test-setup-DZoyF8Ak.js","names":["ADAPTER_NODE_SPEC","ADAPTER_STATIC_SPEC","NOT_FOUND_HINT","ADAPTER_STATIC$1","dedent","resolveConfigTarget","saveTarget","packageName","fs","path","ADAPTER_NODE","ADAPTER_NODE$1","ADAPTER_STATIC","ADAPTER_AUTO","FAILURE_HINT","NOT_FOUND_HINT$1","findAdapterImport","sourceFile","decl","adapterCalls","SyntaxKind","ce","modifySvelteConfig","res","root","adapterImport","target","call","args","i","unmodifySvelteConfig","POCKETBASE_BLOCK","NOT_FOUND_HINT","modifyGitignore","gitignorePath","original","next","unmodifyGitignore","cleaned","WITH_BACKEND","WITHOUT_BACKEND","VITEST_CONFIG","VITEST_CONFIG_NAMES","ext","hasVitestConfig","name","viteConfig","modifyTestSetup","testSetupPath","unmodifyTestSetup"],"sources":["../../src/patterns/enable/backend/modifies/svelte-config.ts","../../src/patterns/enable/backend/modifies/gitignore.ts","../../src/patterns/enable/backend/modifies/test-setup.ts"],"sourcesContent":["import dedent from \"dedent\";\nimport { SyntaxKind } from \"ts-morph\";\nimport {\n resolveConfigTarget,\n saveTarget,\n type ConfigModifyResult,\n type ConfigTarget,\n} from \"../../../../runtime/config-target\";\nimport { packageName } from \"../../../../runtime/write-result\";\nimport {\n ADAPTER_NODE as ADAPTER_NODE_SPEC,\n ADAPTER_STATIC as ADAPTER_STATIC_SPEC,\n} from \"../../../../core/constants\";\n\n// Imports name the package, not the versioned spec the constants install.\nconst ADAPTER_NODE = packageName(ADAPTER_NODE_SPEC);\nconst ADAPTER_STATIC = packageName(ADAPTER_STATIC_SPEC);\nconst ADAPTER_AUTO = \"@sveltejs/adapter-auto\";\n\nconst FAILURE_HINT = dedent`\n Switch the SvelteKit adapter to ${ADAPTER_NODE}:\n\n import adapter from '${ADAPTER_NODE}';\n\n // ...\n adapter: adapter()\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Configure ${ADAPTER_NODE} via the sveltekit() plugin in vite.config.ts.\n`;\n\n/**\n * The adapters this pattern moves between. adapter-auto is included because\n * that is what `sv create` ships, and a project that never chose is one the\n * backend is free to decide for.\n */\nfunction findAdapterImport(sourceFile: ConfigTarget[\"sourceFile\"]) {\n return sourceFile\n .getImportDeclarations()\n .find((decl) =>\n [ADAPTER_STATIC, ADAPTER_AUTO, ADAPTER_NODE].includes(\n decl.getModuleSpecifierValue(),\n ),\n );\n}\n\nfunction adapterCalls(sourceFile: ConfigTarget[\"sourceFile\"]) {\n return sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((ce) => ce.getExpression().getText() === \"adapter\");\n}\n\n/**\n * Switch the adapter to `@sveltejs/adapter-node` and drop its arguments in\n * vite.config, which holds the adapter import + `adapter()` call. A project with a\n * backend is served from a Node process, which is what `vela deploy` runs.\n * Operates on the import and call expression directly, so it never needs the\n * config object.\n */\nexport function modifySvelteConfig(root: string): ConfigModifyResult {\n const res = resolveConfigTarget(root, {\n notFound: NOT_FOUND_HINT,\n failed: FAILURE_HINT,\n });\n if (res.status !== \"resolved\") {\n return {\n filePath: res.filePath,\n outcome: { status: res.status, message: res.message },\n };\n }\n const { target } = res;\n const adapterImport = findAdapterImport(target.sourceFile);\n if (!adapterImport) {\n return {\n filePath: target.filePath,\n outcome: { status: \"failed\", message: FAILURE_HINT },\n };\n }\n\n if (adapterImport.getModuleSpecifierValue() !== ADAPTER_NODE) {\n adapterImport.setModuleSpecifier(ADAPTER_NODE);\n }\n\n for (const call of adapterCalls(target.sourceFile)) {\n const args = call.getArguments();\n for (let i = args.length - 1; i >= 0; i--) {\n call.removeArgument(i);\n }\n }\n\n return { filePath: target.filePath, outcome: saveTarget(target) };\n}\n\n/**\n * Reverse of {@link modifySvelteConfig}: switch back to\n * `@sveltejs/adapter-static` and restore the `{ fallback: '200.html' }` arg.\n * Lenient when there is no config or no adapter import: a no-op success. A\n * config that can't be edited (a leftover svelte.config) still fails.\n */\nexport function unmodifySvelteConfig(root: string): ConfigModifyResult {\n const res = resolveConfigTarget(root, {\n notFound: NOT_FOUND_HINT,\n failed: FAILURE_HINT,\n });\n if (res.status === \"not-found\") {\n // Nothing to revert.\n return {\n filePath: res.filePath,\n outcome: { status: \"success\", changed: false },\n };\n }\n if (res.status === \"failed\") {\n return {\n filePath: res.filePath,\n outcome: { status: \"failed\", message: res.message },\n };\n }\n const { target } = res;\n const adapterImport = findAdapterImport(target.sourceFile);\n if (!adapterImport) {\n return {\n filePath: target.filePath,\n outcome: { status: \"success\", changed: false },\n };\n }\n\n if (adapterImport.getModuleSpecifierValue() !== ADAPTER_STATIC) {\n adapterImport.setModuleSpecifier(ADAPTER_STATIC);\n }\n\n for (const call of adapterCalls(target.sourceFile)) {\n if (call.getArguments().length === 0) {\n call.addArgument(\"{ fallback: '200.html' }\");\n }\n }\n\n return { filePath: target.filePath, outcome: saveTarget(target) };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst POCKETBASE_BLOCK = `# PocketBase\n/data/*\n!/data/fixtures\n!/data/seeds\n!/data/hooks\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create a .gitignore at the project root with the PocketBase block:\n\n # PocketBase\n /data/*\n !/data/fixtures\n !/data/seeds\n !/data/hooks\n`;\n\nexport function modifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n\n if (original.includes(\"# PocketBase\") && original.includes(\"/data/*\")) {\n return { status: \"success\", changed: false };\n }\n\n const separator = original.endsWith(\"\\n\") ? \"\\n\" : \"\\n\\n\";\n const next = original + separator + POCKETBASE_BLOCK;\n fs.writeFileSync(gitignorePath, next, \"utf8\");\n\n return { status: \"success\", changed: true };\n}\n\nexport function unmodifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n\n if (!original.includes(\"# PocketBase\")) {\n return { status: \"success\", changed: false };\n }\n\n const withBlockRemoved = original.replace(\n /\\n*# PocketBase\\n\\/data\\/\\*\\n!\\/data\\/fixtures\\n!\\/data\\/seeds\\n!\\/data\\/hooks\\n?/,\n \"\\n\",\n );\n\n const cleaned = withBlockRemoved.replace(/\\n{3,}$/, \"\\n\");\n\n if (cleaned === original) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(gitignorePath, cleaned, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n// Source of truth: velastack-cli/templates/minimal/test/setup.ts\nexport const WITH_BACKEND = `import { beforeEach, afterEach, beforeAll } from 'vitest';\nimport supertest, { type Agent } from 'supertest';\nimport PocketBase from 'pocketbase-sveltekit';\nimport type { TestContext } from '@velastack/pocketbase/testing';\n\nconst admin = new PocketBase(process.env.POCKETBASE_URL!) as App.Locals['admin'];\nconst pb = new PocketBase(process.env.POCKETBASE_URL!) as App.Locals['pb'];\n\nconst testUserPassword = 'password';\n\nasync function authenticateUser(agent: Agent, user: { email?: string }) {\n\\t// Logs in with the password, so it needs the email (made optional by\n\\t// enable-whatsapp, for accounts that sign in with a phone number).\n\\tif (!user.email) {\n\\t\\tthrow new Error('authenticateUser needs a user with an email');\n\\t}\n\\tawait agent.post('/login').type('form').send({\n\\t\\ttype: 'password',\n\\t\\temail: user.email,\n\\t\\tpassword: testUserPassword\n\\t});\n}\n\nbeforeAll(async () => {\n\\tawait admin\n\\t\\t// @ts-ignore\n\\t\\t.collection('_superusers')\n\\t\\t.authWithPassword(\n\\t\\t\\tprocess.env.POCKETBASE_SUPERUSER_EMAIL!,\n\\t\\t\\tprocess.env.POCKETBASE_SUPERUSER_PASSWORD!\n\\t\\t);\n});\n\nbeforeEach(async (context: TestContext) => {\n\\tcontext.request = supertest(process.env.VITE_TEST_URL!);\n\\tcontext.agent = supertest.agent(process.env.VITE_TEST_URL!) as TestContext['agent'];\n\\tcontext.admin = admin;\n\\tcontext.pb = pb;\n\\tconst email = \\`test-\\${Math.random().toString(36).slice(2)}@example.com\\`;\n\\tcontext.user = await context.admin.collection('users').create({\n\\t\\temail,\n\\t\\tpassword: testUserPassword,\n\\t\\tpasswordConfirm: testUserPassword\n\\t});\n\\tcontext.agent.authenticateUser = () => authenticateUser(context.agent, context.user);\n\\tawait context.pb.collection('users').authWithPassword(email, testUserPassword);\n});\n\nafterEach(async (context: TestContext) => {\n\\tawait context.pb.authStore.clear();\n\\tawait context.admin.collection('users').delete(context.user.id);\n});\n`;\n\n// The static template ships no test setup at all; this is the backend-free\n// subset of the minimal one, kept so existing tests keep their agents.\nconst WITHOUT_BACKEND = `import { beforeEach } from 'vitest';\nimport supertest from 'supertest';\n\nbeforeEach(async (context: any) => {\n\\tcontext.request = supertest(process.env.VITE_TEST_URL!);\n\\tcontext.agent = supertest.agent(process.env.VITE_TEST_URL!);\n});\n`;\n\n// Source of truth: velastack-cli/templates/minimal/vitest.config.ts\nexport const VITEST_CONFIG = `import { defineConfig, mergeConfig } from 'vitest/config';\nimport viteConfig from './vite.config';\n\nexport default mergeConfig(\n\\tviteConfig,\n\\tdefineConfig({\n\\t\\ttest: {\n\\t\\t\\texpect: {\n\\t\\t\\t\\trequireAssertions: true\n\\t\\t\\t},\n\\t\\t\\tname: 'server',\n\\t\\t\\tenvironment: 'node',\n\\t\\t\\tinclude: ['src/**/*.{test,spec}.{js,ts}'],\n\\t\\t\\texclude: ['src/**/*.svelte.{test,spec}.{js,ts}'],\n\\t\\t\\tsetupFiles: ['test/setup.ts']\n\\t\\t}\n\\t})\n);\n`;\n\nconst VITEST_CONFIG_NAMES = [\"ts\", \"mts\", \"js\", \"mjs\"].flatMap((ext) => [\n `vitest.config.${ext}`,\n `vitest.workspace.${ext}`,\n]);\n\n/**\n * Whether the project already configures vitest, in a file of its own or a\n * `test` block in its vite config. Without either, `test/setup.ts` is never\n * loaded and every generated `server.test.ts` fails on its missing context.\n */\nexport function hasVitestConfig(root: string): boolean {\n if (\n VITEST_CONFIG_NAMES.some((name) => fs.existsSync(path.join(root, name)))\n ) {\n return true;\n }\n return [\"ts\", \"mts\", \"js\", \"mjs\"].some((ext) => {\n const viteConfig = path.join(root, `vite.config.${ext}`);\n return (\n fs.existsSync(viteConfig) &&\n /\\btest\\s*:/.test(fs.readFileSync(viteConfig, \"utf8\"))\n );\n });\n}\n\n/**\n * Brings an existing `test/setup.ts` up to the backend one. A project without\n * the file gets it as a create instead (see `generate.runtime.ts`), so it is\n * reported as created rather than modified.\n */\nexport function modifyTestSetup(testSetupPath: string): ModifyOutcome {\n if (!fs.existsSync(testSetupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(testSetupPath, \"utf8\");\n if (original === WITH_BACKEND) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(testSetupPath, WITH_BACKEND, \"utf8\");\n return { status: \"success\", changed: true };\n}\n\nexport function unmodifyTestSetup(testSetupPath: string): ModifyOutcome {\n if (!fs.existsSync(testSetupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(testSetupPath, \"utf8\");\n if (original === WITHOUT_BACKEND) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(testSetupPath, WITHOUT_BACKEND, \"utf8\");\n return { status: \"success\", changed: true };\n}\n"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AG,aAAawC,GAAe,MAC5C,MAAaR,IACR;EAAE,QAAQ;EAAW,SAAS;CAAM,KAG7ChC,EAAG,cAAcwC,GAAeR,GAAiB,MAAM,GAChD;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as e, t } from "./errors-DR3gF_7a.js";
|
|
2
2
|
import { n } from "./logger-CQONztPm.js";
|
|
3
|
-
import { a as r, i, n as a, o, r as s, s as c, t as l } from "./write-result-
|
|
3
|
+
import { a as r, i, n as a, o, r as s, s as c, t as l } from "./write-result-Cq-9A7Zy.js";
|
|
4
4
|
import { i as u, r as d } from "./table-core-DhDqT03G.js";
|
|
5
5
|
import { existsSync as f, readFileSync as p, writeFileSync as m } from "node:fs";
|
|
6
6
|
import h from "node:path";
|
|
@@ -171,4 +171,4 @@ async function N(e, t) {
|
|
|
171
171
|
//#endregion
|
|
172
172
|
export { M as applyBaseColor, N as applyTheme, C as listComponents, D as switchStyle };
|
|
173
173
|
|
|
174
|
-
//# sourceMappingURL=ui-
|
|
174
|
+
//# sourceMappingURL=ui-BuocThuh.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-CuCsupFq.js","names":["RegistryUnavailableError","installedComponents","formatPaths","getAllCustomComponents","isCustomComponent","executeCommand","readComponentsConfig","fetchRegistryIndex","path","loadPreset","resolved","createRequire","root","error","reason","pathToFileURL","STYLE_FONTS","presetFor","preset","config","current","encodePreset","overrides","applyPreset","code","only","runtime","COMPONENTS_JSON","listComponents","options","result","assertOneOf","value","InvalidArgumentError","kind","choices","writeStyle","configPath","existsSync","text","readFileSync","style","indent","registryUiNames","index","item","switchStyle","logger","getLogger","unchanged","offered","reinstall","component","packagesBefore","installedPackagesFromProject","filesModified","reinstalled","installComponents","hints","font","applyStyleFont","packages","name","FONTSOURCE_IMPORT","fontsourceImports","css","match","fonts","cssPath","cssFile","wanted","stale","family","f","applyColors","applyBaseColor","applyTheme"],"sources":["../../src/runtime/shadcn-preset.ts","../../src/runtime/ui.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { WriteResultRuntime } from \"../core/types\";\nimport { readComponentsConfig } from \"./registry\";\nimport { executeCommand, formatPaths } from \"./write-result\";\n\n/**\n * What a shadcn-svelte preset code carries. Mirrors `PresetConfig` from\n * `shadcn-svelte/preset` as plain strings, so this package's types do not\n * depend on a package its consumers may not have installed.\n */\nexport interface PresetConfig {\n style: string;\n baseColor: string;\n theme: string;\n chartColor?: string;\n iconLibrary: string;\n font: string;\n fontHeading: string;\n radius: string;\n menuAccent: string;\n menuColor: string;\n}\n\n/** The part of `shadcn-svelte/preset` this package uses. */\nexport interface ShadcnPreset {\n PRESET_STYLES: readonly string[];\n PRESET_BASE_COLOR_KEYS: readonly string[];\n PRESET_THEME_KEYS: readonly string[];\n PRESET_FONTS: readonly string[];\n PRESET_ICON_LIBRARIES: readonly string[];\n encodePreset(config: Partial<PresetConfig>): string;\n decodePreset(code: string): PresetConfig | null;\n}\n\nexport type PresetPart = \"theme\" | \"font\";\n\n/**\n * The encoder from the *project's* shadcn-svelte, so every preset code is\n * produced by the same version that consumes it and the value lists can\n * never drift from what `apply` accepts.\n */\nexport async function loadPreset(root: string): Promise<ShadcnPreset> {\n let resolved: string;\n try {\n resolved = createRequire(path.join(root, \"package.json\")).resolve(\n \"shadcn-svelte/preset\",\n );\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n throw new Error(\n `Could not load shadcn-svelte/preset from ${root}: ${reason}\\n` +\n \"Install the project's dependencies (shadcn-svelte >= 1.6) and try again.\",\n );\n }\n const module: unknown = await import(\n /* @vite-ignore */ pathToFileURL(resolved).href\n );\n return module as ShadcnPreset;\n}\n\n/**\n * The font each style is designed with. shadcn-svelte keeps this table inside\n * its bundle (the `create` presets) without exporting it, so it is vendored\n * here; `shadcn-preset.test.ts` checks it still covers every style the\n * installed shadcn-svelte knows.\n */\nexport const STYLE_FONTS: Record<\n string,\n { font: string; fontHeading?: string }\n> = {\n nova: { font: \"geist\" },\n vega: { font: \"inter\" },\n maia: { font: \"figtree\" },\n lyra: { font: \"jetbrains-mono\" },\n mira: { font: \"inter\" },\n luma: { font: \"inter\" },\n sera: { font: \"noto-sans\", fontHeading: \"playfair-display\" },\n rhea: { font: \"inter\" },\n};\n\n/**\n * A preset code for the project as it is, with `overrides` on top: the style,\n * base color, icon library and menu settings come from `components.json` so\n * an `apply --only theme` keeps everything it does not mean to change.\n * Values shadcn-svelte does not know (a `slate` from an older template) fall\n * back to its defaults inside `encodePreset`.\n */\nexport async function presetFor(\n root: string,\n overrides: Partial<PresetConfig>,\n preset?: ShadcnPreset,\n): Promise<string> {\n const { encodePreset } = preset ?? (await loadPreset(root));\n const config = readComponentsConfig(root);\n const current: Partial<PresetConfig> = { style: config.style };\n if (config.baseColor) current.baseColor = config.baseColor;\n if (config.iconLibrary) current.iconLibrary = config.iconLibrary;\n if (config.menuColor) current.menuColor = config.menuColor;\n if (config.menuAccent) current.menuAccent = config.menuAccent;\n return encodePreset({ ...current, ...overrides });\n}\n\n/**\n * `shadcn-svelte apply --preset <code> --only <parts> --yes` through the\n * project's package manager. `theme` rewrites the token values in `:root` /\n * `.dark` and records the base color in `components.json`; `font` adds the\n * fontsource import, dependency and `--font-sans`. Both leave the rest of the\n * stylesheet alone but write it in the registry's formatting, so the file is\n * run through the project's prettier afterwards.\n */\nexport async function applyPreset(\n root: string,\n code: string,\n only: PresetPart[],\n runtime?: WriteResultRuntime,\n): Promise<void> {\n await executeCommand(\n root,\n \"execute\",\n [\"shadcn-svelte\", \"apply\", \"--preset\", code, \"--only\", ...only, \"--yes\"],\n runtime,\n );\n await formatPaths(root, [readComponentsConfig(root).cssPath]);\n}\n","import { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type {\n ApplyBaseColorOptions,\n ApplyColorsResult,\n ApplyThemeOptions,\n Component,\n ListComponentsOptions,\n ListComponentsResult,\n RegistryItem,\n SwitchStyleOptions,\n SwitchStyleResult,\n WriteResultRuntime,\n} from \"../core/types\";\nimport { InvalidArgumentError, RegistryUnavailableError } from \"../core/errors\";\nimport { getLogger } from \"../core/logger\";\nimport { fetchRegistryIndex, readComponentsConfig } from \"./registry\";\nimport {\n applyPreset,\n loadPreset,\n presetFor,\n STYLE_FONTS,\n type ShadcnPreset,\n} from \"./shadcn-preset\";\nimport {\n getAllCustomComponents,\n installComponents,\n installedComponents,\n installedPackagesFromProject,\n isCustomComponent,\n} from \"./write-result\";\n\nconst COMPONENTS_JSON = \"components.json\";\n\n/**\n * What a project has and what it could add: the ui directory, this package's\n * bundled components, and the registry index of the configured style. A\n * registry that cannot be read leaves the first two intact and says why.\n */\nexport async function listComponents(\n options: ListComponentsOptions,\n runtime?: WriteResultRuntime,\n): Promise<ListComponentsResult> {\n const { root } = options;\n const { style } = readComponentsConfig(root);\n const result: ListComponentsResult = {\n style,\n installed: installedComponents(root),\n custom: getAllCustomComponents(),\n registry: [],\n };\n try {\n result.registry = await fetchRegistryIndex(root, { runtime });\n } catch (error) {\n if (!(error instanceof RegistryUnavailableError)) throw error;\n result.registryUnavailable = error.message;\n }\n return result;\n}\n\nfunction assertOneOf(\n kind: string,\n value: string,\n choices: readonly string[],\n): void {\n if (choices.includes(value)) return;\n throw new InvalidArgumentError(\n `Unknown ${kind} \"${value}\". Choose one of: ${choices.join(\", \")}.`,\n );\n}\n\n/**\n * Rewrites `style` in `components.json` and nothing else, keeping the file's\n * indentation so the change reads as the one-line diff it is.\n */\nfunction writeStyle(root: string, style: string): void {\n const configPath = path.join(root, COMPONENTS_JSON);\n if (!existsSync(configPath)) {\n throw new Error(\n `${COMPONENTS_JSON} not found in ${root}; this does not look like a shadcn-svelte project.`,\n );\n }\n const text = readFileSync(configPath, \"utf8\");\n const config = JSON.parse(text) as Record<string, unknown>;\n config.style = style;\n const indent = text.includes(\"\\n\\t\") ? \"\\t\" : 2;\n writeFileSync(\n configPath,\n `${JSON.stringify(config, null, indent)}\\n`,\n \"utf8\",\n );\n}\n\nfunction registryUiNames(index: RegistryItem[]): Set<string> {\n return new Set(\n index\n .filter((item) => item.type === \"registry:ui\")\n .map((item) => item.name),\n );\n}\n\n/**\n * Moves a project to another shadcn-svelte style. Every installed component\n * the new style's registry also offers is re-added from there (their local\n * edits are lost, which is what `confirm` is for); this package's own\n * components and anything the registry does not know are left alone. The\n * style's preset font follows unless `font` is false.\n */\nexport async function switchStyle(\n options: SwitchStyleOptions,\n runtime?: WriteResultRuntime,\n): Promise<SwitchStyleResult> {\n const { root, style, font = true } = options;\n const logger = getLogger(options);\n const preset = await loadPreset(root);\n assertOneOf(\"style\", style, preset.PRESET_STYLES);\n\n const unchanged: SwitchStyleResult = {\n status: \"unchanged\",\n style,\n reinstalled: [],\n filesModified: [],\n packages: [],\n hints: [],\n };\n if (readComponentsConfig(root).style === style) {\n return unchanged;\n }\n\n const index = await fetchRegistryIndex(root, { style, runtime });\n const offered = registryUiNames(index);\n const reinstall = installedComponents(root).filter(\n (component) => offered.has(component) && !isCustomComponent(component),\n );\n\n if (options.confirm && !(await options.confirm(reinstall))) {\n return { ...unchanged, status: \"cancelled\" };\n }\n\n const packagesBefore = installedPackagesFromProject(root);\n writeStyle(root, style);\n const filesModified = [COMPONENTS_JSON];\n\n let reinstalled: Component[] = [];\n if (reinstall.length > 0) {\n const outcome = await installComponents(\n { root, components: reinstall, overwrite: true, logger },\n runtime,\n );\n reinstalled = outcome.installed;\n }\n\n const hints: string[] = [];\n if (font) {\n await applyStyleFont(\n root,\n style,\n preset,\n runtime,\n filesModified,\n hints,\n logger,\n );\n }\n\n const packages = [...installedPackagesFromProject(root)]\n .filter((name) => !packagesBefore.has(name))\n .sort();\n\n return {\n status: \"switched\",\n style,\n reinstalled,\n filesModified,\n packages,\n hints,\n };\n}\n\nconst FONTSOURCE_IMPORT =\n /@import\\s+[\"']@fontsource(?:-variable)?\\/([^\"']+)[\"']/g;\n\n/** The fontsource families a stylesheet imports, in order. */\nfunction fontsourceImports(css: string): string[] {\n return [...css.matchAll(FONTSOURCE_IMPORT)].map((match) => match[1]!);\n}\n\nasync function applyStyleFont(\n root: string,\n style: string,\n preset: ShadcnPreset,\n runtime: WriteResultRuntime | undefined,\n filesModified: string[],\n hints: string[],\n logger: ReturnType<typeof getLogger>,\n): Promise<void> {\n const fonts = STYLE_FONTS[style];\n if (!fonts) {\n logger.info(\n `No preset font is known for the ${style} style; leaving fonts unchanged.`,\n );\n return;\n }\n logger.info(`Applying the ${style} font (${fonts.font})`);\n const code = await presetFor(root, { style, ...fonts }, preset);\n await applyPreset(root, code, [\"font\"], runtime);\n\n const cssPath = readComponentsConfig(root).cssPath;\n filesModified.push(cssPath, \"package.json\");\n\n // `apply --only font` adds the new font beside whatever was imported before\n // and leaves it to the project to drop the old one; a font nobody uses\n // still ships to every visitor.\n const cssFile = path.join(root, cssPath);\n if (existsSync(cssFile)) {\n const wanted = new Set([fonts.font, fonts.fontHeading].filter(Boolean));\n const stale = fontsourceImports(readFileSync(cssFile, \"utf8\")).filter(\n (family) => !wanted.has(family),\n );\n if (stale.length > 0) {\n hints.push(\n `${cssPath} still imports ${stale.map((f) => `@fontsource-variable/${f}`).join(\", \")} from the previous style; remove the import and the package if nothing else uses them.`,\n );\n }\n }\n}\n\nasync function applyColors(\n root: string,\n overrides: { baseColor?: string; theme: string },\n runtime?: WriteResultRuntime,\n): Promise<ApplyColorsResult> {\n const preset = await loadPreset(root);\n if (overrides.baseColor) {\n assertOneOf(\n \"base color\",\n overrides.baseColor,\n preset.PRESET_BASE_COLOR_KEYS,\n );\n }\n assertOneOf(\"theme\", overrides.theme, preset.PRESET_THEME_KEYS);\n\n // Charts follow the accent, as shadcn-svelte's own presets do.\n const code = await presetFor(\n root,\n { ...overrides, chartColor: overrides.theme },\n preset,\n );\n await applyPreset(root, code, [\"theme\"], runtime);\n\n const config = readComponentsConfig(root);\n return {\n baseColor: config.baseColor ?? overrides.baseColor ?? \"\",\n theme: overrides.theme,\n filesModified: [config.cssPath, COMPONENTS_JSON],\n };\n}\n\n/**\n * Sets the base (gray) palette. The accent is reset to the base color as\n * well, since `components.json` records only the base color; `applyTheme`\n * puts an accent back on top.\n */\nexport async function applyBaseColor(\n options: ApplyBaseColorOptions,\n runtime?: WriteResultRuntime,\n): Promise<ApplyColorsResult> {\n return applyColors(\n options.root,\n { baseColor: options.color, theme: options.color },\n runtime,\n );\n}\n\n/** Sets the accent (primary, ring, charts) and keeps the base palette. */\nexport async function applyTheme(\n options: ApplyThemeOptions,\n runtime?: WriteResultRuntime,\n): Promise<ApplyColorsResult> {\n return applyColors(options.root, { theme: options.theme }, runtime);\n}\n"],"mappings":";;;;;;;;;AA2CA,eAAsBS,EAAW,GAAqC;CACpE,IAAIC;CACJ,IAAI;EACF,IAAWC,EAAcH,EAAK,KAAKI,GAAM,cAAc,CAAC,CAAC,CAAC,QACxD,sBACF;CACF,SAASC,GAAO;EACd,IAAMC,IAASD,aAAiB,QAAQA,EAAM,UAAU,OAAOA,CAAK;EACpE,MAAU,MACR,4CAA4CD,EAAK,IAAIE,EAAO,2EAE9D;CACF;CAIA,OAAO,MAHuB;;EACTC,EAAcL,CAAQ,CAAC,CAAC;;AAG/C;AAQA,IAAaM,IAGT;CACF,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,EAAE,MAAM,iBAAiB;CAC/B,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM;EAAE,MAAM;EAAa,aAAa;CAAmB;CAC3D,MAAM,EAAE,MAAM,QAAQ;AACxB;AASA,eAAsBC,EACpB,GACA,GACA,GACiB;CACjB,IAAM,EAAE,oBAAiBC,KAAW,MAAMT,EAAWG,CAAI,GACnDO,IAASb,EAAqBM,CAAI,GAClCQ,IAAiC,EAAE,OAAOD,EAAO,MAAM;CAK7D,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AAI,EAAE,uFACvF;CAEJ;AACF;AAEA,eAAeC,EACb,GACA,GACA,GAC4B;CAC5B,IAAMxD,IAAS,MAAMT,EAAWG,CAAI;CAgBpC,AAfIU,EAAU,aACZS,EACE,cACAT,EAAU,WACVJ,EAAO,sBACT,GAEFa,EAAY,SAAST,EAAU,OAAOJ,EAAO,iBAAiB,GAQ9D,MAAMK,EAAYX,GAAM,MALLK,EACjBL,GACA;EAAE,GAAGU;EAAW,YAAYA,EAAU;CAAM,GAC5CJ,CACF,GAC8B,CAAC,OAAO,GAAGQ,CAAO;CAEhD,IAAMP,IAASb,EAAqBM,CAAI;CACxC,OAAO;EACL,WAAWO,EAAO,aAAaG,EAAU,aAAa;EACtD,OAAOA,EAAU;EACjB,eAAe,CAACH,EAAO,SAASQ,CAAe;CACjD;AACF;AAOA,eAAsBgD,EACpB,GACA,GAC4B;CAC5B,OAAOD,EACL7C,EAAQ,MACR;EAAE,WAAWA,EAAQ;EAAO,OAAOA,EAAQ;CAAM,GACjDH,CACF;AACF;AAGA,eAAsBkD,EACpB,GACA,GAC4B;CAC5B,OAAOF,EAAY7C,EAAQ,MAAM,EAAE,OAAOA,EAAQ,MAAM,GAAGH,CAAO;AACpE"}
|
|
1
|
+
{"version":3,"file":"ui-BuocThuh.js","names":["RegistryUnavailableError","installedComponents","formatPaths","getAllCustomComponents","isCustomComponent","executeCommand","readComponentsConfig","fetchRegistryIndex","path","loadPreset","resolved","createRequire","root","error","reason","pathToFileURL","STYLE_FONTS","presetFor","preset","config","current","encodePreset","overrides","applyPreset","code","only","runtime","COMPONENTS_JSON","listComponents","options","result","assertOneOf","value","InvalidArgumentError","kind","choices","writeStyle","configPath","existsSync","text","readFileSync","style","indent","registryUiNames","index","item","switchStyle","logger","getLogger","unchanged","offered","reinstall","component","packagesBefore","installedPackagesFromProject","filesModified","reinstalled","installComponents","hints","font","applyStyleFont","packages","name","FONTSOURCE_IMPORT","fontsourceImports","css","match","fonts","cssPath","cssFile","wanted","stale","family","f","applyColors","applyBaseColor","applyTheme"],"sources":["../../src/runtime/shadcn-preset.ts","../../src/runtime/ui.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { WriteResultRuntime } from \"../core/types\";\nimport { readComponentsConfig } from \"./registry\";\nimport { executeCommand, formatPaths } from \"./write-result\";\n\n/**\n * What a shadcn-svelte preset code carries. Mirrors `PresetConfig` from\n * `shadcn-svelte/preset` as plain strings, so this package's types do not\n * depend on a package its consumers may not have installed.\n */\nexport interface PresetConfig {\n style: string;\n baseColor: string;\n theme: string;\n chartColor?: string;\n iconLibrary: string;\n font: string;\n fontHeading: string;\n radius: string;\n menuAccent: string;\n menuColor: string;\n}\n\n/** The part of `shadcn-svelte/preset` this package uses. */\nexport interface ShadcnPreset {\n PRESET_STYLES: readonly string[];\n PRESET_BASE_COLOR_KEYS: readonly string[];\n PRESET_THEME_KEYS: readonly string[];\n PRESET_FONTS: readonly string[];\n PRESET_ICON_LIBRARIES: readonly string[];\n encodePreset(config: Partial<PresetConfig>): string;\n decodePreset(code: string): PresetConfig | null;\n}\n\nexport type PresetPart = \"theme\" | \"font\";\n\n/**\n * The encoder from the *project's* shadcn-svelte, so every preset code is\n * produced by the same version that consumes it and the value lists can\n * never drift from what `apply` accepts.\n */\nexport async function loadPreset(root: string): Promise<ShadcnPreset> {\n let resolved: string;\n try {\n resolved = createRequire(path.join(root, \"package.json\")).resolve(\n \"shadcn-svelte/preset\",\n );\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n throw new Error(\n `Could not load shadcn-svelte/preset from ${root}: ${reason}\\n` +\n \"Install the project's dependencies (shadcn-svelte >= 1.6) and try again.\",\n );\n }\n const module: unknown = await import(\n /* @vite-ignore */ pathToFileURL(resolved).href\n );\n return module as ShadcnPreset;\n}\n\n/**\n * The font each style is designed with. shadcn-svelte keeps this table inside\n * its bundle (the `create` presets) without exporting it, so it is vendored\n * here; `shadcn-preset.test.ts` checks it still covers every style the\n * installed shadcn-svelte knows.\n */\nexport const STYLE_FONTS: Record<\n string,\n { font: string; fontHeading?: string }\n> = {\n nova: { font: \"geist\" },\n vega: { font: \"inter\" },\n maia: { font: \"figtree\" },\n lyra: { font: \"jetbrains-mono\" },\n mira: { font: \"inter\" },\n luma: { font: \"inter\" },\n sera: { font: \"noto-sans\", fontHeading: \"playfair-display\" },\n rhea: { font: \"inter\" },\n};\n\n/**\n * A preset code for the project as it is, with `overrides` on top: the style,\n * base color, icon library and menu settings come from `components.json` so\n * an `apply --only theme` keeps everything it does not mean to change.\n * Values shadcn-svelte does not know (a `slate` from an older template) fall\n * back to its defaults inside `encodePreset`.\n */\nexport async function presetFor(\n root: string,\n overrides: Partial<PresetConfig>,\n preset?: ShadcnPreset,\n): Promise<string> {\n const { encodePreset } = preset ?? (await loadPreset(root));\n const config = readComponentsConfig(root);\n const current: Partial<PresetConfig> = { style: config.style };\n if (config.baseColor) current.baseColor = config.baseColor;\n if (config.iconLibrary) current.iconLibrary = config.iconLibrary;\n if (config.menuColor) current.menuColor = config.menuColor;\n if (config.menuAccent) current.menuAccent = config.menuAccent;\n return encodePreset({ ...current, ...overrides });\n}\n\n/**\n * `shadcn-svelte apply --preset <code> --only <parts> --yes` through the\n * project's package manager. `theme` rewrites the token values in `:root` /\n * `.dark` and records the base color in `components.json`; `font` adds the\n * fontsource import, dependency and `--font-sans`. Both leave the rest of the\n * stylesheet alone but write it in the registry's formatting, so the file is\n * run through the project's prettier afterwards.\n */\nexport async function applyPreset(\n root: string,\n code: string,\n only: PresetPart[],\n runtime?: WriteResultRuntime,\n): Promise<void> {\n await executeCommand(\n root,\n \"execute\",\n [\"shadcn-svelte\", \"apply\", \"--preset\", code, \"--only\", ...only, \"--yes\"],\n runtime,\n );\n await formatPaths(root, [readComponentsConfig(root).cssPath]);\n}\n","import { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type {\n ApplyBaseColorOptions,\n ApplyColorsResult,\n ApplyThemeOptions,\n Component,\n ListComponentsOptions,\n ListComponentsResult,\n RegistryItem,\n SwitchStyleOptions,\n SwitchStyleResult,\n WriteResultRuntime,\n} from \"../core/types\";\nimport { InvalidArgumentError, RegistryUnavailableError } from \"../core/errors\";\nimport { getLogger } from \"../core/logger\";\nimport { fetchRegistryIndex, readComponentsConfig } from \"./registry\";\nimport {\n applyPreset,\n loadPreset,\n presetFor,\n STYLE_FONTS,\n type ShadcnPreset,\n} from \"./shadcn-preset\";\nimport {\n getAllCustomComponents,\n installComponents,\n installedComponents,\n installedPackagesFromProject,\n isCustomComponent,\n} from \"./write-result\";\n\nconst COMPONENTS_JSON = \"components.json\";\n\n/**\n * What a project has and what it could add: the ui directory, this package's\n * bundled components, and the registry index of the configured style. A\n * registry that cannot be read leaves the first two intact and says why.\n */\nexport async function listComponents(\n options: ListComponentsOptions,\n runtime?: WriteResultRuntime,\n): Promise<ListComponentsResult> {\n const { root } = options;\n const { style } = readComponentsConfig(root);\n const result: ListComponentsResult = {\n style,\n installed: installedComponents(root),\n custom: getAllCustomComponents(),\n registry: [],\n };\n try {\n result.registry = await fetchRegistryIndex(root, { runtime });\n } catch (error) {\n if (!(error instanceof RegistryUnavailableError)) throw error;\n result.registryUnavailable = error.message;\n }\n return result;\n}\n\nfunction assertOneOf(\n kind: string,\n value: string,\n choices: readonly string[],\n): void {\n if (choices.includes(value)) return;\n throw new InvalidArgumentError(\n `Unknown ${kind} \"${value}\". Choose one of: ${choices.join(\", \")}.`,\n );\n}\n\n/**\n * Rewrites `style` in `components.json` and nothing else, keeping the file's\n * indentation so the change reads as the one-line diff it is.\n */\nfunction writeStyle(root: string, style: string): void {\n const configPath = path.join(root, COMPONENTS_JSON);\n if (!existsSync(configPath)) {\n throw new Error(\n `${COMPONENTS_JSON} not found in ${root}; this does not look like a shadcn-svelte project.`,\n );\n }\n const text = readFileSync(configPath, \"utf8\");\n const config = JSON.parse(text) as Record<string, unknown>;\n config.style = style;\n const indent = text.includes(\"\\n\\t\") ? \"\\t\" : 2;\n writeFileSync(\n configPath,\n `${JSON.stringify(config, null, indent)}\\n`,\n \"utf8\",\n );\n}\n\nfunction registryUiNames(index: RegistryItem[]): Set<string> {\n return new Set(\n index\n .filter((item) => item.type === \"registry:ui\")\n .map((item) => item.name),\n );\n}\n\n/**\n * Moves a project to another shadcn-svelte style. Every installed component\n * the new style's registry also offers is re-added from there (their local\n * edits are lost, which is what `confirm` is for); this package's own\n * components and anything the registry does not know are left alone. The\n * style's preset font follows unless `font` is false.\n */\nexport async function switchStyle(\n options: SwitchStyleOptions,\n runtime?: WriteResultRuntime,\n): Promise<SwitchStyleResult> {\n const { root, style, font = true } = options;\n const logger = getLogger(options);\n const preset = await loadPreset(root);\n assertOneOf(\"style\", style, preset.PRESET_STYLES);\n\n const unchanged: SwitchStyleResult = {\n status: \"unchanged\",\n style,\n reinstalled: [],\n filesModified: [],\n packages: [],\n hints: [],\n };\n if (readComponentsConfig(root).style === style) {\n return unchanged;\n }\n\n const index = await fetchRegistryIndex(root, { style, runtime });\n const offered = registryUiNames(index);\n const reinstall = installedComponents(root).filter(\n (component) => offered.has(component) && !isCustomComponent(component),\n );\n\n if (options.confirm && !(await options.confirm(reinstall))) {\n return { ...unchanged, status: \"cancelled\" };\n }\n\n const packagesBefore = installedPackagesFromProject(root);\n writeStyle(root, style);\n const filesModified = [COMPONENTS_JSON];\n\n let reinstalled: Component[] = [];\n if (reinstall.length > 0) {\n const outcome = await installComponents(\n { root, components: reinstall, overwrite: true, logger },\n runtime,\n );\n reinstalled = outcome.installed;\n }\n\n const hints: string[] = [];\n if (font) {\n await applyStyleFont(\n root,\n style,\n preset,\n runtime,\n filesModified,\n hints,\n logger,\n );\n }\n\n const packages = [...installedPackagesFromProject(root)]\n .filter((name) => !packagesBefore.has(name))\n .sort();\n\n return {\n status: \"switched\",\n style,\n reinstalled,\n filesModified,\n packages,\n hints,\n };\n}\n\nconst FONTSOURCE_IMPORT =\n /@import\\s+[\"']@fontsource(?:-variable)?\\/([^\"']+)[\"']/g;\n\n/** The fontsource families a stylesheet imports, in order. */\nfunction fontsourceImports(css: string): string[] {\n return [...css.matchAll(FONTSOURCE_IMPORT)].map((match) => match[1]!);\n}\n\nasync function applyStyleFont(\n root: string,\n style: string,\n preset: ShadcnPreset,\n runtime: WriteResultRuntime | undefined,\n filesModified: string[],\n hints: string[],\n logger: ReturnType<typeof getLogger>,\n): Promise<void> {\n const fonts = STYLE_FONTS[style];\n if (!fonts) {\n logger.info(\n `No preset font is known for the ${style} style; leaving fonts unchanged.`,\n );\n return;\n }\n logger.info(`Applying the ${style} font (${fonts.font})`);\n const code = await presetFor(root, { style, ...fonts }, preset);\n await applyPreset(root, code, [\"font\"], runtime);\n\n const cssPath = readComponentsConfig(root).cssPath;\n filesModified.push(cssPath, \"package.json\");\n\n // `apply --only font` adds the new font beside whatever was imported before\n // and leaves it to the project to drop the old one; a font nobody uses\n // still ships to every visitor.\n const cssFile = path.join(root, cssPath);\n if (existsSync(cssFile)) {\n const wanted = new Set([fonts.font, fonts.fontHeading].filter(Boolean));\n const stale = fontsourceImports(readFileSync(cssFile, \"utf8\")).filter(\n (family) => !wanted.has(family),\n );\n if (stale.length > 0) {\n hints.push(\n `${cssPath} still imports ${stale.map((f) => `@fontsource-variable/${f}`).join(\", \")} from the previous style; remove the import and the package if nothing else uses them.`,\n );\n }\n }\n}\n\nasync function applyColors(\n root: string,\n overrides: { baseColor?: string; theme: string },\n runtime?: WriteResultRuntime,\n): Promise<ApplyColorsResult> {\n const preset = await loadPreset(root);\n if (overrides.baseColor) {\n assertOneOf(\n \"base color\",\n overrides.baseColor,\n preset.PRESET_BASE_COLOR_KEYS,\n );\n }\n assertOneOf(\"theme\", overrides.theme, preset.PRESET_THEME_KEYS);\n\n // Charts follow the accent, as shadcn-svelte's own presets do.\n const code = await presetFor(\n root,\n { ...overrides, chartColor: overrides.theme },\n preset,\n );\n await applyPreset(root, code, [\"theme\"], runtime);\n\n const config = readComponentsConfig(root);\n return {\n baseColor: config.baseColor ?? overrides.baseColor ?? \"\",\n theme: overrides.theme,\n filesModified: [config.cssPath, COMPONENTS_JSON],\n };\n}\n\n/**\n * Sets the base (gray) palette. The accent is reset to the base color as\n * well, since `components.json` records only the base color; `applyTheme`\n * puts an accent back on top.\n */\nexport async function applyBaseColor(\n options: ApplyBaseColorOptions,\n runtime?: WriteResultRuntime,\n): Promise<ApplyColorsResult> {\n return applyColors(\n options.root,\n { baseColor: options.color, theme: options.color },\n runtime,\n );\n}\n\n/** Sets the accent (primary, ring, charts) and keeps the base palette. */\nexport async function applyTheme(\n options: ApplyThemeOptions,\n runtime?: WriteResultRuntime,\n): Promise<ApplyColorsResult> {\n return applyColors(options.root, { theme: options.theme }, runtime);\n}\n"],"mappings":";;;;;;;;;AA2CA,eAAsBS,EAAW,GAAqC;CACpE,IAAIC;CACJ,IAAI;EACF,IAAWC,EAAcH,EAAK,KAAKI,GAAM,cAAc,CAAC,CAAC,CAAC,QACxD,sBACF;CACF,SAASC,GAAO;EACd,IAAMC,IAASD,aAAiB,QAAQA,EAAM,UAAU,OAAOA,CAAK;EACpE,MAAU,MACR,4CAA4CD,EAAK,IAAIE,EAAO,2EAE9D;CACF;CAIA,OAAO,MAHuB;;EACTC,EAAcL,CAAQ,CAAC,CAAC;;AAG/C;AAQA,IAAaM,IAGT;CACF,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,EAAE,MAAM,iBAAiB;CAC/B,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM;EAAE,MAAM;EAAa,aAAa;CAAmB;CAC3D,MAAM,EAAE,MAAM,QAAQ;AACxB;AASA,eAAsBC,EACpB,GACA,GACA,GACiB;CACjB,IAAM,EAAE,oBAAiBC,KAAW,MAAMT,EAAWG,CAAI,GACnDO,IAASb,EAAqBM,CAAI,GAClCQ,IAAiC,EAAE,O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GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,uFACvF;CAEJ;AACF;AAEA,eAAeC,EACb,GACA,GACA,GAC4B;CAC5B,IAAMxD,IAAS,MAAMT,EAAWG,CAAI;CAgBpC,AAfIU,EAAU,aACZS,EACE,cACAT,EAAU,WACVJ,EAAO,sBACT,GAEFa,EAAY,SAAST,EAAU,OAAOJ,EAAO,iBAAiB,GAQ9D,MAAMK,EAAYX,GAAM,MALLK,EACjBL,GACA;EAAE,GAAGU;EAAW,YAAYA,EAAU;CAAM,GAC5CJ,CACF,GAC8B,CAAC,OAAO,GAAGQ,CAAO;CAEhD,IAAMP,IAASb,EAAqBM,CAAI;CACxC,OAAO;EACL,WAAWO,EAAO,aAAaG,EAAU,aAAa;EACtD,OAAOA,EAAU;EACjB,eAAe,CAACH,EAAO,SAASQ,CAAe;CACjD;AACF;AAOA,eAAsBgD,EACpB,GACA,GAC4B;CAC5B,OAAOD,EACL7C,EAAQ,MACR;EAAE,WAAWA,EAAQ;EAAO,OAAOA,EAAQ;CAAM,GACjDH,CACF;AACF;AAGA,eAAsBkD,EACpB,GACA,GAC4B;CAC5B,OAAOF,EAAY7C,EAAQ,MAAM,EAAE,OAAOA,EAAQ,MAAM,GAAGH,CAAO;AACpE"}
|
|
@@ -431,7 +431,7 @@ async function ht(e, t, n) {
|
|
|
431
431
|
collectionDrops: []
|
|
432
432
|
}, a = [];
|
|
433
433
|
if (e.collectionDrops.length > 0) {
|
|
434
|
-
let { dropCollections: n } = await import("./collections-
|
|
434
|
+
let { dropCollections: n } = await import("./collections-Cpjo2OiQ.js").then((e) => e.n);
|
|
435
435
|
a = await n(e.collectionDrops, t);
|
|
436
436
|
}
|
|
437
437
|
let o = C.resolve(t.root, "package.json"), s = (e) => e.status === "success" && C.resolve(I(t.root, e.path)) === o;
|
|
@@ -508,4 +508,4 @@ async function ht(e, t, n) {
|
|
|
508
508
|
//#endregion
|
|
509
509
|
export { Q as a, V as c, $ as i, Qe as l, Z as n, B as o, P as r, X as s, z as t };
|
|
510
510
|
|
|
511
|
-
//# sourceMappingURL=write-result-
|
|
511
|
+
//# sourceMappingURL=write-result-Cq-9A7Zy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-result-Cq-9A7Zy.js","names":["__import_glob__0_0_","__import_glob__0_1_","__import_glob__0_2_","__import_glob__0_3_","__import_glob__0_4_","__import_glob__0_5_","__import_glob__0_6_","__import_glob__0_7_","__import_glob__0_8_","__import_glob__0_9_","__import_glob__0_10_","__import_glob__0_11_","__import_glob__0_12_","__import_glob__0_13_","__import_glob__0_14_","__import_glob__0_15_","__import_glob__0_16_","__import_glob__0_17_","__import_glob__0_18_","__import_glob__0_19_","__import_glob__0_20_","__import_glob__0_21_","__import_glob__0_22_","__import_glob__0_23_","__import_glob__0_24_","__import_glob__0_25_","__import_glob__0_26_","__import_glob__0_27_","__import_glob__0_28_","__import_glob__0_29_","__import_glob__0_30_","__import_glob__0_31_","__import_glob__0_32_","__import_glob__0_33_","__import_glob__0_34_","__import_glob__0_35_","__import_glob__0_36_","__import_glob__0_37_","__import_glob__0_38_","__import_glob__0_39_","__import_glob__0_40_","__import_glob__0_41_","__import_glob__0_42_","__import_glob__0_43_","__import_glob__0_44_","__import_glob__0_45_","__import_glob__0_46_","__import_glob__0_47_","__import_glob__0_48_","__import_glob__0_49_","__import_glob__0_50_","__import_glob__0_51_","__import_glob__0_52_","__import_glob__0_53_","__import_glob__0_54_","__import_glob__0_55_","__exportAll","MissingShadcnError","RegistryUnavailableError","InvalidArgumentError","FORMSNAP","TANSTACK_TABLE_CORE","FORMSNAP_OVERRIDES","formatSource","getLogger","NOOP_LOGGER","resolveUiDir","readComponentsConfig","fetchRegistryIndex","assertTableCorePackage","ensurePackageOverrides","path","spawn","os","auth_menu_content_default","auth_menu_group_default","auth_menu_item_default","auth_menu_label_default","auth_menu_separator_default","auth_menu_trigger_default","auth_menu_default$1","context_default","auth_menu_default","autodate_default","bool_default","date_default","editor_default","email_default","file_default","geoPoint_default","cells_default","json_default","number_default","password_default","relation_default","select_default","text_default","url_default","column_header_default$1","column_header_default","data_table_svelte_default","flex_render_default","data_table_default","render_helpers_default","faceted_filter_default$1","faceted_filter_default","file_field_default","file_input_default","file_multiple_default","file_single_default","file_thumb_default","file_form_default","shared_default","coordinate_default","geopoint_default","input_default$1","toggle_map_default","leaflet_default$1","leaflet_default","chip_default","content_default","field_default","multiselect_default","input_default","item_default","trigger_default","pagination_default$1","pagination_default","row_actions_default$1","row_actions_default","write_result_exports","ensureSvelteKitSync","executeCommand","formatPaths","getAllCustomComponents","installComponents","installedComponents","installedPackagesFromProject","isCustomComponent","isExactSpec","packageName","restoreDowngradedDependencies","writeResult","customDependencies","customNpmPackages","customComponentAssets","componentNameFromAssetPath","parts","assetPath","componentRelativeAssetPath","index","toTargetPath","filePath","root","toRelativePath","writeFile","mkdirSync","writeFileSync","content","removeFile","existsSync","rmSync","pruneEmptyDirectories","stop","current","dir","readdirSync","EXACT_FLAG","executeWithDetectedPackageManager","packageManager","detect","resolved","resolveCommand","operation","args","commandArgs","exactFlag","options","child","reject","code","restoreTypes","preserveSvelteKitTypes","cwd","runtime","packageJsonPath","packageJson","readFileSync","at","spec","name","ensureFormsnapOverride","names","toInstall","formsnap","installed","touched","outcome","logger","appDir","saved","mkdtempSync","cpSync","error","DEPENDENCY_BLOCKS","rangeFloor","match","part","value","compareFloors","i","a","b","pkg","after","restored","previous","block","before","entries","old","oldFloor","newFloor","readPackageJson","file","installPackages","packages","exact","ranged","uninstallPackages","toRemove","component","customNpmPackagesFor","components","copyCustomComponent","targetDir","targetComponentsDir","relativePath","outputPath","FORMATTABLE_EXTENSIONS","filesUnder","target","statSync","entry","context","changed","paths","formatted","uiDir","BARE_ITEM_NAME","assertKnownRegistryItems","bare","known","item","unknown","style","requested","componentsDir","isPresent","skipped","overwrite","customToInstall","publicToInstall","dependency","customList","publicList","indent","recorded","had","installedList","writtenResult","dropMigrationCreates","result","n","dropCollections","isPackageJson","packageInstalls","componentInstalls","packageUninstalls"],"sources":["../../src/runtime/write-result.ts"],"sourcesContent":["import {\n cpSync,\n existsSync,\n mkdirSync,\n mkdtempSync,\n readdirSync,\n readFileSync,\n rmSync,\n statSync,\n writeFileSync,\n} from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { detect } from \"package-manager-detector\";\nimport { resolveCommand } from \"package-manager-detector/commands\";\nimport spawn from \"cross-spawn\";\nimport type {\n Component,\n ExecuteCommandOptions,\n InstallComponentsOptions,\n InstallComponentsResult,\n Options,\n PackageManagerOperation,\n Result,\n WriteResultRuntime,\n} from \"../core/types\";\nimport {\n InvalidArgumentError,\n MissingShadcnError,\n RegistryUnavailableError,\n} from \"../core/errors\";\nimport { getLogger, NOOP_LOGGER, type Logger } from \"../core/logger\";\nimport { formatSource } from \"../core/format-result\";\nimport {\n FORMSNAP,\n FORMSNAP_OVERRIDES,\n TANSTACK_TABLE_CORE,\n} from \"../core/constants\";\nimport {\n fetchRegistryIndex,\n readComponentsConfig,\n resolveUiDir,\n} from \"./registry\";\nimport { assertTableCorePackage } from \"./table-core\";\nimport { ensurePackageOverrides } from \"./package-imports\";\n\nexport { resolveUiDir };\n\ntype CustomNpmPackages = Record<string, string[]>;\n\n/**\n * The components under `src/ui/components` are copied into a project rather\n * than fetched from the shadcn-svelte registry, so their dependencies have to\n * be declared here: every shadcn-svelte component a bundled one imports\n * (`#lib/components/ui/<x>/index.js`) must appear in `customDependencies`, and\n * every npm package that no shadcn item installs for it must appear in\n * `customNpmPackages`.\n */\nconst customDependencies: Record<string, string[]> = {\n \"file-form\": [\"input\"],\n multiselect: [\"command\", \"popover\", \"button\"],\n geopoint: [\"button\", \"leaflet\"],\n cells: [\"badge\"],\n \"data-table\": [],\n \"column-header\": [\"dropdown-menu\", \"button\"],\n \"faceted-filter\": [\"command\", \"popover\", \"button\", \"separator\", \"badge\"],\n pagination: [\"button\", \"select\"],\n \"row-actions\": [\"dropdown-menu\", \"button\"],\n leaflet: [],\n \"auth-menu\": [\"dropdown-menu\", \"button\"],\n};\n\nconst customNpmPackages: CustomNpmPackages = {\n \"file-form\": [FORMSNAP],\n multiselect: [FORMSNAP],\n geopoint: [],\n cells: [],\n // shadcn-svelte >= 1.2.0 resolves items from the style-scoped registry\n // (/registry/styles/<style>/), which has no `data-table` item, so the\n // TanStack helpers ship from here instead.\n \"data-table\": [TANSTACK_TABLE_CORE],\n \"column-header\": [TANSTACK_TABLE_CORE],\n \"faceted-filter\": [TANSTACK_TABLE_CORE],\n pagination: [TANSTACK_TABLE_CORE],\n \"row-actions\": [],\n leaflet: [\"leaflet\", \"@types/leaflet\"],\n};\n\nconst customComponentAssets = import.meta.glob<string>(\"../ui/components/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\n/** The components this package ships, by directory name, sorted. */\nexport function getAllCustomComponents(): Component[] {\n return [\n ...new Set(\n Object.keys(customComponentAssets).map(componentNameFromAssetPath),\n ),\n ]\n .filter(Boolean)\n .sort();\n}\n\nfunction componentNameFromAssetPath(assetPath: string): string {\n const parts = assetPath.split(\"/\");\n const index = parts.indexOf(\"components\");\n return parts[index + 1] ?? \"\";\n}\n\nfunction componentRelativeAssetPath(assetPath: string): string {\n const parts = assetPath.split(\"/\");\n const index = parts.indexOf(\"components\");\n return parts.slice(index + 2).join(\"/\");\n}\n\nfunction toTargetPath(root: string, filePath: string): string {\n if (path.isAbsolute(filePath)) {\n return filePath;\n }\n return path.join(root, filePath);\n}\n\nfunction toRelativePath(root: string, filePath: string): string {\n if (path.isAbsolute(filePath)) {\n return path.relative(root, filePath);\n }\n return filePath;\n}\n\nfunction writeFile(filePath: string, content: string): void {\n mkdirSync(path.dirname(filePath), { recursive: true });\n writeFileSync(filePath, content, \"utf8\");\n}\n\nfunction removeFile(filePath: string, root: string): void {\n if (!existsSync(filePath)) {\n return;\n }\n\n rmSync(filePath, { force: true, recursive: true });\n pruneEmptyDirectories(path.dirname(filePath), root);\n}\n\n/**\n * Deleting a feature's files must also delete the directories it added, up\n * to the first one that still has content. The CLI detects features by\n * directory (`src/routes/(app)` means auth is on), so an empty leftover\n * directory keeps a disabled feature \"enabled\".\n */\nfunction pruneEmptyDirectories(dir: string, root: string): void {\n const stop = path.resolve(root);\n let current = path.resolve(dir);\n while (current !== stop && current.startsWith(stop)) {\n if (!existsSync(current) || readdirSync(current).length > 0) {\n return;\n }\n rmSync(current, { recursive: true, force: true });\n current = path.dirname(current);\n }\n}\n\n/** Each package manager's flag for saving the exact version instead of a range. */\nconst EXACT_FLAG: Record<string, string> = {\n npm: \"--save-exact\",\n pnpm: \"--save-exact\",\n yarn: \"--exact\",\n bun: \"--exact\",\n};\n\nasync function executeWithDetectedPackageManager(\n cwd: string,\n operation: PackageManagerOperation,\n args: string[],\n options: ExecuteCommandOptions = {},\n): Promise<void> {\n const packageManager = (await detect({ cwd }))?.name ?? \"npm\";\n // Adding named packages is `add` (`npm i`, `pnpm add`, `yarn add`):\n // `yarn install <pkg>` is an error.\n const resolved = resolveCommand(\n packageManager,\n operation === \"install\" && args.length > 0 ? \"add\" : operation,\n args,\n );\n if (!resolved) {\n throw new Error(\n `Unable to resolve ${operation} command for ${packageManager}`,\n );\n }\n\n const commandArgs = [...resolved.args];\n if (packageManager === \"npm\") {\n commandArgs.unshift(\"--yes\");\n }\n const exactFlag = EXACT_FLAG[packageManager];\n if (options.exact && exactFlag) {\n commandArgs.push(exactFlag);\n }\n\n await new Promise<void>((resolve, reject) => {\n const child = spawn(resolved.command, commandArgs, {\n cwd,\n stdio: \"inherit\",\n });\n child.on(\"error\", reject);\n child.on(\"exit\", (code) => {\n if (code === 0) {\n resolve();\n return;\n }\n reject(\n new Error(`${resolved.command} exited with code ${code ?? \"unknown\"}`),\n );\n });\n });\n}\n\nexport async function executeCommand(\n cwd: string,\n operation: PackageManagerOperation,\n args: string[],\n runtime?: WriteResultRuntime,\n options?: ExecuteCommandOptions,\n): Promise<void> {\n const restoreTypes =\n operation === \"execute\" ? null : preserveSvelteKitTypes(cwd);\n try {\n if (runtime?.executeCommand) {\n await (options\n ? runtime.executeCommand(cwd, operation, args, options)\n : runtime.executeCommand(cwd, operation, args));\n return;\n }\n\n await executeWithDetectedPackageManager(cwd, operation, args, options);\n } finally {\n restoreTypes?.();\n }\n}\n\n/** Package names `package.json` records, whichever dependency block they sit in. */\nexport function installedPackagesFromProject(root: string): Set<string> {\n const packageJsonPath = path.join(root, \"package.json\");\n if (!existsSync(packageJsonPath)) {\n return new Set();\n }\n\n const packageJson = JSON.parse(readFileSync(packageJsonPath, \"utf8\")) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n optionalDependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n };\n\n return new Set([\n ...Object.keys(packageJson.dependencies ?? {}),\n ...Object.keys(packageJson.devDependencies ?? {}),\n ...Object.keys(packageJson.optionalDependencies ?? {}),\n ...Object.keys(packageJson.peerDependencies ?? {}),\n ]);\n}\n\n/**\n * Splits an npm install spec into its package name, dropping any range.\n * `wuchale@^0.26.3` -> `wuchale`, `@wuchale/svelte@^0.21.1` -> `@wuchale/svelte`.\n *\n * The name is what `package.json` records, so it -- not the full spec -- is what\n * the already-installed check has to compare against.\n */\nexport function packageName(spec: string): string {\n const at = spec.indexOf(\"@\", spec.startsWith(\"@\") ? 1 : 0);\n return at === -1 ? spec : spec.slice(0, at);\n}\n\n/**\n * A spec naming one exact version (`sveltekit-superforms@3.0.0-next.1`),\n * which is saved as written. Package managers otherwise save a caret, and a\n * caret on a prerelease follows every later `next` build.\n */\nexport function isExactSpec(spec: string): boolean {\n const name = packageName(spec);\n return /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?$/.test(\n spec.slice(name.length + 1),\n );\n}\n\n/**\n * formsnap 2 peers superforms ^2 and projects run superforms 3, so the\n * override has to be in package.json before an install that brings either in\n * next to formsnap, or npm stops with ERESOLVE.\n */\nfunction ensureFormsnapOverride(\n root: string,\n installed: Set<string>,\n toInstall: string[],\n logger: Logger,\n): void {\n const names = new Set(toInstall.map(packageName));\n const formsnap = names.has(\"formsnap\") || installed.has(\"formsnap\");\n const touched = names.has(\"formsnap\") || names.has(\"sveltekit-superforms\");\n if (!formsnap || !touched) {\n return;\n }\n const { outcome } = ensurePackageOverrides(root, FORMSNAP_OVERRIDES);\n if (outcome.status === \"failed\") {\n logger.info(outcome.message);\n } else if (outcome.status === \"success\" && outcome.changed) {\n logger.info(\"Added the formsnap override for sveltekit-superforms\");\n }\n}\n\n/**\n * SvelteKit 3's tsconfig extends `$app/tsconfig`, which `svelte-kit sync`\n * writes to `node_modules/$app`. A package-manager install prunes that folder\n * (it is no package) and only an argument-less npm install's `prepare` writes\n * it back, so after `npm install <pkg>` every tool that reads the tsconfig\n * (shadcn-svelte, svelte-check without sync, the editor) fails on the missing\n * `extends`. Syncing again is no fix mid-pattern: it loads vite.config, which\n * may already name a plugin whose own config the pattern has not written yet.\n * So the folder is copied aside before an install and put back after.\n */\nfunction preserveSvelteKitTypes(root: string): (() => void) | null {\n const appDir = path.join(root, \"node_modules\", \"$app\");\n if (!existsSync(appDir)) {\n return null;\n }\n const saved = mkdtempSync(path.join(os.tmpdir(), \"vela-app-types-\"));\n cpSync(appDir, path.join(saved, \"$app\"), { recursive: true });\n return () => {\n try {\n if (!existsSync(appDir) && existsSync(path.join(root, \"node_modules\"))) {\n cpSync(path.join(saved, \"$app\"), appDir, { recursive: true });\n }\n } finally {\n rmSync(saved, { recursive: true, force: true });\n }\n };\n}\n\n/**\n * Run `svelte-kit sync` when SvelteKit is installed but `node_modules/$app`\n * is missing (a fresh copy of `node_modules`, or an install made outside\n * vela), so shadcn-svelte can read the tsconfig. Best effort: a sync that\n * fails is reported and left to shadcn-svelte to complain about.\n */\nexport async function ensureSvelteKitSync(\n root: string,\n runtime?: WriteResultRuntime,\n logger: Logger = NOOP_LOGGER,\n): Promise<boolean> {\n if (!existsSync(path.join(root, \"node_modules\", \"@sveltejs\", \"kit\"))) {\n return false;\n }\n if (existsSync(path.join(root, \"node_modules\", \"$app\", \"tsconfig.json\"))) {\n return false;\n }\n try {\n await executeCommand(root, \"execute\", [\"svelte-kit\", \"sync\"], runtime);\n return true;\n } catch (error) {\n logger.info(\n `svelte-kit sync failed (${error instanceof Error ? error.message : String(error)}); node_modules/$app is missing`,\n );\n return false;\n }\n}\n\ntype DependencyBlocks = Record<string, Record<string, string> | undefined>;\n\nconst DEPENDENCY_BLOCKS = [\n \"dependencies\",\n \"devDependencies\",\n \"optionalDependencies\",\n] as const;\n\n/** The lowest version a range names, as numbers, or null when it is no semver range. */\nfunction rangeFloor(spec: string): number[] | null {\n const match = spec\n .trim()\n .match(\n /^(?:[\\^~=v]|>=?)?\\s*(\\d+)(?:\\.(\\d+|[xX*]))?(?:\\.(\\d+|[xX*]))?(-[0-9A-Za-z.-]+)?$/,\n );\n if (!match) {\n return null;\n }\n const part = (value: string | undefined) =>\n value === undefined || /[xX*]/.test(value) ? 0 : Number(value);\n // A prerelease sorts below its release.\n return [part(match[1]), part(match[2]), part(match[3]), match[4] ? 0 : 1];\n}\n\nfunction compareFloors(a: number[], b: number[]): number {\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) {\n return a[i]! - b[i]!;\n }\n }\n return 0;\n}\n\n/**\n * The dependency entries `shadcn-svelte add` changed that have to go back:\n * shadcn replaces any range its registry item's own range does not cover,\n * downgrades included. The form item still asks for `sveltekit-superforms`\n * ^2, which SvelteKit 3 cannot install, over the project's 3.x pin. So an\n * entry the project already had is restored when shadcn moved it below\n * where it was, or when it is not a semver range at all (file:, git,\n * workspace:). A raised floor and every new entry are kept.\n */\nexport function restoreDowngradedDependencies(\n before: DependencyBlocks,\n after: DependencyBlocks,\n): { pkg: DependencyBlocks; restored: string[] } {\n const pkg: DependencyBlocks = { ...after };\n const restored: string[] = [];\n const previous = new Map<string, string>();\n for (const block of DEPENDENCY_BLOCKS) {\n for (const [name, spec] of Object.entries(before[block] ?? {})) {\n previous.set(name, spec);\n }\n }\n for (const block of DEPENDENCY_BLOCKS) {\n const entries = after[block];\n if (!entries) {\n continue;\n }\n for (const [name, spec] of Object.entries(entries)) {\n const old = previous.get(name);\n if (old === undefined || old === spec) {\n continue;\n }\n const oldFloor = rangeFloor(old);\n const newFloor = rangeFloor(spec);\n const keep =\n oldFloor !== null &&\n newFloor !== null &&\n compareFloors(newFloor, oldFloor) >= 0;\n if (keep) {\n continue;\n }\n pkg[block] = { ...(pkg[block] as Record<string, string>), [name]: old };\n restored.push(`${name}@${old}`);\n }\n }\n return { pkg, restored };\n}\n\nfunction readPackageJson(root: string): Record<string, unknown> | null {\n const file = path.join(root, \"package.json\");\n if (!existsSync(file)) {\n return null;\n }\n return JSON.parse(readFileSync(file, \"utf8\")) as Record<string, unknown>;\n}\n\nasync function installPackages(\n root: string,\n packages: string[],\n runtime?: WriteResultRuntime,\n logger: Logger = NOOP_LOGGER,\n): Promise<string[]> {\n if (packages.length === 0) {\n return [];\n }\n\n const installed = installedPackagesFromProject(root);\n const toInstall = [...new Set(packages)].filter(\n (pkg) => !installed.has(packageName(pkg)),\n );\n if (toInstall.length === 0) {\n return [];\n }\n\n ensureFormsnapOverride(root, installed, toInstall, logger);\n\n logger.info(`Installing packages: ${toInstall.join(\", \")}`);\n // `--save-exact` applies to a whole command, so exact pins go in their own.\n const exact = toInstall.filter(isExactSpec);\n const ranged = toInstall.filter((spec) => !isExactSpec(spec));\n if (exact.length > 0) {\n await executeCommand(root, \"install\", exact, runtime, { exact: true });\n }\n if (ranged.length > 0) {\n await executeCommand(root, \"install\", ranged, runtime);\n }\n return toInstall;\n}\n\n/**\n * `npm uninstall` for the listed packages that `package.json` records. The\n * inverse of `installPackages`: names not present are skipped, so a disable\n * pattern can name everything its enable counterpart installed.\n */\nasync function uninstallPackages(\n root: string,\n packages: string[],\n runtime?: WriteResultRuntime,\n logger: Logger = NOOP_LOGGER,\n): Promise<string[]> {\n if (packages.length === 0) {\n return [];\n }\n\n const installed = installedPackagesFromProject(root);\n const toRemove = [...new Set(packages.map(packageName))].filter((pkg) =>\n installed.has(pkg),\n );\n if (toRemove.length === 0) {\n return [];\n }\n\n logger.info(`Removing packages: ${toRemove.join(\", \")}`);\n await executeCommand(root, \"uninstall\", toRemove, runtime);\n return toRemove;\n}\n\nexport function isCustomComponent(component: string): boolean {\n return getAllCustomComponents().includes(component);\n}\n\nfunction customNpmPackagesFor(components: string[]): string[] {\n return [\n ...new Set(\n components.flatMap((component) => customNpmPackages[component] ?? []),\n ),\n ];\n}\n\nfunction copyCustomComponent(\n component: string,\n targetComponentsDir: string,\n): void {\n const targetDir = path.join(targetComponentsDir, component);\n mkdirSync(targetDir, { recursive: true });\n\n for (const [assetPath, content] of Object.entries(customComponentAssets)) {\n if (componentNameFromAssetPath(assetPath) !== component) {\n continue;\n }\n const relativePath = componentRelativeAssetPath(assetPath);\n if (!relativePath) {\n continue;\n }\n\n const outputPath = path.join(targetDir, relativePath);\n mkdirSync(path.dirname(outputPath), { recursive: true });\n writeFileSync(outputPath, content, \"utf8\");\n }\n}\n\nconst FORMATTABLE_EXTENSIONS = new Set([\n \".ts\",\n \".js\",\n \".svelte\",\n \".json\",\n \".css\",\n]);\n\nfunction* filesUnder(target: string): Generator<string> {\n if (!existsSync(target)) {\n return;\n }\n if (statSync(target).isFile()) {\n yield target;\n return;\n }\n const entries = readdirSync(target, { recursive: true, withFileTypes: true });\n for (const entry of entries) {\n if (entry.isFile()) {\n yield path.join(entry.parentPath, entry.name);\n }\n }\n}\n\n/**\n * `shadcn-svelte add` and `apply` write files in the registry's style and the\n * bundled components carry this repo's; the project's `npm run lint` expects\n * its own. Runs the project's prettier over the given files and directories\n * (relative to the root or absolute) and returns the relative paths it\n * changed. Paths that do not exist are skipped.\n */\nexport async function formatPaths(\n root: string,\n paths: string[],\n): Promise<string[]> {\n const context = { env: \"runtime\" as const, root };\n const changed: string[] = [];\n for (const target of paths) {\n for (const filePath of filesUnder(toTargetPath(root, target))) {\n if (!FORMATTABLE_EXTENSIONS.has(path.extname(filePath))) {\n continue;\n }\n const content = readFileSync(filePath, \"utf8\");\n const formatted = await formatSource(content, filePath, context);\n if (formatted !== content) {\n writeFileSync(filePath, formatted, \"utf8\");\n changed.push(path.relative(root, filePath));\n }\n }\n }\n return changed;\n}\n\n/** The component directories a project has, sorted. */\nexport function installedComponents(root: string): Component[] {\n const uiDir = resolveUiDir(root);\n if (!existsSync(uiDir)) {\n return [];\n }\n return readdirSync(uiDir, { withFileTypes: true })\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name)\n .sort();\n}\n\n/** Bare item names are checked against the index; URLs and `@scope/item` are shadcn's to resolve. */\nconst BARE_ITEM_NAME = /^[a-z0-9][a-z0-9-]*$/i;\n\n/**\n * A name the style's registry does not list would otherwise reach\n * `shadcn-svelte add`, which fails after a fetch with a message that never\n * mentions the style. Skipped when the registry cannot be read: shadcn will\n * report that itself.\n */\nasync function assertKnownRegistryItems(\n root: string,\n components: Component[],\n runtime: WriteResultRuntime | undefined,\n logger: Logger,\n): Promise<void> {\n const bare = components.filter((component) => BARE_ITEM_NAME.test(component));\n if (bare.length === 0) {\n return;\n }\n let known: Set<string>;\n try {\n const index = await fetchRegistryIndex(root, { runtime });\n known = new Set(index.map((item) => item.name));\n } catch (error) {\n if (!(error instanceof RegistryUnavailableError)) throw error;\n logger.info(`${error.message}; leaving component names to shadcn-svelte`);\n return;\n }\n const unknown = bare.filter((component) => !known.has(component));\n if (unknown.length === 0) {\n return;\n }\n const { style } = readComponentsConfig(root);\n const names = unknown.map((component) => `\"${component}\"`).join(\", \");\n throw new InvalidArgumentError(\n `Unknown component${unknown.length > 1 ? \"s\" : \"\"} ${names} for style ${style}. Run \\`vela ui list\\` to see what is available.`,\n );\n}\n\nexport async function installComponents(\n options: InstallComponentsOptions,\n runtime?: WriteResultRuntime,\n): Promise<InstallComponentsResult> {\n const { root, components, overwrite = false } = options;\n const logger = getLogger(options);\n\n const requested = [...new Set(components)];\n if (requested.length === 0) {\n return { installed: [], skipped: [], packages: [] };\n }\n\n // `shadcn-svelte add` exits 1 without a `components.json`, after the custom\n // components and their packages are already in. Checked first, so a project\n // without shadcn-svelte is refused whole rather than left half-written.\n if (!existsSync(path.join(root, \"components.json\"))) {\n throw new MissingShadcnError(\n `Adding ${requested.length > 1 ? \"components\" : \"a component\"} (${requested.join(\", \")})`,\n );\n }\n\n const componentsDir = resolveUiDir(root);\n mkdirSync(componentsDir, { recursive: true });\n const isPresent = (component: string) =>\n existsSync(path.join(componentsDir, component));\n\n const skipped = overwrite ? [] : requested.filter(isPresent);\n const toInstall = requested.filter(\n (component) => !skipped.includes(component),\n );\n if (skipped.length > 0) {\n logger.info(`Already present: ${skipped.join(\", \")}`);\n }\n if (toInstall.length === 0) {\n return { installed: [], skipped, packages: [] };\n }\n\n const customToInstall = new Set(toInstall.filter(isCustomComponent));\n const publicToInstall = new Set(\n toInstall.filter((component) => !isCustomComponent(component)),\n );\n\n // Dependencies are added only when missing, even under `overwrite`:\n // re-adding `button` because `pagination` was re-added would clobber edits\n // the user never asked to lose.\n for (const component of [...customToInstall]) {\n for (const dependency of customDependencies[component] ?? []) {\n if (isPresent(dependency)) {\n continue;\n }\n if (isCustomComponent(dependency)) {\n customToInstall.add(dependency);\n } else {\n publicToInstall.add(dependency);\n }\n }\n }\n\n // `installPackages` keeps an existing @tanstack/table-core whatever its range.\n assertTableCorePackage(root, [...customToInstall]);\n\n const installed: string[] = [];\n const customList = [...customToInstall].sort();\n if (customList.length > 0) {\n logger.info(`Installing custom components: ${customList.join(\", \")}`);\n }\n for (const component of customList) {\n copyCustomComponent(component, componentsDir);\n installed.push(component);\n publicToInstall.delete(component);\n }\n\n const packages = await installPackages(\n root,\n customNpmPackagesFor(customList),\n runtime,\n logger,\n );\n\n const publicList = [...publicToInstall].sort();\n if (publicList.length > 0) {\n await assertKnownRegistryItems(root, publicList, runtime, logger);\n logger.info(\n `Installing shadcn-svelte components: ${publicList.join(\", \")}`,\n );\n // shadcn-svelte reads the tsconfig, whose `extends` an install may have pruned.\n await ensureSvelteKitSync(root, runtime, logger);\n // shadcn only records its packages; they are installed below, once any\n // pin it moved backwards is put back.\n const before = readPackageJson(root);\n await executeCommand(\n root,\n \"execute\",\n [\n \"shadcn-svelte\",\n \"add\",\n \"--yes\",\n \"--overwrite\",\n \"--no-deps-install\",\n ...publicList,\n ],\n runtime,\n );\n installed.push(...publicList);\n const after = readPackageJson(root);\n if (before && after && JSON.stringify(before) !== JSON.stringify(after)) {\n const { pkg, restored } = restoreDowngradedDependencies(\n before as DependencyBlocks,\n after as DependencyBlocks,\n );\n if (restored.length > 0) {\n logger.info(\n `Kept ${restored.join(\", \")} (shadcn-svelte asked for an older range)`,\n );\n const file = path.join(root, \"package.json\");\n const indent =\n readFileSync(file, \"utf8\").match(/^[{]\\s*\\n([\\t ]+)/)?.[1] ?? \"\\t\";\n writeFileSync(file, `${JSON.stringify(pkg, null, indent)}\\n`, \"utf8\");\n }\n const recorded = (pkg: Record<string, unknown>) =>\n new Set(\n DEPENDENCY_BLOCKS.flatMap((block) =>\n Object.keys((pkg[block] as Record<string, string>) ?? {}),\n ),\n );\n const had = recorded(before);\n const added = [...recorded(after)].filter((name) => !had.has(name));\n ensureFormsnapOverride(root, had, added, logger);\n await executeCommand(root, \"install\", [], runtime);\n }\n }\n\n const installedList = [...new Set(installed)].sort();\n await formatPaths(\n root,\n installedList.map((component) => path.join(componentsDir, component)),\n );\n\n return { installed: installedList, skipped, packages };\n}\n\nexport async function writeResult(\n result: Result,\n options: Options,\n runtime?: WriteResultRuntime,\n): Promise<Result> {\n const logger = getLogger(options);\n\n const writtenResult: Result = {\n creates: [],\n modifies: [],\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n };\n\n let dropMigrationCreates: Result[\"creates\"] = [];\n if (result.collectionDrops.length > 0) {\n const { dropCollections } = await import(\"./collections\");\n dropMigrationCreates = await dropCollections(\n result.collectionDrops,\n options,\n );\n }\n\n // A package.json edit lands before the package manager runs, so the install\n // builds on it. Written after, its content (read before the install) would\n // take back every dependency the install just recorded.\n const packageJsonPath = path.resolve(options.root, \"package.json\");\n const isPackageJson = (file: Result[\"modifies\"][number]) =>\n file.status === \"success\" &&\n path.resolve(toTargetPath(options.root, file.path)) === packageJsonPath;\n for (const file of result.modifies.filter(isPackageJson)) {\n writeFile(packageJsonPath, file.content);\n }\n\n const packageInstalls = await installPackages(\n options.root,\n result.packages,\n runtime,\n logger,\n );\n\n const componentInstalls = await installComponents(\n { root: options.root, components: result.components, logger },\n runtime,\n );\n\n const packageUninstalls = await uninstallPackages(\n options.root,\n result.uninstalls ?? [],\n runtime,\n logger,\n );\n\n for (const file of [...result.creates, ...dropMigrationCreates]) {\n if (file.status !== \"success\") {\n // A modifier that could not recognise the file it was asked to edit\n // reports `failed` / `not-found` with a paste-ready remediation snippet.\n // Nothing is written, but the entry has to survive into the result: this\n // loop used to `continue` before pushing, so the entry never reached the\n // caller at all and the snippet was lost. The pattern reported success\n // and simply said nothing about the file it had given up on.\n writtenResult.creates.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n continue;\n }\n const target = toTargetPath(options.root, file.path);\n if (!existsSync(target)) {\n writeFile(target, file.content);\n writtenResult.creates.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n continue;\n }\n if (readFileSync(target, \"utf8\") !== file.content) {\n writeFile(target, file.content);\n writtenResult.modifies.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n }\n }\n\n for (const file of result.modifies) {\n if (isPackageJson(file)) {\n writtenResult.modifies.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n continue;\n }\n if (file.status !== \"success\") {\n // Carried through unwritten, so the caller can report the failure. See\n // the note in the creates loop above.\n writtenResult.modifies.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n continue;\n }\n writeFile(toTargetPath(options.root, file.path), file.content);\n writtenResult.modifies.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n }\n\n for (const file of result.deletes) {\n if (file.status !== \"success\") {\n writtenResult.deletes.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n continue;\n }\n if (existsSync(toTargetPath(options.root, file.path))) {\n removeFile(toTargetPath(options.root, file.path), options.root);\n writtenResult.deletes.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n }\n }\n\n return {\n ...result,\n creates: writtenResult.creates,\n modifies: writtenResult.modifies,\n deletes: writtenResult.deletes,\n components: componentInstalls.installed,\n packages: [...new Set([...packageInstalls, ...componentInstalls.packages])],\n ...(packageUninstalls.length > 0 ? { uninstalls: packageUninstalls } : {}),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;IA0DM+I,KAA+C;CACnD,aAAa,CAAC,OAAO;CACrB,aAAa;EAAC;EAAW;EAAW;CAAQ;CAC5C,UAAU,CAAC,UAAU,SAAS;CAC9B,OAAO,CAAC,OAAO;CACf,cAAc,CAAC;CACf,iBAAiB,CAAC,iBAAiB,QAAQ;CAC3C,kBAAkB;EAAC;EAAW;EAAW;EAAU;EAAa;CAAO;CACvE,YAAY,CAAC,UAAU,QAAQ;CAC/B,eAAe,CAAC,iBAAiB,QAAQ;CACzC,SAAS,CAAC;CACV,aAAa,CAAC,iBAAiB,QAAQ;AACzC,GAEMC,KAAuC;CAC3C,aAAa,CAACpF,CAAQ;CACtB,aAAa,CAACA,CAAQ;CACtB,UAAU,CAAC;CACX,OAAO,CAAC;CAIR,cAAc,CAACC,CAAmB;CAClC,iBAAiB,CAACA,CAAmB;CACrC,kBAAkB,CAACA,CAAmB;CACtC,YAAY,CAACA,CAAmB;CAChC,eAAe,CAAC;CAChB,SAAS,CAAC,WAAW,gBAAgB;AACvC,GAEMoF,IAAwB,uBAAA,OAAA;CAAA,uDAAAjJ;CAAA,qDAAAC;CAAA,oDAAAC;CAAA,qDAAAC;CAAA,yDAAAC;CAAA,uDAAAC;CAAA,+CAAAC;CAAA,yCAAAC;CAAA,uCAAAC;CAAA,0CAAAC;CAAA,sCAAAC;CAA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