@velastack/patterns 0.0.19 → 0.0.20

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 (37) hide show
  1. package/README.md +12 -0
  2. package/dist/chunks/collections-C7dgGs-E.js +67 -0
  3. package/dist/chunks/collections-C7dgGs-E.js.map +1 -0
  4. package/dist/chunks/{env.runtime-C3E02sUH.js → env.runtime-DwDRkEXV.js} +2 -2
  5. package/dist/chunks/{env.runtime-C3E02sUH.js.map → env.runtime-DwDRkEXV.js.map} +1 -1
  6. package/dist/chunks/generate.runtime-C7g-zL0o.js.map +1 -1
  7. package/dist/chunks/generate.runtime-D21wXYWT.js +172 -0
  8. package/dist/chunks/generate.runtime-D21wXYWT.js.map +1 -0
  9. package/dist/chunks/generate.runtime-DcDyK2xK.js +334 -0
  10. package/dist/chunks/generate.runtime-DcDyK2xK.js.map +1 -0
  11. package/dist/chunks/{generate.runtime-DgtB6hP4.js → generate.runtime-cNqC7P0N.js} +33 -10
  12. package/dist/chunks/generate.runtime-cNqC7P0N.js.map +1 -0
  13. package/dist/chunks/generate.runtime-toUqgDQY.js +610 -0
  14. package/dist/chunks/generate.runtime-toUqgDQY.js.map +1 -0
  15. package/dist/chunks/{index-E6LAzq1d.js → index-GTS4D08Z.js} +2533 -2246
  16. package/dist/chunks/index-GTS4D08Z.js.map +1 -0
  17. package/dist/chunks/{pocketbase-BCvqw1Cr.js → pocketbase-QZ34CciJ.js} +50 -45
  18. package/dist/chunks/pocketbase-QZ34CciJ.js.map +1 -0
  19. package/dist/chunks/ts-morph-helpers-BNCluWTs.js +166 -0
  20. package/dist/chunks/ts-morph-helpers-BNCluWTs.js.map +1 -0
  21. package/dist/chunks/{write-result-CbUTMeAc.js → write-result-DmD7kWlV.js} +81 -70
  22. package/dist/chunks/write-result-DmD7kWlV.js.map +1 -0
  23. package/dist/index.d.ts +67 -0
  24. package/dist/index.js +1 -1
  25. package/package.json +16 -1
  26. package/dist/chunks/collections-CAafgIoZ.js +0 -62
  27. package/dist/chunks/collections-CAafgIoZ.js.map +0 -1
  28. package/dist/chunks/generate.runtime-C7YhHvlr.js +0 -353
  29. package/dist/chunks/generate.runtime-C7YhHvlr.js.map +0 -1
  30. package/dist/chunks/generate.runtime-DBTOrhnc.js +0 -633
  31. package/dist/chunks/generate.runtime-DBTOrhnc.js.map +0 -1
  32. package/dist/chunks/generate.runtime-DgtB6hP4.js.map +0 -1
  33. package/dist/chunks/generate.runtime-DoQkjIdl.js +0 -227
  34. package/dist/chunks/generate.runtime-DoQkjIdl.js.map +0 -1
  35. package/dist/chunks/index-E6LAzq1d.js.map +0 -1
  36. package/dist/chunks/pocketbase-BCvqw1Cr.js.map +0 -1
  37. package/dist/chunks/write-result-CbUTMeAc.js.map +0 -1
@@ -1,21 +1,21 @@
1
- import { existsSync as w, readFileSync as S, readdirSync as g } from "node:fs";
1
+ import { existsSync as d, readFileSync as S, readdirSync as g } from "node:fs";
2
2
  import m from "node:path";
3
- import l from "pocketbase";
3
+ import h from "pocketbase";
4
4
  import { detect as y } from "package-manager-detector";
5
- import { resolveCommand as k } from "package-manager-detector/commands";
6
- import _ from "cross-spawn";
5
+ import { resolveCommand as _ } from "package-manager-detector/commands";
6
+ import k from "cross-spawn";
7
7
  import R from "node:net";
