@lomray/vite-ssr-boost 8.0.0-beta.1 → 8.0.0-beta.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 (204) hide show
  1. package/README.md +2 -1
  2. package/adapters/body.d.ts +1 -1
  3. package/adapters/body.js +1 -1
  4. package/adapters/body.js.map +1 -1
  5. package/adapters/compression.d.ts +5 -5
  6. package/adapters/compression.js +1 -1
  7. package/adapters/compression.js.map +1 -1
  8. package/adapters/edge.d.ts +5 -5
  9. package/adapters/edge.js.map +1 -1
  10. package/adapters/express/create-request.d.ts +2 -2
  11. package/adapters/express/create-request.js.map +1 -1
  12. package/adapters/express/entry.d.ts +17 -19
  13. package/adapters/express/entry.js.map +1 -1
  14. package/adapters/express/prepare-server.d.ts +7 -25
  15. package/adapters/express/prepare-server.js +1 -1
  16. package/adapters/express/prepare-server.js.map +1 -1
  17. package/adapters/express/render.d.ts +14 -15
  18. package/adapters/express/render.js +1 -1
  19. package/adapters/express/render.js.map +1 -1
  20. package/adapters/express/server.d.ts +5 -6
  21. package/adapters/express/server.js +1 -1
  22. package/adapters/express/server.js.map +1 -1
  23. package/adapters/express.d.ts +5 -5
  24. package/adapters/express.js.map +1 -1
  25. package/adapters/fastify.d.ts +5 -5
  26. package/adapters/fastify.js +1 -1
  27. package/adapters/fastify.js.map +1 -1
  28. package/adapters/hono.d.ts +2 -2
  29. package/adapters/hono.js.map +1 -1
  30. package/adapters/node.d.ts +6 -5
  31. package/adapters/node.js.map +1 -1
  32. package/browser/entry.d.ts +9 -9
  33. package/browser/entry.js +1 -1
  34. package/browser/entry.js.map +1 -1
  35. package/cli/build.d.ts +2 -2
  36. package/cli/build.js.map +1 -1
  37. package/cli/helpers/keyboard-input.d.ts +1 -1
  38. package/cli/helpers/keyboard-input.js +1 -1
  39. package/cli/helpers/keyboard-input.js.map +1 -1
  40. package/cli/helpers/vite-reset-cache.d.ts +1 -1
  41. package/cli/helpers/vite-reset-cache.js.map +1 -1
  42. package/cli/interfaces/actions.d.ts +8 -9
  43. package/cli/run-amplify-build.d.ts +1 -1
  44. package/cli/run-amplify-build.js.map +1 -1
  45. package/cli/run-dev.d.ts +3 -4
  46. package/cli/run-dev.js.map +1 -1
  47. package/cli/run-docker-build.d.ts +2 -2
  48. package/cli/run-docker-build.js.map +1 -1
  49. package/cli/run-prod.d.ts +4 -5
  50. package/cli/run-prod.js.map +1 -1
  51. package/cli/run-serverless.d.ts +2 -2
  52. package/cli/run-serverless.js.map +1 -1
  53. package/cli/run-vercel-build.d.ts +1 -1
  54. package/cli/run-vercel-build.js.map +1 -1
  55. package/cli.js +1 -1
  56. package/cli.js.map +1 -1
  57. package/components/navigate.d.ts +3 -3
  58. package/components/navigate.js.map +1 -1
  59. package/components/only-client.d.ts +2 -2
  60. package/components/only-client.js +1 -1
  61. package/components/only-client.js.map +1 -1
  62. package/components/render-client.d.ts +4 -4
  63. package/components/render-client.js +1 -1
  64. package/components/render-client.js.map +1 -1
  65. package/components/response-status.d.ts +2 -2
  66. package/components/response-status.js.map +1 -1
  67. package/components/scroll-to-top.d.ts +2 -2
  68. package/components/scroll-to-top.js +1 -1
  69. package/components/scroll-to-top.js.map +1 -1
  70. package/components/with-suspense.d.ts +3 -3
  71. package/components/with-suspense.js.map +1 -1
  72. package/constants/cli-actions.d.ts +1 -1
  73. package/constants/cli-actions.js.map +1 -1
  74. package/constants/cli-context.d.ts +4 -5
  75. package/constants/cli-context.js.map +1 -1
  76. package/constants/cli-name.d.ts +1 -1
  77. package/constants/cli-name.js.map +1 -1
  78. package/constants/cli-shortcuts.d.ts +2 -2
  79. package/constants/cli-shortcuts.js +1 -1
  80. package/constants/cli-shortcuts.js.map +1 -1
  81. package/constants/common.js.map +1 -1
  82. package/constants/plugin-name.d.ts +1 -1
  83. package/constants/plugin-name.js.map +1 -1
  84. package/constants/stream-error.d.ts +1 -1
  85. package/constants/stream-error.js.map +1 -1
  86. package/context/server.d.ts +3 -4
  87. package/context/server.js.map +1 -1
  88. package/core/compose-html.d.ts +2 -2
  89. package/core/compose-html.js.map +1 -1
  90. package/core/early-hints.d.ts +2 -2
  91. package/core/early-hints.js.map +1 -1
  92. package/core/handler.d.ts +3 -3
  93. package/core/handler.js.map +1 -1
  94. package/core/head-response.d.ts +1 -1
  95. package/core/head-response.js.map +1 -1
  96. package/core/headers.d.ts +3 -4
  97. package/core/headers.js +1 -1
  98. package/core/headers.js.map +1 -1
  99. package/core/render.d.ts +13 -13
  100. package/core/render.js +1 -1
  101. package/core/render.js.map +1 -1
  102. package/core/transform-html.d.ts +1 -1
  103. package/core/transform-html.js.map +1 -1
  104. package/core/types.d.ts +2 -3
  105. package/edge/render-to-stream.d.ts +2 -2
  106. package/edge/render-to-stream.js +1 -1
  107. package/edge/render-to-stream.js.map +1 -1
  108. package/helpers/build-custom-state.d.ts +1 -1
  109. package/helpers/build-custom-state.js +1 -1
  110. package/helpers/build-custom-state.js.map +1 -1
  111. package/helpers/build-router-state.d.ts +2 -2
  112. package/helpers/build-router-state.js.map +1 -1
  113. package/helpers/create-focus-only.d.ts +3 -3
  114. package/helpers/create-focus-only.js.map +1 -1
  115. package/helpers/dev-marker.d.ts +1 -1
  116. package/helpers/dev-marker.js.map +1 -1
  117. package/helpers/get-server-state.d.ts +1 -1
  118. package/helpers/get-server-state.js.map +1 -1
  119. package/helpers/html-escape.d.ts +1 -1
  120. package/helpers/html-escape.js +1 -1
  121. package/helpers/html-escape.js.map +1 -1
  122. package/helpers/import-route.d.ts +7 -7
  123. package/helpers/import-route.js +1 -1
  124. package/helpers/import-route.js.map +1 -1
  125. package/helpers/is-route-file.d.ts +1 -1
  126. package/helpers/is-route-file.js.map +1 -1
  127. package/helpers/obtain-stream-error.d.ts +3 -3
  128. package/helpers/obtain-stream-error.js.map +1 -1
  129. package/helpers/plugin-config.d.ts +5 -5
  130. package/helpers/plugin-config.js +1 -1
  131. package/helpers/plugin-config.js.map +1 -1
  132. package/helpers/print-server-info.d.ts +3 -4
  133. package/helpers/print-server-info.js +1 -1
  134. package/helpers/print-server-info.js.map +1 -1
  135. package/helpers/print-server-urls.d.ts +2 -2
  136. package/helpers/print-server-urls.js +1 -1
  137. package/helpers/print-server-urls.js.map +1 -1
  138. package/helpers/process-stop.d.ts +1 -1
  139. package/helpers/process-stop.js.map +1 -1
  140. package/helpers/resolve-server-urls.d.ts +3 -4
  141. package/helpers/resolve-server-urls.js +1 -1
  142. package/helpers/resolve-server-urls.js.map +1 -1
  143. package/helpers/serialize-errors.d.ts +2 -2
  144. package/helpers/serialize-errors.js.map +1 -1
  145. package/helpers/vite-aliases.d.ts +2 -2
  146. package/helpers/vite-aliases.js +1 -1
  147. package/helpers/vite-aliases.js.map +1 -1
  148. package/interfaces/fc-route.d.ts +4 -4
  149. package/interfaces/fc-route.js.map +1 -1
  150. package/interfaces/fc.d.ts +3 -4
  151. package/interfaces/route-object.d.ts +6 -6
  152. package/node/compress-response.d.ts +2 -2
  153. package/node/compress-response.js +1 -1
  154. package/node/compress-response.js.map +1 -1
  155. package/node/create-headers.d.ts +1 -1
  156. package/node/create-headers.js.map +1 -1
  157. package/node/create-request.d.ts +2 -2
  158. package/node/create-request.js.map +1 -1
  159. package/node/http.d.ts +4 -6
  160. package/node/render-to-stream.d.ts +2 -2
  161. package/node/render-to-stream.js +1 -1
  162. package/node/render-to-stream.js.map +1 -1
  163. package/node/request-signal.d.ts +2 -2
  164. package/node/request-signal.js.map +1 -1
  165. package/node/split-link-header.d.ts +1 -1
  166. package/node/split-link-header.js.map +1 -1
  167. package/node/write-early-hints.d.ts +2 -2
  168. package/node/write-early-hints.js.map +1 -1
  169. package/node/write-fetch-response.d.ts +3 -2
  170. package/node/write-fetch-response.js +1 -1
  171. package/node/write-fetch-response.js.map +1 -1
  172. package/package.json +52 -32
  173. package/plugin.d.ts +7 -7
  174. package/plugin.js.map +1 -1
  175. package/plugins/create-spa-index.d.ts +3 -3
  176. package/plugins/create-spa-index.js.map +1 -1
  177. package/plugins/handle-custom-entrypoint.d.ts +4 -4
  178. package/plugins/handle-custom-entrypoint.js +1 -1
  179. package/plugins/handle-custom-entrypoint.js.map +1 -1
  180. package/plugins/make-aliases.d.ts +3 -3
  181. package/plugins/make-aliases.js +1 -1
  182. package/plugins/make-aliases.js.map +1 -1
  183. package/plugins/normalize-route.d.ts +3 -3
  184. package/plugins/normalize-route.js.map +1 -1
  185. package/services/build.d.ts +5 -51
  186. package/services/build.js +1 -1
  187. package/services/build.js.map +1 -1
  188. package/services/logger.d.ts +2 -30
  189. package/services/logger.js.map +1 -1
  190. package/services/parse-routes.d.ts +5 -42
  191. package/services/parse-routes.js +1 -1
  192. package/services/parse-routes.js.map +1 -1
  193. package/services/path-normalize.d.ts +3 -18
  194. package/services/path-normalize.js +1 -1
  195. package/services/path-normalize.js.map +1 -1
  196. package/services/server-api.d.ts +1 -7
  197. package/services/server-api.js.map +1 -1
  198. package/services/server-config.d.ts +4 -48
  199. package/services/server-config.js +1 -1
  200. package/services/server-config.js.map +1 -1
  201. package/services/ssr-manifest.d.ts +6 -63
  202. package/services/ssr-manifest.js +1 -1
  203. package/services/ssr-manifest.js.map +1 -1
  204. package/workflow/Dockerfile +1 -1
