@velastack/patterns 0.2.0 → 0.2.2

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.
Files changed (47) hide show
  1. package/README.md +10 -1
  2. package/dist/chunks/{collections-DcnlHh80.js → collections-1Z0NCLM-.js} +3 -3
  3. package/dist/chunks/{collections-DcnlHh80.js.map → collections-1Z0NCLM-.js.map} +1 -1
  4. package/dist/chunks/errors-D6gyegUK.js +14 -0
  5. package/dist/chunks/errors-D6gyegUK.js.map +1 -0
  6. package/dist/chunks/{generate-3QOmCHGZ.js → generate-vRi-W3rL.js} +2 -2
  7. package/dist/chunks/{generate-3QOmCHGZ.js.map → generate-vRi-W3rL.js.map} +1 -1
  8. package/dist/chunks/{generate.runtime-DURymKCu.js → generate.runtime-BHoIbpFW.js} +2 -2
  9. package/dist/chunks/{generate.runtime-DURymKCu.js.map → generate.runtime-BHoIbpFW.js.map} +1 -1
  10. package/dist/chunks/{generate.runtime-CsGO0zuZ.js → generate.runtime-BhgkUhnZ.js} +2 -2
  11. package/dist/chunks/{generate.runtime-CsGO0zuZ.js.map → generate.runtime-BhgkUhnZ.js.map} +1 -1
  12. package/dist/chunks/{generate.runtime-4QI3es6J.js → generate.runtime-BiQzi7ie.js} +2 -2
  13. package/dist/chunks/{generate.runtime-4QI3es6J.js.map → generate.runtime-BiQzi7ie.js.map} +1 -1
  14. package/dist/chunks/{generate.runtime-CVc_YHTk.js → generate.runtime-C3kgmLls.js} +2 -2
  15. package/dist/chunks/{generate.runtime-CVc_YHTk.js.map → generate.runtime-C3kgmLls.js.map} +1 -1
  16. package/dist/chunks/{generate.runtime-Bhr2eJg6.js → generate.runtime-CbSifpZG.js} +3 -3
  17. package/dist/chunks/{generate.runtime-Bhr2eJg6.js.map → generate.runtime-CbSifpZG.js.map} +1 -1
  18. package/dist/chunks/{generate.runtime-CL7NYB3N.js → generate.runtime-CflCO_6s.js} +2 -2
  19. package/dist/chunks/{generate.runtime-CL7NYB3N.js.map → generate.runtime-CflCO_6s.js.map} +1 -1
  20. package/dist/chunks/{generate.runtime-CAEeX7Pf.js → generate.runtime-CqOjFGKT.js} +3 -3
  21. package/dist/chunks/{generate.runtime-CAEeX7Pf.js.map → generate.runtime-CqOjFGKT.js.map} +1 -1
  22. package/dist/chunks/{generate.runtime-D0D5jods.js → generate.runtime-DUFPsIYY.js} +3 -3
  23. package/dist/chunks/{generate.runtime-D0D5jods.js.map → generate.runtime-DUFPsIYY.js.map} +1 -1
  24. package/dist/chunks/{generate.runtime-CAzHPuHk.js → generate.runtime-DYySjH4f.js} +2 -2
  25. package/dist/chunks/{generate.runtime-CAzHPuHk.js.map → generate.runtime-DYySjH4f.js.map} +1 -1
  26. package/dist/chunks/{generate.runtime-B3IKmGyV.js → generate.runtime-DpgPAnEd.js} +2 -2
  27. package/dist/chunks/{generate.runtime-B3IKmGyV.js.map → generate.runtime-DpgPAnEd.js.map} +1 -1
  28. package/dist/chunks/{generate.runtime-CsBQGP_O.js → generate.runtime-JtRQn3Yl.js} +2 -2
  29. package/dist/chunks/{generate.runtime-CsBQGP_O.js.map → generate.runtime-JtRQn3Yl.js.map} +1 -1
  30. package/dist/chunks/pocketbase-059B1oot.js +228 -0
  31. package/dist/chunks/pocketbase-059B1oot.js.map +1 -0
  32. package/dist/chunks/{shared-ClWQZdMa.js → shared-CaHmNkZE.js} +2 -2
  33. package/dist/chunks/{shared-ClWQZdMa.js.map → shared-CaHmNkZE.js.map} +1 -1
  34. package/dist/chunks/ui-DAtVMiVs.js +173 -0
  35. package/dist/chunks/ui-DAtVMiVs.js.map +1 -0
  36. package/dist/chunks/write-result-BHCOxcsA.js +445 -0
  37. package/dist/chunks/write-result-BHCOxcsA.js.map +1 -0
  38. package/dist/index.d.ts +109 -1
  39. package/dist/index.js +1878 -1842
  40. package/dist/index.js.map +1 -1
  41. package/package.json +2 -1
  42. package/dist/chunks/errors-D3Zy3wCg.js +0 -10
  43. package/dist/chunks/errors-D3Zy3wCg.js.map +0 -1
  44. package/dist/chunks/pocketbase-fERkp8b8.js +0 -123
  45. package/dist/chunks/pocketbase-fERkp8b8.js.map +0 -1
  46. package/dist/chunks/write-result-8JW_vky2.js +0 -355
  47. package/dist/chunks/write-result-8JW_vky2.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-CsBQGP_O.js","names":[],"sources":["../../src/patterns/disable/api-keys/modifies/hooks.server.ts","../../src/patterns/disable/api-keys/modifies/nav-user.svelte.ts","../../src/patterns/disable/api-keys/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n if (!callExpr) return { status: \"success\", changed: false };\n\n const [firstArg] = callExpr.getArguments();\n if (!firstArg || firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n const apiProp = optionsObj.getProperty(\"api\");\n if (!apiProp || apiProp.getKind() !== SyntaxKind.PropertyAssignment) {\n return { status: \"success\", changed: false };\n }\n\n const apiInit = (\n apiProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (!apiInit || apiInit.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const apiObj = apiInit as import(\"ts-morph\").ObjectLiteralExpression;\n const apiKeysProp = apiObj.getProperty(\"apiKeys\");\n if (!apiKeysProp) {\n return { status: \"success\", changed: false };\n }\n\n apiKeysProp.remove();\n\n sourceFile.formatText();\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/api-keys\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"API Keys\",\n \"@lucide/svelte/icons/key-round\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyHooksServer } from \"./modifies/hooks.server\";\nimport { unmodifyNavUser } from \"./modifies/nav-user.svelte\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerPath, unmodifyHooksServer(hooksServerPath)),\n );\n\n logger.info(\"Reverting nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n const collectionDrops = await planDropsForCollections([\"api_keys\"], options);\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAIA,SAAgB,EAAoB,GAAwC;CAC1E,IAAI,CAAC,EAAG,WAAW,CAAe,GAChC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAiB,EAAG,aAAa,GAAiB,MAAM,GAExD,IAAa,IADC,EACD,CAAA,CAAQ,oBAAoB,CAAe,GAExD,IAAW,EACd,qBAAqB,EAAW,cAAc,CAAC,CAC/C,MAAM,MAAO,EAAG,cAAc,CAAC,CAAC,QAAQ,MAAM,kBAAkB;CACnE,IAAI,CAAC,GAAU,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE1D,IAAM,CAAC,KAAY,EAAS,aAAa;CACzC,IAAI,CAAC,KAAY,EAAS,QAAQ,MAAM,EAAW,yBACjD,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAI7C,IAAM,IADa,EAAS,cAAc,EAAW,uBACrC,CAAA,CAAW,YAAY,KAAK;CAC5C,IAAI,CAAC,KAAW,EAAQ,QAAQ,MAAM,EAAW,oBAC/C,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IACJ,EACA,eAAe;CACjB,IAAI,CAAC,KAAW,EAAQ,QAAQ,MAAM,EAAW,yBAC/C,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAI7C,IAAM,IAAc,EAAO,YAAY,SAAS;CAUhD,OATK,KAIL,EAAY,OAAO,GAEnB,EAAW,WAAW,GACtB,EAAW,SAAS,GAEb;EACL,QAAQ;E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,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MAV4B,EAAwB,CAAC,UAAU,GAAG,CAAO;CAW3E;AACF"}
