@pikku/cli 0.12.54 → 0.12.56

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 (267) hide show
  1. package/cli.schema.json +1 -1
  2. package/console-app/assets/{index-DYnbceYg.js → index-xN8LW0II.js} +155 -155
  3. package/console-app/index.html +1 -1
  4. package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +1 -1
  5. package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +3 -3
  6. package/dist/.pikku/channel/pikku-channel-types.gen.js +1 -1
  7. package/dist/.pikku/cli/pikku-cli-channel.d.ts +6 -6
  8. package/dist/.pikku/cli/pikku-cli-channel.js +11 -1
  9. package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +1 -1
  10. package/dist/.pikku/cli/pikku-cli-client.gen.js +1 -1
  11. package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.d.ts +1 -1
  12. package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.js +1 -1
  13. package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.json +14 -0
  14. package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +1 -1
  15. package/dist/.pikku/cli/pikku-cli-types.gen.js +1 -1
  16. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +1 -1
  17. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.json +29 -0
  18. package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +1 -1
  19. package/dist/.pikku/cli/pikku-cli-wirings.gen.js +1 -1
  20. package/dist/.pikku/cli/pikku-cli.gen.d.ts +1 -1
  21. package/dist/.pikku/cli/pikku-cli.gen.js +1 -1
  22. package/dist/.pikku/console/pikku-node-types.gen.d.ts +1 -1
  23. package/dist/.pikku/function/pikku-function-types.gen.d.ts +8 -31
  24. package/dist/.pikku/function/pikku-function-types.gen.js +1 -1
  25. package/dist/.pikku/function/pikku-functions-meta.gen.js +1 -1
  26. package/dist/.pikku/function/pikku-functions-meta.gen.json +1420 -1384
  27. package/dist/.pikku/function/pikku-functions.gen.js +3 -1
  28. package/dist/.pikku/http/pikku-http-types.gen.d.ts +1 -1
  29. package/dist/.pikku/http/pikku-http-types.gen.js +1 -1
  30. package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +1 -1
  31. package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +1 -1
  32. package/dist/.pikku/http/pikku-http-wirings.gen.js +1 -1
  33. package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +1 -1
  34. package/dist/.pikku/mcp/pikku-mcp-types.gen.js +1 -1
  35. package/dist/.pikku/pikku-bootstrap.gen.d.ts +1 -1
  36. package/dist/.pikku/pikku-bootstrap.gen.js +1 -1
  37. package/dist/.pikku/pikku-meta-service.gen.d.ts +1 -1
  38. package/dist/.pikku/pikku-meta-service.gen.js +1 -1
  39. package/dist/.pikku/pikku-services.gen.d.ts +4 -2
  40. package/dist/.pikku/pikku-services.gen.js +2 -0
  41. package/dist/.pikku/pikku-types.gen.d.ts +1 -1
  42. package/dist/.pikku/pikku-types.gen.js +1 -1
  43. package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -1
  44. package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -1
  45. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +1 -1
  46. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.json +0 -248
  47. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +1 -1
  48. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +1 -1
  49. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +1 -1
  50. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.json +69 -67
  51. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -1
  52. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -1
  53. package/dist/.pikku/schemas/register.gen.js +191 -185
  54. package/dist/.pikku/schemas/schemas/FabricAddonVerifyInput.schema.json +1 -0
  55. package/dist/.pikku/schemas/schemas/FabricAddonVerifyOutput.schema.json +1 -0
  56. package/dist/.pikku/schemas/schemas/PikkuAuthInput.schema.json +1 -0
  57. package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
  58. package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +1 -1
  59. package/dist/.pikku/secrets/pikku-secret-types.gen.js +1 -1
  60. package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +1 -1
  61. package/dist/.pikku/secrets/pikku-secrets.gen.js +1 -1
  62. package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +1 -1
  63. package/dist/.pikku/trigger/pikku-trigger-types.gen.js +1 -1
  64. package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +1 -1
  65. package/dist/.pikku/variables/pikku-variable-types.gen.js +1 -1
  66. package/dist/.pikku/variables/pikku-variables.gen.d.ts +1 -1
  67. package/dist/.pikku/variables/pikku-variables.gen.js +1 -1
  68. package/dist/.pikku/workflow/meta/allWorkflow.gen.json +9 -3
  69. package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +1 -1
  70. package/dist/.pikku/workflow/pikku-workflow-types.gen.js +1 -1
  71. package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +1 -1
  72. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -1
  73. package/dist/bin/pikku-bin.mjs +2 -2
  74. package/dist/src/cli.wiring.js +15 -1
  75. package/dist/src/deploy/analyzer/analyzer.d.ts +6 -0
  76. package/dist/src/deploy/analyzer/analyzer.js +5 -4
  77. package/dist/src/deploy/build-pipeline.d.ts +5 -1
  78. package/dist/src/deploy/build-pipeline.js +5 -5
  79. package/dist/src/deploy/bundler/bun-bundler.d.ts +14 -0
  80. package/dist/src/deploy/bundler/bun-bundler.js +121 -0
  81. package/dist/src/deploy/bundler/bundler.d.ts +25 -30
  82. package/dist/src/deploy/bundler/bundler.interface.d.ts +54 -0
  83. package/dist/src/deploy/bundler/bundler.interface.js +11 -0
  84. package/dist/src/deploy/bundler/bundler.js +120 -190
  85. package/dist/src/deploy/bundler/dep-extractor.d.ts +11 -3
  86. package/dist/src/deploy/bundler/dep-extractor.js +12 -6
  87. package/dist/src/deploy/bundler/index.d.ts +5 -2
  88. package/dist/src/deploy/bundler/index.js +4 -2
  89. package/dist/src/deploy/bundler/node-bundler.d.ts +13 -0
  90. package/dist/src/deploy/bundler/node-bundler.js +80 -0
  91. package/dist/src/deploy/provider-adapter.d.ts +11 -0
  92. package/dist/src/deploy/server-entry.js +3 -1
  93. package/dist/src/fabric/fabric-commands.d.ts +109 -72
  94. package/dist/src/fabric/fabric-commands.js +8 -0
  95. package/dist/src/fabric/functions/add.function.d.ts +3 -3
  96. package/dist/src/fabric/functions/addon-verify.function.d.ts +54 -0
  97. package/dist/src/fabric/functions/addon-verify.function.js +153 -0
  98. package/dist/src/fabric/functions/db-schema.function.d.ts +3 -3
  99. package/dist/src/fabric/functions/deploy-list.function.d.ts +3 -3
  100. package/dist/src/fabric/functions/deploy-units.function.d.ts +3 -3
  101. package/dist/src/fabric/functions/deploy.function.d.ts +6 -6
  102. package/dist/src/fabric/functions/domains-add.function.d.ts +3 -3
  103. package/dist/src/fabric/functions/domains-list.function.d.ts +3 -3
  104. package/dist/src/fabric/functions/domains-remove.function.d.ts +3 -3
  105. package/dist/src/fabric/functions/errors.function.d.ts +3 -3
  106. package/dist/src/fabric/functions/init.function.d.ts +3 -3
  107. package/dist/src/fabric/functions/link.function.d.ts +3 -3
  108. package/dist/src/fabric/functions/llm-key.function.d.ts +3 -3
  109. package/dist/src/fabric/functions/llm-key.function.js +1 -1
  110. package/dist/src/fabric/functions/login.function.d.ts +3 -3
  111. package/dist/src/fabric/functions/logs.function.d.ts +3 -3
  112. package/dist/src/fabric/functions/metrics.function.d.ts +3 -3
  113. package/dist/src/fabric/functions/publish.function.d.ts +3 -3
  114. package/dist/src/fabric/functions/publish.function.js +8 -3
  115. package/dist/src/fabric/functions/rollback.function.d.ts +3 -3
  116. package/dist/src/fabric/functions/secrets-list.function.d.ts +3 -3
  117. package/dist/src/fabric/functions/secrets-set.function.d.ts +3 -3
  118. package/dist/src/fabric/functions/smoke.function.d.ts +3 -3
  119. package/dist/src/fabric/functions/status.function.d.ts +3 -3
  120. package/dist/src/fabric/functions/trace.function.d.ts +3 -3
  121. package/dist/src/fabric/functions/validate.function.d.ts +3 -3
  122. package/dist/src/functions/commands/all.d.ts +1 -1
  123. package/dist/src/functions/commands/all.js +19 -2
  124. package/dist/src/functions/commands/binary.d.ts +3 -3
  125. package/dist/src/functions/commands/bootstrap.d.ts +1 -1
  126. package/dist/src/functions/commands/bootstrap.js +3 -0
  127. package/dist/src/functions/commands/console.d.ts +3 -3
  128. package/dist/src/functions/commands/db-audit.d.ts +1 -1
  129. package/dist/src/functions/commands/db-generate.d.ts +1 -1
  130. package/dist/src/functions/commands/db-migrate.d.ts +1 -1
  131. package/dist/src/functions/commands/db-reset.d.ts +1 -1
  132. package/dist/src/functions/commands/db-seed.d.ts +1 -1
  133. package/dist/src/functions/commands/deploy-apply.d.ts +3 -3
  134. package/dist/src/functions/commands/deploy-apply.js +32 -1
  135. package/dist/src/functions/commands/deploy-info.d.ts +1 -1
  136. package/dist/src/functions/commands/deploy-plan.d.ts +3 -3
  137. package/dist/src/functions/commands/deploy-plan.js +3 -1
  138. package/dist/src/functions/commands/dev.d.ts +3 -3
  139. package/dist/src/functions/commands/dev.js +17 -45
  140. package/dist/src/functions/commands/emails-init.d.ts +1 -1
  141. package/dist/src/functions/commands/enable.d.ts +6 -5
  142. package/dist/src/functions/commands/enable.js +4 -0
  143. package/dist/src/functions/commands/info.d.ts +4 -4
  144. package/dist/src/functions/commands/login.d.ts +7 -7
  145. package/dist/src/functions/commands/meta.d.ts +31 -31
  146. package/dist/src/functions/commands/new-addon.d.ts +3 -3
  147. package/dist/src/functions/commands/new-function.d.ts +3 -3
  148. package/dist/src/functions/commands/new-middleware.d.ts +3 -3
  149. package/dist/src/functions/commands/new-permission.d.ts +3 -3
  150. package/dist/src/functions/commands/new-wiring.d.ts +3 -3
  151. package/dist/src/functions/commands/pikku-command-bootstrap.d.ts +1 -1
  152. package/dist/src/functions/commands/pikku-command-summary.d.ts +1 -1
  153. package/dist/src/functions/commands/pikku-command-summary.js +6 -1
  154. package/dist/src/functions/commands/skills.d.ts +6 -6
  155. package/dist/src/functions/commands/tests-coverage.d.ts +3 -3
  156. package/dist/src/functions/commands/tests-init.d.ts +3 -3
  157. package/dist/src/functions/commands/versions-check.d.ts +1 -1
  158. package/dist/src/functions/commands/versions-init.d.ts +3 -3
  159. package/dist/src/functions/commands/versions-update.d.ts +1 -1
  160. package/dist/src/functions/commands/watch.d.ts +3 -3
  161. package/dist/src/functions/commands/workspace-validate.d.ts +3 -3
  162. package/dist/src/functions/db/db-codegen.js +14 -0
  163. package/dist/src/functions/db/sqlite/sqlite-runtime-bun.js +10 -0
  164. package/dist/src/functions/runtimes/fetch/index.d.ts +1 -1
  165. package/dist/src/functions/runtimes/nextjs/pikku-command-nextjs.d.ts +1 -1
  166. package/dist/src/functions/runtimes/tanstack-start/pikku-command-tanstack-start.d.ts +1 -1
  167. package/dist/src/functions/runtimes/websocket/pikku-command-websocket-typed.d.ts +1 -1
  168. package/dist/src/functions/wirings/ai-agent/pikku-command-ai-agent-types.d.ts +1 -1
  169. package/dist/src/functions/wirings/ai-agent/pikku-command-ai-agent.d.ts +1 -1
  170. package/dist/src/functions/wirings/ai-agent/pikku-command-public-agent.d.ts +1 -1
  171. package/dist/src/functions/wirings/auth/pikku-command-auth.d.ts +7 -1
  172. package/dist/src/functions/wirings/auth/pikku-command-auth.js +14 -2
  173. package/dist/src/functions/wirings/auth/serialize-auth-types.d.ts +10 -0
  174. package/dist/src/functions/wirings/auth/serialize-auth-types.js +15 -0
  175. package/dist/src/functions/wirings/channels/pikku-channels.d.ts +1 -1
  176. package/dist/src/functions/wirings/channels/pikku-command-channel-types.d.ts +1 -1
  177. package/dist/src/functions/wirings/channels/pikku-command-channels-map.d.ts +1 -1
  178. package/dist/src/functions/wirings/channels/pikku-command-channels.d.ts +1 -1
  179. package/dist/src/functions/wirings/cli/pikku-command-cli-entry.d.ts +1 -1
  180. package/dist/src/functions/wirings/cli/pikku-command-cli-types.d.ts +1 -1
  181. package/dist/src/functions/wirings/cli/pikku-command-cli.d.ts +1 -1
  182. package/dist/src/functions/wirings/console/pikku-command-console-functions.d.ts +1 -1
  183. package/dist/src/functions/wirings/console/pikku-command-node-types.d.ts +1 -1
  184. package/dist/src/functions/wirings/console/pikku-command-nodes-meta.d.ts +1 -1
  185. package/dist/src/functions/wirings/credentials/pikku-command-credentials.d.ts +1 -1
  186. package/dist/src/functions/wirings/emails/pikku-command-emails.d.ts +1 -1
  187. package/dist/src/functions/wirings/functions/pikku-command-addon-types.d.ts +1 -1
  188. package/dist/src/functions/wirings/functions/pikku-command-function-types-split.d.ts +3 -3
  189. package/dist/src/functions/wirings/functions/pikku-command-function-types.d.ts +3 -3
  190. package/dist/src/functions/wirings/functions/pikku-command-function-types.js +10 -3
  191. package/dist/src/functions/wirings/functions/pikku-command-functions.d.ts +1 -1
  192. package/dist/src/functions/wirings/functions/pikku-command-services.d.ts +1 -1
  193. package/dist/src/functions/wirings/functions/schemas.d.ts +1 -1
  194. package/dist/src/functions/wirings/functions/serialize-function-types.js +6 -29
  195. package/dist/src/functions/wirings/gateway/pikku-command-gateway.d.ts +1 -1
  196. package/dist/src/functions/wirings/http/pikku-command-http-map.d.ts +1 -1
  197. package/dist/src/functions/wirings/http/pikku-command-http-routes.d.ts +1 -1
  198. package/dist/src/functions/wirings/http/pikku-command-http-types.d.ts +1 -1
  199. package/dist/src/functions/wirings/http/pikku-command-openapi.d.ts +1 -1
  200. package/dist/src/functions/wirings/http/pikku-http-routes.d.ts +1 -1
  201. package/dist/src/functions/wirings/mcp/pikku-command-mcp-json.d.ts +1 -1
  202. package/dist/src/functions/wirings/mcp/pikku-command-mcp-types.d.ts +1 -1
  203. package/dist/src/functions/wirings/mcp/pikku-command-mcp.d.ts +1 -1
  204. package/dist/src/functions/wirings/middleware/pikku-command-middleware.d.ts +1 -1
  205. package/dist/src/functions/wirings/package/pikku-command-package-types.d.ts +2 -2
  206. package/dist/src/functions/wirings/package/pikku-command-package.d.ts +1 -1
  207. package/dist/src/functions/wirings/permissions/pikku-command-permissions.d.ts +1 -1
  208. package/dist/src/functions/wirings/queue/pikku-command-queue-map.d.ts +1 -1
  209. package/dist/src/functions/wirings/queue/pikku-command-queue-service.d.ts +1 -1
  210. package/dist/src/functions/wirings/queue/pikku-command-queue-types.d.ts +1 -1
  211. package/dist/src/functions/wirings/queue/pikku-command-queue.d.ts +1 -1
  212. package/dist/src/functions/wirings/queue/pikku-queue-map.d.ts +1 -1
  213. package/dist/src/functions/wirings/queue/pikku-queue.d.ts +1 -1
  214. package/dist/src/functions/wirings/realtime/pikku-command-events-scaffold.d.ts +1 -1
  215. package/dist/src/functions/wirings/realtime/pikku-command-realtime.d.ts +1 -1
  216. package/dist/src/functions/wirings/rpc/pikku-command-public-rpc.d.ts +1 -1
  217. package/dist/src/functions/wirings/rpc/pikku-command-react-query.d.ts +1 -1
  218. package/dist/src/functions/wirings/rpc/pikku-command-remote-rpc.d.ts +1 -1
  219. package/dist/src/functions/wirings/rpc/pikku-command-rpc-client.d.ts +1 -1
  220. package/dist/src/functions/wirings/rpc/pikku-command-rpc-map.d.ts +2 -2
  221. package/dist/src/functions/wirings/rpc/pikku-command-rpc.d.ts +1 -1
  222. package/dist/src/functions/wirings/scheduler/pikku-command-scheduler-types.d.ts +1 -1
  223. package/dist/src/functions/wirings/scheduler/pikku-command-scheduler.d.ts +1 -1
  224. package/dist/src/functions/wirings/secrets/pikku-command-secrets.d.ts +1 -1
  225. package/dist/src/functions/wirings/triggers/pikku-command-trigger-types.d.ts +3 -3
  226. package/dist/src/functions/wirings/triggers/pikku-command-trigger.d.ts +1 -1
  227. package/dist/src/functions/wirings/variables/pikku-command-variables.d.ts +1 -1
  228. package/dist/src/functions/wirings/workflow/pikku-command-workflow-routes.d.ts +1 -1
  229. package/dist/src/functions/wirings/workflow/pikku-command-workflow.d.ts +1 -1
  230. package/dist/src/functions/workflows/all.workflow.js +6 -1
  231. package/dist/src/scaffold/rpc-remote.gen.d.ts +3 -3
  232. package/dist/src/scaffold/rpc-remote.gen.js +1 -1
  233. package/dist/src/server/bun-server-runner.d.ts +17 -0
  234. package/dist/src/server/bun-server-runner.js +25 -0
  235. package/dist/src/server/dev-server-runner.interface.d.ts +31 -0
  236. package/dist/src/server/dev-server-runner.interface.js +11 -0
  237. package/dist/src/server/node-server-runner.d.ts +12 -0
  238. package/dist/src/server/node-server-runner.js +30 -0
  239. package/dist/src/services/cli-logger.service.js +7 -1
  240. package/dist/src/services.js +18 -0
  241. package/dist/src/utils/detect-better-auth.d.ts +7 -0
  242. package/dist/src/utils/detect-better-auth.js +29 -0
  243. package/dist/src/utils/parse-cli-filters.d.ts +1 -0
  244. package/dist/src/utils/parse-cli-filters.js +1 -0
  245. package/dist/src/utils/pikku-cli-config.js +1 -1
  246. package/dist/src/utils/serialize-schemas.js +5 -1
  247. package/dist/tsconfig.tsbuildinfo +1 -1
  248. package/package.json +4 -4
  249. package/skills/pikku-addon/SKILL.md +25 -117
  250. package/skills/pikku-addon/references/addon-package-manifest.md +63 -0
  251. package/skills/pikku-cli/SKILL.md +7 -93
  252. package/skills/pikku-cli/references/complete-example.md +82 -0
  253. package/skills/pikku-concepts/SKILL.md +17 -69
  254. package/skills/pikku-concepts/references/concept-mapping.md +37 -13
  255. package/skills/pikku-concepts/references/packages.md +29 -0
  256. package/skills/pikku-http/SKILL.md +14 -105
  257. package/skills/pikku-http/references/http-options.md +57 -0
  258. package/skills/pikku-middleware/SKILL.md +11 -68
  259. package/skills/pikku-middleware/references/middleware-patterns.md +61 -0
  260. package/skills/pikku-realtime/SKILL.md +56 -105
  261. package/skills/pikku-realtime/references/other-routes.md +23 -0
  262. package/skills/pikku-services/SKILL.md +25 -108
  263. package/skills/pikku-services/references/audit-wire-service.md +34 -0
  264. package/skills/pikku-testing/SKILL.md +51 -359
  265. package/skills/pikku-testing/references/cucumber-bdd-testing.md +176 -0
  266. package/skills/pikku-workflow/SKILL.md +93 -259
  267. package/skills/pikku-workflow/references/workflow-reference.md +63 -0
