@format.dev/compile 0.0.0 → 0.1.1

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 (466) hide show
  1. package/README.md +30 -20
  2. package/bin/format-compile +3 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs +14 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.mjs +16 -0
  5. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.mjs +11 -0
  6. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.mjs +12 -0
  7. package/dist/_virtual/rolldown_runtime.mjs +46 -0
  8. package/dist/node_modules/.pnpm/@babel_parser@7.29.8/node_modules/@babel/parser/lib/index.mjs +12606 -0
  9. package/dist/node_modules/.pnpm/@babel_parser@7.29.8/node_modules/@babel/parser/lib/index.mjs.map +1 -0
  10. package/dist/node_modules/.pnpm/@vue_compiler-core@3.5.41/node_modules/@vue/compiler-core/dist/compiler-core.cjs.mjs +4866 -0
  11. package/dist/node_modules/.pnpm/@vue_compiler-core@3.5.41/node_modules/@vue/compiler-core/dist/compiler-core.cjs.mjs.map +1 -0
  12. package/dist/node_modules/.pnpm/@vue_compiler-core@3.5.41/node_modules/@vue/compiler-core/index.mjs +13 -0
  13. package/dist/node_modules/.pnpm/@vue_compiler-core@3.5.41/node_modules/@vue/compiler-core/index.mjs.map +1 -0
  14. package/dist/node_modules/.pnpm/@vue_compiler-dom@3.5.41/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.mjs +663 -0
  15. package/dist/node_modules/.pnpm/@vue_compiler-dom@3.5.41/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.mjs.map +1 -0
  16. package/dist/node_modules/.pnpm/@vue_compiler-dom@3.5.41/node_modules/@vue/compiler-dom/index.mjs +13 -0
  17. package/dist/node_modules/.pnpm/@vue_compiler-dom@3.5.41/node_modules/@vue/compiler-dom/index.mjs.map +1 -0
  18. package/dist/node_modules/.pnpm/@vue_compiler-ssr@3.5.41/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.mjs +846 -0
  19. package/dist/node_modules/.pnpm/@vue_compiler-ssr@3.5.41/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.mjs.map +1 -0
  20. package/dist/node_modules/.pnpm/@vue_reactivity@3.5.41/node_modules/@vue/reactivity/dist/reactivity.cjs.mjs +1600 -0
  21. package/dist/node_modules/.pnpm/@vue_reactivity@3.5.41/node_modules/@vue/reactivity/dist/reactivity.cjs.mjs.map +1 -0
  22. package/dist/node_modules/.pnpm/@vue_reactivity@3.5.41/node_modules/@vue/reactivity/index.mjs +13 -0
  23. package/dist/node_modules/.pnpm/@vue_reactivity@3.5.41/node_modules/@vue/reactivity/index.mjs.map +1 -0
  24. package/dist/node_modules/.pnpm/@vue_runtime-core@3.5.41/node_modules/@vue/runtime-core/dist/runtime-core.cjs.mjs +5619 -0
  25. package/dist/node_modules/.pnpm/@vue_runtime-core@3.5.41/node_modules/@vue/runtime-core/dist/runtime-core.cjs.mjs.map +1 -0
  26. package/dist/node_modules/.pnpm/@vue_runtime-core@3.5.41/node_modules/@vue/runtime-core/index.mjs +13 -0
  27. package/dist/node_modules/.pnpm/@vue_runtime-core@3.5.41/node_modules/@vue/runtime-core/index.mjs.map +1 -0
  28. package/dist/node_modules/.pnpm/@vue_runtime-dom@3.5.41/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.mjs +1479 -0
  29. package/dist/node_modules/.pnpm/@vue_runtime-dom@3.5.41/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.mjs.map +1 -0
  30. package/dist/node_modules/.pnpm/@vue_runtime-dom@3.5.41/node_modules/@vue/runtime-dom/index.mjs +13 -0
  31. package/dist/node_modules/.pnpm/@vue_runtime-dom@3.5.41/node_modules/@vue/runtime-dom/index.mjs.map +1 -0
  32. package/dist/node_modules/.pnpm/@vue_server-renderer@3.5.41/node_modules/@vue/server-renderer/dist/server-renderer.cjs.mjs +510 -0
  33. package/dist/node_modules/.pnpm/@vue_server-renderer@3.5.41/node_modules/@vue/server-renderer/dist/server-renderer.cjs.mjs.map +1 -0
  34. package/dist/node_modules/.pnpm/@vue_server-renderer@3.5.41/node_modules/@vue/server-renderer/index.mjs +13 -0
  35. package/dist/node_modules/.pnpm/@vue_server-renderer@3.5.41/node_modules/@vue/server-renderer/index.mjs.map +1 -0
  36. package/dist/node_modules/.pnpm/@vue_shared@3.5.41/node_modules/@vue/shared/dist/shared.cjs.mjs +499 -0
  37. package/dist/node_modules/.pnpm/@vue_shared@3.5.41/node_modules/@vue/shared/dist/shared.cjs.mjs.map +1 -0
  38. package/dist/node_modules/.pnpm/@vue_shared@3.5.41/node_modules/@vue/shared/index.mjs +13 -0
  39. package/dist/node_modules/.pnpm/@vue_shared@3.5.41/node_modules/@vue/shared/index.mjs.map +1 -0
  40. package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/decode-codepoint.mjs +79 -0
  41. package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/decode-codepoint.mjs.map +1 -0
  42. package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/decode.mjs +471 -0
  43. package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/decode.mjs.map +1 -0
  44. package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/generated/decode-data-html.mjs +16 -0
  45. package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/generated/decode-data-html.mjs.map +1 -0
  46. package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/generated/decode-data-xml.mjs +16 -0
  47. package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/generated/decode-data-xml.mjs.map +1 -0
  48. package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/internal/bin-trie-flags.mjs +30 -0
  49. package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/internal/bin-trie-flags.mjs.map +1 -0
  50. package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/internal/decode-shared.mjs +24 -0
  51. package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/internal/decode-shared.mjs.map +1 -0
  52. package/dist/node_modules/.pnpm/estree-walker@2.0.2/node_modules/estree-walker/dist/umd/estree-walker.mjs +253 -0
  53. package/dist/node_modules/.pnpm/estree-walker@2.0.2/node_modules/estree-walker/dist/umd/estree-walker.mjs.map +1 -0
  54. package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.mjs +5246 -0
  55. package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.mjs.map +1 -0
  56. package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/cjs/react-dom-server.node.development.mjs +5616 -0
  57. package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/cjs/react-dom-server.node.development.mjs.map +1 -0
  58. package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/cjs/react-dom.development.mjs +183 -0
  59. package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/cjs/react-dom.development.mjs.map +1 -0
  60. package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/index.mjs +13 -0
  61. package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/index.mjs.map +1 -0
  62. package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/server.node.mjs +21 -0
  63. package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/server.node.mjs.map +1 -0
  64. package/dist/node_modules/.pnpm/react@19.2.8/node_modules/react/cjs/react.development.mjs +766 -0
  65. package/dist/node_modules/.pnpm/react@19.2.8/node_modules/react/cjs/react.development.mjs.map +1 -0
  66. package/dist/node_modules/.pnpm/react@19.2.8/node_modules/react/index.mjs +13 -0
  67. package/dist/node_modules/.pnpm/react@19.2.8/node_modules/react/index.mjs.map +1 -0
  68. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/array-set.mjs +100 -0
  69. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/array-set.mjs.map +1 -0
  70. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/base64-vlq.mjs +73 -0
  71. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/base64-vlq.mjs.map +1 -0
  72. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/base64.mjs +41 -0
  73. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/base64.mjs.map +1 -0
  74. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/binary-search.mjs +68 -0
  75. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/binary-search.mjs.map +1 -0
  76. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/mapping-list.mjs +77 -0
  77. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/mapping-list.mjs.map +1 -0
  78. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/quick-sort.mjs +89 -0
  79. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/quick-sort.mjs.map +1 -0
  80. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/source-map-consumer.mjs +788 -0
  81. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/source-map-consumer.mjs.map +1 -0
  82. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/source-map-generator.mjs +295 -0
  83. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/source-map-generator.mjs.map +1 -0
  84. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/source-node.mjs +293 -0
  85. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/source-node.mjs.map +1 -0
  86. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/util.mjs +352 -0
  87. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/util.mjs.map +1 -0
  88. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/source-map.mjs +17 -0
  89. package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/source-map.mjs.map +1 -0
  90. package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/dist/vue.cjs.mjs +67 -0
  91. package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/dist/vue.cjs.mjs.map +1 -0
  92. package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/index.mjs +13 -0
  93. package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/index.mjs.map +1 -0
  94. package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/index2.mjs +10 -0
  95. package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/index2.mjs.map +1 -0
  96. package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/server-renderer/index.mjs +10 -0
  97. package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/server-renderer/index.mjs.map +1 -0
  98. package/dist/server/cli/bin.d.mts +1 -0
  99. package/dist/server/cli/bin.mjs +8 -0
  100. package/dist/server/cli/bin.mjs.map +1 -0
  101. package/dist/server/cli/cli-spec.mjs +150 -0
  102. package/dist/server/cli/cli-spec.mjs.map +1 -0
  103. package/dist/server/cli/index.d.mts +16 -0
  104. package/dist/server/cli/index.d.mts.map +1 -0
  105. package/dist/server/cli/index.mjs +64 -0
  106. package/dist/server/cli/index.mjs.map +1 -0
  107. package/dist/server/compile/adaptors/html-partials.d.mts +24 -0
  108. package/dist/server/compile/adaptors/html-partials.d.mts.map +1 -0
  109. package/dist/server/compile/adaptors/html-partials.mjs +50 -0
  110. package/dist/server/compile/adaptors/html-partials.mjs.map +1 -0
  111. package/dist/server/compile/adaptors/html.d.mts +15 -0
  112. package/dist/server/compile/adaptors/html.d.mts.map +1 -0
  113. package/dist/server/compile/adaptors/html.mjs +39 -0
  114. package/dist/server/compile/adaptors/html.mjs.map +1 -0
  115. package/dist/server/compile/adaptors/node-require.d.mts +6 -0
  116. package/dist/server/compile/adaptors/node-require.d.mts.map +1 -0
  117. package/dist/server/compile/adaptors/node-require.mjs +35 -0
  118. package/dist/server/compile/adaptors/node-require.mjs.map +1 -0
  119. package/dist/server/compile/adaptors/react-browser.d.mts +20 -0
  120. package/dist/server/compile/adaptors/react-browser.d.mts.map +1 -0
  121. package/dist/server/compile/adaptors/react-browser.mjs +19 -0
  122. package/dist/server/compile/adaptors/react-browser.mjs.map +1 -0
  123. package/dist/server/compile/adaptors/react-node.d.mts +17 -0
  124. package/dist/server/compile/adaptors/react-node.d.mts.map +1 -0
  125. package/dist/server/compile/adaptors/react-node.mjs +50 -0
  126. package/dist/server/compile/adaptors/react-node.mjs.map +1 -0
  127. package/dist/server/compile/adaptors/types.d.mts +14 -0
  128. package/dist/server/compile/adaptors/types.d.mts.map +1 -0
  129. package/dist/server/compile/adaptors/types.mjs +1 -0
  130. package/dist/server/compile/adaptors/vue-browser.d.mts +16 -0
  131. package/dist/server/compile/adaptors/vue-browser.d.mts.map +1 -0
  132. package/dist/server/compile/adaptors/vue-browser.mjs +16 -0
  133. package/dist/server/compile/adaptors/vue-browser.mjs.map +1 -0
  134. package/dist/server/compile/adaptors/vue-node.d.mts +17 -0
  135. package/dist/server/compile/adaptors/vue-node.d.mts.map +1 -0
  136. package/dist/server/compile/adaptors/vue-node.mjs +50 -0
  137. package/dist/server/compile/adaptors/vue-node.mjs.map +1 -0
  138. package/dist/server/compile/build-entry-module.d.mts +20 -0
  139. package/dist/server/compile/build-entry-module.d.mts.map +1 -0
  140. package/dist/server/compile/build-entry-module.mjs +56 -0
  141. package/dist/server/compile/build-entry-module.mjs.map +1 -0
  142. package/dist/server/compile/bundle-name.d.mts +5 -0
  143. package/dist/server/compile/bundle-name.d.mts.map +1 -0
  144. package/dist/server/compile/bundle-name.mjs +13 -0
  145. package/dist/server/compile/bundle-name.mjs.map +1 -0
  146. package/dist/server/compile/compile-cache.d.mts +23 -0
  147. package/dist/server/compile/compile-cache.d.mts.map +1 -0
  148. package/dist/server/compile/compile-cache.mjs +102 -0
  149. package/dist/server/compile/compile-cache.mjs.map +1 -0
  150. package/dist/server/compile/compile.d.mts +100 -0
  151. package/dist/server/compile/compile.d.mts.map +1 -0
  152. package/dist/server/compile/compile.mjs +735 -0
  153. package/dist/server/compile/compile.mjs.map +1 -0
  154. package/dist/server/compile/constants.d.mts +11 -0
  155. package/dist/server/compile/constants.d.mts.map +1 -0
  156. package/dist/server/compile/constants.mjs +12 -0
  157. package/dist/server/compile/constants.mjs.map +1 -0
  158. package/dist/server/compile/create-renderer.d.mts +16 -0
  159. package/dist/server/compile/create-renderer.d.mts.map +1 -0
  160. package/dist/server/compile/create-renderer.mjs +59 -0
  161. package/dist/server/compile/create-renderer.mjs.map +1 -0
  162. package/dist/server/compile/decode-style-entities.d.mts +12 -0
  163. package/dist/server/compile/decode-style-entities.d.mts.map +1 -0
  164. package/dist/server/compile/decode-style-entities.mjs +32 -0
  165. package/dist/server/compile/decode-style-entities.mjs.map +1 -0
  166. package/dist/server/compile/defaults.d.mts +18 -0
  167. package/dist/server/compile/defaults.d.mts.map +1 -0
  168. package/dist/server/compile/defaults.mjs +128 -0
  169. package/dist/server/compile/defaults.mjs.map +1 -0
  170. package/dist/server/compile/dependency-closure.d.mts +10 -0
  171. package/dist/server/compile/dependency-closure.d.mts.map +1 -0
  172. package/dist/server/compile/dependency-closure.mjs +79 -0
  173. package/dist/server/compile/dependency-closure.mjs.map +1 -0
  174. package/dist/server/compile/document-assets.d.mts +103 -0
  175. package/dist/server/compile/document-assets.d.mts.map +1 -0
  176. package/dist/server/compile/document-assets.mjs +184 -0
  177. package/dist/server/compile/document-assets.mjs.map +1 -0
  178. package/dist/server/compile/finalize-document-html.d.mts +53 -0
  179. package/dist/server/compile/finalize-document-html.d.mts.map +1 -0
  180. package/dist/server/compile/finalize-document-html.mjs +132 -0
  181. package/dist/server/compile/finalize-document-html.mjs.map +1 -0
  182. package/dist/server/compile/generated/adaptorHtml.mjs +6 -0
  183. package/dist/server/compile/generated/adaptorHtml.mjs.map +1 -0
  184. package/dist/server/compile/generated/adaptorReactBrowser.mjs +6 -0
  185. package/dist/server/compile/generated/adaptorReactBrowser.mjs.map +1 -0
  186. package/dist/server/compile/generated/adaptorReactNode.mjs +6 -0
  187. package/dist/server/compile/generated/adaptorReactNode.mjs.map +1 -0
  188. package/dist/server/compile/generated/adaptorVueBrowser.mjs +6 -0
  189. package/dist/server/compile/generated/adaptorVueBrowser.mjs.map +1 -0
  190. package/dist/server/compile/generated/adaptorVueNode.mjs +6 -0
  191. package/dist/server/compile/generated/adaptorVueNode.mjs.map +1 -0
  192. package/dist/server/compile/generated/createRenderer.mjs +6 -0
  193. package/dist/server/compile/generated/createRenderer.mjs.map +1 -0
  194. package/dist/server/compile/generated/decodeStyleEntities.mjs +6 -0
  195. package/dist/server/compile/generated/decodeStyleEntities.mjs.map +1 -0
  196. package/dist/server/compile/generated/sanitizeHtml.mjs +6 -0
  197. package/dist/server/compile/generated/sanitizeHtml.mjs.map +1 -0
  198. package/dist/server/compile/generated/validate.mjs +6 -0
  199. package/dist/server/compile/generated/validate.mjs.map +1 -0
  200. package/dist/server/compile/generated/virtualStyles.mjs +6 -0
  201. package/dist/server/compile/generated/virtualStyles.mjs.map +1 -0
  202. package/dist/server/compile/get-renderer.d.mts +18 -0
  203. package/dist/server/compile/get-renderer.d.mts.map +1 -0
  204. package/dist/server/compile/get-renderer.mjs +31 -0
  205. package/dist/server/compile/get-renderer.mjs.map +1 -0
  206. package/dist/server/compile/index.d.mts +2 -0
  207. package/dist/server/compile/index.mjs +3 -0
  208. package/dist/server/compile/make-config.d.mts +39 -0
  209. package/dist/server/compile/make-config.d.mts.map +1 -0
  210. package/dist/server/compile/make-config.mjs +278 -0
  211. package/dist/server/compile/make-config.mjs.map +1 -0
  212. package/dist/server/compile/package-json.d.mts +5 -0
  213. package/dist/server/compile/package-json.d.mts.map +1 -0
  214. package/dist/server/compile/package-json.mjs +33 -0
  215. package/dist/server/compile/package-json.mjs.map +1 -0
  216. package/dist/server/compile/producer-agreement.d.mts +82 -0
  217. package/dist/server/compile/producer-agreement.d.mts.map +1 -0
  218. package/dist/server/compile/producer-agreement.mjs +143 -0
  219. package/dist/server/compile/producer-agreement.mjs.map +1 -0
  220. package/dist/server/compile/producer-release.d.mts +19 -0
  221. package/dist/server/compile/producer-release.d.mts.map +1 -0
  222. package/dist/server/compile/producer-release.mjs +27 -0
  223. package/dist/server/compile/producer-release.mjs.map +1 -0
  224. package/dist/server/compile/render-error.d.mts +37 -0
  225. package/dist/server/compile/render-error.d.mts.map +1 -0
  226. package/dist/server/compile/render-error.mjs +55 -0
  227. package/dist/server/compile/render-error.mjs.map +1 -0
  228. package/dist/server/compile/sanitize/shared.d.mts +19 -0
  229. package/dist/server/compile/sanitize/shared.d.mts.map +1 -0
  230. package/dist/server/compile/sanitize/shared.mjs +131 -0
  231. package/dist/server/compile/sanitize/shared.mjs.map +1 -0
  232. package/dist/server/compile/sanitize-html.d.mts +5 -0
  233. package/dist/server/compile/sanitize-html.d.mts.map +1 -0
  234. package/dist/server/compile/sanitize-html.mjs +65 -0
  235. package/dist/server/compile/sanitize-html.mjs.map +1 -0
  236. package/dist/server/compile/structured-log.d.mts +22 -0
  237. package/dist/server/compile/structured-log.d.mts.map +1 -0
  238. package/dist/server/compile/structured-log.mjs +31 -0
  239. package/dist/server/compile/structured-log.mjs.map +1 -0
  240. package/dist/server/compile/virtual-styles.d.mts +5 -0
  241. package/dist/server/compile/virtual-styles.d.mts.map +1 -0
  242. package/dist/server/compile/virtual-styles.mjs +19 -0
  243. package/dist/server/compile/virtual-styles.mjs.map +1 -0
  244. package/dist/server/compile/wrapper-source.d.mts +55 -0
  245. package/dist/server/compile/wrapper-source.d.mts.map +1 -0
  246. package/dist/server/compile/wrapper-source.mjs +187 -0
  247. package/dist/server/compile/wrapper-source.mjs.map +1 -0
  248. package/dist/server/constants.d.mts +17 -0
  249. package/dist/server/constants.d.mts.map +1 -0
  250. package/dist/server/constants.mjs +41 -0
  251. package/dist/server/constants.mjs.map +1 -0
  252. package/dist/server/errors.d.mts +21 -0
  253. package/dist/server/errors.d.mts.map +1 -0
  254. package/dist/server/errors.mjs +24 -0
  255. package/dist/server/errors.mjs.map +1 -0
  256. package/dist/server/index.d.mts +4 -0
  257. package/dist/server/index.mjs +4 -0
  258. package/dist/server/integrations/nextjs/generate-entry.d.mts +19 -0
  259. package/dist/server/integrations/nextjs/generate-entry.d.mts.map +1 -0
  260. package/dist/server/integrations/nextjs/generate-entry.mjs +246 -0
  261. package/dist/server/integrations/nextjs/generate-entry.mjs.map +1 -0
  262. package/dist/server/integrations/nextjs/index.d.mts +8 -0
  263. package/dist/server/integrations/nextjs/index.d.mts.map +1 -0
  264. package/dist/server/integrations/nextjs/index.mjs +90 -0
  265. package/dist/server/integrations/nextjs/index.mjs.map +1 -0
  266. package/dist/server/integrations/nextjs/watcher.d.mts +9 -0
  267. package/dist/server/integrations/nextjs/watcher.d.mts.map +1 -0
  268. package/dist/server/integrations/nextjs/watcher.mjs +45 -0
  269. package/dist/server/integrations/nextjs/watcher.mjs.map +1 -0
  270. package/dist/server/integrations/unplugin/esbuild.d.mts +2 -0
  271. package/dist/server/integrations/unplugin/esbuild.mjs +3 -0
  272. package/dist/server/integrations/unplugin/index.d.mts +69 -0
  273. package/dist/server/integrations/unplugin/index.d.mts.map +1 -0
  274. package/dist/server/integrations/unplugin/index.mjs +539 -0
  275. package/dist/server/integrations/unplugin/index.mjs.map +1 -0
  276. package/dist/server/integrations/unplugin/rollup.d.mts +2 -0
  277. package/dist/server/integrations/unplugin/rollup.mjs +3 -0
  278. package/dist/server/integrations/unplugin/utils.d.mts +12 -0
  279. package/dist/server/integrations/unplugin/utils.d.mts.map +1 -0
  280. package/dist/server/integrations/unplugin/utils.mjs +46 -0
  281. package/dist/server/integrations/unplugin/utils.mjs.map +1 -0
  282. package/dist/server/integrations/unplugin/vite.d.mts +2 -0
  283. package/dist/server/integrations/unplugin/vite.mjs +3 -0
  284. package/dist/server/integrations/unplugin/webpack.d.mts +2 -0
  285. package/dist/server/integrations/unplugin/webpack.mjs +3 -0
  286. package/dist/server/project/documents.d.mts +21 -0
  287. package/dist/server/project/documents.d.mts.map +1 -0
  288. package/dist/server/project/documents.mjs +114 -0
  289. package/dist/server/project/documents.mjs.map +1 -0
  290. package/dist/server/project/format-env-types.d.mts +19 -0
  291. package/dist/server/project/format-env-types.d.mts.map +1 -0
  292. package/dist/server/project/format-env-types.mjs +64 -0
  293. package/dist/server/project/format-env-types.mjs.map +1 -0
  294. package/dist/server/project/paths.d.mts +21 -0
  295. package/dist/server/project/paths.d.mts.map +1 -0
  296. package/dist/server/project/paths.mjs +31 -0
  297. package/dist/server/project/paths.mjs.map +1 -0
  298. package/dist/server/project/user-project-dir.d.mts +7 -0
  299. package/dist/server/project/user-project-dir.d.mts.map +1 -0
  300. package/dist/server/project/user-project-dir.mjs +16 -0
  301. package/dist/server/project/user-project-dir.mjs.map +1 -0
  302. package/dist/server/render-worker/client.d.mts +83 -0
  303. package/dist/server/render-worker/client.d.mts.map +1 -0
  304. package/dist/server/render-worker/client.mjs +359 -0
  305. package/dist/server/render-worker/client.mjs.map +1 -0
  306. package/dist/server/render-worker/document-css.d.mts +27 -0
  307. package/dist/server/render-worker/document-css.d.mts.map +1 -0
  308. package/dist/server/render-worker/document-css.mjs +37 -0
  309. package/dist/server/render-worker/document-css.mjs.map +1 -0
  310. package/dist/server/render-worker/env.d.mts +11 -0
  311. package/dist/server/render-worker/env.d.mts.map +1 -0
  312. package/dist/server/render-worker/env.mjs +26 -0
  313. package/dist/server/render-worker/env.mjs.map +1 -0
  314. package/dist/server/render-worker/error.d.mts +17 -0
  315. package/dist/server/render-worker/error.d.mts.map +1 -0
  316. package/dist/server/render-worker/error.mjs +40 -0
  317. package/dist/server/render-worker/error.mjs.map +1 -0
  318. package/dist/server/render-worker/host.d.mts +1 -0
  319. package/dist/server/render-worker/host.mjs +181 -0
  320. package/dist/server/render-worker/host.mjs.map +1 -0
  321. package/dist/server/render-worker/index.d.mts +4 -0
  322. package/dist/server/render-worker/index.mjs +4 -0
  323. package/dist/server/render-worker/sandbox.d.mts +25 -0
  324. package/dist/server/render-worker/sandbox.d.mts.map +1 -0
  325. package/dist/server/render-worker/sandbox.mjs +60 -0
  326. package/dist/server/render-worker/sandbox.mjs.map +1 -0
  327. package/dist/server/render-worker/types.d.mts +59 -0
  328. package/dist/server/render-worker/types.d.mts.map +1 -0
  329. package/dist/server/render-worker/types.mjs +1 -0
  330. package/dist/server/runtime-state.d.mts +12 -0
  331. package/dist/server/runtime-state.d.mts.map +1 -0
  332. package/dist/server/runtime-state.mjs +24 -0
  333. package/dist/server/runtime-state.mjs.map +1 -0
  334. package/dist/server/utils/check-dir.d.mts +12 -0
  335. package/dist/server/utils/check-dir.d.mts.map +1 -0
  336. package/dist/server/utils/check-dir.mjs +30 -0
  337. package/dist/server/utils/check-dir.mjs.map +1 -0
  338. package/dist/server/utils/dependencies.d.mts +11 -0
  339. package/dist/server/utils/dependencies.d.mts.map +1 -0
  340. package/dist/server/utils/dependencies.mjs +34 -0
  341. package/dist/server/utils/dependencies.mjs.map +1 -0
  342. package/dist/server/utils/env-var.d.mts +6 -0
  343. package/dist/server/utils/env-var.d.mts.map +1 -0
  344. package/dist/server/utils/env-var.mjs +28 -0
  345. package/dist/server/utils/env-var.mjs.map +1 -0
  346. package/dist/server/utils/format-for-log.d.mts +5 -0
  347. package/dist/server/utils/format-for-log.d.mts.map +1 -0
  348. package/dist/server/utils/format-for-log.mjs +17 -0
  349. package/dist/server/utils/format-for-log.mjs.map +1 -0
  350. package/dist/server/utils/index.d.mts +8 -0
  351. package/dist/server/utils/index.mjs +9 -0
  352. package/dist/server/utils/load-config.d.mts +13 -0
  353. package/dist/server/utils/load-config.d.mts.map +1 -0
  354. package/dist/server/utils/load-config.mjs +65 -0
  355. package/dist/server/utils/load-config.mjs.map +1 -0
  356. package/dist/server/utils/log.d.mts +36 -0
  357. package/dist/server/utils/log.d.mts.map +1 -0
  358. package/dist/server/utils/log.mjs +125 -0
  359. package/dist/server/utils/log.mjs.map +1 -0
  360. package/dist/server/utils/read-file.d.mts +5 -0
  361. package/dist/server/utils/read-file.d.mts.map +1 -0
  362. package/dist/server/utils/read-file.mjs +14 -0
  363. package/dist/server/utils/read-file.mjs.map +1 -0
  364. package/dist/server/utils/resolve-path-with-extensions.d.mts +21 -0
  365. package/dist/server/utils/resolve-path-with-extensions.d.mts.map +1 -0
  366. package/dist/server/utils/resolve-path-with-extensions.mjs +39 -0
  367. package/dist/server/utils/resolve-path-with-extensions.mjs.map +1 -0
  368. package/dist/server/utils/schema.d.mts +7 -0
  369. package/dist/server/utils/schema.d.mts.map +1 -0
  370. package/dist/server/utils/schema.mjs +21 -0
  371. package/dist/server/utils/schema.mjs.map +1 -0
  372. package/dist/server/utils/standard-schema-validate.d.mts +13 -0
  373. package/dist/server/utils/standard-schema-validate.d.mts.map +1 -0
  374. package/dist/server/utils/standard-schema-validate.mjs +21 -0
  375. package/dist/server/utils/standard-schema-validate.mjs.map +1 -0
  376. package/dist/server/utils/suggest-similar.d.mts +9 -0
  377. package/dist/server/utils/suggest-similar.d.mts.map +1 -0
  378. package/dist/server/utils/suggest-similar.mjs +39 -0
  379. package/dist/server/utils/suggest-similar.mjs.map +1 -0
  380. package/dist/server/utils/warn-lockstep.d.mts +13 -0
  381. package/dist/server/utils/warn-lockstep.d.mts.map +1 -0
  382. package/dist/server/utils/warn-lockstep.mjs +23 -0
  383. package/dist/server/utils/warn-lockstep.mjs.map +1 -0
  384. package/dist/server/vite/create-config.d.mts +35 -0
  385. package/dist/server/vite/create-config.d.mts.map +1 -0
  386. package/dist/server/vite/create-config.mjs +64 -0
  387. package/dist/server/vite/create-config.mjs.map +1 -0
  388. package/dist/server/vite/plugins/collect-css.d.mts +8 -0
  389. package/dist/server/vite/plugins/collect-css.d.mts.map +1 -0
  390. package/dist/server/vite/plugins/collect-css.mjs +21 -0
  391. package/dist/server/vite/plugins/collect-css.mjs.map +1 -0
  392. package/dist/server/vite/plugins/get-styles.d.mts +14 -0
  393. package/dist/server/vite/plugins/get-styles.d.mts.map +1 -0
  394. package/dist/server/vite/plugins/get-styles.mjs +88 -0
  395. package/dist/server/vite/plugins/get-styles.mjs.map +1 -0
  396. package/dist/server/vite/plugins/html-loader.d.mts +18 -0
  397. package/dist/server/vite/plugins/html-loader.d.mts.map +1 -0
  398. package/dist/server/vite/plugins/html-loader.mjs +88 -0
  399. package/dist/server/vite/plugins/html-loader.mjs.map +1 -0
  400. package/dist/server/vite/plugins/postcss/import-url.d.mts +14 -0
  401. package/dist/server/vite/plugins/postcss/import-url.d.mts.map +1 -0
  402. package/dist/server/vite/plugins/postcss/import-url.mjs +163 -0
  403. package/dist/server/vite/plugins/postcss/import-url.mjs.map +1 -0
  404. package/dist/server/vite/plugins/styles-pre-processor.d.mts +7 -0
  405. package/dist/server/vite/plugins/styles-pre-processor.d.mts.map +1 -0
  406. package/dist/server/vite/plugins/styles-pre-processor.mjs +64 -0
  407. package/dist/server/vite/plugins/styles-pre-processor.mjs.map +1 -0
  408. package/dist/server/vite/plugins/utils.d.mts +9 -0
  409. package/dist/server/vite/plugins/utils.d.mts.map +1 -0
  410. package/dist/server/vite/plugins/utils.mjs +14 -0
  411. package/dist/server/vite/plugins/utils.mjs.map +1 -0
  412. package/dist/shared/constants.d.mts +11 -0
  413. package/dist/shared/constants.d.mts.map +1 -0
  414. package/dist/shared/constants.mjs +12 -0
  415. package/dist/shared/constants.mjs.map +1 -0
  416. package/dist/shared/env.d.mts +6 -0
  417. package/dist/shared/env.d.mts.map +1 -0
  418. package/dist/shared/env.mjs +11 -0
  419. package/dist/shared/env.mjs.map +1 -0
  420. package/dist/shared/http.d.mts +15 -0
  421. package/dist/shared/http.d.mts.map +1 -0
  422. package/dist/shared/http.mjs +54 -0
  423. package/dist/shared/http.mjs.map +1 -0
  424. package/dist/shared/types/document.d.mts +17 -0
  425. package/dist/shared/types/document.d.mts.map +1 -0
  426. package/dist/shared/types/document.mjs +1 -0
  427. package/dist/shared/types/index.d.mts +7 -0
  428. package/dist/shared/types/index.mjs +4 -0
  429. package/dist/shared/types/log.d.mts +10 -0
  430. package/dist/shared/types/log.d.mts.map +1 -0
  431. package/dist/shared/types/log.mjs +12 -0
  432. package/dist/shared/types/log.mjs.map +1 -0
  433. package/dist/shared/types/public/cli.d.mts +33 -0
  434. package/dist/shared/types/public/cli.d.mts.map +1 -0
  435. package/dist/shared/types/public/cli.mjs +1 -0
  436. package/dist/shared/types/public/compile.d.mts +45 -0
  437. package/dist/shared/types/public/compile.d.mts.map +1 -0
  438. package/dist/shared/types/public/compile.mjs +29 -0
  439. package/dist/shared/types/public/compile.mjs.map +1 -0
  440. package/dist/shared/types/public/config.d.mts +94 -0
  441. package/dist/shared/types/public/config.d.mts.map +1 -0
  442. package/dist/shared/types/public/config.mjs +20 -0
  443. package/dist/shared/types/public/config.mjs.map +1 -0
  444. package/dist/shared/types/public/index.d.mts +6 -0
  445. package/dist/shared/types/public/index.mjs +4 -0
  446. package/dist/shared/types/public/nextjs.d.mts +111 -0
  447. package/dist/shared/types/public/nextjs.d.mts.map +1 -0
  448. package/dist/shared/types/public/nextjs.mjs +1 -0
  449. package/dist/shared/types/public/renderer.d.mts +2 -0
  450. package/dist/shared/types/public/renderer.mjs +1 -0
  451. package/dist/shared/types/public/unplugin.d.mts +65 -0
  452. package/dist/shared/types/public/unplugin.d.mts.map +1 -0
  453. package/dist/shared/types/public/unplugin.mjs +1 -0
  454. package/dist/shared/types/server.d.mts +5 -0
  455. package/dist/shared/types/server.d.mts.map +1 -0
  456. package/dist/shared/types/server.mjs +1 -0
  457. package/dist/shared/types/state.d.mts +15 -0
  458. package/dist/shared/types/state.d.mts.map +1 -0
  459. package/dist/shared/types/state.mjs +1 -0
  460. package/dist/shared/types/system.d.mts +18 -0
  461. package/dist/shared/types/system.d.mts.map +1 -0
  462. package/dist/shared/types/system.mjs +1 -0
  463. package/package.json +146 -34
  464. package/types/next.d.ts +6 -0
  465. package/index.d.ts +0 -2
  466. package/index.js +0 -3