1
+ {"version":3,"file":"generate.runtime-JtRQn3Yl.js","names":[],"sources":["../../src/patterns/disable/api-keys/modifies/hooks.server.ts","../../src/patterns/disable/api-keys/modifies/nav-user.svelte.ts","../../src/patterns/disable/api-keys/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n if (!callExpr) return { status: \"success\", changed: false };\n\n const [firstArg] = callExpr.getArguments();\n if (!firstArg || firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n const apiProp = optionsObj.getProperty(\"api\");\n if (!apiProp || apiProp.getKind() !== SyntaxKind.PropertyAssignment) {\n return { status: \"success\", changed: false };\n }\n\n const apiInit = (\n apiProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (!apiInit || apiInit.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const apiObj = apiInit as import(\"ts-morph\").ObjectLiteralExpression;\n const apiKeysProp = apiObj.getProperty(\"apiKeys\");\n if (!apiKeysProp) {\n return { status: \"success\", changed: false };\n }\n\n apiKeysProp.remove();\n\n sourceFile.formatText();\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/api-keys\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"API Keys\",\n \"@lucide/svelte/icons/key-round\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyHooksServer } from \"./modifies/hooks.server\";\nimport { unmodifyNavUser } from \"./modifies/nav-user.svelte\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerPath, unmodifyHooksServer(hooksServerPath)),\n );\n\n logger.info(\"Reverting nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n const collectionDrops = await planDropsForCollections([\"api_keys\"], options);\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAIA,SAAgB,EAAoB,GAAwC;CAC1E,IAAI,CAAC,EAAG,WAAW,CAAe,GAChC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAiB,EAAG,aAAa,GAAiB,MAAM,GAExD,IAAa,IADC,EACD,CAAA,CAAQ,oBAAoB,CAAe,GAExD,IAAW,EACd,qBAAqB,EAAW,cAAc,CAAC,CAC/C,MAAM,MAAO,EAAG,cAAc,CAAC,CAAC,QAAQ,MAAM,kBAAkB;CACnE,IAAI,CAAC,GAAU,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE1D,IAAM,CAAC,KAAY,EAAS,aAAa;CACzC,IAAI,CAAC,KAAY,EAAS,QAAQ,MAAM,EAAW,yBACjD,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAI7C,IAAM,IADa,EAAS,cAAc,EAAW,uBACrC,CAAA,CAAW,YAAY,KAAK;CAC5C,IAAI,CAAC,KAAW,EAAQ,QAAQ,MAAM,EAAW,oBAC/C,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IACJ,EACA,eAAe;CACjB,IAAI,CAAC,KAAW,EAAQ,QAAQ,MAAM,EAAW,yBAC/C,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAI7C,IAAM,IAAc,EAAO,YAAY,SAAS;CAUhD,OATK,KAIL,EAAY,OAAO,GAEnB,EAAW,WAAW,GACtB,EAAW,SAAS,GAEb;EACL,QAAQ;EACR,SAAS,EAAW,YAAY,MAAM;CACxC,KAXS;EAAE,QAAQ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mB,CAAC;EACpB,iBAAA,MAV4B,EAAwB,CAAC,UAAU,GAAG,CAAO;CAW3E;AACF"}
@@ -0,0 +1,228 @@
1
+ import { i as e, n as t } from "./constants-PBCzh8eY.js";
2
+ import n from "node:path";
3
+ import { existsSync as r, readFileSync as i, readdirSync as a } from "node:fs";
4
+ import o from "pocketbase";
5
+ import { detect as s } from "package-manager-detector";
6
+ import { resolveCommand as c } from "package-manager-detector/commands";
7
+ import l from "cross-spawn";
8
+ import u from "node:net";
9
+ //#region src/runtime/net.ts
10
+ var d = /* @__PURE__ */ new Set([
11
+ 1,
12
+ 7,
13
+ 9,
14
+ 11,
15
+ 13,
16
+ 15,
17
+ 17,
18
+ 19,
19
+ 20,
20
+ 21,
21
+ 22,
22
+ 23,
23
+ 25,
24
+ 37,
25
+ 42,
26
+ 43,
27
+ 53,
28
+ 69,
29
+ 77,
30
+ 79,
31
+ 87,
32
+ 95,
33
+ 101,
34
+ 102,
35
+ 103,
36
+ 104,
37
+ 109,
38
+ 110,
39
+ 111,
40
+ 113,
41
+ 115,
42
+ 117,
43
+ 119,
44
+ 123,
45
+ 135,
46
+ 137,
47
+ 139,
48
+ 143,
49
+ 161,
50
+ 179,
51
+ 389,
52
+ 427,
53
+ 465,
54
+ 512,
55
+ 513,
56
+ 514,
57
+ 515,
58
+ 526,
59
+ 530,
60
+ 531,
61
+ 532,
62
+ 540,
63
+ 548,
64
+ 554,
65
+ 556,
66
+ 563,
67
+ 587,
68
+ 601,
69
+ 636,
70
+ 989,
71
+ 990,
72
+ 993,
73
+ 995,
74
+ 1719,
75
+ 1720,
76
+ 1723,
77
+ 2049,
78
+ 3659,
79
+ 4045,
80
+ 4190,
81
+ 5060,
82
+ 5061,
83
+ 6e3,
84
+ 6566,
85
+ 6665,
86
+ 6666,
87
+ 6667,
88
+ 6668,
89
+ 6669,
90
+ 6679,
91
+ 6697,
92
+ 10080
93
+ ]);
94
+ function f(e) {
95
+ return new Promise((t, n) => {
96
+ let r = u.createServer();
97
+ r.unref(), r.once("error", n), r.listen(0, e, () => {
98
+ let { port: e } = r.address();
99
+ r.close(() => t(e));
100
+ });
101
+ });
102
+ }
103
+ async function p(e) {
104
+ for (;;) {
105
+ let t = await f(e);
106
+ if (!d.has(t)) return t;
107
+ }
108
+ }
109
+ function m(e, t, n = 60) {
110
+ return new Promise((r, i) => {
111
+ let a = 0, o = () => {
112
+ a++;
113
+ let s = new u.Socket();
114
+ s.once("error", () => {
115
+ if (s.destroy(), a === n) {
116
+ i(/* @__PURE__ */ Error(`Timed out waiting for port ${e} to be available`));
117
+ return;
118
+ }
119
+ setTimeout(o, 500);
120
+ }), s.connect(e, t, () => {
121
+ s.destroy(), r();
122
+ });
123
+ };
124
+ o();
125
+ });
126
+ }
127
+ function h(e) {
128
+ if (!(e instanceof Error)) return String(e);
129
+ let { cause: t } = e;
130
+ return t instanceof Error ? t.code || t.message || e.message : t === void 0 ? e.message : String(t);
131
+ }
132
+ function g(e, t = 60) {
133
+ return new Promise((n, r) => {
134
+ let i = 0, a = "no attempt made", o = async () => {
135
+ i++;
136
+ try {
137
+ let t = await fetch(`${e}/api/health`);
138
+ if (t.status === 200) {
139
+ n();
140
+ return;
141
+ }
142
+ a = `HTTP ${t.status}`;
143
+ } catch (e) {
144
+ a = h(e);
145
+ }
146
+ if (i === t) {
147
+ r(/* @__PURE__ */ Error(`Timed out waiting for health check at ${e}/api/health (last attempt: ${a})`));
148
+ return;
149
+ }
150
+ setTimeout(o, 500);
151
+ };
152
+ o();
153
+ });
154
+ }
155
+ //#endregion
156
+ //#region src/runtime/pocketbase.ts
157
+ var _ = 1100;
158
+ function v() {
159
+ return new Promise((e) => setTimeout(e, _));
160
+ }
161
+ function y(t, r, i) {
162
+ let o = `${r}_${t}.js`, s = a(n.join(i.root, e)).filter((e) => e.endsWith(o)).sort().pop();
163
+ if (s) return n.join(i.root, e, s);
164
+ }
165
+ function b(e) {
166
+ let t = n.join(e, "node_modules", ".vite", "_pocketbase_metadata.json");
167
+ return r(t) ? JSON.parse(i(t, "utf8")) : null;
168
+ }
169
+ async function x(e, t, n) {
170
+ let r = !1;
171
+ for (let i = 1; i <= 3; i++) try {
172
+ await e.collection("_superusers").authWithPassword(t, n), r = !0;
173
+ break;
174
+ } catch {
175
+ i < 3 && await new Promise((e) => setTimeout(e, 100));
176
+ }
177
+ if (!r) throw Error("Failed to authenticate with PocketBase. Check your superuser credentials.");
178
+ }
179
+ async function S(i, a) {
180
+ let u = n.join(i, t), d = n.join(i, e), f = "localhost";
181
+ if (!r(u)) throw Error("PocketBase data directory does not exist");
182
+ let h = b(i);
183
+ if (h && h.pocketbaseUrl) {
184
+ let e = new o(h.pocketbaseUrl);
185
+ await x(e, process.env.POCKETBASE_SUPERUSER_EMAIL, process.env.POCKETBASE_SUPERUSER_PASSWORD), await a(e);
186
+ return;
187
+ }
188
+ let _ = await p(f), v = [
189
+ "pocketbase-server",
190
+ "serve",
191
+ "--dir",
192
+ u,
193
+ "--migrationsDir",
194
+ d,
195
+ "--http",
196
+ `${f}:${_}`
197
+ ], y = (await s({ cwd: i }))?.name ?? "npm", { command: S, args: w } = c(y, "execute", v);
198
+ y === "npm" && w.unshift("--yes");
199
+ let T = process.platform !== "win32", E = l(S, w, {
200
+ cwd: i,
201
+ stdio: "ignore",
202
+ detached: T
203
+ }), D = new Promise((e, t) => {
204
+ E.once("exit", (e, n) => {
205
+ t(/* @__PURE__ */ Error(`pocketbase-server exited before listening on ${f}:${_} (${n ?? `code ${e}`})`));
206
+ }), E.once("error", t);
207
+ });
208
+ try {
209
+ await Promise.race([(async () => {
210
+ await m(_, f), await g(`http://${f}:${_}`);
211
+ })(), D]);
212
+ let e = new o(`http://${f}:${_}`);
213
+ await x(e, process.env.POCKETBASE_SUPERUSER_EMAIL, process.env.POCKETBASE_SUPERUSER_PASSWORD), await a(e);
214
+ } finally {
215
+ C(E, T);
216
+ }
217
+ }
218
+ function C(e, t) {
219
+ if (t && e.pid) try {
220
+ process.kill(-e.pid, "SIGTERM");
221
+ return;
222
+ } catch {}
223
+ e.kill();
224
+ }
225
+ //#endregion
226
+ export { y as getMigrationFile, v as migrationDelay, S as withPocketbase };
227
+
228
+ //# sourceMappingURL=pocketbase-059B1oot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pocketbase-059B1oot.js","names":[],"sources":["../../src/runtime/net.ts","../../src/runtime/pocketbase.ts"],"sourcesContent":["import net from \"node:net\";\n\n/**\n * Ports the Fetch spec tells clients to refuse outright\n * (https://fetch.spec.whatwg.org/#port-blocking). Node's `fetch` enforces the\n * list, so a server bound to one of them is unreachable from `waitForHealth`\n * and the PocketBase SDK alike: the request fails with cause \"bad port\"\n * before a connection is even attempted. 10080 sat inside the 10000–19999\n * range ports used to be drawn from, and cost a CI run a 30-second health\n * timeout whenever the draw landed on it.\n */\nexport const BAD_PORTS: ReadonlySet<number> = new Set([\n 1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 69, 77, 79,\n 87, 95, 101, 102, 103, 104, 109, 110, 111, 113, 115, 117, 119, 123, 135, 137,\n 139, 143, 161, 179, 389, 427, 465, 512, 513, 514, 515, 526, 530, 531, 532,\n 540, 548, 554, 556, 563, 587, 601, 636, 989, 990, 993, 995, 1719, 1720, 1723,\n 2049, 3659, 4045, 4190, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668, 6669,\n 6679, 6697, 10080,\n]);\n\nfunction osAssignedPort(host: string): Promise<number> {\n return new Promise((resolve, reject) => {\n const server = net.createServer();\n server.unref();\n server.once(\"error\", reject);\n server.listen(0, host, () => {\n const { port } = server.address() as net.AddressInfo;\n server.close(() => resolve(port));\n });\n });\n}\n\n/**\n * A port nothing is listening on right now, taken from the OS's ephemeral\n * range so it neither collides with whatever else the machine runs nor hits\n * `BAD_PORTS`. The port is released again before this resolves, so the\n * caller's server has to bind it promptly.\n */\nexport async function freePort(host: string): Promise<number> {\n for (;;) {\n const port = await osAssignedPort(host);\n if (!BAD_PORTS.has(port)) return port;\n }\n}\n\n// Wait for the port to be available. A cold `npx pocketbase-server` on a CI\n// runner can take well over the five seconds the old default allowed.\nexport function waitForPort(\n port: number,\n host: string,\n maxAttempts = 60,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n\n const tryConnect = () => {\n attempts++;\n\n const socket = new net.Socket();\n\n const onError = () => {\n socket.destroy();\n\n if (attempts === maxAttempts) {\n reject(\n new Error(`Timed out waiting for port ${port} to be available`),\n );\n return;\n }\n\n setTimeout(tryConnect, 500);\n };\n\n socket.once(\"error\", onError);\n\n socket.connect(port, host, () => {\n socket.destroy();\n resolve();\n });\n };\n\n tryConnect();\n });\n}\n\n/**\n * `fetch` wraps the interesting part in `cause`: an errno error for a\n * connection that was refused, or a bare string such as \"bad port\" for a\n * request undici declined to make.\n */\nfunction describeFetchError(error: unknown): string {\n if (!(error instanceof Error)) return String(error);\n const { cause } = error as Error & { cause?: unknown };\n if (cause instanceof Error) {\n const code = (cause as NodeJS.ErrnoException).code;\n return code || cause.message || error.message;\n }\n if (cause !== undefined) return String(cause);\n return error.message;\n}\n\n// Wait for the health check to be successful\nexport function waitForHealth(url: string, maxAttempts = 60): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n let lastFailure = \"no attempt made\";\n\n const tryHealth = async () => {\n attempts++;\n\n try {\n const response = await fetch(`${url}/api/health`);\n if (response.status === 200) {\n resolve();\n return;\n }\n lastFailure = `HTTP ${response.status}`;\n } catch (error) {\n lastFailure = describeFetchError(error);\n }\n\n if (attempts === maxAttempts) {\n reject(\n new Error(\n `Timed out waiting for health check at ${url}/api/health (last attempt: ${lastFailure})`,\n ),\n );\n return;\n }\n\n setTimeout(tryHealth, 500);\n };\n\n tryHealth();\n });\n}\n","import { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport PocketBase from \"pocketbase\";\nimport { detect } from \"package-manager-detector\";\nimport { resolveCommand } from \"package-manager-detector/commands\";\nimport spawn from \"cross-spawn\";\nimport { freePort, waitForPort, waitForHealth } from \"./net\";\nimport type { Options } from \"../core/types\";\nimport { DATA_DIR, MIGRATIONS_DIR } from \"../core/constants\";\n\n/**\n * PocketBase names migration files with a 1-second-resolution Unix timestamp\n * (e.g. `1776099881_created_users.js`). Two schema operations issued in the\n * same wall-clock second produce files that sort alphabetically by their\n * action/collection suffix — which reverses the intended order whenever a\n * later migration depends on an earlier one. Wait out the full second between\n * migration-producing calls so the timestamps stay distinct.\n */\nconst MIGRATION_DELAY_MS = 1100;\n\nexport function migrationDelay(): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, MIGRATION_DELAY_MS));\n}\n\nexport function getMigrationFile(\n collectionName: string,\n action: \"created\" | \"deleted\" | \"updated\",\n options: Options,\n): string | undefined {\n const ending = `${action}_${collectionName}.js`;\n\n // find last file with ending in migrations dir\n const migrationFiles = readdirSync(\n path.join(options.root, MIGRATIONS_DIR),\n ).filter((file) => file.endsWith(ending));\n\n const migrationFile = migrationFiles.sort().pop();\n\n if (!migrationFile) {\n return undefined;\n }\n\n return path.join(options.root, MIGRATIONS_DIR, migrationFile);\n}\n\nexport function getPocketbaseMetadata(cwd: string): {\n pocketbaseUrl: string;\n vitePort: number;\n} | null {\n const metadataPath = path.join(\n cwd,\n \"node_modules\",\n \".vite\",\n \"_pocketbase_metadata.json\",\n );\n if (existsSync(metadataPath)) {\n return JSON.parse(readFileSync(metadataPath, \"utf8\"));\n }\n return null;\n}\n\nexport async function authWithRetries(\n pb: PocketBase,\n email: string,\n password: string,\n) {\n // Retry authentication up to 3 times with 100ms backoff\n let authSuccess = false;\n for (let attempt = 1; attempt <= 3; attempt++) {\n try {\n await pb.collection(\"_superusers\").authWithPassword(email, password);\n authSuccess = true;\n break;\n } catch {\n if (attempt < 3) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n }\n\n if (!authSuccess) {\n throw new Error(\n \"Failed to authenticate with PocketBase. Check your superuser credentials.\",\n );\n }\n}\n\nexport async function withPocketbase(\n cwd: string,\n fn: (pb: PocketBase) => Promise<void>,\n) {\n const dir = path.join(cwd, DATA_DIR);\n const migrationsDir = path.join(cwd, MIGRATIONS_DIR);\n const host = \"localhost\";\n\n if (!existsSync(dir)) {\n throw new Error(\"PocketBase data directory does not exist\");\n }\n\n // First check if the server is already running by reading node_modules/.vite/_pocketbase_metadata.json\n const metadata = getPocketbaseMetadata(cwd);\n if (metadata) {\n if (metadata.pocketbaseUrl) {\n const pb = new PocketBase(metadata.pocketbaseUrl);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n return;\n }\n }\n\n const port = await freePort(host);\n const commandArgs = [\n \"pocketbase-server\",\n \"serve\",\n \"--dir\",\n dir,\n \"--migrationsDir\",\n migrationsDir,\n \"--http\",\n `${host}:${port}`,\n ];\n\n const packageManager = (await detect({ cwd }))?.name ?? \"npm\";\n const { command, args } = resolveCommand(\n packageManager,\n \"execute\",\n commandArgs,\n )!;\n\n // adding --yes as the first parameter helps avoiding the \"Need to install the following packages:\" message\n if (packageManager === \"npm\") args.unshift(\"--yes\");\n\n // Start the PocketBase server process. The package manager wrapper (`npx`)\n // spawns the real binary as a grandchild; put the tree in its own process\n // group so it can be killed as a whole, otherwise `pocketbase serve` outlives\n // us and keeps the data directory open.\n const detached = process.platform !== \"win32\";\n const serverProcess = spawn(command, args, {\n cwd,\n stdio: \"ignore\",\n detached,\n });\n\n // A wrapper that dies before the server listens (missing binary, bad\n // arguments) would otherwise only surface as a port timeout a minute later.\n const exited = new Promise<never>((_, reject) => {\n serverProcess.once(\"exit\", (code, signal) => {\n reject(\n new Error(\n `pocketbase-server exited before listening on ${host}:${port} (${signal ?? `code ${code}`})`,\n ),\n );\n });\n serverProcess.once(\"error\", reject);\n });\n\n try {\n // Wait for the server to be ready\n await Promise.race([\n (async () => {\n await waitForPort(port, host);\n await waitForHealth(`http://${host}:${port}`);\n })(),\n exited,\n ]);\n\n const pb = new PocketBase(`http://${host}:${port}`);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n } finally {\n // Ensure we always clean up the process tree\n stopProcessTree(serverProcess, detached);\n }\n}\n\nfunction stopProcessTree(\n child: ReturnType<typeof spawn>,\n detached: boolean,\n): void {\n if (detached && child.pid) {\n try {\n process.kill(-child.pid, \"SIGTERM\");\n return;\n } catch {\n // Group already gone or unsupported; fall through to the plain kill.\n }\n }\n child.kill();\n}\n"],"mappings":";;;;;;;;;AAWA,IAAa,oBAAiC,IAAI,IAAI;CACpD;CAAG;CAAG;CAAG;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CACzE;CAAI;CAAI;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CACzE;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CACtE;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAM;CAAM;CACxE;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CACxE;CAAM;CAAM;AACd,CAAC;AAED,SAAS,EAAe,GAA+B;CACrD,OAAO,IAAI,SAAS,GAAS,MAAW;EACtC,IAAM,IAAS,EAAI,aAAa;EAGhC,AAFA,EAAO,MAAM,GACb,EAAO,KAAK,SAAS,CAAM,GAC3B,EAAO,OAAO,GAAG,SAAY;GAC3B,IAAM,EAAE,YAAS,EAAO,QAAQ;GAChC,EAAO,YAAY,EAAQ,CAAI,CAAC;EAClC,CAAC;CACH,CAAC;AACH;AAQA,eAAsB,EAAS,GAA+B;CAC5D,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AM,EAAG,CAAE;EACX;CACF;CAGF,IAAM,IAAO,MAAM,EAAS,CAAI,GAC1B,IAAc;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;EACA,GAAG,EAAK,GAAG;CACb,GAEM,KAAkB,MAAM,EAAO,EAAE,OAAI,CAAC,EAAA,EAAI,QAAQ,OAClD,EAAE,YAAS,YAAS,EACxB,GACA,WACA,CACF;CAGA,AAAI,MAAmB,SAAO,EAAK,QAAQ,OAAO;CAMlD,IAAM,IAAW,QAAQ,aAAa,SAChC,IAAgB,EAAM,GAAS,GAAM;EACzC;EACA,OAAO;EACP;CACF,CAAC,GAIK,IAAS,IAAI,SAAgB,GAAG,MAAW;EAQ/C,AAPA,EAAc,KAAK,SAAS,GAAM,MAAW;GAC3C,EACE,gBAAI,MACF,gDAAgD,EAAK,GAAG,EAAK,IAAI,KAAU,QAAQ,IAAO,EAC5F,CACF;EACF,CAAC,GACD,EAAc,KAAK,SAAS,CAAM;CACpC,CAAC;CAED,IAAI;EAEF,MAAM,QAAQ,KAAK,EAChB,YAAY;GAEX,AADA,MAAM,EAAY,GAAM,CAAI,GAC5B,MAAM,EAAc,UAAU,EAAK,GAAG,GAAM;EAC9C,EAAA,CAAG,GACH,CACF,CAAC;EAED,IAAM,IAAK,IAAI,EAAW,UAAU,EAAK,GAAG,GAAM;EAMlD,AALA,MAAM,EACJ,GACA,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BACd,GACA,MAAM,EAAG,CAAE;CACb,UAAU;EAER,EAAgB,GAAe,CAAQ;CACzC;AACF;AAEA,SAAS,EACP,GACA,GACM;CACN,IAAI,KAAY,EAAM,KACpB,IAAI;EACF,QAAQ,KAAK,CAAC,EAAM,KAAK,SAAS;EAClC;CACF,QAAQ,CAER;CAEF,EAAM,KAAK;AACb"}
@@ -15,7 +15,7 @@ async function n(e, t) {
15
15
  exists: !0,
16
16
  rowCount: 0
17
17
  }));
