@velastack/patterns 0.7.0 → 0.8.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 +4 -3
- package/dist/chunks/{_layout-Bsx3eNrC.js → _layout-DQhSAhfF.js} +2 -2
- package/dist/chunks/{_layout-Bsx3eNrC.js.map → _layout-DQhSAhfF.js.map} +1 -1
- package/dist/chunks/{collections-DrUG8ngq.js → collections-BYcVyY9O.js} +2 -2
- package/dist/chunks/{collections-DrUG8ngq.js.map → collections-BYcVyY9O.js.map} +1 -1
- package/dist/chunks/constants-Bdx8mp7v.js +6 -0
- package/dist/chunks/constants-Bdx8mp7v.js.map +1 -0
- package/dist/chunks/{env-vars-CdarYsrc.js → env-vars-0hvKe55u.js} +3 -3
- package/dist/chunks/{env-vars-CdarYsrc.js.map → env-vars-0hvKe55u.js.map} +1 -1
- package/dist/chunks/generate-6JS05dWK.js +79 -0
- package/dist/chunks/generate-6JS05dWK.js.map +1 -0
- package/dist/chunks/generate-BZ741GPx.js +177 -0
- package/dist/chunks/generate-BZ741GPx.js.map +1 -0
- package/dist/chunks/{generate-27CjLiGW.js → generate-CNabcEBx.js} +2 -2
- package/dist/chunks/{generate-27CjLiGW.js.map → generate-CNabcEBx.js.map} +1 -1
- package/dist/chunks/{generate-BFcy2wrS.js → generate-Df7t5Nbk.js} +3 -3
- package/dist/chunks/{generate-BFcy2wrS.js.map → generate-Df7t5Nbk.js.map} +1 -1
- package/dist/chunks/{generate-Cqwa8kD9.js → generate-DoHn_xJZ.js} +2 -2
- package/dist/chunks/{generate-Cqwa8kD9.js.map → generate-DoHn_xJZ.js.map} +1 -1
- package/dist/chunks/{generate-D3mSFPdT.js → generate-l2JZTRKb.js} +2 -2
- package/dist/chunks/{generate-D3mSFPdT.js.map → generate-l2JZTRKb.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DIeAeOJg.js → generate.runtime-B53OTMcE.js} +4 -4
- package/dist/chunks/{generate.runtime-DIeAeOJg.js.map → generate.runtime-B53OTMcE.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BJxM7FNA.js → generate.runtime-B84ymwlD.js} +4 -4
- package/dist/chunks/{generate.runtime-BJxM7FNA.js.map → generate.runtime-B84ymwlD.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DMTAocSE.js → generate.runtime-BC6CBKh6.js} +3 -3
- package/dist/chunks/{generate.runtime-DMTAocSE.js.map → generate.runtime-BC6CBKh6.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cxr15Y5H.js → generate.runtime-BDbotRNZ.js} +6 -6
- package/dist/chunks/{generate.runtime-Cxr15Y5H.js.map → generate.runtime-BDbotRNZ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-9KuMcI5r.js → generate.runtime-BOl3LpPB.js} +3 -3
- package/dist/chunks/{generate.runtime-9KuMcI5r.js.map → generate.runtime-BOl3LpPB.js.map} +1 -1
- package/dist/chunks/{generate.runtime-NxuWvkKt.js → generate.runtime-BP31tAcD.js} +4 -4
- package/dist/chunks/{generate.runtime-NxuWvkKt.js.map → generate.runtime-BP31tAcD.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DlLwmjGF.js → generate.runtime-BoYwV0nt.js} +3 -3
- package/dist/chunks/{generate.runtime-DlLwmjGF.js.map → generate.runtime-BoYwV0nt.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CIZO2XO9.js → generate.runtime-BqCbJ-No.js} +3 -3
- package/dist/chunks/{generate.runtime-CIZO2XO9.js.map → generate.runtime-BqCbJ-No.js.map} +1 -1
- package/dist/chunks/{generate.runtime-ww3-1FWf.js → generate.runtime-Bvjj3zn0.js} +3 -3
- package/dist/chunks/{generate.runtime-ww3-1FWf.js.map → generate.runtime-Bvjj3zn0.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CK0MTeqc.js → generate.runtime-ByPcr9vJ.js} +3 -3
- package/dist/chunks/{generate.runtime-CK0MTeqc.js.map → generate.runtime-ByPcr9vJ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CMO-Skpk.js → generate.runtime-C4LUUuq7.js} +3 -3
- package/dist/chunks/{generate.runtime-CMO-Skpk.js.map → generate.runtime-C4LUUuq7.js.map} +1 -1
- package/dist/chunks/{generate.runtime-dFTOU_KE.js → generate.runtime-C7tlPKH1.js} +4 -4
- package/dist/chunks/{generate.runtime-dFTOU_KE.js.map → generate.runtime-C7tlPKH1.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BdghkfNp.js → generate.runtime-CHUCMVa2.js} +2 -2
- package/dist/chunks/{generate.runtime-BdghkfNp.js.map → generate.runtime-CHUCMVa2.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DtCaz98N.js → generate.runtime-CVWCUn52.js} +4 -4
- package/dist/chunks/{generate.runtime-DtCaz98N.js.map → generate.runtime-CVWCUn52.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B10-KA87.js → generate.runtime-Cj-5fzbQ.js} +4 -4
- package/dist/chunks/{generate.runtime-B10-KA87.js.map → generate.runtime-Cj-5fzbQ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CbT-EbQT.js → generate.runtime-Cv3unKap.js} +3 -3
- package/dist/chunks/{generate.runtime-CbT-EbQT.js.map → generate.runtime-Cv3unKap.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CVDb-yLt.js → generate.runtime-D677SB4v.js} +2 -2
- package/dist/chunks/{generate.runtime-CVDb-yLt.js.map → generate.runtime-D677SB4v.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B_tWu-Bw.js → generate.runtime-DERcpgc-.js} +4 -4
- package/dist/chunks/{generate.runtime-B_tWu-Bw.js.map → generate.runtime-DERcpgc-.js.map} +1 -1
- package/dist/chunks/{generate.runtime-HSZD935T.js → generate.runtime-DJ5uF6EN.js} +2 -2
- package/dist/chunks/{generate.runtime-HSZD935T.js.map → generate.runtime-DJ5uF6EN.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D6vhkGs8.js → generate.runtime-Dfz53sSK.js} +3 -3
- package/dist/chunks/{generate.runtime-D6vhkGs8.js.map → generate.runtime-Dfz53sSK.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BGuXHl5o.js → generate.runtime-DiqfbDfk.js} +2 -2
- package/dist/chunks/{generate.runtime-BGuXHl5o.js.map → generate.runtime-DiqfbDfk.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B8-GLMkk.js → generate.runtime-Dt3Edp8-.js} +86 -75
- package/dist/chunks/generate.runtime-Dt3Edp8-.js.map +1 -0
- package/dist/chunks/{generate.runtime-CEexT8cJ.js → generate.runtime-Du84quuK.js} +5 -5
- package/dist/chunks/{generate.runtime-CEexT8cJ.js.map → generate.runtime-Du84quuK.js.map} +1 -1
- package/dist/chunks/generate.runtime-KrQk7mqG.js +112 -0
- package/dist/chunks/generate.runtime-KrQk7mqG.js.map +1 -0
- package/dist/chunks/{generate.runtime-tGKorg85.js → generate.runtime-T7JLE4Wc.js} +3 -3
- package/dist/chunks/{generate.runtime-tGKorg85.js.map → generate.runtime-T7JLE4Wc.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CbOMXQSo.js → generate.runtime-WPq7bHRA.js} +2 -2
- package/dist/chunks/{generate.runtime-CbOMXQSo.js.map → generate.runtime-WPq7bHRA.js.map} +1 -1
- package/dist/chunks/{generate.runtime-si5Za61F.js → generate.runtime-e_BkDyP0.js} +2 -2
- package/dist/chunks/{generate.runtime-si5Za61F.js.map → generate.runtime-e_BkDyP0.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Blb6QPZn.js → generate.runtime-gZ4wfYBP.js} +6 -6
- package/dist/chunks/{generate.runtime-Blb6QPZn.js.map → generate.runtime-gZ4wfYBP.js.map} +1 -1
- package/dist/chunks/{generate.runtime-m0m43lkL.js → generate.runtime-oUJUQRdg.js} +6 -6
- package/dist/chunks/{generate.runtime-m0m43lkL.js.map → generate.runtime-oUJUQRdg.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BWRtyQeD.js → generate.runtime-q17D7QUT.js} +3 -3
- package/dist/chunks/{generate.runtime-BWRtyQeD.js.map → generate.runtime-q17D7QUT.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CyTxBcX3.js → generate.runtime-rLlDp4R6.js} +4 -4
- package/dist/chunks/{generate.runtime-CyTxBcX3.js.map → generate.runtime-rLlDp4R6.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Nnk5E8Pi.js → generate.runtime-zr6uIHCd.js} +2 -2
- package/dist/chunks/{generate.runtime-Nnk5E8Pi.js.map → generate.runtime-zr6uIHCd.js.map} +1 -1
- package/dist/chunks/{modify-file-COBp4eCh.js → modify-file-B4uJzOEj.js} +2 -2
- package/dist/chunks/{modify-file-COBp4eCh.js.map → modify-file-B4uJzOEj.js.map} +1 -1
- package/dist/chunks/{package-imports-Dx05A-4S.js → package-imports-B9Asv3ZH.js} +2 -2
- package/dist/chunks/{package-imports-Dx05A-4S.js.map → package-imports-B9Asv3ZH.js.map} +1 -1
- package/dist/chunks/{pocketbase-DL02rq73.js → pocketbase-BtN-wL8f.js} +6 -6
- package/dist/chunks/{pocketbase-DL02rq73.js.map → pocketbase-BtN-wL8f.js.map} +1 -1
- package/dist/chunks/{providers-CAehyySB.js → providers-DRwJnSzb.js} +2 -2
- package/dist/chunks/{providers-CAehyySB.js.map → providers-DRwJnSzb.js.map} +1 -1
- package/dist/chunks/root-layout.svelte-CsJ2QJYi.js +93 -0
- package/dist/chunks/root-layout.svelte-CsJ2QJYi.js.map +1 -0
- package/dist/chunks/{shared-C_Fr8wph.js → shared-BbxLil4g.js} +2 -2
- package/dist/chunks/{shared-C_Fr8wph.js.map → shared-BbxLil4g.js.map} +1 -1
- package/dist/chunks/site-VrqOvuiU.js +149 -0
- package/dist/chunks/site-VrqOvuiU.js.map +1 -0
- package/dist/chunks/{table-core-BPv_RYgD.js → table-core-BHFT-uMX.js} +2 -2
- package/dist/chunks/{table-core-BPv_RYgD.js.map → table-core-BHFT-uMX.js.map} +1 -1
- package/dist/chunks/{test-setup-pYUIfWb2.js → test-setup-BVJwm22s.js} +3 -3
- package/dist/chunks/{test-setup-pYUIfWb2.js.map → test-setup-BVJwm22s.js.map} +1 -1
- package/dist/chunks/{ui-B2yn8c_-.js → ui-gG8i_Mzk.js} +3 -3
- package/dist/chunks/{ui-B2yn8c_-.js.map → ui-gG8i_Mzk.js.map} +1 -1
- package/dist/chunks/{whatsapp-5qJ_xCV1.js → whatsapp-DbjOxHaZ.js} +2 -2
- package/dist/chunks/{whatsapp-5qJ_xCV1.js.map → whatsapp-DbjOxHaZ.js.map} +1 -1
- package/dist/chunks/write-result-DcqMefuP.js +499 -0
- package/dist/chunks/write-result-DcqMefuP.js.map +1 -0
- package/dist/index.d.ts +11 -18
- package/dist/index.js +2144 -2141
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/constants-iej3WkEa.js +0 -6
- package/dist/chunks/constants-iej3WkEa.js.map +0 -1
- package/dist/chunks/generate-BxOzEdc_.js +0 -171
- package/dist/chunks/generate-BxOzEdc_.js.map +0 -1
- package/dist/chunks/generate-DdLwP0E7.js +0 -76
- package/dist/chunks/generate-DdLwP0E7.js.map +0 -1
- package/dist/chunks/generate.runtime-B8-GLMkk.js.map +0 -1
- package/dist/chunks/generate.runtime-D5HxAups.js +0 -109
- package/dist/chunks/generate.runtime-D5HxAups.js.map +0 -1
- package/dist/chunks/site-BoujshKo.js +0 -108
- package/dist/chunks/site-BoujshKo.js.map +0 -1
- package/dist/chunks/write-result-Bn4bnrBI.js +0 -481
- package/dist/chunks/write-result-Bn4bnrBI.js.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { o as e } from "./generate-
|
|
1
|
+
import { o as e } from "./generate-l2JZTRKb.js";
|
|
2
2
|
import { n as t } from "./logger-CQONztPm.js";
|
|
3
|
-
import { n } from "./shared-
|
|
4
|
-
import { n as r, r as i, t as a } from "./generate-
|
|
3
|
+
import { n } from "./shared-BbxLil4g.js";
|
|
4
|
+
import { n as r, r as i, t as a } from "./generate-Df7t5Nbk.js";
|
|
5
5
|
import { n as o } from "./env-BugddEjd.js";
|
|
6
|
-
import { t as s } from "./modify-file-
|
|
7
|
-
import { unmodifyEnvVarsFiles as c } from "./env-vars-
|
|
6
|
+
import { t as s } from "./modify-file-B4uJzOEj.js";
|
|
7
|
+
import { unmodifyEnvVarsFiles as c } from "./env-vars-0hvKe55u.js";
|
|
8
8
|
import l from "node:fs";
|
|
9
9
|
import u from "node:path";
|
|
10
10
|
//#region src/patterns/disable/ai/generate.runtime.ts
|
|
@@ -32,4 +32,4 @@ async function d(d) {
|
|
|
32
32
|
//#endregion
|
|
33
33
|
export { d as generate };
|
|
34
34
|
|
|
35
|
-
//# sourceMappingURL=generate.runtime-
|
|
35
|
+
//# sourceMappingURL=generate.runtime-oUJUQRdg.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-oUJUQRdg.js","names":["demoDir","getLogger","allEnvNames","demoDirs","allEnvEdits","modifyEnvRemove","envRevertOutcomeToFile","fs","path","generate","logger","options","modifies","deletes","current","dir","page","toDeleteEntry","envVars","unmodifyEnvVarsFiles","envPath","env"],"sources":["../../src/patterns/disable/ai/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyEnvRemove } from \"../../../runtime/env\";\nimport { envRevertOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { toDeleteEntry } from \"../../destroy/shared\";\nimport { demoDir } from \"../../enable/ai/generate\";\nimport { allEnvEdits, allEnvNames, demoDirs } from \"./generate\";\nimport { unmodifyEnvVarsFiles } from \"../../../runtime/env-vars\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const deletes: File[] = [];\n\n // The base result names the page in the current default group; a page\n // generated before auth was enabled sits in the other one.\n const current = demoDir(options);\n for (const dir of demoDirs(options)) {\n const page = `${dir}/+page.svelte`;\n if (dir !== current && fs.existsSync(path.join(options.root, page))) {\n deletes.push(toDeleteEntry(page));\n }\n }\n\n // Which provider was chosen is not recorded, so every one's key goes; the\n // file goes too when these were all it declared.\n logger.info(\"Removing the AI provider's API key from src/env.ts\");\n const envVars = unmodifyEnvVarsFiles(options.root, allEnvNames());\n if (envVars.modify) modifies.push(envVars.modify);\n if (envVars.delete) deletes.push(envVars.delete);\n\n logger.info(\"Removing the AI provider's API key from .env\");\n const envPath = path.join(options.root, \".env\");\n const env = envRevertOutcomeToFile(\n envPath,\n modifyEnvRemove(envPath, allEnvEdits()),\n );\n if (env.modify) modifies.push(env.modify);\n if (env.delete) deletes.push(env.delete);\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":";;;;;;;;;;AAWA,eAAsBS,EAAS,GAAkB;CAC/C,IAAMC,IAAST,EAAUU,CAAO,GAC1BC,IAAmB,CAAC,GACpBC,IAAkB,CAAC,GAInBC,IAAUd,EAAQW,CAAO;CAC/B,KAAK,IAAMI,KAAOZ,EAASQ,CAAO,GAAG;EACnC,IAAMK,IAAO,GAAGD,EAAI;EACpB,AAAIA,MAAQD,KAAWP,EAAG,WAAWC,EAAK,KAAKG,EAAQ,MAAMK,CAAI,CAAC,KAChEH,EAAQ,KAAKI,EAAcD,CAAI,CAAC;CAEpC;CAIA,EAAO,KAAK,oDAAoD;CAChE,IAAME,IAAUC,EAAqBR,EAAQ,MAAMT,EAAY,CAAC;CAIhE,AAHIgB,EAAQ,UAAQN,EAAS,KAAKM,EAAQ,MAAM,GAC5CA,EAAQ,UAAQL,EAAQ,KAAKK,EAAQ,MAAM,GAE/CR,EAAO,KAAK,8CAA8C;CAC1D,IAAMU,IAAUZ,EAAK,KAAKG,EAAQ,MAAM,MAAM,GACxCU,IAAMf,EACVc,GACAf,EAAgBe,GAAShB,EAAY,CAAC,CACxC;CAIA,OAHIiB,EAAI,UAAQT,EAAS,KAAKS,EAAI,MAAM,GACpCA,EAAI,UAAQR,EAAQ,KAAKQ,EAAI,MAAM,GAEhC;EACL,SAAS,CAAC;EACV;EACA;EACA,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { r as e } from "./lib-specifier-Cngo1zF_.js";
|
|
2
2
|
import { n as t } from "./logger-CQONztPm.js";
|
|
3
|
-
import { t as n } from "./shared-
|
|
3
|
+
import { t as n } from "./shared-BbxLil4g.js";
|
|
4
4
|
import { _ as r, n as i, u as a } from "./ts-morph-helpers-CHI9wAil.js";
|
|
5
|
-
import { r as o } from "./modify-file-
|
|
5
|
+
import { r as o } from "./modify-file-B4uJzOEj.js";
|
|
6
6
|
import { t as s } from "./svelte-file-Dv5-bl79.js";
|
|
7
7
|
import { t as c } from "./unmodify-load-Buak-r1f.js";
|
|
8
8
|
import l from "node:fs";
|
|
@@ -64,4 +64,4 @@ async function p(e) {
|
|
|
64
64
|
//#endregion
|
|
65
65
|
export { p as generate };
|
|
66
66
|
|
|
67
|
-
//# sourceMappingURL=generate.runtime-
|
|
67
|
+
//# sourceMappingURL=generate.runtime-q17D7QUT.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-q17D7QUT.js","names":["libModule","getLogger","planDropsForCollections","withInMemoryScript","ensureBlankLineAfterImports","removeImportByModuleSpecifier","modifyOutcomeToFile","SvelteFile","removeFromLoad","fs","path","unmodifyAppLayout","layoutPath","original","file","out","source","sf","updated","unmodifyLayoutServer","layoutServerPath","generate","logger","options","modifies","pushResult","appLayoutPath","appLayoutServerPath"],"sources":["../../src/patterns/disable/notifications/modifies/modify-app-layout.ts","../../src/patterns/disable/notifications/modifies/+layout.server.ts","../../src/patterns/disable/notifications/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\n\n/** Take the bell (and the wrapper enable-notifications put it in) out of the header. */\nexport function unmodifyAppLayout(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutPath, \"utf8\");\n if (!original.includes(\"NotificationsBell\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n removeImportByModuleSpecifier(\n sf,\n libModule(\"components/notifications-bell.svelte\"),\n );\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n let updated = file.toString();\n updated = updated.replace(\n /\\n*[ \\t]*<div class=\"ml-auto px-4\">\\s*<NotificationsBell\\s*\\/>\\s*<\\/div>[ \\t]*/g,\n \"\",\n );\n updated = updated.replace(/[ \\t]*<NotificationsBell\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n\n fs.writeFileSync(layoutPath, updated, \"utf8\");\n return { status: \"success\", changed: updated !== original };\n}\n","import type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeFromLoad } from \"../../../../runtime/unmodify-load\";\n\n/** Take the unread-notifications query back out of the (app) layout's load. */\nexport function unmodifyLayoutServer(layoutServerPath: string): ModifyOutcome {\n return removeFromLoad(layoutServerPath, {\n variables: [\"notificationsList\", \"notifications\"],\n dependsKeys: [\"app:notifications\"],\n returnProps: [\"notifications\"],\n });\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 { planDropsForCollections } from \"../../destroy/shared\";\nimport { unmodifyAppLayout } from \"./modifies/modify-app-layout\";\nimport { unmodifyLayoutServer } from \"./modifies/+layout.server\";\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 (app) +layout.svelte\");\n const appLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appLayoutPath, unmodifyAppLayout(appLayoutPath)),\n );\n\n logger.info(\"Reverting (app) +layout.server.ts\");\n const appLayoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutServerPath,\n unmodifyLayoutServer(appLayoutServerPath),\n ),\n );\n\n // The timeAgo helper enable-notifications added to #lib/utils.js stays: it is\n // generic, and other code may have started using it.\n\n const collectionDrops = await planDropsForCollections(\n [\"notifications\"],\n options,\n );\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":";;;;;;;;;;AAWA,SAAgBW,EAAkB,GAAmC;CACnE,IAAI,CAACF,EAAG,WAAWG,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAWJ,EAAG,aAAaG,GAAY,MAAM;CACnD,IAAI,CAACC,EAAS,SAAS,mBAAmB,GACxC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAOP,EAAW,SAASK,CAAU;CAC3C,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQG,MAAQZ,EAAmBa,IAAS,MAAO;GAKzD,AAJAX,EACEY,GACAjB,EAAU,sCAAsC,CAClD,GACAI,EAA4Ba,CAAE;EAChC,CAAC;EACD,OAAOF;CACT,CAAC;CAED,IAAIG,IAAUJ,EAAK,SAAS;CAQ5B,OAPA,IAAUI,EAAQ,QAChB,mFACA,EACF,GACA,IAAUA,EAAQ,QAAQ,+CAA+C,EAAE,GAE3ET,EAAG,cAAcG,GAAYM,GAAS,MAAM,GACrC;EAAE,QAAQ;EAAW,SAASA,MAAYL;CAAS;AAC5D;;;ACtCA,SAAgBM,EAAqB,GAAyC;CAC5E,OAAOX,EAAeY,GAAkB;EACtC,WAAW,CAAC,qBAAqB,eAAe;EAChD,aAAa,CAAC,mBAAmB;EACjC,aAAa,CAAC,eAAe;CAC/B,CAAC;AACH;;;ACFA,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASrB,EAAUsB,CAAO,GAC1BC,IAAmB,CAAC,GACpBC,KAAc,MAAsB;EACxC,AAAIX,KAAMU,EAAS,KAAKV,CAAI;CAC9B;CAEA,EAAO,KAAK,gCAAgC;CAC5C,IAAMY,IAAgBhB,EAAK,KACzBa,EAAQ,MACR,OACA,UACA,SACA,gBACF;CAKA,AAJAE,EACEnB,EAAoBoB,GAAef,EAAkBe,CAAa,CAAC,CACrE,GAEAJ,EAAO,KAAK,mCAAmC;CAC/C,IAAMK,IAAsBjB,EAAK,KAC/Ba,EAAQ,MACR,OACA,UACA,SACA,mBACF;CAgBA,OAfAE,EACEnB,EACEqB,GACAR,EAAqBQ,CAAmB,CAC1C,CACF,GAUO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MAb4BzB,EAC5B,CAAC,eAAe,GAChBqB,CACF;CAWA;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as e } from "./logger-CQONztPm.js";
|
|
2
|
-
import { i as t, n } from "./pocketbase-
|
|
3
|
-
import { r } from "./modify-file-
|
|
4
|
-
import { i, n as a, o } from "./whatsapp-
|
|
2
|
+
import { i as t, n } from "./pocketbase-BtN-wL8f.js";
|
|
3
|
+
import { r } from "./modify-file-B4uJzOEj.js";
|
|
4
|
+
import { i, n as a, o } from "./whatsapp-DbjOxHaZ.js";
|
|
5
5
|
import { swapAuthPages as s } from "./auth-pages-jsyDV1GR.js";
|
|
6
6
|
import c from "node:fs";
|
|
7
7
|
import l from "node:path";
|
|
@@ -39,4 +39,4 @@ async function d(d) {
|
|
|
39
39
|
//#endregion
|
|
40
40
|
export { d as generate };
|
|
41
41
|
|
|
42
|
-
//# sourceMappingURL=generate.runtime-
|
|
42
|
+
//# sourceMappingURL=generate.runtime-rLlDp4R6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-rLlDp4R6.js","names":["getLogger","withPocketbase","disableWhatsAppAuth","fs","path","DOCS_URL","generate","logger","options","creates","hasWhatsAppPlugin","pb","migrationDelay","file","writeWhatsAppConfigMigration","modifies","outcomes","swapAuthPages","filePath","outcome","modifyOutcomeToFile"],"sources":["../../src/patterns/disable/whatsapp/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { migrationDelay, withPocketbase } from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n disableWhatsAppAuth,\n hasWhatsAppPlugin,\n writeWhatsAppConfigMigration,\n} from \"../../enable/whatsapp/runtime/whatsapp\";\nimport { swapAuthPages } from \"../../enable/whatsapp/modifies/auth-pages\";\n\nconst DOCS_URL = \"https://velastack.dev/docs/disable/whatsapp\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n\n await withPocketbase(options.root, async (pb) => {\n // Without the plugin there is no WhatsApp sign-in to turn off.\n if (!(await hasWhatsAppPlugin(pb))) return;\n\n logger.info(\"Turning off WhatsApp sign-in for users\");\n await disableWhatsAppAuth(pb);\n await migrationDelay();\n const file = writeWhatsAppConfigMigration(options, false);\n if (!file) return;\n creates.push({\n path: file,\n language: \"js\",\n content: fs.readFileSync(file, \"utf8\"),\n status: \"success\",\n });\n });\n logger.info(\n \"Keeping the phone fields on users, and email optional: they hold your users' data\",\n );\n\n logger.info(\"Taking WhatsApp off the login and signup pages\");\n const modifies: File[] = [];\n const outcomes = await swapAuthPages(\n options.root,\n \"disable\",\n (filePath) =>\n `${path.relative(options.root, filePath)} is not the page enable-whatsapp wrote, so it was left as it is. Take the WhatsApp option out of it by hand: ${DOCS_URL}`,\n );\n for (const [filePath, outcome] of outcomes) {\n const file = modifyOutcomeToFile(filePath, outcome);\n if (file) modifies.push(file);\n }\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":";;;;;;;;AAaA,IAAMK,IAAW;AAEjB,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASP,EAAUQ,CAAO,GAC1BC,IAAkB,CAAC;CAsBzB,AApBA,MAAMR,EAAeO,EAAQ,MAAM,OAAO,MAAO;EAE/C,IAAI,CAAE,MAAME,EAAkBC,CAAE,GAAI;EAIpC,AAFAJ,EAAO,KAAK,wCAAwC,GACpD,MAAML,EAAoBS,CAAE,GAC5B,MAAMC,EAAe;EACrB,IAAMC,IAAOC,EAA6BN,GAAS,EAAK;EACxD,AAAKK,KACLJ,EAAQ,KAAK;GACX,MAAMI;GACN,UAAU;GACV,SAASV,EAAG,aAAaU,GAAM,MAAM;GACrC,QAAQ;EACV,CAAC;CACH,CAAC,GACDN,EAAO,KACL,mFACF,GAEAA,EAAO,KAAK,gDAAgD;CAC5D,IAAMQ,IAAmB,CAAC,GACpBC,IAAW,MAAMC,EACrBT,EAAQ,MACR,YACC,MACC,GAAGJ,EAAK,SAASI,EAAQ,MAAMU,CAAQ,EAAE,+GAA+Gb,GAC5J;CACA,KAAK,IAAM,CAACa,GAAUC,MAAYH,GAAU;EAC1C,IAAMH,IAAOO,EAAoBF,GAAUC,CAAO;EAClD,AAAIN,KAAME,EAAS,KAAKF,CAAI;CAC9B;CAEA,OAAO;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as e } from "./logger-CQONztPm.js";
|
|
2
2
|
import { o as t } from "./ts-morph-helpers-CHI9wAil.js";
|
|
3
|
-
import { r as n } from "./modify-file-
|
|
3
|
+
import { r as n } from "./modify-file-B4uJzOEj.js";
|
|
4
4
|
import r from "node:fs";
|
|
5
5
|
import i from "node:path";
|
|
6
6
|
import { Project as a, SyntaxKind as o } from "ts-morph";
|
|
@@ -54,4 +54,4 @@ async function c(t) {
|
|
|
54
54
|
//#endregion
|
|
55
55
|
export { c as generate };
|
|
56
56
|
|
|
57
|
-
//# sourceMappingURL=generate.runtime-
|
|
57
|
+
//# sourceMappingURL=generate.runtime-zr6uIHCd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-zr6uIHCd.js","names":["getLogger","formatLikeSource","modifyOutcomeToFile","fs","path","unmodifyHooksServer","hooksServerPath","originalSource","sourceFile","Project","callExpr","SyntaxKind","ce","args","firstArg","optionsObj","apiProp","generate","logger","options","modifies","file"],"sources":["../../src/patterns/disable/api/modifies/hooks.server.ts","../../src/patterns/disable/api/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\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\n if (!callExpr) {\n return { status: \"success\", changed: false };\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n return { status: \"success\", changed: false };\n }\n\n const firstArg = args[0];\n if (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) {\n return { status: \"success\", changed: false };\n }\n\n apiProp.remove();\n\n if (optionsObj.getProperties().length === 0) {\n callExpr.removeArgument(0);\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\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\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const file = modifyOutcomeToFile(\n hooksServerPath,\n unmodifyHooksServer(hooksServerPath),\n );\n if (file) modifies.push(file);\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":";;;;;;;AAKA,SAAgBK,EAAoB,GAAwC;CAC1E,IAAI,CAACF,EAAG,WAAWG,CAAe,GAChC,OAAO;EA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AAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as e } from "./rolldown-runtime-5HNE8Q1r.js";
|
|
2
2
|
import { a as t } from "./util-BLYliuUK.js";
|
|
3
|
-
import { n } from "./shared-
|
|
3
|
+
import { n } from "./shared-BbxLil4g.js";
|
|
4
4
|
import { _ as r, s as i } from "./ts-morph-helpers-CHI9wAil.js";
|
|
5
5
|
import a from "node:fs";
|
|
6
6
|
import o from "node:path";
|
|
@@ -50,4 +50,4 @@ function d(e, t) {
|
|
|
50
50
|
//#endregion
|
|
51
51
|
export { l as a, s as i, d as n, c as r, u as t };
|
|
52
52
|
|
|
53
|
-
//# sourceMappingURL=modify-file-
|
|
53
|
+
//# sourceMappingURL=modify-file-B4uJzOEj.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modify-file-
|
|
1
|
+
{"version":3,"file":"modify-file-B4uJzOEj.js","names":["__exportAll","languageFromPath","withInMemoryScript","isEffectivelyEmpty","fs","path","modify_file_exports","envRevertOutcomeToFile","keepMissing","modifyOutcomeToFile","revertOutcomeToFile","language","filePath","outcome","toDeleteEntry","envPath","creates","root","file"],"sources":["../../src/runtime/modify-file.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, ModifyOutcome } from \"../core/types\";\nimport { languageFromPath } from \"../core/util\";\nimport { toDeleteEntry } from \"../patterns/destroy/shared\";\nimport { isEffectivelyEmpty, withInMemoryScript } from \"./ts-morph-helpers\";\n\nexport function modifyOutcomeToFile(\n filePath: string,\n outcome: ModifyOutcome,\n): File | null {\n const language = languageFromPath(filePath);\n\n if (outcome.status === \"success\") {\n if (!outcome.changed) return null;\n return {\n path: filePath,\n language,\n content: fs.readFileSync(filePath, \"utf8\"),\n status: \"success\",\n };\n }\n\n const content =\n outcome.status === \"failed\" && fs.existsSync(filePath)\n ? fs.readFileSync(filePath, \"utf8\")\n : \"\";\n\n return {\n path: filePath,\n language,\n content,\n status: outcome.status,\n message: outcome.message,\n };\n}\n\n/**\n * `modifyOutcomeToFile` for a revert that may have taken out everything the\n * file held: a script left with no statements, only comments and whitespace,\n * is reported as a delete. For hooks files a pattern created, or that ended\n * up holding nothing but what patterns put there.\n */\nexport function revertOutcomeToFile(\n filePath: string,\n outcome: ModifyOutcome,\n): { modify: File | null; delete: File | null } {\n if (\n outcome.status === \"success\" &&\n outcome.changed &&\n fs.existsSync(filePath) &&\n withInMemoryScript(fs.readFileSync(filePath, \"utf8\"), isEffectivelyEmpty)\n .result\n ) {\n return { modify: null, delete: toDeleteEntry(filePath) };\n }\n return { modify: modifyOutcomeToFile(filePath, outcome), delete: null };\n}\n\n/**\n * `modifyOutcomeToFile` for a `.env` revert: a file the revert left empty is\n * reported as a delete. The enable pattern most likely created it, and an\n * empty `.env` holds nothing worth keeping.\n */\nexport function envRevertOutcomeToFile(\n envPath: string,\n outcome: ModifyOutcome,\n): { modify: File | null; delete: File | null } {\n if (\n outcome.status === \"success\" &&\n outcome.changed &&\n fs.existsSync(envPath) &&\n fs.readFileSync(envPath, \"utf8\").trim() === \"\"\n ) {\n return { modify: null, delete: toDeleteEntry(envPath) };\n }\n return { modify: modifyOutcomeToFile(envPath, outcome), delete: null };\n}\n\n/**\n * Drop any create that already exists on disk.\n *\n * `writeResult` overwrites an existing create whose content differs and\n * reports it as a modify, which would mean a re-run silently resetting a\n * developer's edits, or a create clobbering a file other patterns have\n * already written to. The file is theirs once it exists; a pattern that has\n * something to add to it does so with a modifier.\n */\nexport function keepMissing(creates: File[], root: string): File[] {\n return creates.filter((file) => !fs.existsSync(path.join(root, file.path)));\n}\n"],"mappings":";;;;;;;;;;;;;AAOA,SAAgBS,EACd,GACA,GACa;CACb,IAAME,IAAWV,EAAiBW,CAAQ;CAiB1C,OAfIC,EAAQ,WAAW,YAChBA,EAAQ,UACN;EACL,MAAMD;EACN;EACA,SAASR,EAAG,aAAaQ,GAAU,MAAM;EACzC,QAAQ;CACV,IAN6B,OAcxB;EACL,MAAMA;EACN;EACA,SAPAC,EAAQ,WAAW,YAAYT,EAAG,WAAWQ,CAAQ,IACjDR,EAAG,aAAaQ,GAAU,MAAM,IAChC;EAMJ,QAAQC,EAAQ;EAChB,SAASA,EAAQ;CACnB;AACF;AAQA,SAAgBH,EACd,GACA,GAC8C;CAU9C,OAREG,EAAQ,WAAW,aACnBA,EAAQ,WACRT,EAAG,WAAWQ,CAAQ,KACtBV,EAAmBE,EAAG,aAAaQ,GAAU,MAAM,GAAGT,CAAkB,CAAC,CACtE,SAEI;EAAE,QAAQ;EAAM,QAAQW,EAAcF,CAAQ;CAAE,IAElD;EAAE,QAAQH,EAAoBG,GAAUC,CAAO;EAAG,QAAQ;CAAK;AACxE;AAOA,SAAgBN,EACd,GACA,GAC8C;CAS9C,OAPEM,EAAQ,WAAW,aACnBA,EAAQ,WACRT,EAAG,WAAWW,CAAO,KACrBX,EAAG,aAAaW,GAAS,MAAM,CAAC,CAAC,KAAK,MAAM,KAErC;EAAE,QAAQ;EAAM,QAAQD,EAAcC,CAAO;CAAE,IAEjD;EAAE,QAAQN,EAAoBM,GAASF,CAAO;EAAG,QAAQ;CAAK;AACvE;AAWA,SAAgBL,EAAY,GAAiB,GAAsB;CACjE,OAAOQ,EAAQ,QAAQ,MAAS,CAACZ,EAAG,WAAWC,EAAK,KAAKY,GAAMC,EAAK,IAAI,CAAC,CAAC;AAC5E"}
|
|
@@ -168,6 +168,6 @@ function f(e, t, n, r) {
|
|
|
168
168
|
return a;
|
|
169
169
|
}
|
|
170
170
|
//#endregion
|
|
171
|
-
export {
|
|
171
|
+
export { r as n, u as r, l as t };
|
|
172
172
|
|
|
173
|
-
//# sourceMappingURL=package-imports-
|
|
173
|
+
//# sourceMappingURL=package-imports-B9Asv3ZH.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-imports-Dx05A-4S.js","names":["__exportAll","fs","path","package_imports_exports","ensurePackageImports","ensurePackageOverrides","removePackageImports","isObject","value","readPackage","filePath","root","text","pkg","indent","eol","trailing","writePackage","next","file","insertKey","anchor","after","name","key","existing","finish","outcome","conflicts","field","line","current","entries","imports","keys","expected","_","rest","overrides","merged","mergeOverrides","out","target","wanted","source","have","where","trail"],"sources":["../../src/runtime/package-imports.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { ModifyOutcome } from \"../core/types\";\n\n/**\n * Edits to the project's `package.json` that npm has no command for: the\n * `imports` map SvelteKit 3 resolves `#lib` (and `#locales`) through, and\n * `overrides`. The file is rewritten with the indentation and trailing\n * newline it had, and a key that already holds a different value is never\n * overwritten: it is the project's, and the outcome says what to change.\n */\n\nexport interface PackageJsonEditResult {\n filePath: string;\n outcome: ModifyOutcome;\n}\n\ntype Json = string | number | boolean | null | Json[] | { [key: string]: Json };\ntype JsonObject = { [key: string]: Json };\n\n/** An `overrides` value: a version, or nested overrides (npm's `\".\"` is the package itself). */\nexport type OverrideValue = string | { [key: string]: OverrideValue };\n\ninterface PackageFile {\n filePath: string;\n text: string;\n pkg: JsonObject;\n indent: string;\n eol: string;\n trailing: string;\n}\n\nfunction isObject(value: unknown): value is JsonObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction readPackage(root: string): PackageFile | PackageJsonEditResult {\n const filePath = path.join(root, \"package.json\");\n if (!fs.existsSync(filePath)) {\n return {\n filePath,\n outcome: { status: \"not-found\", message: \"No package.json to edit.\" },\n };\n }\n const text = fs.readFileSync(filePath, \"utf8\");\n let pkg: unknown;\n try {\n pkg = JSON.parse(text);\n } catch {\n return {\n filePath,\n outcome: { status: \"failed\", message: \"package.json is not valid JSON.\" },\n };\n }\n if (!isObject(pkg)) {\n return {\n filePath,\n outcome: { status: \"failed\", message: \"package.json is not an object.\" },\n };\n }\n const indent = text.match(/^[{[][^\\S\\n]*\\r?\\n([\\t ]+)\\S/)?.[1] ?? \"\\t\";\n const eol = text.includes(\"\\r\\n\") ? \"\\r\\n\" : \"\\n\";\n const trailing = text.match(/(\\r?\\n)*$/)?.[0] ?? \"\";\n return { filePath, text, pkg, indent, eol, trailing };\n}\n\nfunction writePackage(file: PackageFile): ModifyOutcome {\n const body = JSON.stringify(file.pkg, null, file.indent).replace(\n /\\n/g,\n file.eol,\n );\n const next = body + file.trailing;\n if (next === file.text) return { status: \"success\", changed: false };\n fs.writeFileSync(file.filePath, next, \"utf8\");\n return { status: \"success\", changed: true };\n}\n\n/**\n * Add `key` to `pkg` right after the first of `after` it has, else at the end.\n * JSON object key order is insertion order, so this rebuilds the object.\n */\nfunction insertKey(\n pkg: JsonObject,\n key: string,\n value: Json,\n after: string[],\n): JsonObject {\n const anchor = after.find((name) => name in pkg);\n if (!anchor) return { ...pkg, [key]: value };\n const next: JsonObject = {};\n for (const [name, existing] of Object.entries(pkg)) {\n next[name] = existing;\n if (name === anchor) next[key] = value;\n }\n return next;\n}\n\nfunction finish(\n file: PackageFile,\n conflicts: string[],\n field: string,\n): PackageJsonEditResult {\n const outcome = writePackage(file);\n if (conflicts.length === 0) return { filePath: file.filePath, outcome };\n return {\n filePath: file.filePath,\n outcome: {\n status: \"failed\",\n message: [\n `package.json \\`${field}\\` already has a different value for:`,\n ...conflicts.map((line) => ` ${line}`),\n \"Change these by hand if vela's value is the one you want.\",\n ].join(\"\\n\"),\n },\n };\n}\n\n/**\n * Add the subpath `imports` (`{ \"#lib/*\": \"./src/lib/*\" }`) that are missing.\n * Creates `imports` after `type` when the project has none.\n */\nexport function ensurePackageImports(\n root: string,\n entries: Record<string, string>,\n): PackageJsonEditResult {\n const file = readPackage(root);\n if (!(\"pkg\" in file)) return file;\n\n const current = file.pkg.imports;\n if (current !== undefined && !isObject(current)) {\n return {\n filePath: file.filePath,\n outcome: {\n status: \"failed\",\n message: [\n \"package.json `imports` is not an object. Add these entries to it by hand:\",\n ...Object.entries(entries).map(\n ([key, value]) =>\n ` ${JSON.stringify(key)}: ${JSON.stringify(value)}`,\n ),\n ].join(\"\\n\"),\n },\n };\n }\n\n const imports: JsonObject = { ...(current ?? {}) };\n const conflicts: string[] = [];\n for (const [key, value] of Object.entries(entries)) {\n if (!(key in imports)) {\n imports[key] = value;\n } else if (imports[key] !== value) {\n conflicts.push(\n `${JSON.stringify(key)}: ${JSON.stringify(imports[key])} (vela uses ${JSON.stringify(value)})`,\n );\n }\n }\n file.pkg =\n current === undefined\n ? Object.keys(imports).length > 0\n ? insertKey(file.pkg, \"imports\", imports, [\"type\", \"version\", \"name\"])\n : file.pkg\n : { ...file.pkg, imports };\n return finish(file, conflicts, \"imports\");\n}\n\n/**\n * Remove subpath `imports` keys. With `expected`, a key is removed only while\n * it still maps to the value vela wrote, so one the developer repointed stays.\n * An `imports` left empty is removed too.\n */\nexport function removePackageImports(\n root: string,\n keys: string[],\n expected?: Record<string, string>,\n): PackageJsonEditResult {\n const file = readPackage(root);\n if (!(\"pkg\" in file)) {\n // Nothing to revert in a project without a package.json.\n return file.outcome.status === \"not-found\"\n ? {\n filePath: file.filePath,\n outcome: { status: \"success\", changed: false },\n }\n : file;\n }\n const current = file.pkg.imports;\n if (!isObject(current)) {\n return {\n filePath: file.filePath,\n outcome: { status: \"success\", changed: false },\n };\n }\n const imports: JsonObject = { ...current };\n for (const key of keys) {\n if (!(key in imports)) continue;\n if (expected && key in expected && imports[key] !== expected[key]) continue;\n delete imports[key];\n }\n if (Object.keys(imports).length === 0) {\n const { imports: _, ...rest } = file.pkg;\n file.pkg = rest;\n } else {\n file.pkg = { ...file.pkg, imports };\n }\n return { filePath: file.filePath, outcome: writePackage(file) };\n}\n\n/**\n * Deep-merge `overrides` into package.json's `overrides`, created at the end\n * when missing. A version already there that differs is left as it is and\n * reported. A package overridden with a bare version that now needs nested\n * overrides keeps that version as npm's `\".\"`.\n */\nexport function ensurePackageOverrides(\n root: string,\n overrides: Record<string, OverrideValue>,\n): PackageJsonEditResult {\n const file = readPackage(root);\n if (!(\"pkg\" in file)) return file;\n\n const current = file.pkg.overrides;\n if (current !== undefined && !isObject(current)) {\n return {\n filePath: file.filePath,\n outcome: {\n status: \"failed\",\n message: `package.json \\`overrides\\` is not an object. Add this to it by hand:\\n${JSON.stringify(overrides, null, 2)}`,\n },\n };\n }\n const conflicts: string[] = [];\n const merged = mergeOverrides(current ?? {}, overrides, [], conflicts);\n file.pkg = { ...file.pkg, overrides: merged };\n return finish(file, conflicts, \"overrides\");\n}\n\nfunction mergeOverrides(\n target: JsonObject,\n source: Record<string, OverrideValue>,\n trail: string[],\n conflicts: string[],\n): JsonObject {\n const out: JsonObject = { ...target };\n for (const [key, wanted] of Object.entries(source)) {\n const have = out[key];\n const where = [...trail, key].join(\" > \");\n if (have === undefined) {\n out[key] = wanted as Json;\n } else if (typeof wanted === \"string\") {\n if (have === wanted) continue;\n if (isObject(have) && have[\".\"] === wanted) continue;\n conflicts.push(\n `${where}: ${JSON.stringify(have)} (vela uses ${JSON.stringify(wanted)})`,\n );\n } else if (isObject(have)) {\n out[key] = mergeOverrides(have, wanted, [...trail, key], conflicts);\n } else if (typeof have === \"string\") {\n out[key] = mergeOverrides(\n { \".\": have },\n wanted,\n [...trail, key],\n conflicts,\n );\n } else {\n conflicts.push(\n `${where}: ${JSON.stringify(have)} (vela uses ${JSON.stringify(wanted)})`,\n );\n }\n }\n return out;\n}\n"],"mappings":";;;;;;;;;AAgCA,SAASO,EAAS,GAAqC;CACrD,OAAO,OAAOC,KAAU,cAAYA,KAAkB,CAAC,MAAM,QAAQA,CAAK;AAC5E;AAEA,SAASC,EAAY,GAAmD;CACtE,IAAMC,IAAWR,EAAK,KAAKS,GAAM,cAAc;CAC/C,IAAI,CAACV,EAAG,WAAWS,CAAQ,GACzB,OAAO;EACL;EACA,SAAS;GAAE,QAAQ;GAAa,SAAS;EAA2B;CACtE;CAEF,IAAME,IAAOX,EAAG,aAAaS,GAAU,MAAM,GACzCG;CACJ,IAAI;EACF,IAAM,KAAK,MAAMD,CAAI;CACvB,QAAQ;EACN,OAAO;GACL;GACA,SAAS;IAAE,QAAQ;IAAU,SAAS;G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IACXsB,IAAQ,CAAC,GAAGC,GAAOvB,CAAG,CAAC,CAAC,KAAK,KAAK;EACxC,IAAIqB,MAAS,KAAA,GACX,EAAIrB,KAAOmB;OACN,IAAI,OAAOA,KAAW,UAAU;GAErC,IADIE,MAASF,KACTpC,EAASsC,CAAI,KAAKA,EAAK,SAASF,GAAQ;GAC5C,EAAU,KACR,GAAGG,EAAM,IAAI,KAAK,UAAUD,CAAI,EAAE,cAAc,KAAK,UAAUF,CAAM,EAAE,EACzE;EACF,OAAO,AAAIpC,EAASsC,CAAI,IACtB,EAAIrB,KAAOgB,EAAeK,GAAMF,GAAQ,CAAC,GAAGI,GAAOvB,CAAG,GAAGI,CAAS,IACzD,OAAOiB,KAAS,WACzB,EAAIrB,KAAOgB,EACT,EAAE,KAAKK,EAAK,GACZF,GACA,CAAC,GAAGI,GAAOvB,CAAG,GACdI,CACF,IAEAA,EAAU,KACR,GAAGkB,EAAM,IAAI,KAAK,UAAUD,CAAI,EAAE,cAAc,KAAK,UAAUF,CAAM,EAAE,EACzE;CAEJ;CACA,OAAOF;AACT"}
|
|
1
|
+
{"version":3,"file":"package-imports-B9Asv3ZH.js","names":["__exportAll","fs","path","package_imports_exports","ensurePackageImports","ensurePackageOverrides","removePackageImports","isObject","value","readPackage","filePath","root","text","pkg","indent","eol","trailing","writePackage","next","file","insertKey","anchor","after","name","key","existing","finish","outcome","conflicts","field","line","current","entries","imports","keys","expected","_","rest","overrides","merged","mergeOverrides","out","target","wanted","source","have","where","trail"],"sources":["../../src/runtime/package-imports.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { ModifyOutcome } from \"../core/types\";\n\n/**\n * Edits to the project's `package.json` that npm has no command for: the\n * `imports` map SvelteKit 3 resolves `#lib` (and `#locales`) through, and\n * `overrides`. The file is rewritten with the indentation and trailing\n * newline it had, and a key that already holds a different value is never\n * overwritten: it is the project's, and the outcome says what to change.\n */\n\nexport interface PackageJsonEditResult {\n filePath: string;\n outcome: ModifyOutcome;\n}\n\ntype Json = string | number | boolean | null | Json[] | { [key: string]: Json };\ntype JsonObject = { [key: string]: Json };\n\n/** An `overrides` value: a version, or nested overrides (npm's `\".\"` is the package itself). */\nexport type OverrideValue = string | { [key: string]: OverrideValue };\n\ninterface PackageFile {\n filePath: string;\n text: string;\n pkg: JsonObject;\n indent: string;\n eol: string;\n trailing: string;\n}\n\nfunction isObject(value: unknown): value is JsonObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction readPackage(root: string): PackageFile | PackageJsonEditResult {\n const filePath = path.join(root, \"package.json\");\n if (!fs.existsSync(filePath)) {\n return {\n filePath,\n outcome: { status: \"not-found\", message: \"No package.json to edit.\" },\n };\n }\n const text = fs.readFileSync(filePath, \"utf8\");\n let pkg: unknown;\n try {\n pkg = JSON.parse(text);\n } catch {\n return {\n filePath,\n outcome: { status: \"failed\", message: \"package.json is not valid JSON.\" },\n };\n }\n if (!isObject(pkg)) {\n return {\n filePath,\n outcome: { status: \"failed\", message: \"package.json is not an object.\" },\n };\n }\n const indent = text.match(/^[{[][^\\S\\n]*\\r?\\n([\\t ]+)\\S/)?.[1] ?? \"\\t\";\n const eol = text.includes(\"\\r\\n\") ? \"\\r\\n\" : \"\\n\";\n const trailing = text.match(/(\\r?\\n)*$/)?.[0] ?? \"\";\n return { filePath, text, pkg, indent, eol, trailing };\n}\n\nfunction writePackage(file: PackageFile): ModifyOutcome {\n const body = JSON.stringify(file.pkg, null, file.indent).replace(\n /\\n/g,\n file.eol,\n );\n const next = body + file.trailing;\n if (next === file.text) return { status: \"success\", changed: false };\n fs.writeFileSync(file.filePath, next, \"utf8\");\n return { status: \"success\", changed: true };\n}\n\n/**\n * Add `key` to `pkg` right after the first of `after` it has, else at the end.\n * JSON object key order is insertion order, so this rebuilds the object.\n */\nfunction insertKey(\n pkg: JsonObject,\n key: string,\n value: Json,\n after: string[],\n): JsonObject {\n const anchor = after.find((name) => name in pkg);\n if (!anchor) return { ...pkg, [key]: value };\n const next: JsonObject = {};\n for (const [name, existing] of Object.entries(pkg)) {\n next[name] = existing;\n if (name === anchor) next[key] = value;\n }\n return next;\n}\n\nfunction finish(\n file: PackageFile,\n conflicts: string[],\n field: string,\n): PackageJsonEditResult {\n const outcome = writePackage(file);\n if (conflicts.length === 0) return { filePath: file.filePath, outcome };\n return {\n filePath: file.filePath,\n outcome: {\n status: \"failed\",\n message: [\n `package.json \\`${field}\\` already has a different value for:`,\n ...conflicts.map((line) => ` ${line}`),\n \"Change these by hand if vela's value is the one you want.\",\n ].join(\"\\n\"),\n },\n };\n}\n\n/**\n * Add the subpath `imports` (`{ \"#lib/*\": \"./src/lib/*\" }`) that are missing.\n * Creates `imports` after `type` when the project has none.\n */\nexport function ensurePackageImports(\n root: string,\n entries: Record<string, string>,\n): PackageJsonEditResult {\n const file = readPackage(root);\n if (!(\"pkg\" in file)) return file;\n\n const current = file.pkg.imports;\n if (current !== undefined && !isObject(current)) {\n return {\n filePath: file.filePath,\n outcome: {\n status: \"failed\",\n message: [\n \"package.json `imports` is not an object. Add these entries to it by hand:\",\n ...Object.entries(entries).map(\n ([key, value]) =>\n ` ${JSON.stringify(key)}: ${JSON.stringify(value)}`,\n ),\n ].join(\"\\n\"),\n },\n };\n }\n\n const imports: JsonObject = { ...(current ?? {}) };\n const conflicts: string[] = [];\n for (const [key, value] of Object.entries(entries)) {\n if (!(key in imports)) {\n imports[key] = value;\n } else if (imports[key] !== value) {\n conflicts.push(\n `${JSON.stringify(key)}: ${JSON.stringify(imports[key])} (vela uses ${JSON.stringify(value)})`,\n );\n }\n }\n file.pkg =\n current === undefined\n ? Object.keys(imports).length > 0\n ? insertKey(file.pkg, \"imports\", imports, [\"type\", \"version\", \"name\"])\n : file.pkg\n : { ...file.pkg, imports };\n return finish(file, conflicts, \"imports\");\n}\n\n/**\n * Remove subpath `imports` keys. With `expected`, a key is removed only while\n * it still maps to the value vela wrote, so one the developer repointed stays.\n * An `imports` left empty is removed too.\n */\nexport function removePackageImports(\n root: string,\n keys: string[],\n expected?: Record<string, string>,\n): PackageJsonEditResult {\n const file = readPackage(root);\n if (!(\"pkg\" in file)) {\n // Nothing to revert in a project without a package.json.\n return file.outcome.status === \"not-found\"\n ? {\n filePath: file.filePath,\n outcome: { status: \"success\", changed: false },\n }\n : file;\n }\n const current = file.pkg.imports;\n if (!isObject(current)) {\n return {\n filePath: file.filePath,\n outcome: { status: \"success\", changed: false },\n };\n }\n const imports: JsonObject = { ...current };\n for (const key of keys) {\n if (!(key in imports)) continue;\n if (expected && key in expected && imports[key] !== expected[key]) continue;\n delete imports[key];\n }\n if (Object.keys(imports).length === 0) {\n const { imports: _, ...rest } = file.pkg;\n file.pkg = rest;\n } else {\n file.pkg = { ...file.pkg, imports };\n }\n return { filePath: file.filePath, outcome: writePackage(file) };\n}\n\n/**\n * Deep-merge `overrides` into package.json's `overrides`, created at the end\n * when missing. A version already there that differs is left as it is and\n * reported. A package overridden with a bare version that now needs nested\n * overrides keeps that version as npm's `\".\"`.\n */\nexport function ensurePackageOverrides(\n root: string,\n overrides: Record<string, OverrideValue>,\n): PackageJsonEditResult {\n const file = readPackage(root);\n if (!(\"pkg\" in file)) return file;\n\n const current = file.pkg.overrides;\n if (current !== undefined && !isObject(current)) {\n return {\n filePath: file.filePath,\n outcome: {\n status: \"failed\",\n message: `package.json \\`overrides\\` is not an object. Add this to it by hand:\\n${JSON.stringify(overrides, null, 2)}`,\n },\n };\n }\n const conflicts: string[] = [];\n const merged = mergeOverrides(current ?? {}, overrides, [], conflicts);\n file.pkg = { ...file.pkg, overrides: merged };\n return finish(file, conflicts, \"overrides\");\n}\n\nfunction mergeOverrides(\n target: JsonObject,\n source: Record<string, OverrideValue>,\n trail: string[],\n conflicts: string[],\n): JsonObject {\n const out: JsonObject = { ...target };\n for (const [key, wanted] of Object.entries(source)) {\n const have = out[key];\n const where = [...trail, key].join(\" > \");\n if (have === undefined) {\n out[key] = wanted as Json;\n } else if (typeof wanted === \"string\") {\n if (have === wanted) continue;\n if (isObject(have) && have[\".\"] === wanted) continue;\n conflicts.push(\n `${where}: ${JSON.stringify(have)} (vela uses ${JSON.stringify(wanted)})`,\n );\n } else if (isObject(have)) {\n out[key] = mergeOverrides(have, wanted, [...trail, key], conflicts);\n } else if (typeof have === \"string\") {\n out[key] = mergeOverrides(\n { \".\": have },\n wanted,\n [...trail, key],\n conflicts,\n );\n } else {\n conflicts.push(\n `${where}: ${JSON.stringify(have)} (vela uses ${JSON.stringify(wanted)})`,\n );\n }\n }\n return out;\n}\n"],"mappings":";;;;;;;;;AAgCA,SAASO,EAAS,GAAqC;CACrD,OAAO,OAAOC,KAAU,cAAYA,KAAkB,CAAC,MAAM,QAAQA,CAAK;AAC5E;AAEA,SAASC,EAAY,GAAmD;CACtE,IAAMC,IAAWR,EAAK,KAAKS,GAAM,cAAc;CAC/C,IAAI,CAACV,EAAG,WAAWS,CAAQ,GACzB,OAAO;EACL;EACA,SAAS;GAAE,QAAQ;GAAa,SAAS;EAA2B;CACtE;CAEF,IAAME,IAAOX,EAAG,aAAaS,GAAU,MAAM,GACzCG;CACJ,IAAI;EACF,IAAM,KAAK,MAAMD,CAAI;CACvB,QAAQ;EACN,OAAO;GACL;GACA,SAAS;IAAE,QAAQ;IAAU,SAAS;GAAkC;EAC1E;CACF;CACA,IAAI,CAACL,EAASM,CAAG,GACf,OAAO;EACL;EACA,SAAS;GAAE,QAAQ;GAAU,SAAS;EAAiC;CACzE;CAEF,IAAMC,IAASF,EAAK,MAAM,8BAA8B,CAAC,GAAG,MAAM,KAC5DG,IAAMH,EAAK,SAAS,MAAM,IAAI,SAAS,MACvCI,IAAWJ,EAAK,MAAM,WAAW,CAAC,GAAG,MAAM;CACjD,OAAO;EAAE;EAAU;EAAM;EAAK;EAAQ;EAAK;CAAS;AACtD;AAEA,SAASK,EAAa,GAAkC;CAKtD,IAAMC,IAJO,KAAK,UAAUC,EAAK,KAAK,MAAMA,EAAK,MAAM,CAAC,CAAC,QACvD,OACAA,EAAK,GAE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,EAAIrB,KAAOgB,EACT,EAAE,KAAKK,EAAK,GACZF,GACA,CAAC,GAAGI,GAAOvB,CAAG,GACdI,CACF,IAEAA,EAAU,KACR,GAAGkB,EAAM,IAAI,KAAK,UAAUD,CAAI,EAAE,cAAc,KAAK,UAAUF,CAAM,EAAE,EACzE;CAEJ;CACA,OAAOF;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as e } from "./rolldown-runtime-5HNE8Q1r.js";
|
|
2
|
-
import {
|
|
2
|
+
import { i as t, s as n } from "./constants-Bdx8mp7v.js";
|
|
3
3
|
import { existsSync as r, readFileSync as i, readdirSync as a } from "node:fs";
|
|
4
4
|
import o from "node:path";
|
|
5
5
|
import s from "pocketbase";
|
|
@@ -157,9 +157,9 @@ var v = /* @__PURE__ */ e({
|
|
|
157
157
|
function b() {
|
|
158
158
|
return new Promise((e) => setTimeout(e, y));
|
|
159
159
|
}
|
|
160
|
-
function x(e,
|
|
161
|
-
let i = `${
|
|
162
|
-
if (s) return o.join(r.root,
|
|
160
|
+
function x(e, t, r) {
|
|
161
|
+
let i = `${t}_${e}.js`, s = a(o.join(r.root, n)).filter((e) => e.endsWith(i)).sort().pop();
|
|
162
|
+
if (s) return o.join(r.root, n, s);
|
|
163
163
|
}
|
|
164
164
|
function S(e) {
|
|
165
165
|
let t = o.join(e, "node_modules", ".vite", "_pocketbase_metadata.json");
|
|
@@ -176,7 +176,7 @@ async function C(e, t, n) {
|
|
|
176
176
|
if (!r) throw Error("Failed to authenticate with PocketBase. Check your superuser credentials.");
|
|
177
177
|
}
|
|
178
178
|
async function w(e, i) {
|
|
179
|
-
let a = o.join(e,
|
|
179
|
+
let a = o.join(e, t), d = o.join(e, n), f = "localhost";
|
|
180
180
|
if (!r(a)) throw Error("PocketBase data directory does not exist");
|
|
181
181
|
let p = S(e);
|
|
182
182
|
if (p && p.pocketbaseUrl) {
|
|
@@ -224,4 +224,4 @@ function T(e, t) {
|
|
|
224
224
|
//#endregion
|
|
225
225
|
export { w as i, b as n, v as r, x as t };
|
|
226
226
|
|
|
227
|
-
//# sourceMappingURL=pocketbase-
|
|
227
|
+
//# sourceMappingURL=pocketbase-BtN-wL8f.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pocketbase-DL02rq73.js","names":["__exportAll","MIGRATIONS_DIR","DATA_DIR","path","PocketBase","spawn","net","BAD_PORTS","osAssignedPort","server","reject","host","resolve","port","freePort","waitForPort","attempts","tryConnect","socket","maxAttempts","describeFetchError","error","cause","waitForHealth","lastFailure","tryHealth","response","url","pocketbase_exports","authWithRetries","getMigrationFile","getPocketbaseMetadata","migrationDelay","withPocketbase","MIGRATION_DELAY_MS","ending","action","collectionName","migrationFile","readdirSync","options","file","metadataPath","cwd","existsSync","readFileSync","authSuccess","attempt","pb","email","password","dir","migrationsDir","metadata","fn","commandArgs","packageManager","detect","resolveCommand","args","detached","serverProcess","command","exited","signal","code","stopProcessTree","child"],"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,IAAaO,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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AChB,YAAY;GAEX,AADA,MAAMK,EAAYF,GAAMF,CAAI,GAC5B,MAAMY,EAAc,UAAUZ,EAAK,GAAGE,GAAM;EAC9C,EAAA,CAAG,GACHkD,CACF,CAAC;EAED,IAAMf,IAAK,IAAI5C,EAAW,UAAUO,EAAK,GAAGE,GAAM;EAMlD,AALA,MAAMgB,EACJmB,GACA,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BACd,GACA,MAAMM,EAAGN,CAAE;CACb,UAAU;EAER,EAAgBa,GAAeD,CAAQ;CACzC;AACF;AAEA,SAASM,EACP,GACA,GACM;CACN,IAAIN,KAAYO,EAAM,KACpB,IAAI;EACF,QAAQ,KAAK,CAACA,EAAM,KAAK,SAAS;EAClC;CACF,QAAQ,CAER;CAEF,EAAM,KAAK;AACb"}
|
|
1
|
+
{"version":3,"file":"pocketbase-BtN-wL8f.js","names":["__exportAll","DATA_DIR","MIGRATIONS_DIR","path","PocketBase","spawn","net","BAD_PORTS","osAssignedPort","server","reject","host","resolve","port","freePort","waitForPort","attempts","tryConnect","socket","maxAttempts","describeFetchError","error","cause","waitForHealth","lastFailure","tryHealth","response","url","pocketbase_exports","authWithRetries","getMigrationFile","getPocketbaseMetadata","migrationDelay","withPocketbase","MIGRATION_DELAY_MS","ending","action","collectionName","migrationFile","readdirSync","options","file","metadataPath","cwd","existsSync","readFileSync","authSuccess","attempt","pb","email","password","dir","migrationsDir","metadata","fn","commandArgs","packageManager","detect","resolveCommand","args","detached","serverProcess","command","exited","signal","code","stopProcessTree","child"],"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,IAAaO,oBAAiC,IAAI,IAAI;CACpD;CAAG;CAAG;CAAG;CAAI;CAAI;CAAI;CAAI;CAAI;CA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AAQ,aAAa,SAChCC,IAAgBxD,EAAMyD,GAASH,GAAM;EACzC;EACA,OAAO;EACP;CACF,CAAC,GAIKI,IAAS,IAAI,SAAgB,GAAG,MAAW;EAQ/C,AAPAF,EAAc,KAAK,SAAS,GAAM,MAAW;GAC3C,EACE,gBAAI,MACF,gDAAgDlD,EAAK,GAAGE,EAAK,IAAImD,KAAU,QAAQC,IAAO,EAC5F,CACF;EACF,CAAC,GACDJ,EAAc,KAAK,SAASnD,CAAM;CACpC,CAAC;CAED,IAAI;EAEF,MAAM,QAAQ,KAAK,EAChB,YAAY;GAEX,AADA,MAAMK,EAAYF,GAAMF,CAAI,GAC5B,MAAMY,EAAc,UAAUZ,EAAK,GAAGE,GAAM;EAC9C,EAAA,CAAG,GACHkD,CACF,CAAC;EAED,IAAMf,IAAK,IAAI5C,EAAW,UAAUO,EAAK,GAAGE,GAAM;EAMlD,AALA,MAAMgB,EACJmB,GACA,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BACd,GACA,MAAMM,EAAGN,CAAE;CACb,UAAU;EAER,EAAgBa,GAAeD,CAAQ;CACzC;AACF;AAEA,SAASM,EACP,GACA,GACM;CACN,IAAIN,KAAYO,EAAM,KACpB,IAAI;EACF,QAAQ,KAAK,CAACA,EAAM,KAAK,SAAS;EAClC;CACF,QAAQ,CAER;CAEF,EAAM,KAAK;AACb"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as e, s as t } from "./providers-CL9kQ4hp.js";
|
|
2
|
-
import { readEnvVarNames as n } from "./env-vars-
|
|
2
|
+
import { readEnvVarNames as n } from "./env-vars-0hvKe55u.js";
|
|
3
3
|
import r from "node:fs";
|
|
4
4
|
import i from "node:path";
|
|
5
5
|
//#region src/runtime/providers.ts
|
|
@@ -35,4 +35,4 @@ function s(e) {
|
|
|
35
35
|
//#endregion
|
|
36
36
|
export { a as detectProviders };
|
|
37
37
|
|
|
38
|
-
//# sourceMappingURL=providers-
|
|
38
|
+
//# sourceMappingURL=providers-DRwJnSzb.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers-
|
|
1
|
+
{"version":3,"file":"providers-DRwJnSzb.js","names":["capabilityName","providerMarkers","fs","path","detectProviders","detected","present","markerProbe","root","pattern","patterns","ids","provider","capability","envNames","dependencies","marker","readEnvVarNames","readDependencies","file","pkg"],"sources":["../../src/runtime/providers.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { capabilityName, providerMarkers } from \"../core/providers\";\nimport type { DetectedProviders, Pattern, ProviderMarker } from \"../core/types\";\nimport { readEnvVarNames } from \"./env-vars\";\n\ntype DetectablePattern = Pick<\n Pattern,\n \"slug\" | \"providers\" | \"inheritsProvider\"\n>;\n\n/**\n * The provider in use for each capability, read from what the providers left\n * in the project. Nothing records the choice, so this is the only way to know\n * it. A pattern that inherits its provider is skipped: its files say nothing\n * the capability it is built on doesn't already.\n *\n * The registry is passed in rather than imported, so this module and the\n * package entry don't import each other.\n */\nexport function detectProviders(\n root: string,\n patterns: readonly DetectablePattern[],\n): DetectedProviders {\n const detected: DetectedProviders = { providers: {}, ambiguous: [] };\n const present = markerProbe(root);\n\n for (const pattern of patterns) {\n if (!pattern.providers?.length || pattern.inheritsProvider) continue;\n const ids = pattern.providers\n .filter((provider) => providerMarkers(provider).some(present))\n .map((provider) => provider.id);\n\n const capability = capabilityName(pattern.slug);\n if (ids.length === 1) detected.providers[capability] = ids[0];\n if (ids.length > 1) detected.ambiguous.push({ capability, ids });\n }\n\n return detected;\n}\n\n/** Checks one marker against the project; `src/env.ts` and `package.json` are read once. */\nfunction markerProbe(root: string): (marker: ProviderMarker) => boolean {\n let envNames: Set<string> | undefined;\n let dependencies: Set<string> | undefined;\n\n return (marker) => {\n if (\"env\" in marker) {\n envNames ??= readEnvVarNames(root);\n return envNames.has(marker.env);\n }\n if (\"path\" in marker) {\n return fs.existsSync(path.join(root, marker.path));\n }\n dependencies ??= readDependencies(root);\n return dependencies.has(marker.dependency);\n };\n}\n\nfunction readDependencies(root: string): Set<string> {\n const file = path.join(root, \"package.json\");\n if (!fs.existsSync(file)) return new Set();\n try {\n const pkg = JSON.parse(fs.readFileSync(file, \"utf8\")) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n return new Set([\n ...Object.keys(pkg.dependencies ?? {}),\n ...Object.keys(pkg.devDependencies ?? {}),\n ]);\n } catch {\n return new Set();\n }\n}\n"],"mappings":";;;;;AAoBA,SAAgBI,EACd,GACA,GACmB;CACnB,IAAMC,IAA8B;EAAE,WAAW,CAAC;EAAG,WAAW,CAAC;CAAE,GAC7DC,IAAUC,EAAYC,CAAI;CAEhC,KAAK,IAAMC,KAAWC,GAAU;EAC9B,IAAI,CAACD,EAAQ,WAAW,UAAUA,EAAQ,kBAAkB;EAC5D,IAAME,IAAMF,EAAQ,UACjB,QAAQ,MAAaR,EAAgBW,CAAQ,CAAC,CAAC,KAAKN,CAAO,CAAC,CAAC,CAC7D,KAAK,MAAaM,EAAS,EAAE,GAE1BC,IAAab,EAAeS,EAAQ,IAAI;EAE9C,AADIE,EAAI,WAAW,MAAG,EAAS,UAAUE,KAAcF,EAAI,KACvDA,EAAI,SAAS,KAAGN,EAAS,UAAU,KAAK;GAAE;GAAY;EAAI,CAAC;CACjE;CAEA,OAAOA;AACT;AAGA,SAASE,EAAY,GAAmD;CACtE,IAAIO,GACAC;CAEJ,QAAQ,MACF,SAASC,KACX,MAAaC,EAAgBT,CAAI,GAC1BM,EAAS,IAAIE,EAAO,GAAG,KAE5B,UAAUA,IACLd,EAAG,WAAWC,EAAK,KAAKK,GAAMQ,EAAO,IAAI,CAAC,KAEnD,MAAiBE,EAAiBV,CAAI,GAC/BO,EAAa,IAAIC,EAAO,UAAU;AAE7C;AAEA,SAASE,EAAiB,GAA2B;CACnD,IAAMC,IAAOhB,EAAK,KAAKK,GAAM,cAAc;CAC3C,IAAI,CAACN,EAAG,WAAWiB,CAAI,GAAG,uBAAO,IAAI,IAAI;CACzC,IAAI;EACF,IAAMC,IAAM,KAAK,MAAMlB,EAAG,aAAaiB,GAAM,MAAM,CAAC;EAIpD,uBAAO,IAAI,IAAI,CACb,GAAG,OAAO,KAAKC,EAAI,gBAAgB,CAAC,CAAC,GACrC,GAAG,OAAO,KAAKA,EAAI,mBAAmB,CAAC,CAAC,CAC1C,CAAC;CACH,QAAQ;EACN,uBAAO,IAAI,IAAI;CACjB;AACF"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { r as e } from "./lib-specifier-Cngo1zF_.js";
|
|
2
|
+
import { t } from "./dedent-Gq6Krl4n.js";
|
|
3
|
+
import { _ as n, n as r, r as i, u as a } from "./ts-morph-helpers-CHI9wAil.js";
|
|
4
|
+
import { t as o } from "./svelte-file-Dv5-bl79.js";
|
|
5
|
+
import s from "node:fs";
|
|
6
|
+
//#region src/patterns/enable/payments/modifies/root-layout.svelte.ts
|
|
7
|
+
function c(e) {
|
|
8
|
+
return `<Navbar.Item>\n${e}\t<CurrencySelect />\n${e}</Navbar.Item>\n${e}`;
|
|
9
|
+
}
|
|
10
|
+
var l = c(" "), u = t`
|
|
11
|
+
import CurrencySelect from '#lib/components/currency-select.svelte';
|
|
12
|
+
`, d = [
|
|
13
|
+
"Add the currency select inside your <Navbar.List> in the root layout.",
|
|
14
|
+
"",
|
|
15
|
+
"Import to add to the <script> tag:",
|
|
16
|
+
"",
|
|
17
|
+
u,
|
|
18
|
+
"",
|
|
19
|
+
"Markup to add at the end of <Navbar.List>, after the language select if there is one:",
|
|
20
|
+
l
|
|
21
|
+
].join("\n"), f = [
|
|
22
|
+
"Create a root layout that includes a currency select inside <Navbar.List>.",
|
|
23
|
+
"",
|
|
24
|
+
"Import for the <script> tag:",
|
|
25
|
+
"",
|
|
26
|
+
u,
|
|
27
|
+
"",
|
|
28
|
+
"Markup at the end of <Navbar.List>:",
|
|
29
|
+
l
|
|
30
|
+
].join("\n");
|
|
31
|
+
function p(e) {
|
|
32
|
+
if (!s.existsSync(e)) return {
|
|
33
|
+
status: "not-found",
|
|
34
|
+
message: f
|
|
35
|
+
};
|
|
36
|
+
let t = o.fromPath(e);
|
|
37
|
+
if (t.hasElement("CurrencySelect")) return {
|
|
38
|
+
status: "success",
|
|
39
|
+
changed: !1
|
|
40
|
+
};
|
|
41
|
+
if (!t.hasElement("Navbar.List")) return {
|
|
42
|
+
status: "failed",
|
|
43
|
+
message: d
|
|
44
|
+
};
|
|
45
|
+
let r = t.findElementContaining("Navbar.Item", "LanguageSelect");
|
|
46
|
+
if (r) t.insertAfterElement(r, "<Navbar.Item>\n <CurrencySelect />\n</Navbar.Item>");
|
|
47
|
+
else {
|
|
48
|
+
let e = /^([ \t]*)<\/Navbar\.List>/m.exec(t.toString())?.[1] ?? " ", n = `\t<Navbar.Item>\n${e}\t\t<CurrencySelect />\n${e}\t</Navbar.Item>\n${e}`;
|
|
49
|
+
if (!t.insertBeforeClosingTag("Navbar.List", n)) return {
|
|
50
|
+
status: "failed",
|
|
51
|
+
message: d
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return t.modifyScript((e) => {
|
|
55
|
+
let { source: t } = n(e, (e) => {
|
|
56
|
+
i(e, [{
|
|
57
|
+
defaultImport: "CurrencySelect",
|
|
58
|
+
moduleSpecifier: "#lib/components/currency-select.svelte"
|
|
59
|
+
}]);
|
|
60
|
+
});
|
|
61
|
+
return t;
|
|
62
|
+
}), t.writeTo(e), {
|
|
63
|
+
status: "success",
|
|
64
|
+
changed: t.hasChanged()
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function m(t) {
|
|
68
|
+
if (!s.existsSync(t)) return {
|
|
69
|
+
status: "success",
|
|
70
|
+
changed: !1
|
|
71
|
+
};
|
|
72
|
+
let i = s.readFileSync(t, "utf8");
|
|
73
|
+
if (!i.includes("CurrencySelect")) return {
|
|
74
|
+
status: "success",
|
|
75
|
+
changed: !1
|
|
76
|
+
};
|
|
77
|
+
let c = o.fromPath(t);
|
|
78
|
+
c.modifyScript((t) => {
|
|
79
|
+
let { source: i } = n(t, (t) => {
|
|
80
|
+
a(t, e("components/currency-select.svelte")), r(t);
|
|
81
|
+
});
|
|
82
|
+
return i;
|
|
83
|
+
});
|
|
84
|
+
let l = c.toString();
|
|
85
|
+
return l = l.replace(/[ \t]*<Navbar\.Item>\s*<CurrencySelect\s*\/>\s*<\/Navbar\.Item>[ \t]*\r?\n?/g, ""), l = l.replace(/[ \t]*<CurrencySelect\s*\/>[ \t]*\r?\n?/g, ""), s.writeFileSync(t, l, "utf8"), {
|
|
86
|
+
status: "success",
|
|
87
|
+
changed: l !== i
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { m as n, p as t };
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=root-layout.svelte-CsJ2QJYi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"root-layout.svelte-CsJ2QJYi.js","names":["libModule","withInMemoryScript","ensureBlankLineAfterImports","ensureImports","removeImportByModuleSpecifier","SvelteFile","fs","snippet","indent","SNIPPET","IMPORT","FAILURE_HINT","NOT_FOUND_HINT","modifyRootLayoutCurrencySelect","layoutPath","file","language","item","out","source","sf","unmodifyRootLayoutCurrencySelect","original","updated"],"sources":["../../src/patterns/enable/payments/modifies/root-layout.svelte.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\nimport {\n ensureBlankLineAfterImports,\n ensureImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/** The item, indented like the list it joins; `indent` is the list's closing tag's. */\nfunction snippet(indent: string): string {\n return `<Navbar.Item>\\n${indent}\\t<CurrencySelect />\\n${indent}</Navbar.Item>\\n${indent}`;\n}\n\nconst SNIPPET = snippet(\"\\t\\t\\t\");\n\nconst IMPORT = dedent`\n import CurrencySelect from '#lib/components/currency-select.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the currency select inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT,\n \"\",\n \"Markup to add at the end of <Navbar.List>, after the language select if there is one:\",\n SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes a currency select inside <Navbar.List>.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT,\n \"\",\n \"Markup at the end of <Navbar.List>:\",\n SNIPPET,\n].join(\"\\n\");\n\n/**\n * The currency select goes in the navbar beside the language select, when\n * there is one, else as the last item. It renders nothing until the business\n * offers a second currency, so the layout gains it with payments.\n */\nexport function modifyRootLayoutCurrencySelect(\n layoutPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"CurrencySelect\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const language = file.findElementContaining(\"Navbar.Item\", \"LanguageSelect\");\n if (language) {\n // On the line after the language select's item; the helper indents it.\n file.insertAfterElement(\n language,\n \"<Navbar.Item>\\n\\t<CurrencySelect />\\n</Navbar.Item>\",\n );\n } else {\n // The closing tag's own indentation already precedes the insertion point,\n // so the item starts one level in and hands that indentation back.\n const indent =\n /^([ \\t]*)<\\/Navbar\\.List>/m.exec(file.toString())?.[1] ?? \"\\t\\t\";\n const item = `\\t<Navbar.Item>\\n${indent}\\t\\t<CurrencySelect />\\n${indent}\\t</Navbar.Item>\\n${indent}`;\n if (!file.insertBeforeClosingTag(\"Navbar.List\", item))\n return { status: \"failed\", message: FAILURE_HINT };\n }\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n defaultImport: \"CurrencySelect\",\n moduleSpecifier: \"#lib/components/currency-select.svelte\",\n },\n ]);\n });\n return out;\n });\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n\n/** Take the currency select (and the nav item around it) back out. */\nexport function unmodifyRootLayoutCurrencySelect(\n layoutPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(layoutPath, \"utf8\");\n if (!original.includes(\"CurrencySelect\")) {\n return { status: \"success\", changed: false };\n }\n const file = SvelteFile.fromPath(layoutPath);\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n removeImportByModuleSpecifier(\n sf,\n libModule(\"components/currency-select.svelte\"),\n );\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n let updated = file.toString();\n updated = updated.replace(\n /[ \\t]*<Navbar\\.Item>\\s*<CurrencySelect\\s*\\/>\\s*<\\/Navbar\\.Item>[ \\t]*\\r?\\n?/g,\n \"\",\n );\n updated = updated.replace(/[ \\t]*<CurrencySelect\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n fs.writeFileSync(layoutPath, updated, \"utf8\");\n return { status: \"success\", changed: updated !== original };\n}\n"],"mappings":";;;;;;AAaA,SAASO,EAAQ,GAAwB;CACvC,OAAO,kBAAkBC,EAAO,wBAAwBA,EAAO,kBAAkBA;AACnF;AAEA,IAAMC,IAAUF,EAAQ,KAAQ,GAE1BG,IAAS,CAAM;;GAIfC,IAAe;CACnB;CACA;CACA;CACA;CACAD;CACA;CACA;CACAD;AACF,CAAC,CAAC,KAAK,IAAI,GAELG,IAAiB;CACrB;CACA;CACA;CACA;CACAF;CACA;CACA;CACAD;AACF,CAAC,CAAC,KAAK,IAAI;AAOX,SAAgBI,EACd,GACe;CACf,IAAI,CAACP,EAAG,WAAWQ,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAa,SAASF;CAAe;CAExD,IAAMG,IAAOV,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C;CACD,IAAIK,IAAUR,EAAK,SAAS;CAO5B,OANA,IAAUQ,EAAQ,QAChB,gFACA,EACF,GACA,IAAUA,EAAQ,QAAQ,4CAA4C,EAAE,GACxEjB,EAAG,cAAcQ,GAAYS,GAAS,MAAM,GACrC;EAAE,QAAQ;EAAW,SAASA,MAAYD;CAAS;AAC5D"}
|
|
@@ -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-
|
|
18
|
+
let { withPocketbase: n } = await import("./pocketbase-BtN-wL8f.js").then((e) => e.r), { planCollectionDrops: r } = await import("./collections-BYcVyY9O.js").then((e) => e.n), 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-
|
|
27
|
+
//# sourceMappingURL=shared-BbxLil4g.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-
|
|
1
|
+
{"version":3,"file":"shared-BbxLil4g.js","names":["languageFromPath","toDeleteEntry","path","planDropsForCollections","collectionNames","options","n","drops","withPocketbase","plans","planCollectionDrops","pb"],"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,SAAgBC,EAAc,GAAoB;CAChD,OAAO;EACL;EACA,UAAUD,EAAiBE,CAAI;EAC/B,SAAS;EACT,QAAQ;CACV;AACF;AAOA,eAAsBC,EACpB,GACA,GAC+B;CAC/B,IAAIC,EAAgB,WAAW,GAAG,OAAO,CAAC;CAE1C,IAAIC,EAAQ,QAAQ,WAClB,OAAOD,EAAgB,KAAK,OAAU;EACpC;EACA,QAAQ;EACR,UAAU;CACZ,EAAE;CAGJ,IAAM,EAAE,sBAAmB,MAAM,OAAO,2BAAA,CAAA,MAAA,MAAAE,EAAA,CAAA,GAClC,EAAE,2BAAwB,MAAM,OAAO,4BAAA,CAAA,MAAA,MAAAA,EAAA,CAAA,GACvCC,IAA8B,CAAC;CAKrC,OAJA,MAAMC,EAAeH,EAAQ,MAAM,OAAO,MAAO;EAC/C,IAAMI,IAAQ,MAAMC,EAAoBC,GAAIP,CAAe;EAC3D,EAAM,KAAK,GAAGK,CAAK;CACrB,CAAC,GACMF;AACT"}
|