8
- import { D as A, M as u } from "./index-E6LAzq1d.js";
9
- function b() {
8
+ import { D as A, M as p } from "./index-GTS4D08Z.js";
9
+ function T() {
10
10
  return Math.floor(Math.random() * 1e4) + 1e4;
11
11
  }
12
- function v(t, r, a = 10) {
13
- return new Promise((n, e) => {
12
+ function b(t, r, n = 10) {
13
+ return new Promise((a, e) => {
14
14
  let o = 0;
15
15
  const i = () => {
16
16
  o++;
17
- const s = new R.Socket(), p = () => {
18
- if (s.destroy(), o === a) {
17
+ const s = new R.Socket(), u = () => {
18
+ if (s.destroy(), o === n) {
19
19
  e(
20
20
  new Error(`Timed out waiting for port ${t} to be available`)
21
21
  );
@@ -23,27 +23,27 @@ function v(t, r, a = 10) {
23
23
  }
24
24
  setTimeout(i, 500);
25
25
  };
26
- s.once("error", p), s.connect(t, r, () => {
27
- s.destroy(), n();
26
+ s.once("error", u), s.connect(t, r, () => {
27
+ s.destroy(), a();
28
28
  });
29
29
  };
30
30
  i();
31
31
  });
32
32
  }
33
- function T(t, r = 10) {
34
- return new Promise((a, n) => {
33
+ function v(t, r = 10) {
34
+ return new Promise((n, a) => {
35
35
  let e = 0;
36
36
  const o = async () => {
37
37
  e++;
38
38
  try {
39
39
  if ((await fetch(`${t}/api/health`)).status === 200) {
40
- a();
40
+ n();
41
41
  return;
42
42
  }
43
43
  } catch {
44
44
  }
45
45
  if (e === r) {
46
- n(
46
+ a(
47
47
  new Error(`Timed out waiting for health check at ${t}/api/health`)
48
48
  );
49
49
  return;
@@ -53,12 +53,16 @@ function T(t, r = 10) {
53
53
  o();
54
54
  });
55
55
  }
56
- function I(t, r, a) {
57
- const n = `${r}_${t}.js`, o = g(
58
- m.join(a.root, u)
59
- ).filter((i) => i.endsWith(n)).sort().pop();
56
+ const M = 1100;
57
+ function W() {
58
+ return new Promise((t) => setTimeout(t, M));
59
+ }
60
+ function x(t, r, n) {
61
+ const a = `${r}_${t}.js`, o = g(
62
+ m.join(n.root, p)
63
+ ).filter((i) => i.endsWith(a)).sort().pop();
60
64
  if (o)
61
- return m.join(a.root, u, o);
65
+ return m.join(n.root, p, o);
62
66
  }
63
67
  function $(t) {
64
68
  const r = m.join(
@@ -67,59 +71,59 @@ function $(t) {
67
71
  ".vite",
68
72
  "_pocketbase_metadata.json"
69
73
  );
70
- return w(r) ? JSON.parse(S(r, "utf8")) : null;
74
+ return d(r) ? JSON.parse(S(r, "utf8")) : null;
71
75
  }
72
- async function d(t, r, a) {
73
- let n = !1;
76
+ async function w(t, r, n) {
77
+ let a = !1;
74
78
  for (let e = 1; e <= 3; e++)
75
79
  try {
76
- await t.collection("_superusers").authWithPassword(r, a), n = !0;
80
+ await t.collection("_superusers").authWithPassword(r, n), a = !0;
77
81
  break;
78
82
  } catch {
79
83
  e < 3 && await new Promise((o) => setTimeout(o, 100));
80
84
  }
81
- if (!n)
85
+ if (!a)
82
86
  throw new Error(
83
87
  "Failed to authenticate with PocketBase. Check your superuser credentials."
84
88
  );
85
89
  }
86
- async function W(t, r) {
87
- var h;
88
- const a = m.join(t, A), n = m.join(t, u), e = "localhost";
89
- if (!w(a))
90
+ async function K(t, r) {
91
+ var l;
92
+ const n = m.join(t, A), a = m.join(t, p), e = "localhost";
93
+ if (!d(n))
90
94
  throw new Error("PocketBase data directory does not exist");
91
95
  const o = $(t);
92
96
  if (o && o.pocketbaseUrl) {
93
- const c = new l(o.pocketbaseUrl);
94
- await d(
97
+ const c = new h(o.pocketbaseUrl);
98
+ await w(
95
99
  c,
96
100
  process.env.POCKETBASE_SUPERUSER_EMAIL,
97
101
  process.env.POCKETBASE_SUPERUSER_PASSWORD
98
102
  ), await r(c);
99
103
  return;
100
104
  }
101
- const i = b(), s = [
105
+ const i = T(), s = [
102
106
  "pocketbase-server",
103
107
  "serve",
104
108
  "--dir",
105
- a,
106
- "--migrationsDir",
107
109
  n,
110
+ "--migrationsDir",
111
+ a,
108
112
  "--http",
109
113
  `${e}:${i}`
110
- ], p = ((h = await y({ cwd: t })) == null ? void 0 : h.name) ?? "npm", { command: E, args: f } = k(
111
- p,
114
+ ], u = ((l = await y({ cwd: t })) == null ? void 0 : l.name) ?? "npm", { command: E, args: f } = _(
115
+ u,
112
116
  "execute",
113
117
  s
114
118
  );
115
- p === "npm" && f.unshift("--yes");
116
- const P = _(E, f, {
119
+ u === "npm" && f.unshift("--yes");
120
+ const P = k(E, f, {
117
121
  stdio: "ignore"
118
122
  });
119
123
  try {
120
- await v(i, e), await T(`http://${e}:${i}`);
121
- const c = new l(`http://${e}:${i}`);
122
- await d(
124
+ await b(i, e), await v(`http://${e}:${i}`);
125
+ const c = new h(`http://${e}:${i}`);
126
+ await w(
123
127
  c,
124
128
  process.env.POCKETBASE_SUPERUSER_EMAIL,
125
129
  process.env.POCKETBASE_SUPERUSER_PASSWORD
@@ -129,7 +133,8 @@ async function W(t, r) {
129
133
  }
130
134
  }
131
135
  export {
132
- I as g,
133
- W as w
136
+ x as g,
137
+ W as m,
138
+ K as w
134
139
  };
135
- //# sourceMappingURL=pocketbase-BCvqw1Cr.js.map
140
+ //# sourceMappingURL=pocketbase-QZ34CciJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pocketbase-QZ34CciJ.js","sources":["../../src/runtime/net.ts","../../src/runtime/pocketbase.ts"],"sourcesContent":["import net from \"node:net\";\n\n// Generate a random port\nexport function randomPort() {\n return Math.floor(Math.random() * 10000) + 10000;\n}\n\n// Wait for the port to be available\nexport function waitForPort(\n port: number,\n host: string,\n maxAttempts = 10,\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// Wait for the health check to be successful\nexport function waitForHealth(url: string, maxAttempts = 10): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\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 } catch {\n // Ignore fetch errors and continue retrying\n }\n\n if (attempts === maxAttempts) {\n reject(\n new Error(`Timed out waiting for health check at ${url}/api/health`),\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 { randomPort, 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 = randomPort();\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\n const serverProcess = spawn(command, args, {\n stdio: \"ignore\",\n });\n\n try {\n // Wait for the server to be ready\n await waitForPort(port, host);\n await waitForHealth(`http://${host}:${port}`);\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\n serverProcess.kill();\n }\n}\n"],"names":["randomPort","waitForPort","port","host","maxAttempts","resolve","reject","attempts","tryConnect","socket","net","onError","waitForHealth","url","tryHealth","MIGRATION_DELAY_MS","migrationDelay","getMigrationFile","collectionName","action","options","ending","migrationFile","readdirSync","path","MIGRATIONS_DIR","file","getPocketbaseMetadata","cwd","metadataPath","existsSync","readFileSync","authWithRetries","pb","email","password","authSuccess","attempt","withPocketbase","fn","dir","DATA_DIR","migrationsDir","metadata","PocketBase","commandArgs","packageManager","_a","detect","command","args","resolveCommand","serverProcess","spawn"],"mappings":";;;;;;;;AAGO,SAASA,IAAa;AAC3B,SAAO,KAAK,MAAM,KAAK,OAAA,IAAW,GAAK,IAAI;AAC7C;AAGO,SAASC,EACdC,GACAC,GACAC,IAAc,IACC;AACf,SAAO,IAAI,QAAQ,CAACC,GAASC,MAAW;AACtC,QAAIC,IAAW;AAEf,UAAMC,IAAa,MAAM;AACvB,MAAAD;AAEA,YAAME,IAAS,IAAIC,EAAI,OAAA,GAEjBC,IAAU,MAAM;AAGpB,YAFAF,EAAO,QAAA,GAEHF,MAAaH,GAAa;AAC5B,UAAAE;AAAA,YACE,IAAI,MAAM,8BAA8BJ,CAAI,kBAAkB;AAAA,UAAA;AAEhE;AAAA,QACF;AAEA,mBAAWM,GAAY,GAAG;AAAA,MAC5B;AAEA,MAAAC,EAAO,KAAK,SAASE,CAAO,GAE5BF,EAAO,QAAQP,GAAMC,GAAM,MAAM;AAC/B,QAAAM,EAAO,QAAA,GACPJ,EAAA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,IAAAG,EAAA;AAAA,EACF,CAAC;AACH;AAGO,SAASI,EAAcC,GAAaT,IAAc,IAAmB;AAC1E,SAAO,IAAI,QAAQ,CAACC,GAASC,MAAW;AACtC,QAAIC,IAAW;AAEf,UAAMO,IAAY,YAAY;AAC5B,MAAAP;AAEA,UAAI;AAEF,aADiB,MAAM,MAAM,GAAGM,CAAG,aAAa,GACnC,WAAW,KAAK;AAC3B,UAAAR,EAAA;AACA;AAAA,QACF;AAAA,MACF,QAAQ;AAAA,MAER;AAEA,UAAIE,MAAaH,GAAa;AAC5B,QAAAE;AAAA,UACE,IAAI,MAAM,yCAAyCO,CAAG,aAAa;AAAA,QAAA;AAErE;AAAA,MACF;AAEA,iBAAWC,GAAW,GAAG;AAAA,I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0C;AAI5D,QAAMG,IAAWhB,EAAsBC,CAAG;AAC1C,MAAIe,KACEA,EAAS,eAAe;AAC1B,UAAMV,IAAK,IAAIW,EAAWD,EAAS,aAAa;AAChD,UAAMX;AAAA,MACJC;AAAA,MACA,QAAQ,IAAI;AAAA,MACZ,QAAQ,IAAI;AAAA,IAAA,GAEd,MAAMM,EAAGN,CAAE;AACX;AAAA,EACF;AAGF,QAAM/B,IAAOF,EAAA,GACP6C,IAAc;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACAL;AAAA,IACA;AAAA,IACAE;AAAA,IACA;AAAA,IACA,GAAGvC,CAAI,IAAID,CAAI;AAAA,EAAA,GAGX4C,MAAkBC,IAAA,MAAMC,EAAO,EAAE,KAAApB,EAAA,CAAK,MAApB,gBAAAmB,EAAwB,SAAQ,OAClD,EAAE,SAAAE,GAAS,MAAAC,EAAA,IAASC;AAAA,IACxBL;AAAA,IACA;AAAA,IACAD;AAAA,EAAA;AAIF,EAAIC,MAAmB,SAAOI,EAAK,QAAQ,OAAO;AAGlD,QAAME,IAAgBC,EAAMJ,GAASC,GAAM;AAAA,IACzC,OAAO;AAAA,EAAA,CACR;AAED,MAAI;AAEF,UAAMjD,EAAYC,GAAMC,CAAI,GAC5B,MAAMS,EAAc,UAAUT,CAAI,IAAID,CAAI,EAAE;AAE5C,UAAM+B,IAAK,IAAIW,EAAW,UAAUzC,CAAI,IAAID,CAAI,EAAE;AAClD,UAAM8B;AAAA,MACJC;AAAA,MACA,QAAQ,IAAI;AAAA,MACZ,QAAQ,IAAI;AAAA,IAAA,GAEd,MAAMM,EAAGN,CAAE;AAAA,EACb,UAAA;AAEE,IAAAmB,EAAc,KAAA;AAAA,EAChB;AACF;"}
@@ -0,0 +1,166 @@
1
+ import y from "node:fs";
2
+ import { parse as w } from "svelte/compiler";
3
+ import A from "magic-string";
4
+ import { Project as x, QuoteKind as E, SyntaxKind as s } from "ts-morph";
5
+ class I {
6
+ constructor(t) {
7
+ this.source = t, this.ast = w(t, { modern: !0 }), this.s = new A(t);
8
+ }
9
+ static fromPath(t) {
10
+ return new I(y.readFileSync(t, "utf8"));
11
+ }
12
+ getScript() {
13
+ return this.scriptInner(this.ast.instance);
14
+ }
15
+ getModuleScript() {
16
+ return this.scriptInner(this.ast.module);
17
+ }
18
+ scriptInner(t) {
19
+ if (!t) return null;
20
+ const e = t.content.start, r = t.content.end;
21
+ return { content: this.source.slice(e, r), start: e, end: r };
22
+ }
23
+ /**
24
+ * Replace the inner contents of <script>. Use for ts-morph round-trips.
25
+ * Returns true when an edit was made.
26
+ */
27
+ modifyScript(t) {
28
+ return this.modifyScriptBlock(this.getScript(), t);
29
+ }
30
+ modifyModuleScript(t) {
31
+ return this.modifyScriptBlock(this.getModuleScript(), t);
32
+ }
33
+ modifyScriptBlock(t, e) {
34
+ if (!t) return !1;
35
+ const r = e(t.content);
36
+ return r === t.content ? !1 : (this.s.overwrite(t.start, t.end, r), !0);
37
+ }
38
+ /** First Component or RegularElement node with the given name. */
39
+ findElement(t) {
40
+ return K(
41
+ this.ast.fragment,
42
+ (e) => (e.type === "Component" || e.type === "RegularElement") && e.name === t
43
+ );
44
+ }
45
+ hasElement(t) {
46
+ return this.findElement(t) !== null;
47
+ }
48
+ hasAttribute(t, e) {
49
+ const r = this.findElement(t);
50
+ return r ? (r.attributes ?? []).some(
51
+ (n) => n.type === "Attribute" && n.name === e
52
+ ) : !1;
53
+ }
54
+ /**
55
+ * Insert content at the end of <ComponentName>'s children, just before the
56
+ * closing tag. No-op if the element is not found.
57
+ */
58
+ insertBeforeClosingTag(t, e) {
59
+ const r = this.findElement(t);
60
+ if (!r) return !1;
61
+ const n = `</${t}>`, i = this.source.lastIndexOf(n, r.end);
62
+ return i === -1 ? !1 : (this.s.appendLeft(i, e), !0);
63
+ }
64
+ /** Replace the element entirely (start tag through close tag). */
65
+ replaceElement(t, e) {
66
+ const r = this.findElement(t);
67
+ return r ? (this.s.overwrite(r.start, r.end, e), !0) : !1;
68
+ }
69
+ /**
70
+ * Append attribute text (e.g. " team={data.team}") just after the last
71
+ * existing attribute on the element's start tag.
72
+ */
73
+ appendToAttributes(t, e) {
74
+ const r = this.findElement(t);
75
+ if (!r) return !1;
76
+ const n = (r.attributes ?? []).at(-1), i = n ? n.end : r.start + `<${t}`.length;
77
+ return this.s.appendLeft(i, e), !0;
78
+ }
79
+ hasChanged() {
80
+ return this.s.hasChanged();
81
+ }
82
+ toString() {
83
+ return this.s.toString();
84
+ }
85
+ writeTo(t) {
86
+ this.hasChanged() && y.writeFileSync(t, this.toString(), "utf8");
87
+ }
88
+ }
89
+ function K(o, t) {
90
+ const e = /* @__PURE__ */ new WeakSet();
91
+ function r(n) {
92
+ if (!n || typeof n != "object" || e.has(n))
93
+ return null;
94
+ if (e.add(n), t(n)) return n;
95
+ for (const i of Object.keys(n)) {
96
+ if (i === "parent") continue;
97
+ const a = n[i];
98
+ if (Array.isArray(a))
99
+ for (const c of a) {
100
+ const u = r(c);
101
+ if (u) return u;
102
+ }
103
+ else if (a && typeof a == "object" && "type" in a) {
104
+ const c = r(a);
105
+ if (c) return c;
106
+ }
107
+ }
108
+ return null;
109
+ }
110
+ return r(o);
111
+ }
112
+ function T(o, t) {
113
+ const r = new x({
114
+ useInMemoryFileSystem: !0,
115
+ skipFileDependencyResolution: !0,
116
+ manipulationSettings: { quoteKind: E.Single }
117
+ }).createSourceFile("script.ts", o, { overwrite: !0 }), n = t(r);
118
+ return { source: r.getFullText(), result: n };
119
+ }
120
+ function j(o, t) {
121
+ for (const e of t) {
122
+ if (o.getImportDeclarations().find((i) => i.getModuleSpecifierValue() === e.moduleSpecifier)) continue;
123
+ const n = {
124
+ moduleSpecifier: e.moduleSpecifier
125
+ };
126
+ e.defaultImport && (n.defaultImport = e.defaultImport), e.namespaceImport && (n.namespaceImport = e.namespaceImport), e.namedImports && (n.namedImports = e.namedImports), o.addImportDeclaration(n);
127
+ }
128
+ }
129
+ function C(o, t, e, r, n) {
130
+ const i = `
131
+ {
132
+ title: '${t}',
133
+ url: '${e}',
134
+ icon: ${r}
135
+ }
136
+ `.trim(), { source: a, result: c } = T(o, (u) => {
137
+ const l = u.getVariableDeclarations().find((d) => d.getName() === "data"), p = l == null ? void 0 : l.getInitializer();
138
+ if (!p || p.getKind() !== s.ObjectLiteralExpression)
139
+ return { wasAdded: !1 };
140
+ const m = p.asKindOrThrow(s.ObjectLiteralExpression).getProperty("navUser");
141
+ if (!m || m.getKind() !== s.PropertyAssignment)
142
+ return { wasAdded: !1 };
143
+ const g = m.asKindOrThrow(s.PropertyAssignment).getInitializer();
144
+ if (!g || g.getKind() !== s.ArrayLiteralExpression)
145
+ return { wasAdded: !1 };
146
+ const S = g.asKindOrThrow(s.ArrayLiteralExpression);
147
+ return S.getElements().some((d) => {
148
+ if (d.getKind() !== s.ObjectLiteralExpression) return !1;
149
+ const h = d.asKindOrThrow(s.ObjectLiteralExpression).getProperty("title");
150
+ if (!h || h.getKind() !== s.PropertyAssignment)
151
+ return !1;
152
+ const f = h.asKindOrThrow(s.PropertyAssignment).getInitializer();
153
+ return (f == null ? void 0 : f.getKind()) === s.StringLiteral && f.getLiteralText() === t;
154
+ }) ? { wasAdded: !1 } : (j(u, [
155
+ { defaultImport: r, moduleSpecifier: n }
156
+ ]), S.addElement(i), u.formatText(), { wasAdded: !0 });
157
+ });
158
+ return { source: a, wasAdded: c.wasAdded };
159
+ }
160
+ export {
161
+ I as S,
162
+ C as a,
163
+ j as e,
164
+ T as w
165
+ };
166
+ //# sourceMappingURL=ts-morph-helpers-BNCluWTs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-morph-helpers-BNCluWTs.js","sources":["../../src/runtime/svelte-file.ts","../../src/runtime/ts-morph-helpers.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 /**\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 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 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","import {\n Project,\n QuoteKind,\n SyntaxKind,\n type ImportDeclarationStructure,\n type OptionalKind,\n type SourceFile,\n type StringLiteral,\n} from \"ts-morph\";\n\nexport interface ImportSpec {\n defaultImport?: string;\n namespaceImport?: string;\n namedImports?: string[];\n moduleSpecifier: string;\n}\n\n/**\n * Run a function with an in-memory ts-morph SourceFile and return the resulting\n * source plus whatever the callback returned.\n */\nexport function withInMemoryScript<T>(\n source: string,\n fn: (sf: SourceFile) => T,\n): { source: string; result: T } {\n const project = new Project({\n useInMemoryFileSystem: true,\n skipFileDependencyResolution: true,\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sf = project.createSourceFile(\"script.ts\", source, { overwrite: true });\n const result = fn(sf);\n return { source: sf.getFullText(), result };\n}\n\n/** Add the given imports to the source file, skipping any whose module specifier already exists. */\nexport function ensureImports(sf: SourceFile, imports: ImportSpec[]): void {\n for (const spec of imports) {\n const existing = sf\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === spec.moduleSpecifier);\n if (existing) continue;\n\n const structure: OptionalKind<ImportDeclarationStructure> = {\n moduleSpecifier: spec.moduleSpecifier,\n };\n if (spec.defaultImport) structure.defaultImport = spec.defaultImport;\n if (spec.namespaceImport) structure.namespaceImport = spec.namespaceImport;\n if (spec.namedImports) structure.namedImports = spec.namedImports;\n sf.addImportDeclaration(structure);\n }\n}\n\n/**\n * Add an item to the `data.navUser` array in a Svelte component's script body.\n * Idempotent: if an entry with the same `title` already exists, no-op.\n */\nexport function addNavItemToScript(\n scriptSource: string,\n title: string,\n url: string,\n icon: string,\n iconImportPath: string,\n): { source: string; wasAdded: boolean } {\n const newNavItemSnippet = `\n {\n title: '${title}',\n url: '${url}',\n icon: ${icon}\n }\n `.trim();\n\n const { source, result } = withInMemoryScript(scriptSource, (sf) => {\n const dataDecl = sf\n .getVariableDeclarations()\n .find((d) => d.getName() === \"data\");\n const dataInit = dataDecl?.getInitializer();\n if (\n !dataInit ||\n dataInit.getKind() !== SyntaxKind.ObjectLiteralExpression\n ) {\n return { wasAdded: false };\n }\n\n const obj = dataInit.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n const navProp = obj.getProperty(\"navUser\");\n if (!navProp || navProp.getKind() !== SyntaxKind.PropertyAssignment) {\n return { wasAdded: false };\n }\n\n const init = navProp\n .asKindOrThrow(SyntaxKind.PropertyAssignment)\n .getInitializer();\n if (!init || init.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n return { wasAdded: false };\n }\n\n const arr = init.asKindOrThrow(SyntaxKind.ArrayLiteralExpression);\n const exists = arr.getElements().some((el) => {\n if (el.getKind() !== SyntaxKind.ObjectLiteralExpression) return false;\n const o = el.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n const titleProp = o.getProperty(\"title\");\n if (!titleProp || titleProp.getKind() !== SyntaxKind.PropertyAssignment) {\n return false;\n }\n const value = titleProp\n .asKindOrThrow(SyntaxKind.PropertyAssignment)\n .getInitializer();\n return (\n value?.getKind() === SyntaxKind.StringLiteral &&\n (value as StringLiteral).getLiteralText() === title\n );\n });\n\n if (exists) return { wasAdded: false };\n\n ensureImports(sf, [\n { defaultImport: icon, moduleSpecifier: iconImportPath },\n ]);\n arr.addElement(newNavItemSnippet);\n sf.formatText();\n return { wasAdded: true };\n });\n\n return { source, wasAdded: result.wasAdded };\n}\n"],"names":["SvelteFile","source","parse","MagicString","filePath","fs","script","start","end","fn","block","next","name","findNode","node","componentName","attrName","attr","content","closingTag","closingPos","newContent","attrs","last","insertAt","root","predicate","seen","visit","key","child","item","found","withInMemoryScript","sf","Project","QuoteKind","result","ensureImports","imports","spec","d","structure","addNavItemToScript","scriptSource","title","url","icon","iconImportPath","newNavItemSnippet","dataDecl","dataInit","SyntaxKind","navProp","init","arr","el","titleProp","value"],"mappings":";;;;AAqBO,MAAMA,EAAW;AAAA,EAKtB,YAAYC,GAAgB;AAC1B,SAAK,SAASA,GACd,KAAK,MAAMC,EAAMD,GAAQ,EAAE,QAAQ,IAAM,GACzC,KAAK,IAAI,IAAIE,EAAYF,CAAM;AAAA,EACjC;AAAA,EAEA,OAAO,SAASG,GAA8B;AAC5C,WAAO,IAAIJ,EAAWK,EAAG,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