18
- let { withPocketbase: n } = await import("./pocketbase-fERkp8b8.js"), { planCollectionDrops: r } = await import("./collections-DcnlHh80.js"), i = [];
18
+ let { withPocketbase: n } = await import("./pocketbase-059B1oot.js"), { planCollectionDrops: r } = await import("./collections-1Z0NCLM-.js"), i = [];
19
19
  return await n(t.root, async (t) => {
20
20
  let n = await r(t, e);
21
21
  i.push(...n);
@@ -24,4 +24,4 @@ async function n(e, t) {
24
24
  //#endregion
25
25
  export { t as n, n as t };
26
26
 
27
- //# sourceMappingURL=shared-ClWQZdMa.js.map
27
+ //# sourceMappingURL=shared-CaHmNkZE.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared-ClWQZdMa.js","names":[],"sources":["../../src/patterns/destroy/shared.ts"],"sourcesContent":["import type { CollectionDropSpec, File, Options } from \"../../core/types\";\nimport { languageFromPath } from \"../../core/util\";\n\nexport function toDeleteEntry(path: string): File {\n return {\n path,\n language: languageFromPath(path),\n content: \"\",\n status: \"success\",\n };\n}\n\n/**\n * Build `CollectionDropSpec` entries for each collection name, with live row\n * counts from PocketBase when `env === \"runtime\"`. In preview mode, returns\n * `{ exists: true, rowCount: 0 }` placeholders.\n */\nexport async function planDropsForCollections(\n collectionNames: string[],\n options: Options,\n): Promise<CollectionDropSpec[]> {\n if (collectionNames.length === 0) return [];\n\n if (options.env !== \"runtime\") {\n return collectionNames.map((name) => ({\n name,\n exists: true,\n rowCount: 0,\n }));\n }\n\n const { withPocketbase } = await import(\"../../runtime/pocketbase\");\n const { planCollectionDrops } = await import(\"../../runtime/collections\");\n const drops: CollectionDropSpec[] = [];\n await withPocketbase(options.root, async (pb) => {\n const plans = await planCollectionDrops(pb, collectionNames);\n drops.push(...plans);\n });\n return drops;\n}\n"],"mappings":";;AAGA,SAAgB,EAAc,GAAoB;CAChD,OAAO;EACL;EACA,UAAU,EAAiB,CAAI;EAC/B,SAAS;EACT,QAAQ;CACV;AACF;AAOA,eAAsB,EACpB,GACA,GAC+B;CAC/B,IAAI,EAAgB,WAAW,GAAG,OAAO,CAAC;CAE1C,IAAI,EAAQ,QAAQ,WAClB,OAAO,EAAgB,KAAK,OAAU;EACpC;EACA,QAAQ;EACR,UAAU;CACZ,EAAE;CAGJ,IAAM,EAAE,sBAAmB,MAAM,OAAO,6BAClC,EAAE,2BAAwB,MAAM,OAAO,8BACvC,IAA8B,CAAC;CAKrC,OAJA,MAAM,EAAe,EAAQ,MAAM,OAAO,MAAO;EAC/C,IAAM,IAAQ,MAAM,EAAoB,GAAI,CAAe;EAC3D,EAAM,KAAK,GAAG,CAAK;CACrB,CAAC,GACM;AACT"}
1
+ {"version":3,"file":"shared-CaHmNkZE.js","names":[],"sources":["../../src/patterns/destroy/shared.ts"],"sourcesContent":["import type { CollectionDropSpec, File, Options } from \"../../core/types\";\nimport { languageFromPath } from \"../../core/util\";\n\nexport function toDeleteEntry(path: string): File {\n return {\n path,\n language: languageFromPath(path),\n content: \"\",\n status: \"success\",\n };\n}\n\n/**\n * Build `CollectionDropSpec` entries for each collection name, with live row\n * counts from PocketBase when `env === \"runtime\"`. In preview mode, returns\n * `{ exists: true, rowCount: 0 }` placeholders.\n */\nexport async function planDropsForCollections(\n collectionNames: string[],\n options: Options,\n): Promise<CollectionDropSpec[]> {\n if (collectionNames.length === 0) return [];\n\n if (options.env !== \"runtime\") {\n return collectionNames.map((name) => ({\n name,\n exists: true,\n rowCount: 0,\n }));\n }\n\n const { withPocketbase } = await import(\"../../runtime/pocketbase\");\n const { planCollectionDrops } = await import(\"../../runtime/collections\");\n const drops: CollectionDropSpec[] = [];\n await withPocketbase(options.root, async (pb) => {\n const plans = await planCollectionDrops(pb, collectionNames);\n drops.push(...plans);\n });\n return drops;\n}\n"],"mappings":";;AAGA,SAAgB,EAAc,GAAoB;CAChD,OAAO;EACL;EACA,UAAU,EAAiB,CAAI;EAC/B,SAAS;EACT,QAAQ;CACV;AACF;AAOA,eAAsB,EACpB,GACA,GAC+B;CAC/B,IAAI,EAAgB,WAAW,GAAG,OAAO,CAAC;CAE1C,IAAI,EAAQ,QAAQ,WAClB,OAAO,EAAgB,KAAK,OAAU;EACpC;EACA,QAAQ;EACR,UAAU;CACZ,EAAE;CAGJ,IAAM,EAAE,sBAAmB,MAAM,OAAO,6BAClC,EAAE,2BAAwB,MAAM,OAAO,8BACvC,IAA8B,CAAC;CAKrC,OAJA,MAAM,EAAe,EAAQ,MAAM,OAAO,MAAO;EAC/C,IAAM,IAAQ,MAAM,EAAoB,GAAI,CAAe;EAC3D,EAAM,KAAK,GAAG,CAAK;CACrB,CAAC,GACM;AACT"}
@@ -0,0 +1,173 @@
1
+ import { n as e, t } from "./errors-D6gyegUK.js";
2
+ import { n } from "./logger-CQONztPm.js";
3
+ import { executeCommand as r, formatPaths as i, getAllCustomComponents as a, installComponents as o, installedComponents as s, installedPackagesFromProject as c, isCustomComponent as l, n as u, t as d } from "./write-result-BHCOxcsA.js";
4
+ import f from "node:path";
5
+ import { existsSync as p, readFileSync as m, writeFileSync as h } from "node:fs";
6
+ import { createRequire as g } from "node:module";
7
+ import { pathToFileURL as _ } from "node:url";
8
+ //#region src/runtime/shadcn-preset.ts
9
+ async function v(e) {
10
+ let t;
11
+ try {
12
+ t = g(f.join(e, "package.json")).resolve("shadcn-svelte/preset");
13
+ } catch (t) {
14
+ let n = t instanceof Error ? t.message : String(t);
15
+ throw Error(`Could not load shadcn-svelte/preset from ${e}: ${n}\nInstall the project's dependencies (shadcn-svelte >= 1.6) and try again.`);
16
+ }
17
+ return await import(
18
+ /* @vite-ignore */
19
+ _(t).href
20
+ );
21
+ }
22
+ var y = {
23
+ nova: { font: "geist" },
24
+ vega: { font: "inter" },
25
+ maia: { font: "figtree" },
26
+ lyra: { font: "jetbrains-mono" },
27
+ mira: { font: "inter" },
28
+ luma: { font: "inter" },
29
+ sera: {
30
+ font: "noto-sans",
31
+ fontHeading: "playfair-display"
32
+ },
33
+ rhea: { font: "inter" }
34
+ };
35
+ async function b(e, t, n) {
36
+ let { encodePreset: r } = n ?? await v(e), i = u(e), a = { style: i.style };
37
+ return i.baseColor && (a.baseColor = i.baseColor), i.iconLibrary && (a.iconLibrary = i.iconLibrary), i.menuColor && (a.menuColor = i.menuColor), i.menuAccent && (a.menuAccent = i.menuAccent), r({
38
+ ...a,
39
+ ...t
40
+ });
41
+ }
42
+ async function x(e, t, n, a) {
43
+ await r(e, "execute", [
44
+ "shadcn-svelte",
45
+ "apply",
46
+ "--preset",
47
+ t,
48
+ "--only",
49
+ ...n,
50
+ "--yes"
51
+ ], a), await i(e, [u(e).cssPath]);
52
+ }
53
+ //#endregion
54
+ //#region src/runtime/ui.ts
55
+ var S = "components.json";
56
+ async function C(t, n) {
57
+ let { root: r } = t, { style: i } = u(r), o = {
58
+ style: i,
59
+ installed: s(r),
60
+ custom: a(),
61
+ registry: []
62
+ };
63
+ try {
64
+ o.registry = await d(r, { runtime: n });
65
+ } catch (t) {
66
+ if (!(t instanceof e)) throw t;
67
+ o.registryUnavailable = t.message;
68
+ }
69
+ return o;
70
+ }
71
+ function w(e, n, r) {
72
+ if (!r.includes(n)) throw new t(`Unknown ${e} "${n}". Choose one of: ${r.join(", ")}.`);
73
+ }
74
+ function T(e, t) {
75
+ let n = f.join(e, S);
76
+ if (!p(n)) throw Error(`${S} not found in ${e}; this does not look like a shadcn-svelte project.`);
77
+ let r = m(n, "utf8"), i = JSON.parse(r);
78
+ i.style = t;
79
+ let a = r.includes("\n ") ? " " : 2;
80
+ h(n, `${JSON.stringify(i, null, a)}\n`, "utf8");
81
+ }
82
+ function E(e) {
83
+ return new Set(e.filter((e) => e.type === "registry:ui").map((e) => e.name));
84
+ }
85
+ async function D(e, t) {
86
+ let { root: r, style: i, font: a = !0 } = e, f = n(e), p = await v(r);
87
+ w("style", i, p.PRESET_STYLES);
88
+ let m = {
89
+ status: "unchanged",
90
+ style: i,
91
+ reinstalled: [],
92
+ filesModified: [],
93
+ packages: [],
94
+ hints: []
95
+ };
96
+ if (u(r).style === i) return m;
97
+ let h = E(await d(r, {
98
+ style: i,
99
+ runtime: t
100
+ })), g = s(r).filter((e) => h.has(e) && !l(e));
101
+ if (e.confirm && !await e.confirm(g)) return {
102
+ ...m,
103
+ status: "cancelled"
104
+ };
105
+ let _ = c(r);
106
+ T(r, i);
107
+ let y = [S], b = [];
108
+ g.length > 0 && (b = (await o({
109
+ root: r,
110
+ components: g,
111
+ overwrite: !0,
112
+ logger: f
113
+ }, t)).installed);
114
+ let x = [];
115
+ a && await A(r, i, p, t, y, x, f);
116
+ let C = [...c(r)].filter((e) => !_.has(e)).sort();
117
+ return {
118
+ status: "switched",
119
+ style: i,
120
+ reinstalled: b,
121
+ filesModified: y,
122
+ packages: C,
123
+ hints: x
124
+ };
125
+ }
126
+ var O = /@import\s+["']@fontsource(?:-variable)?\/([^"']+)["']/g;
127
+ function k(e) {
128
+ return [...e.matchAll(O)].map((e) => e[1]);
129
+ }
130
+ async function A(e, t, n, r, i, a, o) {
131
+ let s = y[t];
132
+ if (!s) {
133
+ o.info(`No preset font is known for the ${t} style; leaving fonts unchanged.`);
134
+ return;
135
+ }
136
+ o.info(`Applying the ${t} font (${s.font})`), await x(e, await b(e, {
137
+ style: t,
138
+ ...s
139
+ }, n), ["font"], r);
140
+ let c = u(e).cssPath;
141
+ i.push(c, "package.json");
142
+ let l = f.join(e, c);
143
+ if (p(l)) {
144
+ let e = new Set([s.font, s.fontHeading].filter(Boolean)), t = k(m(l, "utf8")).filter((t) => !e.has(t));
145
+ t.length > 0 && a.push(`${c} still imports ${t.map((e) => `@fontsource-variable/${e}`).join(", ")} from the previous style; remove the import and the package if nothing else uses them.`);
146
+ }
147
+ }
148
+ async function j(e, t, n) {
149
+ let r = await v(e);
150
+ t.baseColor && w("base color", t.baseColor, r.PRESET_BASE_COLOR_KEYS), w("theme", t.theme, r.PRESET_THEME_KEYS), await x(e, await b(e, {
151
+ ...t,
152
+ chartColor: t.theme
153
+ }, r), ["theme"], n);
154
+ let i = u(e);
155
+ return {
156
+ baseColor: i.baseColor ?? t.baseColor ?? "",
157
+ theme: t.theme,
158
+ filesModified: [i.cssPath, S]
159
+ };
160
+ }
161
+ async function M(e, t) {
162
+ return j(e.root, {
163
+ baseColor: e.color,
164
+ theme: e.color
165
+ }, t);
166
+ }
167
+ async function N(e, t) {
168
+ return j(e.root, { theme: e.theme }, t);
169
+ }
170
+ //#endregion
171
+ export { M as applyBaseColor, N as applyTheme, C as listComponents, D as switchStyle };
172
+
173
+ //# sourceMappingURL=ui-DAtVMiVs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui-DAtVMiVs.js","names":[],"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,eAAsB,EAAW,GAAqC;CACpE,IAAI;CACJ,IAAI;EACF,IAAW,EAAc,EAAK,KAAK,GAAM,cAAc,CAAC,CAAC,CAAC,QACxD,sBACF;CACF,SAAS,GAAO;EACd,IAAM,IAAS,aAAiB,QAAQ,EAAM,UAAU,OAAO,CAAK;EACpE,MAAU,MACR,4CAA4C,EAAK,IAAI,EAAO,2EAE9D;CACF;CAIA,OAAO,MAHuB;;EACT,EAAc,CAAQ,CAAC,CAAC;;AAG/C;AAQA,IAAa,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;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