@@ -1,35 +1,30 @@
1
1
  /**
2
- * Main esbuild bundling pipeline for Pikku.
2
+ * Shared bundling orchestration for Pikku deploys.
3
3
  *
4
- * For each deployment unit in a DeploymentManifest, this module:
5
- * 1. Takes a pre-generated entry point (provided by the deploy provider)
6
- * 2. Runs esbuild with bundle:true, npm packages external
7
- * 3. Stubs Node.js-only gen files that aren't needed by this unit
8
- * 4. Parses the metafile to extract external dependencies
9
- * 5. Generates a minimal package.json with exact versions
10
- * 6. Writes all artifacts to `<outputDir>/<unit-name>/`
4
+ * `BaseBundler` performs everything that is runtime-independent for each
5
+ * deployment unit:
6
+ * 1. Take a pre-generated entry point (provided by the deploy provider)
7
+ * 2. Stub gen files / npm modules not needed by this unit
8
+ * 3. Delegate the actual compile to a runtime backend (`compile`)
9
+ * 4. Resolve external dependency versions into a minimal package.json
10
+ * 5. Write all artifacts to `<outputDir>/<unit-name>/` and hash them
11
+ *
12
+ * The runtime-specific compile step lives in `NodeBundler` (esbuild) and
13
+ * `BunBundler` (Bun.build); the right one is injected from `services.ts`.
11
14
  */
