@velastack/patterns 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/README.md +32 -2
  2. package/dist/chunks/_layout-B7ujvjnA.js +55 -0
  3. package/dist/chunks/_layout-B7ujvjnA.js.map +1 -0
  4. package/dist/chunks/{collections-CgdvZXmh.js → collections-UPqYto13.js} +2 -2
  5. package/dist/chunks/{collections-CgdvZXmh.js.map → collections-UPqYto13.js.map} +1 -1
  6. package/dist/chunks/{compose-handle-Cg9jnCsS.js → compose-handle-B-CkDcQD.js} +23 -23
  7. package/dist/chunks/{compose-handle-Cg9jnCsS.js.map → compose-handle-B-CkDcQD.js.map} +1 -1
  8. package/dist/chunks/config-target-Bln26FJe.js +164 -0
  9. package/dist/chunks/config-target-Bln26FJe.js.map +1 -0
  10. package/dist/chunks/errors-DR3gF_7a.js +18 -0
  11. package/dist/chunks/errors-DR3gF_7a.js.map +1 -0
  12. package/dist/chunks/{generate-DRA63W0r.js → generate-6snrlnpA.js} +2 -2
  13. package/dist/chunks/{generate-DRA63W0r.js.map → generate-6snrlnpA.js.map} +1 -1
  14. package/dist/chunks/{generate-BkQ1xMDp.js → generate-C6xi5S5L.js} +4 -4
  15. package/dist/chunks/{generate-BkQ1xMDp.js.map → generate-C6xi5S5L.js.map} +1 -1
  16. package/dist/chunks/{generate-tOkjJFUf.js → generate-CyuY2Ci7.js} +4 -3
  17. package/dist/chunks/generate-CyuY2Ci7.js.map +1 -0
  18. package/dist/chunks/{generate-iQP31-m1.js → generate-DHgKgHb7.js} +4 -4
  19. package/dist/chunks/{generate-iQP31-m1.js.map → generate-DHgKgHb7.js.map} +1 -1
  20. package/dist/chunks/{generate-_LvrYK6i.js → generate-jsB_oO0b.js} +4 -4
  21. package/dist/chunks/{generate-_LvrYK6i.js.map → generate-jsB_oO0b.js.map} +1 -1
  22. package/dist/chunks/{generate.runtime-DAmYsIvF.js → generate.runtime-9R2AUKLS.js} +5 -5
  23. package/dist/chunks/{generate.runtime-DAmYsIvF.js.map → generate.runtime-9R2AUKLS.js.map} +1 -1
  24. package/dist/chunks/generate.runtime-B3yX6kl2.js +87 -0
  25. package/dist/chunks/generate.runtime-B3yX6kl2.js.map +1 -0
  26. package/dist/chunks/{generate.runtime-BKo-Nidn.js → generate.runtime-B7wkyj-8.js} +6 -6
  27. package/dist/chunks/{generate.runtime-BKo-Nidn.js.map → generate.runtime-B7wkyj-8.js.map} +1 -1
  28. package/dist/chunks/generate.runtime-BHf8p_3K.js +94 -0
  29. package/dist/chunks/generate.runtime-BHf8p_3K.js.map +1 -0
  30. package/dist/chunks/{generate.runtime-BbIN0tUZ.js → generate.runtime-BSFIwX58.js} +67 -66
  31. package/dist/chunks/generate.runtime-BSFIwX58.js.map +1 -0
  32. package/dist/chunks/{generate.runtime-BnWE4qsu.js → generate.runtime-Bb9CCwQm.js} +55 -54
  33. package/dist/chunks/generate.runtime-Bb9CCwQm.js.map +1 -0
  34. package/dist/chunks/{generate.runtime-D8vgh5MH.js → generate.runtime-BjciAjq7.js} +156 -76
  35. package/dist/chunks/generate.runtime-BjciAjq7.js.map +1 -0
  36. package/dist/chunks/{generate.runtime-BwhGDnGu.js → generate.runtime-BpTpRBdH.js} +151 -150
  37. package/dist/chunks/generate.runtime-BpTpRBdH.js.map +1 -0
  38. package/dist/chunks/{generate.runtime-D0icLb5j.js → generate.runtime-Brf08fMW.js} +11 -10
  39. package/dist/chunks/{generate.runtime-D0icLb5j.js.map → generate.runtime-Brf08fMW.js.map} +1 -1
  40. package/dist/chunks/{generate.runtime-S5RIgbQx.js → generate.runtime-C6DfW_NO.js} +98 -92
  41. package/dist/chunks/generate.runtime-C6DfW_NO.js.map +1 -0
  42. package/dist/chunks/{generate.runtime-DhkaXTq3.js → generate.runtime-C9fSqy6a.js} +61 -59
  43. package/dist/chunks/generate.runtime-C9fSqy6a.js.map +1 -0
  44. package/dist/chunks/{generate.runtime-CRYjWJRe.js → generate.runtime-CawvLUoV.js} +89 -88
  45. package/dist/chunks/generate.runtime-CawvLUoV.js.map +1 -0
  46. package/dist/chunks/{generate.runtime-DNaQxed-.js → generate.runtime-CzS7PuPN.js} +84 -83
  47. package/dist/chunks/generate.runtime-CzS7PuPN.js.map +1 -0
  48. package/dist/chunks/{generate.runtime-B0hhtyAL.js → generate.runtime-D1NZPV6C.js} +27 -26
  49. package/dist/chunks/generate.runtime-D1NZPV6C.js.map +1 -0
  50. package/dist/chunks/generate.runtime-D3baqo6a.js +111 -0
  51. package/dist/chunks/generate.runtime-D3baqo6a.js.map +1 -0
  52. package/dist/chunks/{generate.runtime-DSqkXvps.js → generate.runtime-D47djbeG.js} +15 -14
  53. package/dist/chunks/{generate.runtime-DSqkXvps.js.map → generate.runtime-D47djbeG.js.map} +1 -1
  54. package/dist/chunks/generate.runtime-D72UBiwD.js +313 -0
  55. package/dist/chunks/generate.runtime-D72UBiwD.js.map +1 -0
  56. package/dist/chunks/{generate.runtime-CcuAXuV2.js → generate.runtime-DDPoXmqN.js} +15 -14
  57. package/dist/chunks/{generate.runtime-CcuAXuV2.js.map → generate.runtime-DDPoXmqN.js.map} +1 -1
  58. package/dist/chunks/{generate.runtime-acRmiU7e.js → generate.runtime-DEnn0HKw.js} +9 -8
  59. package/dist/chunks/{generate.runtime-acRmiU7e.js.map → generate.runtime-DEnn0HKw.js.map} +1 -1
  60. package/dist/chunks/{generate.runtime-wA1G3tQ4.js → generate.runtime-DHXkw2gf.js} +38 -37
  61. package/dist/chunks/generate.runtime-DHXkw2gf.js.map +1 -0
  62. package/dist/chunks/{generate.runtime-DOuufRLr.js → generate.runtime-DIuCrH6l.js} +82 -81
  63. package/dist/chunks/generate.runtime-DIuCrH6l.js.map +1 -0
  64. package/dist/chunks/generate.runtime-DOB4U-Sa.js +57 -0
  65. package/dist/chunks/generate.runtime-DOB4U-Sa.js.map +1 -0
  66. package/dist/chunks/generate.runtime-DPAy7Cav.js +328 -0
  67. package/dist/chunks/generate.runtime-DPAy7Cav.js.map +1 -0
  68. package/dist/chunks/{generate.runtime-BORbegw_.js → generate.runtime-D_ZqiYt-.js} +123 -122
  69. package/dist/chunks/generate.runtime-D_ZqiYt-.js.map +1 -0
  70. package/dist/chunks/{generate.runtime-B49wetSx.js → generate.runtime-Dm7g_WTN.js} +43 -42
  71. package/dist/chunks/generate.runtime-Dm7g_WTN.js.map +1 -0
  72. package/dist/chunks/{generate.runtime-DoZdSh9W.js → generate.runtime-HE9rzfXz.js} +58 -57
  73. package/dist/chunks/generate.runtime-HE9rzfXz.js.map +1 -0
  74. package/dist/chunks/{generate.runtime-flFRYzpi.js → generate.runtime-ejrt1o6M.js} +62 -61
  75. package/dist/chunks/generate.runtime-ejrt1o6M.js.map +1 -0
  76. package/dist/chunks/generate.runtime-l6I-St2R.js +94 -0
  77. package/dist/chunks/generate.runtime-l6I-St2R.js.map +1 -0
  78. package/dist/chunks/modify-file-DGe7MJu_.js +46 -0
  79. package/dist/chunks/modify-file-DGe7MJu_.js.map +1 -0
  80. package/dist/chunks/{modify-svelte-config-remote-CDKs_Qi0.js → modify-svelte-config-remote-BUU_EaDf.js} +2 -2
  81. package/dist/chunks/{modify-svelte-config-remote-CDKs_Qi0.js.map → modify-svelte-config-remote-BUU_EaDf.js.map} +1 -1
  82. package/dist/chunks/{providers-DO9kMyzB.js → providers-BL9vJP_9.js} +2 -2
  83. package/dist/chunks/{providers-DO9kMyzB.js.map → providers-BL9vJP_9.js.map} +1 -1
  84. package/dist/chunks/{shared-BwHQM-a9.js → shared-DkGfltvn.js} +2 -2
  85. package/dist/chunks/{shared-BwHQM-a9.js.map → shared-DkGfltvn.js.map} +1 -1
  86. package/dist/chunks/{test-setup-B2hd8I-s.js → test-setup-DHEFKEHE.js} +23 -10
  87. package/dist/chunks/test-setup-DHEFKEHE.js.map +1 -0
  88. package/dist/chunks/ts-morph-helpers-CeduA--o.js +253 -0
  89. package/dist/chunks/ts-morph-helpers-CeduA--o.js.map +1 -0
  90. package/dist/chunks/{ui-B4Tuit-7.js → ui-B3-B3sE2.js} +3 -3
  91. package/dist/chunks/{ui-B4Tuit-7.js.map → ui-B3-B3sE2.js.map} +1 -1
  92. package/dist/chunks/{ui-jhXrsw4T.js → ui-DD4NltyN.js} +2 -2
  93. package/dist/chunks/{ui-jhXrsw4T.js.map → ui-DD4NltyN.js.map} +1 -1
  94. package/dist/chunks/unmodify-load-jfdcVZ_a.js +81 -0
  95. package/dist/chunks/unmodify-load-jfdcVZ_a.js.map +1 -0
  96. package/dist/chunks/write-result-DRwceOV3.js +452 -0
  97. package/dist/chunks/write-result-DRwceOV3.js.map +1 -0
  98. package/dist/index.d.ts +34 -0
  99. package/dist/index.js +1918 -1901
  100. package/dist/index.js.map +1 -1
  101. package/package.json +1 -1
  102. package/dist/chunks/_layout-DqH4lA_r.js +0 -47
  103. package/dist/chunks/_layout-DqH4lA_r.js.map +0 -1
  104. package/dist/chunks/config-target-Co-ij8p3.js +0 -163
  105. package/dist/chunks/config-target-Co-ij8p3.js.map +0 -1
  106. package/dist/chunks/errors-D6gyegUK.js +0 -14
  107. package/dist/chunks/errors-D6gyegUK.js.map +0 -1
  108. package/dist/chunks/generate-tOkjJFUf.js.map +0 -1
  109. package/dist/chunks/generate.runtime-B0hhtyAL.js.map +0 -1
  110. package/dist/chunks/generate.runtime-B49wetSx.js.map +0 -1
  111. package/dist/chunks/generate.runtime-B7LRx-BU.js +0 -86
  112. package/dist/chunks/generate.runtime-B7LRx-BU.js.map +0 -1
  113. package/dist/chunks/generate.runtime-BORbegw_.js.map +0 -1
  114. package/dist/chunks/generate.runtime-BbIN0tUZ.js.map +0 -1
  115. package/dist/chunks/generate.runtime-BnWE4qsu.js.map +0 -1
  116. package/dist/chunks/generate.runtime-BwhGDnGu.js.map +0 -1
  117. package/dist/chunks/generate.runtime-CCg2Pjcv.js +0 -257
  118. package/dist/chunks/generate.runtime-CCg2Pjcv.js.map +0 -1
  119. package/dist/chunks/generate.runtime-CRYjWJRe.js.map +0 -1
  120. package/dist/chunks/generate.runtime-D2e_KRj0.js +0 -56
  121. package/dist/chunks/generate.runtime-D2e_KRj0.js.map +0 -1
  122. package/dist/chunks/generate.runtime-D44gjxRA.js +0 -332
  123. package/dist/chunks/generate.runtime-D44gjxRA.js.map +0 -1
  124. package/dist/chunks/generate.runtime-D8vgh5MH.js.map +0 -1
  125. package/dist/chunks/generate.runtime-DNaQxed-.js.map +0 -1
  126. package/dist/chunks/generate.runtime-DOuufRLr.js.map +0 -1
  127. package/dist/chunks/generate.runtime-DhkaXTq3.js.map +0 -1
  128. package/dist/chunks/generate.runtime-DoZdSh9W.js.map +0 -1
  129. package/dist/chunks/generate.runtime-S5RIgbQx.js.map +0 -1
  130. package/dist/chunks/generate.runtime-WmSMWL15.js +0 -82
  131. package/dist/chunks/generate.runtime-WmSMWL15.js.map +0 -1
  132. package/dist/chunks/generate.runtime-flFRYzpi.js.map +0 -1
  133. package/dist/chunks/generate.runtime-gtpOuLNO.js +0 -110
  134. package/dist/chunks/generate.runtime-gtpOuLNO.js.map +0 -1
  135. package/dist/chunks/generate.runtime-kLxeDGnS.js +0 -93
  136. package/dist/chunks/generate.runtime-kLxeDGnS.js.map +0 -1
  137. package/dist/chunks/generate.runtime-wA1G3tQ4.js.map +0 -1
  138. package/dist/chunks/modify-file-GQD6uNgI.js +0 -254
  139. package/dist/chunks/modify-file-GQD6uNgI.js.map +0 -1
  140. package/dist/chunks/test-setup-B2hd8I-s.js.map +0 -1
  141. package/dist/chunks/unmodify-load-W1ePZQHr.js +0 -80
  142. package/dist/chunks/unmodify-load-W1ePZQHr.js.map +0 -1
  143. package/dist/chunks/write-result-DewHCNhM.js +0 -451
  144. package/dist/chunks/write-result-DewHCNhM.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.runtime-C6DfW_NO.js","names":[],"sources":["../../src/patterns/enable/auth/modifies/+layout.server.ts","../../src/patterns/enable/auth/modifies/root-layout.svelte.ts","../../src/patterns/enable/auth/modifies/hooks.server.ts","../../src/patterns/enable/auth/modifies/sidebar-menu-button.svelte.ts","../../src/patterns/enable/auth/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nexport function modifyLayoutServer(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n const snippet = dedent`\n\t\t\texport const load = async ({ locals }) => {\n\t\t\t\treturn { user: locals.pb.authStore.record };\n\t\t\t};\n\t\t`;\n\n fs.writeFileSync(layoutPath, snippet);\n return { status: \"success\", changed: true };\n }\n\n const originalSource = fs.readFileSync(layoutPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(layoutPath);\n\n // helper to add user property to an object literal if missing\n const addUserProp = (obj: import(\"ts-morph\").ObjectLiteralExpression) => {\n const hasUser = !!obj.getProperty(\"user\");\n if (!hasUser) {\n obj.addPropertyAssignment({\n name: \"user\",\n initializer: \"locals.pb.authStore.record\",\n });\n }\n };\n\n // find existing exported load (function or const with arrow)\n let loadArrow: import(\"ts-morph\").ArrowFunction | undefined;\n let loadFn:\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression\n | undefined;\n\n const varDecl = sourceFile.getVariableDeclaration(\"load\");\n if (varDecl) {\n const vs = varDecl.getFirstAncestorByKind(SyntaxKind.VariableStatement);\n const isExported = !!vs?.hasExportKeyword();\n if (isExported) {\n const directArrow = varDecl.getInitializerIfKind(\n SyntaxKind.ArrowFunction,\n );\n if (directArrow) {\n loadArrow = directArrow;\n } else {\n const init = varDecl.getInitializer();\n if (init) {\n const innerArrow = init.getFirstDescendantByKind(\n SyntaxKind.ArrowFunction,\n );\n if (innerArrow) {\n loadArrow = innerArrow;\n } else {\n const innerFnExpr = init.getFirstDescendantByKind(\n SyntaxKind.FunctionExpression,\n );\n if (innerFnExpr) {\n loadFn = innerFnExpr;\n }\n }\n }\n }\n }\n }\n\n if (!loadArrow) {\n const maybeFn = sourceFile.getFunction(\"load\");\n if (maybeFn && maybeFn.isExported()) {\n loadFn = maybeFn;\n }\n }\n\n // if no load found, create one\n if (!loadArrow && !loadFn) {\n sourceFile.addFunction({\n isExported: true,\n isAsync: true,\n name: \"load\",\n parameters: [{ name: \"{ locals }\" }],\n statements: `return { user: locals.pb.authStore.record };`,\n });\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n // normalize function-like to a single handle\n const fnLike:\n | import(\"ts-morph\").ArrowFunction\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression = (loadArrow ?? loadFn!) as any;\n\n // ensure first parameter destructures locals, preserving existing information\n const params = fnLike.getParameters();\n if (params.length === 0) {\n fnLike.insertParameter(0, { name: \"{ locals }\" });\n } else {\n const first = params[0];\n const original = first.getStructure();\n const nameNode = first.getNameNode();\n if (nameNode.getKind() === SyntaxKind.ObjectBindingPattern) {\n const obp = nameNode as import(\"ts-morph\").ObjectBindingPattern;\n const hasLocals = obp\n .getElements()\n .some((el) => el.getName() === \"locals\");\n if (!hasLocals) {\n const parts = obp\n .getElements()\n .map((el) => el.getText())\n .filter(Boolean);\n const tail = parts.length > 0 ? \", \" + parts.join(\", \") : \"\";\n first.set({\n name: `{ locals${tail} }`,\n type: original.type,\n initializer: (original as any).initializer,\n });\n }\n } else {\n const currentName = first.getName();\n if (currentName !== \"locals\") {\n first.set({\n name: `{ locals, ...${currentName} }`,\n type: original.type,\n initializer: (original as any).initializer,\n });\n }\n }\n }\n\n // add user to returned object literals without altering other properties\n if (loadArrow) {\n const body = loadArrow.getBody();\n if (body.getKind() === SyntaxKind.Block) {\n const returns = body.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n });\n } else {\n // concise body\n const bodyExpr = body as import(\"ts-morph\").Expression;\n if (bodyExpr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n bodyExpr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n } else if (bodyExpr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(bodyExpr as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n } else if (loadFn) {\n const body = loadFn.getBody();\n if (body) {\n const returns = body.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n });\n }\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n ensurePropsBinding,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst AUTH_MENU_NAVBAR_ITEM = `\n\t\t<Navbar.Item\n\t\t\tclass=\"flex flex-col md:flex-row items-center space-y-2 md:space-y-0 md:space-x-4\"\n\t\t>\n\t\t\t<AuthMenu.Root>\n\t\t\t\t{#snippet user()}\n\t\t\t\t\t<AuthMenu.Trigger>\n\t\t\t\t\t\t<Avatar.Root>\n\t\t\t\t\t\t\t{#if data.user?.avatar}\n\t\t\t\t\t\t\t\t<Avatar.Image\n\t\t\t\t\t\t\t\t\tsrc=\"/api/files/users/{data.user?.id}/{data.user?.avatar}\"\n\t\t\t\t\t\t\t\t\talt={data.user?.email}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t<Avatar.Fallback>\n\t\t\t\t\t\t\t\t{data.user?.email?.charAt(0).toUpperCase()}\n\t\t\t\t\t\t\t</Avatar.Fallback>\n\t\t\t\t\t\t</Avatar.Root>\n\t\t\t\t\t</AuthMenu.Trigger>\n\n\t\t\t\t\t<AuthMenu.Content align=\"end\">\n\t\t\t\t\t\t<AuthMenu.Item href=\"/dashboard\">Dashboard</AuthMenu.Item>\n\t\t\t\t\t\t<AuthMenu.Group>\n\t\t\t\t\t\t\t<AuthMenu.Item href=\"/settings\">Settings</AuthMenu.Item>\n\t\t\t\t\t\t\t<AuthMenu.Item>\n\t\t\t\t\t\t\t\t<form action=\"/logout\" method=\"post\">\n\t\t\t\t\t\t\t\t\t<button type=\"submit\" class=\"contents\">Logout</button>\n\t\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t\t</AuthMenu.Item>\n\t\t\t\t\t\t</AuthMenu.Group>\n\t\t\t\t\t</AuthMenu.Content>\n\t\t\t\t{/snippet}\n\n\t\t\t\t{#snippet guest()}\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclass=\"w-full justify-start md:justify-center md:w-auto\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\thref=\"/login\">Login</Button\n\t\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclass=\"w-full justify-start md:justify-center md:w-auto\"\n\t\t\t\t\t\tvariant=\"outline\"\n\t\t\t\t\t\thref=\"/signup\">Sign up</Button\n\t\t\t\t\t>\n\t\t\t\t{/snippet}\n\t\t\t</AuthMenu.Root>\n\t\t</Navbar.Item>\n\t`;\n\nconst IMPORT_SNIPPET = dedent`\n import * as AuthMenu from '$lib/components/ui/auth-menu';\n import * as Avatar from '$lib/components/ui/avatar';\n`;\n\nconst FAILURE_HINT = [\n \"Add the auth menu inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Imports to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add inside <Navbar.List>:\",\n AUTH_MENU_NAVBAR_ITEM,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes an auth menu inside <Navbar.List>.\",\n \"\",\n \"Imports for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup inside <Navbar.List>:\",\n AUTH_MENU_NAVBAR_ITEM,\n].join(\"\\n\");\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(\"AuthMenu.Root\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n namespaceImport: \"AuthMenu\",\n moduleSpecifier: \"$lib/components/ui/auth-menu\",\n },\n {\n namespaceImport: \"Avatar\",\n moduleSpecifier: \"$lib/components/ui/avatar\",\n },\n ]);\n // The menu reads `data.user`; the template's layout takes no props.\n ensurePropsBinding(sf, \"data\");\n });\n return out;\n });\n\n file.insertBeforeClosingTag(\"Navbar.List\", AUTH_MENU_NAVBAR_ITEM);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Configure handlePocketbase() with the auth option in hooks.server.ts:\n\n handlePocketbase({\n auth: { protectedRoutes: ['/(app)'] },\n });\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with handlePocketbase:\n\n import { handlePocketbase } from 'velastack/handle';\n\n export const handle = handlePocketbase({\n auth: { protectedRoutes: ['/(app)'] },\n });\n`;\n\nexport function modifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n // Find the handlePocketbase(...) call\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n\n if (!callExpr) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n callExpr.addArgument(`{ auth: { protectedRoutes: ['/(app)'] } }`);\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n callExpr.insertArgument(0, `{ auth: { protectedRoutes: ['/(app)'] } }`);\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n // Ensure auth property exists\n const authProp = optionsObj.getProperty(\"auth\");\n if (!authProp) {\n optionsObj.addPropertyAssignment({\n name: \"auth\",\n initializer: `{ protectedRoutes: ['/(app)'] }`,\n });\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n // If auth exists, ensure protectedRoutes includes '/(app)'\n if (authProp.getKind() === SyntaxKind.PropertyAssignment) {\n const authInit = (\n authProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (authInit && authInit.getKind() === SyntaxKind.ObjectLiteralExpression) {\n const authObj = authInit as import(\"ts-morph\").ObjectLiteralExpression;\n const prProp = authObj.getProperty(\"protectedRoutes\");\n if (!prProp) {\n authObj.addPropertyAssignment({\n name: \"protectedRoutes\",\n initializer: `['/(app)']`,\n });\n } else if (prProp.getKind() === SyntaxKind.PropertyAssignment) {\n const prInit = (\n prProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (prInit && prInit.getKind() === SyntaxKind.ArrayLiteralExpression) {\n const arr = prInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasApp = arr\n .getElements()\n .some((el) => el.getText().replace(/['\"`]/g, \"\") === \"/(app)\");\n if (!hasApp) {\n arr.addElement(`'/(app)'`);\n }\n } else {\n (prProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n `['/(app)']`,\n );\n }\n }\n }\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst VARIANTS = [\n {\n from: \"'data-active': isActive,\",\n to: \"'data-active': isActive ? true : undefined,\",\n },\n {\n from: '\"data-active\": isActive,',\n to: '\"data-active\": isActive ? true : undefined,',\n },\n];\n\nconst NOT_FOUND_HINT = dedent`\n The shadcn-svelte sidebar component was not installed at the expected path.\n Run: vela enable auth (or install the 'sidebar' shadcn-svelte component).\n`;\n\nexport function modifySidebarMenuButton(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(filePath, \"utf8\");\n\n if (VARIANTS.some(({ to }) => original.includes(to))) {\n return { status: \"success\", changed: false };\n }\n\n const variant = VARIANTS.find(({ from }) => original.includes(from));\n if (!variant) {\n return { status: \"success\", changed: false };\n }\n\n const updated = original.replace(variant.from, variant.to);\n fs.writeFileSync(filePath, updated, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport { Options, Result, File } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { ensureSiteFile } from \"../../../runtime/site\";\n\nimport { modifyLayoutServer } from \"./modifies/+layout.server\";\nimport { modifyRootLayoutSvelte } from \"./modifies/root-layout.svelte\";\nimport { modifyHooksServer } from \"./modifies/hooks.server\";\nimport { modifySidebarMenuButton } from \"./modifies/sidebar-menu-button.svelte\";\n\nexport async function generate(options: Options) {\n const { input } = options;\n const logger = getLogger(options);\n\n let creates: File[] = [];\n\n // Update PocketBase\n await withPocketbase(options.root, async (pb) => {\n logger.info(\"Updating PocketBase mail settings\");\n await pb.settings.update({\n meta: {\n senderName: input.senderName,\n senderAddress: input.senderAddress,\n },\n });\n await migrationDelay();\n\n const userCollection = await pb.collections.getOne(\"users\");\n\n if (!userCollection) {\n throw new Error(\"Users collection not found\");\n }\n\n const verificationTemplate =\n userCollection.verificationTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-verification/{TOKEN}\",\n \"{APP_URL}/confirm-verification/{TOKEN}\",\n );\n const resetPasswordTemplate =\n userCollection.resetPasswordTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-reset/{TOKEN}\",\n \"{APP_URL}/confirm-reset/{TOKEN}\",\n );\n const confirmEmailChangeTemplate =\n userCollection.confirmEmailChangeTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-email-change/{TOKEN}\",\n \"{APP_URL}/confirm-email-change/{TOKEN}\",\n );\n\n logger.info(\"Locking down users collection rules and email templates\");\n // Update user auth rules to lock down access to the user's own account\n await pb.collections.update(\"users\", {\n listRule: \"@request.auth.id = id\",\n viewRule: \"@request.auth.id = id\",\n createRule: \"@request.auth.id = id\",\n updateRule: \"@request.auth.id = id\",\n deleteRule: \"@request.auth.id = id\",\n\n // Update email templates to VelaStack auth urls\n verificationTemplate: {\n body: verificationTemplate,\n },\n resetPasswordTemplate: {\n body: resetPasswordTemplate,\n },\n confirmEmailChangeTemplate: {\n body: confirmEmailChangeTemplate,\n },\n });\n await migrationDelay();\n\n const migrationFile = getMigrationFile(\"users\", \"updated\", options);\n if (migrationFile) {\n creates.push({\n path: migrationFile,\n language: \"ts\",\n content: fs.readFileSync(migrationFile, \"utf8\"),\n status: \"success\",\n });\n }\n });\n\n // Modify files\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying +layout.server.ts\");\n const layoutServerFile = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(layoutServerFile, modifyLayoutServer(layoutServerFile)),\n );\n\n logger.info(\"Modifying root layout\");\n // TODO: make this more robust by searching for Navbar.Root > Navbar.List\n // src/routes/(public)/root-layout.svelte is what vela creates by default\n const layoutCandidates = [\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"+layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"+layout.svelte\"),\n ];\n const layoutFile =\n layoutCandidates.find((p) => fs.existsSync(p)) ?? layoutCandidates[0];\n pushResult(\n modifyOutcomeToFile(layoutFile, modifyRootLayoutSvelte(layoutFile)),\n );\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerFile = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerFile, modifyHooksServer(hooksServerFile)),\n );\n\n logger.info(\"Modifying sidebar-menu-button.svelte\");\n const sidebarMenuButtonFile = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"ui\",\n \"sidebar\",\n \"sidebar-menu-button.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n sidebarMenuButtonFile,\n modifySidebarMenuButton(sidebarMenuButtonFile),\n ),\n );\n\n // The auth pages and the app sidebar show `site.name`.\n const siteFile = await ensureSiteFile(options);\n\n return {\n creates: siteFile ? [siteFile] : [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AAMA,SAAgB,EAAmB,GAAmC;CACpE,IAAI,CAAC,EAAG,WAAW,CAAU,GAAG;EAC9B,IAAM,IAAU,CAAM;;;;;EAOtB,OADA,EAAG,cAAc,GAAY,CAAO,GAC7B;GAAE,QAAQ;GAAW,SAAS;EAAK;CAC5C;CAEA,IAAM,IAAiB,EAAG,aAAa,GAAY,MAAM,GAEnD,IAAa,IADC,EACD,CAAA,CAAQ,oBAAoB,CAAU,GAGnD,KAAe,MAAoD;EAEvE,AADkB,EAAI,YAAY,MAAM,KAEtC,EAAI,sBAAsB;GACxB,MAAM;GACN,aAAa;EACf,CAAC;CAEL,GAGI,GACA,GAKE,IAAU,EAAW,uBAAuB,MAAM;CACxD,IAAI,KACS,EAAQ,uBAAuB,EAAW,iBAChC,CAAA,EAAI,iBAAiB,GAC1B;EACd,IAAM,IAAc,EAAQ,qBAC1B,EAAW,aACb;EACA,IAAI,GACF,IAAY;OACP;GACL,IAAM,IAAO,EAAQ,eAAe;GACpC,IAAI,GAAM;IACR,IAAM,IAAa,EAAK,yBACtB,EAAW,aACb;IACA,IAAI,GACF,I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Ae,CAAO;CAE7C,OAAO;EACL,SAAS,IAAW,CAAC,CAAQ,IAAI,CAAC;EAClC;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -1,27 +1,26 @@
1
1
  import { t as e } from "./dedent-Gq6Krl4n.js";
2
2
  import { n as t } from "./logger-CQONztPm.js";
3
- import { h as n, modifyOutcomeToFile as r, r as i } from "./modify-file-GQD6uNgI.js";
4
- import { t as a } from "./svelte-file-B3RfgVdt.js";
5
- import { t as o } from "./compose-handle-Cg9jnCsS.js";
6
- import s from "node:fs";
7
- import c from "node:path";
8
- import { Project as l, QuoteKind as u, SyntaxKind as d } from "ts-morph";
3
+ import { _ as n, o as r, r as i } from "./ts-morph-helpers-CeduA--o.js";
4
+ import { modifyOutcomeToFile as a } from "./modify-file-DGe7MJu_.js";
5
+ import { t as o } from "./svelte-file-B3RfgVdt.js";
6
+ import { t as s } from "./compose-handle-B-CkDcQD.js";
7
+ import c from "node:fs";
8
+ import l from "node:path";
9
+ import { Project as u, QuoteKind as d, SyntaxKind as f } from "ts-morph";
9
10
  //#region src/patterns/enable/content-negotiation/modifies/hooks.server.ts
10
- var f = e`
11
+ var p = e`
11
12
  Wrap your exported handle with the negotiation handler:
12
13
 
13
14
  import { sequence } from '@sveltejs/kit/hooks';
14
15
  import { handle as handleNegotiate } from '$lib/negotiate';
15
16
 
16
17
  export const handle = sequence(handleNegotiate, /* your existing handle */);
17
- `, p = e`
18
- Create src/hooks.server.ts with a negotiation handle:
19
-
18
+ `, m = e`
20
19
  import { handle as handleNegotiate } from '$lib/negotiate';
21
20
 
22
21
  export const handle = handleNegotiate;
23
22
  `;
24
- function m(e) {
23
+ function h(e) {
25
24
  let t = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === "$lib/negotiate");
26
25
  if (t) {
27
26
  t.getNamedImports().some((e) => e.getName() === "handle" && e.getAliasNode()?.getText() === "handleNegotiate") || t.addNamedImport({
@@ -38,42 +37,45 @@ function m(e) {
38
37
  moduleSpecifier: "$lib/negotiate"
39
38
  });
40
39
  }
41
- function h(e) {
42
- if (!s.existsSync(e)) return {
43
- status: "not-found",
40
+ function g(e) {
41
+ if (!c.existsSync(e)) return c.existsSync(e.replace(/\.ts$/, ".js")) ? {
42
+ status: "failed",
44
43
  message: p
45
- };
46
- let t = s.readFileSync(e, "utf8");
44
+ } : (c.mkdirSync(l.dirname(e), { recursive: !0 }), c.writeFileSync(e, m + "\n"), {
45
+ status: "success",
46
+ changed: !0
47
+ });
48
+ let t = c.readFileSync(e, "utf8");
47
49
  if (t.includes("handleNegotiate")) return {
48
50
  status: "success",
49
51
  changed: !1
50
52
  };
51
- let n = new l({
53
+ let n = new u({
52
54
  compilerOptions: { allowJs: !0 },
53
- manipulationSettings: { quoteKind: u.Single }
55
+ manipulationSettings: { quoteKind: d.Single }
54
56
  }).addSourceFileAtPath(e);
55
- return o(n, { expression: "handleNegotiate" }).status === "unsupported" ? {
57
+ return s(n, { expression: "handleNegotiate" }).status === "unsupported" ? {
56
58
  status: "failed",
57
- message: f
58
- } : (m(n), n.formatText(), n.saveSync(), {
59
+ message: p
60
+ } : (h(n), r(n), n.saveSync(), {
59
61
  status: "success",
60
62
  changed: n.getFullText() !== t
61
63
  });
62
64
  }
63
65
  //#endregion
64
66
  //#region src/patterns/enable/content-negotiation/modifies/hooks.ts
65
- var g = e`
67
+ var _ = e`
66
68
  import { reroute as negotiateReroute } from '$lib/negotiate';
67
69
 
68
70
  export const reroute = ({ url }) => negotiateReroute(url.pathname);
69
- `, _ = e`
71
+ `, v = e`
70
72
  Compose your existing reroute in src/hooks.ts with the negotiation reroute:
71
73
 
72
74
  import { reroute as negotiateReroute } from '$lib/negotiate';
73
75
 
74
76
  export const reroute = ({ url }) => existingReroute(negotiateReroute(url.pathname));
75
77
  `;
76
- function v(e) {
78
+ function y(e) {
77
79
  let t = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === "$lib/negotiate");
78
80
  if (t) {
79
81
  t.getNamedImports().some((e) => e.getName() === "reroute" && e.getAliasNode()?.getText() === "negotiateReroute") || t.addNamedImport({
@@ -90,61 +92,61 @@ function v(e) {
90
92
  moduleSpecifier: "$lib/negotiate"
91
93
  });
92
94
  }
93
- function y(e) {
94
- if (!s.existsSync(e)) return s.mkdirSync(c.dirname(e), { recursive: !0 }), s.writeFileSync(e, g + "\n"), {
95
+ function b(e) {
96
+ if (!c.existsSync(e)) return c.mkdirSync(l.dirname(e), { recursive: !0 }), c.writeFileSync(e, _ + "\n"), {
95
97
  status: "success",
96
98
  changed: !0
97
99
  };
98
- if (s.readFileSync(e, "utf8").includes("negotiateReroute")) return {
100
+ if (c.readFileSync(e, "utf8").includes("negotiateReroute")) return {
99
101
  status: "success",
100
102
  changed: !1
101
103
  };
102
- let t = new l({
104
+ let t = new u({
103
105
  compilerOptions: { allowJs: !0 },
104
- manipulationSettings: { quoteKind: u.Single }
106
+ manipulationSettings: { quoteKind: d.Single }
105
107
  }).addSourceFileAtPath(e), n = t.getVariableDeclaration("reroute");
106
- if (!n) return v(t), t.addStatements("\nexport const reroute = ({ url }) => negotiateReroute(url.pathname);\n"), t.formatText(), t.saveSync(), {
108
+ if (!n) return y(t), t.addStatements("\nexport const reroute = ({ url }) => negotiateReroute(url.pathname);\n"), r(t), t.saveSync(), {
107
109
  status: "success",
108
110
  changed: !0
109
111
  };
110
- if (!n.getFirstAncestorByKind(d.VariableStatement)?.hasExportKeyword()) return {
112
+ if (!n.getFirstAncestorByKind(f.VariableStatement)?.hasExportKeyword()) return {
111
113
  status: "failed",
112
- message: _
114
+ message: v
113
115
  };
114
- let r = n.getInitializer();
115
- if (!r) return {
116
+ let i = n.getInitializer();
117
+ if (!i) return {
116
118
  status: "failed",
117
- message: _
119
+ message: v
118
120
  };
119
- let i = t.getVariableDeclarations().some((e) => e.getName() === "rerouteDeLocalize"), a = r.getText();
120
- return i && a.includes("rerouteDeLocalize") ? (v(t), n.setInitializer("({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))"), t.formatText(), t.saveSync(), {
121
+ let a = t.getVariableDeclarations().some((e) => e.getName() === "rerouteDeLocalize"), o = i.getText();
122
+ return a && o.includes("rerouteDeLocalize") ? (y(t), n.setInitializer("({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))"), r(t), t.saveSync(), {
121
123
  status: "success",
122
124
  changed: !0
123
125
  }) : {
124
126
  status: "failed",
125
- message: _
127
+ message: v
126
128
  };
127
129
  }
128
130
  //#endregion
129
131
  //#region src/patterns/enable/content-negotiation/modifies/root-layout.svelte.ts
130
- var b = e`
132
+ var x = e`
131
133
  import { Negotiate } from '$lib/negotiate';
132
- `, x = "\n<Negotiate />\n", S = [
134
+ `, S = "\n<Negotiate />\n", C = [
133
135
  "Create the root +layout.svelte and mount <Negotiate /> inside it.",
134
136
  "",
135
137
  "Import for the <script> tag:",
136
138
  "",
137
- b,
139
+ x,
138
140
  "",
139
141
  "Markup to add at the top level of the layout:",
140
- x.trim()
142
+ S.trim()
141
143
  ].join("\n");
142
- function C(e) {
143
- if (!s.existsSync(e)) return {
144
+ function w(e) {
145
+ if (!c.existsSync(e)) return {
144
146
  status: "not-found",
145
- message: S
147
+ message: C
146
148
  };
147
- let t = a.fromPath(e);
149
+ let t = o.fromPath(e);
148
150
  return t.hasElement("Negotiate") ? {
149
151
  status: "success",
150
152
  changed: !1
@@ -156,26 +158,26 @@ function C(e) {
156
158
  }]);
157
159
  });
158
160
  return t;
159
- }), t.appendMarkup(x), t.writeTo(e), {
161
+ }), t.appendMarkup(S), t.writeTo(e), {
160
162
  status: "success",
161
163
  changed: t.hasChanged()
162
164
  });
163
165
  }
164
166
  //#endregion
165
167
  //#region src/patterns/enable/content-negotiation/generate.runtime.ts
166
- async function w(e) {
167
- let n = t(e), i = [], a = (e) => {
168
- e && i.push(e);
168
+ async function T(e) {
169
+ let n = t(e), r = [], i = (e) => {
170
+ e && r.push(e);
169
171
  };
170
172
  n.info("Modifying hooks.server.ts");
171
- let o = c.join(e.root, "src", "hooks.server.ts");
172
- a(r(o, h(o))), n.info("Modifying hooks.ts");
173
- let s = c.join(e.root, "src", "hooks.ts");
174
- a(r(s, y(s))), n.info("Modifying src/routes/+layout.svelte");
175
- let l = c.join(e.root, "src", "routes", "+layout.svelte");
176
- return a(r(l, C(l))), {
173
+ let o = l.join(e.root, "src", "hooks.server.ts");
174
+ i(a(o, g(o))), n.info("Modifying hooks.ts");
175
+ let s = l.join(e.root, "src", "hooks.ts");
176
+ i(a(s, b(s))), n.info("Modifying src/routes/+layout.svelte");
177
+ let c = l.join(e.root, "src", "routes", "+layout.svelte");
178
+ return i(a(c, w(c))), {
177
179
  creates: [],
178
- modifies: i,
180
+ modifies: r,
179
181
  deletes: [],
180
182
  components: [],
181
183
  packages: [],
@@ -185,6 +187,6 @@ async function w(e) {
185
187
  };
186
188
  }
187
189
  //#endregion
188
- export { w as generate };
190
+ export { T as generate };
189
191
 
190
- //# sourceMappingURL=generate.runtime-DhkaXTq3.js.map
192
+ //# sourceMappingURL=generate.runtime-C9fSqy6a.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.runtime-C9fSqy6a.js","names":[],"sources":["../../src/patterns/enable/content-negotiation/modifies/hooks.server.ts","../../src/patterns/enable/content-negotiation/modifies/hooks.ts","../../src/patterns/enable/content-negotiation/modifies/root-layout.svelte.ts","../../src/patterns/enable/content-negotiation/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { addHandle } from \"../../../../runtime/compose-handle\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Wrap your exported handle with the negotiation handler:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { handle as handleNegotiate } from '$lib/negotiate';\n\n export const handle = sequence(handleNegotiate, /* your existing handle */);\n`;\n\nconst HOOKS_SERVER_SNIPPET = dedent`\n import { handle as handleNegotiate } from '$lib/negotiate';\n\n export const handle = handleNegotiate;\n`;\n\nfunction ensureNegotiateHandleImport(sourceFile: SourceFile) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === \"$lib/negotiate\");\n if (existing) {\n const has = existing.getNamedImports().some((ni) => {\n return (\n ni.getName() === \"handle\" &&\n ni.getAliasNode()?.getText() === \"handleNegotiate\"\n );\n });\n if (!has)\n existing.addNamedImport({ name: \"handle\", alias: \"handleNegotiate\" });\n return;\n }\n sourceFile.addImportDeclaration({\n namedImports: [{ name: \"handle\", alias: \"handleNegotiate\" }],\n moduleSpecifier: \"$lib/negotiate\",\n });\n}\n\nexport function modifyHooksServerNegotiate(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n // SvelteKit loads the first `hooks.server.*` it finds, and `.js` sorts\n // first, so a new `.ts` beside it would never run.\n if (fs.existsSync(hooksServerPath.replace(/\\.ts$/, \".js\"))) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.mkdirSync(path.dirname(hooksServerPath), { recursive: true });\n fs.writeFileSync(hooksServerPath, HOOKS_SERVER_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"handleNegotiate\")) {\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 const composed = addHandle(sourceFile, { expression: \"handleNegotiate\" });\n if (composed.status === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNegotiateHandleImport(sourceFile);\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst NEGOTIATE_ONLY_SNIPPET = dedent`\n import { reroute as negotiateReroute } from '$lib/negotiate';\n\n export const reroute = ({ url }) => negotiateReroute(url.pathname);\n`;\n\nconst FAILURE_HINT = dedent`\n Compose your existing reroute in src/hooks.ts with the negotiation reroute:\n\n import { reroute as negotiateReroute } from '$lib/negotiate';\n\n export const reroute = ({ url }) => existingReroute(negotiateReroute(url.pathname));\n`;\n\nfunction ensureNegotiateImport(sourceFile: SourceFile) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === \"$lib/negotiate\");\n if (existing) {\n const has = existing.getNamedImports().some((ni) => {\n return (\n ni.getName() === \"reroute\" &&\n ni.getAliasNode()?.getText() === \"negotiateReroute\"\n );\n });\n if (!has) {\n existing.addNamedImport({ name: \"reroute\", alias: \"negotiateReroute\" });\n }\n return;\n }\n sourceFile.addImportDeclaration({\n namedImports: [{ name: \"reroute\", alias: \"negotiateReroute\" }],\n moduleSpecifier: \"$lib/negotiate\",\n });\n}\n\nexport function modifyHooksNegotiate(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n fs.mkdirSync(path.dirname(hooksPath), { recursive: true });\n fs.writeFileSync(hooksPath, NEGOTIATE_ONLY_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (original.includes(\"negotiateReroute\")) {\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(hooksPath);\n\n const rerouteDecl = sourceFile.getVariableDeclaration(\"reroute\");\n\n if (!rerouteDecl) {\n ensureNegotiateImport(sourceFile);\n sourceFile.addStatements(\n `\\nexport const reroute = ({ url }) => negotiateReroute(url.pathname);\\n`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const rerouteStmt = rerouteDecl.getFirstAncestorByKind(\n SyntaxKind.VariableStatement,\n );\n if (!rerouteStmt?.hasExportKeyword()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const init = rerouteDecl.getInitializer();\n if (!init) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const hasI18nHelper = sourceFile\n .getVariableDeclarations()\n .some((d) => d.getName() === \"rerouteDeLocalize\");\n const initText = init.getText();\n\n if (hasI18nHelper && initText.includes(\"rerouteDeLocalize\")) {\n ensureNegotiateImport(sourceFile);\n rerouteDecl.setInitializer(\n \"({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))\",\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n return { status: \"failed\", message: FAILURE_HINT };\n}\n","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\nconst IMPORT_SNIPPET = dedent`\n import { Negotiate } from '$lib/negotiate';\n`;\n\nconst MARKUP_SNIPPET = \"\\n<Negotiate />\\n\";\n\nconst NOT_FOUND_HINT = [\n \"Create the root +layout.svelte and mount <Negotiate /> inside it.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\nexport function modifyRootLayoutNegotiate(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(\"Negotiate\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n namedImports: [\"Negotiate\"],\n moduleSpecifier: \"$lib/negotiate\",\n },\n ]);\n });\n return out;\n });\n\n file.appendMarkup(MARKUP_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\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 { modifyHooksServerNegotiate } from \"./modifies/hooks.server\";\nimport { modifyHooksNegotiate } from \"./modifies/hooks\";\nimport { modifyRootLayoutNegotiate } from \"./modifies/root-layout.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerNegotiate(hooksServerPath),\n ),\n );\n\n logger.info(\"Modifying hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n pushResult(modifyOutcomeToFile(hooksPath, modifyHooksNegotiate(hooksPath)));\n\n logger.info(\"Modifying src/routes/+layout.svelte\");\n const rootLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutNegotiate(rootLayoutPath),\n ),\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":";;;;;;;;;;AAQA,IAAM,IAAe,CAAM;;;;;;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