@velastack/patterns 0.6.0 → 0.7.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 +11 -0
- package/dist/chunks/{_layout-D-FzWqn0.js → _layout-Bsx3eNrC.js} +3 -3
- package/dist/chunks/{_layout-D-FzWqn0.js.map → _layout-Bsx3eNrC.js.map} +1 -1
- package/dist/chunks/{auth-pages-B52ei-4z.js → auth-pages-jsyDV1GR.js} +7 -10
- package/dist/chunks/{auth-pages-B52ei-4z.js.map → auth-pages-jsyDV1GR.js.map} +1 -1
- package/dist/chunks/collections-BrEA7a62.js +309 -0
- package/dist/chunks/collections-BrEA7a62.js.map +1 -0
- package/dist/chunks/{collections-B_DisSfA.js → collections-DrUG8ngq.js} +39 -35
- package/dist/chunks/collections-DrUG8ngq.js.map +1 -0
- package/dist/chunks/{compose-handle-BDlZ7Pif.js → compose-handle-BBlamPfx.js} +18 -22
- package/dist/chunks/{compose-handle-BDlZ7Pif.js.map → compose-handle-BBlamPfx.js.map} +1 -1
- package/dist/chunks/{config-target-rHgjaA8u.js → config-target-BgyFkbFL.js} +2 -2
- package/dist/chunks/{config-target-rHgjaA8u.js.map → config-target-BgyFkbFL.js.map} +1 -1
- package/dist/chunks/dedent-Gq6Krl4n.js.map +1 -1
- package/dist/chunks/{env-BPfk1VAw.js → env-BugddEjd.js} +5 -9
- package/dist/chunks/{env-BPfk1VAw.js.map → env-BugddEjd.js.map} +1 -1
- package/dist/chunks/{env-vars-cqQU0ECK.js → env-vars-CdarYsrc.js} +6 -11
- package/dist/chunks/{env-vars-cqQU0ECK.js.map → env-vars-CdarYsrc.js.map} +1 -1
- package/dist/chunks/{generate-CXoQPz7n.js → generate-27CjLiGW.js} +2 -2
- package/dist/chunks/{generate-CXoQPz7n.js.map → generate-27CjLiGW.js.map} +1 -1
- package/dist/chunks/{generate-Bm_jOMtF.js → generate-BFcy2wrS.js} +2 -2
- package/dist/chunks/{generate-Bm_jOMtF.js.map → generate-BFcy2wrS.js.map} +1 -1
- package/dist/chunks/generate-BxOzEdc_.js +171 -0
- package/dist/chunks/generate-BxOzEdc_.js.map +1 -0
- package/dist/chunks/generate-D3mSFPdT.js.map +1 -1
- package/dist/chunks/{generate-jx5Iuq5w.js → generate-DdLwP0E7.js} +54 -53
- package/dist/chunks/generate-DdLwP0E7.js.map +1 -0
- package/dist/chunks/generate-DyV5R8NP.js.map +1 -1
- package/dist/chunks/{generate.runtime-Dug2UIhV.js → generate.runtime-9KuMcI5r.js} +9 -12
- package/dist/chunks/{generate.runtime-Dug2UIhV.js.map → generate.runtime-9KuMcI5r.js.map} +1 -1
- package/dist/chunks/{generate.runtime-wziCW3ct.js → generate.runtime-B10-KA87.js} +5 -5
- package/dist/chunks/{generate.runtime-wziCW3ct.js.map → generate.runtime-B10-KA87.js.map} +1 -1
- package/dist/chunks/{generate.runtime-N1KtAG8C.js → generate.runtime-B8-GLMkk.js} +90 -175
- package/dist/chunks/generate.runtime-B8-GLMkk.js.map +1 -0
- package/dist/chunks/{generate.runtime-CWnIiXwV.js → generate.runtime-BGuXHl5o.js} +3 -3
- package/dist/chunks/{generate.runtime-CWnIiXwV.js.map → generate.runtime-BGuXHl5o.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DCqf7nYM.js → generate.runtime-BJxM7FNA.js} +7 -7
- package/dist/chunks/{generate.runtime-DCqf7nYM.js.map → generate.runtime-BJxM7FNA.js.map} +1 -1
- package/dist/chunks/{generate.runtime-gFr2Gsjz.js → generate.runtime-BWRtyQeD.js} +5 -5
- package/dist/chunks/{generate.runtime-gFr2Gsjz.js.map → generate.runtime-BWRtyQeD.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DeniHg8L.js → generate.runtime-B_tWu-Bw.js} +5 -5
- package/dist/chunks/{generate.runtime-DeniHg8L.js.map → generate.runtime-B_tWu-Bw.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CyGR8VTx.js → generate.runtime-BdghkfNp.js} +3 -3
- package/dist/chunks/{generate.runtime-CyGR8VTx.js.map → generate.runtime-BdghkfNp.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DY5vQ3aZ.js → generate.runtime-Blb6QPZn.js} +6 -6
- package/dist/chunks/{generate.runtime-DY5vQ3aZ.js.map → generate.runtime-Blb6QPZn.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CHb4znYx.js → generate.runtime-CEexT8cJ.js} +6 -6
- package/dist/chunks/{generate.runtime-CHb4znYx.js.map → generate.runtime-CEexT8cJ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-wGRE1zwZ.js → generate.runtime-CIZO2XO9.js} +4 -4
- package/dist/chunks/{generate.runtime-wGRE1zwZ.js.map → generate.runtime-CIZO2XO9.js.map} +1 -1
- package/dist/chunks/{generate.runtime-_c7daMAw.js → generate.runtime-CK0MTeqc.js} +4 -4
- package/dist/chunks/{generate.runtime-_c7daMAw.js.map → generate.runtime-CK0MTeqc.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Dmob2wFf.js → generate.runtime-CMO-Skpk.js} +5 -5
- package/dist/chunks/{generate.runtime-Dmob2wFf.js.map → generate.runtime-CMO-Skpk.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CkmledBw.js → generate.runtime-CVDb-yLt.js} +12 -20
- package/dist/chunks/{generate.runtime-CkmledBw.js.map → generate.runtime-CVDb-yLt.js.map} +1 -1
- package/dist/chunks/generate.runtime-C_5Ghjri.js +17 -0
- package/dist/chunks/generate.runtime-C_5Ghjri.js.map +1 -0
- package/dist/chunks/{generate.runtime-Du4uf98c.js → generate.runtime-CbOMXQSo.js} +3 -3
- package/dist/chunks/{generate.runtime-Du4uf98c.js.map → generate.runtime-CbOMXQSo.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CRhD98rs.js → generate.runtime-CbT-EbQT.js} +5 -5
- package/dist/chunks/{generate.runtime-CRhD98rs.js.map → generate.runtime-CbT-EbQT.js.map} +1 -1
- package/dist/chunks/{generate.runtime-kpqW3dVO.js → generate.runtime-Cxr15Y5H.js} +8 -8
- package/dist/chunks/{generate.runtime-kpqW3dVO.js.map → generate.runtime-Cxr15Y5H.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B4u9C2YH.js → generate.runtime-CyTxBcX3.js} +4 -4
- package/dist/chunks/{generate.runtime-B4u9C2YH.js.map → generate.runtime-CyTxBcX3.js.map} +1 -1
- package/dist/chunks/{generate.runtime-aN5QWygO.js → generate.runtime-D5HxAups.js} +39 -36
- package/dist/chunks/generate.runtime-D5HxAups.js.map +1 -0
- package/dist/chunks/{generate.runtime-CYBs0JgY.js → generate.runtime-D6vhkGs8.js} +5 -5
- package/dist/chunks/{generate.runtime-CYBs0JgY.js.map → generate.runtime-D6vhkGs8.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B2r11K7S.js → generate.runtime-DIeAeOJg.js} +6 -6
- package/dist/chunks/{generate.runtime-B2r11K7S.js.map → generate.runtime-DIeAeOJg.js.map} +1 -1
- package/dist/chunks/{generate.runtime-FGYc365Q.js → generate.runtime-DMTAocSE.js} +6 -6
- package/dist/chunks/{generate.runtime-FGYc365Q.js.map → generate.runtime-DMTAocSE.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DdcVnK8J.js → generate.runtime-DlLwmjGF.js} +133 -121
- package/dist/chunks/generate.runtime-DlLwmjGF.js.map +1 -0
- package/dist/chunks/{generate.runtime-BxUGDXIK.js → generate.runtime-DtCaz98N.js} +6 -6
- package/dist/chunks/{generate.runtime-BxUGDXIK.js.map → generate.runtime-DtCaz98N.js.map} +1 -1
- package/dist/chunks/{generate.runtime-x-o4LS8d.js → generate.runtime-HSZD935T.js} +4 -4
- package/dist/chunks/{generate.runtime-x-o4LS8d.js.map → generate.runtime-HSZD935T.js.map} +1 -1
- package/dist/chunks/{generate.runtime-bpH3DB0t.js → generate.runtime-Nnk5E8Pi.js} +3 -3
- package/dist/chunks/{generate.runtime-bpH3DB0t.js.map → generate.runtime-Nnk5E8Pi.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BxDUtkpT.js → generate.runtime-NxuWvkKt.js} +4 -4
- package/dist/chunks/{generate.runtime-BxDUtkpT.js.map → generate.runtime-NxuWvkKt.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DYdkrHJ1.js → generate.runtime-dFTOU_KE.js} +6 -6
- package/dist/chunks/{generate.runtime-DYdkrHJ1.js.map → generate.runtime-dFTOU_KE.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DUo-pLRr.js → generate.runtime-m0m43lkL.js} +6 -6
- package/dist/chunks/{generate.runtime-DUo-pLRr.js.map → generate.runtime-m0m43lkL.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Bh9Z2cRN.js → generate.runtime-si5Za61F.js} +3 -3
- package/dist/chunks/{generate.runtime-Bh9Z2cRN.js.map → generate.runtime-si5Za61F.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BRCzUO94.js → generate.runtime-tGKorg85.js} +10 -14
- package/dist/chunks/{generate.runtime-BRCzUO94.js.map → generate.runtime-tGKorg85.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BVavIXtX.js → generate.runtime-ww3-1FWf.js} +6 -6
- package/dist/chunks/{generate.runtime-BVavIXtX.js.map → generate.runtime-ww3-1FWf.js.map} +1 -1
- package/dist/chunks/{modify-file-289rStJ2.js → modify-file-COBp4eCh.js} +4 -4
- package/dist/chunks/{modify-file-289rStJ2.js.map → modify-file-COBp4eCh.js.map} +1 -1
- package/dist/chunks/{modify-nav-user-B8h8WTrM.js → modify-nav-user-CJ1LevSU.js} +2 -2
- package/dist/chunks/{modify-nav-user-B8h8WTrM.js.map → modify-nav-user-CJ1LevSU.js.map} +1 -1
- package/dist/chunks/{modify-svelte-config-remote-DhuRX4FI.js → modify-svelte-config-remote-CEyYydL7.js} +2 -2
- package/dist/chunks/{modify-svelte-config-remote-DhuRX4FI.js.map → modify-svelte-config-remote-CEyYydL7.js.map} +1 -1
- package/dist/chunks/{modify-user-signup-BbqTiUuA.js → modify-user-signup-DLtopazD.js} +2 -2
- package/dist/chunks/{modify-user-signup-BbqTiUuA.js.map → modify-user-signup-DLtopazD.js.map} +1 -1
- package/dist/chunks/{package-imports-Bbw3iMPg.js → package-imports-Dx05A-4S.js} +2 -2
- package/dist/chunks/{package-imports-Bbw3iMPg.js.map → package-imports-Dx05A-4S.js.map} +1 -1
- package/dist/chunks/{pocketbase-B017Cqjq.js → pocketbase-DL02rq73.js} +4 -12
- package/dist/chunks/{pocketbase-B017Cqjq.js.map → pocketbase-DL02rq73.js.map} +1 -1
- package/dist/chunks/{providers-CN5J5_fY.js → providers-CAehyySB.js} +2 -2
- package/dist/chunks/{providers-CN5J5_fY.js.map → providers-CAehyySB.js.map} +1 -1
- package/dist/chunks/{rolldown-runtime-DArdT4gl.js → rolldown-runtime-5HNE8Q1r.js} +1 -1
- package/dist/chunks/{shared-BPlAVf-T.js → shared-C_Fr8wph.js} +2 -2
- package/dist/chunks/{shared-BPlAVf-T.js.map → shared-C_Fr8wph.js.map} +1 -1
- package/dist/chunks/{site-DkU1-VRq.js → site-BoujshKo.js} +2 -2
- package/dist/chunks/{site-DkU1-VRq.js.map → site-BoujshKo.js.map} +1 -1
- package/dist/chunks/{table-core-vXEjJDYP.js → table-core-BPv_RYgD.js} +2 -2
- package/dist/chunks/{table-core-vXEjJDYP.js.map → table-core-BPv_RYgD.js.map} +1 -1
- package/dist/chunks/{taggedTemplateLiteral-CswN2AAa.js → taggedTemplateLiteral-KSUnuvOk.js} +1 -1
- package/dist/chunks/{test-setup-CAfgVlwc.js → test-setup-pYUIfWb2.js} +4 -4
- package/dist/chunks/{test-setup-CAfgVlwc.js.map → test-setup-pYUIfWb2.js.map} +1 -1
- package/dist/chunks/{ts-morph-helpers-Bepc-Es2.js → ts-morph-helpers-CHI9wAil.js} +7 -11
- package/dist/chunks/{ts-morph-helpers-Bepc-Es2.js.map → ts-morph-helpers-CHI9wAil.js.map} +1 -1
- package/dist/chunks/{ui-CTdsenEv.js → ui-B2yn8c_-.js} +3 -3
- package/dist/chunks/{ui-CTdsenEv.js.map → ui-B2yn8c_-.js.map} +1 -1
- package/dist/chunks/{unmodify-load-Bl5vXQiL.js → unmodify-load-Buak-r1f.js} +2 -2
- package/dist/chunks/{unmodify-load-Bl5vXQiL.js.map → unmodify-load-Buak-r1f.js.map} +1 -1
- package/dist/chunks/{write-result-0HYIr5a6.js → write-result-Bn4bnrBI.js} +19 -49
- package/dist/chunks/write-result-Bn4bnrBI.js.map +1 -0
- package/dist/chunks/wuchale-config-c3Q4JVSF.js +50 -0
- package/dist/chunks/wuchale-config-c3Q4JVSF.js.map +1 -0
- package/dist/index.d.ts +162 -1
- package/dist/index.js +2001 -2176
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunks/collections-B_DisSfA.js.map +0 -1
- package/dist/chunks/generate-8FS2ROOJ.js +0 -170
- package/dist/chunks/generate-8FS2ROOJ.js.map +0 -1
- package/dist/chunks/generate-jx5Iuq5w.js.map +0 -1
- package/dist/chunks/generate.runtime-DdcVnK8J.js.map +0 -1
- package/dist/chunks/generate.runtime-N1KtAG8C.js.map +0 -1
- package/dist/chunks/generate.runtime-aN5QWygO.js.map +0 -1
- package/dist/chunks/shopify-page-D-VFwGxI.js +0 -11
- package/dist/chunks/shopify-page-D-VFwGxI.js.map +0 -1
- package/dist/chunks/write-result-0HYIr5a6.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
2
|
import { n as t } from "./logger-CQONztPm.js";
|
|
3
|
-
import { _ as n, r } from "./ts-morph-helpers-
|
|
4
|
-
import { r as i } from "./modify-file-
|
|
3
|
+
import { _ as n, r } from "./ts-morph-helpers-CHI9wAil.js";
|
|
4
|
+
import { r as i } from "./modify-file-COBp4eCh.js";
|
|
5
5
|
import { t as a } from "./svelte-file-Dv5-bl79.js";
|
|
6
6
|
import o from "node:fs";
|
|
7
7
|
import s from "node:path";
|
|
@@ -79,4 +79,4 @@ async function h(e) {
|
|
|
79
79
|
//#endregion
|
|
80
80
|
export { h as generate, m as hasStripeCustomer };
|
|
81
81
|
|
|
82
|
-
//# sourceMappingURL=generate.runtime-
|
|
82
|
+
//# sourceMappingURL=generate.runtime-si5Za61F.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-si5Za61F.js","names":["dedent","getLogger","withInMemoryScript","modifyOutcomeToFile","SvelteFile","fs","path","CART_BUTTON_MODULE","CART_NAVBAR_ITEM","IMPORT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","modifyRootLayoutSvelte","layoutPath","file","out","source","sf","authItem","items","lastItem","hasStripeCustomer","root","generate","logger","options","modifies"],"sources":["../../src/patterns/enable/ecommerce/modifies/root-layout.svelte.ts","../../src/patterns/enable/ecommerce/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport const CART_BUTTON_MODULE = \"#lib/components/cart/cart-button.svelte\";\n\nconst CART_NAVBAR_ITEM = \"<Navbar.Item>\\n\\t<CartButton />\\n</Navbar.Item>\";\n\nconst IMPORT_SNIPPET = `import CartButton from '${CART_BUTTON_MODULE}';`;\n\nconst FAILURE_HINT = dedent`\n Add the cart button inside your <Navbar.List> in the root layout.\n\n Import to add to the <script> tag:\n\n ${IMPORT_SNIPPET}\n\n Markup to add inside <Navbar.List>:\n\n ${CART_NAVBAR_ITEM}\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Add the cart button to the layout your public pages share.\n\n Import for the <script> tag:\n\n ${IMPORT_SNIPPET}\n\n Markup, wherever your navigation is:\n\n <CartButton />\n`;\n\n/**\n * Puts the cart button in the navbar: left of the account menu when auth\n * added one, else after the last item.\n */\nexport function modifyRootLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"CartButton\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n { defaultImport: \"CartButton\", moduleSpecifier: CART_BUTTON_MODULE },\n ]);\n });\n return out;\n });\n\n const authItem = file.findElementContaining(\"Navbar.Item\", \"AuthMenu.Root\");\n const items = file.childElements(\"Navbar.List\", \"Navbar.Item\");\n const lastItem = items[items.length - 1];\n if (authItem) {\n file.insertBeforeElement(authItem, CART_NAVBAR_ITEM);\n } else if (lastItem) {\n file.insertAfterElement(lastItem, CART_NAVBAR_ITEM);\n } else {\n file.insertBeforeClosingTag(\n \"Navbar.List\",\n `\\n\\t\\t${CART_NAVBAR_ITEM.replace(/\\n/g, \"\\n\\t\\t\")}\\n\\t`,\n );\n }\n\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyRootLayoutSvelte } from \"./modifies/root-layout.svelte\";\n\n/** Created by enable-payments for Stripe when auth was already on. */\nexport function hasStripeCustomer(root: string): boolean {\n return fs.existsSync(\n path.join(root, \"src\", \"lib\", \"server\", \"stripe-customer.ts\"),\n );\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n logger.info(\"Adding the cart to the navbar\");\n const layoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"root-layout.svelte\",\n );\n const file = modifyOutcomeToFile(\n layoutPath,\n modifyRootLayoutSvelte(layoutPath),\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":";;;;;;;;AASA,IAAaO,IAAqB,2CAE5BC,IAAmB,kDAEnBC,IAAiB,2BAA2BF,EAAmB,KAE/DG,IAAe,CAAM;;;;;IAKvBD,EAAe;;;;IAIfD,EAAiB;GAGfG,IAAiB,CAAM;;;;;IAKzBF,EAAe;;;;;;AAWnB,SAAgBG,EAAuB,GAAmC;CACxE,IAAI,CAACP,EAAG,WAAWQ,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAa,SAASF;CAAe;CAGxD,IAAMG,IAAOV,EAAW,SAASS,CAAU;CAC3C,IAAI,CAACC,EAAK,WAAW,aAAa,GAChC,OAAO;EAAE,QAAQ;EAAU,SAASJ;CAAa;CAEnD,IAAII,EAAK,WAAW,YAAY,GAC9B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQC,MAAQb,EAAmBc,IAAS,MAAO;GACzD,EAAcC,GAAI,CAChB;IAAE,eAAe;IAAc,iBAAiBV;GAAmB,CACrE,CAAC;EACH,CAAC;EACD,OAAOQ;CACT,CAAC;CAED,IAAMG,IAAWJ,EAAK,sBAAsB,eAAe,eAAe,GACpEK,IAAQL,EAAK,cAAc,eAAe,aAAa,GACvDM,IAAWD,EAAMA,EAAM,SAAS;CAatC,OAZID,IACFJ,EAAK,oBAAoBI,GAAUV,CAAgB,IAC1CY,IACTN,EAAK,mBAAmBM,GAAUZ,CAAgB,IAElDM,EAAK,uBACH,eACA,SAASN,EAAiB,QAAQ,OAAO,MAAQ,EAAE,KACrD,GAGFM,EAAK,QAAQD,CAAU,GAChB;EAAE,QAAQ;EAAW,SAASC,EAAK,WAAW;CAAE;AACzD;;;ACzEA,SAAgBO,EAAkB,GAAuB;CACvD,OAAOhB,EAAG,WACRC,EAAK,KAAKgB,GAAM,OAAO,OAAO,UAAU,oBAAoB,CAC9D;AACF;AAEA,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASvB,EAAUwB,CAAO,GAC1BC,IAAmB,CAAC;CAE1B,EAAO,KAAK,+BAA+B;CAC3C,IAAMb,IAAaP,EAAK,KACtBmB,EAAQ,MACR,OACA,UACA,YACA,oBACF,GACMX,IAAOX,EACXU,GACAD,EAAuBC,CAAU,CACnC;CAGA,OAFIC,KAAMY,EAAS,KAAKZ,CAAI,GAErB;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
2
|
import { n as t } from "./logger-CQONztPm.js";
|
|
3
3
|
import { t as n } from "./env-vars-Cr4lbMD_.js";
|
|
4
|
-
import { o as r } from "./ts-morph-helpers-
|
|
5
|
-
import { r as i } from "./modify-file-
|
|
6
|
-
import { modifyEnvVarsFiles as a } from "./env-vars-
|
|
4
|
+
import { o as r } from "./ts-morph-helpers-CHI9wAil.js";
|
|
5
|
+
import { r as i } from "./modify-file-COBp4eCh.js";
|
|
6
|
+
import { modifyEnvVarsFiles as a } from "./env-vars-CdarYsrc.js";
|
|
7
7
|
import o from "node:fs";
|
|
8
8
|
import s from "node:path";
|
|
9
9
|
import { Project as c, QuoteKind as l } from "ts-morph";
|
|
@@ -30,18 +30,14 @@ var u = e`
|
|
|
30
30
|
`;
|
|
31
31
|
function p(e, t, n, r = !1) {
|
|
32
32
|
let i = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t);
|
|
33
|
-
|
|
34
|
-
e.addImportDeclaration({
|
|
35
|
-
isTypeOnly: r,
|
|
36
|
-
namedImports: [n],
|
|
37
|
-
moduleSpecifier: t
|
|
38
|
-
});
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
i.getNamedImports().some((e) => e.getName() === n) || i.addNamedImport(r && !i.isTypeOnly() ? {
|
|
33
|
+
i ? i.getNamedImports().some((e) => e.getName() === n) || i.addNamedImport(r && !i.isTypeOnly() ? {
|
|
42
34
|
name: n,
|
|
43
35
|
isTypeOnly: !0
|
|
44
|
-
} : n)
|
|
36
|
+
} : n) : e.addImportDeclaration({
|
|
37
|
+
isTypeOnly: r,
|
|
38
|
+
namedImports: [n],
|
|
39
|
+
moduleSpecifier: t
|
|
40
|
+
});
|
|
45
41
|
}
|
|
46
42
|
function m(e) {
|
|
47
43
|
return e.getVariableDeclaration("init") || e.getFunction("init") ? !0 : e.getExportDeclarations().some((e) => e.getNamedExports().some((e) => e.getName() === "init"));
|
|
@@ -89,4 +85,4 @@ async function g(e) {
|
|
|
89
85
|
//#endregion
|
|
90
86
|
export { g as generate };
|
|
91
87
|
|
|
92
|
-
//# sourceMappingURL=generate.runtime-
|
|
88
|
+
//# sourceMappingURL=generate.runtime-tGKorg85.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-tGKorg85.js","names":["dedent","getLogger","WORKFLOWS_ENV_VARS","formatLikeSource","modifyOutcomeToFile","fs","path","INIT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","ensureNamedImport","existing","sourceFile","d","moduleSpecifier","ni","name","typeOnly","hasInitExport","modifyHooksServerWorkflows","hooksServerPath","Project","QuoteKind","generate","logger","options","creates","modifies","hooksFile","envVars","modifyEnvVarsFiles"],"sources":["../../src/patterns/enable/workflows/modifies/hooks.server.ts","../../src/patterns/enable/workflows/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst INIT_SNIPPET = dedent`\n // Runs once when the server starts: executes the workflows in src/lib/workflows.\n export const init: ServerInit = () => startWorker();\n`;\n\nconst FAILURE_HINT = dedent`\n src/hooks.server.ts already exports an init hook. Start the workflow worker from it:\n\n import { startWorker } from '#lib/server/workflows.js';\n\n export const init: ServerInit = async () => {\n await startWorker();\n // ...the rest of your init\n };\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts and start the workflow worker from its init hook:\n\n import type { ServerInit } from '@sveltejs/kit/hooks';\n import { startWorker } from '#lib/server/workflows.js';\n\n export const init: ServerInit = () => startWorker();\n`;\n\nfunction ensureNamedImport(\n sourceFile: SourceFile,\n moduleSpecifier: string,\n name: string,\n typeOnly = false,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (!existing) {\n sourceFile.addImportDeclaration({\n isTypeOnly: typeOnly,\n namedImports: [name],\n moduleSpecifier,\n });\n return;\n }\n if (existing.getNamedImports().some((ni) => ni.getName() === name)) return;\n // A declaration that is already `import type` covers the new name; a value\n // import takes the name as an inline `type` specifier.\n existing.addNamedImport(\n typeOnly && !existing.isTypeOnly() ? { name, isTypeOnly: true } : name,\n );\n}\n\nfunction hasInitExport(sourceFile: SourceFile): boolean {\n if (sourceFile.getVariableDeclaration(\"init\")) return true;\n if (sourceFile.getFunction(\"init\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) => d.getNamedExports().some((e) => e.getName() === \"init\"));\n}\n\n/**\n * Adds the `init` hook that starts the workflow worker. Projects created from\n * the base template already have it; this is the upgrade path for older ones.\n */\nexport function modifyHooksServerWorkflows(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"startWorker\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n if (hasInitExport(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNamedImport(sourceFile, \"@sveltejs/kit/hooks\", \"ServerInit\", true);\n ensureNamedImport(sourceFile, \"#lib/server/workflows.js\", \"startWorker\");\n\n // After everything else, so the hook reads as the last thing the server does on start.\n sourceFile.addStatements(`\\n${INIT_SNIPPET}`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyHooksServerWorkflows } from \"./modifies/hooks.server\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { WORKFLOWS_ENV_VARS } from \"./env-vars\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n const modifies: File[] = [];\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerWorkflows(hooksServerPath),\n );\n if (hooksFile) modifies.push(hooksFile);\n\n // SvelteKit 3 exposes only declared variables; the template declares these\n // already, an older project gets whichever it is missing.\n logger.info(\"Declaring the workflow variables in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, WORKFLOWS_ENV_VARS);\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\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":";;;;;;;;;;AAMA,IAAMO,IAAe,CAAM;;;GAKrBC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W,SAAS,GACb;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C;;;AC3FA,eAAsBW,EAAS,GAAkB;CAC/C,IAAMC,IAASvB,EAAUwB,CAAO,GAC1BC,IAAkB,CAAC,GACnBC,IAAmB,CAAC;CAE1B,EAAO,KAAK,2BAA2B;CACvC,IAAMP,IAAkBd,EAAK,KAAKmB,EAAQ,MAAM,OAAO,iBAAiB,GAClEG,IAAYxB,EAChBgB,GACAD,EAA2BC,CAAe,CAC5C;CAKA,AAJIQ,KAAWD,EAAS,KAAKC,CAAS,GAItCJ,EAAO,KAAK,gDAAgD;CAC5D,IAAMK,IAAUC,EAAmBL,EAAQ,MAAMvB,CAAkB;CAInE,OAHI2B,EAAQ,UAAQH,EAAQ,KAAKG,EAAQ,MAAM,GAC3CA,EAAQ,UAAQF,EAAS,KAAKE,EAAQ,MAAM,GAEzC;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { n as e } from "./logger-CQONztPm.js";
|
|
2
2
|
import { n as t, t as n } from "./_page-DoPdZgZv.js";
|
|
3
|
-
import { t as r } from "./shared-
|
|
4
|
-
import { _ as i, h as a, o, u as s } from "./ts-morph-helpers-
|
|
5
|
-
import { r as c } from "./modify-file-
|
|
3
|
+
import { t as r } from "./shared-C_Fr8wph.js";
|
|
4
|
+
import { _ as i, h as a, o, u as s } from "./ts-morph-helpers-CHI9wAil.js";
|
|
5
|
+
import { r as c } from "./modify-file-COBp4eCh.js";
|
|
6
6
|
import { t as l } from "./svelte-file-Dv5-bl79.js";
|
|
7
|
-
import { t as u } from "./unmodify-load-
|
|
8
|
-
import { r as d, t as f } from "./modify-nav-user-
|
|
7
|
+
import { t as u } from "./unmodify-load-Buak-r1f.js";
|
|
8
|
+
import { r as d, t as f } from "./modify-nav-user-CJ1LevSU.js";
|
|
9
9
|
import p from "node:fs";
|
|
10
10
|
import m from "node:path";
|
|
11
11
|
import { Project as h, QuoteKind as g, SyntaxKind as _ } from "ts-morph";
|
|
@@ -215,4 +215,4 @@ async function O(i) {
|
|
|
215
215
|
//#endregion
|
|
216
216
|
export { O as generate };
|
|
217
217
|
|
|
218
|
-
//# sourceMappingURL=generate.runtime-
|
|
218
|
+
//# sourceMappingURL=generate.runtime-ww3-1FWf.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-BVavIXtX.js","names":["paymentsBillingPageServerTemplate","paymentsBillingPageSvelteTemplate","getLogger","_page_server_default","_page_default","planDropsForCollections","withInMemoryScript","removeTopLevelStatementByIdentifier","removeImportByModuleSpecifier","modifyOutcomeToFile","SvelteFile","removeFromLoad","propsStatement","bindingText","fs","path","SUBSCRIPTION_CASE_VALUES","unmodifyWebhookServer","filePath","original","sf","switchStmt","SyntaxKind","stmt","toRemove","clause","expr","literal","c","spaced","source","unmodifyAppLayoutSvelte","file","updateScript","out","decl","init","nameNode","pattern","elements","hasSub","typeNode","intersection","member","lit","propTexts","p","t","remaining","unmodifyAppSidebar","hasSubPropType","hasSubProp","hasNavUserSubAttr","unmodifyAppLayoutServer","fromLoad","Project","QuoteKind","formatLikeSource","unmodifyNavUser","content","binding","kept","revertByTemplate","current","enabledMarker","stripped","template","unmodifyBillingPageServer","paymentsBillingPageServerTemplate","unmodifyBillingPageSvelte","paymentsBillingPageSvelteTemplate","generate","logger","options","modifies","pushResult","webhookServerPath","appLayoutServerPath","appLayoutSveltePath","appSidebarPath","navUserPath","billingPageServerPath","billingPageSveltePath"],"sources":["../../src/patterns/disable/subscriptions/modifies/modify-webhook-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-layout-svelte.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-sidebar.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-layout-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-nav-user.ts","../../src/patterns/disable/subscriptions/modifies/revert-by-template.ts","../../src/patterns/disable/subscriptions/modifies/modify-billing-page-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-billing-page-svelte.ts","../../src/patterns/disable/subscriptions/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n removeImportByModuleSpecifier,\n withInMemoryScript,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst SUBSCRIPTION_CASE_VALUES = new Set([\n \"customer.subscription.created\",\n \"customer.subscription.updated\",\n \"customer.subscription.deleted\",\n]);\n\nexport function unmodifyWebhookServer(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n if (!original.includes(\"handleSubscriptionCreated\")) {\n return { status: \"success\", changed: false };\n }\n\n const { source } = withInMemoryScript(original, (sf) => {\n removeImportByModuleSpecifier(sf, \"./subscription/created\");\n removeImportByModuleSpecifier(sf, \"./subscription/updated\");\n removeImportByModuleSpecifier(sf, \"./subscription/deleted\");\n\n const switchStmt = sf\n .getDescendantsOfKind(SyntaxKind.SwitchStatement)\n .find((stmt) => stmt.getExpression().getText().includes(\"event.type\"));\n if (!switchStmt) return;\n\n const caseBlock = switchStmt.getCaseBlock();\n // Collect matching case clauses first — removing invalidates node refs.\n const toRemove = caseBlock\n .getClauses()\n .filter((clause) => {\n if (clause.getKind() !== SyntaxKind.CaseClause) return false;\n const caseClause = clause.asKindOrThrow(SyntaxKind.CaseClause);\n const expr = caseClause.getExpression();\n const literal =\n expr.asKind(SyntaxKind.StringLiteral) ??\n expr.asKind(SyntaxKind.NoSubstitutionTemplateLiteral);\n if (!literal) return false;\n return SUBSCRIPTION_CASE_VALUES.has(literal.getLiteralValue());\n })\n .map((c) => c.asKindOrThrow(SyntaxKind.CaseClause));\n\n for (const clause of toRemove.reverse()) {\n clause.remove();\n }\n\n formatLikeSource(sf);\n });\n\n // Removing the clauses takes the blank line before `default:` with them.\n const spaced = source.replace(/(break;)\\n(\\s*default:)/, \"$1\\n\\n$2\");\n\n if (spaced === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(filePath, spaced, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyAppLayoutSvelte(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(filePath);\n if (!file.hasElement(\"AppSidebar\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.hasAttribute(\"AppSidebar\", \"subscription\")) {\n return { status: \"success\", changed: false };\n }\n\n const removed = file.removeAttribute(\"AppSidebar\", \"subscription\");\n if (!removed) {\n return { status: \"success\", changed: false };\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n withInMemoryScript,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nfunction updateScript(source: string): string {\n const { source: out } = withInMemoryScript(source, (sf) => {\n for (const decl of sf.getVariableDeclarations()) {\n const init = decl.getInitializer();\n if (!init || init.getText() !== \"$props()\") continue;\n\n const nameNode = decl.getNameNode();\n if (nameNode.getKind() !== SyntaxKind.ObjectBindingPattern) continue;\n const pattern = nameNode.asKindOrThrow(SyntaxKind.ObjectBindingPattern);\n const elements = pattern.getElements();\n const hasSub = elements.some((e) => e.getName() === \"subscription\");\n\n // Strip subscription from the props type literal (the specific type\n // added by enable-subscriptions — leave unrelated `subscription` props\n // alone).\n const typeNode = decl.getTypeNode();\n if (typeNode?.getKind() === SyntaxKind.IntersectionType) {\n const intersection = typeNode.asKindOrThrow(\n SyntaxKind.IntersectionType,\n );\n for (const member of intersection.getTypeNodes()) {\n if (member.getKind() !== SyntaxKind.TypeLiteral) continue;\n const lit = member.asKindOrThrow(SyntaxKind.TypeLiteral);\n const propTexts = lit\n .getProperties()\n .map((p) => p.getText().replace(/[;,]\\s*$/, \"\"))\n .filter((t) => !/^\\s*subscription\\??\\s*:/.test(t));\n lit.replaceWithText(\n propTexts.length ? `{ ${propTexts.join(\"; \")}; }` : \"{}\",\n );\n break;\n }\n }\n\n if (hasSub) {\n const remaining = elements\n .filter((e) => e.getName() !== \"subscription\")\n .map((e) => e.getText());\n pattern.replaceWithText(`{ ${remaining.join(\", \")} }`);\n }\n }\n formatLikeSource(sf);\n });\n return out;\n}\n\nexport function unmodifyAppSidebar(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(filePath, \"utf8\");\n const hasSubPropType = /subscription\\??\\s*:\\s*\\{/.test(source);\n const hasSubProp = /\\bsubscription\\s*=\\s*null\\b/.test(source);\n\n const file = new SvelteFile(source);\n const hasNavUserSubAttr =\n file.hasElement(\"NavUser\") && file.hasAttribute(\"NavUser\", \"subscription\");\n\n if (!hasSubPropType && !hasSubProp && !hasNavUserSubAttr) {\n return { status: \"success\", changed: false };\n }\n\n if (hasSubPropType || hasSubProp) {\n file.modifyScript(updateScript);\n }\n if (hasNavUserSubAttr) {\n file.removeAttribute(\"NavUser\", \"subscription\");\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport { Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeFromLoad } from \"../../../../runtime/unmodify-load\";\nimport {\n formatLikeSource,\n removeTopLevelStatementByIdentifier,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/**\n * Takes out what enable-subscriptions added to the (app) layout load: the\n * `subscription` it loads and returns, and the `loadActiveSubscription`\n * helper. The rest of the load (what other patterns added) stays.\n */\nexport function unmodifyAppLayoutServer(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n if (!original.includes(\"loadActiveSubscription\")) {\n return { status: \"success\", changed: false };\n }\n\n const fromLoad = removeFromLoad(filePath, {\n variables: [\"subscription\"],\n dependsKeys: [],\n returnProps: [\"subscription\"],\n });\n if (fromLoad.status !== \"success\") return fromLoad;\n\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sf = project.addSourceFileAtPath(filePath);\n removeTopLevelStatementByIdentifier(sf, \"loadActiveSubscription\");\n formatLikeSource(sf);\n sf.saveSync();\n\n return {\n status: \"success\",\n changed: fs.readFileSync(filePath, \"utf8\") !== original,\n };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { withInMemoryScript } from \"../../../../runtime/ts-morph-helpers\";\nimport {\n bindingText,\n propsStatement,\n} from \"../../../enable/subscriptions/modifies/modify-nav-user\";\n\n/**\n * Takes the plan label out of nav-user: the lines showing it, `planLabel`\n * and the `subscription` prop. What other patterns added stays.\n */\nexport function unmodifyNavUser(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n if (!original.includes(\"planLabel\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(original);\n file.modifyScript(\n (content) =>\n withInMemoryScript(\n // With the blank line enable-subscriptions put before it.\n content.replace(\n /\\n[ \\t]*\\n[ \\t]*const planLabel = \\$derived\\([^\\n]*\\);/,\n \"\",\n ),\n (sf) => {\n const decl = propsStatement(sf)?.getDeclarations()[0];\n const binding = decl\n ?.getNameNode()\n .asKind(SyntaxKind.ObjectBindingPattern);\n const kept = binding\n ?.getElements()\n .filter((e) => e.getName() !== \"subscription\")\n .map((e) => e.getText());\n if (binding && kept) {\n binding.replaceWithText(bindingText(binding.getText(), kept));\n }\n decl\n ?.getTypeNode()\n ?.asKind(SyntaxKind.TypeLiteral)\n ?.getProperty(\"subscription\")\n ?.remove();\n },\n ).source,\n );\n\n // The lines under the name, with the line break before them.\n const out = file\n .toString()\n .replace(/\\n[ \\t]*<span class=\"[^\"]*\">\\s*\\{planLabel\\}\\s*<\\/span>/g, \"\");\n\n fs.writeFileSync(filePath, out, \"utf8\");\n return { status: \"success\", changed: out !== original };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * Rewrites a file to the given `template` if the current content still shows\n * the `enabledMarker` (meaning enable-subscriptions is applied). If the marker\n * is absent (already reverted or never applied), it's a no-op.\n *\n * Strips leading `// [!code highlight:N]` / `<!-- [!code highlight:N] -->`\n * lines so templates can be pulled from `preview-modifies/` directories which\n * use those for documentation highlighting.\n */\nexport function revertByTemplate(\n filePath: string,\n template: string,\n enabledMarker: string,\n): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const current = fs.readFileSync(filePath, \"utf8\");\n if (!current.includes(enabledMarker)) {\n return { status: \"success\", changed: false };\n }\n const stripped = template\n .replace(/^[ \\t]*\\/\\/[ \\t]*\\[!code highlight:\\d+\\][ \\t]*\\r?\\n/gm, \"\")\n .replace(\n /^[ \\t]*<!--[ \\t]*\\[!code highlight:\\d+\\][ \\t]*-->[ \\t]*\\r?\\n/gm,\n \"\",\n );\n if (current === stripped) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(filePath, stripped, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import { revertByTemplate } from \"./revert-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyBillingPageServer(\n filePath: string,\n paymentsBillingPageServerTemplate: string,\n): ModifyOutcome {\n return revertByTemplate(\n filePath,\n paymentsBillingPageServerTemplate,\n \"selectPlan\",\n );\n}\n","import { revertByTemplate } from \"./revert-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyBillingPageSvelte(\n filePath: string,\n paymentsBillingPageSvelteTemplate: string,\n): ModifyOutcome {\n return revertByTemplate(\n filePath,\n paymentsBillingPageSvelteTemplate,\n \"availablePlans\",\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 { unmodifyWebhookServer } from \"./modifies/modify-webhook-server\";\nimport { unmodifyAppLayoutSvelte } from \"./modifies/modify-app-layout-svelte\";\nimport { unmodifyAppSidebar } from \"./modifies/modify-app-sidebar\";\nimport { unmodifyAppLayoutServer } from \"./modifies/modify-app-layout-server\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { unmodifyBillingPageServer } from \"./modifies/modify-billing-page-server\";\nimport { unmodifyBillingPageSvelte } from \"./modifies/modify-billing-page-svelte\";\n\n// Pull the \"post-payments\" state of files that enable-subscriptions fully\n// overwrote. For the billing pages, that's exactly what enable-payments\n// writes in creates-app-mode; for nav-user it's the payments preview-modifies\n// snapshot (with highlight annotations stripped by the revert helper).\nimport paymentsBillingPageServerTemplate from \"../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/+page.server.ts?raw\";\nimport paymentsBillingPageSvelteTemplate from \"../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/+page.svelte?raw\";\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 webhooks/stripe/handlers/dispatch.ts\");\n const webhookServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"handlers\",\n \"dispatch.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n webhookServerPath,\n unmodifyWebhookServer(webhookServerPath),\n ),\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 unmodifyAppLayoutServer(appLayoutServerPath),\n ),\n );\n\n logger.info(\"Reverting (app)/+layout.svelte\");\n const appLayoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutSveltePath,\n unmodifyAppLayoutSvelte(appLayoutSveltePath),\n ),\n );\n\n logger.info(\"Reverting app-sidebar.svelte\");\n const appSidebarPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"app-sidebar.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appSidebarPath, unmodifyAppSidebar(appSidebarPath)),\n );\n\n logger.info(\"Reverting nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n logger.info(\"Reverting billing/+page.server.ts\");\n const billingPageServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageServerPath,\n unmodifyBillingPageServer(\n billingPageServerPath,\n paymentsBillingPageServerTemplate,\n ),\n ),\n );\n\n logger.info(\"Reverting billing/+page.svelte\");\n const billingPageSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageSveltePath,\n unmodifyBillingPageSvelte(\n billingPageSveltePath,\n paymentsBillingPageSvelteTemplate,\n ),\n ),\n );\n\n const collectionDrops = await planDropsForCollections(\n [\"stripe_subscriptions\"],\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":";;;;;;;;;;;;AASA,IAAMgB,oBAA2B,IAAI,IAAI;CACvC;CACA;CACA;AACF,CAAC;AAED,SAAgBC,EAAsB,GAAiC;CACrE,IAAI,CAACH,EAAG,WAAWI,CAAQ,GACzB,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE7C,IAAMC,IAAWL,EAAG,aAAaI,GAAU,MAAM;CACjD,IAAI,CAACC,EAAS,SAAS,2BAA2B,GAChD,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,EAAE,cAAWb,EAAmBa,IAAW,MAAO;EAGtD,AAFAX,EAA8BY,GAAI,wBAAwB,GAC1DZ,EAA8BY,GAAI,wBAAwB,GAC1DZ,EAA8BY,GAAI,wBAAwB;EAE1D,IAAMC,IAAaD,EAChB,qBAAqBE,EAAW,eAAe,CAAC,CAChD,MAAM,MAASC,EAAK,cAAc,CAAC,CAAC,QAAQ,CAAC,CAAC,SAAS,YAAY,CAAC;EACvE,IAAI,CAACF,GAAY;EAIjB,IAAMG,IAFYH,EAAW,aAEZ,CAAA,CACd,WAAW,CAAC,CACZ,QAAQ,MAAW;GAClB,IAAII,EAAO,QAAQ,MAAMH,EAAW,YAAY,OAAO;GAEvD,IAAMI,IADaD,EAAO,cAAcH,EAAW,UACtC,CAAA,CAAW,cAAc,GAChCK,IACJD,EAAK,OAAOJ,EAAW,aAAa,KACpCI,EAAK,OAAOJ,EAAW,6BAA6B;GAEtD,OADKK,IACEX,EAAyB,IAAIW,EAAQ,gBAAgB,CAAC,IADxC;EAEvB,CAAC,CAAC,CACD,KAAK,MAAMC,EAAE,cAAcN,EAAW,UAAU,CAAC;EAEpD,KA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,MAb4BI,EAC5B,CAAC,sBAAsB,GACvBoE,CACF;CAWA;AACF"}
|
|
1
|
+
{"version":3,"file":"generate.runtime-ww3-1FWf.js","names":["paymentsBillingPageServerTemplate","paymentsBillingPageSvelteTemplate","getLogger","_page_server_default","_page_default","planDropsForCollections","withInMemoryScript","removeTopLevelStatementByIdentifier","removeImportByModuleSpecifier","modifyOutcomeToFile","SvelteFile","removeFromLoad","propsStatement","bindingText","fs","path","SUBSCRIPTION_CASE_VALUES","unmodifyWebhookServer","filePath","original","sf","switchStmt","SyntaxKind","stmt","toRemove","clause","expr","literal","c","spaced","source","unmodifyAppLayoutSvelte","file","updateScript","out","decl","init","nameNode","pattern","elements","hasSub","typeNode","intersection","member","lit","propTexts","p","t","remaining","unmodifyAppSidebar","hasSubPropType","hasSubProp","hasNavUserSubAttr","unmodifyAppLayoutServer","fromLoad","Project","QuoteKind","formatLikeSource","unmodifyNavUser","content","binding","kept","revertByTemplate","current","enabledMarker","stripped","template","unmodifyBillingPageServer","paymentsBillingPageServerTemplate","unmodifyBillingPageSvelte","paymentsBillingPageSvelteTemplate","generate","logger","options","modifies","pushResult","webhookServerPath","appLayoutServerPath","appLayoutSveltePath","appSidebarPath","navUserPath","billingPageServerPath","billingPageSveltePath"],"sources":["../../src/patterns/disable/subscriptions/modifies/modify-webhook-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-layout-svelte.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-sidebar.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-layout-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-nav-user.ts","../../src/patterns/disable/subscriptions/modifies/revert-by-template.ts","../../src/patterns/disable/subscriptions/modifies/modify-billing-page-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-billing-page-svelte.ts","../../src/patterns/disable/subscriptions/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n removeImportByModuleSpecifier,\n withInMemoryScript,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst SUBSCRIPTION_CASE_VALUES = new Set([\n \"customer.subscription.created\",\n \"customer.subscription.updated\",\n \"customer.subscription.deleted\",\n]);\n\nexport function unmodifyWebhookServer(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n if (!original.includes(\"handleSubscriptionCreated\")) {\n return { status: \"success\", changed: false };\n }\n\n const { source } = withInMemoryScript(original, (sf) => {\n removeImportByModuleSpecifier(sf, \"./subscription/created\");\n removeImportByModuleSpecifier(sf, \"./subscription/updated\");\n removeImportByModuleSpecifier(sf, \"./subscription/deleted\");\n\n const switchStmt = sf\n .getDescendantsOfKind(SyntaxKind.SwitchStatement)\n .find((stmt) => stmt.getExpression().getText().includes(\"event.type\"));\n if (!switchStmt) return;\n\n const caseBlock = switchStmt.getCaseBlock();\n // Collect matching case clauses first — removing invalidates node refs.\n const toRemove = caseBlock\n .getClauses()\n .filter((clause) => {\n if (clause.getKind() !== SyntaxKind.CaseClause) return false;\n const caseClause = clause.asKindOrThrow(SyntaxKind.CaseClause);\n const expr = caseClause.getExpression();\n const literal =\n expr.asKind(SyntaxKind.StringLiteral) ??\n expr.asKind(SyntaxKind.NoSubstitutionTemplateLiteral);\n if (!literal) return false;\n return SUBSCRIPTION_CASE_VALUES.has(literal.getLiteralValue());\n })\n .map((c) => c.asKindOrThrow(SyntaxKind.CaseClause));\n\n for (const clause of toRemove.reverse()) {\n clause.remove();\n }\n\n formatLikeSource(sf);\n });\n\n // Removing the clauses takes the blank line before `default:` with them.\n const spaced = source.replace(/(break;)\\n(\\s*default:)/, \"$1\\n\\n$2\");\n\n if (spaced === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(filePath, spaced, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyAppLayoutSvelte(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(filePath);\n if (!file.hasElement(\"AppSidebar\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.hasAttribute(\"AppSidebar\", \"subscription\")) {\n return { status: \"success\", changed: false };\n }\n\n const removed = file.removeAttribute(\"AppSidebar\", \"subscription\");\n if (!removed) {\n return { status: \"success\", changed: false };\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n withInMemoryScript,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nfunction updateScript(source: string): string {\n const { source: out } = withInMemoryScript(source, (sf) => {\n for (const decl of sf.getVariableDeclarations()) {\n const init = decl.getInitializer();\n if (!init || init.getText() !== \"$props()\") continue;\n\n const nameNode = decl.getNameNode();\n if (nameNode.getKind() !== SyntaxKind.ObjectBindingPattern) continue;\n const pattern = nameNode.asKindOrThrow(SyntaxKind.ObjectBindingPattern);\n const elements = pattern.getElements();\n const hasSub = elements.some((e) => e.getName() === \"subscription\");\n\n // Strip subscription from the props type literal (the specific type\n // added by enable-subscriptions — leave unrelated `subscription` props\n // alone).\n const typeNode = decl.getTypeNode();\n if (typeNode?.getKind() === SyntaxKind.IntersectionType) {\n const intersection = typeNode.asKindOrThrow(\n SyntaxKind.IntersectionType,\n );\n for (const member of intersection.getTypeNodes()) {\n if (member.getKind() !== SyntaxKind.TypeLiteral) continue;\n const lit = member.asKindOrThrow(SyntaxKind.TypeLiteral);\n const propTexts = lit\n .getProperties()\n .map((p) => p.getText().replace(/[;,]\\s*$/, \"\"))\n .filter((t) => !/^\\s*subscription\\??\\s*:/.test(t));\n lit.replaceWithText(\n propTexts.length ? `{ ${propTexts.join(\"; \")}; }` : \"{}\",\n );\n break;\n }\n }\n\n if (hasSub) {\n const remaining = elements\n .filter((e) => e.getName() !== \"subscription\")\n .map((e) => e.getText());\n pattern.replaceWithText(`{ ${remaining.join(\", \")} }`);\n }\n }\n formatLikeSource(sf);\n });\n return out;\n}\n\nexport function unmodifyAppSidebar(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(filePath, \"utf8\");\n const hasSubPropType = /subscription\\??\\s*:\\s*\\{/.test(source);\n const hasSubProp = /\\bsubscription\\s*=\\s*null\\b/.test(source);\n\n const file = new SvelteFile(source);\n const hasNavUserSubAttr =\n file.hasElement(\"NavUser\") && file.hasAttribute(\"NavUser\", \"subscription\");\n\n if (!hasSubPropType && !hasSubProp && !hasNavUserSubAttr) {\n return { status: \"success\", changed: false };\n }\n\n if (hasSubPropType || hasSubProp) {\n file.modifyScript(updateScript);\n }\n if (hasNavUserSubAttr) {\n file.removeAttribute(\"NavUser\", \"subscription\");\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport { Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeFromLoad } from \"../../../../runtime/unmodify-load\";\nimport {\n formatLikeSource,\n removeTopLevelStatementByIdentifier,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/**\n * Takes out what enable-subscriptions added to the (app) layout load: the\n * `subscription` it loads and returns, and the `loadActiveSubscription`\n * helper. The rest of the load (what other patterns added) stays.\n */\nexport function unmodifyAppLayoutServer(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n if (!original.includes(\"loadActiveSubscription\")) {\n return { status: \"success\", changed: false };\n }\n\n const fromLoad = removeFromLoad(filePath, {\n variables: [\"subscription\"],\n dependsKeys: [],\n returnProps: [\"subscription\"],\n });\n if (fromLoad.status !== \"success\") return fromLoad;\n\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sf = project.addSourceFileAtPath(filePath);\n removeTopLevelStatementByIdentifier(sf, \"loadActiveSubscription\");\n formatLikeSource(sf);\n sf.saveSync();\n\n return {\n status: \"success\",\n changed: fs.readFileSync(filePath, \"utf8\") !== original,\n };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { withInMemoryScript } from \"../../../../runtime/ts-morph-helpers\";\nimport {\n bindingText,\n propsStatement,\n} from \"../../../enable/subscriptions/modifies/modify-nav-user\";\n\n/**\n * Takes the plan label out of nav-user: the lines showing it, `planLabel`\n * and the `subscription` prop. What other patterns added stays.\n */\nexport function unmodifyNavUser(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n if (!original.includes(\"planLabel\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(original);\n file.modifyScript(\n (content) =>\n withInMemoryScript(\n // With the blank line enable-subscriptions put before it.\n content.replace(\n /\\n[ \\t]*\\n[ \\t]*const planLabel = \\$derived\\([^\\n]*\\);/,\n \"\",\n ),\n (sf) => {\n const decl = propsStatement(sf)?.getDeclarations()[0];\n const binding = decl\n ?.getNameNode()\n .asKind(SyntaxKind.ObjectBindingPattern);\n const kept = binding\n ?.getElements()\n .filter((e) => e.getName() !== \"subscription\")\n .map((e) => e.getText());\n if (binding && kept) {\n binding.replaceWithText(bindingText(binding.getText(), kept));\n }\n decl\n ?.getTypeNode()\n ?.asKind(SyntaxKind.TypeLiteral)\n ?.getProperty(\"subscription\")\n ?.remove();\n },\n ).source,\n );\n\n // The lines under the name, with the line break before them.\n const out = file\n .toString()\n .replace(/\\n[ \\t]*<span class=\"[^\"]*\">\\s*\\{planLabel\\}\\s*<\\/span>/g, \"\");\n\n fs.writeFileSync(filePath, out, \"utf8\");\n return { status: \"success\", changed: out !== original };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * Rewrites a file to the given `template` if the current content still shows\n * the `enabledMarker` (meaning enable-subscriptions is applied). If the marker\n * is absent (already reverted or never applied), it's a no-op.\n *\n * Strips leading `// [!code highlight:N]` / `<!-- [!code highlight:N] -->`\n * lines so templates can be pulled from `preview-modifies/` directories which\n * use those for documentation highlighting.\n */\nexport function revertByTemplate(\n filePath: string,\n template: string,\n enabledMarker: string,\n): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const current = fs.readFileSync(filePath, \"utf8\");\n if (!current.includes(enabledMarker)) {\n return { status: \"success\", changed: false };\n }\n const stripped = template\n .replace(/^[ \\t]*\\/\\/[ \\t]*\\[!code highlight:\\d+\\][ \\t]*\\r?\\n/gm, \"\")\n .replace(\n /^[ \\t]*<!--[ \\t]*\\[!code highlight:\\d+\\][ \\t]*-->[ \\t]*\\r?\\n/gm,\n \"\",\n );\n if (current === stripped) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(filePath, stripped, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import { revertByTemplate } from \"./revert-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyBillingPageServer(\n filePath: string,\n paymentsBillingPageServerTemplate: string,\n): ModifyOutcome {\n return revertByTemplate(\n filePath,\n paymentsBillingPageServerTemplate,\n \"selectPlan\",\n );\n}\n","import { revertByTemplate } from \"./revert-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyBillingPageSvelte(\n filePath: string,\n paymentsBillingPageSvelteTemplate: string,\n): ModifyOutcome {\n return revertByTemplate(\n filePath,\n paymentsBillingPageSvelteTemplate,\n \"availablePlans\",\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 { unmodifyWebhookServer } from \"./modifies/modify-webhook-server\";\nimport { unmodifyAppLayoutSvelte } from \"./modifies/modify-app-layout-svelte\";\nimport { unmodifyAppSidebar } from \"./modifies/modify-app-sidebar\";\nimport { unmodifyAppLayoutServer } from \"./modifies/modify-app-layout-server\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { unmodifyBillingPageServer } from \"./modifies/modify-billing-page-server\";\nimport { unmodifyBillingPageSvelte } from \"./modifies/modify-billing-page-svelte\";\n\n// Pull the \"post-payments\" state of files that enable-subscriptions fully\n// overwrote. For the billing pages, that's exactly what enable-payments\n// writes in creates-app-mode; for nav-user it's the payments preview-modifies\n// snapshot (with highlight annotations stripped by the revert helper).\nimport paymentsBillingPageServerTemplate from \"../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/+page.server.ts?raw\";\nimport paymentsBillingPageSvelteTemplate from \"../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/+page.svelte?raw\";\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 webhooks/stripe/handlers/dispatch.ts\");\n const webhookServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"handlers\",\n \"dispatch.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n webhookServerPath,\n unmodifyWebhookServer(webhookServerPath),\n ),\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 unmodifyAppLayoutServer(appLayoutServerPath),\n ),\n );\n\n logger.info(\"Reverting (app)/+layout.svelte\");\n const appLayoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutSveltePath,\n unmodifyAppLayoutSvelte(appLayoutSveltePath),\n ),\n );\n\n logger.info(\"Reverting app-sidebar.svelte\");\n const appSidebarPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"app-sidebar.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appSidebarPath, unmodifyAppSidebar(appSidebarPath)),\n );\n\n logger.info(\"Reverting nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n logger.info(\"Reverting billing/+page.server.ts\");\n const billingPageServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageServerPath,\n unmodifyBillingPageServer(\n billingPageServerPath,\n paymentsBillingPageServerTemplate,\n ),\n ),\n );\n\n logger.info(\"Reverting billing/+page.svelte\");\n const billingPageSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageSveltePath,\n unmodifyBillingPageSvelte(\n billingPageSveltePath,\n paymentsBillingPageSvelteTemplate,\n ),\n ),\n );\n\n const collectionDrops = await planDropsForCollections(\n [\"stripe_subscriptions\"],\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":";;;;;;;;;;;;AASA,IAAMgB,oBAA2B,IAAI,IAA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ACAxB,EAAwBwB,CAAmB,CAC7C,CACF,GAEAL,EAAO,KAAK,gCAAgC;CAC5C,IAAMM,IAAsB/D,EAAK,KAC/B0D,EAAQ,MACR,OACA,UACA,SACA,gBACF;CAQA,AAPAE,EACElE,EACEqE,GACA/C,EAAwB+C,CAAmB,CAC7C,CACF,GAEAN,EAAO,KAAK,8BAA8B;CAC1C,IAAMO,IAAiBhE,EAAK,KAC1B0D,EAAQ,MACR,OACA,OACA,cACA,oBACF;CAKA,AAJAE,EACElE,EAAoBsE,GAAgB9B,EAAmB8B,CAAc,CAAC,CACxE,GAEAP,EAAO,KAAK,2BAA2B;CACvC,IAAMQ,IAAcjE,EAAK,KACvB0D,EAAQ,MACR,OACA,OACA,cACA,iBACF;CAGA,AAFAE,EAAWlE,EAAoBuE,GAAatB,EAAgBsB,CAAW,CAAC,CAAC,GAEzER,EAAO,KAAK,mCAAmC;CAC/C,IAAMS,IAAwBlE,EAAK,KACjC0D,EAAQ,MACR,OACA,UACA,SACA,WACA,iBACF;CAWA,AAVAE,EACElE,EACEwE,GACAd,EACEc,GACAjF,CACF,CACF,CACF,GAEAwE,EAAO,KAAK,gCAAgC;CAC5C,IAAMU,IAAwBnE,EAAK,KACjC0D,EAAQ,MACR,OACA,UACA,SACA,WACA,cACF;CAgBA,OAfAE,EACElE,EACEyE,GACAb,EACEa,GACAjF,CACF,CACF,CACF,GAOO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MAb4BI,EAC5B,CAAC,sBAAsB,GACvBoE,CACF;CAWA;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as e } from "./rolldown-runtime-
|
|
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-
|
|
4
|
-
import { _ as r, s as i } from "./ts-morph-helpers-
|
|
3
|
+
import { n } from "./shared-C_Fr8wph.js";
|
|
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";
|
|
7
7
|
//#region src/runtime/modify-file.ts
|
|
@@ -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-COBp4eCh.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modify-file-
|
|
1
|
+
{"version":3,"file":"modify-file-COBp4eCh.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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as e } from "./ts-morph-helpers-
|
|
1
|
+
import { _ as e } from "./ts-morph-helpers-CHI9wAil.js";
|
|
2
2
|
import { t } from "./svelte-file-Dv5-bl79.js";
|
|
3
3
|
import n from "node:fs";
|
|
4
4
|
import { SyntaxKind as r } from "ts-morph";
|
|
@@ -68,4 +68,4 @@ function f(r) {
|
|
|
68
68
|
//#endregion
|
|
69
69
|
export { f as n, l as r, u as t };
|
|
70
70
|
|
|
71
|
-
//# sourceMappingURL=modify-nav-user-
|
|
71
|
+
//# sourceMappingURL=modify-nav-user-CJ1LevSU.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modify-nav-user-
|
|
1
|
+
{"version":3,"file":"modify-nav-user-CJ1LevSU.js","names":["withInMemoryScript","fs","NOT_FOUND_HINT","FAILURE_HINT","SUBSCRIPTION_TYPE","PLAN_LABEL","PLAN_LINES","propsStatement","sf","s","d","SyntaxKind","bindingText","current","texts","indent","close","t","addSubscriptionProp","statement","decl","binding","type","rest","writer","modifyNavUser","filePath","original","file","SvelteFile","added","content","source","markupStart","names","out","i","match","end"],"sources":["../../src/patterns/enable/subscriptions/modifies/modify-nav-user.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SyntaxKind, type SourceFile, type VariableStatement } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { withInMemoryScript } from \"../../../../runtime/ts-morph-helpers\";\n\nconst NOT_FOUND_HINT = [\n \"src/lib/components/nav-user.svelte is missing.\",\n \"Enable auth and payments first; subscriptions layers a plan label on top of the existing nav-user.\",\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Could not find the props and the name lines in nav-user.svelte. Show the plan by hand:\",\n \"\",\n \"let { user, subscription = null }: { ...; subscription?: { id: string; productName: string | null } | null } = $props();\",\n \"const planLabel = $derived(subscription?.productName ?? 'Free');\",\n \"\",\n \"<!-- Under the name, in the trigger and in the dropdown label: -->\",\n '<span class=\"truncate text-xs text-muted-foreground\">{planLabel}</span>',\n].join(\"\\n\");\n\nconst SUBSCRIPTION_TYPE = \"{ id: string; productName: string | null } | null\";\nconst PLAN_LABEL =\n \"const planLabel = $derived(subscription?.productName ?? 'Free');\";\n\n/** The line under the name: muted in the trigger, plain in the dropdown label. */\nconst PLAN_LINES = [\n '<span class=\"truncate text-xs text-muted-foreground\">{planLabel}</span>',\n '<span class=\"truncate text-xs\">{planLabel}</span>',\n];\n\n/** `let { ... }: { ... } = $props();` */\nexport function propsStatement(sf: SourceFile): VariableStatement | undefined {\n return sf\n .getVariableStatements()\n .find((s) =>\n s\n .getDeclarations()\n .some(\n (d) =>\n d.getInitializer()?.getText() === \"$props()\" &&\n d.getNameNode().getKind() === SyntaxKind.ObjectBindingPattern,\n ),\n );\n}\n\n/** `{ a, b }` with `texts` as its elements, one per line if it was. */\nexport function bindingText(current: string, texts: string[]): string {\n if (!current.includes(\"\\n\")) return `{ ${texts.join(\", \")} }`;\n const indent = current.match(/\\n([ \\t]+)\\S/)?.[1] ?? \"\\t\";\n const close = current.match(/\\n([ \\t]*)\\}$/)?.[1] ?? \"\";\n return `{\\n${texts.map((t) => indent + t).join(\",\\n\")}\\n${close}}`;\n}\n\nfunction addSubscriptionProp(sf: SourceFile): boolean {\n const statement = propsStatement(sf);\n const decl = statement?.getDeclarations()[0];\n const binding = decl?.getNameNode().asKind(SyntaxKind.ObjectBindingPattern);\n const type = decl?.getTypeNode()?.asKind(SyntaxKind.TypeLiteral);\n if (!statement || !decl || !binding || !type) return false;\n\n if (!binding.getElements().some((e) => e.getName() === \"subscription\")) {\n const texts = binding.getElements().map((e) => e.getText());\n const rest = binding.getElements().findIndex((e) => e.getDotDotDotToken());\n texts.splice(rest === -1 ? texts.length : rest, 0, \"subscription = null\");\n binding.replaceWithText(bindingText(binding.getText(), texts));\n }\n if (!type.getProperty(\"subscription\")) {\n type.addProperty({\n name: \"subscription\",\n hasQuestionToken: true,\n type: SUBSCRIPTION_TYPE,\n });\n }\n sf.insertStatements(sf.getStatements().indexOf(statement) + 1, (writer) =>\n writer.blankLine().write(PLAN_LABEL),\n );\n return true;\n}\n\n/**\n * Shows the user's plan under their name in nav-user: a `subscription` prop\n * (the (app) layout passes it), `planLabel` from it, and a line under each\n * name. Edits the file rather than replacing it, so the items other patterns\n * added to the menu (teams, API keys) stay.\n */\nexport function modifyNavUser(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n if (original.includes(\"planLabel\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(original);\n let added = false;\n file.modifyScript(\n (content) =>\n withInMemoryScript(content, (sf) => {\n added = addSubscriptionProp(sf);\n }).source,\n );\n if (!added) return { status: \"failed\", message: FAILURE_HINT };\n\n // The name lines, in the markup after the script.\n const source = file.toString();\n const markupStart = source.indexOf(\"</script>\");\n const names = [\n ...source\n .slice(markupStart)\n .matchAll(\n /^([ \\t]*)<span class=\"truncate font-medium\">[\\s\\S]*?<\\/span>/gm,\n ),\n ];\n if (names.length < 2) return { status: \"failed\", message: FAILURE_HINT };\n\n let out = source;\n // From the last, so the earlier offsets stay put.\n for (const [i, match] of [...names.slice(0, 2).entries()].reverse()) {\n const end = markupStart + match.index! + match[0].length;\n out = `${out.slice(0, end)}\\n${match[1]}${PLAN_LINES[i]}${out.slice(end)}`;\n }\n\n fs.writeFileSync(filePath, out, \"utf8\");\n return { status: \"success\", changed: true };\n}\n"],"mappings":";;;;;AAMA,IAAME,IAAiB,CACrB,kDACA,oGACF,CAAC,CAAC,KAAK,IAAI,GAELC,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAELC,IAAoB,qDACpBC,IACJ,oEAGIC,IAAa,CACjB,6EACA,qDACF;AAGA,SAAgBC,EAAe,GAA+C;CAC5E,OAAOC,EACJ,sBAAsB,CAAC,CACvB,MAAM,MACLC,EACG,gBAAgB,CAAC,CACjB,MACE,MACCC,EAAE,eAAe,CAAC,EAAE,QAAQ,MAAM,cAClCA,EAAE,YAAY,CAAC,CAAC,QAAQ,MAAMC,EAAW,oBAC7C,CACJ;AACJ;AAGA,SAAgBC,EAAY,GAAiB,GAAyB;CACpE,IAAI,CAACC,EAAQ,SAAS,IAAI,GAAG,OAAO,KAAKC,EAAM,KAAK,IAAI,EAAE;CAC1D,IAAMC,IAASF,EAAQ,MAAM,cAAc,CAAC,GAAG,MAAM,KAC/CG,IAAQH,EAAQ,MAAM,eAAe,CAAC,GAAG,MAAM;CACrD,OAAO,MAAMC,EAAM,KAAK,MAAMC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IC,EAAWF,CAAQ,GAChCG,IAAQ;CAOZ,IANAF,EAAK,cACF,MACC5B,EAAmB+B,IAAU,MAAO;EAClC,IAAQb,EAAoBV,CAAE;CAChC,CAAC,CAAC,CAAC,MACP,GACI,CAACsB,GAAO,OAAO;EAAE,QAAQ;EAAU,SAAS3B;CAAa;CAG7D,IAAM6B,IAASJ,EAAK,SAAS,GACvBK,IAAcD,EAAO,QAAQ,YAAW,GACxCE,IAAQ,CACZ,GAAGF,EACA,MAAMC,CAAW,CAAC,CAClB,SACC,gEACF,CACJ;CACA,IAAIC,EAAM,SAAS,GAAG,OAAO;EAAE,QAAQ;EAAU,SAAS/B;CAAa;CAEvE,IAAIgC,IAAMH;CAEV,KAAK,IAAM,CAACI,GAAGC,MAAU,CAAC,GAAGH,EAAM,MAAM,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG;EACnE,IAAMI,IAAML,IAAcI,EAAM,QAASA,EAAM,EAAE,CAAC;EAClD,IAAM,GAAGF,EAAI,MAAM,GAAGG,CAAG,EAAE,IAAID,EAAM,KAAK/B,EAAW8B,KAAKD,EAAI,MAAMG,CAAG;CACzE;CAGA,OADArC,EAAG,cAAcyB,GAAUS,GAAK,MAAM,GAC/B;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as e, n as t, r as n } from "./config-target-
|
|
1
|
+
import { i as e, n as t, r as n } from "./config-target-BgyFkbFL.js";
|
|
2
2
|
//#region src/runtime/modify-svelte-config-remote.ts
|
|
3
3
|
var r = [
|
|
4
4
|
"Enable SvelteKit remote functions and Svelte async in your config",
|
|
@@ -39,4 +39,4 @@ function a(a) {
|
|
|
39
39
|
//#endregion
|
|
40
40
|
export { a as modifySvelteConfigRemote };
|
|
41
41
|
|
|
42
|
-
//# sourceMappingURL=modify-svelte-config-remote-
|
|
42
|
+
//# sourceMappingURL=modify-svelte-config-remote-CEyYydL7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modify-svelte-config-remote-
|
|
1
|
+
{"version":3,"file":"modify-svelte-config-remote-CEyYydL7.js","names":["modifyConfig","ensureBooleanTrue","getOrCreateObjectLiteralProperty","FAILURE_HINT","NOT_FOUND_HINT","modifySvelteConfigRemote","root","kitExperimental","target","compilerObj","compilerExperimental"],"sources":["../../src/runtime/modify-svelte-config-remote.ts"],"sourcesContent":["import {\n ensureBooleanTrue,\n getOrCreateObjectLiteralProperty,\n modifyConfig,\n type ConfigModifyResult,\n} from \"./config-target\";\n\nconst FAILURE_HINT = [\n \"Enable SvelteKit remote functions and Svelte async in your config\",\n \"(the sveltekit() plugin arg in vite.config):\",\n \"\",\n \"experimental: { remoteFunctions: true },\",\n \"compilerOptions: { experimental: { async: true } },\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Enable SvelteKit remote functions and Svelte async by passing config to the\",\n \"sveltekit() plugin in vite.config.ts:\",\n \"\",\n \"import { sveltekit } from '@sveltejs/kit/vite';\",\n \"import { defineConfig } from 'vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [\",\n \" sveltekit({\",\n \" experimental: { remoteFunctions: true },\",\n \" compilerOptions: { experimental: { async: true } },\",\n \" }),\",\n \" ],\",\n \"});\",\n].join(\"\\n\");\n\n/**\n * Enable SvelteKit remote functions (`experimental.remoteFunctions`) and Svelte\n * async (`compilerOptions.experimental.async`) in the inline `sveltekit()` arg\n * in vite.config, where both sit at the top level.\n */\nexport function modifySvelteConfigRemote(root: string): ConfigModifyResult {\n return modifyConfig(\n root,\n { notFound: NOT_FOUND_HINT, failed: FAILURE_HINT },\n (target) => {\n const kitExperimental = getOrCreateObjectLiteralProperty(\n target.configObject,\n \"experimental\",\n \"{}\",\n );\n if (!kitExperimental) return false;\n ensureBooleanTrue(kitExperimental, \"remoteFunctions\");\n\n const compilerObj = getOrCreateObjectLiteralProperty(\n target.configObject,\n \"compilerOptions\",\n \"{}\",\n );\n if (!compilerObj) return false;\n const compilerExperimental = getOrCreateObjectLiteralProperty(\n compilerObj,\n \"experimental\",\n \"{}\",\n );\n if (!compilerExperimental) return false;\n ensureBooleanTrue(compilerExperimental, \"async\");\n\n return true;\n },\n );\n}\n"],"mappings":";;AAOA,IAAMG,IAAe;CACnB;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAELC,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAOX,SAAgBC,EAAyB,GAAkC;CACzE,OAAOL,EACLM,GACA;EAAE,UAAUF;EAAgB,QAAQD;CAAa,IAChD,MAAW;EACV,IAAMI,IAAkBL,EACtBM,EAAO,cACP,gBACA,IACF;EACA,IAAI,CAACD,GAAiB,OAAO;EAC7B,EAAkBA,GAAiB,iBAAiB;EAEpD,IAAME,IAAcP,EAClBM,EAAO,cACP,mBACA,IACF;EACA,IAAI,CAACC,GAAa,OAAO;EACzB,IAAMC,IAAuBR,EAC3BO,GACA,gBACA,IACF;EAIA,OAHKC,KACLT,EAAkBS,GAAsB,OAAO,GAExC,MAH2B;CAIpC,CACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
|
-
import { o as t } from "./ts-morph-helpers-
|
|
2
|
+
import { o as t } from "./ts-morph-helpers-CHI9wAil.js";
|
|
3
3
|
import n from "node:fs";
|
|
4
4
|
import { Project as r, QuoteKind as i, SyntaxKind as a } from "ts-morph";
|
|
5
5
|
//#region src/patterns/enable/payments/modifies/modify-user-signup.ts
|
|
@@ -51,4 +51,4 @@ function u(e) {
|
|
|
51
51
|
//#endregion
|
|
52
52
|
export { u as t };
|
|
53
53
|
|
|
54
|
-
//# sourceMappingURL=modify-user-signup-
|
|
54
|
+
//# sourceMappingURL=modify-user-signup-DLtopazD.js.map
|
package/dist/chunks/{modify-user-signup-BbqTiUuA.js.map → modify-user-signup-DLtopazD.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modify-user-signup-
|
|
1
|
+
{"version":3,"file":"modify-user-signup-DLtopazD.js","names":["dedent","formatLikeSource","fs","WORKFLOW_MODULE","RUN_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","modifyUserSignup","userSignupPath","originalSource","sourceFile","Project","QuoteKind","requestVerificationCall","SyntaxKind","expr","ce","statement"],"sources":["../../src/patterns/enable/payments/modifies/modify-user-signup.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst WORKFLOW_MODULE = \"#lib/workflows/link-stripe-customer.js\";\n\nconst RUN_SNIPPET = dedent`\n // Queued here, done in the background: the Stripe calls retry on their own,\n // and the key means a retry never makes a second customer for this user.\n await linkStripeCustomer.run(\n { userId: user.id, email: form.data.email },\n { idempotencyKey: user.id }\n );\n`;\n\nconst FAILURE_HINT = [\n \"Could not locate the requestVerification call in signup +page.server.ts.\",\n \"Start the workflow once the user exists:\",\n \"\",\n `import { linkStripeCustomer } from '${WORKFLOW_MODULE}';`,\n \"\",\n RUN_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/routes/(public)/(auth)/signup/+page.server.ts before enabling payments.\",\n].join(\"\\n\");\n\n/**\n * Starts the link-stripe-customer workflow right after the user is created.\n * The work itself lives in src/lib/workflows/link-stripe-customer.ts.\n */\nexport function modifyUserSignup(userSignupPath: string): ModifyOutcome {\n if (!fs.existsSync(userSignupPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const originalSource = fs.readFileSync(userSignupPath, \"utf8\");\n if (originalSource.includes(\"linkStripeCustomer\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(userSignupPath);\n\n const requestVerificationCall = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => {\n const expr = ce.getExpression();\n return (\n expr.getKind() === SyntaxKind.PropertyAccessExpression &&\n expr.getText().includes(\"requestVerification\")\n );\n });\n\n if (!requestVerificationCall) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const statement = requestVerificationCall.getFirstAncestorByKind(\n SyntaxKind.ExpressionStatement,\n );\n\n if (!statement) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n sourceFile.addImportDeclaration({\n namedImports: [\"linkStripeCustomer\"],\n moduleSpecifier: WORKFLOW_MODULE,\n });\n\n statement.replaceWithText(RUN_SNIPPET + \"\\n\\n\" + statement.getText());\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n"],"mappings":";;;;;AAMA,IAAMG,IAAkB,0CAElBC,IAAc,CAAM;;;;;;;GASpBC,IAAe;CACnB;CACA;CACA;CACA,uCAAuCF,EAAgB;CACvD;CACAC;AACF,CAAC,CAAC,KAAK,IAAI,GAELE,IAAiB,CACrB,oFACF,CAAC,CAAC,KAAK,IAAI;AAMX,SAAgBC,EAAiB,GAAuC;CACtE,IAAI,CAACL,EAAG,WAAWM,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAASF;CAAe;CAGxD,IAAMG,IAAiBP,EAAG,aAAaM,GAAgB,MAAM;CAC7D,IAAIC,EAAe,SAAS,oBAAoB,GAC9C,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAM7C,IAAMC,IAAa,IAHCC,EAAQ,EAC1B,sBAAsB,EAAE,WAAWC,EAAU,OAAO,EACtD,CACmB,CAAA,CAAQ,oBAAoBJ,CAAc,GAEvDK,IAA0BH,EAC7B,qBAAqBI,EAAW,cAAc,CAAC,CAC/C,MAAM,MAAO;EACZ,IAAMC,IAAOC,EAAG,cAAc;EAC9B,OACED,EAAK,QAAQ,MAAMD,EAAW,4BAC9BC,EAAK,QAAQ,CAAC,CAAC,SAAS,qBAAqB;CAEjD,CAAC;CAEH,IAAI,CAACF,GACH,OAAO;EAAE,QAAQ;EAAU,SAASR;CAAa;CAGnD,IAAMY,IAAYJ,EAAwB,uBACxCC,EAAW,mBACb;CAgBA,OAdKG,KAILP,EAAW,qBAAqB;EAC9B,cAAc,CAAC,oBAAoB;EACnC,iBAAiBP;CACnB,CAAC,GAEDc,EAAU,gBAAgBb,IAAc,SAASa,EAAU,QAAQ,CAAC,GAEpEhB,EAAiBS,CAAU,GAC3BA,EAAW,SAAS,GAEb;EACL,QAAQ;EACR,SAASA,EAAW,YAAY,MAAMD;CACxC,KAhBS;EAAE,QAAQ;EAAU,SAASJ;CAAa;AAiBrD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as e } from "./rolldown-runtime-
|
|
1
|
+
import { n as e } from "./rolldown-runtime-5HNE8Q1r.js";
|
|
2
2
|
import t from "node:fs";
|
|
3
3
|
import n from "node:path";
|
|
4
4
|
//#region src/runtime/package-imports.ts
|
|
@@ -170,4 +170,4 @@ function f(e, t, n, r) {
|
|
|
170
170
|
//#endregion
|
|
171
171
|
export { u as i, d as n, r, l as t };
|
|
172
172
|
|
|
173
|
-
//# sourceMappingURL=package-imports-
|
|
173
|
+
//# sourceMappingURL=package-imports-Dx05A-4S.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-imports-Bbw3iMPg.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,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ACTpC,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-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;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,GAEM,IAAOA,EAAK;CAGzB,OAFID,MAASC,EAAK,OAAa;EAAE,QAAQ;EAAW,SAAS;CAAM,KACnElB,EAAG,cAAckB,EAAK,UAAUD,GAAM,MAAM,GACrC;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC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K,UAAUF,CAAM,EAAE,EACzE;CAEJ;CACA,OAAOF;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as e } from "./rolldown-runtime-
|
|
1
|
+
import { n as e } from "./rolldown-runtime-5HNE8Q1r.js";
|
|
2
2
|
import { c as t, i as n } from "./constants-iej3WkEa.js";
|
|
3
3
|
import { existsSync as r, readFileSync as i, readdirSync as a } from "node:fs";
|
|
4
4
|
import o from "node:path";
|
|
@@ -113,11 +113,7 @@ function h(e, t, n = 60) {
|
|
|
113
113
|
a++;
|
|
114
114
|
let s = new d.Socket();
|
|
115
115
|
s.once("error", () => {
|
|
116
|
-
|
|
117
|
-
i(/* @__PURE__ */ Error(`Timed out waiting for port ${e} to be available`));
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
setTimeout(o, 500);
|
|
116
|
+
s.destroy(), a === n ? i(/* @__PURE__ */ Error(`Timed out waiting for port ${e} to be available`)) : setTimeout(o, 500);
|
|
121
117
|
}), s.connect(e, t, () => {
|
|
122
118
|
s.destroy(), r();
|
|
123
119
|
});
|
|
@@ -144,11 +140,7 @@ function _(e, t = 60) {
|
|
|
144
140
|
} catch (e) {
|
|
145
141
|
a = g(e);
|
|
146
142
|
}
|
|
147
|
-
|
|
148
|
-
r(/* @__PURE__ */ Error(`Timed out waiting for health check at ${e}/api/health (last attempt: ${a})`));
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
setTimeout(o, 500);
|
|
143
|
+
i === t ? r(/* @__PURE__ */ Error(`Timed out waiting for health check at ${e}/api/health (last attempt: ${a})`)) : setTimeout(o, 500);
|
|
152
144
|
};
|
|
153
145
|
o();
|
|
154
146
|
});
|
|
@@ -232,4 +224,4 @@ function T(e, t) {
|
|
|
232
224
|
//#endregion
|
|
233
225
|
export { w as i, b as n, v as r, x as t };
|
|
234
226
|
|
|
235
|
-
//# sourceMappingURL=pocketbase-
|
|
227
|
+
//# sourceMappingURL=pocketbase-DL02rq73.js.map
|