@@ -1,4 +1,4 @@
1
- import { TIncomingMessage, TServerResponse } from "./http.js";
1
+ import type { TIncomingMessage, TServerResponse } from './http.js';
2
2
  interface IRequestSignal {
3
3
  dispose: () => void;
4
4
  signal: AbortSignal;
@@ -7,4 +7,4 @@ interface IRequestSignal {
7
7
  * Expose incomplete Node requests and disconnected responses as an AbortSignal.
8
8
  */
9
9
  declare const createRequestSignal: (req: TIncomingMessage, res: TServerResponse) => IRequestSignal;
10
- export { createRequestSignal as default };
10
+ export default createRequestSignal;
@@ -1 +1 @@
1
- {"version":3,"file":"request-signal.js","sources":["../../src/node/request-signal.ts"],"sourcesContent":["import type { TIncomingMessage, TServerResponse } from '@node/http';\n\ninterface IRequestSignal {\n dispose: () => void;\n signal: AbortSignal;\n}\n\n/**\n * Expose incomplete Node requests and disconnected responses as an AbortSignal.\n */\nconst createRequestSignal = (req: TIncomingMessage, res: TServerResponse): IRequestSignal => {\n const controller = new AbortController();\n\n /**\n * Cancel downstream work when the incoming request is aborted.\n */\n const abort = (): void => controller.abort();\n\n /**\n * Distinguish an interrupted response from normal completion.\n */\n const onClose = (): void => {\n if (!res.writableEnded) {\n abort();\n }\n };\n\n /**\n * Remove transport listeners after the handler finishes.\n */\n const dispose = (): void => {\n req.off('aborted', abort);\n res.off('close', onClose);\n };\n\n req.once('aborted', abort);\n res.once('close', onClose);\n\n if (req.aborted || res.destroyed) {\n abort();\n }\n\n return { dispose, signal: controller.signal };\n};\n\nexport default createRequestSignal;\n"],"names":["createRequestSignal","req","res","controller","AbortController","abort","onClose","writableEnded","once","aborted","destroyed","dispose","off","signal"],"mappings":"AAUA,MAAMA,EAAsB,CAACC,EAAuBC,KAClD,MAAMC,EAAa,IAAIC,gBAKjBC,EAAQ,IAAYF,EAAWE,QAK/BC,EAAU,KACTJ,EAAIK,eACPF,GACF,EAkBF,OAPAJ,EAAIO,KAAK,UAAWH,GACpBH,EAAIM,KAAK,QAASF,IAEdL,EAAIQ,SAAWP,EAAIQ,YACrBL,IAGK,CAAEM,QAZO,KACdV,EAAIW,IAAI,UAAWP,GACnBH,EAAIU,IAAI,QAASN,EAAQ,EAUTO,OAAQV,EAAWU,OAAQ"}
1
+ {"version":3,"file":"request-signal.js","sources":["../../src/node/request-signal.ts"],"sourcesContent":[null],"names":["createRequestSignal","req","res","controller","AbortController","abort","onClose","writableEnded","once","aborted","destroyed","dispose","off","signal"],"mappings":"AAUA,MAAMA,EAAsB,CAACC,EAAuBC,KAClD,MAAMC,EAAa,IAAIC,gBAKjBC,EAAQ,IAAYF,EAAWE,QAK/BC,EAAU,KACTJ,EAAIK,eACPF,KAmBJ,OAPAJ,EAAIO,KAAK,UAAWH,GACpBH,EAAIM,KAAK,QAASF,IAEdL,EAAIQ,SAAWP,EAAIQ,YACrBL,IAGK,CAAEM,QAZO,KACdV,EAAIW,IAAI,UAAWP,GACnBH,EAAIU,IAAI,QAASN,IAUDO,OAAQV,EAAWU"}
@@ -2,4 +2,4 @@
2
2
  * Split Link entries while preserving commas inside URLs and quoted parameters.
3
3
  */
4
4
  declare const splitLinkHeader: (header: string) => string[];
5
- export { splitLinkHeader as default };
5
+ export default splitLinkHeader;
@@ -1 +1 @@
1
- {"version":3,"file":"split-link-header.js","sources":["../../src/node/split-link-header.ts"],"sourcesContent":["/**\n * Split Link entries while preserving commas inside URLs and quoted parameters.\n */\nconst splitLinkHeader = (header: string): string[] => {\n const links: string[] = [];\n let angleDepth = 0;\n let isEscaped = false;\n let isQuoted = false;\n let start = 0;\n\n for (let index = 0; index < header.length; index += 1) {\n const char = header[index];\n\n if (isEscaped) {\n isEscaped = false;\n } else if (char === '\\\\' && isQuoted) {\n isEscaped = true;\n } else if (char === '\"') {\n isQuoted = !isQuoted;\n } else if (!isQuoted && char === '<') {\n angleDepth += 1;\n } else if (!isQuoted && char === '>') {\n angleDepth = Math.max(0, angleDepth - 1);\n } else if (!isQuoted && angleDepth === 0 && char === ',') {\n links.push(header.slice(start, index).trim());\n start = index + 1;\n }\n }\n\n links.push(header.slice(start).trim());\n\n return links.filter(Boolean);\n};\n\nexport default splitLinkHeader;\n"],"names":["splitLinkHeader","header","links","angleDepth","isEscaped","isQuoted","start","index","length","char","push","slice","trim","Math","max","filter","Boolean"],"mappings":"AAGA,MAAMA,EAAmBC,IACvB,MAAMC,EAAkB,GACxB,IAAIC,EAAa,EACbC,GAAY,EACZC,GAAW,EACXC,EAAQ,EAEZ,IAAK,IAAIC,EAAQ,EAAGA,EAAQN,EAAOO,OAAQD,GAAS,EAAG,CACrD,MAAME,EAAOR,EAAOM,GAEhBH,EACFA,GAAY,EACM,OAATK,GAAiBJ,EAC1BD,GAAY,EACM,MAATK,EACTJ,GAAYA,EACFA,GAAqB,MAATI,EAEZJ,GAAqB,MAATI,EAEZJ,GAA2B,IAAfF,GAA6B,MAATM,IAC1CP,EAAMQ,KAAKT,EAAOU,MAAML,EAAOC,GAAOK,QACtCN,EAAQC,EAAQ,GAHhBJ,EAAaU,KAAKC,IAAI,EAAGX,EAAa,GAFtCA,GAAc,CAOlB,CAIA,OAFAD,EAAMQ,KAAKT,EAAOU,MAAML,GAAOM,QAExBV,EAAMa,OAAOC,QAAQ"}
1
+ {"version":3,"file":"split-link-header.js","sources":["../../src/node/split-link-header.ts"],"sourcesContent":[null],"names":["splitLinkHeader","header","links","angleDepth","isEscaped","isQuoted","start","index","length","char","push","slice","trim","Math","max","filter","Boolean"],"mappings":"AAGA,MAAMA,EAAmBC,IACvB,MAAMC,EAAkB,GACxB,IAAIC,EAAa,EACbC,GAAY,EACZC,GAAW,EACXC,EAAQ,EAEZ,IAAK,IAAIC,EAAQ,EAAGA,EAAQN,EAAOO,OAAQD,GAAS,EAAG,CACrD,MAAME,EAAOR,EAAOM,GAEhBH,EACFA,GAAY,EACM,OAATK,GAAiBJ,EAC1BD,GAAY,EACM,MAATK,EACTJ,GAAYA,EACFA,GAAqB,MAATI,EAEZJ,GAAqB,MAATI,EAEZJ,GAA2B,IAAfF,GAA6B,MAATM,IAC1CP,EAAMQ,KAAKT,EAAOU,MAAML,EAAOC,GAAOK,QACtCN,EAAQC,EAAQ,GAHhBJ,EAAaU,KAAKC,IAAI,EAAGX,EAAa,GAFtCA,GAAc,CAOlB,CAIA,OAFAD,EAAMQ,KAAKT,EAAOU,MAAML,GAAOM,QAExBV,EAAMa,OAAOC"}
@@ -1,6 +1,6 @@
1
- import { TServerResponse } from "./http.js";
1
+ import type { TServerResponse } from './http.js';
2
2
  /**
3
3
  * Send Node early hints with distinct Link entries when the transport supports them.
4
4
  */
5
5
  declare const writeEarlyHints: (res: TServerResponse, headers: Headers) => void;
6
- export { writeEarlyHints as default };
6
+ export default writeEarlyHints;
@@ -1 +1 @@
1
- {"version":3,"file":"write-early-hints.js","sources":["../../src/node/write-early-hints.ts"],"sourcesContent":["import { getHeaderEntries } from '@core/headers';\nimport type { TServerResponse } from '@node/http';\nimport splitLinkHeader from '@node/split-link-header';\n\n/**\n * Send Node early hints with distinct Link entries when the transport supports them.\n */\nconst writeEarlyHints = (res: TServerResponse, headers: Headers): void => {\n if (res.headersSent || typeof res.writeEarlyHints !== 'function') {\n return;\n }\n\n const hints: Record<string, string | string[]> = Object.fromEntries(getHeaderEntries(headers));\n const link = headers.get('Link');\n\n if (link) {\n hints.link = splitLinkHeader(link);\n }\n\n if (Object.keys(hints).length) {\n res.writeEarlyHints(hints);\n }\n};\n\nexport default writeEarlyHints;\n"],"names":["writeEarlyHints","res","headers","headersSent","hints","Object","fromEntries","getHeaderEntries","link","get","splitLinkHeader","keys","length"],"mappings":"4FAOA,MAAMA,EAAkB,CAACC,EAAsBC,KAC7C,GAAID,EAAIE,aAA8C,mBAAxBF,EAAID,gBAChC,OAGF,MAAMI,EAA2CC,OAAOC,YAAYC,EAAiBL,IAC/EM,EAAON,EAAQO,IAAI,QAErBD,IACFJ,EAAMI,KAAOE,EAAgBF,IAG3BH,OAAOM,KAAKP,GAAOQ,QACrBX,EAAID,gBAAgBI,EACtB"}
1
+ {"version":3,"file":"write-early-hints.js","sources":["../../src/node/write-early-hints.ts"],"sourcesContent":[null],"names":["writeEarlyHints","res","headers","headersSent","hints","Object","fromEntries","getHeaderEntries","link","get","splitLinkHeader","keys","length"],"mappings":"4FAOA,MAAMA,EAAkB,CAACC,EAAsBC,KAC7C,GAAID,EAAIE,aAA8C,mBAAxBF,EAAID,gBAChC,OAGF,MAAMI,EAA2CC,OAAOC,YAAYC,EAAiBL,IAC/EM,EAAON,EAAQO,IAAI,QAErBD,IACFJ,EAAMI,KAAOE,EAAgBF,IAG3BH,OAAOM,KAAKP,GAAOQ,QACrBX,EAAID,gBAAgBI"}
@@ -1,4 +1,4 @@
1
- import { TServerResponse } from "./http.js";
1
+ import type { TServerResponse } from './http.js';
2
2
  /**
3
3
  * Write Fetch status and headers while preserving existing transport cookies.
4
4
  */
@@ -7,4 +7,5 @@ declare const writeFetchHeaders: (res: TServerResponse, response: Response) => v
7
7
  * Write the Fetch body with backpressure and cancel unread data on disconnect.
8
8
  */
9
9
  declare const writeFetchResponse: (res: TServerResponse, response: Response) => Promise<void>;
10
- export { writeFetchResponse as default, writeFetchHeaders };
10
+ export { writeFetchHeaders };
11
+ export default writeFetchResponse;
@@ -1,2 +1,2 @@
1
- import{getHeaderEntries as e,getSetCookieHeaders as r}from"../core/headers.js";const a="Set-Cookie",o=(o,d)=>{o.statusCode=d.status,e(d.headers).forEach((([e,r])=>o.setHeader(e,r)));const t=r(d.headers);if("function"==typeof o.appendHeader)t.forEach((e=>o.appendHeader(a,e)));else if(t.length){const e=o.getHeader(a),r=Array.isArray(e)?e:[String(e)];o.setHeader(a,e?[...r,...t]:t)}},d=e=>new Promise(((r,a)=>{const o=()=>{e.off("close",d),e.off("drain",t),e.off("error",n)},d=()=>{o(),a(new Error("Response closed before drain."))},t=()=>{o(),r()},n=e=>{o(),a(e)};e.once("close",d),e.once("drain",t),e.once("error",n)})),t=async(e,r)=>{if(e.destroyed||e.writableEnded)return void await(r.body?.cancel());if(e.headersSent||o(e,r),!r.body||"HEAD"===e.req?.method||[204,205,304].includes(e.statusCode))return await(r.body?.cancel()),void e.end();const a=r.body.getReader(),t=()=>{e.writableEnded||a.cancel().catch((()=>{}))};e.once("close",t);try{for(;;){const r=await a.read();if(r.done)break;if(e.destroyed||e.writableEnded)return void await a.cancel();e.write(r.value)||await d(e),e.flush?.()}e.destroyed||e.writableEnded||e.end()}catch(r){await a.cancel(r).catch((()=>{})),e.destroyed||e.destroy(r)}finally{e.off("close",t),a.releaseLock()}};export{t as default,o as writeFetchHeaders};
1
+ import{getHeaderEntries as e,getSetCookieHeaders as r}from"../core/headers.js";const a="Set-Cookie",o=(o,d)=>{o.statusCode=d.status,e(d.headers).forEach(([e,r])=>o.setHeader(e,r));const t=r(d.headers);if("function"==typeof o.appendHeader)t.forEach(e=>o.appendHeader(a,e));else if(t.length){const e=o.getHeader(a),r=Array.isArray(e)?e:[String(e)];o.setHeader(a,e?[...r,...t]:t)}},d=e=>new Promise((r,a)=>{const o=()=>{e.off("close",d),e.off("drain",t),e.off("error",n)},d=()=>{o(),a(new Error("Response closed before drain."))},t=()=>{o(),r()},n=e=>{o(),a(e)};e.once("close",d),e.once("drain",t),e.once("error",n)}),t=async(e,r)=>{if(e.destroyed||e.writableEnded)return void await(r.body?.cancel());if(e.headersSent||o(e,r),!r.body||"HEAD"===e.req?.method||[204,205,304].includes(e.statusCode))return await(r.body?.cancel()),void e.end();const a=r.body.getReader(),t=()=>{e.writableEnded||a.cancel().catch(()=>{})};e.once("close",t);try{for(;;){const r=await a.read();if(r.done)break;if(e.destroyed||e.writableEnded)return void await a.cancel();e.write(r.value)||await d(e),e.flush?.()}e.destroyed||e.writableEnded||e.end()}catch(r){await a.cancel(r).catch(()=>{}),e.destroyed||e.destroy(r)}finally{e.off("close",t),a.releaseLock()}};export{t as default,o as writeFetchHeaders};
2
2
  //# sourceMappingURL=write-fetch-response.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"write-fetch-response.js","sources":["../../src/node/write-fetch-response.ts"],"sourcesContent":["import { getHeaderEntries, getSetCookieHeaders } from '@core/headers';\nimport type { TServerResponse } from '@node/http';\n\nconst SET_COOKIE = 'Set-Cookie';\n\n/**\n * Write Fetch status and headers while preserving existing transport cookies.\n */\nconst writeFetchHeaders = (res: TServerResponse, response: Response): void => {\n res.statusCode = response.status;\n getHeaderEntries(response.headers).forEach(([name, value]) => res.setHeader(name, value));\n const cookies = getSetCookieHeaders(response.headers);\n\n if (typeof res.appendHeader === 'function') {\n cookies.forEach((cookie) => res.appendHeader(SET_COOKIE, cookie));\n } else if (cookies.length) {\n /**\n * The HTTP/2 compatibility response has setHeader(), but no appendHeader().\n */\n const existing = res.getHeader(SET_COOKIE);\n const previousCookies = Array.isArray(existing) ? existing : [String(existing)];\n\n res.setHeader(SET_COOKIE, existing ? [...previousCookies, ...cookies] : cookies);\n }\n};\n\n/**\n * Wait for response capacity and release listeners on drain, close or failure.\n */\nconst waitForDrain = (res: TServerResponse): Promise<void> =>\n new Promise((resolve, reject) => {\n /**\n * Remove every listener registered for this drain wait.\n */\n const cleanup = (): void => {\n res.off('close', onClose);\n res.off('drain', onDrain);\n res.off('error', onError);\n };\n\n /**\n * Stop waiting for drain when the client closes the response.\n */\n const onClose = (): void => {\n cleanup();\n reject(new Error('Response closed before drain.'));\n };\n\n /**\n * Resume body consumption when the transport has capacity.\n */\n const onDrain = (): void => {\n cleanup();\n resolve();\n };\n\n /**\n * Release drain listeners before rejecting a transport failure.\n */\n const onError = (error: Error): void => {\n cleanup();\n reject(error);\n };\n\n res.once('close', onClose);\n res.once('drain', onDrain);\n res.once('error', onError);\n });\n\n/**\n * Write the Fetch body with backpressure and cancel unread data on disconnect.\n */\nconst writeFetchResponse = async (res: TServerResponse, response: Response): Promise<void> => {\n if (res.destroyed || res.writableEnded) {\n await response.body?.cancel();\n\n return;\n }\n\n if (!res.headersSent) {\n writeFetchHeaders(res, response);\n }\n\n if (!response.body || res.req?.method === 'HEAD' || [204, 205, 304].includes(res.statusCode)) {\n await response.body?.cancel();\n res.end();\n\n return;\n }\n\n const reader = response.body.getReader();\n\n /**\n * Cancel unread Fetch bytes when the response is interrupted.\n */\n const onClose = (): void => {\n if (!res.writableEnded) {\n void reader.cancel().catch(() => undefined);\n }\n };\n\n res.once('close', onClose);\n\n try {\n while (true) {\n const chunk = await reader.read();\n\n if (chunk.done) {\n break;\n }\n\n if (res.destroyed || res.writableEnded) {\n await reader.cancel();\n\n return;\n }\n\n if (!res.write(chunk.value)) {\n await waitForDrain(res);\n }\n\n /**\n * Express compression buffers otherwise: a gzip header alone is not a usable SSR shell.\n */\n (res as TServerResponse & { flush?: () => void }).flush?.();\n }\n\n if (!res.destroyed && !res.writableEnded) {\n res.end();\n }\n } catch (error) {\n await reader.cancel(error).catch(() => undefined);\n\n if (!res.destroyed) {\n res.destroy(error as Error);\n }\n } finally {\n res.off('close', onClose);\n reader.releaseLock();\n }\n};\n\nexport { writeFetchHeaders };\n\nexport default writeFetchResponse;\n"],"names":["SET_COOKIE","writeFetchHeaders","res","response","statusCode","status","getHeaderEntries","headers","forEach","name","value","setHeader","cookies","getSetCookieHeaders","appendHeader","cookie","length","existing","getHeader","previousCookies","Array","isArray","String","waitForDrain","Promise","resolve","reject","cleanup","off","onClose","onDrain","onError","Error","error","once","writeFetchResponse","async","destroyed","writableEnded","body","cancel","headersSent","req","method","includes","end","reader","getReader","catch","chunk","read","done","write","flush","destroy","releaseLock"],"mappings":"+EAGA,MAAMA,EAAa,aAKbC,EAAoB,CAACC,EAAsBC,KAC/CD,EAAIE,WAAaD,EAASE,OAC1BC,EAAiBH,EAASI,SAASC,SAAQ,EAAEC,EAAMC,KAAWR,EAAIS,UAAUF,EAAMC,KAClF,MAAME,EAAUC,EAAoBV,EAASI,SAE7C,GAAgC,mBAArBL,EAAIY,aACbF,EAAQJ,SAASO,GAAWb,EAAIY,aAAad,EAAYe,UACpD,GAAIH,EAAQI,OAAQ,CAIzB,MAAMC,EAAWf,EAAIgB,UAAUlB,GACzBmB,EAAkBC,MAAMC,QAAQJ,GAAYA,EAAW,CAACK,OAAOL,IAErEf,EAAIS,UAAUX,EAAYiB,EAAW,IAAIE,KAAoBP,GAAWA,EAC1E,GAMIW,EAAgBrB,GACpB,IAAIsB,SAAQ,CAACC,EAASC,KAIpB,MAAMC,EAAU,KACdzB,EAAI0B,IAAI,QAASC,GACjB3B,EAAI0B,IAAI,QAASE,GACjB5B,EAAI0B,IAAI,QAASG,EAAQ,EAMrBF,EAAU,KACdF,IACAD,EAAO,IAAIM,MAAM,iCAAiC,EAM9CF,EAAU,KACdH,IACAF,GAAS,EAMLM,EAAWE,IACfN,IACAD,EAAOO,EAAM,EAGf/B,EAAIgC,KAAK,QAASL,GAClB3B,EAAIgC,KAAK,QAASJ,GAClB5B,EAAIgC,KAAK,QAASH,EAAQ,IAMxBI,EAAqBC,MAAOlC,EAAsBC,KACtD,GAAID,EAAImC,WAAanC,EAAIoC,cAGvB,kBAFMnC,EAASoC,MAAMC,UASvB,GAJKtC,EAAIuC,aACPxC,EAAkBC,EAAKC,IAGpBA,EAASoC,MAA4B,SAApBrC,EAAIwC,KAAKC,QAAqB,CAAC,IAAK,IAAK,KAAKC,SAAS1C,EAAIE,YAI/E,aAHMD,EAASoC,MAAMC,eACrBtC,EAAI2C,MAKN,MAAMC,EAAS3C,EAASoC,KAAKQ,YAKvBlB,EAAU,KACT3B,EAAIoC,eACFQ,EAAON,SAASQ,OAAM,KAAe,GAC5C,EAGF9C,EAAIgC,KAAK,QAASL,GAElB,IACE,OAAa,CACX,MAAMoB,QAAcH,EAAOI,OAE3B,GAAID,EAAME,KACR,MAGF,GAAIjD,EAAImC,WAAanC,EAAIoC,cAGvB,kBAFMQ,EAAON,SAKVtC,EAAIkD,MAAMH,EAAMvC,cACba,EAAarB,GAMpBA,EAAiDmD,SACpD,CAEKnD,EAAImC,WAAcnC,EAAIoC,eACzBpC,EAAI2C,KAER,CAAE,MAAOZ,SACDa,EAAON,OAAOP,GAAOe,OAAM,KAAe,IAE3C9C,EAAImC,WACPnC,EAAIoD,QAAQrB,EAEhB,SACE/B,EAAI0B,IAAI,QAASC,GACjBiB,EAAOS,aACT"}
1
+ {"version":3,"file":"write-fetch-response.js","sources":["../../src/node/write-fetch-response.ts"],"sourcesContent":[null],"names":["SET_COOKIE","writeFetchHeaders","res","response","statusCode","status","getHeaderEntries","headers","forEach","name","value","setHeader","cookies","getSetCookieHeaders","appendHeader","cookie","length","existing","getHeader","previousCookies","Array","isArray","String","waitForDrain","Promise","resolve","reject","cleanup","off","onClose","onDrain","onError","Error","error","once","writeFetchResponse","async","destroyed","writableEnded","body","cancel","headersSent","req","method","includes","end","reader","getReader","catch","chunk","read","done","write","flush","destroy","releaseLock"],"mappings":"+EAGA,MAAMA,EAAa,aAKbC,EAAoB,CAACC,EAAsBC,KAC/CD,EAAIE,WAAaD,EAASE,OAC1BC,EAAiBH,EAASI,SAASC,QAAQ,EAAEC,EAAMC,KAAWR,EAAIS,UAAUF,EAAMC,IAClF,MAAME,EAAUC,EAAoBV,EAASI,SAE7C,GAAgC,mBAArBL,EAAIY,aACbF,EAAQJ,QAASO,GAAWb,EAAIY,aAAad,EAAYe,SACpD,GAAIH,EAAQI,OAAQ,CAIzB,MAAMC,EAAWf,EAAIgB,UAAUlB,GACzBmB,EAAkBC,MAAMC,QAAQJ,GAAYA,EAAW,CAACK,OAAOL,IAErEf,EAAIS,UAAUX,EAAYiB,EAAW,IAAIE,KAAoBP,GAAWA,EAC1E,GAMIW,EAAgBrB,GACpB,IAAIsB,QAAQ,CAACC,EAASC,KAIpB,MAAMC,EAAU,KACdzB,EAAI0B,IAAI,QAASC,GACjB3B,EAAI0B,IAAI,QAASE,GACjB5B,EAAI0B,IAAI,QAASG,IAMbF,EAAU,KACdF,IACAD,EAAO,IAAIM,MAAM,mCAMbF,EAAU,KACdH,IACAF,KAMIM,EAAWE,IACfN,IACAD,EAAOO,IAGT/B,EAAIgC,KAAK,QAASL,GAClB3B,EAAIgC,KAAK,QAASJ,GAClB5B,EAAIgC,KAAK,QAASH,KAMhBI,EAAqBC,MAAOlC,EAAsBC,KACtD,GAAID,EAAImC,WAAanC,EAAIoC,cAGvB,kBAFMnC,EAASoC,MAAMC,UASvB,GAJKtC,EAAIuC,aACPxC,EAAkBC,EAAKC,IAGpBA,EAASoC,MAA4B,SAApBrC,EAAIwC,KAAKC,QAAqB,CAAC,IAAK,IAAK,KAAKC,SAAS1C,EAAIE,YAI/E,aAHMD,EAASoC,MAAMC,eACrBtC,EAAI2C,MAKN,MAAMC,EAAS3C,EAASoC,KAAKQ,YAKvBlB,EAAU,KACT3B,EAAIoC,eACFQ,EAAON,SAASQ,MAAM,SAI/B9C,EAAIgC,KAAK,QAASL,GAElB,IACE,OAAa,CACX,MAAMoB,QAAcH,EAAOI,OAE3B,GAAID,EAAME,KACR,MAGF,GAAIjD,EAAImC,WAAanC,EAAIoC,cAGvB,kBAFMQ,EAAON,SAKVtC,EAAIkD,MAAMH,EAAMvC,cACba,EAAarB,GAMpBA,EAAiDmD,SACpD,CAEKnD,EAAImC,WAAcnC,EAAIoC,eACzBpC,EAAI2C,KAER,CAAE,MAAOZ,SACDa,EAAON,OAAOP,GAAOe,MAAM,QAE5B9C,EAAImC,WACPnC,EAAIoD,QAAQrB,EAEhB,SACE/B,EAAI0B,IAAI,QAASC,GACjBiB,EAAOS,aACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lomray/vite-ssr-boost",
3
- "version": "8.0.0-beta.1",
3
+ "version": "8.0.0-beta.2",
4
4
  "description": "Vite plugin for create awesome SSR or SPA applications on React.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -57,8 +57,8 @@
57
57
  "test:coverage": "vitest run --coverage"
58
58
  },
59
59
  "dependencies": {
60
- "chalk": "^5.6.2",
61
- "commander": "^14.0.3",
60
+ "chalk": "^6.0.0",
61
+ "commander": "^15.0.0",
62
62
  "hoist-non-react-statics": "^3.3.2",
63
63
  "json5": "^2.2.3"
64
64
  },
@@ -67,51 +67,66 @@
67
67
  "express": "^5.2.1"
68
68
  },
69
69
  "devDependencies": {
70
- "@commitlint/cli": "^20.5.0",
71
- "@commitlint/config-conventional": "^20.5.0",
72
- "@lomray/eslint-config-react": "^6.0.3",
73
- "@lomray/prettier-config": "^2.1.0",
70
+ "@babel/generator": "^8.0.0",
71
+ "@babel/parser": "^8.0.4",
72
+ "@babel/traverse": "^8.0.4",
73
+ "@babel/types": "^8.0.4",
74
+ "@commitlint/cli": "^21.2.2",
75
+ "@commitlint/config-conventional": "^21.2.2",
76
+ "@lomray/eslint-config": "^7.0.0",
77
+ "@lomray/eslint-config-react": "^7.0.0",
78
+ "@lomray/prettier-config": "^3.0.0",
74
79
  "@rollup/plugin-terser": "^1.0.0",
75
- "@testing-library/react": "^16.3.2",
80
+ "@rollup/plugin-typescript": "^12.3.0",
81
+ "@testing-library/react": "^16.3.3",
76
82
  "@types/babel__generator": "^7.27.0",
77
83
  "@types/babel__traverse": "^7.28.0",
78
84
  "@types/compression": "^1.8.1",
85
+ "@types/express": "^5.0.6",
79
86
  "@types/hoist-non-react-statics": "^3.3.7",
80
- "@types/react-dom": "^19.2.3",
81
- "@types/sinon": "^21.0.0",
82
- "@vitest/coverage-v8": "^4.1.0",
83
- "@zerollup/ts-transform-paths": "^1.7.18",
84
- "conventional-changelog-conventionalcommits": "^9.3.0",
85
- "esbuild": "^0.25.12",
86
- "eslint": "^9.39.4",
87
- "fastify": "^5.10.0",
88
- "hono": "^4.12.31",
87
+ "@types/node": "^22.20.1",
88
+ "@types/react": "^19.2.18",
89
+ "@types/react-dom": "^19.2.7",
90
+ "@types/serve-static": "^2.2.0",
91
+ "@types/sinon": "^22.0.0",
92
+ "@vitest/coverage-v8": "^5.0.0",
93
+ "conventional-changelog-conventionalcommits": "^9.3.1",
94
+ "esbuild": "^0.28.2",
95
+ "eslint": "^10.10.0",
96
+ "fastify": "^5.12.3",
97
+ "globals": "^17.12.0",
98
+ "hono": "^4.13.7",
89
99
  "husky": "^9.1.7",
90
- "jsdom": "^29.0.1",
91
- "lint-staged": "^16.4.0",
92
- "miniflare": "^4.20260721.0",
93
- "prettier": "^3.8.1",
94
- "react-router": "^7.18.3",
95
- "rollup": "^4.59.1",
100
+ "jsdom": "^30.0.1",
101
+ "lint-staged": "^17.4.1",
102
+ "miniflare": "^4.20260730.0",
103
+ "prettier": "^3.9.6",
104
+ "react": "^19.2.8",
105
+ "react-dom": "^19.2.8",
106
+ "react-router": "^8.3.1",
107
+ "rollup": "^4.63.1",
96
108
  "rollup-plugin-copy": "^3.5.0",
97
109
  "rollup-plugin-folder-input": "^1.0.1",
98
110
  "rollup-plugin-peer-deps-external": "^2.2.4",
99
111
  "rollup-plugin-preserve-shebangs": "^0.2.0",
100
- "rollup-plugin-ts": "^3.4.5",
101
- "semantic-release": "^25.0.3",
102
- "sinon": "^21.0.3",
103
- "typescript": "^5.3.3",
104
- "vite": "^6.4.3",
112
+ "semantic-release": "^25.0.9",
113
+ "sinon": "^22.1.0",
114
+ "tsc-alias": "^1.9.4",
115
+ "typescript": "^6.0.3",
116
+ "typescript-eslint": "^8.69.0",
117
+ "vite": "^8.2.2",
105
118
  "vitepress": "^1.6.4",
106
- "vitest": "^4.1.0"
119
+ "vitest": "^5.0.0"
107
120
  },
108
121
  "peerDependencies": {
109
122
  "@babel/generator": ">=7.23.0",
110
123
  "@babel/parser": ">=7.23.0",
111
124
  "@babel/traverse": ">=7.23.0",
125
+ "@babel/types": ">=7.23.0",
112
126
  "@types/compression": ">=1.7.5",
113
127
  "@types/express": ">=4.17.21",
114
128
  "@types/serve-static": ">=1.15.5",
129
+ "react": ">=18.2.0",
115
130
  "react-dom": ">=18.2.0",
116
131
  "react-router": ">=7.0.1",
117
132
  "vite": ">=5"
@@ -128,14 +143,19 @@
128
143
  }
129
144
  },
