@velastack/patterns 0.3.3 → 0.4.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 +44 -2
- package/dist/chunks/_layout-kkgN0IF7.js +62 -0
- package/dist/chunks/_layout-kkgN0IF7.js.map +1 -0
- package/dist/chunks/{collections-CrOvS2E7.js → collections-Dz2fvKnz.js} +2 -2
- package/dist/chunks/{collections-CrOvS2E7.js.map → collections-Dz2fvKnz.js.map} +1 -1
- package/dist/chunks/{compose-handle-B-CkDcQD.js → compose-handle-D_Rz3Fzo.js} +10 -4
- package/dist/chunks/compose-handle-D_Rz3Fzo.js.map +1 -0
- package/dist/chunks/{config-target-Bln26FJe.js → config-target-Dx3w6WSk.js} +59 -70
- package/dist/chunks/config-target-Dx3w6WSk.js.map +1 -0
- package/dist/chunks/constants-BjyMU5s8.js +6 -0
- package/dist/chunks/constants-BjyMU5s8.js.map +1 -0
- package/dist/chunks/dispatch-CXOXPLFk.js +6 -0
- package/dist/chunks/dispatch-CXOXPLFk.js.map +1 -0
- package/dist/chunks/env-vars-C1NUX-bf.js +268 -0
- package/dist/chunks/env-vars-C1NUX-bf.js.map +1 -0
- package/dist/chunks/env-vars-Cr4lbMD_.js +21 -0
- package/dist/chunks/env-vars-Cr4lbMD_.js.map +1 -0
- package/dist/chunks/env-vars-De0Xs0L2.js +20 -0
- package/dist/chunks/env-vars-De0Xs0L2.js.map +1 -0
- package/dist/chunks/env-vars-file-B_6esJW3.js +34 -0
- package/dist/chunks/env-vars-file-B_6esJW3.js.map +1 -0
- package/dist/chunks/env-vars-mnRA0hOe.js +19 -0
- package/dist/chunks/env-vars-mnRA0hOe.js.map +1 -0
- package/dist/chunks/generate-BW3l5Fxw.js +252 -0
- package/dist/chunks/{generate-Ca_6FlPi.js.map → generate-BW3l5Fxw.js.map} +1 -1
- package/dist/chunks/{generate-CyuY2Ci7.js → generate-DeaBlnK6.js} +25 -24
- package/dist/chunks/generate-DeaBlnK6.js.map +1 -0
- package/dist/chunks/generate-DetW_gbr.js +68 -0
- package/dist/chunks/generate-DetW_gbr.js.map +1 -0
- package/dist/chunks/{generate-DwADTUob.js → generate-Gcc8iRkZ.js} +9 -6
- package/dist/chunks/{generate-DwADTUob.js.map → generate-Gcc8iRkZ.js.map} +1 -1
- package/dist/chunks/{generate-DQeWOEPY.js → generate-WMJo3QGZ.js} +9 -6
- package/dist/chunks/generate-WMJo3QGZ.js.map +1 -0
- package/dist/chunks/generate.runtime-1-91UmM8.js +85 -0
- package/dist/chunks/generate.runtime-1-91UmM8.js.map +1 -0
- package/dist/chunks/generate.runtime-6FXJM8hT.js +67 -0
- package/dist/chunks/generate.runtime-6FXJM8hT.js.map +1 -0
- package/dist/chunks/generate.runtime-B1jVAnDI.js +155 -0
- package/dist/chunks/generate.runtime-B1jVAnDI.js.map +1 -0
- package/dist/chunks/generate.runtime-BA3tDKnn.js +147 -0
- package/dist/chunks/generate.runtime-BA3tDKnn.js.map +1 -0
- package/dist/chunks/{generate.runtime-4FDxnvCl.js → generate.runtime-BO778G0r.js} +5 -5
- package/dist/chunks/{generate.runtime-4FDxnvCl.js.map → generate.runtime-BO778G0r.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D1DNAY6k.js → generate.runtime-BXkZob1O.js} +8 -8
- package/dist/chunks/generate.runtime-BXkZob1O.js.map +1 -0
- package/dist/chunks/{generate.runtime-Um77JfwC.js → generate.runtime-B_UVGa3q.js} +7 -7
- package/dist/chunks/{generate.runtime-Um77JfwC.js.map → generate.runtime-B_UVGa3q.js.map} +1 -1
- package/dist/chunks/{generate.runtime-FdZw277n.js → generate.runtime-C6bSvGMb.js} +108 -142
- package/dist/chunks/generate.runtime-C6bSvGMb.js.map +1 -0
- package/dist/chunks/generate.runtime-C8zJRNYG.js +124 -0
- package/dist/chunks/generate.runtime-C8zJRNYG.js.map +1 -0
- package/dist/chunks/{generate.runtime-BKiJvE8I.js → generate.runtime-CA7Ofjlx.js} +104 -100
- package/dist/chunks/generate.runtime-CA7Ofjlx.js.map +1 -0
- package/dist/chunks/generate.runtime-CCr1lvo4.js +43 -0
- package/dist/chunks/generate.runtime-CCr1lvo4.js.map +1 -0
- package/dist/chunks/generate.runtime-CYagyR5c.js +326 -0
- package/dist/chunks/generate.runtime-CYagyR5c.js.map +1 -0
- package/dist/chunks/{generate.runtime-n9AFWtPp.js → generate.runtime-Ce_rwzNa.js} +4 -4
- package/dist/chunks/{generate.runtime-n9AFWtPp.js.map → generate.runtime-Ce_rwzNa.js.map} +1 -1
- package/dist/chunks/{generate.runtime-cQGLxuZM.js → generate.runtime-CexC1Oky.js} +4 -4
- package/dist/chunks/{generate.runtime-cQGLxuZM.js.map → generate.runtime-CexC1Oky.js.map} +1 -1
- package/dist/chunks/{generate.runtime-AYQVW1S-.js → generate.runtime-CnPraLKv.js} +35 -31
- package/dist/chunks/generate.runtime-CnPraLKv.js.map +1 -0
- package/dist/chunks/generate.runtime-CslAvllQ.js +112 -0
- package/dist/chunks/generate.runtime-CslAvllQ.js.map +1 -0
- package/dist/chunks/{generate.runtime-onBnOiS7.js → generate.runtime-CuNhY5hn.js} +10 -10
- package/dist/chunks/generate.runtime-CuNhY5hn.js.map +1 -0
- package/dist/chunks/{generate.runtime-B45MvtYm.js → generate.runtime-DD51OSuL.js} +14 -14
- package/dist/chunks/generate.runtime-DD51OSuL.js.map +1 -0
- package/dist/chunks/generate.runtime-DHBRyMAq.js +65 -0
- package/dist/chunks/generate.runtime-DHBRyMAq.js.map +1 -0
- package/dist/chunks/generate.runtime-DV3WmZtb.js +35 -0
- package/dist/chunks/generate.runtime-DV3WmZtb.js.map +1 -0
- package/dist/chunks/generate.runtime-D_sQOeQa.js +164 -0
- package/dist/chunks/generate.runtime-D_sQOeQa.js.map +1 -0
- package/dist/chunks/{generate.runtime-ofdnLtxS.js → generate.runtime-DqD3PW-W.js} +3 -3
- package/dist/chunks/{generate.runtime-ofdnLtxS.js.map → generate.runtime-DqD3PW-W.js.map} +1 -1
- package/dist/chunks/{generate.runtime-VgVwRiiN.js → generate.runtime-Dtgw9IQO.js} +8 -8
- package/dist/chunks/generate.runtime-Dtgw9IQO.js.map +1 -0
- package/dist/chunks/{generate.runtime-CN5c2xH8.js → generate.runtime-IlBCcXvv.js} +14 -14
- package/dist/chunks/generate.runtime-IlBCcXvv.js.map +1 -0
- package/dist/chunks/{generate.runtime-BSRFv4cJ.js → generate.runtime-cwvAoKoH.js} +3 -3
- package/dist/chunks/{generate.runtime-BSRFv4cJ.js.map → generate.runtime-cwvAoKoH.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DG-3G00z.js → generate.runtime-kvxmTlQb.js} +3 -3
- package/dist/chunks/{generate.runtime-DG-3G00z.js.map → generate.runtime-kvxmTlQb.js.map} +1 -1
- package/dist/chunks/generate.runtime-pVLzzpUM.js +122 -0
- package/dist/chunks/generate.runtime-pVLzzpUM.js.map +1 -0
- package/dist/chunks/{generate.runtime-BFOXm2DD.js → generate.runtime-zJpEufTc.js} +10 -10
- package/dist/chunks/generate.runtime-zJpEufTc.js.map +1 -0
- package/dist/chunks/lib-specifier-Cngo1zF_.js +33 -0
- package/dist/chunks/lib-specifier-Cngo1zF_.js.map +1 -0
- package/dist/chunks/{modify-file-Dwfv0dCI.js → modify-file-BlDeeurK.js} +3 -3
- package/dist/chunks/{modify-file-Dwfv0dCI.js.map → modify-file-BlDeeurK.js.map} +1 -1
- package/dist/chunks/{modify-svelte-config-remote-BUU_EaDf.js → modify-svelte-config-remote-p0TfVzxm.js} +8 -10
- package/dist/chunks/modify-svelte-config-remote-p0TfVzxm.js.map +1 -0
- package/dist/chunks/nav-user-BRIHOOpG.js +6 -0
- package/dist/chunks/nav-user-BRIHOOpG.js.map +1 -0
- package/dist/chunks/package-imports-Bbw3iMPg.js +173 -0
- package/dist/chunks/package-imports-Bbw3iMPg.js.map +1 -0
- package/dist/chunks/{pocketbase-BkhUywtb.js → pocketbase-Dry6ry17.js} +2 -2
- package/dist/chunks/{pocketbase-BkhUywtb.js.map → pocketbase-Dry6ry17.js.map} +1 -1
- package/dist/chunks/{providers-BL9vJP_9.js → providers-BHR6-XZ7.js} +11 -4
- package/dist/chunks/providers-BHR6-XZ7.js.map +1 -0
- package/dist/chunks/{shared-C8GtNxpm.js → shared-CZC4d7Uj.js} +2 -2
- package/dist/chunks/{shared-C8GtNxpm.js.map → shared-CZC4d7Uj.js.map} +1 -1
- package/dist/chunks/{site-BdMX8qrH.js → site-BwCA18Sv.js} +2 -2
- package/dist/chunks/{site-BdMX8qrH.js.map → site-BwCA18Sv.js.map} +1 -1
- package/dist/chunks/table-core-AjBpYi-y.js +127 -0
- package/dist/chunks/table-core-AjBpYi-y.js.map +1 -0
- package/dist/chunks/{test-setup-DHEFKEHE.js → test-setup-DEmWd9Ul.js} +76 -67
- package/dist/chunks/test-setup-DEmWd9Ul.js.map +1 -0
- package/dist/chunks/{ts-morph-helpers-CeduA--o.js → ts-morph-helpers-CDW4lhox.js} +77 -63
- package/dist/chunks/ts-morph-helpers-CDW4lhox.js.map +1 -0
- package/dist/chunks/ui-DD4NltyN.js.map +1 -1
- package/dist/chunks/{ui-TlEuI2Sz.js → ui-X698F10c.js} +47 -47
- package/dist/chunks/{ui-TlEuI2Sz.js.map → ui-X698F10c.js.map} +1 -1
- package/dist/chunks/{unmodify-load-jfdcVZ_a.js → unmodify-load-CyGzC1Hu.js} +2 -2
- package/dist/chunks/{unmodify-load-jfdcVZ_a.js.map → unmodify-load-CyGzC1Hu.js.map} +1 -1
- package/dist/chunks/write-result-B68lvI57.js +511 -0
- package/dist/chunks/write-result-B68lvI57.js.map +1 -0
- package/dist/index.d.ts +302 -157
- package/dist/index.js +2124 -2066
- package/dist/index.js.map +1 -1
- package/package.json +10 -9
- package/dist/chunks/_layout-B7ujvjnA.js +0 -55
- package/dist/chunks/_layout-B7ujvjnA.js.map +0 -1
- package/dist/chunks/compose-handle-B-CkDcQD.js.map +0 -1
- package/dist/chunks/config-target-Bln26FJe.js.map +0 -1
- package/dist/chunks/constants-BYkd9jeJ.js +0 -6
- package/dist/chunks/constants-BYkd9jeJ.js.map +0 -1
- package/dist/chunks/dispatch-BRnt8PcW.js +0 -6
- package/dist/chunks/dispatch-BRnt8PcW.js.map +0 -1
- package/dist/chunks/generate-6snrlnpA.js +0 -64
- package/dist/chunks/generate-6snrlnpA.js.map +0 -1
- package/dist/chunks/generate-Ca_6FlPi.js +0 -252
- package/dist/chunks/generate-CyuY2Ci7.js.map +0 -1
- package/dist/chunks/generate-DQeWOEPY.js.map +0 -1
- package/dist/chunks/generate.runtime-AYQVW1S-.js.map +0 -1
- package/dist/chunks/generate.runtime-B2aFFaac.js +0 -117
- package/dist/chunks/generate.runtime-B2aFFaac.js.map +0 -1
- package/dist/chunks/generate.runtime-B45MvtYm.js.map +0 -1
- package/dist/chunks/generate.runtime-BFOXm2DD.js.map +0 -1
- package/dist/chunks/generate.runtime-BHkFmI2Y.js +0 -146
- package/dist/chunks/generate.runtime-BHkFmI2Y.js.map +0 -1
- package/dist/chunks/generate.runtime-BKiJvE8I.js.map +0 -1
- package/dist/chunks/generate.runtime-BUqsF3AF.js +0 -123
- package/dist/chunks/generate.runtime-BUqsF3AF.js.map +0 -1
- package/dist/chunks/generate.runtime-BsaSyTnU.js +0 -82
- package/dist/chunks/generate.runtime-BsaSyTnU.js.map +0 -1
- package/dist/chunks/generate.runtime-CMnvmeVt.js +0 -111
- package/dist/chunks/generate.runtime-CMnvmeVt.js.map +0 -1
- package/dist/chunks/generate.runtime-CN5c2xH8.js.map +0 -1
- package/dist/chunks/generate.runtime-CgoSrP55.js +0 -146
- package/dist/chunks/generate.runtime-CgoSrP55.js.map +0 -1
- package/dist/chunks/generate.runtime-D1DNAY6k.js.map +0 -1
- package/dist/chunks/generate.runtime-DQwSY6Nc.js +0 -38
- package/dist/chunks/generate.runtime-DQwSY6Nc.js.map +0 -1
- package/dist/chunks/generate.runtime-D_yqWLcI.js +0 -66
- package/dist/chunks/generate.runtime-D_yqWLcI.js.map +0 -1
- package/dist/chunks/generate.runtime-Drmahmdl.js +0 -313
- package/dist/chunks/generate.runtime-Drmahmdl.js.map +0 -1
- package/dist/chunks/generate.runtime-FdZw277n.js.map +0 -1
- package/dist/chunks/generate.runtime-Lh1cW9Tz.js +0 -94
- package/dist/chunks/generate.runtime-Lh1cW9Tz.js.map +0 -1
- package/dist/chunks/generate.runtime-QGHToXRY.js +0 -32
- package/dist/chunks/generate.runtime-QGHToXRY.js.map +0 -1
- package/dist/chunks/generate.runtime-VgVwRiiN.js.map +0 -1
- package/dist/chunks/generate.runtime-YyIVd4oy.js +0 -61
- package/dist/chunks/generate.runtime-YyIVd4oy.js.map +0 -1
- package/dist/chunks/generate.runtime-onBnOiS7.js.map +0 -1
- package/dist/chunks/modify-svelte-config-remote-BUU_EaDf.js.map +0 -1
- package/dist/chunks/nav-user-BYI-h8Od.js +0 -6
- package/dist/chunks/nav-user-BYI-h8Od.js.map +0 -1
- package/dist/chunks/providers-BL9vJP_9.js.map +0 -1
- package/dist/chunks/table-core-G9Shld4F.js +0 -126
- package/dist/chunks/table-core-G9Shld4F.js.map +0 -1
- package/dist/chunks/test-setup-DHEFKEHE.js.map +0 -1
- package/dist/chunks/ts-morph-helpers-CeduA--o.js.map +0 -1
- package/dist/chunks/write-result-Djy0SZXX.js +0 -376
- package/dist/chunks/write-result-Djy0SZXX.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-core-AjBpYi-y.js","names":[],"sources":["../../src/runtime/registry.ts","../../src/runtime/table-core.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type { RegistryItem, WriteResultRuntime } from \"../core/types\";\nimport { RegistryUnavailableError } from \"../core/errors\";\nimport { libAliasPath } from \"./lib-specifier\";\n\n/**\n * shadcn-svelte's schema defaults. A `components.json` that names no `style`\n * resolves to `nova` (not `vega`, whatever `getRegistryUrl`'s fallback says),\n * which is why the CLI's templates write the key explicitly.\n */\nexport const DEFAULT_STYLE = \"nova\";\nexport const DEFAULT_REGISTRY = \"https://shadcn-svelte.com/registry\";\nexport const DEFAULT_CSS_PATH = \"src/app.css\";\n\nconst REGISTRY_TIMEOUT_MS = 10_000;\n\nexport interface ComponentsConfig {\n style: string;\n registry: string;\n baseColor?: string;\n iconLibrary?: string;\n menuColor?: string;\n menuAccent?: string;\n aliases: Record<string, string>;\n /** `tailwind.css`: the global stylesheet, relative to the root. */\n cssPath: string;\n}\n\ninterface RawComponentsConfig {\n style?: unknown;\n registry?: unknown;\n iconLibrary?: unknown;\n menuColor?: unknown;\n menuAccent?: unknown;\n tailwind?: { css?: unknown; baseColor?: unknown };\n aliases?: Record<string, unknown>;\n}\n\nfunction optionalString(value: unknown): string | undefined {\n return typeof value === \"string\" && value.length > 0 ? value : undefined;\n}\n\n/**\n * The project's `components.json` with the schema defaults filled in. A\n * missing or unreadable file behaves like an empty one, so callers can still\n * compute paths and the existence checks here agree with shadcn's own.\n */\nexport function readComponentsConfig(root: string): ComponentsConfig {\n let raw: RawComponentsConfig = {};\n const configPath = path.join(root, \"components.json\");\n if (existsSync(configPath)) {\n try {\n const parsed: unknown = JSON.parse(readFileSync(configPath, \"utf8\"));\n if (parsed && typeof parsed === \"object\") {\n raw = parsed as RawComponentsConfig;\n }\n } catch {\n raw = {};\n }\n }\n\n const aliases: Record<string, string> = {};\n for (const [key, value] of Object.entries(raw.aliases ?? {})) {\n const alias = optionalString(value);\n if (alias) aliases[key] = alias;\n }\n\n return {\n style: optionalString(raw.style) ?? DEFAULT_STYLE,\n registry: optionalString(raw.registry) ?? DEFAULT_REGISTRY,\n baseColor: optionalString(raw.tailwind?.baseColor),\n iconLibrary: optionalString(raw.iconLibrary),\n menuColor: optionalString(raw.menuColor),\n menuAccent: optionalString(raw.menuAccent),\n aliases,\n cssPath: optionalString(raw.tailwind?.css) ?? DEFAULT_CSS_PATH,\n };\n}\n\nconst DEFAULT_UI_DIR = [\"src\", \"lib\", \"components\", \"ui\"];\n\n/**\n * Where shadcn-svelte writes items: `components.json` `aliases.ui`, resolved\n * under `src/lib` for `#lib/...`, or the alias a project from before\n * SvelteKit 3 still has.\n * Anything else (a custom alias, a missing or unreadable config) falls back\n * to the default so the existence check here and shadcn's own target agree\n * for every project the CLI creates.\n */\nexport function resolveUiDir(root: string): string {\n const alias = readComponentsConfig(root).aliases.ui;\n const rel = alias === undefined ? null : libAliasPath(alias);\n if (rel === null) {\n return path.join(root, ...DEFAULT_UI_DIR);\n }\n return path.join(root, \"src\", \"lib\", ...rel.split(\"/\").filter(Boolean));\n}\n\n/** `${registry}/styles/${style}/index.json`: the items one style offers. */\nexport function registryIndexUrl(registry: string, style: string): string {\n return `${registry.replace(/\\/+$/, \"\")}/styles/${encodeURIComponent(style)}/index.json`;\n}\n\n/**\n * One request per registry URL per process, keyed on the fetch implementation\n * so an injected test double never sees another test's answer and the real\n * `fetch` shares its answer across a style switch and the installs it runs.\n */\nconst indexCache = new WeakMap<\n typeof fetch,\n Map<string, Promise<RegistryItem[]>>\n>();\n\nfunction parseIndex(body: unknown): RegistryItem[] {\n if (!Array.isArray(body)) {\n throw new Error(\"the index is not a list\");\n }\n const items: RegistryItem[] = [];\n for (const entry of body) {\n if (!entry || typeof entry !== \"object\") continue;\n const { name, type } = entry as { name?: unknown; type?: unknown };\n if (typeof name === \"string\" && typeof type === \"string\") {\n items.push({ name, type });\n }\n }\n return items;\n}\n\nasync function requestIndex(\n url: string,\n fetchImpl: typeof fetch,\n): Promise<RegistryItem[]> {\n let response: Response;\n try {\n response = await fetchImpl(url, {\n signal: AbortSignal.timeout(REGISTRY_TIMEOUT_MS),\n });\n } catch (error) {\n const reason =\n error instanceof Error && error.name === \"TimeoutError\"\n ? `no answer within ${REGISTRY_TIMEOUT_MS / 1000}s`\n : error instanceof Error\n ? error.message\n : String(error);\n throw new RegistryUnavailableError(url, reason);\n }\n if (!response.ok) {\n throw new RegistryUnavailableError(url, `HTTP ${response.status}`);\n }\n try {\n return parseIndex(await response.json());\n } catch (error) {\n throw new RegistryUnavailableError(\n url,\n error instanceof Error ? error.message : String(error),\n );\n }\n}\n\n/**\n * The items the project's registry offers for a style: the configured one by\n * default, or `options.style` to look at the style a project is about to\n * switch to. Throws `RegistryUnavailableError` when the index cannot be read.\n */\nexport async function fetchRegistryIndex(\n root: string,\n options: { style?: string; runtime?: WriteResultRuntime } = {},\n): Promise<RegistryItem[]> {\n const config = readComponentsConfig(root);\n const url = registryIndexUrl(config.registry, options.style ?? config.style);\n const fetchImpl = options.runtime?.fetch ?? globalThis.fetch;\n\n let cache = indexCache.get(fetchImpl);\n if (!cache) {\n cache = new Map();\n indexCache.set(fetchImpl, cache);\n }\n let pending = cache.get(url);\n if (!pending) {\n pending = requestIndex(url, fetchImpl).catch((error: unknown) => {\n // A failed read is not worth remembering: the next command may be online.\n cache.delete(url);\n throw error;\n });\n cache.set(url, pending);\n }\n return pending;\n}\n","import { existsSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport {\n TANSTACK_TABLE_CORE,\n TANSTACK_TABLE_CORE_MAJOR,\n} from \"../core/constants\";\nimport { InvalidArgumentError } from \"../core/errors\";\nimport { resolveUiDir } from \"./registry\";\n\n/** The components this package ships that are built on `@tanstack/table-core`. */\nexport const TABLE_CORE_COMPONENTS = [\n \"data-table\",\n \"column-header\",\n \"faceted-filter\",\n \"pagination\",\n];\n\nconst MIGRATION_GUIDE =\n \"https://tanstack.com/table/latest/docs/framework/svelte/guide/migrating\";\n\n/**\n * The major of the `@tanstack/table-core` range `package.json` declares, when\n * it names one (`^8.21.3` is 8; `latest` or `workspace:*` is undefined).\n */\nexport function declaredTableCoreMajor(root: string): number | undefined {\n const packageJsonPath = path.join(root, \"package.json\");\n if (!existsSync(packageJsonPath)) return undefined;\n const pkg = JSON.parse(readFileSync(packageJsonPath, \"utf8\")) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n const range =\n pkg.dependencies?.[\"@tanstack/table-core\"] ??\n pkg.devDependencies?.[\"@tanstack/table-core\"];\n const major = range?.match(/^[\\^~>=v\\s]*(\\d+)/)?.[1];\n return major === undefined ? undefined : Number(major);\n}\n\n/** Whether the project's `data-table` helper is the v8 one (`createSvelteTable`). */\nfunction hasV8DataTable(root: string): boolean {\n const index = path.join(resolveUiDir(root), \"data-table\", \"index.ts\");\n return (\n existsSync(index) &&\n readFileSync(index, \"utf8\").includes(\"createSvelteTable\")\n );\n}\n\nfunction upgradeSteps(): string {\n return (\n \"Nothing was changed. To upgrade:\\n\" +\n ` 1. Install ${TANSTACK_TABLE_CORE}: npm install ${TANSTACK_TABLE_CORE}\\n` +\n ` 2. Replace the table helpers: vela ui add ${TABLE_CORE_COMPONENTS.join(\" \")} --overwrite\\n` +\n ` 3. Move existing list pages to the v9 API (createTable, tableFeatures): ${MIGRATION_GUIDE}\\n` +\n \"Then run this again.\"\n );\n}\n\n/**\n * Refuses a project still on TanStack Table v8, before anything is written.\n *\n * The scaffold list pages and the table helpers target v9. A project set up\n * before that has `@tanstack/table-core@^8` and v8 helpers; the package is\n * never upgraded by `installPackages` (it is already present) and the helpers\n * are never replaced (they already exist), so a new page would not compile,\n * and upgrading in place would break the list pages already there.\n */\nexport function assertTableCoreV9(root: string): void {\n const major = declaredTableCoreMajor(root);\n const outdatedPackage =\n major !== undefined && major < TANSTACK_TABLE_CORE_MAJOR;\n if (!outdatedPackage && !hasV8DataTable(root)) return;\n\n const found = outdatedPackage\n ? `package.json pins @tanstack/table-core ${major}.x`\n : \"its data-table helper is the v8 one (createSvelteTable)\";\n throw new InvalidArgumentError(\n `This project uses TanStack Table v8 (${found}), and scaffold list pages now need v${TANSTACK_TABLE_CORE_MAJOR}.\\n\\n` +\n upgradeSteps(),\n );\n}\n\n/**\n * Refuses to add v9 table helpers next to a v8 `@tanstack/table-core`, which\n * `installPackages` would leave in place.\n */\nexport function assertTableCorePackage(\n root: string,\n components: string[],\n): void {\n const tableComponents = components.filter((component) =>\n TABLE_CORE_COMPONENTS.includes(component),\n );\n if (tableComponents.length === 0) return;\n const major = declaredTableCoreMajor(root);\n if (major === undefined || major >= TANSTACK_TABLE_CORE_MAJOR) return;\n\n throw new InvalidArgumentError(\n `${tableComponents.join(\", \")} target${tableComponents.length === 1 ? \"s\" : \"\"} TanStack Table v${TANSTACK_TABLE_CORE_MAJOR}, and package.json pins @tanstack/table-core ${major}.x.\\n\\n` +\n `Nothing was changed. Install ${TANSTACK_TABLE_CORE} first (npm install ${TANSTACK_TABLE_CORE}), then run this again.`,\n );\n}\n"],"mappings":";;;;;;AAeA,IAAM,IAAsB;AAwB5B,SAAS,EAAe,GAAoC;CAC1D,OAAO,OAAO,KAAU,YAAY,EAAM,SAAS,IAAI,IAAQ,KAAA;AACjE;AAOA,SAAgB,EAAqB,GAAgC;CACnE,IAAI,IAA2B,CAAC,GAC1B,IAAa,EAAK,KAAK,GAAM,iBAAiB;CACpD,IAAI,EAAW,CAAU,GACvB,IAAI;EACF,IAAM,IAAkB,KAAK,MAAM,EAAa,GAAY,MAAM,CAAC;EACnE,AAAI,KAAU,OAAO,KAAW,aAC9B,IAAM;CAEV,QAAQ;EACN,IAAM,CAAC;CACT;CAGF,IAAM,IAAkC,CAAC;CACzC,KAAK,IAAM,CAAC,GAAK,MAAU,OAAO,QAAQ,EAAI,WAAW,CAAC,CAAC,GAAG;EAC5D,IAAM,IAAQ,EAAe,CAAK;EAClC,AAAI,MAAO,EAAQ,KAAO;CAC5B;CAEA,OAAO;EACL,OAAO,EAAe,EAAI,KAAK,KAAA;EAC/B,UAAU,EAAe,EAAI,QAAQ,KAAA;EACrC,WAAW,EAAe,EAAI,UAAU,SAAS;EACjD,aAAa,EAAe,EAAI,WAAW;EAC3C,WAAW,EAAe,EAAI,SAAS;EACvC,YAAY,EAAe,EAAI,UAAU;EACzC;EACA,SAAS,EAAe,EAAI,UAAU,GAAG,KAAA;CAC3C;AACF;AAEA,IAAM,IAAiB;CAAC;CAAO;CAAO;CAAc;AAAI;AAUxD,SAAgB,EAAa,GAAsB;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;CACzB,IAAI,CAAC,KAAmB,CAAC,EAAe,CAAI,GAAG;CAE/C,IAAM,IAAQ,IACV,0CAA0C,EAAM,MAChD;CACJ,MAAM,IAAI,EACR,wCAAwC,EAAM,+CAC5C,EAAa,CACjB;AACF;AAMA,SAAgB,EACd,GACA,GACM;CACN,IAAM,IAAkB,EAAW,QAAQ,MACzC,EAAsB,SAAS,CAAS,CAC1C;CACA,IAAI,EAAgB,WAAW,GAAG;CAClC,IAAM,IAAQ,EAAuB,CAAI;CACrC,YAAU,KAAA,KAAa,KAAA,IAE3B,MAAM,IAAI,EACR,GAAG,EAAgB,KAAK,IAAI,EAAE,SAAS,EAAgB,WAAW,IAAI,MAAM,GAAG,iEAA4F,EAAM,sCAC/I,EAAoB,sBAAsB,EAAoB,wBAClG;AACF"}
|
|
@@ -1,89 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import r from "
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { n as e, t } from "./constants-BjyMU5s8.js";
|
|
2
|
+
import { t as n } from "./dedent-Gq6Krl4n.js";
|
|
3
|
+
import { o as r, s as i } from "./config-target-Dx3w6WSk.js";
|
|
4
|
+
import { c as a } from "./write-result-B68lvI57.js";
|
|
5
|
+
import o from "node:fs";
|
|
6
|
+
import s from "node:path";
|
|
7
|
+
import { SyntaxKind as c } from "ts-morph";
|
|
6
8
|
//#region src/patterns/enable/backend/modifies/svelte-config.ts
|
|
7
|
-
var
|
|
8
|
-
Switch the SvelteKit adapter to ${
|
|
9
|
+
var l = a(t), u = a(e), d = "@sveltejs/adapter-auto", f = n`
|
|
10
|
+
Switch the SvelteKit adapter to ${l}:
|
|
9
11
|
|
|
10
|
-
import adapter from '${
|
|
12
|
+
import adapter from '${l}';
|
|
11
13
|
|
|
12
14
|
// ...
|
|
13
15
|
adapter: adapter()
|
|
14
|
-
`,
|
|
15
|
-
Configure ${
|
|
16
|
+
`, p = n`
|
|
17
|
+
Configure ${l} via the sveltekit() plugin in vite.config.ts.
|
|
16
18
|
`;
|
|
17
|
-
function
|
|
19
|
+
function m(e) {
|
|
18
20
|
return e.getImportDeclarations().find((e) => [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
u,
|
|
22
|
+
d,
|
|
23
|
+
l
|
|
22
24
|
].includes(e.getModuleSpecifierValue()));
|
|
23
25
|
}
|
|
24
|
-
function
|
|
25
|
-
return e.getDescendantsOfKind(
|
|
26
|
+
function h(e) {
|
|
27
|
+
return e.getDescendantsOfKind(c.CallExpression).filter((e) => e.getExpression().getText() === "adapter");
|
|
26
28
|
}
|
|
27
|
-
function
|
|
28
|
-
let
|
|
29
|
-
notFound:
|
|
30
|
-
failed:
|
|
29
|
+
function g(e) {
|
|
30
|
+
let t = r(e, {
|
|
31
|
+
notFound: p,
|
|
32
|
+
failed: f
|
|
31
33
|
});
|
|
32
|
-
if (
|
|
33
|
-
filePath:
|
|
34
|
+
if (t.status !== "resolved") return {
|
|
35
|
+
filePath: t.filePath,
|
|
34
36
|
outcome: {
|
|
35
|
-
status:
|
|
36
|
-
message:
|
|
37
|
+
status: t.status,
|
|
38
|
+
message: t.message
|
|
37
39
|
}
|
|
38
40
|
};
|
|
39
|
-
let { target:
|
|
41
|
+
let { target: n } = t, a = m(n.sourceFile);
|
|
40
42
|
if (!a) return {
|
|
41
|
-
filePath:
|
|
43
|
+
filePath: n.filePath,
|
|
42
44
|
outcome: {
|
|
43
45
|
status: "failed",
|
|
44
|
-
message:
|
|
46
|
+
message: f
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
|
-
a.getModuleSpecifierValue() !==
|
|
48
|
-
for (let e of
|
|
49
|
+
a.getModuleSpecifierValue() !== l && a.setModuleSpecifier(l);
|
|
50
|
+
for (let e of h(n.sourceFile)) {
|
|
49
51
|
let t = e.getArguments();
|
|
50
52
|
for (let n = t.length - 1; n >= 0; n--) e.removeArgument(n);
|
|
51
53
|
}
|
|
52
54
|
return {
|
|
53
|
-
filePath:
|
|
54
|
-
outcome: n
|
|
55
|
+
filePath: n.filePath,
|
|
56
|
+
outcome: i(n)
|
|
55
57
|
};
|
|
56
58
|
}
|
|
57
|
-
function
|
|
58
|
-
let
|
|
59
|
-
notFound:
|
|
60
|
-
failed:
|
|
59
|
+
function _(e) {
|
|
60
|
+
let t = r(e, {
|
|
61
|
+
notFound: p,
|
|
62
|
+
failed: f
|
|
61
63
|
});
|
|
62
|
-
if (
|
|
63
|
-
filePath:
|
|
64
|
+
if (t.status === "not-found") return {
|
|
65
|
+
filePath: t.filePath,
|
|
64
66
|
outcome: {
|
|
65
67
|
status: "success",
|
|
66
68
|
changed: !1
|
|
67
69
|
}
|
|
68
70
|
};
|
|
69
|
-
|
|
71
|
+
if (t.status === "failed") return {
|
|
72
|
+
filePath: t.filePath,
|
|
73
|
+
outcome: {
|
|
74
|
+
status: "failed",
|
|
75
|
+
message: t.message
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
let { target: n } = t, a = m(n.sourceFile);
|
|
70
79
|
if (!a) return {
|
|
71
|
-
filePath:
|
|
80
|
+
filePath: n.filePath,
|
|
72
81
|
outcome: {
|
|
73
82
|
status: "success",
|
|
74
83
|
changed: !1
|
|
75
84
|
}
|
|
76
85
|
};
|
|
77
|
-
a.getModuleSpecifierValue() !==
|
|
78
|
-
for (let e of
|
|
86
|
+
a.getModuleSpecifierValue() !== u && a.setModuleSpecifier(u);
|
|
87
|
+
for (let e of h(n.sourceFile)) e.getArguments().length === 0 && e.addArgument("{ fallback: '200.html' }");
|
|
79
88
|
return {
|
|
80
|
-
filePath:
|
|
81
|
-
outcome: n
|
|
89
|
+
filePath: n.filePath,
|
|
90
|
+
outcome: i(n)
|
|
82
91
|
};
|
|
83
92
|
}
|
|
84
93
|
//#endregion
|
|
85
94
|
//#region src/patterns/enable/backend/modifies/gitignore.ts
|
|
86
|
-
var
|
|
95
|
+
var v = "# PocketBase\n/data/*\n!/data/fixtures\n!/data/seeds\n!/data/hooks\n", y = n`
|
|
87
96
|
Create a .gitignore at the project root with the PocketBase block:
|
|
88
97
|
|
|
89
98
|
# PocketBase
|
|
@@ -92,28 +101,28 @@ var h = "# PocketBase\n/data/*\n!/data/fixtures\n!/data/seeds\n!/data/hooks\n",
|
|
|
92
101
|
!/data/seeds
|
|
93
102
|
!/data/hooks
|
|
94
103
|
`;
|
|
95
|
-
function
|
|
96
|
-
if (!
|
|
104
|
+
function b(e) {
|
|
105
|
+
if (!o.existsSync(e)) return {
|
|
97
106
|
status: "not-found",
|
|
98
|
-
message:
|
|
107
|
+
message: y
|
|
99
108
|
};
|
|
100
|
-
let t =
|
|
109
|
+
let t = o.readFileSync(e, "utf8");
|
|
101
110
|
if (t.includes("# PocketBase") && t.includes("/data/*")) return {
|
|
102
111
|
status: "success",
|
|
103
112
|
changed: !1
|
|
104
113
|
};
|
|
105
|
-
let n = t + (t.endsWith("\n") ? "\n" : "\n\n") +
|
|
106
|
-
return
|
|
114
|
+
let n = t + (t.endsWith("\n") ? "\n" : "\n\n") + v;
|
|
115
|
+
return o.writeFileSync(e, n, "utf8"), {
|
|
107
116
|
status: "success",
|
|
108
117
|
changed: !0
|
|
109
118
|
};
|
|
110
119
|
}
|
|
111
|
-
function
|
|
112
|
-
if (!
|
|
120
|
+
function x(e) {
|
|
121
|
+
if (!o.existsSync(e)) return {
|
|
113
122
|
status: "success",
|
|
114
123
|
changed: !1
|
|
115
124
|
};
|
|
116
|
-
let t =
|
|
125
|
+
let t = o.readFileSync(e, "utf8");
|
|
117
126
|
if (!t.includes("# PocketBase")) return {
|
|
118
127
|
status: "success",
|
|
119
128
|
changed: !1
|
|
@@ -122,49 +131,49 @@ function v(e) {
|
|
|
122
131
|
return n === t ? {
|
|
123
132
|
status: "success",
|
|
124
133
|
changed: !1
|
|
125
|
-
} : (
|
|
134
|
+
} : (o.writeFileSync(e, n, "utf8"), {
|
|
126
135
|
status: "success",
|
|
127
136
|
changed: !0
|
|
128
137
|
});
|
|
129
138
|
}
|
|
130
139
|
//#endregion
|
|
131
140
|
//#region src/patterns/enable/backend/modifies/test-setup.ts
|
|
132
|
-
var
|
|
141
|
+
var S = "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 await agent.post('/login').type('form').send({\n type: 'password',\n email: user.email,\n password: testUserPassword\n });\n}\n\nbeforeAll(async () => {\n await admin\n // @ts-ignore\n .collection('_superusers')\n .authWithPassword(\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!\n );\n});\n\nbeforeEach(async (context: TestContext) => {\n context.request = supertest(process.env.VITE_TEST_URL!);\n context.agent = supertest.agent(process.env.VITE_TEST_URL!) as TestContext['agent'];\n context.admin = admin;\n context.pb = pb;\n context.user = await context.admin.collection('users').create({\n email: `test-${Math.random().toString(36).slice(2)}@example.com`,\n password: testUserPassword,\n passwordConfirm: testUserPassword\n });\n context.agent.authenticateUser = () => authenticateUser(context.agent, context.user);\n await context.pb.collection('users').authWithPassword(context.user.email, testUserPassword);\n});\n\nafterEach(async (context: TestContext) => {\n await context.pb.authStore.clear();\n await context.admin.collection('users').delete(context.user.id);\n});\n", C = "import { beforeEach } from 'vitest';\nimport supertest from 'supertest';\n\nbeforeEach(async (context: any) => {\n context.request = supertest(process.env.VITE_TEST_URL!);\n context.agent = supertest.agent(process.env.VITE_TEST_URL!);\n});\n", w = "import { defineConfig, mergeConfig } from 'vitest/config';\nimport viteConfig from './vite.config';\n\nexport default mergeConfig(\n viteConfig,\n defineConfig({\n test: {\n expect: {\n requireAssertions: true\n },\n name: 'server',\n environment: 'node',\n include: ['src/**/*.{test,spec}.{js,ts}'],\n exclude: ['src/**/*.svelte.{test,spec}.{js,ts}'],\n setupFiles: ['test/setup.ts']\n }\n })\n);\n", T = [
|
|
133
142
|
"ts",
|
|
134
143
|
"mts",
|
|
135
144
|
"js",
|
|
136
145
|
"mjs"
|
|
137
146
|
].flatMap((e) => [`vitest.config.${e}`, `vitest.workspace.${e}`]);
|
|
138
|
-
function
|
|
139
|
-
return
|
|
147
|
+
function E(e) {
|
|
148
|
+
return T.some((t) => o.existsSync(s.join(e, t))) ? !0 : [
|
|
140
149
|
"ts",
|
|
141
150
|
"mts",
|
|
142
151
|
"js",
|
|
143
152
|
"mjs"
|
|
144
153
|
].some((t) => {
|
|
145
|
-
let n =
|
|
146
|
-
return
|
|
154
|
+
let n = s.join(e, `vite.config.${t}`);
|
|
155
|
+
return o.existsSync(n) && /\btest\s*:/.test(o.readFileSync(n, "utf8"));
|
|
147
156
|
});
|
|
148
157
|
}
|
|
149
|
-
function
|
|
150
|
-
return !
|
|
158
|
+
function D(e) {
|
|
159
|
+
return !o.existsSync(e) || o.readFileSync(e, "utf8") === S ? {
|
|
151
160
|
status: "success",
|
|
152
161
|
changed: !1
|
|
153
|
-
} : (
|
|
162
|
+
} : (o.writeFileSync(e, S, "utf8"), {
|
|
154
163
|
status: "success",
|
|
155
164
|
changed: !0
|
|
156
165
|
});
|
|
157
166
|
}
|
|
158
|
-
function
|
|
159
|
-
return !
|
|
167
|
+
function O(e) {
|
|
168
|
+
return !o.existsSync(e) || o.readFileSync(e, "utf8") === C ? {
|
|
160
169
|
status: "success",
|
|
161
170
|
changed: !1
|
|
162
|
-
} : (
|
|
171
|
+
} : (o.writeFileSync(e, C, "utf8"), {
|
|
163
172
|
status: "success",
|
|
164
173
|
changed: !0
|
|
165
174
|
});
|
|
166
175
|
}
|
|
167
176
|
//#endregion
|
|
168
|
-
export {
|
|
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 };
|
|
169
178
|
|
|
170
|
-
//# sourceMappingURL=test-setup-
|
|
179
|
+
//# sourceMappingURL=test-setup-DEmWd9Ul.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-setup-DEmWd9Ul.js","names":[],"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\\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\\tcontext.user = await context.admin.collection('users').create({\n\\t\\temail: \\`test-\\${Math.random().toString(36).slice(2)}@example.com\\`,\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(context.user.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,IAAM,IAAe,EAAY,CAAiB,GAC5C,IAAiB,EAAY,CAAmB,GAChD,IAAe,0BAEf,IAAe,CAAM;oCACS,EAAa;;yBAExB,EAAa;;;;GAMhC,IAAiB,CAAM;cACf,EAAa;;AAQ3B,SAAS,EAAkB,GAAwC;CACjE,OAAO,EACJ,sBAAsB,CAAC,CACvB,MAAM,MACL;EAAC;EAAgB;EAAc;CAAY,CAAC,CAAC,SAC3C,EAAK,wBAAwB,CAC/B,CACF;AACJ;AAEA,SAAS,EAAa,GAAwC;CAC5D,OAAO,EACJ,qBAAqB,EAAW,cAAc,CAAC,CAC/C,QAAQ,MAAO,EAAG,cAAc,CAAC,CAAC,QAAQ,MAAM,SAAS;AAC9D;AASA,SAAgB,EAAmB,GAAkC;CACnE,IAAM,IAAM,EAAoB,GAAM;EACpC,UAAU;EACV,QAAQ;CACV,CAAC;CACD,IAAI,EAAI,WAAW,YACjB,OAAO;EACL,UAAU,EAAI;EACd,SAAS;GAAE,QAAQ,EAAI;GAAQ,SAAS,EAAI;EAAQ;CACtD;CAEF,IAAM,EAAE,cAAW,GACb,IAAgB,EAAkB,EAAO,UAAU;CACzD,IAAI,CAAC,GACH,OAAO;EACL,UAAU,EAAO;EACjB,SAAS;GAAE,QAAQ;GAAU,SAAS;EAAa;CACrD;CAGF,AAAI,EAAc,wBAAwB,MAA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;EAAW,SAAS;CAAM,KAG7C,EAAG,cAAc,GAAe,GAAc,MAAM,GAC7C;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C;AAEA,SAAgB,EAAkB,GAAsC;CAWtE,OAVI,CAAC,EAAG,WAAW,CAAa,KAIf,EAAG,aAAa,GAAe,MAC5C,MAAa,IACR;EAAE,QAAQ;EAAW,SAAS;CAAM,KAG7C,EAAG,cAAc,GAAe,GAAiB,MAAM,GAChD;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Node as e, Project as t, QuoteKind as n, SyntaxKind as r } from "ts-morph";
|
|
2
2
|
//#region src/runtime/ts-morph-helpers.ts
|
|
3
|
-
function i(e) {
|
|
3
|
+
function i(e, t) {
|
|
4
|
+
let n = e.getModuleSpecifierValue();
|
|
5
|
+
return typeof t == "string" ? n === t : t(n);
|
|
6
|
+
}
|
|
7
|
+
function a(e) {
|
|
4
8
|
let t = 0;
|
|
5
9
|
for (let n of e.split("\n")) {
|
|
6
10
|
if (n.startsWith(" ")) return " ";
|
|
@@ -9,15 +13,15 @@ function i(e) {
|
|
|
9
13
|
}
|
|
10
14
|
return t === 0 ? " " : " ".repeat(t);
|
|
11
15
|
}
|
|
12
|
-
function
|
|
13
|
-
let t =
|
|
16
|
+
function o(e) {
|
|
17
|
+
let t = a(e.getFullText()), n = t === " " ? 4 : t.length;
|
|
14
18
|
e.formatText({
|
|
15
19
|
convertTabsToSpaces: t !== " ",
|
|
16
20
|
indentSize: n,
|
|
17
21
|
tabSize: n
|
|
18
22
|
});
|
|
19
23
|
}
|
|
20
|
-
function
|
|
24
|
+
function s(e) {
|
|
21
25
|
let t = null;
|
|
22
26
|
for (let n of e.split("\n")) {
|
|
23
27
|
if (n.trim() === "") continue;
|
|
@@ -32,17 +36,17 @@ function o(e) {
|
|
|
32
36
|
}
|
|
33
37
|
return t ?? "";
|
|
34
38
|
}
|
|
35
|
-
function
|
|
39
|
+
function c(e, r) {
|
|
36
40
|
let i = new t({
|
|
37
41
|
useInMemoryFileSystem: !0,
|
|
38
42
|
skipFileDependencyResolution: !0,
|
|
39
43
|
manipulationSettings: { quoteKind: n.Single }
|
|
40
|
-
}), a =
|
|
44
|
+
}), a = s(e), o = a ? e.split("\n").map((e) => e.startsWith(a) ? e.slice(a.length) : e).join("\n") : e, c = i.createSourceFile("script.ts", o, { overwrite: !0 }), l = r(c), u = c.getFullText();
|
|
41
45
|
if (!a) return {
|
|
42
46
|
source: u,
|
|
43
47
|
result: l
|
|
44
48
|
};
|
|
45
|
-
if (u ===
|
|
49
|
+
if (u === o) return {
|
|
46
50
|
source: e,
|
|
47
51
|
result: l
|
|
48
52
|
};
|
|
@@ -52,46 +56,56 @@ function s(e, r) {
|
|
|
52
56
|
result: l
|
|
53
57
|
};
|
|
54
58
|
}
|
|
55
|
-
function
|
|
59
|
+
function l(e, t) {
|
|
56
60
|
for (let n of t) {
|
|
57
61
|
if (e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === n.moduleSpecifier)) continue;
|
|
58
62
|
let t = { moduleSpecifier: n.moduleSpecifier };
|
|
59
63
|
n.defaultImport && (t.defaultImport = n.defaultImport), n.namespaceImport && (t.namespaceImport = n.namespaceImport), n.namedImports && (t.namedImports = n.namedImports), e.addImportDeclaration(t);
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
|
-
function
|
|
63
|
-
let n = e.getImportDeclarations().find((e) => e
|
|
66
|
+
function u(e, t) {
|
|
67
|
+
let n = e.getImportDeclarations().find((e) => i(e, t));
|
|
64
68
|
return n ? (n.remove(), { wasRemoved: !0 }) : { wasRemoved: !1 };
|
|
65
69
|
}
|
|
66
|
-
function
|
|
70
|
+
function d(e, t) {
|
|
67
71
|
return e.getDescendantsOfKind(r.Identifier).some((e) => {
|
|
68
72
|
if (e.getText() !== t) return !1;
|
|
69
73
|
let n = e.getParent()?.getKind();
|
|
70
74
|
return n !== r.ImportSpecifier && n !== r.ImportClause && n !== r.NamespaceImport;
|
|
71
75
|
});
|
|
72
76
|
}
|
|
73
|
-
function
|
|
74
|
-
let r = e.getImportDeclarations().find((e) => e.
|
|
77
|
+
function f(e, t, n) {
|
|
78
|
+
let r = e.getImportDeclarations().find((e) => i(e, t) && e.getNamedImports().some((e) => e.getName() === n));
|
|
75
79
|
if (!r) return { wasRemoved: !1 };
|
|
76
|
-
let
|
|
77
|
-
|
|
80
|
+
let a = r.getNamedImports().find((e) => e.getName() === n);
|
|
81
|
+
if (!a || d(e, a.getAliasNode()?.getText() ?? n)) return { wasRemoved: !1 };
|
|
82
|
+
if (r.getNamedImports().length === 1 && !r.getDefaultImport()) r.remove();
|
|
83
|
+
else {
|
|
84
|
+
a.remove();
|
|
85
|
+
let e = r.getNamedImports();
|
|
86
|
+
if (!r.getDefaultImport() && e.every((e) => e.isTypeOnly())) {
|
|
87
|
+
for (let t of e) t.setIsTypeOnly(!1);
|
|
88
|
+
r.setIsTypeOnly(!0);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { wasRemoved: !0 };
|
|
78
92
|
}
|
|
79
|
-
function
|
|
93
|
+
function p(e, t) {
|
|
80
94
|
let n = [];
|
|
81
95
|
for (let r of e.getImportDeclarations()) {
|
|
82
|
-
if (!t.
|
|
96
|
+
if (!t.some((e) => i(r, e)) || !r.getImportClause()) continue;
|
|
83
97
|
for (let t of r.getNamedImports()) {
|
|
84
98
|
let r = t.getAliasNode()?.getText() ?? t.getName();
|
|
85
|
-
|
|
99
|
+
d(e, r) || (t.remove(), n.push(r));
|
|
86
100
|
}
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
let
|
|
90
|
-
|
|
101
|
+
let a = r.getDefaultImport();
|
|
102
|
+
a && !d(e, a.getText()) && (n.push(a.getText()), r.removeDefaultImport());
|
|
103
|
+
let o = r.getNamespaceImport();
|
|
104
|
+
o && !d(e, o.getText()) && (n.push(o.getText()), r.removeNamespaceImport()), r.getNamedImports().length === 0 && !r.getDefaultImport() && !r.getNamespaceImport() && r.remove();
|
|
91
105
|
}
|
|
92
106
|
return { removed: n };
|
|
93
107
|
}
|
|
94
|
-
function
|
|
108
|
+
function m(e, t, n, r = !1) {
|
|
95
109
|
let i = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t && !e.getNamespaceImport() && (r || !e.isTypeOnly()));
|
|
96
110
|
if (!i) {
|
|
97
111
|
e.addImportDeclaration({
|
|
@@ -106,55 +120,55 @@ function p(e, t, n, r = !1) {
|
|
|
106
120
|
isTypeOnly: !0
|
|
107
121
|
} : n);
|
|
108
122
|
}
|
|
109
|
-
function
|
|
123
|
+
function h(e) {
|
|
110
124
|
let t = e.getKind();
|
|
111
125
|
return t === r.SingleLineCommentTrivia || t === r.MultiLineCommentTrivia;
|
|
112
126
|
}
|
|
113
|
-
function
|
|
127
|
+
function g(e) {
|
|
114
128
|
return (e.match(/\n/g) ?? []).length;
|
|
115
129
|
}
|
|
116
|
-
function
|
|
130
|
+
function _(e, t) {
|
|
117
131
|
let n = e.getStatementsWithComments(), r = e.getFullText(), i = [], a = t.getStart(!0);
|
|
118
132
|
for (let e = n.indexOf(t) - 1; e >= 0; e--) {
|
|
119
133
|
let t = n[e];
|
|
120
|
-
if (!
|
|
134
|
+
if (!h(t) || g(r.slice(t.getEnd(), a)) > 1) break;
|
|
121
135
|
i.unshift(t), a = t.getStart();
|
|
122
136
|
}
|
|
123
137
|
return i;
|
|
124
138
|
}
|
|
125
|
-
function
|
|
126
|
-
let r =
|
|
139
|
+
function v(t, n) {
|
|
140
|
+
let r = _(t, n), i = b(t, r[0] ?? n);
|
|
127
141
|
if (e.isJSDocable(n)) for (let e of n.getJsDocs()) e.remove();
|
|
128
142
|
for (let e of r.reverse()) e.remove();
|
|
129
143
|
i.restore(n);
|
|
130
144
|
}
|
|
131
|
-
function
|
|
132
|
-
let n =
|
|
145
|
+
function y(e, t) {
|
|
146
|
+
let n = _(e, t), r = e.getStatementsWithComments(), i = r[r.indexOf(t) + 1], a = b(e, n[0] ?? t);
|
|
133
147
|
t.remove();
|
|
134
148
|
for (let e of n.reverse()) e.remove();
|
|
135
149
|
i && a.restore(i);
|
|
136
150
|
}
|
|
137
|
-
function
|
|
138
|
-
let n = e.getStatementsWithComments(), r = n[n.indexOf(t) - 1], i = r !== void 0 &&
|
|
151
|
+
function b(e, t) {
|
|
152
|
+
let n = e.getStatementsWithComments(), r = n[n.indexOf(t) - 1], i = r !== void 0 && g(e.getFullText().slice(r.getEnd(), t.getStart(!0))) > 1;
|
|
139
153
|
return { restore(t) {
|
|
140
|
-
i && r &&
|
|
154
|
+
i && r && g(e.getFullText().slice(r.getEnd(), t.getStart(!0))) < 2 && e.insertText(r.getEnd(), "\n");
|
|
141
155
|
} };
|
|
142
156
|
}
|
|
143
|
-
function
|
|
157
|
+
function x(e) {
|
|
144
158
|
return e.compilerNode.statements.every((e) => e.kind === r.EmptyStatement);
|
|
145
159
|
}
|
|
146
|
-
function
|
|
160
|
+
function S(e) {
|
|
147
161
|
let t = e.getImportDeclarations(), n = t[t.length - 1], r = n?.getNextSibling();
|
|
148
162
|
n && r && ((e.getFullText().slice(n.getEnd(), r.getStart(!0)).match(/\n/g) ?? []).length >= 2 || e.insertText(n.getEnd(), "\n"));
|
|
149
163
|
}
|
|
150
|
-
function
|
|
164
|
+
function C(t) {
|
|
151
165
|
return t.getVariableDeclarations().find((t) => t.getInitializer()?.getText() === "$props()" && e.isObjectBindingPattern(t.getNameNode()));
|
|
152
166
|
}
|
|
153
|
-
function
|
|
154
|
-
return
|
|
167
|
+
function w(e) {
|
|
168
|
+
return C(e)?.getNameNode().asKind(r.ObjectBindingPattern);
|
|
155
169
|
}
|
|
156
|
-
function
|
|
157
|
-
let n =
|
|
170
|
+
function T(e, t) {
|
|
171
|
+
let n = w(e);
|
|
158
172
|
if (!n) {
|
|
159
173
|
e.addStatements(`let { ${t} } = $props();`);
|
|
160
174
|
return;
|
|
@@ -164,15 +178,15 @@ function w(e, t) {
|
|
|
164
178
|
let i = r.map((e) => e.getText()), a = r.findIndex((e) => e.getDotDotDotToken());
|
|
165
179
|
i.splice(a === -1 ? i.length : a, 0, t), n.replaceWithText(`{ ${i.join(", ")} }`);
|
|
166
180
|
}
|
|
167
|
-
function
|
|
181
|
+
function E(e, t, n) {
|
|
168
182
|
let i = RegExp(`(?<![\\w$.])${t}(?![\\w$])`);
|
|
169
183
|
if ((n.replace(/<style[\s\S]*?<\/style>/g, "").match(/\{[^{}]*\}/g) ?? []).some((e) => i.test(e))) return;
|
|
170
|
-
let a =
|
|
184
|
+
let a = C(e), o = w(e), s = o?.getElements().find((e) => e.getName() === t && !e.getPropertyNameNode());
|
|
171
185
|
if (!a || !o || !s || e.getDescendantsOfKind(r.Identifier).some((e) => e.getText() === t && !a.containsRange(e.getPos(), e.getEnd()))) return;
|
|
172
186
|
let c = o.getElements().filter((e) => e !== s).map((e) => e.getText());
|
|
173
187
|
o.replaceWithText(`{ ${c.join(", ")} }`);
|
|
174
188
|
}
|
|
175
|
-
function
|
|
189
|
+
function D(t, n) {
|
|
176
190
|
let i = t.getDescendantsOfKind(r.BindingElement).find((e) => e.getName() === n && !e.getPropertyNameNode() && !e.getDotDotDotToken());
|
|
177
191
|
if (!i) return;
|
|
178
192
|
let a = i.getNameNode();
|
|
@@ -180,25 +194,25 @@ function E(t, n) {
|
|
|
180
194
|
let o = i.getParentIfKindOrThrow(r.ObjectBindingPattern), s = o.getElements().filter((e) => e !== i).map((e) => e.getText()), c = o.getParent();
|
|
181
195
|
s.length === 0 && e.isParameterDeclaration(c) ? c.remove() : s.length === 0 && e.isVariableDeclaration(c) ? c.getVariableStatement()?.remove() : o.replaceWithText(`{ ${s.join(", ")} }`);
|
|
182
196
|
}
|
|
183
|
-
function
|
|
197
|
+
function O(e, t) {
|
|
184
198
|
let n = e.getFunction(t);
|
|
185
199
|
if (n) return n.remove(), { wasRemoved: !0 };
|
|
186
200
|
let r = e.getVariableStatements().flatMap((e) => e.getDeclarations()).find((e) => e.getName() === t);
|
|
187
201
|
return r ? (r.remove(), { wasRemoved: !0 }) : { wasRemoved: !1 };
|
|
188
202
|
}
|
|
189
|
-
function
|
|
190
|
-
let
|
|
203
|
+
function k(e, t, n, i, a) {
|
|
204
|
+
let s = `
|
|
191
205
|
{
|
|
192
206
|
title: '${t}',
|
|
193
207
|
url: '${n}',
|
|
194
208
|
icon: ${i}
|
|
195
209
|
}
|
|
196
|
-
`.trim(), { source: u, result: d } =
|
|
210
|
+
`.trim(), { source: u, result: d } = c(e, (e) => {
|
|
197
211
|
let n = e.getVariableDeclarations().find((e) => e.getName() === "data")?.getInitializer();
|
|
198
212
|
if (!n || n.getKind() !== r.ObjectLiteralExpression) return { wasAdded: !1 };
|
|
199
|
-
let
|
|
200
|
-
if (!
|
|
201
|
-
let u =
|
|
213
|
+
let c = n.asKindOrThrow(r.ObjectLiteralExpression).getProperty("navUser");
|
|
214
|
+
if (!c || c.getKind() !== r.PropertyAssignment) return { wasAdded: !1 };
|
|
215
|
+
let u = c.asKindOrThrow(r.PropertyAssignment).getInitializer();
|
|
202
216
|
if (!u || u.getKind() !== r.ArrayLiteralExpression) return { wasAdded: !1 };
|
|
203
217
|
let d = u.asKindOrThrow(r.ArrayLiteralExpression);
|
|
204
218
|
return d.getElements().some((e) => {
|
|
@@ -207,23 +221,23 @@ function O(e, t, n, i, o) {
|
|
|
207
221
|
if (!n || n.getKind() !== r.PropertyAssignment) return !1;
|
|
208
222
|
let i = n.asKindOrThrow(r.PropertyAssignment).getInitializer();
|
|
209
223
|
return i?.getKind() === r.StringLiteral && i.getLiteralText() === t;
|
|
210
|
-
}) ? { wasAdded: !1 } : (
|
|
224
|
+
}) ? { wasAdded: !1 } : (l(e, [{
|
|
211
225
|
defaultImport: i,
|
|
212
|
-
moduleSpecifier:
|
|
213
|
-
}]), d.addElement(
|
|
226
|
+
moduleSpecifier: a
|
|
227
|
+
}]), d.addElement(s), o(e), { wasAdded: !0 });
|
|
214
228
|
});
|
|
215
229
|
return {
|
|
216
230
|
source: u,
|
|
217
231
|
wasAdded: d.wasAdded
|
|
218
232
|
};
|
|
219
233
|
}
|
|
220
|
-
function
|
|
221
|
-
let { source: i, result:
|
|
234
|
+
function A(e, t, n) {
|
|
235
|
+
let { source: i, result: a } = c(e, (e) => {
|
|
222
236
|
let i = e.getVariableDeclarations().find((e) => e.getName() === "data")?.getInitializer();
|
|
223
237
|
if (!i || i.getKind() !== r.ObjectLiteralExpression) return { wasRemoved: !1 };
|
|
224
|
-
let
|
|
225
|
-
if (!
|
|
226
|
-
let s =
|
|
238
|
+
let a = i.asKindOrThrow(r.ObjectLiteralExpression).getProperty("navUser");
|
|
239
|
+
if (!a || a.getKind() !== r.PropertyAssignment) return { wasRemoved: !1 };
|
|
240
|
+
let s = a.asKindOrThrow(r.PropertyAssignment).getInitializer();
|
|
227
241
|
if (!s || s.getKind() !== r.ArrayLiteralExpression) return { wasRemoved: !1 };
|
|
228
242
|
let c = s.asKindOrThrow(r.ArrayLiteralExpression), l = c.getElements().findIndex((e) => {
|
|
229
243
|
if (e.getKind() !== r.ObjectLiteralExpression) return !1;
|
|
@@ -240,14 +254,14 @@ function k(e, t, n) {
|
|
|
240
254
|
n && e.getDescendantsOfKind(r.Identifier).some((e) => e.getText() === n && e.getParent()?.getKind() !== r.ImportClause && e.getParent()?.getKind() !== r.ImportSpecifier) || t.remove();
|
|
241
255
|
}
|
|
242
256
|
}
|
|
243
|
-
return
|
|
257
|
+
return o(e), { wasRemoved: !0 };
|
|
244
258
|
});
|
|
245
259
|
return {
|
|
246
260
|
source: i,
|
|
247
|
-
wasRemoved:
|
|
261
|
+
wasRemoved: a.wasRemoved
|
|
248
262
|
};
|
|
249
263
|
}
|
|
250
264
|
//#endregion
|
|
251
|
-
export {
|
|
265
|
+
export { c as _, T as a, p as c, f as d, A as f, D as g, O as h, m as i, v as l, y as m, S as n, o, E as p, l as r, x as s, k as t, u };
|
|
252
266
|
|
|
253
|
-
//# sourceMappingURL=ts-morph-helpers-
|
|
267
|
+
//# sourceMappingURL=ts-morph-helpers-CDW4lhox.js.map
|