@@ -0,0 +1,246 @@
1
+ import { getDocumentsDir } from "../../project/paths.mjs";
2
+ import { BUNDLE_ENTRY_POINT_FILE_NAME } from "../../compile/constants.mjs";
3
+ import { logger, withPrefixedConsole } from "../../utils/log.mjs";
4
+ import { resolveBundleName } from "../../compile/bundle-name.mjs";
5
+ import { computeCacheHash, readCachedHash, writeCacheHash } from "../../compile/compile-cache.mjs";
6
+ import { buildWrapperFactorySource } from "../../compile/wrapper-source.mjs";
7
+ import { resolveZipModulePath } from "../../compile/make-config.mjs";
8
+ import { dynamicAssetEmitEntries } from "../../compile/document-assets.mjs";
9
+ import { getDocuments } from "../../project/documents.mjs";
10
+ import { compileForUnplugin, getBundleOutDir } from "../../compile/compile.mjs";
11
+ import { writeFormatEnvTypes } from "../../project/format-env-types.mjs";
12
+ import { resolve } from "node:path";
13
+ import { pathToFileURL } from "node:url";
14
+ import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
15
+ import { listZipEntries } from "@format.dev/zip";
16
+ import { buildDocumentExportMap } from "@format.dev/cli/scaffold";
17
+
18
+ //#region src/server/integrations/nextjs/generate-entry.ts
19
+ const TARGET_SUFFIXES = {
20
+ node: "/node",
21
+ browser: "/browser",
22
+ worker: "/edge"
23
+ };
24
+ function resolveTargetOptions(shared, target) {
25
+ return {
26
+ target: target.target,
27
+ assets: target.assets ?? shared.assets ?? null,
28
+ inlineRemoteCss: target.inlineRemoteCss ?? shared.inlineRemoteCss ?? false,
29
+ validateSchema: target.validateSchema ?? shared.validateSchema ?? true,
30
+ bundle: target.bundle ?? [],
31
+ external: target.external ?? []
32
+ };
33
+ }
34
+ function getEntryFileName(target) {
35
+ return `_next-entry-${target}.js`;
36
+ }
37
+ function buildEntrySource(target, assetMode, rendererRelativePath, documents) {
38
+ const exportList = documents.map((doc) => doc.exportName).join(", ");
39
+ const factory = buildWrapperFactorySource({
40
+ mode: assetMode,
41
+ target,
42
+ zipModulePath: resolveZipModulePath(assetMode)
43
+ });
44
+ const wrapperLines = documents.map((doc) => `const ${doc.exportName} = createRendererWrapper(${JSON.stringify(doc.documentName)}, resolveRenderer(${JSON.stringify(doc.exportName)}), ${JSON.stringify(doc.init)});`);
45
+ return [
46
+ `import * as rendererModule from ${JSON.stringify(rendererRelativePath)};`,
47
+ factory,
48
+ [
49
+ `function resolveRenderer(name) {`,
50
+ ` const renderer = rendererModule?.[name] ?? rendererModule?.default?.[name] ?? rendererModule?.default?.default?.[name];`,
51
+ ` if (!renderer) {`,
52
+ ` throw new Error('Renderer export "' + name + '" not found');`,
53
+ ` }`,
54
+ ` return renderer;`,
55
+ `}`
56
+ ].join("\n"),
57
+ wrapperLines.join("\n"),
58
+ `export { ${exportList} };`,
59
+ `export default { ${exportList} };`,
60
+ ""
61
+ ].join("\n\n");
62
+ }
63
+ function buildTypesSourceForModule(moduleAlias, documents) {
64
+ const exportNames = documents.map((doc) => doc.exportName);
65
+ const namedExports = exportNames.map((name) => `\texport const ${name}: FormatRenderer`).join("\n");
66
+ const defaultShape = exportNames.map((name) => `${name}: FormatRenderer`).join("; ");
67
+ return [
68
+ `declare module '${moduleAlias}' {`,
69
+ " interface FormatAssetConfig {",
70
+ " getAssetsUrl(): string | undefined",
71
+ " setAssetsUrl(url: string): void",
72
+ " }",
73
+ "",
74
+ " interface FormatDocument {",
75
+ " html: string",
76
+ " getAssetsWebStream(): Promise<ReadableStream<Uint8Array> | undefined>",
77
+ " }",
78
+ "",
79
+ " interface FormatRenderer extends FormatAssetConfig {",
80
+ " render(data?: Record<string, unknown>): Promise<FormatDocument>",
81
+ " getAssetsWebStream(): Promise<ReadableStream<Uint8Array> | undefined>",
82
+ " }",
83
+ "",
84
+ namedExports,
85
+ "",
86
+ `\tconst renderers: { ${defaultShape}; [key: string]: FormatRenderer }`,
87
+ " export default renderers",
88
+ "}"
89
+ ].join("\n");
90
+ }
91
+ function buildTypesSource(aliases, documents) {
92
+ return `// Auto-generated by Format Studio — do not edit\n${aliases.map((alias) => buildTypesSourceForModule(alias, documents)).join("\n\n")}\n`;
93
+ }
94
+ function patchReactDomServerImports(source) {
95
+ let patched = source;
96
+ patched = patched.replace(/import\s*\{([^}]+)\}\s*from\s*["']react-dom\/server["']\s*;?/g, "const {$1} = await import(\"react-dom/server\");");
97
+ patched = patched.replace(/import\s*\*\s*as\s+(\w+)\s+from\s*["']react-dom\/server["']\s*;?/g, "const $1 = await import(\"react-dom/server\");");
98
+ patched = patched.replace(/import\s+(\w+)\s+from\s*["']react-dom\/server["']\s*;?/g, "const { default: $1 } = await import(\"react-dom/server\");");
99
+ return patched;
100
+ }
101
+ async function patchFile(filePath) {
102
+ const content = await readFile(filePath, "utf-8");
103
+ const patched = patchReactDomServerImports(content);
104
+ if (patched !== content) {
105
+ await writeFile(filePath, patched, "utf-8");
106
+ logger.debug(`Patched react-dom/server imports in ${filePath}`);
107
+ }
108
+ }
109
+ async function patchCompiledBundles(outDir, documentNames) {
110
+ for (const documentName of documentNames) await patchFile(resolve(outDir, documentName, BUNDLE_ENTRY_POINT_FILE_NAME));
111
+ const chunksDir = resolve(outDir, "chunks");
112
+ const chunkFiles = await readdir(chunksDir).catch(() => []);
113
+ for (const file of chunkFiles) if (file.endsWith(".js")) await patchFile(resolve(chunksDir, file));
114
+ }
115
+ async function compileTarget(targetConfig, options, config, outDir, bundleName, documentNames, exportNames) {
116
+ const resolved = resolveTargetOptions(options, targetConfig);
117
+ const suffix = TARGET_SUFFIXES[resolved.target];
118
+ const suffixedAlias = `@format:${bundleName}${suffix}`;
119
+ const targetOutDir = resolve(outDir, resolved.target);
120
+ const assetMode = resolved.assets ?? "static";
121
+ logger.info(`Compiling ${resolved.target} bundle. Documents: ${documentNames.join(", ")}`);
122
+ const assetState = /* @__PURE__ */ new Map();
123
+ await compileForUnplugin({
124
+ documents: documentNames,
125
+ assets: resolved.assets,
126
+ validateSchema: resolved.validateSchema,
127
+ inlineRemoteCss: resolved.inlineRemoteCss,
128
+ bundle: resolved.bundle,
129
+ external: resolved.external,
130
+ target: resolved.target,
131
+ configPath: options.configPath,
132
+ outDir: targetOutDir,
133
+ bundleName,
134
+ clean: false,
135
+ userBundler: "webpack"
136
+ }, { capturedAssetState: assetState });
137
+ await patchCompiledBundles(targetOutDir, documentNames);
138
+ const compiledDocuments = [];
139
+ for (const name of documentNames) {
140
+ const init = {
141
+ knownAssets: [],
142
+ assetUrls: null,
143
+ assetsPath: null,
144
+ assetsUrl: null
145
+ };
146
+ if (assetMode === "static") {
147
+ const zipPath = resolve(targetOutDir, name, "assets.zip");
148
+ const zipBuffer = await readFile(zipPath).catch(() => null);
149
+ if (zipBuffer) {
150
+ init.knownAssets = listZipEntries(new Uint8Array(zipBuffer));
151
+ init.assetsUrl = pathToFileURL(zipPath).href;
152
+ }
153
+ } else if (assetMode === "dynamic") {
154
+ const entries = dynamicAssetEmitEntries({
155
+ outDir: targetOutDir,
156
+ documentName: name,
157
+ urlMap: assetState.get(name)?.urlMap ?? {}
158
+ });
159
+ const urlMap = {};
160
+ for (const entry of entries) urlMap[entry.knownPath] = pathToFileURL(entry.sourcePath).href;
161
+ init.assetUrls = urlMap;
162
+ init.knownAssets = Object.keys(urlMap).sort();
163
+ }
164
+ compiledDocuments.push({
165
+ documentName: name,
166
+ exportName: exportNames.get(name),
167
+ init
168
+ });
169
+ }
170
+ const entryFileName = getEntryFileName(resolved.target);
171
+ const rendererRelativePath = `./${resolved.target}/${BUNDLE_ENTRY_POINT_FILE_NAME}`;
172
+ const entrySource = buildEntrySource(resolved.target, assetMode, rendererRelativePath, compiledDocuments);
173
+ const entryPath = resolve(outDir, entryFileName);
174
+ await writeFile(entryPath, entrySource, "utf-8");
175
+ logger.debug(`Generated Next.js entry module for ${resolved.target} at ${entryPath}`);
176
+ return {
177
+ target: resolved.target,
178
+ suffix,
179
+ aliasKeys: [suffixedAlias],
180
+ entryPath
181
+ };
182
+ }
183
+ async function generateEntry(config, options) {
184
+ const bundleName = resolveBundleName(options.bundleName);
185
+ const outDir = getBundleOutDir(config, options.outDir);
186
+ const targets = options.targets ?? [{ target: "node" }];
187
+ const documentNames = (await getDocuments(config)).map((doc) => doc.name).sort((a, b) => a.localeCompare(b));
188
+ if (documentNames.length === 0) throw new Error("No documents found to compile.");
189
+ const exportNames = buildDocumentExportMap(documentNames);
190
+ const currentHash = await computeCacheHash(getDocumentsDir(config), options);
191
+ if (await readCachedHash(outDir) === currentHash) {
192
+ logger.info("Cache hit. Skipping compile.");
193
+ return {
194
+ entries: targets.map((targetConfig, index) => {
195
+ const resolved = resolveTargetOptions(options, targetConfig);
196
+ const suffix = TARGET_SUFFIXES[resolved.target];
197
+ const suffixedAlias = `@format:${bundleName}${suffix}`;
198
+ const entryPath = resolve(outDir, getEntryFileName(resolved.target));
199
+ const aliasKeys = index === 0 ? [`@format:${bundleName}`, suffixedAlias] : [suffixedAlias];
200
+ return {
201
+ target: resolved.target,
202
+ suffix,
203
+ aliasKeys,
204
+ entryPath
205
+ };
206
+ }),
207
+ outDir
208
+ };
209
+ }
210
+ logger.debug(`Cache miss. Compiling ${targets.length} target(s)`);
211
+ if (options.clean !== false) {
212
+ const { rm: rm$1 } = await import("node:fs/promises");
213
+ await rm$1(outDir, {
214
+ recursive: true,
215
+ force: true
216
+ }).catch(() => {});
217
+ }
218
+ await mkdir(outDir, { recursive: true });
219
+ const suppressRolldownLogs = (_level, ...args) => {
220
+ const msg = args.join(" ");
221
+ if (msg.includes("vite v") && msg.includes("building")) return false;
222
+ if (msg.includes("built in")) return false;
223
+ return true;
224
+ };
225
+ const entries = await withPrefixedConsole(() => Promise.all(targets.map((targetConfig) => compileTarget(targetConfig, options, config, outDir, bundleName, documentNames, exportNames))), suppressRolldownLogs);
226
+ const baseAlias = `@format:${bundleName}`;
227
+ entries[0].aliasKeys = [baseAlias, ...entries[0].aliasKeys];
228
+ const allAliases = entries.flatMap((e) => e.aliasKeys);
229
+ const documentsForTypes = documentNames.map((name) => ({ exportName: exportNames.get(name) }));
230
+ const typesSource = buildTypesSource(allAliases, documentsForTypes);
231
+ await writeFile(resolve(outDir, "types.d.ts"), typesSource, "utf-8");
232
+ await writeFormatEnvTypes({
233
+ projectRoot: process.cwd(),
234
+ aliases: allAliases,
235
+ documents: documentsForTypes
236
+ });
237
+ await writeCacheHash(outDir, currentHash);
238
+ return {
239
+ entries,
240
+ outDir
241
+ };
242
+ }
243
+
244
+ //#endregion
245
+ export { generateEntry };
246
+ //# sourceMappingURL=generate-entry.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-entry.mjs","names":["TARGET_SUFFIXES: Record<Target, string>","assetMode: AssetMode","compiledDocuments: EntryDocument[]","init: EntryDocument['init']","urlMap: Record<string, string>","rm"],"sources":["../../../../src/server/integrations/nextjs/generate-entry.ts"],"sourcesContent":["import type { FormatConfig } from '../../../shared/types'\nimport type { AssetMode, Target } from '../../../shared/types/public/compile'\nimport type { FormatNextPluginOptions, FormatTargetOptions } from '../../../shared/types/public/nextjs'\nimport type { DocumentAssetState } from '../../compile/compile'\n\nimport { resolve } from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { mkdir, readdir, readFile, writeFile } from 'node:fs/promises'\nimport { listZipEntries } from '@format.dev/zip'\nimport { compileForUnplugin } from '../../compile/compile'\nimport { getBundleOutDir } from '../../compile/compile'\nimport { getDocuments } from '../../project/documents'\nimport { getDocumentsDir } from '../../project/paths'\nimport { buildDocumentExportMap } from '@format.dev/cli/scaffold'\nimport { resolveBundleName } from '../../compile/bundle-name'\nimport { BUNDLE_ENTRY_POINT_FILE_NAME } from '../../compile/constants'\nimport { computeCacheHash, readCachedHash, writeCacheHash } from '../../compile/compile-cache'\nimport { dynamicAssetEmitEntries } from '../../compile/document-assets'\nimport { buildWrapperFactorySource } from '../../compile/wrapper-source'\nimport { resolveZipModulePath } from '../../compile/make-config'\nimport { writeFormatEnvTypes } from '../../project/format-env-types'\nimport { logger, withPrefixedConsole } from '../../utils/log'\n\nconst TARGET_SUFFIXES: Record<Target, string> = {\n\tnode: '/node',\n\tbrowser: '/browser',\n\tworker: '/edge'\n}\n\ninterface ResolvedTargetOptions {\n\ttarget: Target\n\tassets: AssetMode | null\n\tinlineRemoteCss: boolean\n\tvalidateSchema: boolean\n\tbundle: string[]\n\texternal: string[]\n}\n\ninterface TargetEntry {\n\ttarget: Target\n\tsuffix: string\n\taliasKeys: string[]\n\tentryPath: string\n}\n\nexport interface GenerateEntryResult {\n\tentries: TargetEntry[]\n\toutDir: string\n}\n\nfunction resolveTargetOptions(shared: FormatNextPluginOptions, target: FormatTargetOptions): ResolvedTargetOptions {\n\treturn {\n\t\ttarget: target.target,\n\t\tassets: target.assets ?? shared.assets ?? null,\n\t\tinlineRemoteCss: target.inlineRemoteCss ?? shared.inlineRemoteCss ?? false,\n\t\tvalidateSchema: target.validateSchema ?? shared.validateSchema ?? true,\n\t\tbundle: target.bundle ?? [],\n\t\texternal: target.external ?? []\n\t}\n}\n\nfunction getEntryFileName(target: Target): string {\n\treturn `_next-entry-${target}.js`\n}\n\ninterface EntryDocument {\n\tdocumentName: string\n\texportName: string\n\tinit: {\n\t\tknownAssets: string[]\n\t\tassetUrls: Record<string, string> | null\n\t\tassetsPath: string | null\n\t\tassetsUrl: string | null\n\t}\n}\n\nfunction buildEntrySource(\n\ttarget: Target,\n\tassetMode: AssetMode,\n\trendererRelativePath: string,\n\tdocuments: EntryDocument[]\n): string {\n\tconst exportList = documents.map(doc => doc.exportName).join(', ')\n\n\tconst factory = buildWrapperFactorySource({\n\t\tmode: assetMode,\n\t\ttarget,\n\t\tzipModulePath: resolveZipModulePath(assetMode)\n\t})\n\n\tconst wrapperLines = documents.map(\n\t\tdoc =>\n\t\t\t`const ${doc.exportName} = createRendererWrapper(${JSON.stringify(doc.documentName)}, resolveRenderer(${JSON.stringify(doc.exportName)}), ${JSON.stringify(doc.init)});`\n\t)\n\n\treturn [\n\t\t`import * as rendererModule from ${JSON.stringify(rendererRelativePath)};`,\n\t\tfactory,\n\t\t[\n\t\t\t`function resolveRenderer(name) {`,\n\t\t\t`\tconst renderer = rendererModule?.[name] ?? rendererModule?.default?.[name] ?? rendererModule?.default?.default?.[name];`,\n\t\t\t`\tif (!renderer) {`,\n\t\t\t`\t\tthrow new Error('Renderer export \"' + name + '\" not found');`,\n\t\t\t`\t}`,\n\t\t\t`\treturn renderer;`,\n\t\t\t`}`\n\t\t].join('\\n'),\n\t\twrapperLines.join('\\n'),\n\t\t`export { ${exportList} };`,\n\t\t`export default { ${exportList} };`,\n\t\t''\n\t].join('\\n\\n')\n}\n\nfunction buildTypesSourceForModule(moduleAlias: string, documents: Array<{ exportName: string }>): string {\n\tconst exportNames = documents.map(doc => doc.exportName)\n\n\tconst namedExports = exportNames.map(name => `\\texport const ${name}: FormatRenderer`).join('\\n')\n\n\tconst defaultShape = exportNames.map(name => `${name}: FormatRenderer`).join('; ')\n\n\treturn [\n\t\t`declare module '${moduleAlias}' {`,\n\t\t'\\tinterface FormatAssetConfig {',\n\t\t'\\t\\tgetAssetsUrl(): string | undefined',\n\t\t'\\t\\tsetAssetsUrl(url: string): void',\n\t\t'\\t}',\n\t\t'',\n\t\t'\\tinterface FormatDocument {',\n\t\t'\\t\\thtml: string',\n\t\t'\\t\\tgetAssetsWebStream(): Promise<ReadableStream<Uint8Array> | undefined>',\n\t\t'\\t}',\n\t\t'',\n\t\t'\\tinterface FormatRenderer extends FormatAssetConfig {',\n\t\t'\\t\\trender(data?: Record<string, unknown>): Promise<FormatDocument>',\n\t\t'\\t\\tgetAssetsWebStream(): Promise<ReadableStream<Uint8Array> | undefined>',\n\t\t'\\t}',\n\t\t'',\n\t\tnamedExports,\n\t\t'',\n\t\t`\\tconst renderers: { ${defaultShape}; [key: string]: FormatRenderer }`,\n\t\t'\\texport default renderers',\n\t\t'}'\n\t].join('\\n')\n}\n\nfunction buildTypesSource(aliases: string[], documents: Array<{ exportName: string }>): string {\n\tconst modules = aliases.map(alias => buildTypesSourceForModule(alias, documents)).join('\\n\\n')\n\n\treturn `// Auto-generated by Format Studio — do not edit\\n${modules}\\n`\n}\n\nfunction patchReactDomServerImports(source: string): string {\n\tlet patched = source\n\n\tpatched = patched.replace(\n\t\t/import\\s*\\{([^}]+)\\}\\s*from\\s*[\"']react-dom\\/server[\"']\\s*;?/g,\n\t\t'const {$1} = await import(\"react-dom/server\");'\n\t)\n\n\tpatched = patched.replace(\n\t\t/import\\s*\\*\\s*as\\s+(\\w+)\\s+from\\s*[\"']react-dom\\/server[\"']\\s*;?/g,\n\t\t'const $1 = await import(\"react-dom/server\");'\n\t)\n\n\tpatched = patched.replace(\n\t\t/import\\s+(\\w+)\\s+from\\s*[\"']react-dom\\/server[\"']\\s*;?/g,\n\t\t'const { default: $1 } = await import(\"react-dom/server\");'\n\t)\n\n\treturn patched\n}\n\nasync function patchFile(filePath: string): Promise<void> {\n\tconst content = await readFile(filePath, 'utf-8')\n\tconst patched = patchReactDomServerImports(content)\n\n\tif (patched !== content) {\n\t\tawait writeFile(filePath, patched, 'utf-8')\n\t\tlogger.debug(`Patched react-dom/server imports in ${filePath}`)\n\t}\n}\n\nasync function patchCompiledBundles(outDir: string, documentNames: string[]): Promise<void> {\n\tfor (const documentName of documentNames) {\n\t\tawait patchFile(resolve(outDir, documentName, BUNDLE_ENTRY_POINT_FILE_NAME))\n\t}\n\n\t// Shared chunks can also contain react-dom/server imports (e.g. the engine chunk)\n\tconst chunksDir = resolve(outDir, 'chunks')\n\tconst chunkFiles = await readdir(chunksDir).catch(() => [] as string[])\n\n\tfor (const file of chunkFiles) {\n\t\tif (file.endsWith('.js')) {\n\t\t\tawait patchFile(resolve(chunksDir, file))\n\t\t}\n\t}\n}\n\nasync function compileTarget(\n\ttargetConfig: FormatTargetOptions,\n\toptions: FormatNextPluginOptions,\n\tconfig: FormatConfig,\n\toutDir: string,\n\tbundleName: string,\n\tdocumentNames: string[],\n\texportNames: Map<string, string>\n): Promise<TargetEntry> {\n\tconst resolved = resolveTargetOptions(options, targetConfig)\n\tconst suffix = TARGET_SUFFIXES[resolved.target]\n\tconst suffixedAlias = `@format:${bundleName}${suffix}`\n\tconst targetOutDir = resolve(outDir, resolved.target)\n\tconst assetMode: AssetMode = resolved.assets ?? 'static'\n\n\tlogger.info(`Compiling ${resolved.target} bundle. Documents: ${documentNames.join(', ')}`)\n\n\tconst assetState = new Map<string, DocumentAssetState>()\n\tawait compileForUnplugin(\n\t\t{\n\t\t\tdocuments: documentNames,\n\t\t\tassets: resolved.assets,\n\t\t\tvalidateSchema: resolved.validateSchema,\n\t\t\tinlineRemoteCss: resolved.inlineRemoteCss,\n\t\t\tbundle: resolved.bundle,\n\t\t\texternal: resolved.external,\n\t\t\ttarget: resolved.target,\n\t\t\tconfigPath: options.configPath,\n\t\t\toutDir: targetOutDir,\n\t\t\tbundleName,\n\t\t\tclean: false,\n\t\t\tuserBundler: 'webpack'\n\t\t},\n\t\t{ capturedAssetState: assetState }\n\t)\n\n\tawait patchCompiledBundles(targetOutDir, documentNames)\n\n\t// The generated entry lives outside the compiled outDir and is re-bundled\n\t// by Next.js, so all asset locations are baked as absolute file:// URLs.\n\t// Browser/edge consumers point at hosted assets with setAssetsUrl().\n\tconst compiledDocuments: EntryDocument[] = []\n\n\tfor (const name of documentNames) {\n\t\tconst init: EntryDocument['init'] = { knownAssets: [], assetUrls: null, assetsPath: null, assetsUrl: null }\n\n\t\tif (assetMode === 'static') {\n\t\t\tconst zipPath = resolve(targetOutDir, name, 'assets.zip')\n\t\t\tconst zipBuffer = await readFile(zipPath).catch(() => null)\n\n\t\t\tif (zipBuffer) {\n\t\t\t\tinit.knownAssets = listZipEntries(new Uint8Array(zipBuffer))\n\t\t\t\tinit.assetsUrl = pathToFileURL(zipPath).href\n\t\t\t}\n\t\t} else if (assetMode === 'dynamic') {\n\t\t\tconst compiledUrlMap = assetState.get(name)?.urlMap ?? {}\n\t\t\tconst entries = dynamicAssetEmitEntries({\n\t\t\t\toutDir: targetOutDir,\n\t\t\t\tdocumentName: name,\n\t\t\t\turlMap: compiledUrlMap\n\t\t\t})\n\n\t\t\tconst urlMap: Record<string, string> = {}\n\t\t\tfor (const entry of entries) {\n\t\t\t\turlMap[entry.knownPath] = pathToFileURL(entry.sourcePath).href\n\t\t\t}\n\n\t\t\tinit.assetUrls = urlMap\n\t\t\tinit.knownAssets = Object.keys(urlMap).sort()\n\t\t}\n\n\t\tcompiledDocuments.push({ documentName: name, exportName: exportNames.get(name)!, init })\n\t}\n\n\tconst entryFileName = getEntryFileName(resolved.target)\n\tconst rendererRelativePath = `./${resolved.target}/${BUNDLE_ENTRY_POINT_FILE_NAME}`\n\tconst entrySource = buildEntrySource(resolved.target, assetMode, rendererRelativePath, compiledDocuments)\n\tconst entryPath = resolve(outDir, entryFileName)\n\tawait writeFile(entryPath, entrySource, 'utf-8')\n\n\tlogger.debug(`Generated Next.js entry module for ${resolved.target} at ${entryPath}`)\n\n\treturn { target: resolved.target, suffix, aliasKeys: [suffixedAlias], entryPath }\n}\n\nexport async function generateEntry(\n\tconfig: FormatConfig,\n\toptions: FormatNextPluginOptions\n): Promise<GenerateEntryResult> {\n\tconst bundleName = resolveBundleName(options.bundleName)\n\tconst outDir = getBundleOutDir(config, options.outDir)\n\tconst targets = options.targets ?? [{ target: 'node' }]\n\n\tconst documents = await getDocuments(config)\n\tconst documentNames = documents.map(doc => doc.name).sort((a, b) => a.localeCompare(b))\n\n\tif (documentNames.length === 0) {\n\t\tthrow new Error('No documents found to compile.')\n\t}\n\n\tconst exportNames = buildDocumentExportMap(documentNames)\n\n\t// Check cache — skip compilation if documents + options haven't changed\n\tconst documentsDir = getDocumentsDir(config)\n\tconst currentHash = await computeCacheHash(documentsDir, options)\n\tconst cachedHash = await readCachedHash(outDir)\n\n\tif (cachedHash === currentHash) {\n\t\tlogger.info('Cache hit. Skipping compile.')\n\n\t\tconst entries: TargetEntry[] = targets.map((targetConfig, index) => {\n\t\t\tconst resolved = resolveTargetOptions(options, targetConfig)\n\t\t\tconst suffix = TARGET_SUFFIXES[resolved.target]\n\t\t\tconst suffixedAlias = `@format:${bundleName}${suffix}`\n\t\t\tconst entryFileName = getEntryFileName(resolved.target)\n\t\t\tconst entryPath = resolve(outDir, entryFileName)\n\n\t\t\tconst aliasKeys = index === 0 ? [`@format:${bundleName}`, suffixedAlias] : [suffixedAlias]\n\n\t\t\treturn { target: resolved.target, suffix, aliasKeys, entryPath }\n\t\t})\n\n\t\treturn { entries, outDir }\n\t}\n\n\tlogger.debug(`Cache miss. Compiling ${targets.length} target(s)`)\n\n\tif (options.clean !== false) {\n\t\tconst { rm } = await import('node:fs/promises')\n\t\tawait rm(outDir, { recursive: true, force: true }).catch(() => {})\n\t}\n\n\tawait mkdir(outDir, { recursive: true })\n\n\tconst suppressRolldownLogs = (_level: string, ...args: unknown[]) => {\n\t\tconst msg = args.join(' ')\n\n\t\tif (msg.includes('vite v') && msg.includes('building')) return false\n\t\tif (msg.includes('built in')) return false\n\n\t\treturn true\n\t}\n\n\t// Compile all targets in parallel, suppressing rolldown's stdout noise\n\tconst entries = (await withPrefixedConsole(\n\t\t() =>\n\t\t\tPromise.all(\n\t\t\t\ttargets.map(targetConfig =>\n\t\t\t\t\tcompileTarget(targetConfig, options, config, outDir, bundleName, documentNames, exportNames)\n\t\t\t\t)\n\t\t\t),\n\t\tsuppressRolldownLogs\n\t)) as TargetEntry[]\n\n\t// First target also gets the base alias (format:<bundleName>)\n\tconst baseAlias = `@format:${bundleName}`\n\tentries[0].aliasKeys = [baseAlias, ...entries[0].aliasKeys]\n\n\tconst allAliases = entries.flatMap(e => e.aliasKeys)\n\tconst documentsForTypes = documentNames.map(name => ({\n\t\texportName: exportNames.get(name)!\n\t}))\n\n\tconst typesSource = buildTypesSource(allAliases, documentsForTypes)\n\tconst typesPath = resolve(outDir, 'types.d.ts')\n\tawait writeFile(typesPath, typesSource, 'utf-8')\n\n\t// Write the project's format-env.d.ts — the same file init seeds and every\n\t// bundler plugin regenerates, so document imports are strongly typed.\n\tawait writeFormatEnvTypes({\n\t\tprojectRoot: process.cwd(),\n\t\taliases: allAliases,\n\t\tdocuments: documentsForTypes\n\t})\n\n\tawait writeCacheHash(outDir, currentHash)\n\n\treturn { entries, outDir }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,MAAMA,kBAA0C;CAC/C,MAAM;CACN,SAAS;CACT,QAAQ;CACR;AAuBD,SAAS,qBAAqB,QAAiC,QAAoD;AAClH,QAAO;EACN,QAAQ,OAAO;EACf,QAAQ,OAAO,UAAU,OAAO,UAAU;EAC1C,iBAAiB,OAAO,mBAAmB,OAAO,mBAAmB;EACrE,gBAAgB,OAAO,kBAAkB,OAAO,kBAAkB;EAClE,QAAQ,OAAO,UAAU,EAAE;EAC3B,UAAU,OAAO,YAAY,EAAE;EAC/B;;AAGF,SAAS,iBAAiB,QAAwB;AACjD,QAAO,eAAe,OAAO;;AAc9B,SAAS,iBACR,QACA,WACA,sBACA,WACS;CACT,MAAM,aAAa,UAAU,KAAI,QAAO,IAAI,WAAW,CAAC,KAAK,KAAK;CAElE,MAAM,UAAU,0BAA0B;EACzC,MAAM;EACN;EACA,eAAe,qBAAq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,MAAM,aAAa,QAAQ,SAAQ,MAAK,EAAE,UAAU;CACpD,MAAM,oBAAoB,cAAc,KAAI,UAAS,EACpD,YAAY,YAAY,IAAI,KAAK,EACjC,EAAE;CAEH,MAAM,cAAc,iBAAiB,YAAY,kBAAkB;AAEnE,OAAM,UADY,QAAQ,QAAQ,aAAa,EACpB,aAAa,QAAQ;AAIhD,OAAM,oBAAoB;EACzB,aAAa,QAAQ,KAAK;EAC1B,SAAS;EACT,WAAW;EACX,CAAC;AAEF,OAAM,eAAe,QAAQ,YAAY;AAEzC,QAAO;EAAE;EAAS;EAAQ"}
@@ -0,0 +1,8 @@
1
+ import { FormatRenderer } from "../../../shared/types/public/renderer.mjs";
2
+ import { FormatNextPluginOptions, FormatTargetOptions } from "../../../shared/types/public/nextjs.mjs";
3
+
4
+ //#region src/server/integrations/nextjs/index.d.ts
5
+ declare function withFormat(formatOptions?: FormatNextPluginOptions): (nextConfig?: any) => Promise<any>;
6
+ //#endregion
7
+ export { type FormatNextPluginOptions, type FormatRenderer, type FormatTargetOptions, withFormat as default };
8
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../src/server/integrations/nextjs/index.ts"],"sourcesContent":[],"mappings":";;;;iBAyCwB,UAAA,iBAA0B,gDAAqD"}
@@ -0,0 +1,90 @@
1
+ import { logger, setLogLevel } from "../../utils/log.mjs";
2
+ import { parseLogLevelFromEnv } from "../../utils/env-var.mjs";
3
+ import { loadConfig } from "../../utils/load-config.mjs";
4
+ import { resolveBundleName } from "../../compile/bundle-name.mjs";
5
+ import { generateEntry } from "./generate-entry.mjs";
6
+ import { startWatcher } from "./watcher.mjs";
7
+ import { relative, resolve } from "node:path";
8
+ import { readFile } from "node:fs/promises";
9
+
10
+ //#region src/server/integrations/nextjs/index.ts
11
+ async function readExternals(outDir, targets) {
12
+ const allExternals = /* @__PURE__ */ new Set();
13
+ for (const target of targets) {
14
+ if (target !== "node") continue;
15
+ const externalsPath = resolve(outDir, target, "externals.json");
16
+ try {
17
+ const raw = await readFile(externalsPath, "utf-8");
18
+ const parsed = JSON.parse(raw);
19
+ for (const pkg of parsed.externals ?? []) allExternals.add(pkg);
20
+ } catch {}
21
+ }
22
+ return [...allExternals];
23
+ }
24
+ let entryPromise = null;
25
+ let watcherStarted = false;
26
+ function withFormat(formatOptions = {}) {
27
+ return async (nextConfig = {}) => {
28
+ setLogLevel(parseLogLevelFromEnv());
29
+ const bundleName = resolveBundleName(formatOptions.bundleName);
30
+ logger.debug(`withFormat initializing (bundle: format:${bundleName})`);
31
+ const { config } = await loadConfig(formatOptions.configPath);
32
+ if (!entryPromise) entryPromise = generateEntry(config, formatOptions);
33
+ const { entries, outDir } = await entryPromise;
34
+ if (!watcherStarted) {
35
+ watcherStarted = true;
36
+ startWatcher(config, formatOptions);
37
+ }
38
+ const projectRoot = process.cwd();
39
+ const relativeOutDir = `./${relative(projectRoot, outDir).replace(/\\/g, "/")}`;
40
+ const webpackAliases = {};
41
+ const turbopackAliases = {};
42
+ for (const entry of entries) {
43
+ const relativePath = `./${relative(projectRoot, entry.entryPath).replace(/\\/g, "/")}`;
44
+ for (const alias of entry.aliasKeys) {
45
+ webpackAliases[alias] = entry.entryPath;
46
+ turbopackAliases[alias] = relativePath;
47
+ }
48
+ }
49
+ const detectedExternals = await readExternals(outDir, entries.map((e) => e.target));
50
+ const nextManagedPackages = new Set(["react", "react-dom"]);
51
+ const safeExternals = detectedExternals.filter((pkg) => !nextManagedPackages.has(pkg));
52
+ const existingWebpack = nextConfig.webpack;
53
+ return {
54
+ ...nextConfig,
55
+ webpack(webpackConfig, webpackContext) {
56
+ const resolveConfig = webpackConfig.resolve ?? {};
57
+ const existingAlias = resolveConfig.alias ?? {};
58
+ webpackConfig.resolve = {
59
+ ...resolveConfig,
60
+ alias: {
61
+ ...existingAlias,
62
+ ...webpackAliases
63
+ }
64
+ };
65
+ if (existingWebpack) return existingWebpack(webpackConfig, webpackContext);
66
+ return webpackConfig;
67
+ },
68
+ turbopack: {
69
+ ...nextConfig.turbopack ?? {},
70
+ resolveAlias: {
71
+ ...nextConfig.turbopack?.resolveAlias ?? {},
72
+ ...turbopackAliases
73
+ }
74
+ },
75
+ serverExternalPackages: [
76
+ ...nextConfig.serverExternalPackages ?? [],
77
+ "@format.dev/compile",
78
+ ...safeExternals
79
+ ],
80
+ outputFileTracingIncludes: {
81
+ ...nextConfig.outputFileTracingIncludes ?? {},
82
+ "/**": [`${relativeOutDir}/**/*`]
83
+ }
84
+ };
85
+ };
86
+ }
87
+
88
+ //#endregion
89
+ export { withFormat as default };
90
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["entryPromise: Promise<GenerateEntryResult> | null","webpackAliases: Record<string, string>","turbopackAliases: Record<string, string>"],"sources":["../../../../src/server/integrations/nextjs/index.ts"],"sourcesContent":["export type { FormatNextPluginOptions, FormatTargetOptions, FormatRenderer } from '../../../shared/types/public/nextjs'\nimport type { FormatNextPluginOptions } from '../../../shared/types/public/nextjs'\n\nimport { resolve, relative } from 'node:path'\nimport { readFile } from 'node:fs/promises'\nimport { loadConfig } from '../../utils/load-config'\nimport { resolveBundleName } from '../../compile/bundle-name'\nimport { generateEntry, type GenerateEntryResult } from './generate-entry'\nimport { startWatcher } from './watcher'\nimport { logger, setLogLevel } from '../../utils/log'\nimport { parseLogLevelFromEnv } from '../../utils/env-var'\n\nasync function readExternals(outDir: string, targets: string[]): Promise<string[]> {\n\tconst allExternals = new Set<string>()\n\n\tfor (const target of targets) {\n\t\tif (target !== 'node') {\n\t\t\tcontinue\n\t\t}\n\n\t\tconst externalsPath = resolve(outDir, target, 'externals.json')\n\n\t\ttry {\n\t\t\tconst raw = await readFile(externalsPath, 'utf-8')\n\t\t\tconst parsed = JSON.parse(raw) as { externals?: string[] }\n\n\t\t\tfor (const pkg of parsed.externals ?? []) {\n\t\t\t\tallExternals.add(pkg)\n\t\t\t}\n\t\t} catch {\n\t\t\t// externals.json may not exist yet on first build\n\t\t}\n\t}\n\n\treturn [...allExternals]\n}\n\nlet entryPromise: Promise<GenerateEntryResult> | null = null\nlet watcherStarted = false\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function withFormat(formatOptions: FormatNextPluginOptions = {}): (nextConfig?: any) => Promise<any> {\n\treturn async (nextConfig: any = {}) => {\n\t\tsetLogLevel(parseLogLevelFromEnv())\n\n\t\tconst bundleName = resolveBundleName(formatOptions.bundleName)\n\n\t\tlogger.debug(`withFormat initializing (bundle: format:${bundleName})`)\n\n\t\tconst { config } = await loadConfig(formatOptions.configPath)\n\n\t\tif (!entryPromise) {\n\t\t\tentryPromise = generateEntry(config, formatOptions)\n\t\t}\n\n\t\tconst { entries, outDir } = await entryPromise\n\n\t\tconst isDev = process.env.NODE_ENV !== 'production'\n\n\t\tif (isDev && !watcherStarted) {\n\t\t\twatcherStarted = true\n\t\t\tstartWatcher(config, formatOptions)\n\t\t}\n\n\t\tconst projectRoot = process.cwd()\n\t\tconst relativeOutDir = `./${relative(projectRoot, outDir).replace(/\\\\/g, '/')}`\n\n\t\tconst webpackAliases: Record<string, string> = {}\n\t\tconst turbopackAliases: Record<string, string> = {}\n\n\t\tfor (const entry of entries) {\n\t\t\tconst relativePath = `./${relative(projectRoot, entry.entryPath).replace(/\\\\/g, '/')}`\n\n\t\t\tfor (const alias of entry.aliasKeys) {\n\t\t\t\twebpackAliases[alias] = entry.entryPath\n\t\t\t\tturbopackAliases[alias] = relativePath\n\t\t\t}\n\t\t}\n\n\t\tconst targetNames = entries.map(e => e.target)\n\t\tconst detectedExternals = await readExternals(outDir, targetNames)\n\n\t\t// Next.js manages React resolution internally (server builds, RSC layers, etc).\n\t\t// Adding react/react-dom to serverExternalPackages bypasses that and breaks hooks.\n\t\tconst nextManagedPackages = new Set(['react', 'react-dom'])\n\t\tconst safeExternals = detectedExternals.filter(pkg => !nextManagedPackages.has(pkg))\n\n\t\tconst existingWebpack = nextConfig.webpack as ((...args: unknown[]) => unknown) | undefined\n\n\t\treturn {\n\t\t\t...nextConfig,\n\n\t\t\twebpack(webpackConfig: Record<string, unknown>, webpackContext: unknown) {\n\t\t\t\tconst resolveConfig = (webpackConfig.resolve ?? {}) as Record<string, unknown>\n\t\t\t\tconst existingAlias = (resolveConfig.alias ?? {}) as Record<string, string>\n\n\t\t\t\twebpackConfig.resolve = {\n\t\t\t\t\t...resolveConfig,\n\t\t\t\t\talias: {\n\t\t\t\t\t\t...existingAlias,\n\t\t\t\t\t\t...webpackAliases\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (existingWebpack) {\n\t\t\t\t\treturn existingWebpack(webpackConfig, webpackContext)\n\t\t\t\t}\n\n\t\t\t\treturn webpackConfig\n\t\t\t},\n\n\t\t\tturbopack: {\n\t\t\t\t...(nextConfig.turbopack ?? {}),\n\t\t\t\tresolveAlias: {\n\t\t\t\t\t...(nextConfig.turbopack?.resolveAlias ?? {}),\n\t\t\t\t\t...turbopackAliases\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tserverExternalPackages: [...(nextConfig.serverExternalPackages ?? []), '@format.dev/compile', ...safeExternals],\n\n\t\t\toutputFileTracingIncludes: {\n\t\t\t\t...(nextConfig.outputFileTracingIncludes ?? {}),\n\t\t\t\t'/**': [`${relativeOutDir}/**/*`]\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;AAYA,eAAe,cAAc,QAAgB,SAAsC;CAClF,MAAM,+BAAe,IAAI,KAAa;AAEtC,MAAK,MAAM,UAAU,SAAS;AAC7B,MAAI,WAAW,OACd;EAGD,MAAM,gBAAgB,QAAQ,QAAQ,QAAQ,iBAAiB;AAE/D,MAAI;GACH,MAAM,MAAM,MAAM,SAAS,eAAe,QAAQ;GAClD,MAAM,SAAS,KAAK,MAAM,IAAI;AAE9B,QAAK,MAAM,OAAO,OAAO,aAAa,EAAE,CACvC,cAAa,IAAI,IAAI;UAEf;;AAKT,QAAO,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H,GAAG;MACH;KACD;AAED,QAAI,gBACH,QAAO,gBAAgB,eAAe,eAAe;AAGtD,WAAO;;GAGR,WAAW;IACV,GAAI,WAAW,aAAa,EAAE;IAC9B,cAAc;KACb,GAAI,WAAW,WAAW,gBAAgB,EAAE;KAC5C,GAAG;KACH;IACD;GAED,wBAAwB;IAAC,GAAI,WAAW,0BAA0B,EAAE;IAAG;IAAuB,GAAG;IAAc;GAE/G,2BAA2B;IAC1B,GAAI,WAAW,6BAA6B,EAAE;IAC9C,OAAO,CAAC,GAAG,eAAe,OAAO;IACjC;GACD"}
@@ -0,0 +1,9 @@
1
+ import { FormatConfig } from "../../../shared/types/public/config.mjs";
2
+ import { FormatNextPluginOptions } from "../../../shared/types/public/nextjs.mjs";
3
+ import { FSWatcher } from "node:fs";
4
+
5
+ //#region src/server/integrations/nextjs/watcher.d.ts
6
+ declare function startWatcher(config: FormatConfig, options: FormatNextPluginOptions): FSWatcher;
7
+ //#endregion
8
+ export { startWatcher };
9
+ //# sourceMappingURL=watcher.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watcher.d.mts","names":[],"sources":["../../../../src/server/integrations/nextjs/watcher.ts"],"sourcesContent":[],"mappings":";;;;;iBAUgB,YAAA,SAAqB,uBAAuB,0BAA0B"}
@@ -0,0 +1,45 @@
1
+ import { getDocumentsDir } from "../../project/paths.mjs";
2
+ import { logger } from "../../utils/log.mjs";
3
+ import { generateEntry } from "./generate-entry.mjs";
4
+ import { watch } from "node:fs";
5
+
6
+ //#region src/server/integrations/nextjs/watcher.ts
7
+ const DEBOUNCE_MS = 1500;
8
+ function startWatcher(config, options) {
9
+ const documentsDir = getDocumentsDir(config);
10
+ let debounceTimer = null;
11
+ let isRecompiling = false;
12
+ const recompile = async () => {
13
+ if (isRecompiling) return;
14
+ isRecompiling = true;
15
+ try {
16
+ logger.info("Document changed. Recompiling started...");
17
+ await generateEntry(config, {
18
+ ...options,
19
+ clean: false
20
+ });
21
+ logger.info("Recompile completed. Bundles are ready.");
22
+ } catch (error) {
23
+ logger.error("Recompile failed.", error);
24
+ } finally {
25
+ isRecompiling = false;
26
+ }
27
+ };
28
+ const watcher = watch(documentsDir, { recursive: true }, (_event, filename) => {
29
+ if (!filename) return;
30
+ if (debounceTimer) clearTimeout(debounceTimer);
31
+ debounceTimer = setTimeout(recompile, DEBOUNCE_MS);
32
+ });
33
+ const cleanup = () => {
34
+ watcher.close();
35
+ if (debounceTimer) clearTimeout(debounceTimer);
36
+ };
37
+ process.once("SIGINT", cleanup);
38
+ process.once("SIGTERM", cleanup);
39
+ logger.debug(`Watching ${documentsDir} for document changes`);
40
+ return watcher;
41
+ }
42
+
43
+ //#endregion
44
+ export { startWatcher };
45
+ //# sourceMappingURL=watcher.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watcher.mjs","names":["debounceTimer: ReturnType<typeof setTimeout> | null"],"sources":["../../../../src/server/integrations/nextjs/watcher.ts"],"sourcesContent":["import type { FormatConfig } from '../../../shared/types'\nimport type { FormatNextPluginOptions } from '../../../shared/types/public/nextjs'\n\nimport { watch, type FSWatcher } from 'node:fs'\nimport { generateEntry } from './generate-entry'\nimport { logger } from '../../utils/log'\nimport { getDocumentsDir } from '../../project/paths'\n\nconst DEBOUNCE_MS = 1500\n\nexport function startWatcher(config: FormatConfig, options: FormatNextPluginOptions): FSWatcher {\n\tconst documentsDir = getDocumentsDir(config)\n\tlet debounceTimer: ReturnType<typeof setTimeout> | null = null\n\tlet isRecompiling = false\n\n\tconst recompile = async () => {\n\t\tif (isRecompiling) {\n\t\t\treturn\n\t\t}\n\n\t\tisRecompiling = true\n\n\t\ttry {\n\t\t\tlogger.info('Document changed. Recompiling started...')\n\t\t\tawait generateEntry(config, { ...options, clean: false })\n\t\t\tlogger.info('Recompile completed. Bundles are ready.')\n\t\t} catch (error) {\n\t\t\tlogger.error('Recompile failed.', error)\n\t\t} finally {\n\t\t\tisRecompiling = false\n\t\t}\n\t}\n\n\tconst watcher = watch(documentsDir, { recursive: true }, (_event, filename) => {\n\t\tif (!filename) {\n\t\t\treturn\n\t\t}\n\n\t\tif (debounceTimer) {\n\t\t\tclearTimeout(debounceTimer)\n\t\t}\n\n\t\tdebounceTimer = setTimeout(recompile, DEBOUNCE_MS)\n\t})\n\n\tconst cleanup = () => {\n\t\twatcher.close()\n\n\t\tif (debounceTimer) {\n\t\t\tclearTimeout(debounceTimer)\n\t\t}\n\t}\n\n\tprocess.once('SIGINT', cleanup)\n\tprocess.once('SIGTERM', cleanup)\n\n\tlogger.debug(`Watching ${documentsDir} for document changes`)\n\n\treturn watcher\n}\n"],"mappings":";;;;;;AAQA,MAAM,cAAc;AAEpB,SAAgB,aAAa,QAAsB,SAA6C;CAC/F,MAAM,eAAe,gBAAgB,OAAO;CAC5C,IAAIA,gBAAsD;CAC1D,IAAI,gBAAgB;CAEpB,MAAM,YAAY,YAAY;AAC7B,MAAI,cACH;AAGD,kBAAgB;AAEhB,MAAI;AACH,UAAO,KAAK,2CAA2C;AACvD,SAAM,cAAc,QAAQ;IAAE,GAAG;IAAS,OAAO;IAAO,CAAC;AACzD,UAAO,KAAK,0CAA0C;WAC9C,OAAO;AACf,UAAO,MAAM,qBAAqB,MAAM;YAC/B;AACT,mBAAgB;;;CAIlB,MAAM,UAAU,MAAM,cAAc,EAAE,WAAW,MAAM,GAAG,QAAQ,aAAa;AAC9E,MAAI,CAAC,SACJ;AAGD,MAAI,cACH,cAAa,cAAc;AAG5B,kBAAgB,WAAW,WAAW,YAAY;GACjD;CAEF,MAAM,gBAAgB;AACrB,UAAQ,OAAO;AAEf,MAAI,cACH,cAAa,cAAc;;AAI7B,SAAQ,KAAK,UAAU,QAAQ;AAC/B,SAAQ,KAAK,WAAW,QAAQ;AAEhC,QAAO,MAAM,YAAY,aAAa,uBAAuB;AAE7D,QAAO"}
@@ -0,0 +1,2 @@
1
+ import { formatEsbuildPlugin } from "./index.mjs";
2
+ export { formatEsbuildPlugin as default };
@@ -0,0 +1,3 @@
1
+ import { formatEsbuildPlugin } from "./index.mjs";
2
+
3
+ export { formatEsbuildPlugin as default };
@@ -0,0 +1,69 @@
1
+ import { FormatConfig } from "../../../shared/types/public/config.mjs";
2
+ import { Target } from "../../../shared/types/public/compile.mjs";
3
+ import { FormatUnpluginOptions } from "../../../shared/types/public/unplugin.mjs";
4
+ import { DocumentAssetState } from "../../compile/compile.mjs";
5
+ import * as vite5 from "vite";
6
+ import * as unplugin0 from "unplugin";
7
+
8
+ //#region src/server/integrations/unplugin/index.d.ts
9
+ interface CompiledDocument {
10
+ documentName: string;
11
+ exportName: string;
12
+ assetsPath: string | null;
13
+ hash: string;
14
+ }
15
+ interface CompiledBundle {
16
+ outDir: string;
17
+ hash: string;
18
+ compiledAt: number;
19
+ /** Each document's compiled asset state, keyed by name. Empty for static/none. */
20
+ assetState: Map<string, DocumentAssetState>;
21
+ }
22
+ declare function buildRendererModuleSource(outDir: string, documents: CompiledDocument[]): string;
23
+ type Bundler = 'vite' | 'rollup' | 'esbuild' | 'webpack' | 'rspack';
24
+ interface EmitAssetFileArgs {
25
+ emitFile: (asset: {
26
+ type: 'asset';
27
+ fileName: string;
28
+ source: Buffer;
29
+ }) => void;
30
+ buffer: Buffer;
31
+ relName: string;
32
+ outRoot: string;
33
+ assetsSubdir: string;
34
+ emittedAssetNames: Set<string>;
35
+ bundler: Bundler;
36
+ }
37
+ /**
38
+ * Emit one asset file into the consumer's bundle output. Returns the emitted
39
+ * path relative to the bundler's out dir, or the already-emitted path when a
40
+ * previous document emitted the same file (shared `_imported/` files, fonts).
41
+ */
42
+ declare function emitAssetFile(args: EmitAssetFileArgs): Promise<string>;
43
+ interface BuildVirtualModuleArgs {
44
+ target: Target;
45
+ useZeroPrefix: boolean;
46
+ options: FormatUnpluginOptions;
47
+ config: FormatConfig;
48
+ compiledDocuments: Map<string, CompiledDocument>;
49
+ compiledBundle: CompiledBundle | null;
50
+ rendererSourceMap: Map<string, string>;
51
+ outRoot?: string;
52
+ assetsSubdir?: string;
53
+ emittedAssetNames: Set<string>;
54
+ bundler: Bundler;
55
+ virtualModuleName: string;
56
+ emitFile: (x: any) => void;
57
+ isDevServer: boolean;
58
+ bundleName: string;
59
+ }
60
+ declare function buildVirtualModuleCode(args: BuildVirtualModuleArgs): Promise<string | null>;
61
+ declare const universalBundlerPlugin: unplugin0.UnpluginInstance<FormatUnpluginOptions, boolean>;
62
+ declare const formatVitePlugin: (options: FormatUnpluginOptions) => vite5.Plugin<any> | vite5.Plugin<any>[];
63
+ declare const formatRollupPlugin: (options: FormatUnpluginOptions) => any;
64
+ declare const formatRolldownPlugin: (options: FormatUnpluginOptions) => any;
65
+ declare const formatWebpackPlugin: (options: FormatUnpluginOptions) => WebpackPluginInstance;
66
+ declare const formatEsbuildPlugin: (options: FormatUnpluginOptions) => unplugin0.EsbuildPlugin;
67
+ //#endregion
68
+ export { BuildVirtualModuleArgs, CompiledBundle, CompiledDocument, EmitAssetFileArgs, buildRendererModuleSource, buildVirtualModuleCode, emitAssetFile, formatEsbuildPlugin, formatRolldownPlugin, formatRollupPlugin, formatVitePlugin, formatWebpackPlugin, universalBundlerPlugin };
69
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../src/server/integrations/unplugin/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;UA6BiB,gBAAA;;;;;AAAjB;AAWiB,UAAA,cAAA,CAAc;EA2Bf,MAAA,EAAA,MAAA;EAuCX,IAAA,EAAA,MAAO;EA+FK,UAAA,EAAA,MAAA;EAC6C;EACrD,UAAA,EA9JI,GA8JJ,CAAA,MAAA,EA9JgB,kBA8JhB,CAAA;;AAKC,iBA7IM,yBAAA,CA6IN,MAAA,EAAA,MAAA,EAAA,SAAA,EA7I2D,gBA6I3D,EAAA,CAAA,EAAA,MAAA;KAtGL,OAAA,GAsGY,MAAA,GAAA,QAAA,GAAA,SAAA,GAAA,SAAA,GAAA,QAAA;AAQK,UAfL,iBAAA,CAeyB;E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