130
145
  "overrides": {
131
- "rollup-plugin-ts": {
132
- "browserslist-generator": "^3.0.0"
146
+ "miniflare": {
147
+ "undici": "^7.29.0"
148
+ },
149
+ "vitepress": {
150
+ "vite": "^6.4.3",
151
+ "@docsearch/js": "^3.9.0",
152
+ "@docsearch/css": "^3.9.0"
133
153
  }
134
154
  },
135
155
  "bin": {
136
156
  "ssr-boost": "cli.js"
137
157
  },
138
158
  "engines": {
139
- "node": ">=22.0.0"
159
+ "node": ">=22.12.0"
140
160
  }
141
161
  }
package/plugin.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { Plugin } from 'vite';
2
- import { ICliContext } from "./constants/cli-context.js";
3
- import { IPluginOptions as ICreateSPAIndex } from "./plugins/create-spa-index.js";
4
- import { IPluginOptions as IMakeAliasesPluginOptions } from "./plugins/make-aliases.js";
5
- import { IBuildEntrypoint } from "./services/build.js";
6
- interface IPluginOptions {
1
+ import type { Plugin } from 'vite';
2
+ import type { ICliContext } from './constants/cli-context.js';
3
+ import type { IPluginOptions as ICreateSPAIndex } from './plugins/create-spa-index.js';
4
+ import type { IPluginOptions as IMakeAliasesPluginOptions } from './plugins/make-aliases.js';
5
+ import type { IBuildEntrypoint } from './services/build.js';
6
+ export interface IPluginOptions {
7
7
  indexFile?: string;
8
8
  serverFile?: string;
9
9
  clientFile?: string;
@@ -23,4 +23,4 @@ interface IPluginOptions {
23
23
  * @constructor
24
24
  */
25
25
  declare function ViteSsrBoostPlugin(options?: IPluginOptions): Plugin[];
26
- export { ViteSsrBoostPlugin as default, IPluginOptions };
26
+ export default ViteSsrBoostPlugin;
package/plugin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path';\nimport process from 'node:process';\nimport type { Plugin } from 'vite';\nimport CliActions from '@constants/cli-actions';\nimport type { ICliContext } from '@constants/cli-context';\nimport PLUGIN_NAME from '@constants/plugin-name';\nimport ViteCreateSPAIndexPlugin from '@plugins/create-spa-index';\nimport type { IPluginOptions as ICreateSPAIndex } from '@plugins/create-spa-index';\nimport {\n ViteHandleCustomEntrypointPlugin,\n getCurrentEntrypoint,\n} from '@plugins/handle-custom-entrypoint';\nimport type { IPluginOptions as IMakeAliasesPluginOptions } from '@plugins/make-aliases';\nimport ViteMakeAliasesPlugin from '@plugins/make-aliases';\nimport ViteNormalizeRouterPlugin from '@plugins/normalize-route';\nimport type { IBuildEntrypoint } from '@services/build';\n\nexport interface IPluginOptions {\n // default: index.html\n indexFile?: string;\n // default: server.ts\n serverFile?: string;\n // default: client.ts\n clientFile?: string;\n // Path contains routes declaration files (need to detect route files). default: undefined, e.g.: /routes/\n routesPath?: string;\n // Create additional SPA entrypoint: index-spa.html\n // Can be used for service worker: createHandlerBoundToURL(\"index-spa.html\")\n spaIndex?: boolean | ICreateSPAIndex;\n // Read aliases from tsconfig\n tsconfigAliases?: boolean | IMakeAliasesPluginOptions;\n customShortcuts?: {\n key: string;\n description: string;\n action: (cliContext: ICliContext) => Promise<void> | void;\n isOnlyDev?: boolean;\n }[];\n // Additional entry points for build\n entrypoint?: IBuildEntrypoint[];\n}\n\nconst defaultOptions: IPluginOptions = {\n indexFile: 'index.html',\n serverFile: 'server.ts',\n clientFile: 'client.ts',\n tsconfigAliases: true,\n spaIndex: false,\n};\n\n/**\n * Init plugin\n * @constructor\n */\nfunction ViteSsrBoostPlugin(options: IPluginOptions = {}): Plugin[] {\n const dirInfo = new URL(import.meta.url);\n const action = (global.viteBoostAction || process.env.SSR_BOOST_ACTION) as CliActions;\n const mergedOptions: IPluginOptions = { ...defaultOptions, ...options };\n const entrypointConfig = getCurrentEntrypoint(mergedOptions.entrypoint ?? []);\n const isSSR = process.env.SSR_BOOST_IS_SSR === '1' || action === CliActions.dev;\n const isBuild = action === CliActions.build;\n\n const plugins: Plugin[] = [\n {\n name: PLUGIN_NAME,\n enforce: 'pre',\n // @ts-ignore save custom options\n pluginOptions: {\n ...mergedOptions,\n pluginPath: path.dirname(dirInfo.pathname),\n action,\n isDev: action === CliActions.dev,\n },\n\n config(config, { isSsrBuild }) {\n config.define = {\n ...(config.define ?? {}),\n __IS_SSR__: entrypointConfig ? entrypointConfig.type === 'ssr' : isSSR,\n };\n\n config.build = {\n ...(config.build ?? {}),\n };\n\n if (!isSsrBuild) {\n if (isSSR && isBuild) {\n config.build.manifest = true;\n }\n\n return config;\n }\n\n return {\n ...config,\n ...(isBuild ? { appType: 'custom' } : {}),\n publicDir: false,\n };\n },\n },\n ];\n\n const { tsconfigAliases, routesPath, spaIndex } = mergedOptions;\n\n if (tsconfigAliases) {\n plugins.push(\n ViteMakeAliasesPlugin(typeof tsconfigAliases === 'boolean' ? undefined : tsconfigAliases),\n );\n }\n\n if (spaIndex) {\n plugins.push(ViteCreateSPAIndexPlugin(typeof spaIndex === 'boolean' ? undefined : spaIndex));\n }\n\n if (entrypointConfig) {\n plugins.push(ViteHandleCustomEntrypointPlugin({ entrypoint: entrypointConfig }));\n }\n\n plugins.push(ViteNormalizeRouterPlugin({ isSSR, isBuild, routesPath }));\n\n return plugins;\n}\n\nexport default ViteSsrBoostPlugin;\n"],"names":["defaultOptions","indexFile","serverFile","clientFile","tsconfigAliases","spaIndex","ViteSsrBoostPlugin","options","dirInfo","URL","url","action","global","viteBoostAction","process","env","SSR_BOOST_ACTION","mergedOptions","entrypointConfig","getCurrentEntrypoint","entrypoint","isSSR","SSR_BOOST_IS_SSR","CliActions","dev","isBuild","build","plugins","name","PLUGIN_NAME","enforce","pluginOptions","pluginPath","path","dirname","pathname","isDev","config","isSsrBuild","define","__IS_SSR__","type","appType","publicDir","manifest","routesPath","push","ViteMakeAliasesPlugin","undefined","ViteCreateSPAIndexPlugin","ViteHandleCustomEntrypointPlugin","ViteNormalizeRouterPlugin"],"mappings":"8XAyCA,MAAMA,EAAiC,CACrCC,UAAW,aACXC,WAAY,YACZC,WAAY,YACZC,iBAAiB,EACjBC,UAAU,GAOZ,SAASC,EAAmBC,EAA0B,IACpD,MAAMC,EAAU,IAAIC,gBAAgBC,KAC9BC,EAAUC,OAAOC,iBAAmBC,EAAQC,IAAIC,iBAChDC,EAAgC,IAAKjB,KAAmBO,GACxDW,EAAmBC,EAAqBF,EAAcG,YAAc,IACpEC,EAAyC,MAAjCP,EAAQC,IAAIO,kBAA4BX,IAAWY,EAAWC,IACtEC,EAAUd,IAAWY,EAAWG,MAEhCC,EAAoB,CACxB,CACEC,KAAMC,EACNC,QAAS,MAETC,cAAe,IACVd,EACHe,WAAYC,EAAKC,QAAQ1B,EAAQ2B,UACjCxB,SACAyB,MAAOzB,IAAWY,EAAWC,KAG/Ba,OAAM,CAACA,GAAQC,WAAEA,MACfD,EAAOE,OAAS,IACVF,EAAOE,QAAU,GACrBC,WAAYtB,EAA6C,QAA1BA,EAAiBuB,KAAiBpB,GAGnEgB,EAAOX,MAAQ,IACTW,EAAOX,OAAS,IAGjBY,EAQE,IACFD,KACCZ,EAAU,CAAEiB,QAAS,UAAa,CAAA,EACtCC,WAAW,IAVPtB,GAASI,IACXY,EAAOX,MAAMkB,UAAW,GAGnBP,OAYTjC,gBAAEA,EAAeyC,WAAEA,EAAUxC,SAAEA,GAAaY,EAkBlD,OAhBIb,GACFuB,EAAQmB,KACNC,EAAiD,kBAApB3C,OAAgC4C,EAAY5C,IAIzEC,GACFsB,EAAQmB,KAAKG,EAA6C,kBAAb5C,OAAyB2C,EAAY3C,IAGhFa,GACFS,EAAQmB,KAAKI,EAAiC,CAAE9B,WAAYF,KAG9DS,EAAQmB,KAAKK,EAA0B,CAAE9B,QAAOI,UAASoB,gBAElDlB,CACT"}
1
+ {"version":3,"file":"plugin.js","sources":["../src/plugin.ts"],"sourcesContent":[null],"names":["defaultOptions","indexFile","serverFile","clientFile","tsconfigAliases","spaIndex","ViteSsrBoostPlugin","options","dirInfo","URL","url","action","global","viteBoostAction","process","env","SSR_BOOST_ACTION","mergedOptions","entrypointConfig","getCurrentEntrypoint","entrypoint","isSSR","SSR_BOOST_IS_SSR","CliActions","dev","isBuild","build","plugins","name","PLUGIN_NAME","enforce","pluginOptions","pluginPath","path","dirname","pathname","isDev","config","isSsrBuild","define","__IS_SSR__","type","appType","publicDir","manifest","routesPath","push","ViteMakeAliasesPlugin","undefined","ViteCreateSPAIndexPlugin","ViteHandleCustomEntrypointPlugin","ViteNormalizeRouterPlugin"],"mappings":"8XAyCA,MAAMA,EAAiC,CACrCC,UAAW,aACXC,WAAY,YACZC,WAAY,YACZC,iBAAiB,EACjBC,UAAU,GAOZ,SAASC,EAAmBC,EAA0B,IACpD,MAAMC,EAAU,IAAIC,gBAAgBC,KAC9BC,EAAUC,OAAOC,iBAAmBC,EAAQC,IAAIC,iBAChDC,EAAgC,IAAKjB,KAAmBO,GACxDW,EAAmBC,EAAqBF,EAAcG,YAAc,IACpEC,EAAyC,MAAjCP,EAAQC,IAAIO,kBAA4BX,IAAWY,EAAWC,IACtEC,EAAUd,IAAWY,EAAWG,MAEhCC,EAAoB,CACxB,CACEC,KAAMC,EACNC,QAAS,MAETC,cAAe,IACVd,EACHe,WAAYC,EAAKC,QAAQ1B,EAAQ2B,UACjCxB,SACAyB,MAAOzB,IAAWY,EAAWC,KAG/Ba,OAAM,CAACA,GAAQC,WAAEA,MACfD,EAAOE,OAAS,IACVF,EAAOE,QAAU,GACrBC,WAAYtB,EAA6C,QAA1BA,EAAiBuB,KAAiBpB,GAGnEgB,EAAOX,MAAQ,IACTW,EAAOX,OAAS,IAGjBY,EAQE,IACFD,KACCZ,EAAU,CAAEiB,QAAS,UAAa,CAAA,EACtCC,WAAW,IAVPtB,GAASI,IACXY,EAAOX,MAAMkB,UAAW,GAGnBP,OAYTjC,gBAAEA,EAAeyC,WAAEA,EAAUxC,SAAEA,GAAaY,EAkBlD,OAhBIb,GACFuB,EAAQmB,KACNC,EAAiD,kBAApB3C,OAAgC4C,EAAY5C,IAIzEC,GACFsB,EAAQmB,KAAKG,EAA6C,kBAAb5C,OAAyB2C,EAAY3C,IAGhFa,GACFS,EAAQmB,KAAKI,EAAiC,CAAE9B,WAAYF,KAG9DS,EAAQmB,KAAKK,EAA0B,CAAE9B,QAAOI,UAASoB,gBAElDlB,CACT"}
@@ -1,5 +1,5 @@
1
- import { Plugin } from 'vite';
2
- interface IPluginOptions {
1
+ import type { Plugin } from 'vite';
2
+ export interface IPluginOptions {
3
3
  filename?: string;
4
4
  rootId?: string;
5
5
  }
@@ -11,4 +11,4 @@ interface IPluginOptions {
11
11
  * @constructor
12
12
  */
13
13
  declare function ViteCreateSPAIndexPlugin(options?: IPluginOptions): Plugin;
14
- export { ViteCreateSPAIndexPlugin as default, IPluginOptions };
14
+ export default ViteCreateSPAIndexPlugin;
@@ -1 +1 @@
1
- {"version":3,"file":"create-spa-index.js","sources":["../../src/plugins/create-spa-index.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport PLUGIN_NAME from '@constants/plugin-name';\nimport { getCurrentEntrypointName } from '@plugins/handle-custom-entrypoint';\n\nexport interface IPluginOptions {\n filename?: string;\n rootId?: string;\n}\n\nconst pluginName = `${PLUGIN_NAME}-create-spa-entrypoint`;\n\n/**\n * Create additional entrypoint for SPA.\n * File: index-spa.html\n *\n * E.g. for service worker entrypoint\n * @constructor\n */\nfunction ViteCreateSPAIndexPlugin(options: IPluginOptions = {}): Plugin {\n const { filename = 'index-spa.html', rootId = 'root' } = options;\n let spaHtml = '';\n\n return {\n name: pluginName,\n enforce: 'post',\n /**\n * Apply only on build but not for SSR\n */\n apply(_, { command, isSsrBuild }): boolean {\n return command === 'build' && !isSsrBuild && !getCurrentEntrypointName();\n },\n transformIndexHtml(html): string {\n spaHtml = html.replace(`id=\"${rootId}\"`, `id=\"${rootId}\" data-force-spa=\"1\"`);\n\n return html;\n },\n generateBundle(): void {\n if (!spaHtml) {\n return;\n }\n\n this.emitFile({\n type: 'asset',\n fileName: filename,\n source: spaHtml,\n });\n },\n };\n}\n\nexport default ViteCreateSPAIndexPlugin;\n"],"names":["pluginName","PLUGIN_NAME","ViteCreateSPAIndexPlugin","options","filename","rootId","spaHtml","name","enforce","apply","_","command","isSsrBuild","getCurrentEntrypointName","transformIndexHtml","html","replace","generateBundle","this","emitFile","type","fileName","source"],"mappings":"oHASA,MAAMA,EAAa,GAAGC,0BAStB,SAASC,EAAyBC,EAA0B,IAC1D,MAAMC,SAAEA,EAAW,iBAAgBC,OAAEA,EAAS,QAAWF,EACzD,IAAIG,EAAU,GAEd,MAAO,CACLC,KAAMP,EACNQ,QAAS,OAITC,MAAK,CAACC,GAAGC,QAAEA,EAAOC,WAAEA,KACC,UAAZD,IAAwBC,IAAeC,IAEhDC,mBAAmBC,IACjBT,EAAUS,EAAKC,QAAQ,OAAOX,KAAW,OAAOA,yBAEzCU,GAETE,iBACOX,GAILY,KAAKC,SAAS,CACZC,KAAM,QACNC,SAAUjB,EACVkB,OAAQhB,GAEZ,EAEJ"}
1
+ {"version":3,"file":"create-spa-index.js","sources":["../../src/plugins/create-spa-index.ts"],"sourcesContent":[null],"names":["pluginName","PLUGIN_NAME","ViteCreateSPAIndexPlugin","options","filename","rootId","spaHtml","name","enforce","apply","_","command","isSsrBuild","getCurrentEntrypointName","transformIndexHtml","html","replace","generateBundle","this","emitFile","type","fileName","source"],"mappings":"oHASA,MAAMA,EAAa,GAAGC,0BAStB,SAASC,EAAyBC,EAA0B,IAC1D,MAAMC,SAAEA,EAAW,iBAAgBC,OAAEA,EAAS,QAAWF,EACzD,IAAIG,EAAU,GAEd,MAAO,CACLC,KAAMP,EACNQ,QAAS,OAITC,MAAK,CAACC,GAAGC,QAAEA,EAAOC,WAAEA,KACC,UAAZD,IAAwBC,IAAeC,IAEhDC,mBAAmBC,IACjBT,EAAUS,EAAKC,QAAQ,OAAOX,KAAW,OAAOA,yBAEzCU,GAET,cAAAE,GACOX,GAILY,KAAKC,SAAS,CACZC,KAAM,QACNC,SAAUjB,EACVkB,OAAQhB,GAEZ,EAEJ"}
@@ -1,6 +1,6 @@
1
- import { Plugin } from 'vite';
2
- import { IBuildEntrypoint } from "../services/build.js";
3
- interface IPluginOptions {
1
+ import type { Plugin } from 'vite';
2
+ import type { IBuildEntrypoint } from '../services/build.js';
3
+ export interface IPluginOptions {
4
4
  entrypoint: IBuildEntrypoint;
5
5
  }
6
6
  /**
@@ -22,4 +22,4 @@ declare const getCurrentEntrypoint: (entrypoint: IBuildEntrypoint[], currentEntr
22
22
  * @constructor
23
23
  */
24
24
  declare function ViteHandleCustomEntrypointPlugin(options: IPluginOptions): Plugin;
25
- export { IPluginOptions, ViteHandleCustomEntrypointPlugin, getCurrentEntrypoint, getCurrentEntrypointName, setCurrentEntrypointName };
25
+ export { ViteHandleCustomEntrypointPlugin, getCurrentEntrypoint, getCurrentEntrypointName, setCurrentEntrypointName, };
@@ -1,2 +1,2 @@
1
- import e from"node:fs";import n from"node:path";import o from"node:process";import r from"../constants/plugin-name.js";const t=`${r}-handle-custom-entrypoint`,i=()=>o.env.SSR_BOOST_CUSTOM_ENTRYPOINT_BUILD_NAME,l=e=>{o.env.SSR_BOOST_CUSTOM_ENTRYPOINT_BUILD_NAME=e},s=(e,n=i())=>{if(!e.length||!n)return null;for(const o of e)if(o.name===n&&!o.serverFile)return o;return null},c=(e,n,o)=>{const r=n.replace("./","/"),t=o.replace("./","/");return e.replace(r,t)};function m(o){const{entrypoint:i}=o;let l="",s="";return{name:t,enforce:"pre",apply:(e,{isSsrBuild:n})=>!n&&Boolean(i),config(e){const{indexFile:o}=i,r=e.build??{},t=o?n.resolve(e.root??"",o):void 0;return{...e,build:{...r,rollupOptions:{...r.rollupOptions??{},input:t}}}},configResolved(e){const o=e.plugins.find((e=>e.name===r));l=n.resolve(e.root,e.build.outDir),s=o.pluginOptions.clientFile},transform(e,n){if(n.endsWith(".html")){const{clientFile:n}=i;if(n)return{code:c(e,s,n),map:this.getCombinedSourcemap()}}return{code:e,map:this.getCombinedSourcemap()}},transformIndexHtml(e,{originalUrl:n,server:o}){const{clientFile:r}=i;return r&&"serve"===o?.config.command&&n?.endsWith(".html")?c(e,s,r):e},closeBundle(){const{indexFile:o}=i;if(!o)return;const r=n.resolve(l,n.basename(o));e.existsSync(r)&&e.renameSync(r,n.resolve(l,"index.html"))}}}export{m as ViteHandleCustomEntrypointPlugin,s as getCurrentEntrypoint,i as getCurrentEntrypointName,l as setCurrentEntrypointName};
1
+ import e from"node:fs";import n from"node:path";import r from"node:process";import o from"../constants/plugin-name.js";const t=`${o}-handle-custom-entrypoint`,i=()=>r.env.SSR_BOOST_CUSTOM_ENTRYPOINT_BUILD_NAME,l=e=>{r.env.SSR_BOOST_CUSTOM_ENTRYPOINT_BUILD_NAME=e},s=(e,n=i())=>{if(!e.length||!n)return null;for(const r of e)if(r.name===n&&!r.serverFile)return r;return null},c=(e,n,r)=>{const o=n.replace("./","/"),t=r.replace("./","/");return e.replace(o,t)};function m(r){const{entrypoint:i}=r;let l="",s="";return{name:t,enforce:"pre",apply:(e,{isSsrBuild:n})=>!n&&Boolean(i),config(e){const{indexFile:r}=i,o=e.build??{},t=r?n.resolve(e.root??"",r):void 0;return{...e,build:{...o,rollupOptions:{...o.rollupOptions??{},input:t}}}},configResolved(e){const r=e.plugins.find(e=>e.name===o);l=n.resolve(e.root,e.build.outDir),s=r.pluginOptions.clientFile},transform(e,n){if(n.endsWith(".html")){const{clientFile:n}=i;if(n)return{code:c(e,s,n),map:JSON.stringify(this.getCombinedSourcemap())}}return{code:e,map:JSON.stringify(this.getCombinedSourcemap())}},transformIndexHtml(e,{originalUrl:n,server:r}){const{clientFile:o}=i;return o&&"serve"===r?.config.command&&n?.endsWith(".html")?c(e,s,o):e},closeBundle(){const{indexFile:r}=i;if(!r)return;const o=n.resolve(l,n.basename(r));e.existsSync(o)&&e.renameSync(o,n.resolve(l,"index.html"))}}}export{m as ViteHandleCustomEntrypointPlugin,s as getCurrentEntrypoint,i as getCurrentEntrypointName,l as setCurrentEntrypointName};
2
2
  //# sourceMappingURL=handle-custom-entrypoint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"handle-custom-entrypoint.js","sources":["../../src/plugins/handle-custom-entrypoint.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport process from 'node:process';\nimport type { Plugin } from 'vite';\nimport PLUGIN_NAME from '@constants/plugin-name';\nimport type { IBuildEntrypoint } from '@services/build';\n\nexport interface IPluginOptions {\n entrypoint: IBuildEntrypoint;\n}\n\nconst pluginName = `${PLUGIN_NAME}-handle-custom-entrypoint`;\n\n/**\n * Get current entrypoint name\n */\nconst getCurrentEntrypointName = (): string | undefined =>\n process.env.SSR_BOOST_CUSTOM_ENTRYPOINT_BUILD_NAME;\n\n/**\n * Set current entrypoint name\n */\nconst setCurrentEntrypointName = (name: string): void => {\n process.env.SSR_BOOST_CUSTOM_ENTRYPOINT_BUILD_NAME = name;\n};\n\n/**\n * Find current entrypoint by env\n */\nconst getCurrentEntrypoint = (\n entrypoint: IBuildEntrypoint[],\n currentEntrypointName = getCurrentEntrypointName(),\n): IBuildEntrypoint | null => {\n if (!entrypoint.length || !currentEntrypointName) {\n return null;\n }\n\n for (const entry of entrypoint) {\n if (entry.name === currentEntrypointName && !entry.serverFile) {\n return entry;\n }\n }\n\n return null;\n};\n\n/**\n * Replace entrypoint in html file\n */\nconst replaceEntrypoint = (code: string, originalPath: string, endpointPath: string): string => {\n const cleanOrigPath = originalPath.replace('./', '/');\n const cleanEndpointPath = endpointPath.replace('./', '/');\n\n return code.replace(cleanOrigPath, cleanEndpointPath);\n};\n\n/**\n * Return custom entrypoint instead default (index.html).\n *\n * E.g. for build multiple entrypoint\n * @constructor\n */\nfunction ViteHandleCustomEntrypointPlugin(options: IPluginOptions): Plugin {\n const { entrypoint } = options;\n let outPath = '';\n let origClientFile = '';\n\n return {\n name: pluginName,\n enforce: 'pre',\n /**\n * Apply only on build but not for SSR and only for custom entrypoint\n */\n apply(_, { isSsrBuild }): boolean {\n return !isSsrBuild && Boolean(entrypoint);\n },\n config(config) {\n const { indexFile } = entrypoint;\n const buildConfig = config.build ?? {};\n const indexFilePath = indexFile ? path.resolve(config.root ?? '', indexFile) : undefined;\n\n return {\n ...config,\n build: {\n ...buildConfig,\n rollupOptions: {\n ...(buildConfig.rollupOptions ?? {}),\n input: indexFilePath,\n },\n },\n };\n },\n configResolved(config) {\n const pluginConfig = config.plugins.find((plugin) => plugin.name === PLUGIN_NAME);\n\n outPath = path.resolve(config.root, config.build.outDir);\n // @ts-expect-error pluginOptions is custom param\n origClientFile = (pluginConfig.pluginOptions as Record<string, any>).clientFile as string;\n },\n transform(code, id) {\n if (id.endsWith('.html')) {\n const { clientFile } = entrypoint;\n\n if (clientFile) {\n return {\n code: replaceEntrypoint(code, origClientFile, clientFile),\n map: this.getCombinedSourcemap(),\n };\n }\n }\n\n return {\n code,\n map: this.getCombinedSourcemap(),\n };\n },\n /**\n * Development mode\n */\n transformIndexHtml(html, { originalUrl, server }): string {\n const { clientFile } = entrypoint;\n\n if (clientFile && server?.config.command === 'serve' && originalUrl?.endsWith('.html')) {\n return replaceEntrypoint(html, origClientFile, clientFile);\n }\n\n return html;\n },\n closeBundle() {\n const { indexFile } = entrypoint;\n\n if (!indexFile) {\n return;\n }\n\n const indexFilePath = path.resolve(outPath, path.basename(indexFile));\n\n if (fs.existsSync(indexFilePath)) {\n fs.renameSync(indexFilePath, path.resolve(outPath, 'index.html'));\n }\n },\n };\n}\n\nexport {\n ViteHandleCustomEntrypointPlugin,\n getCurrentEntrypoint,\n getCurrentEntrypointName,\n setCurrentEntrypointName,\n};\n"],"names":["pluginName","PLUGIN_NAME","getCurrentEntrypointName","process","env","SSR_BOOST_CUSTOM_ENTRYPOINT_BUILD_NAME","setCurrentEntrypointName","name","getCurrentEntrypoint","entrypoint","currentEntrypointName","length","entry","serverFile","replaceEntrypoint","code","originalPath","endpointPath","cleanOrigPath","replace","cleanEndpointPath","ViteHandleCustomEntrypointPlugin","options","outPath","origClientFile","enforce","apply","_","isSsrBuild","Boolean","config","indexFile","buildConfig","build","indexFilePath","path","resolve","root","undefined","rollupOptions","input","configResolved","pluginConfig","plugins","find","plugin","outDir","pluginOptions","clientFile","transform","id","endsWith","map","this","getCombinedSourcemap","transformIndexHtml","html","originalUrl","server","command","closeBundle","basename","fs","existsSync","renameSync"],"mappings":"uHAWA,MAAMA,EAAa,GAAGC,6BAKhBC,EAA2B,IAC/BC,EAAQC,IAAIC,uCAKRC,EAA4BC,IAChCJ,EAAQC,IAAIC,uCAAyCE,CAAI,EAMrDC,EAAuB,CAC3BC,EACAC,EAAwBR,OAExB,IAAKO,EAAWE,SAAWD,EACzB,OAAO,KAGT,IAAK,MAAME,KAASH,EAClB,GAAIG,EAAML,OAASG,IAA0BE,EAAMC,WACjD,OAAOD,EAIX,OAAO,IAAI,EAMPE,EAAoB,CAACC,EAAcC,EAAsBC,KAC7D,MAAMC,EAAgBF,EAAaG,QAAQ,KAAM,KAC3CC,EAAoBH,EAAaE,QAAQ,KAAM,KAErD,OAAOJ,EAAKI,QAAQD,EAAeE,EAAkB,EASvD,SAASC,EAAiCC,GACxC,MAAMb,WAAEA,GAAea,EACvB,IAAIC,EAAU,GACVC,EAAiB,GAErB,MAAO,CACLjB,KAAMP,EACNyB,QAAS,MAITC,MAAK,CAACC,GAAGC,WAAEA,MACDA,GAAcC,QAAQpB,GAEhCqB,OAAOA,GACL,MAAMC,UAAEA,GAActB,EAChBuB,EAAcF,EAAOG,OAAS,CAAA,EAC9BC,EAAgBH,EAAYI,EAAKC,QAAQN,EAAOO,MAAQ,GAAIN,QAAaO,EAE/E,MAAO,IACFR,EACHG,MAAO,IACFD,EACHO,cAAe,IACTP,EAAYO,eAAiB,GACjCC,MAAON,IAIf,EACAO,eAAeX,GACb,MAAMY,EAAeZ,EAAOa,QAAQC,MAAMC,GAAWA,EAAOtC,OAASN,IAErEsB,EAAUY,EAAKC,QAAQN,EAAOO,KAAMP,EAAOG,MAAMa,QAEjDtB,EAAkBkB,EAAaK,cAAsCC,UACvE,EACAC,UAAUlC,EAAMmC,GACd,GAAIA,EAAGC,SAAS,SAAU,CACxB,MAAMH,WAAEA,GAAevC,EAEvB,GAAIuC,EACF,MAAO,CACLjC,KAAMD,EAAkBC,EAAMS,EAAgBwB,GAC9CI,IAAKC,KAAKC,uBAGhB,CAEA,MAAO,CACLvC,OACAqC,IAAKC,KAAKC,uBAEd,EAIAC,mBAAmBC,GAAMC,YAAEA,EAAWC,OAAEA,IACtC,MAAMV,WAAEA,GAAevC,EAEvB,OAAIuC,GAAyC,UAA3BU,GAAQ5B,OAAO6B,SAAuBF,GAAaN,SAAS,SACrErC,EAAkB0C,EAAMhC,EAAgBwB,GAG1CQ,CACT,EACAI,cACE,MAAM7B,UAAEA,GAActB,EAEtB,IAAKsB,EACH,OAGF,MAAMG,EAAgBC,EAAKC,QAAQb,EAASY,EAAK0B,SAAS9B,IAEtD+B,EAAGC,WAAW7B,IAChB4B,EAAGE,WAAW9B,EAAeC,EAAKC,QAAQb,EAAS,cAEvD,EAEJ"}
1
+ {"version":3,"file":"handle-custom-entrypoint.js","sources":["../../src/plugins/handle-custom-entrypoint.ts"],"sourcesContent":[null],"names":["pluginName","PLUGIN_NAME","getCurrentEntrypointName","process","env","SSR_BOOST_CUSTOM_ENTRYPOINT_BUILD_NAME","setCurrentEntrypointName","name","getCurrentEntrypoint","entrypoint","currentEntrypointName","length","entry","serverFile","replaceEntrypoint","code","originalPath","endpointPath","cleanOrigPath","replace","cleanEndpointPath","ViteHandleCustomEntrypointPlugin","options","outPath","origClientFile","enforce","apply","_","isSsrBuild","Boolean","config","indexFile","buildConfig","build","indexFilePath","path","resolve","root","undefined","rollupOptions","input","configResolved","pluginConfig","plugins","find","plugin","outDir","pluginOptions","clientFile","transform","id","endsWith","map","JSON","stringify","this","getCombinedSourcemap","transformIndexHtml","html","originalUrl","server","command","closeBundle","basename","fs","existsSync","renameSync"],"mappings":"uHAWA,MAAMA,EAAa,GAAGC,6BAKhBC,EAA2B,IAC/BC,EAAQC,IAAIC,uCAKRC,EAA4BC,IAChCJ,EAAQC,IAAIC,uCAAyCE,GAMjDC,EAAuB,CAC3BC,EACAC,EAAwBR,OAExB,IAAKO,EAAWE,SAAWD,EACzB,OAAO,KAGT,IAAK,MAAME,KAASH,EAClB,GAAIG,EAAML,OAASG,IAA0BE,EAAMC,WACjD,OAAOD,EAIX,OAAO,MAMHE,EAAoB,CAACC,EAAcC,EAAsBC,KAC7D,MAAMC,EAAgBF,EAAaG,QAAQ,KAAM,KAC3CC,EAAoBH,EAAaE,QAAQ,KAAM,KAErD,OAAOJ,EAAKI,QAAQD,EAAeE,IASrC,SAASC,EAAiCC,GACxC,MAAMb,WAAEA,GAAea,EACvB,IAAIC,EAAU,GACVC,EAAiB,GAErB,MAAO,CACLjB,KAAMP,EACNyB,QAAS,MAITC,MAAK,CAACC,GAAGC,WAAEA,MACDA,GAAcC,QAAQpB,GAEhC,MAAAqB,CAAOA,GACL,MAAMC,UAAEA,GAActB,EAChBuB,EAAcF,EAAOG,OAAS,CAAA,EAC9BC,EAAgBH,EAAYI,EAAKC,QAAQN,EAAOO,MAAQ,GAAIN,QAAaO,EAE/E,MAAO,IACFR,EACHG,MAAO,IACFD,EACHO,cAAe,IACTP,EAAYO,eAAiB,GACjCC,MAAON,IAIf,EACA,cAAAO,CAAeX,GACb,MAAMY,EAAeZ,EAAOa,QAAQC,KAAMC,GAAWA,EAAOtC,OAASN,GAErEsB,EAAUY,EAAKC,QAAQN,EAAOO,KAAMP,EAAOG,MAAMa,QAEjDtB,EAAkBkB,EAAaK,cAAsCC,UACvE,EACA,SAAAC,CAAUlC,EAAMmC,GACd,GAAIA,EAAGC,SAAS,SAAU,CACxB,MAAMH,WAAEA,GAAevC,EAEvB,GAAIuC,EACF,MAAO,CACLjC,KAAMD,EAAkBC,EAAMS,EAAgBwB,GAC9CI,IAAKC,KAAKC,UAAUC,KAAKC,wBAG/B,CAEA,MAAO,CACLzC,OACAqC,IAAKC,KAAKC,UAAUC,KAAKC,wBAE7B,EAIA,kBAAAC,CAAmBC,GAAMC,YAAEA,EAAWC,OAAEA,IACtC,MAAMZ,WAAEA,GAAevC,EAEvB,OAAIuC,GAAyC,UAA3BY,GAAQ9B,OAAO+B,SAAuBF,GAAaR,SAAS,SACrErC,EAAkB4C,EAAMlC,EAAgBwB,GAG1CU,CACT,EACA,WAAAI,GACE,MAAM/B,UAAEA,GAActB,EAEtB,IAAKsB,EACH,OAGF,MAAMG,EAAgBC,EAAKC,QAAQb,EAASY,EAAK4B,SAAShC,IAEtDiC,EAAGC,WAAW/B,IAChB8B,EAAGE,WAAWhC,EAAeC,EAAKC,QAAQb,EAAS,cAEvD,EAEJ"}
@@ -1,5 +1,5 @@
1
- import { Plugin } from 'vite';
2
- interface IPluginOptions {
1
+ import type { Plugin } from 'vite';
2
+ export interface IPluginOptions {
3
3
  root?: string;
4
4
  tsconfig?: string;
5
5
  }
@@ -9,4 +9,4 @@ interface IPluginOptions {
9
9
  * @constructor
10
10
  */
11
11
  declare function ViteMakeAliasesPlugin(options?: IPluginOptions): Plugin;
12
- export { ViteMakeAliasesPlugin as default, IPluginOptions };
12
+ export default ViteMakeAliasesPlugin;
@@ -1,2 +1,2 @@
1
- import e from"node:fs";import o from"node:path";import s from"node:process";import r from"json5";import t from"../constants/plugin-name.js";import n from"../helpers/vite-aliases.js";const i=`${t}-make-aliases`,a=e=>e.replace(/\/?\*$/,"");function c(t={}){const{root:c,tsconfig:p}=t,f=c??s.cwd(),m=o.resolve(f,p??"tsconfig.json"),l=[];if(e.existsSync(m)){const o=r.parse(e.readFileSync(m,{encoding:"utf-8"})),s=o?.compilerOptions?.paths??{};Object.entries(s).forEach((([e,o])=>{l.push([a(e),a(o[0])])}))}else console.error(`${i}: tsconfig not exist in "${m}"`);return{name:i,config(e){if(l.length){const o=e.resolve??{},s=o.alias??[],r=Array.isArray(s)?s:Object.entries(s).map((([e,o])=>({find:e,replacement:o})));r.push(...n(l,`${f}/${e?.root??""}`)),e.resolve={...o,alias:r}}return e}}}export{c as default};
1
+ import e from"node:fs";import o from"node:path";import s from"node:process";import r from"json5";import t from"../constants/plugin-name.js";import n from"../helpers/vite-aliases.js";const i=`${t}-make-aliases`,a=e=>e.replace(/\/?\*$/,"");function c(t={}){const{root:c,tsconfig:p}=t,f=c??s.cwd(),m=o.resolve(f,p??"tsconfig.json"),l=[];if(e.existsSync(m)){const o=r.parse(e.readFileSync(m,{encoding:"utf-8"})),s=o?.compilerOptions?.paths??{};Object.entries(s).forEach(([e,o])=>{l.push([a(e),a(o[0])])})}else console.error(`${i}: tsconfig not exist in "${m}"`);return{name:i,config(e){if(l.length){const o=e.resolve??{},s=o.alias??[],r=Array.isArray(s)?s:Object.entries(s).map(([e,o])=>({find:e,replacement:o}));r.push(...n(l,`${f}/${e?.root??""}`)),e.resolve={...o,alias:r}}return e}}}export{c as default};
2
2
  //# sourceMappingURL=make-aliases.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"make-aliases.js","sources":["../../src/plugins/make-aliases.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport process from 'node:process';\nimport JSON5 from 'json5';\nimport type { Plugin } from 'vite';\n// import without aliases for use in vitest.config.ts\nimport PLUGIN_NAME from '../constants/plugin-name';\nimport ViteAliases from '../helpers/vite-aliases';\n\nexport interface IPluginOptions {\n root?: string; // default: cwd()\n tsconfig?: string; // default: tsconfig.json\n}\n\nconst pluginName = `${PLUGIN_NAME}-make-aliases`;\nconst cleanupAlias = (str: string): string => str.replace(/\\/?\\*$/, '');\n\n/**\n * Read tsconfig file and set vite aliases\n * @see PathNormalize.getAliases\n * @constructor\n */\nfunction ViteMakeAliasesPlugin(options: IPluginOptions = {}): Plugin {\n const { root, tsconfig } = options;\n const projectRoot = root ?? process.cwd();\n const tsconfigPath = path.resolve(projectRoot, tsconfig ?? 'tsconfig.json');\n const aliases: [string, string][] = [];\n\n if (!fs.existsSync(tsconfigPath)) {\n console.error(`${pluginName}: tsconfig not exist in \"${tsconfigPath}\"`);\n } else {\n const tsJson = JSON5.parse<{ compilerOptions?: { paths: Record<string, string[]> } }>(\n fs.readFileSync(tsconfigPath, { encoding: 'utf-8' }),\n );\n const paths = tsJson?.compilerOptions?.paths ?? {};\n\n Object.entries(paths).forEach(([alias, aliasPaths]) => {\n aliases.push([cleanupAlias(alias), cleanupAlias(aliasPaths[0])]);\n });\n }\n\n return {\n name: pluginName,\n config(config) {\n if (aliases.length) {\n const resolveConfig = config.resolve ?? {};\n const defaultAliases = resolveConfig.alias ?? [];\n const normalizedAliases = Array.isArray(defaultAliases)\n ? defaultAliases\n : Object.entries(defaultAliases).map(([find, val]) => ({\n find,\n replacement: val as string,\n }));\n\n normalizedAliases.push(...ViteAliases(aliases, `${projectRoot}/${config?.root ?? ''}`));\n\n config.resolve = {\n ...resolveConfig,\n alias: normalizedAliases,\n };\n }\n\n return config;\n },\n };\n}\n\nexport default ViteMakeAliasesPlugin;\n"],"names":["pluginName","PLUGIN_NAME","cleanupAlias","str","replace","ViteMakeAliasesPlugin","options","root","tsconfig","projectRoot","process","cwd","tsconfigPath","path","resolve","aliases","fs","existsSync","tsJson","JSON5","parse","readFileSync","encoding","paths","compilerOptions","Object","entries","forEach","alias","aliasPaths","push","console","error","name","config","length","resolveConfig","defaultAliases","normalizedAliases","Array","isArray","map","find","val","replacement","ViteAliases"],"mappings":"sLAcA,MAAMA,EAAa,GAAGC,iBAChBC,EAAgBC,GAAwBA,EAAIC,QAAQ,SAAU,IAOpE,SAASC,EAAsBC,EAA0B,IACvD,MAAMC,KAAEA,EAAIC,SAAEA,GAAaF,EACrBG,EAAcF,GAAQG,EAAQC,MAC9BC,EAAeC,EAAKC,QAAQL,EAAaD,GAAY,iBACrDO,EAA8B,GAEpC,GAAKC,EAAGC,WAAWL,GAEZ,CACL,MAAMM,EAASC,EAAMC,MACnBJ,EAAGK,aAAaT,EAAc,CAAEU,SAAU,WAEtCC,EAAQL,GAAQM,iBAAiBD,OAAS,CAAA,EAEhDE,OAAOC,QAAQH,GAAOI,SAAQ,EAAEC,EAAOC,MACrCd,EAAQe,KAAK,CAAC5B,EAAa0B,GAAQ1B,EAAa2B,EAAW,KAAK,GAEpE,MAVEE,QAAQC,MAAM,GAAGhC,6BAAsCY,MAYzD,MAAO,CACLqB,KAAMjC,EACNkC,OAAOA,GACL,GAAInB,EAAQoB,OAAQ,CAClB,MAAMC,EAAgBF,EAAOpB,SAAW,CAAA,EAClCuB,EAAiBD,EAAcR,OAAS,GACxCU,EAAoBC,MAAMC,QAAQH,GACpCA,EACAZ,OAAOC,QAAQW,GAAgBI,KAAI,EAAEC,EAAMC,MAAI,CAC7CD,OACAE,YAAaD,MAGnBL,EAAkBR,QAAQe,EAAY9B,EAAS,GAAGN,KAAeyB,GAAQ3B,MAAQ,OAEjF2B,EAAOpB,QAAU,IACZsB,EACHR,MAAOU,EAEX,CAEA,OAAOJ,CACT,EAEJ"}
1
+ {"version":3,"file":"make-aliases.js","sources":["../../src/plugins/make-aliases.ts"],"sourcesContent":[null],"names":["pluginName","PLUGIN_NAME","cleanupAlias","str","replace","ViteMakeAliasesPlugin","options","root","tsconfig","projectRoot","process","cwd","tsconfigPath","path","resolve","aliases","fs","existsSync","tsJson","JSON5","parse","readFileSync","encoding","paths","compilerOptions","Object","entries","forEach","alias","aliasPaths","push","console","error","name","config","length","resolveConfig","defaultAliases","normalizedAliases","Array","isArray","map","find","val","replacement","ViteAliases"],"mappings":"sLAcA,MAAMA,EAAa,GAAGC,iBAChBC,EAAgBC,GAAwBA,EAAIC,QAAQ,SAAU,IAOpE,SAASC,EAAsBC,EAA0B,IACvD,MAAMC,KAAEA,EAAIC,SAAEA,GAAaF,EACrBG,EAAcF,GAAQG,EAAQC,MAC9BC,EAAeC,EAAKC,QAAQL,EAAaD,GAAY,iBACrDO,EAA8B,GAEpC,GAAKC,EAAGC,WAAWL,GAEZ,CACL,MAAMM,EAASC,EAAMC,MACnBJ,EAAGK,aAAaT,EAAc,CAAEU,SAAU,WAEtCC,EAAQL,GAAQM,iBAAiBD,OAAS,CAAA,EAEhDE,OAAOC,QAAQH,GAAOI,QAAQ,EAAEC,EAAOC,MACrCd,EAAQe,KAAK,CAAC5B,EAAa0B,GAAQ1B,EAAa2B,EAAW,OAE/D,MAVEE,QAAQC,MAAM,GAAGhC,6BAAsCY,MAYzD,MAAO,CACLqB,KAAMjC,EACN,MAAAkC,CAAOA,GACL,GAAInB,EAAQoB,OAAQ,CAClB,MAAMC,EAAgBF,EAAOpB,SAAW,CAAA,EAClCuB,EAAiBD,EAAcR,OAAS,GACxCU,EAAoBC,MAAMC,QAAQH,GACpCA,EACAZ,OAAOC,QAAQW,GAAgBI,IAAI,EAAEC,EAAMC,MAAI,CAC7CD,OACAE,YAAaD,KAGnBL,EAAkBR,QAAQe,EAAY9B,EAAS,GAAGN,KAAeyB,GAAQ3B,MAAQ,OAEjF2B,EAAOpB,QAAU,IACZsB,EACHR,MAAOU,EAEX,CAEA,OAAOJ,CACT,EAEJ"}
@@ -1,5 +1,5 @@
1
- import { Plugin } from 'vite';
2
- interface IPluginOptions {
1
+ import type { Plugin } from 'vite';
2
+ export interface IPluginOptions {
3
3
  isSSR?: boolean;
4
4
  isBuild?: boolean;
5
5
  routesPath?: string;
@@ -13,4 +13,4 @@ interface IPluginOptions {
13
13
  * @constructor
14
14
  */
15
15
  declare function ViteNormalizeRouterPlugin(options?: IPluginOptions): Plugin;
16
- export { ViteNormalizeRouterPlugin as default, IPluginOptions };
16
+ export default ViteNormalizeRouterPlugin;
@@ -1 +1 @@
1
- {"version":3,"file":"normalize-route.js","sources":["../../src/plugins/normalize-route.ts"],"sourcesContent":["import { extname } from 'node:path';\nimport type { Plugin } from 'vite';\nimport PLUGIN_NAME from '@constants/plugin-name';\nimport isRoutesFile from '@helpers/is-route-file';\nimport ParseRoutes from '@services/parse-routes';\n\nexport interface IPluginOptions {\n isSSR?: boolean;\n isBuild?: boolean;\n routesPath?: string;\n}\n\n/**\n * Add possibility to export route components like FCRoute or FCCRoute\n * USAGE: { path: '/', lazy: () => import('./pages/home') }\n * @see FCRoute\n * @see FCCRoute\n * @see importRoute\n * @constructor\n */\nfunction ViteNormalizeRouterPlugin(options: IPluginOptions = {}): Plugin {\n const { routesPath, isSSR = false, isBuild = false } = options;\n\n return {\n name: `${PLUGIN_NAME}-normalize-route`,\n enforce: 'pre',\n transform(code, id) {\n const [extName] = extname(id).split('?');\n const isRoutesPath = !routesPath || id.includes(routesPath);\n\n if (\n id.includes('node_modules') ||\n !['.js', '.mjs', '.ts', '.tsx'].includes(extName) ||\n !isRoutesPath ||\n !isRoutesFile(code)\n ) {\n return;\n }\n\n return {\n code: ParseRoutes.handleRoutes(\n code,\n // always add pathId to routes for development\n isSSR && !isBuild,\n ),\n map: { mappings: '' },\n };\n },\n };\n}\n\nexport default ViteNormalizeRouterPlugin;\n"],"names":["ViteNormalizeRouterPlugin","options","routesPath","isSSR","isBuild","name","PLUGIN_NAME","enforce","transform","code","id","extName","extname","split","isRoutesPath","includes","isRoutesFile","ParseRoutes","handleRoutes","map","mappings"],"mappings":"qKAoBA,SAASA,EAA0BC,EAA0B,IAC3D,MAAMC,WAAEA,EAAUC,MAAEA,GAAQ,EAAKC,QAAEA,GAAU,GAAUH,EAEvD,MAAO,CACLI,KAAM,GAAGC,oBACTC,QAAS,MACTC,UAAUC,EAAMC,GACd,MAAOC,GAAWC,EAAQF,GAAIG,MAAM,KAC9BC,GAAgBZ,GAAcQ,EAAGK,SAASb,GAEhD,IACEQ,EAAGK,SAAS,iBACX,CAAC,MAAO,OAAQ,MAAO,QAAQA,SAASJ,IACxCG,GACAE,EAAaP,GAKhB,MAAO,CACLA,KAAMQ,EAAYC,aAChBT,EAEAN,IAAUC,GAEZe,IAAK,CAAEC,SAAU,IAErB,EAEJ"}
1
+ {"version":3,"file":"normalize-route.js","sources":["../../src/plugins/normalize-route.ts"],"sourcesContent":[null],"names":["ViteNormalizeRouterPlugin","options","routesPath","isSSR","isBuild","name","PLUGIN_NAME","enforce","transform","code","id","extName","extname","split","isRoutesPath","includes","isRoutesFile","ParseRoutes","handleRoutes","map","mappings"],"mappings":"qKAoBA,SAASA,EAA0BC,EAA0B,IAC3D,MAAMC,WAAEA,EAAUC,MAAEA,GAAQ,EAAKC,QAAEA,GAAU,GAAUH,EAEvD,MAAO,CACLI,KAAM,GAAGC,oBACTC,QAAS,MACT,SAAAC,CAAUC,EAAMC,GACd,MAAOC,GAAWC,EAAQF,GAAIG,MAAM,KAC9BC,GAAgBZ,GAAcQ,EAAGK,SAASb,GAEhD,IACEQ,EAAGK,SAAS,iBACX,CAAC,MAAO,OAAQ,MAAO,QAAQA,SAASJ,IACxCG,GACAE,EAAaP,GAKhB,MAAO,CACLA,KAAMQ,EAAYC,aAChBT,EAEAN,IAAUC,GAEZe,IAAK,CAAEC,SAAU,IAErB,EAEJ"}
@@ -1,8 +1,7 @@
1
- /// <reference types="node" />
2
1
  import childProcess from 'node:child_process';
3
- import { ResolvedConfig } from 'vite';
4
- import { IPluginConfig } from "../helpers/plugin-config.js";
5
- interface IBuildParams {
2
+ import type { ResolvedConfig } from 'vite';
3
+ import type { IPluginConfig } from '../helpers/plugin-config.js';
4
+ export interface IBuildParams {
6
5
  mode: string;
7
6
  onFinish?: () => void;
8
7
  clientOptions?: string;
@@ -23,7 +22,7 @@ interface ISpawnBuildParams {
23
22
  focusOnly?: IBuildParams['focusOnly'];
24
23
  env?: Record<string, string>;
25
24
  }
26
- interface IBuildEntrypoint {
25
+ export interface IBuildEntrypoint {
27
26
  name: string;
28
27
  type: 'spa' | 'ssr';
29
28
  indexFile?: string;
@@ -74,110 +73,65 @@ declare class Build {
74
73
  * Listener for preview has attached
75
74
  */
76
75
  protected hasPreviewModeExitListener: boolean;
77
- /**
78
- * @constructor
79
- */
80
76
  /**
81
77
  * @constructor
82
78
  */
83
79
  constructor(params: IBuildParams);
84
- /**
85
- * Make config
86
- */
87
80
  /**
88
81
  * Make config
89
82
  */
90
83
  protected makeConfig(): Promise<void>;
91
- /**
92
- * Clear build folder
93
- */
94
84
  /**
95
85
  * Clear build folder
96
86
  */
97
87
  clearBuildFolder(): void;
98
- /**
99
- * Return is prod indicator value
100
- */
101
88
  /**
102
89
  * Return is prod indicator value
103
90
  */
104
91
  getIsProd(): boolean;
105
- /**
106
- * Return node env value
107
- */
108
92
  /**
109
93
  * Return node env value
110
94
  */
111
95
  getNodeEnv(): string;
112
- /**
113
- * Return build names
114
- */
115
96
  /**
116
97
  * Return build names
117
98
  */
118
99
  getRunningBuildNames(): string[];
119
- /**
120
- * Promisify spawn process
121
- */
122
100
  /**
123
101
  * Promisify spawn process
124
102
  */
125
103
  protected promisifyProcess(command: childProcess.ChildProcess, isRejectWarnings?: boolean): IBuildProcess;
126
- /**
127
- * Build assets manifest file
128
- */
129
104
  /**
130
105
  * Build assets manifest file
131
106
  */
132
107
  protected buildManifest(): void;
133
- /**
134
- * Change general directive Disallow to Allow in robots.txt.
135
- */
136
108
  /**
137
109
  * Change general directive Disallow to Allow in robots.txt.
138
110
  */
139
111
  protected unlockRobots(): void;
140
- /**
141
- * Eject cli to run app via node
142
- */
143
112
  /**
144
113
  * Eject cli to run app via node
145
114
  */
146
115
  protected eject(): void;
147
- /**
148
- * Create serverless entrypoint
149
- */
150
116
  /**
151
117
  * Create serverless entrypoint
152
118
  */
153
119
  protected createServerless(): void;
154
- /**
155
- * Build specified entrypoint
156
- */
157
120
  /**
158
121
  * Build specified entrypoint
159
122
  */
160
123
  protected spawnBuild(name: string, buildOptions: string, params?: ISpawnBuildParams): Promise<void>;
161
- /**
162
- * Wait latest build and stop process in case error
163
- */
164
124
  /**
165
125
  * Wait latest build and stop process in case error
166
126
  */
167
127
  protected waitLastBuild(): Promise<void>;
168
- /**
169
- * Run preview mode
170
- */
171
128
  /**
172
129
  * Run preview mode
173
130
  */
174
131
  protected runPreviewMode(): void;
175
- /**
176
- * Run app build
177
- */
178
132
  /**
179
133
  * Run app build
180
134
  */
181
135
  build(): Promise<void>;
182
136
  }
183
- export { Build as default, IBuildParams, IBuildEntrypoint };
137
+ export default Build;
package/services/build.js CHANGED
@@ -1,2 +1,2 @@
1
- import i from"node:child_process";import s from"node:fs";import t from"node:path";import e from"chalk";import{resolveConfig as o}from"vite";import r from"../cli/helpers/vite-reset-cache.js";import n from"../helpers/create-focus-only.js";import{createDevMarker as l}from"../helpers/dev-marker.js";import a from"../helpers/plugin-config.js";import u from"../helpers/process-stop.js";import c from"./server-config.js";import d from"./ssr-manifest.js";class h{isProd;nodeEnv;buildDir;viteConfig;pluginConfig;params={mode:"",clientOptions:"",serverOptions:"",focusOnly:"app",isWatch:!1,isUnlockRobots:!1,isEject:!1,isServerless:!1,isNoWarnings:!1};abortController=null;runningBuild=[];hasPreviewModeExitListener=!1;constructor(i){this.params={...this.params,...i}}async makeConfig(){const{mode:i}=this.params;this.viteConfig=await o({},"build",i,"production"),this.pluginConfig=a(this.viteConfig),this.buildDir=t.resolve(this.viteConfig.root,this.viteConfig.build.outDir),this.nodeEnv=process.env.NODE_ENV||"production",this.isProd="production"===this.nodeEnv}clearBuildFolder(){s.existsSync(this.buildDir)&&s.rmSync(this.buildDir,{recursive:!0})}getIsProd(){return this.isProd}getNodeEnv(){return this.nodeEnv}getRunningBuildNames(){return this.runningBuild.map((({name:i})=>i))}promisifyProcess(i,s=!1){const t=new Promise(((t,e)=>{i.on("exit",(i=>{t(i)})),i.on("close",(i=>{t(i)})),i.on("error",(i=>{e(i)})),s&&i.stderr?.on("data",(i=>{const s=Buffer.from(i).toString();(s.includes("warning")||s.includes("WARNING"))&&t(1)}))}));return i.stdout?.pipe(process.stdout),i.stderr?.pipe(process.stderr),{promise:t,command:i}}buildManifest(){console.info(e.blue("Building routes manifest file"));const i=c.init({isProd:this.isProd,mode:this.params.mode},{root:this.viteConfig.root,clientFile:this.pluginConfig.clientFile});d.get(i,{buildDir:this.viteConfig.build.outDir,viteAliases:this.viteConfig.resolve.alias,basename:this.viteConfig.base,renderBuiltUrl:this.viteConfig?.experimental?.renderBuiltUrl}).buildRoutesManifest()}unlockRobots(){const i=`${this.buildDir}/client/robots.txt`;if(!s.existsSync(i))return void console.warn(`Failed to unlock robots.txt, file not exist: ${i}`);const t=s.readFileSync(i,{encoding:"utf-8"}).replace(/Disallow: \/$/m,"Allow: /");s.writeFileSync(i,t,{encoding:"utf-8"}),console.info(e.blue("\nrobots.txt unlocked."))}eject(){const i=`${this.buildDir}/server/start.js`;s.writeFileSync(i,"import runProd from '@lomray/vite-ssr-boost/cli/run-prod.js';\n\nconst VERSION = process.env.VERSION || \"1.0.0\";\nconst PORT = process.env.PORT || 3000;\nconst IS_HOST = process.env.IS_HOST || \"0\";\nconst ONLY_CLIENT = process.env.ONLY_CLIENT || \"0\";\n\nawait runProd({\n version: VERSION,\n isHost: IS_HOST === '1',\n isPrintInfo: true,\n port: PORT,\n onlyClient: ONLY_CLIENT === '1',\n });\n",{encoding:"utf-8"})}createServerless(){const i=`${this.buildDir}/server/serverless.js`;s.writeFileSync(i,"import runServerless from '@lomray/vite-ssr-boost/cli/run-serverless.js';\n\nexport default await runServerless({ version: process.env.VERSION || \"1.0.0\" });\n",{encoding:"utf-8"})}async spawnBuild(s,t,e={}){const{mode:o,isNoWarnings:r}=this.params,{focusOnly:l=this.params.focusOnly,shouldWait:a=!1,env:u={}}=e,c=o&&!t.includes("--mode")?`--mode ${o}`:"",d=this.promisifyProcess(i.spawn(`vite build ${t} ${c} --emptyOutDir`,{signal:this.abortController.signal,stdio:[process.stdin,"pipe","pipe"],shell:!0,env:{...process.env,...u,FORCE_COLOR:"2",SSR_BOOST_IS_SSR:n(l).isOnlyClient()?"0":"1",SSR_BOOST_ACTION:global.viteBoostAction}}),r);this.runningBuild.push({name:s,buildProcess:d}),a&&await this.waitLastBuild()}async waitLastBuild(){const i=this.runningBuild.at(-1);if(!i)return;const s=await i.buildProcess.promise;u(s,!0)}runPreviewMode(){this.hasPreviewModeExitListener||(process.on("exit",(()=>{this.abortController.abort()})),this.hasPreviewModeExitListener=!0);const{onFinish:i}=this.params;let s=this.runningBuild.length;const t=e=>{Buffer.from(e).toString().includes("built in")&&(s-=1,s||(this.runningBuild.forEach((({buildProcess:i})=>{i.command.stdout?.removeListener("data",t)})),l(this.isProd,this.viteConfig),i?.()))};this.runningBuild.forEach((({buildProcess:i})=>{i.command.stdout?.on("data",t)}))}async build(){await this.makeConfig(),await r(),this.clearBuildFolder();const{clientOptions:i,serverOptions:s,onFinish:t,isWatch:e,focusOnly:o,isEject:a,isServerless:u,isUnlockRobots:c}=this.params,{outDir:d}=this.viteConfig.build,h=n(o);this.abortController=new AbortController,this.runningBuild=[],h.isClient()&&await this.spawnBuild("client",`${i} --outDir ${d}/client`,{shouldWait:!e}),h.isServer()&&(await this.spawnBuild("server",`${s} --outDir ${d}/server --ssr ${this.pluginConfig.serverFile}`,{shouldWait:!e}),e||(this.buildManifest(),a&&this.eject(),u&&this.createServerless()));const{entrypoint:p}=this.pluginConfig;if(p?.length&&h.isEntrypoint())for(const{name:i,type:s,serverFile:t,buildOptions:o=""}of p){const r=t&&"ssr"===s?`--ssr ${t}`:"";await this.spawnBuild(i,`${o} ${r} --outDir ${d}/${i}`,{shouldWait:!e,focusOnly:"ssr"===s?"server":"client",env:{SSR_BOOST_CUSTOM_ENTRYPOINT_BUILD_NAME:i}})}e?this.runPreviewMode():(c&&this.unlockRobots(),l(this.isProd,this.viteConfig),t?.())}}export{h as default};
1
+ import i from"node:child_process";import s from"node:fs";import t from"node:path";import e from"chalk";import{resolveConfig as o}from"vite";import r from"../cli/helpers/vite-reset-cache.js";import n from"../helpers/create-focus-only.js";import{createDevMarker as l}from"../helpers/dev-marker.js";import a from"../helpers/plugin-config.js";import u from"../helpers/process-stop.js";import c from"./server-config.js";import d from"./ssr-manifest.js";class h{isProd;nodeEnv;buildDir;viteConfig;pluginConfig;params={mode:"",clientOptions:"",serverOptions:"",focusOnly:"app",isWatch:!1,isUnlockRobots:!1,isEject:!1,isServerless:!1,isNoWarnings:!1};abortController=null;runningBuild=[];hasPreviewModeExitListener=!1;constructor(i){this.params={...this.params,...i}}async makeConfig(){const{mode:i}=this.params;this.viteConfig=await o({},"build",i,"production"),this.pluginConfig=a(this.viteConfig),this.buildDir=t.resolve(this.viteConfig.root,this.viteConfig.build.outDir),this.nodeEnv=process.env.NODE_ENV||"production",this.isProd="production"===this.nodeEnv}clearBuildFolder(){s.existsSync(this.buildDir)&&s.rmSync(this.buildDir,{recursive:!0})}getIsProd(){return this.isProd}getNodeEnv(){return this.nodeEnv}getRunningBuildNames(){return this.runningBuild.map(({name:i})=>i)}promisifyProcess(i,s=!1){const t=new Promise((t,e)=>{i.on("exit",i=>{t(i)}),i.on("close",i=>{t(i)}),i.on("error",i=>{e(i)}),s&&i.stderr?.on("data",i=>{const s=Buffer.from(i).toString();(s.includes("warning")||s.includes("WARNING"))&&t(1)})});return i.stdout?.pipe(process.stdout),i.stderr?.pipe(process.stderr),{promise:t,command:i}}buildManifest(){console.info(e.blue("Building routes manifest file"));const i=c.init({isProd:this.isProd,mode:this.params.mode},{root:this.viteConfig.root,clientFile:this.pluginConfig.clientFile});d.get(i,{buildDir:this.viteConfig.build.outDir,viteAliases:this.viteConfig.resolve.alias,basename:this.viteConfig.base,renderBuiltUrl:this.viteConfig?.experimental?.renderBuiltUrl}).buildRoutesManifest()}unlockRobots(){const i=`${this.buildDir}/client/robots.txt`;if(!s.existsSync(i))return void console.warn(`Failed to unlock robots.txt, file not exist: ${i}`);const t=s.readFileSync(i,{encoding:"utf-8"}).replace(/Disallow: \/$/m,"Allow: /");s.writeFileSync(i,t,{encoding:"utf-8"}),console.info(e.blue("\nrobots.txt unlocked."))}eject(){const i=`${this.buildDir}/server/start.js`;s.writeFileSync(i,"import runProd from '@lomray/vite-ssr-boost/cli/run-prod.js';\n\nconst VERSION = process.env.VERSION || \"1.0.0\";\nconst PORT = process.env.PORT || 3000;\nconst IS_HOST = process.env.IS_HOST || \"0\";\nconst ONLY_CLIENT = process.env.ONLY_CLIENT || \"0\";\n\nawait runProd({\n version: VERSION,\n isHost: IS_HOST === '1',\n isPrintInfo: true,\n port: PORT,\n onlyClient: ONLY_CLIENT === '1',\n });\n",{encoding:"utf-8"})}createServerless(){const i=`${this.buildDir}/server/serverless.js`;s.writeFileSync(i,"import runServerless from '@lomray/vite-ssr-boost/cli/run-serverless.js';\n\nexport default await runServerless({ version: process.env.VERSION || \"1.0.0\" });\n",{encoding:"utf-8"})}async spawnBuild(s,t,e={}){const{mode:o,isNoWarnings:r}=this.params,{focusOnly:l=this.params.focusOnly,shouldWait:a=!1,env:u={}}=e,c=o&&!t.includes("--mode")?`--mode ${o}`:"",d=this.promisifyProcess(i.spawn(`vite build ${t} ${c} --emptyOutDir`,{signal:this.abortController.signal,stdio:[process.stdin,"pipe","pipe"],shell:!0,env:{...process.env,...u,FORCE_COLOR:"2",SSR_BOOST_IS_SSR:n(l).isOnlyClient()?"0":"1",SSR_BOOST_ACTION:global.viteBoostAction}}),r);this.runningBuild.push({name:s,buildProcess:d}),a&&await this.waitLastBuild()}async waitLastBuild(){const i=this.runningBuild.at(-1);if(!i)return;const s=await i.buildProcess.promise;u(s,!0)}runPreviewMode(){this.hasPreviewModeExitListener||(process.on("exit",()=>{this.abortController.abort()}),this.hasPreviewModeExitListener=!0);const{onFinish:i}=this.params;let s=this.runningBuild.length;const t=e=>{Buffer.from(e).toString().includes("built in")&&(s-=1,s||(this.runningBuild.forEach(({buildProcess:i})=>{i.command.stdout?.removeListener("data",t)}),l(this.isProd,this.viteConfig),i?.()))};this.runningBuild.forEach(({buildProcess:i})=>{i.command.stdout?.on("data",t)})}async build(){await this.makeConfig(),await r(),this.clearBuildFolder();const{clientOptions:i,serverOptions:s,onFinish:t,isWatch:e,focusOnly:o,isEject:a,isServerless:u,isUnlockRobots:c}=this.params,{outDir:d}=this.viteConfig.build,h=n(o);this.abortController=new AbortController,this.runningBuild=[],h.isClient()&&await this.spawnBuild("client",`${i} --outDir ${d}/client`,{shouldWait:!e}),h.isServer()&&(await this.spawnBuild("server",`${s} --outDir ${d}/server --ssr ${this.pluginConfig.serverFile}`,{shouldWait:!e}),e||(this.buildManifest(),a&&this.eject(),u&&this.createServerless()));const{entrypoint:p}=this.pluginConfig;if(p?.length&&h.isEntrypoint())for(const{name:i,type:s,serverFile:t,buildOptions:o=""}of p){const r=t&&"ssr"===s?`--ssr ${t}`:"";await this.spawnBuild(i,`${o} ${r} --outDir ${d}/${i}`,{shouldWait:!e,focusOnly:"ssr"===s?"server":"client",env:{SSR_BOOST_CUSTOM_ENTRYPOINT_BUILD_NAME:i}})}e?this.runPreviewMode():(c&&this.unlockRobots(),l(this.isProd,this.viteConfig),t?.())}}export{h as default};
2
2
  //# sourceMappingURL=build.js.map