12
- import type { DeploymentManifest, DeploymentUnit, BundleOutput } from './types.js';
15
+ import type { DeploymentManifest, BundleOutput } from './types.js';
16
+ import type { Bundler, BundleUnitsOptions, CompileInput, CompileResult } from './bundler.interface.js';
13
17
  /**
14
- * Bundles all deployment units defined in a DeploymentManifest.
15
- *
16
- * Entry points must be pre-generated by the provider-specific package
17
- * (e.g. @pikku/deploy-cloudflare) and passed in as entryFiles.
18
- *
19
- * @param projectDir - Root directory of the Pikku project
20
- * @param manifest - The deployment manifest describing all units
21
- * @param entryFiles - Map of unit name -> entry file path (generated by the deploy provider)
22
- * @param outputDir - Base output directory (defaults to `<projectDir>/.deploy/build`)
18
+ * Runtime-independent bundling orchestration. Subclasses implement only
19
+ * `compile` — the actual esbuild / Bun.build invocation.
23
20
  */
24
- export declare function bundleUnits(projectDir: string, manifest: DeploymentManifest, entryFiles: Map<string, string>, outputDir?: string, options?: {
25
- externals?: string[];
26
- aliases?: Record<string, string>;
27
- define?: Record<string, string>;
28
- platform?: 'node' | 'neutral' | 'browser';
29
- format?: 'esm' | 'cjs';
30
- noRequireShim?: boolean;
31
- sourcemap?: boolean;
32
- emitMetafile?: boolean;
33
- stubModules?: string[];
34
- resolveOutputDir?: (unit: DeploymentUnit, baseOutputDir: string) => string;
35
- }): Promise<BundleOutput>;
21
+ export declare abstract class BaseBundler implements Bundler {
22
+ /**
23
+ * Runtime-specific compile step: write `input.bundlePath` (and its `.map`
24
+ * when `input.sourcemap`) and return the external packages + optional
25
+ * metafile JSON.
26
+ */
27
+ protected abstract compile(input: CompileInput): Promise<CompileResult>;
28
+ bundleUnits(projectDir: string, manifest: DeploymentManifest, entryFiles: Map<string, string>, outputDir?: string, options?: BundleUnitsOptions): Promise<BundleOutput>;
29
+ private bundleUnit;
30
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Bundler abstraction.
3
+ *
4
+ * A `Bundler` turns a deployment manifest's units into self-contained bundles.
5
+ * The shared orchestration (dead-module stubbing, dependency extraction,
6
+ * package.json + hashing) lives in `BaseBundler`; each runtime supplies only the
7
+ * compile step via a `Bundler` implementation (esbuild for node, Bun.build for
8
+ * bun). The runtime is resolved once in `services.ts` and injected — no
9
+ * `typeof Bun` checks in the pipeline.
10
+ */
11
+ import type { DeploymentManifest, DeploymentUnit, BundleOutput } from './types.js';
12
+ /**
13
+ * Inputs the shared orchestration hands to a backend's runtime-specific compile
14
+ * step. The backend writes `bundlePath` (and `${bundlePath}.map` when
15
+ * `sourcemap`) itself and returns the external packages + optional metafile.
16
+ */
17
+ export interface CompileInput {
18
+ unitName: string;
19
+ entryPath: string;
20
+ bundlePath: string;
21
+ projectDir: string;
22
+ platform: 'node' | 'neutral' | 'browser';
23
+ format: 'esm' | 'cjs';
24
+ externals: string[];
25
+ aliases?: Record<string, string>;
26
+ define?: Record<string, string>;
27
+ /** ESM require/__filename/__dirname shim, or undefined when not needed. */
28
+ bannerJs?: string;
29
+ sourcemap: boolean;
30
+ emitMetafile: boolean;
31
+ /** Regexes for modules to replace with an empty `export {}` module. */
32
+ deadPatterns: RegExp[];
33
+ }
34
+ export interface CompileResult {
35
+ /** Real npm package names kept external — drive the unit's package.json. */
36
+ externalPackages: Set<string>;
37
+ /** Stringified metafile when `emitMetafile` was set; otherwise undefined. */
38
+ metafileJson?: string;
39
+ }
40
+ export interface BundleUnitsOptions {
41
+ externals?: string[];
42
+ aliases?: Record<string, string>;
43
+ define?: Record<string, string>;
44
+ platform?: 'node' | 'neutral' | 'browser';
45
+ format?: 'esm' | 'cjs';
46
+ noRequireShim?: boolean;
47
+ sourcemap?: boolean;
48
+ emitMetafile?: boolean;
49
+ stubModules?: string[];
50
+ resolveOutputDir?: (unit: DeploymentUnit, baseOutputDir: string) => string;
51
+ }
52
+ export interface Bundler {
53
+ bundleUnits(projectDir: string, manifest: DeploymentManifest, entryFiles: Map<string, string>, outputDir?: string, options?: BundleUnitsOptions): Promise<BundleOutput>;
54
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Bundler abstraction.
3
+ *
4
+ * A `Bundler` turns a deployment manifest's units into self-contained bundles.
5
+ * The shared orchestration (dead-module stubbing, dependency extraction,
6
+ * package.json + hashing) lives in `BaseBundler`; each runtime supplies only the
7
+ * compile step via a `Bundler` implementation (esbuild for node, Bun.build for
8
+ * bun). The runtime is resolved once in `services.ts` and injected — no
9
+ * `typeof Bun` checks in the pipeline.
10
+ */
11
+ export {};
@@ -1,19 +1,21 @@
1
1
  /**
2
- * Main esbuild bundling pipeline for Pikku.
2
+ * Shared bundling orchestration for Pikku deploys.
3
3
  *
4
- * For each deployment unit in a DeploymentManifest, this module:
5
- * 1. Takes a pre-generated entry point (provided by the deploy provider)
6
- * 2. Runs esbuild with bundle:true, npm packages external
7
- * 3. Stubs Node.js-only gen files that aren't needed by this unit
8
- * 4. Parses the metafile to extract external dependencies
9
- * 5. Generates a minimal package.json with exact versions
10
- * 6. Writes all artifacts to `<outputDir>/<unit-name>/`
4
+ * `BaseBundler` performs everything that is runtime-independent for each
5
+ * deployment unit:
6
+ * 1. Take a pre-generated entry point (provided by the deploy provider)
7
+ * 2. Stub gen files / npm modules not needed by this unit
8
+ * 3. Delegate the actual compile to a runtime backend (`compile`)
9
+ * 4. Resolve external dependency versions into a minimal package.json
10
+ * 5. Write all artifacts to `<outputDir>/<unit-name>/` and hash them
11
+ *
12
+ * The runtime-specific compile step lives in `NodeBundler` (esbuild) and
13
+ * `BunBundler` (Bun.build); the right one is injected from `services.ts`.
11
14
  */
12
- import { build } from 'esbuild';
13
15
  import { writeFile, mkdir, stat, readFile } from 'node:fs/promises';
14
16
  import { join } from 'node:path';
15
17
  import { createHash } from 'node:crypto';
16
- import { extractDependencies, generateMinimalPackageJson, } from './dep-extractor.js';
18
+ import { resolveExternalVersions, generateMinimalPackageJson, } from './dep-extractor.js';
17
19
  /**
18
20
  * Mapping of service name -> gen file pattern that should be stubbed
19
21
  * when the service is not required by a deployment unit.
@@ -66,196 +68,124 @@ async function getDeadGenFilePatterns(unitOutputDir) {
66
68
  }
67
69
  return patterns;
68
70
  }
69
- /**
70
- * esbuild plugin that stubs gen files for services not needed by this unit.
71
- * This prevents Node.js-only modules (e.g. LocalMetaService which uses fs)
72
- * from being pulled into serverless worker bundles via dynamic imports.
73
- */
74
- function createDeadModuleStubPlugin(patterns) {
75
- return {
76
- name: 'pikku-dead-module-stub',
77
- setup(build) {
78
- if (patterns.length === 0)
79
- return;
80
- const combined = new RegExp(patterns.map((p) => p.source).join('|'));
81
- build.onResolve({ filter: combined }, (args) => ({
82
- path: args.path,
83
- namespace: 'pikku-stub',
84
- }));
85
- build.onLoad({ filter: /.*/, namespace: 'pikku-stub' }, () => ({
86
- contents: 'export {}',
87
- loader: 'js',
88
- }));
89
- },
90
- };
91
- }
92
71
  const BUNDLE_FILENAME = 'bundle.js';
93
72
  const METAFILE_FILENAME = 'metafile.json';
94
73
  const PACKAGE_JSON_FILENAME = 'package.json';
95
74
  const EXACT_DEPENDENCIES_FILENAME = 'exact-dependencies.json';
96
75
  /**
97
- * Bundles a single deployment unit using esbuild.
98
- *
99
- * Produces three files in the unit output directory:
100
- * - bundle.js: The bundled code (user code only, external deps as bare imports)
101
- * - metafile.json: esbuild's metafile for analysis
102
- * - package.json: Minimal manifest with only the external deps this unit needs
76
+ * Runtime-independent bundling orchestration. Subclasses implement only
77
+ * `compile` — the actual esbuild / Bun.build invocation.
103
78
  */
104
- async function bundleUnit(options) {
105
- const { unit, entryPath, unitOutputDir, projectDir, externals, aliases, define, platform, format, sourcemap, emitMetafile, stubModules, } = options;
106
- await mkdir(unitOutputDir, { recursive: true });
107
- const bundlePath = join(unitOutputDir, BUNDLE_FILENAME);
108
- const metafilePath = join(unitOutputDir, METAFILE_FILENAME);
109
- const packageJsonPath = join(unitOutputDir, PACKAGE_JSON_FILENAME);
110
- const exactDependenciesPath = join(unitOutputDir, EXACT_DEPENDENCIES_FILENAME);
111
- // Determine which gen files to stub based on per-unit service requirements,
112
- // plus any provider-supplied module stubs (modules the provider's runtime
113
- // never executes — e.g. the `postgres` driver on CF Workers, which use a
114
- // libsql/Turso dialect; the postgres branch is URL-gated and never taken).
115
- const deadPatterns = await getDeadGenFilePatterns(unitOutputDir);
116
- for (const source of stubModules ?? []) {
117
- deadPatterns.push(new RegExp(source));
118
- }
119
- // Run esbuild — inline everything into a self-contained bundle.
120
- // Only Node built-ins are kept external (CF Workers provides them).
121
- // The stub plugin replaces gen files for unused services with empty
122
- // modules, preventing Node.js-only code from entering the bundle.
123
- // Resolve node_modules paths up the directory tree for workspace packages
124
- const nodePaths = [];
125
- let dir = projectDir;
126
- while (true) {
127
- const nm = join(dir, 'node_modules');
128
- nodePaths.push(nm);
129
- const parent = join(dir, '..');
130
- if (parent === dir)
131
- break;
132
- dir = parent;
133
- }
134
- // For ESM + node platform, CJS deps may use require() / __filename / __dirname
135
- // for builtins or to locate native addons (the `bindings` package, used
136
- // transitively by `pg` and many others, calls `__filename` directly). esbuild
137
- // wraps require() as __require() which fails at runtime in ESM, and leaves
138
- // `__filename` / `__dirname` as undefined references. The banner shims all
139
- // three via createRequire / fileURLToPath so CJS builtins resolve and native-
140
- // addon loaders find their .node files.
141
- // Skipped when the provider opts out via `noRequireShim` (e.g. CF Workers
142
- // — `import.meta.url` is undefined there, so the shim crashes at boot).
143
- const resolvedFormat = format ?? 'esm';
144
- const banner = resolvedFormat === 'esm' &&
145
- (platform ?? 'node') === 'node' &&
146
- !options.noRequireShim
147
- ? {
148
- js: `import { createRequire as __pikkuCreateRequire } from 'node:module'; import { fileURLToPath as __pikkuFileURLToPath } from 'node:url'; import { dirname as __pikkuDirname } from 'node:path'; const require = __pikkuCreateRequire(import.meta.url); const __filename = __pikkuFileURLToPath(import.meta.url); const __dirname = __pikkuDirname(__filename);`,
79
+ export class BaseBundler {
80
+ async bundleUnits(projectDir, manifest, entryFiles, outputDir, options) {
81
+ const buildDir = outputDir ?? join(projectDir, '.deploy', 'build');
82
+ const results = [];
83
+ const errors = [];
84
+ if (manifest.units.length === 0) {
85
+ return { results, errors };
86
+ }
87
+ for (const unit of manifest.units) {
88
+ const entryPath = entryFiles.get(unit.name);
89
+ if (!entryPath) {
90
+ errors.push({
91
+ unitName: unit.name,
92
+ error: `No entry point provided for unit "${unit.name}"`,
93
+ });
94
+ continue;
95
+ }
96
+ const unitOutputDir = options?.resolveOutputDir
97
+ ? options.resolveOutputDir(unit, buildDir)
98
+ : join(buildDir, unit.name);
99
+ try {
100
+ const result = await this.bundleUnit(unit, entryPath, unitOutputDir, projectDir, options ?? {});
101
+ results.push(result);
102
+ }
103
+ catch (err) {
104
+ const message = err instanceof Error ? err.message : String(err);
105
+ errors.push({ unitName: unit.name, error: message });
106
+ }
149
107
  }
150
- : undefined;
151
- const result = await build({
152
- entryPoints: [entryPath],
153
- bundle: true,
154
- absWorkingDir: projectDir,
155
- nodePaths,
156
- platform: platform ?? 'node',
157
- format: resolvedFormat,
158
- banner,
159
- metafile: true,
160
- target: 'es2022',
161
- outfile: bundlePath,
162
- // Minify every deploy bundle — esbuild output ships straight to the runtime
163
- // (CF Workers / container), tsc is never the bundler. keepNames preserves
164
- // Function.name / constructor.name so name-based reflection still works.
165
- minify: true,
166
- keepNames: true,
167
- sourcemap: sourcemap ?? false,
168
- logLevel: 'warning',
169
- loader: { '.ts': 'ts' },
170
- external: externals ?? ['node:*'],
171
- alias: aliases,
172
- define,
173
- plugins: [createDeadModuleStubPlugin(deadPatterns)],
174
- });
175
- // Always produced in-memory (drives dependency extraction); only persisted
176
- // when requested — it's large (~1.6MB/unit) and never needed at runtime.
177
- if (emitMetafile) {
178
- const metafileJson = JSON.stringify(result.metafile, null, 2);
179
- await writeFile(metafilePath, metafileJson, 'utf-8');
180
- }
181
- // Extract dependencies and generate minimal package.json
182
- const { exactDependencies, exactOptionalDependencies } = await extractDependencies(result.metafile, projectDir);
183
- const packageJson = generateMinimalPackageJson(unit.name, exactDependencies, exactOptionalDependencies);
184
- await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');
185
- await writeFile(exactDependenciesPath, JSON.stringify({
186
- dependencies: Object.fromEntries(Object.entries(exactDependencies).sort(([a], [b]) => a.localeCompare(b))),
187
- optionalDependencies: Object.fromEntries(Object.entries(exactOptionalDependencies).sort(([a], [b]) => a.localeCompare(b))),
188
- }, null, 2), 'utf-8');
189
- // Get bundle size
190
- const bundleStat = await stat(bundlePath);
191
- const bundleContents = await readFile(bundlePath);
192
- const bundleHash = createHash('sha256').update(bundleContents).digest('hex');
193
- const exactDependenciesHash = createHash('sha256')
194
- .update(JSON.stringify({
195
- dependencies: Object.entries(exactDependencies).sort(([a], [b]) => a.localeCompare(b)),
196
- optionalDependencies: Object.entries(exactOptionalDependencies).sort(([a], [b]) => a.localeCompare(b)),
197
- }))
198
- .digest('hex');
199
- return {
200
- unitName: unit.name,
201
- bundlePath,
202
- packageJsonPath,
203
- exactDependenciesPath,
204
- metafilePath,
205
- bundleSizeBytes: bundleStat.size,
206
- bundleHash,
207
- exactDependenciesHash,
208
- exactDependencies,
209
- exactOptionalDependencies,
210
- };
211
- }
212
- /**
213
- * Bundles all deployment units defined in a DeploymentManifest.
214
- *
215
- * Entry points must be pre-generated by the provider-specific package
216
- * (e.g. @pikku/deploy-cloudflare) and passed in as entryFiles.
217
- *
218
- * @param projectDir - Root directory of the Pikku project
219
- * @param manifest - The deployment manifest describing all units
220
- * @param entryFiles - Map of unit name -> entry file path (generated by the deploy provider)
221
- * @param outputDir - Base output directory (defaults to `<projectDir>/.deploy/build`)
222
- */
223
- export async function bundleUnits(projectDir, manifest, entryFiles, outputDir, options) {
224
- const buildDir = outputDir ?? join(projectDir, '.deploy', 'build');
225
- const results = [];
226
- const errors = [];
227
- if (manifest.units.length === 0) {
228
108
  return { results, errors };
229
109
  }
230
- for (const unit of manifest.units) {
231
- const entryPath = entryFiles.get(unit.name);
232
- if (!entryPath) {
233
- errors.push({
234
- unitName: unit.name,
235
- error: `No entry point provided for unit "${unit.name}"`,
236
- });
237
- continue;
238
- }
239
- const unitOutputDir = options?.resolveOutputDir
240
- ? options.resolveOutputDir(unit, buildDir)
241
- : join(buildDir, unit.name);
242
- try {
243
- const result = await bundleUnit({
244
- unit,
245
- entryPath,
246
- unitOutputDir,
247
- projectDir,
248
- ...options,
249
- });
250
- results.push(result);
110
+ async bundleUnit(unit, entryPath, unitOutputDir, projectDir, options) {
111
+ await mkdir(unitOutputDir, { recursive: true });
112
+ const bundlePath = join(unitOutputDir, BUNDLE_FILENAME);
113
+ const metafilePath = join(unitOutputDir, METAFILE_FILENAME);
114
+ const packageJsonPath = join(unitOutputDir, PACKAGE_JSON_FILENAME);
115
+ const exactDependenciesPath = join(unitOutputDir, EXACT_DEPENDENCIES_FILENAME);
116
+ // Determine which gen files to stub based on per-unit service requirements,
117
+ // plus any provider-supplied module stubs (modules the provider's runtime
118
+ // never executes — e.g. the `postgres` driver on CF Workers, which use a
119
+ // libsql/Turso dialect; the postgres branch is URL-gated and never taken).
120
+ const deadPatterns = await getDeadGenFilePatterns(unitOutputDir);
121
+ for (const source of options.stubModules ?? []) {
122
+ deadPatterns.push(new RegExp(source));
251
123
  }
252
- catch (err) {
253
- const message = err instanceof Error ? err.message : String(err);
254
- errors.push({
255
- unitName: unit.name,
256
- error: message,
257
- });
124
+ const platform = options.platform ?? 'node';
125
+ const format = options.format ?? 'esm';
126
+ const externals = options.externals ?? ['node:*'];
127
+ const sourcemap = options.sourcemap ?? false;
128
+ const emitMetafile = options.emitMetafile ?? false;
129
+ // For ESM + node platform, CJS deps may use require() / __filename /
130
+ // __dirname for builtins or to locate native addons (the `bindings`
131
+ // package, used transitively by `pg`, calls `__filename` directly). esbuild
132
+ // wraps require() as __require() which fails at runtime in ESM, and leaves
133
+ // `__filename` / `__dirname` as undefined references. The banner shims all
134
+ // three so CJS builtins resolve and native-addon loaders find their .node
135
+ // files. Skipped when the provider opts out via `noRequireShim` (e.g. CF
136
+ // Workers — `import.meta.url` is undefined there, so the shim crashes).
137
+ const bannerJs = format === 'esm' && platform === 'node' && !options.noRequireShim
138
+ ? `import { createRequire as __pikkuCreateRequire } from 'node:module'; import { fileURLToPath as __pikkuFileURLToPath } from 'node:url'; import { dirname as __pikkuDirname } from 'node:path'; const require = __pikkuCreateRequire(import.meta.url); const __filename = __pikkuFileURLToPath(import.meta.url); const __dirname = __pikkuDirname(__filename);`
139
+ : undefined;
140
+ const { externalPackages, metafileJson } = await this.compile({
141
+ unitName: unit.name,
142
+ entryPath,
143
+ bundlePath,
144
+ projectDir,
145
+ platform,
146
+ format,
147
+ externals,
148
+ aliases: options.aliases,
149
+ define: options.define,
150
+ bannerJs,
151
+ sourcemap,
152
+ emitMetafile,
153
+ deadPatterns,
154
+ });
155
+ // Metafile is large (~1.6MB/unit) and never needed at runtime — only
156
+ // persisted for debugging.
157
+ if (emitMetafile && metafileJson) {
158
+ await writeFile(metafilePath, metafileJson, 'utf-8');
258
159
  }
160
+ // Extract dependencies and generate minimal package.json
161
+ const { exactDependencies, exactOptionalDependencies } = await resolveExternalVersions(externalPackages, projectDir);
162
+ const packageJson = generateMinimalPackageJson(unit.name, exactDependencies, exactOptionalDependencies);
163
+ await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');
164
+ await writeFile(exactDependenciesPath, JSON.stringify({
165
+ dependencies: Object.fromEntries(Object.entries(exactDependencies).sort(([a], [b]) => a.localeCompare(b))),
166
+ optionalDependencies: Object.fromEntries(Object.entries(exactOptionalDependencies).sort(([a], [b]) => a.localeCompare(b))),
167
+ }, null, 2), 'utf-8');
168
+ // Get bundle size + hashes
169
+ const bundleStat = await stat(bundlePath);
170
+ const bundleContents = await readFile(bundlePath);
171
+ const bundleHash = createHash('sha256').update(bundleContents).digest('hex');
172
+ const exactDependenciesHash = createHash('sha256')
173
+ .update(JSON.stringify({
174
+ dependencies: Object.entries(exactDependencies).sort(([a], [b]) => a.localeCompare(b)),
175
+ optionalDependencies: Object.entries(exactOptionalDependencies).sort(([a], [b]) => a.localeCompare(b)),
176
+ }))
177
+ .digest('hex');
178
+ return {
179
+ unitName: unit.name,
180
+ bundlePath,
181
+ packageJsonPath,
182
+ exactDependenciesPath,
183
+ metafilePath,
184
+ bundleSizeBytes: bundleStat.size,
185
+ bundleHash,
186
+ exactDependenciesHash,
187
+ exactDependencies,
188
+ exactOptionalDependencies,
189
+ };
259
190
  }
260
- return { results, errors };
261
191
  }
@@ -21,12 +21,20 @@ export declare function extractExternalPackages(metafile: Metafile): Set<string>
21
21
  * Returns null for relative imports or other non-package specifiers.
22
22
  */
23
23
  export declare function parsePackageName(specifier: string): string | null;
24
+ /**
25
+ * Resolves exact versions for a set of external package names.
26
+ *
27
+ * Shared by both bundler backends: esbuild derives the set from its metafile
28
+ * (`extractExternalPackages`), while the Bun.build backend captures it via a
29
+ * resolve plugin (Bun's metafile does not record external imports).
30
+ */
31
+ export declare function resolveExternalVersions(externalPackages: Set<string>, projectDir: string): Promise<{
32
+ exactDependencies: Record<string, string>;
33
+ exactOptionalDependencies: Record<string, string>;
34
+ }>;
24
35
  /**
25
36
  * Given an esbuild metafile, extracts all external packages and resolves
26
37
  * their versions from the project's dependency files.
27
- *
28
- * Returns a record of package name to exact version, suitable for
29
- * writing into a minimal package.json.
30
38
  */
31
39
  export declare function extractDependencies(metafile: Metafile, projectDir: string): Promise<{
32
40
  exactDependencies: Record<string, string>;
@@ -244,14 +244,13 @@ async function resolveVersion(packageName, projectDeps, yarnLockVersions, projec
244
244
  return null;
245
245
  }
246
246
  /**
247
- * Given an esbuild metafile, extracts all external packages and resolves
248
- * their versions from the project's dependency files.
247
+ * Resolves exact versions for a set of external package names.
249
248
  *
250
- * Returns a record of package name to exact version, suitable for
251
- * writing into a minimal package.json.
249
+ * Shared by both bundler backends: esbuild derives the set from its metafile
250
+ * (`extractExternalPackages`), while the Bun.build backend captures it via a
251
+ * resolve plugin (Bun's metafile does not record external imports).
252
252
  */
253
- export async function extractDependencies(metafile, projectDir) {
254
- const externalPackages = extractExternalPackages(metafile);
253
+ export async function resolveExternalVersions(externalPackages, projectDir) {
255
254
  if (externalPackages.size === 0) {
256
255
  return { exactDependencies: {}, exactOptionalDependencies: {} };
257
256
  }
@@ -278,6 +277,13 @@ export async function extractDependencies(metafile, projectDir) {
278
277
  }
279
278
  return { exactDependencies, exactOptionalDependencies };
280
279
  }
280
+ /**
281
+ * Given an esbuild metafile, extracts all external packages and resolves
282
+ * their versions from the project's dependency files.
283
+ */
284
+ export async function extractDependencies(metafile, projectDir) {
285
+ return resolveExternalVersions(extractExternalPackages(metafile), projectDir);
286
+ }
281
287
  /**
282
288
  * Generates a minimal package.json content object for a unit bundle.
283
289
  */
@@ -1,3 +1,6 @@
1
- export { bundleUnits } from './bundler.js';
2
- export { extractDependencies, extractExternalPackages, parsePackageName, generateMinimalPackageJson, } from './dep-extractor.js';
1
+ export { BaseBundler } from './bundler.js';
2
+ export { NodeBundler } from './node-bundler.js';
3
+ export { BunBundler } from './bun-bundler.js';
4
+ export type { Bundler, BundleUnitsOptions } from './bundler.interface.js';
5
+ export { extractDependencies, extractExternalPackages, resolveExternalVersions, parsePackageName, generateMinimalPackageJson, } from './dep-extractor.js';
3
6
  export type { BundleResult, BundleError, BundleOutput, DeploymentUnit, DeploymentUnitRole, } from './types.js';
@@ -1,2 +1,4 @@
1
- export { bundleUnits } from './bundler.js';
2
- export { extractDependencies, extractExternalPackages, parsePackageName, generateMinimalPackageJson, } from './dep-extractor.js';
1
+ export { BaseBundler } from './bundler.js';
2
+ export { NodeBundler } from './node-bundler.js';
3
+ export { BunBundler } from './bun-bundler.js';
4
+ export { extractDependencies, extractExternalPackages, resolveExternalVersions, parsePackageName, generateMinimalPackageJson, } from './dep-extractor.js';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Node (esbuild) bundler backend.
3
+ *
4
+ * Used when the CLI runs under Node (yarn/npm projects). esbuild resolves deps
5
+ * via `nodePaths` walking up the directory tree, which assumes a flat, hoisted
6
+ * `node_modules` — exactly what yarn/npm produce. For bun's per-workspace
7
+ * symlink layout use `BunBundler` instead (selected in `services.ts`).
8
+ */
9
+ import { BaseBundler } from './bundler.js';
10
+ import type { CompileInput, CompileResult } from './bundler.interface.js';
11
+ export declare class NodeBundler extends BaseBundler {
12
+ protected compile(input: CompileInput): Promise<CompileResult>;
13
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Node (esbuild) bundler backend.
3
+ *
4
+ * Used when the CLI runs under Node (yarn/npm projects). esbuild resolves deps
5
+ * via `nodePaths` walking up the directory tree, which assumes a flat, hoisted
6
+ * `node_modules` — exactly what yarn/npm produce. For bun's per-workspace
7
+ * symlink layout use `BunBundler` instead (selected in `services.ts`).
8
+ */
9
+ import { build } from 'esbuild';
10
+ import { join } from 'node:path';
11
+ import { extractExternalPackages } from './dep-extractor.js';
12
+ import { BaseBundler } from './bundler.js';
13
+ /**
14
+ * esbuild plugin that stubs gen files / modules not needed by this unit,
15
+ * preventing Node-only modules (e.g. LocalMetaService using fs) from being
16
+ * pulled into serverless worker bundles via dynamic imports.
17
+ */
18
+ function createDeadModuleStubPlugin(patterns) {
19
+ return {
20
+ name: 'pikku-dead-module-stub',
21
+ setup(build) {
22
+ if (patterns.length === 0)
23
+ return;
24
+ const combined = new RegExp(patterns.map((p) => p.source).join('|'));
25
+ build.onResolve({ filter: combined }, (args) => ({
26
+ path: args.path,
27
+ namespace: 'pikku-stub',
28
+ }));
29
+ build.onLoad({ filter: /.*/, namespace: 'pikku-stub' }, () => ({
30
+ contents: 'export {}',
31
+ loader: 'js',
32
+ }));
33
+ },
34
+ };
35
+ }
36
+ export class NodeBundler extends BaseBundler {
37
+ async compile(input) {
38
+ // Resolve node_modules paths up the directory tree for workspace packages.
39
+ const nodePaths = [];
40
+ let dir = input.projectDir;
41
+ while (true) {
42
+ nodePaths.push(join(dir, 'node_modules'));
43
+ const parent = join(dir, '..');
44
+ if (parent === dir)
45
+ break;
46
+ dir = parent;
47
+ }
48
+ const result = await build({
49
+ entryPoints: [input.entryPath],
50
+ bundle: true,
51
+ absWorkingDir: input.projectDir,
52
+ nodePaths,
53
+ platform: input.platform,
54
+ format: input.format,
55
+ banner: input.bannerJs ? { js: input.bannerJs } : undefined,
56
+ metafile: true,
57
+ target: 'es2022',
58
+ outfile: input.bundlePath,
59
+ // Minify every deploy bundle — esbuild output ships straight to the
60
+ // runtime (CF Workers / container), tsc is never the bundler. keepNames
61
+ // preserves Function.name / constructor.name so name-based reflection
62
+ // still works.
63
+ minify: true,
64
+ keepNames: true,
65
+ sourcemap: input.sourcemap,
66
+ logLevel: 'warning',
67
+ loader: { '.ts': 'ts' },
68
+ external: input.externals,
69
+ alias: input.aliases,
70
+ define: input.define,
71
+ plugins: [createDeadModuleStubPlugin(input.deadPatterns)],
72
+ });
73
+ return {
74
+ externalPackages: extractExternalPackages(result.metafile),
75
+ metafileJson: input.emitMetafile
76
+ ? JSON.stringify(result.metafile, null, 2)
77
+ : undefined,
78
+ };
79
+ }
80
+ }