@powerhousedao/shared 6.2.3-staging.0 → 6.3.0-dev.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.
- package/dist/action-id-DON1WCeY.d.ts +19 -0
- package/dist/action-id-DON1WCeY.d.ts.map +1 -0
- package/dist/clis/args/access-token.d.mts +14 -2
- package/dist/clis/args/access-token.d.mts.map +1 -0
- package/dist/clis/args/access-token.mjs +21 -1
- package/dist/clis/args/access-token.mjs.map +1 -0
- package/dist/clis/args/{common-BXabdhiO.mjs → common-DG_SF8fN.mjs} +39 -8
- package/dist/clis/args/common-DG_SF8fN.mjs.map +1 -0
- package/dist/clis/args/{common-Bnm859xU.d.mts → common-DmerPWXo.d.mts} +8 -4
- package/dist/clis/args/common-DmerPWXo.d.mts.map +1 -0
- package/dist/clis/args/common.d.mts +1 -1
- package/dist/clis/args/common.mjs +1 -1
- package/dist/clis/args/connect.d.mts +448 -2
- package/dist/clis/args/connect.d.mts.map +1 -0
- package/dist/clis/args/connect.mjs +202 -1
- package/dist/clis/args/connect.mjs.map +1 -0
- package/dist/clis/args/{generate-BOItUNvP.mjs → generate-DMKgc6et.mjs} +2 -21
- package/dist/clis/args/generate-DMKgc6et.mjs.map +1 -0
- package/dist/clis/args/generate.d.mts +92 -2
- package/dist/clis/args/generate.d.mts.map +1 -0
- package/dist/clis/args/generate.mjs +1 -1
- package/dist/clis/args/{help-DVPTARGn.d.mts → help-BnD14eCa.d.mts} +62 -2
- package/dist/clis/args/help-BnD14eCa.d.mts.map +1 -0
- package/dist/clis/args/{help-DS1NlcJQ.mjs → help-Cjoe-b7d.mjs} +55 -15
- package/dist/clis/args/help-Cjoe-b7d.mjs.map +1 -0
- package/dist/clis/args/help.d.mts +1 -1
- package/dist/clis/args/help.mjs +16 -1
- package/dist/clis/args/host.d.mts +23 -0
- package/dist/clis/args/host.d.mts.map +1 -0
- package/dist/clis/args/host.mjs +35 -0
- package/dist/clis/args/host.mjs.map +1 -0
- package/dist/clis/args/index.d.mts +23 -19
- package/dist/clis/args/index.mjs +23 -19
- package/dist/clis/args/init.d.mts +53 -2
- package/dist/clis/args/init.d.mts.map +1 -0
- package/dist/clis/args/init.mjs +77 -1
- package/dist/clis/args/init.mjs.map +1 -0
- package/dist/clis/args/inspect.d.mts +11 -2
- package/dist/clis/args/inspect.d.mts.map +1 -0
- package/dist/clis/args/inspect.mjs +14 -1
- package/dist/clis/args/inspect.mjs.map +1 -0
- package/dist/clis/args/install.d.mts +35 -2
- package/dist/clis/args/install.d.mts.map +1 -0
- package/dist/clis/args/install.mjs +31 -1
- package/dist/clis/args/install.mjs.map +1 -0
- package/dist/clis/args/{login-CXRJXg71.d.mts → keyframes.d.mts} +13 -13
- package/dist/clis/args/keyframes.d.mts.map +1 -0
- package/dist/clis/args/keyframes.mjs +42 -0
- package/dist/clis/args/keyframes.mjs.map +1 -0
- package/dist/clis/args/list.d.mts +8 -2
- package/dist/clis/args/list.d.mts.map +1 -0
- package/dist/clis/args/list.mjs +6 -1
- package/dist/clis/args/list.mjs.map +1 -0
- package/dist/clis/args/login.d.mts +23 -2
- package/dist/clis/args/login.d.mts.map +1 -0
- package/dist/clis/args/login.mjs +39 -1
- package/dist/clis/args/login.mjs.map +1 -0
- package/dist/clis/args/{access-token-C5sKsH2O.d.mts → mcp.d.mts} +6 -7
- package/dist/clis/args/mcp.d.mts.map +1 -0
- package/dist/clis/args/mcp.mjs +22 -0
- package/dist/clis/args/mcp.mjs.map +1 -0
- package/dist/clis/args/migrate.d.mts +26 -2
- package/dist/clis/args/migrate.d.mts.map +1 -0
- package/dist/clis/args/migrate.mjs +43 -1
- package/dist/clis/args/migrate.mjs.map +1 -0
- package/dist/clis/args/{uninstall-CDx7lwxn.d.mts → model.d.mts} +28 -17
- package/dist/clis/args/model.d.mts.map +1 -0
- package/dist/clis/args/model.mjs +51 -0
- package/dist/clis/args/model.mjs.map +1 -0
- package/dist/clis/args/publish.d.mts +18 -2
- package/dist/clis/args/publish.d.mts.map +1 -0
- package/dist/clis/args/publish.mjs +26 -1
- package/dist/clis/args/publish.mjs.map +1 -0
- package/dist/clis/args/registry.d.mts +15 -2
- package/dist/clis/args/registry.d.mts.map +1 -0
- package/dist/clis/args/registry.mjs +22 -1
- package/dist/clis/args/registry.mjs.map +1 -0
- package/dist/clis/args/{unpublish-CEDsk6uv.d.mts → run.d.mts} +11 -12
- package/dist/clis/args/run.d.mts.map +1 -0
- package/dist/clis/args/run.mjs +33 -0
- package/dist/clis/args/run.mjs.map +1 -0
- package/dist/clis/args/{service-BBx5GDTc.d.mts → service-CLCvH3kf.d.mts} +4 -4
- package/dist/clis/args/service-CLCvH3kf.d.mts.map +1 -0
- package/dist/clis/args/service.d.mts +1 -1
- package/dist/clis/args/service.mjs +10 -1
- package/dist/clis/args/service.mjs.map +1 -0
- package/dist/clis/args/switchboard.d.mts +68 -2
- package/dist/clis/args/switchboard.d.mts.map +1 -0
- package/dist/clis/args/switchboard.mjs +84 -1
- package/dist/clis/args/switchboard.mjs.map +1 -0
- package/dist/clis/args/uninstall.d.mts +26 -2
- package/dist/clis/args/uninstall.d.mts.map +1 -0
- package/dist/clis/args/uninstall.mjs +15 -1
- package/dist/clis/args/uninstall.mjs.map +1 -0
- package/dist/clis/args/unpublish.d.mts +20 -2
- package/dist/clis/args/unpublish.d.mts.map +1 -0
- package/dist/clis/args/unpublish.mjs +29 -1
- package/dist/clis/args/unpublish.mjs.map +1 -0
- package/dist/clis/args/{vetra-BUNlAAPp.mjs → vetra-BqjDopAP.mjs} +18 -2
- package/dist/clis/args/vetra-BqjDopAP.mjs.map +1 -0
- package/dist/clis/args/vetra.d.mts +112 -2
- package/dist/clis/args/vetra.d.mts.map +1 -0
- package/dist/clis/args/vetra.mjs +1 -1
- package/dist/clis/{build-config-CmdMi_wu.mjs → build-config-BM1RL4u_.mjs} +87 -8
- package/dist/clis/build-config-BM1RL4u_.mjs.map +1 -0
- package/dist/clis/build-config.d.mts +26 -1
- package/dist/clis/build-config.d.mts.map +1 -1
- package/dist/clis/build-config.mjs +2 -2
- package/dist/clis/build-pieces.d.mts +71 -4
- package/dist/clis/build-pieces.d.mts.map +1 -1
- package/dist/clis/build-pieces.mjs +249 -26
- package/dist/clis/build-pieces.mjs.map +1 -1
- package/dist/clis/command-names.d.mts +3 -1
- package/dist/clis/command-names.d.mts.map +1 -1
- package/dist/clis/command-names.mjs +8 -1
- package/dist/clis/command-names.mjs.map +1 -1
- package/dist/clis/constants.d.mts +2 -2
- package/dist/clis/constants.mjs +92 -20
- package/dist/clis/constants.mjs.map +1 -1
- package/dist/clis/definition-sources.d.mts +26 -0
- package/dist/clis/definition-sources.d.mts.map +1 -0
- package/dist/clis/definition-sources.mjs +27 -0
- package/dist/clis/definition-sources.mjs.map +1 -0
- package/dist/clis/deprecations.d.mts +73 -0
- package/dist/clis/deprecations.d.mts.map +1 -0
- package/dist/clis/deprecations.mjs +121 -0
- package/dist/clis/deprecations.mjs.map +1 -0
- package/dist/clis/{index-6CZwrmQi.d.mts → index-DnZYG-8g.d.mts} +2 -2
- package/dist/clis/{index-6CZwrmQi.d.mts.map → index-DnZYG-8g.d.mts.map} +1 -1
- package/dist/clis/index.d.mts +2584 -901
- package/dist/clis/index.d.mts.map +1 -1
- package/dist/clis/index.mjs +1540 -919
- package/dist/clis/index.mjs.map +1 -1
- package/dist/clis/package-style.d.mts +32 -0
- package/dist/clis/package-style.d.mts.map +1 -0
- package/dist/clis/package-style.mjs +102 -0
- package/dist/clis/package-style.mjs.map +1 -0
- package/dist/clis/ph-dir.d.mts +26 -0
- package/dist/clis/ph-dir.d.mts.map +1 -0
- package/dist/clis/ph-dir.mjs +37 -0
- package/dist/clis/ph-dir.mjs.map +1 -0
- package/dist/clis/project-env.d.mts +6 -0
- package/dist/clis/project-env.d.mts.map +1 -1
- package/dist/clis/project-env.mjs +16 -1
- package/dist/clis/project-env.mjs.map +1 -1
- package/dist/clis/real-paths.d.mts +14 -0
- package/dist/clis/real-paths.d.mts.map +1 -0
- package/dist/clis/real-paths.mjs +36 -0
- package/dist/clis/real-paths.mjs.map +1 -0
- package/dist/clis/retired-flags.d.mts +45 -0
- package/dist/clis/retired-flags.d.mts.map +1 -0
- package/dist/clis/retired-flags.mjs +55 -0
- package/dist/clis/retired-flags.mjs.map +1 -0
- package/dist/clis/rolldown-runtime-B4iAMlE-.mjs +35 -0
- package/dist/clis/types-CZU17kAm.d.mts +2510 -0
- package/dist/clis/types-CZU17kAm.d.mts.map +1 -0
- package/dist/clis/utils.d.mts.map +1 -1
- package/dist/clis/utils.mjs.map +1 -1
- package/dist/{config-loader-C6dZB_iX.js → config-loader-B7SqNz8z.js} +24 -6
- package/dist/config-loader-B7SqNz8z.js.map +1 -0
- package/dist/connect/app-shell.d.ts +48 -0
- package/dist/connect/app-shell.d.ts.map +1 -0
- package/dist/connect/app-shell.js +90 -0
- package/dist/connect/app-shell.js.map +1 -0
- package/dist/connect/config-loader.d.ts +8 -1
- package/dist/connect/config-loader.d.ts.map +1 -1
- package/dist/connect/config-loader.js +2 -2
- package/dist/connect/connect-config-schema.d.ts +3 -0
- package/dist/connect/connect-config-schema.js +486 -0
- package/dist/connect/connect-config-schema.js.map +1 -0
- package/dist/connect/image-ref.d.ts +32 -0
- package/dist/connect/image-ref.d.ts.map +1 -0
- package/dist/connect/image-ref.js +80 -0
- package/dist/connect/image-ref.js.map +1 -0
- package/dist/connect/index.d.ts +84 -635
- package/dist/connect/index.d.ts.map +1 -1
- package/dist/connect/index.js +216 -553
- package/dist/connect/index.js.map +1 -1
- package/dist/connect/origin-placeholder.d.ts +52 -0
- package/dist/connect/origin-placeholder.d.ts.map +1 -0
- package/dist/connect/origin-placeholder.js +101 -0
- package/dist/connect/origin-placeholder.js.map +1 -0
- package/dist/connect-config-schema-cBfkNo1b.d.ts +1872 -0
- package/dist/connect-config-schema-cBfkNo1b.d.ts.map +1 -0
- package/dist/constants-5UFY_rXh.d.ts +9 -0
- package/dist/constants-5UFY_rXh.d.ts.map +1 -0
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +22 -6
- package/dist/constants.js.map +1 -1
- package/dist/document-drive/index.d.ts +3 -4
- package/dist/document-drive/index.d.ts.map +1 -1
- package/dist/document-drive/index.js +2 -13
- package/dist/document-drive/index.js.map +1 -1
- package/dist/document-model/action-id.d.ts +3 -0
- package/dist/document-model/action-id.js +59 -0
- package/dist/document-model/action-id.js.map +1 -0
- package/dist/document-model/dispatch.d.ts +25 -0
- package/dist/document-model/dispatch.d.ts.map +1 -0
- package/dist/document-model/dispatch.js +0 -0
- package/dist/document-model/errors.d.ts +3 -0
- package/dist/document-model/errors.js +214 -0
- package/dist/document-model/errors.js.map +1 -0
- package/dist/document-model/index.d.ts +5 -4
- package/dist/document-model/index.js +7 -5521
- package/dist/document-model/utils.d.ts +3 -2
- package/dist/document-model/utils.js +3 -2
- package/dist/document-model/version.d.ts +3 -0
- package/dist/document-model/version.js +8 -0
- package/dist/document-model/version.js.map +1 -0
- package/dist/document-model-CqySIaKV.js +5805 -0
- package/dist/document-model-CqySIaKV.js.map +1 -0
- package/dist/host-tokens/index.d.ts +3 -0
- package/dist/host-tokens/index.js +2 -0
- package/dist/host-tokens-DOeyxqLi.js +322 -0
- package/dist/host-tokens-DOeyxqLi.js.map +1 -0
- package/dist/{index-5gwOhPG5.d.ts → index-CUZ8eWun.d.ts} +2 -2
- package/dist/{index-5gwOhPG5.d.ts.map → index-CUZ8eWun.d.ts.map} +1 -1
- package/dist/index-D58WVj_E.d.ts +246 -0
- package/dist/index-D58WVj_E.d.ts.map +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/processors/index.d.ts +2 -2
- package/dist/processors/index.js +177 -68
- package/dist/processors/index.js.map +1 -1
- package/dist/processors/testing.d.ts +22 -0
- package/dist/processors/testing.d.ts.map +1 -0
- package/dist/processors/testing.js +77 -0
- package/dist/processors/testing.js.map +1 -0
- package/dist/purge-CbAV5DVh.js +631 -0
- package/dist/purge-CbAV5DVh.js.map +1 -0
- package/dist/registry/index.d.ts +3 -3
- package/dist/registry/index.js +52 -9
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/manifest-slim.d.ts +2 -2
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/types-CV2j3BvH.d.ts +5709 -0
- package/dist/types-CV2j3BvH.d.ts.map +1 -0
- package/dist/{types-CI3ren9F.d.ts → types-D_6ZcaJj.d.ts} +20 -12
- package/dist/types-D_6ZcaJj.d.ts.map +1 -0
- package/dist/{utils-CSF716ux.js → utils-DiV32YIj.js} +45 -2
- package/dist/utils-DiV32YIj.js.map +1 -0
- package/dist/utils-MrLmLEVr.js +78 -0
- package/dist/utils-MrLmLEVr.js.map +1 -0
- package/dist/version-BxLITo9P.d.ts +6 -0
- package/dist/version-BxLITo9P.d.ts.map +1 -0
- package/package.json +37 -3
- package/dist/clis/args/access-token-3Hqv_U8I.mjs +0 -22
- package/dist/clis/args/access-token-3Hqv_U8I.mjs.map +0 -1
- package/dist/clis/args/access-token-C5sKsH2O.d.mts.map +0 -1
- package/dist/clis/args/common-BXabdhiO.mjs.map +0 -1
- package/dist/clis/args/common-Bnm859xU.d.mts.map +0 -1
- package/dist/clis/args/connect-BG3HkYBk.mjs +0 -203
- package/dist/clis/args/connect-BG3HkYBk.mjs.map +0 -1
- package/dist/clis/args/connect-DjeiqXus.d.mts +0 -450
- package/dist/clis/args/connect-DjeiqXus.d.mts.map +0 -1
- package/dist/clis/args/generate-BOItUNvP.mjs.map +0 -1
- package/dist/clis/args/generate-BPBBLeUD.d.mts +0 -103
- package/dist/clis/args/generate-BPBBLeUD.d.mts.map +0 -1
- package/dist/clis/args/help-DS1NlcJQ.mjs.map +0 -1
- package/dist/clis/args/help-DVPTARGn.d.mts.map +0 -1
- package/dist/clis/args/init-CFeTq4Cq.d.mts +0 -52
- package/dist/clis/args/init-CFeTq4Cq.d.mts.map +0 -1
- package/dist/clis/args/init-Dvb42Y87.mjs +0 -67
- package/dist/clis/args/init-Dvb42Y87.mjs.map +0 -1
- package/dist/clis/args/inspect-BjRmtB86.d.mts +0 -13
- package/dist/clis/args/inspect-BjRmtB86.d.mts.map +0 -1
- package/dist/clis/args/inspect-UNQgtuR0.mjs +0 -15
- package/dist/clis/args/inspect-UNQgtuR0.mjs.map +0 -1
- package/dist/clis/args/install-B0tMyUMw.d.mts +0 -37
- package/dist/clis/args/install-B0tMyUMw.d.mts.map +0 -1
- package/dist/clis/args/install-F-27kF6m.mjs +0 -32
- package/dist/clis/args/install-F-27kF6m.mjs.map +0 -1
- package/dist/clis/args/list-Bkfn8Yuo.mjs +0 -7
- package/dist/clis/args/list-Bkfn8Yuo.mjs.map +0 -1
- package/dist/clis/args/list-DrbxA7JJ.d.mts +0 -10
- package/dist/clis/args/list-DrbxA7JJ.d.mts.map +0 -1
- package/dist/clis/args/login-CIFkQExi.mjs +0 -40
- package/dist/clis/args/login-CIFkQExi.mjs.map +0 -1
- package/dist/clis/args/login-CXRJXg71.d.mts.map +0 -1
- package/dist/clis/args/magic-string.es-BWtG0AyA.mjs +0 -1019
- package/dist/clis/args/magic-string.es-BWtG0AyA.mjs.map +0 -1
- package/dist/clis/args/migrate-DkCQRL2D.d.mts +0 -19
- package/dist/clis/args/migrate-DkCQRL2D.d.mts.map +0 -1
- package/dist/clis/args/migrate-DwJGhc2d.mjs +0 -29
- package/dist/clis/args/migrate-DwJGhc2d.mjs.map +0 -1
- package/dist/clis/args/publish-CeW4bOrl.d.mts +0 -16
- package/dist/clis/args/publish-CeW4bOrl.d.mts.map +0 -1
- package/dist/clis/args/publish-DHqlGWmL.mjs +0 -19
- package/dist/clis/args/publish-DHqlGWmL.mjs.map +0 -1
- package/dist/clis/args/registry-DIwES3l2.mjs +0 -23
- package/dist/clis/args/registry-DIwES3l2.mjs.map +0 -1
- package/dist/clis/args/registry-DNH8xuaE.d.mts +0 -17
- package/dist/clis/args/registry-DNH8xuaE.d.mts.map +0 -1
- package/dist/clis/args/service-BBx5GDTc.d.mts.map +0 -1
- package/dist/clis/args/service-Cpjlyeu5.mjs +0 -11
- package/dist/clis/args/service-Cpjlyeu5.mjs.map +0 -1
- package/dist/clis/args/switchboard-CCaAtU56.mjs +0 -85
- package/dist/clis/args/switchboard-CCaAtU56.mjs.map +0 -1
- package/dist/clis/args/switchboard-RrNb1fUH.d.mts +0 -70
- package/dist/clis/args/switchboard-RrNb1fUH.d.mts.map +0 -1
- package/dist/clis/args/uninstall-3U0B8g5c.mjs +0 -16
- package/dist/clis/args/uninstall-3U0B8g5c.mjs.map +0 -1
- package/dist/clis/args/uninstall-CDx7lwxn.d.mts.map +0 -1
- package/dist/clis/args/unpublish-CEDsk6uv.d.mts.map +0 -1
- package/dist/clis/args/unpublish-s9zUh6Gw.mjs +0 -30
- package/dist/clis/args/unpublish-s9zUh6Gw.mjs.map +0 -1
- package/dist/clis/args/vetra-BUNlAAPp.mjs.map +0 -1
- package/dist/clis/args/vetra-DkDaWFPi.d.mts +0 -111
- package/dist/clis/args/vetra-DkDaWFPi.d.mts.map +0 -1
- package/dist/clis/args/vetra-ports.test.d.mts +0 -2
- package/dist/clis/args/vetra-ports.test.mjs +0 -13354
- package/dist/clis/args/vetra-ports.test.mjs.map +0 -1
- package/dist/clis/build-config-CmdMi_wu.mjs.map +0 -1
- package/dist/clis/types-nzer4WIr.d.mts +0 -541
- package/dist/clis/types-nzer4WIr.d.mts.map +0 -1
- package/dist/config-loader-C6dZB_iX.js.map +0 -1
- package/dist/constants-DO4IYxuR.d.ts +0 -9
- package/dist/constants-DO4IYxuR.d.ts.map +0 -1
- package/dist/document-model/index.js.map +0 -1
- package/dist/index-D6833Siv.d.ts +0 -939
- package/dist/index-D6833Siv.d.ts.map +0 -1
- package/dist/types-CI3ren9F.d.ts.map +0 -1
- package/dist/types-CmeoQg_J.d.ts +0 -3337
- package/dist/types-CmeoQg_J.d.ts.map +0 -1
- package/dist/utils-BrKxCmKx.d.ts +0 -18
- package/dist/utils-BrKxCmKx.d.ts.map +0 -1
- package/dist/utils-CSF716ux.js.map +0 -1
|
@@ -1,10 +1,183 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as PIECE_ENTRY_GLOB, s as buildPieceBuildConfig } from "./build-config-BM1RL4u_.mjs";
|
|
2
|
+
import { isBuiltin } from "node:module";
|
|
2
3
|
import { tmpdir } from "node:os";
|
|
3
4
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
|
-
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
6
|
import { execFileSync } from "node:child_process";
|
|
7
|
+
//#region clis/external-deps.mts
|
|
8
|
+
const createDetectionCache = () => ({
|
|
9
|
+
files: /* @__PURE__ */ new Map(),
|
|
10
|
+
wasm: /* @__PURE__ */ new Map()
|
|
11
|
+
});
|
|
12
|
+
const NODE_MODULES = `${sep}node_modules${sep}`;
|
|
13
|
+
/** `file` relative to `root`, with forward slashes on every platform. */
|
|
14
|
+
function projectPath(root, file) {
|
|
15
|
+
return relative(root, file).split(sep).join("/");
|
|
16
|
+
}
|
|
17
|
+
const samePath = (file) => process.platform === "win32" ? file.toLowerCase() : file;
|
|
18
|
+
function packageNameOf(specifier) {
|
|
19
|
+
if (specifier.startsWith(".") || isAbsolute(specifier)) return void 0;
|
|
20
|
+
const parts = specifier.split("/");
|
|
21
|
+
return (specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]) || void 0;
|
|
22
|
+
}
|
|
23
|
+
function packageRootOf(file) {
|
|
24
|
+
const at = file.lastIndexOf(NODE_MODULES);
|
|
25
|
+
if (at < 0) return void 0;
|
|
26
|
+
const rest = file.slice(at + NODE_MODULES.length).split(sep);
|
|
27
|
+
const depth = rest[0]?.startsWith("@") ? 2 : 1;
|
|
28
|
+
if (rest.length <= depth) return void 0;
|
|
29
|
+
return join(file.slice(0, at + NODE_MODULES.length), ...rest.slice(0, depth));
|
|
30
|
+
}
|
|
31
|
+
function readPackageJson(root) {
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
34
|
+
} catch {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function requires(importerRoot, importedRoot) {
|
|
39
|
+
const importer = readPackageJson(importerRoot);
|
|
40
|
+
const name = readPackageJson(importedRoot)?.name;
|
|
41
|
+
if (!importer || !name) return false;
|
|
42
|
+
return importer.dependencies?.[name] !== void 0 || importer.optionalDependencies?.[name] !== void 0;
|
|
43
|
+
}
|
|
44
|
+
function wasmIn(root, cache) {
|
|
45
|
+
if (cache?.wasm.has(root)) return cache.wasm.get(root);
|
|
46
|
+
const found = scanForWasm(root);
|
|
47
|
+
cache?.wasm.set(root, found);
|
|
48
|
+
return found;
|
|
49
|
+
}
|
|
50
|
+
function scanForWasm(root) {
|
|
51
|
+
try {
|
|
52
|
+
const found = readdirSync(root, {
|
|
53
|
+
recursive: true,
|
|
54
|
+
encoding: "utf8"
|
|
55
|
+
}).find((file) => file.endsWith(".wasm") && !file.split(sep).includes("node_modules"));
|
|
56
|
+
return found && join(root, found);
|
|
57
|
+
} catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** The first file `entry` cannot load without that a bundle cannot carry. */
|
|
62
|
+
async function findRequiredFile(entry, trace, cache) {
|
|
63
|
+
const { fileList, reasons } = await trace(entry);
|
|
64
|
+
const start = samePath(realpathSync(entry));
|
|
65
|
+
const candidates = [...fileList].filter((file) => file.endsWith(".node")).map((file) => ({
|
|
66
|
+
file,
|
|
67
|
+
kind: "native",
|
|
68
|
+
from: file
|
|
69
|
+
}));
|
|
70
|
+
{
|
|
71
|
+
const traced = /* @__PURE__ */ new Map();
|
|
72
|
+
for (const file of fileList) {
|
|
73
|
+
const root = packageRootOf(file);
|
|
74
|
+
if (root && !traced.has(root) && /\.[cm]?js$/.test(file)) traced.set(root, file);
|
|
75
|
+
}
|
|
76
|
+
const tracedWasm = [...fileList].filter((file) => file.endsWith(".wasm"));
|
|
77
|
+
for (const [root, from] of traced) {
|
|
78
|
+
const file = tracedWasm.find((wasm) => packageRootOf(wasm) === root) ?? wasmIn(root, cache);
|
|
79
|
+
if (file) candidates.push({
|
|
80
|
+
file,
|
|
81
|
+
kind: "wasm",
|
|
82
|
+
from
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (const { from, ...required } of candidates) {
|
|
87
|
+
const seen = /* @__PURE__ */ new Set([from]);
|
|
88
|
+
const queue = [from];
|
|
89
|
+
while (queue.length > 0) {
|
|
90
|
+
const file = queue.shift();
|
|
91
|
+
if (samePath(file) === start) return required;
|
|
92
|
+
for (const parent of reasons.get(file)?.parents ?? []) {
|
|
93
|
+
if (seen.has(parent)) continue;
|
|
94
|
+
const fromRoot = packageRootOf(parent);
|
|
95
|
+
const toRoot = packageRootOf(file);
|
|
96
|
+
if (fromRoot !== toRoot && (!fromRoot || !toRoot || !requires(fromRoot, toRoot))) continue;
|
|
97
|
+
seen.add(parent);
|
|
98
|
+
queue.push(parent);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Keeps each package the code imports that needs such a file out of the bundle. */
|
|
104
|
+
function externalDepsPlugin(trace, found, options = {}) {
|
|
105
|
+
const cache = options.cache ?? createDetectionCache();
|
|
106
|
+
const root = options.root ?? process.cwd();
|
|
107
|
+
const show = (file) => projectPath(root, file);
|
|
108
|
+
const inDir = (id, dirs = []) => dirs.some((dir) => show(id).startsWith(`${dir}/`));
|
|
109
|
+
const detect = (id) => {
|
|
110
|
+
let verdict = cache.files.get(id);
|
|
111
|
+
if (!verdict) {
|
|
112
|
+
verdict = findRequiredFile(id, trace, cache);
|
|
113
|
+
cache.files.set(id, verdict);
|
|
114
|
+
}
|
|
115
|
+
return verdict;
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
name: "powerhouse:external-deps",
|
|
119
|
+
async resolveId(source, importer, extra) {
|
|
120
|
+
if (!importer || importer.includes(NODE_MODULES)) return null;
|
|
121
|
+
if (isBuiltin(source) || inDir(importer, options.ignoreDirs)) return null;
|
|
122
|
+
const name = packageNameOf(source);
|
|
123
|
+
if (!name) return null;
|
|
124
|
+
const resolved = await this.resolve(source, importer, {
|
|
125
|
+
...extra,
|
|
126
|
+
skipSelf: true
|
|
127
|
+
});
|
|
128
|
+
if (!resolved || resolved.external) return null;
|
|
129
|
+
const required = await detect(resolved.id);
|
|
130
|
+
const pkgRoot = packageRootOf(resolved.id);
|
|
131
|
+
const version = pkgRoot ? readPackageJson(pkgRoot)?.version : void 0;
|
|
132
|
+
if (!required || !version) return null;
|
|
133
|
+
const what = required.kind === "native" ? `the native addon ${show(required.file)}` : `the WebAssembly module ${show(required.file)}`;
|
|
134
|
+
if (options.browser) {
|
|
135
|
+
if (required.kind === "wasm") return null;
|
|
136
|
+
throw new Error(`${show(importer)} imports ${name}, which needs ${what}. Native code cannot run in the browser: import it only from subgraphs, switchboard processors or pieces.`);
|
|
137
|
+
}
|
|
138
|
+
if (inDir(importer, options.forbidDirs)) throw new Error(`${show(importer)} imports ${name}, which needs ${what}. Document models and scalars run in Connect and on every host: use it from a subgraph, processor or piece instead.`);
|
|
139
|
+
if (!found.has(name)) found.set(name, {
|
|
140
|
+
name,
|
|
141
|
+
version,
|
|
142
|
+
...required,
|
|
143
|
+
importer
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
id: source,
|
|
147
|
+
external: true
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The detected packages `pkg` does not install for its consumers: anything
|
|
154
|
+
* outside dependencies, optionalDependencies and peerDependencies.
|
|
155
|
+
*/
|
|
156
|
+
function undeclaredExternalDependencies(found, pkg) {
|
|
157
|
+
return [...found].filter((dep) => pkg.dependencies?.[dep.name] === void 0 && pkg.optionalDependencies?.[dep.name] === void 0 && pkg.peerDependencies?.[dep.name] === void 0);
|
|
158
|
+
}
|
|
159
|
+
/** name -> version, sorted by name. */
|
|
160
|
+
function externalDependencyVersions(found) {
|
|
161
|
+
return Object.fromEntries([...found].sort((a, b) => a.name.localeCompare(b.name)).map((dep) => [dep.name, dep.version]));
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
6
164
|
//#region clis/build-pieces.mts
|
|
7
165
|
const toPosix = (p) => p.split(sep).join("/");
|
|
166
|
+
/** `relative(dir, path)` leaves `dir`: `..`, `../…`, or another root. */
|
|
167
|
+
const leaves = (inside) => inside === ".." || inside.startsWith(`..${sep}`) || isAbsolute(inside);
|
|
168
|
+
function onDisk(path, redirect) {
|
|
169
|
+
if (!redirect) return path;
|
|
170
|
+
const inside = relative(redirect.from, path);
|
|
171
|
+
return leaves(inside) ? path : join(redirect.to, inside);
|
|
172
|
+
}
|
|
173
|
+
function toLogical(path, redirect) {
|
|
174
|
+
if (!redirect) return path;
|
|
175
|
+
for (const dir of [redirect.to, redirect.toReal]) {
|
|
176
|
+
const inside = relative(dir, path);
|
|
177
|
+
if (!leaves(inside)) return join(redirect.from, inside);
|
|
178
|
+
}
|
|
179
|
+
return path;
|
|
180
|
+
}
|
|
8
181
|
function statSafe(p) {
|
|
9
182
|
try {
|
|
10
183
|
return statSync(p);
|
|
@@ -12,6 +185,13 @@ function statSafe(p) {
|
|
|
12
185
|
return null;
|
|
13
186
|
}
|
|
14
187
|
}
|
|
188
|
+
function realpathSafe(p) {
|
|
189
|
+
try {
|
|
190
|
+
return realpathSync(p);
|
|
191
|
+
} catch {
|
|
192
|
+
return p;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
15
195
|
function expandEntryGlobs(root, globs) {
|
|
16
196
|
const files = /* @__PURE__ */ new Set();
|
|
17
197
|
for (const pattern of globs) {
|
|
@@ -113,11 +293,19 @@ function createJsonReplacer() {
|
|
|
113
293
|
`;
|
|
114
294
|
const DESCRIBE_SCRIPT = `
|
|
115
295
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
116
|
-
import { isAbsolute, join } from "node:path";
|
|
296
|
+
import { isAbsolute, join, relative, sep } from "node:path";
|
|
117
297
|
import { pathToFileURL } from "node:url";
|
|
118
298
|
|
|
119
299
|
const job = JSON.parse(readFileSync(process.argv[2], "utf8"));
|
|
120
300
|
${DESCRIBE_HELPERS}
|
|
301
|
+
// The parent's onDisk, for the paths a list names under the output directory.
|
|
302
|
+
function onDisk(path) {
|
|
303
|
+
if (!job.redirect) return path;
|
|
304
|
+
const inside = relative(job.redirect.from, path);
|
|
305
|
+
const leaves = inside === ".." || inside.startsWith(".." + sep) || isAbsolute(inside);
|
|
306
|
+
return leaves ? path : join(job.redirect.to, inside);
|
|
307
|
+
}
|
|
308
|
+
|
|
121
309
|
// Says why the child gave up in the one place the parent always reads, so a
|
|
122
310
|
// failure reports the cause and never the text of this script.
|
|
123
311
|
function fail(message) {
|
|
@@ -131,7 +319,7 @@ function entryFile(piece) {
|
|
|
131
319
|
if (typeof declared !== "string") return undefined;
|
|
132
320
|
const path = isAbsolute(declared) ? declared : join(job.projectRoot, declared);
|
|
133
321
|
if (piece.entry) return path;
|
|
134
|
-
const pkgFile = join(path, "package.json");
|
|
322
|
+
const pkgFile = join(onDisk(path), "package.json");
|
|
135
323
|
if (!existsSync(pkgFile)) return undefined;
|
|
136
324
|
const pkg = JSON.parse(readFileSync(pkgFile, "utf8"));
|
|
137
325
|
return join(path, typeof pkg.main === "string" ? pkg.main : "index.mjs");
|
|
@@ -139,7 +327,7 @@ function entryFile(piece) {
|
|
|
139
327
|
|
|
140
328
|
let listModule;
|
|
141
329
|
try {
|
|
142
|
-
listModule = await import(pathToFileURL(job.listPath).href);
|
|
330
|
+
listModule = await import(pathToFileURL(onDisk(job.listPath)).href);
|
|
143
331
|
} catch (error) {
|
|
144
332
|
fail(job.listPath + " threw on import: " + (error instanceof Error ? error.message : String(error)));
|
|
145
333
|
}
|
|
@@ -152,9 +340,9 @@ const out = { list, pieces: [], errors: [] };
|
|
|
152
340
|
for (const piece of list) {
|
|
153
341
|
const file = entryFile(piece);
|
|
154
342
|
// A missing file is the parent's to report, with the message it owns.
|
|
155
|
-
if (!file || !existsSync(file)) continue;
|
|
343
|
+
if (!file || !existsSync(onDisk(file))) continue;
|
|
156
344
|
try {
|
|
157
|
-
const mod = await import(pathToFileURL(file).href);
|
|
345
|
+
const mod = await import(pathToFileURL(onDisk(file)).href);
|
|
158
346
|
const found = findPiece(mod);
|
|
159
347
|
if (!found) {
|
|
160
348
|
throw new Error(
|
|
@@ -182,6 +370,9 @@ function childFailure(error, outFile) {
|
|
|
182
370
|
return `the describe child exited with code ${status ?? "unknown"}`;
|
|
183
371
|
}
|
|
184
372
|
function describePieces(projectRoot, listPath) {
|
|
373
|
+
return describePiecesThrough(projectRoot, listPath, void 0);
|
|
374
|
+
}
|
|
375
|
+
function describePiecesThrough(projectRoot, listPath, redirect) {
|
|
185
376
|
const dir = mkdtempSync(join(tmpdir(), "ph-build-pieces-"));
|
|
186
377
|
const rel = toPosix(relative(projectRoot, listPath));
|
|
187
378
|
try {
|
|
@@ -192,7 +383,8 @@ function describePieces(projectRoot, listPath) {
|
|
|
192
383
|
writeFileSync(jobFile, JSON.stringify({
|
|
193
384
|
projectRoot,
|
|
194
385
|
listPath,
|
|
195
|
-
outFile
|
|
386
|
+
outFile,
|
|
387
|
+
redirect
|
|
196
388
|
}));
|
|
197
389
|
try {
|
|
198
390
|
execFileSync(process.execPath, [scriptFile, jobFile], {
|
|
@@ -211,17 +403,22 @@ function describePieces(projectRoot, listPath) {
|
|
|
211
403
|
}
|
|
212
404
|
}
|
|
213
405
|
function resolvePieceLocation(piece, projectRoot, outDir) {
|
|
406
|
+
return locatePieceThrough(piece, projectRoot, outDir, void 0);
|
|
407
|
+
}
|
|
408
|
+
function locatePieceThrough(piece, projectRoot, outDir, redirect) {
|
|
214
409
|
const declared = piece.entry ?? piece.bundle;
|
|
215
410
|
if (typeof declared !== "string" || declared === "") throw new Error(`pieces: "${piece.name}" declares neither an entry nor a bundle`);
|
|
216
|
-
const
|
|
411
|
+
const shown = isAbsolute(declared) ? toLogical(declared, redirect) : declared;
|
|
412
|
+
const path = isAbsolute(declared) ? shown : join(projectRoot, declared);
|
|
217
413
|
const form = piece.entry ? "entry" : "bundle";
|
|
218
|
-
|
|
414
|
+
const disk = onDisk(path, redirect);
|
|
415
|
+
if (!(form === "entry" ? statSafe(disk)?.isFile() : statSafe(join(disk, "package.json"))?.isFile())) throw new Error(`pieces: "${piece.name}" declares ${shown}, which is missing`);
|
|
219
416
|
const dir = form === "entry" ? dirname(path) : path;
|
|
220
417
|
const piecesRoot = resolve(projectRoot, outDir, "node", "pieces");
|
|
221
418
|
const inside = relative(piecesRoot, dir);
|
|
222
419
|
if (inside === "" || inside.startsWith("..") || isAbsolute(inside)) {
|
|
223
420
|
const expected = toPosix(join(outDir, "node", "pieces"));
|
|
224
|
-
throw new Error(`pieces: "${piece.name}" declares ${
|
|
421
|
+
throw new Error(`pieces: "${piece.name}" declares ${shown}, which is outside ${expected}/; a piece is built to ${expected}/<dir>/index.mjs and its entry must point there`);
|
|
225
422
|
}
|
|
226
423
|
return form === "entry" ? {
|
|
227
424
|
dir,
|
|
@@ -250,7 +447,7 @@ function piecePackageJson(options) {
|
|
|
250
447
|
type: "module",
|
|
251
448
|
main: options.main,
|
|
252
449
|
...options.license ? { license: options.license } : {},
|
|
253
|
-
dependencies: {}
|
|
450
|
+
dependencies: options.dependencies ?? {}
|
|
254
451
|
};
|
|
255
452
|
}
|
|
256
453
|
function bundlePackageJson(dir, version) {
|
|
@@ -301,20 +498,35 @@ const count = (record) => typeof record === "object" && record !== null ? Object
|
|
|
301
498
|
async function buildPieces(target, pkg, options) {
|
|
302
499
|
const { projectRoot, outDir } = target;
|
|
303
500
|
assertPiecesOutDir(target);
|
|
501
|
+
const redirect = target.writeTo ? {
|
|
502
|
+
from: resolve(projectRoot, outDir),
|
|
503
|
+
to: target.writeTo,
|
|
504
|
+
toReal: realpathSafe(target.writeTo)
|
|
505
|
+
} : void 0;
|
|
506
|
+
const externalByDir = /* @__PURE__ */ new Map();
|
|
304
507
|
for (const piece of target.pieces) {
|
|
305
508
|
console.log(`\n▶ Building piece ${piece.dir}...`);
|
|
509
|
+
const outDir = resolve(projectRoot, piece.outDir);
|
|
510
|
+
const external = /* @__PURE__ */ new Map();
|
|
306
511
|
await options.bundle(buildPieceBuildConfig({
|
|
307
512
|
entry: resolve(projectRoot, piece.entry),
|
|
308
|
-
outDir:
|
|
513
|
+
outDir: onDisk(outDir, redirect),
|
|
514
|
+
...options.trace ? { plugins: [externalDepsPlugin(options.trace, external, {
|
|
515
|
+
root: projectRoot,
|
|
516
|
+
...options.cache ? { cache: options.cache } : {}
|
|
517
|
+
})] } : {}
|
|
309
518
|
}));
|
|
519
|
+
for (const dep of external.values()) console.log(`piece ${piece.dir}: ${dep.name}@${dep.version} stays external, it needs ${projectPath(projectRoot, dep.file)}`);
|
|
520
|
+
externalByDir.set(outDir, external);
|
|
310
521
|
}
|
|
311
522
|
const listPath = pieceListPath(target);
|
|
312
|
-
if (!existsSync(listPath)) throw new Error(`pieces: ${toPosix(relative(projectRoot, listPath))} was not built; pieces/index.ts must export the list of pieces this package ships`);
|
|
313
|
-
const described =
|
|
523
|
+
if (!existsSync(onDisk(listPath, redirect))) throw new Error(`pieces: ${toPosix(relative(projectRoot, listPath))} was not built; pieces/index.ts must export the list of pieces this package ships`);
|
|
524
|
+
const described = describePiecesThrough(projectRoot, listPath, redirect);
|
|
314
525
|
const built = [];
|
|
315
526
|
const listedDirs = /* @__PURE__ */ new Set();
|
|
316
527
|
for (const piece of described.list) {
|
|
317
|
-
const location =
|
|
528
|
+
const location = locatePieceThrough(piece, projectRoot, outDir, redirect);
|
|
529
|
+
const dirOnDisk = onDisk(location.dir, redirect);
|
|
318
530
|
assertPieceVersion(piece, pkg);
|
|
319
531
|
const failure = described.errors.find((e) => e.name === piece.name);
|
|
320
532
|
if (failure) throw new Error(`pieces: "${piece.name}" could not be described: ${failure.message}`);
|
|
@@ -323,15 +535,16 @@ async function buildPieces(target, pkg, options) {
|
|
|
323
535
|
const metadata = found.metadata;
|
|
324
536
|
const relDir = toPosix(relative(projectRoot, location.dir));
|
|
325
537
|
listedDirs.add(relDir);
|
|
326
|
-
writeFileSync(join(
|
|
538
|
+
writeFileSync(join(dirOnDisk, "descriptor.json"), JSON.stringify(pieceDescriptor(piece, pkg.version, metadata), createJsonReplacer(), 2) + "\n");
|
|
327
539
|
const piecePackage = location.form === "entry" && location.entryFile ? piecePackageJson({
|
|
328
540
|
name: piece.name,
|
|
329
541
|
version: pkg.version,
|
|
330
542
|
description: metadata.description,
|
|
331
543
|
main: relative(location.dir, location.entryFile),
|
|
332
|
-
license: pkg.license
|
|
333
|
-
|
|
334
|
-
|
|
544
|
+
license: pkg.license,
|
|
545
|
+
dependencies: externalDependencyVersions(externalByDir.get(resolve(location.dir))?.values() ?? [])
|
|
546
|
+
}) : bundlePackageJson(dirOnDisk, pkg.version);
|
|
547
|
+
writeFileSync(join(dirOnDisk, "package.json"), JSON.stringify(piecePackage, null, 2) + "\n");
|
|
335
548
|
console.log(`piece: ${piece.name}@${pkg.version} -> ${relDir} (${count(metadata.actions)} actions, ${count(metadata.triggers)} triggers)`);
|
|
336
549
|
built.push({
|
|
337
550
|
name: piece.name,
|
|
@@ -348,24 +561,34 @@ async function buildPieces(target, pkg, options) {
|
|
|
348
561
|
function warnUnlistedPieces(planned, listedDirs) {
|
|
349
562
|
for (const piece of planned) if (!listedDirs.has(toPosix(piece.outDir))) console.warn(`⚠ pieces: pieces/${piece.dir} was built but pieces/index.ts does not list it; a host will not find it`);
|
|
350
563
|
}
|
|
351
|
-
function syncDistManifest(target, built) {
|
|
564
|
+
function syncDistManifest(target, built, externalDependencies = {}) {
|
|
352
565
|
const { projectRoot, outDir } = target;
|
|
353
566
|
const source = join(projectRoot, "powerhouse.manifest.json");
|
|
354
567
|
const copy = resolve(projectRoot, outDir, "powerhouse.manifest.json");
|
|
355
568
|
const shipsPieces = existsSync(pieceListPath(target));
|
|
569
|
+
const shipsExternal = Object.keys(externalDependencies).length > 0;
|
|
356
570
|
if (!existsSync(source)) {
|
|
357
571
|
if (shipsPieces) console.warn("⚠ no powerhouse.manifest.json; pieces will not be listed");
|
|
572
|
+
if (shipsExternal) console.warn("⚠ no powerhouse.manifest.json; external dependencies will not be listed");
|
|
358
573
|
return;
|
|
359
574
|
}
|
|
360
575
|
mkdirSync(dirname(copy), { recursive: true });
|
|
361
576
|
copyFileSync(source, copy);
|
|
362
|
-
if (!shipsPieces) return copy;
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
577
|
+
if (!shipsPieces && !shipsExternal) return copy;
|
|
578
|
+
let manifest = JSON.parse(readFileSync(copy, "utf8"));
|
|
579
|
+
if (shipsPieces) {
|
|
580
|
+
const enriched = enrichManifestPieces(manifest, built);
|
|
581
|
+
for (const id of enriched.unbuilt) console.warn(`⚠ manifest lists piece "${id}" but nothing built it`);
|
|
582
|
+
manifest = enriched.manifest;
|
|
583
|
+
}
|
|
584
|
+
if (shipsExternal) manifest = {
|
|
585
|
+
...manifest,
|
|
586
|
+
externalDependencies
|
|
587
|
+
};
|
|
588
|
+
writeFileSync(copy, JSON.stringify(manifest, null, 2) + "\n");
|
|
366
589
|
return copy;
|
|
367
590
|
}
|
|
368
591
|
//#endregion
|
|
369
|
-
export { DESCRIBE_HELPERS, DESCRIBE_SCRIPT, assertPieceVersion, assertPiecesOutDir, buildPieces, bundlePackageJson, createJsonReplacer, describePieces, enrichManifestPieces, expandEntryGlobs, pieceDescriptor, pieceListPath, piecePackageJson, planPieces, resolvePieceLocation, statSafe, syncDistManifest };
|
|
592
|
+
export { DESCRIBE_HELPERS, DESCRIBE_SCRIPT, assertPieceVersion, assertPiecesOutDir, buildPieces, bundlePackageJson, createDetectionCache, createJsonReplacer, describePieces, enrichManifestPieces, expandEntryGlobs, externalDependencyVersions, externalDepsPlugin, findRequiredFile, pieceDescriptor, pieceListPath, piecePackageJson, planPieces, projectPath, resolvePieceLocation, statSafe, syncDistManifest, undeclaredExternalDependencies };
|
|
370
593
|
|
|
371
594
|
//# sourceMappingURL=build-pieces.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-pieces.mjs","names":[],"sources":["../../clis/build-pieces.mts"],"sourcesContent":["// The pieces half of a package build: find and bundle each piece whole, load\n// it once in a child process to learn what it is, and write what a host reads.\nimport { execFileSync } from \"node:child_process\";\nimport {\n copyFileSync,\n existsSync,\n mkdirSync,\n mkdtempSync,\n readdirSync,\n readFileSync,\n rmSync,\n statSync,\n writeFileSync,\n} from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport {\n basename,\n dirname,\n isAbsolute,\n join,\n relative,\n resolve,\n sep,\n} from \"node:path\";\nimport type { InlineConfig } from \"tsdown\";\nimport type { Manifest, PieceModule } from \"../document-model/types.js\";\nimport { buildPieceBuildConfig, PIECE_ENTRY_GLOB } from \"./build-config.mjs\";\n\nexport type PiecePlan = {\n /** The directory under pieces/, and so under <outDir>/node/pieces. */\n dir: string;\n /** Source entry, relative to the project root: pieces/<dir>/index.ts. */\n entry: string;\n /** Where the piece lands, relative to the project root. */\n outDir: string;\n};\n\n// What buildPieces needs to know about the package it works in: where it is,\n// where it builds to, and which pieces the plan found.\nexport type PieceBuildTarget = {\n projectRoot: string;\n outDir: string;\n pieces: PiecePlan[];\n};\n\n// One entry of pieces/index.ts, as @powerhousedao/pieces-framework declares it.\n// Declared here so the build needs no dependency on a package meant for pieces.\nexport type PackagePiece = {\n name: string;\n entry?: string;\n bundle?: string;\n};\n\n// What a piece says about itself, in the framework's PieceMetadata shape.\n// Read from the built piece, so nothing in the build has to know the framework.\nexport type PieceMetadata = Record<string, unknown> & {\n displayName?: string;\n description?: string;\n actions?: Record<string, unknown>;\n triggers?: Record<string, unknown>;\n};\n\nexport type DescribedPiece = {\n name: string;\n metadata: PieceMetadata;\n};\n\nexport type DescribeResult = {\n list: PackagePiece[];\n pieces: DescribedPiece[];\n errors: { name: string; message: string }[];\n};\n\nexport type BuiltPiece = {\n name: string;\n version: string;\n displayName?: string;\n description?: string;\n /** Piece directory, relative to the project root, `/` separated. */\n bundle: string;\n /** The descriptor inside it, relative to the project root, `/` separated. */\n descriptor: string;\n};\n\nexport type PackageIdentity = {\n name: string;\n version: string;\n license?: string;\n};\n\nexport type PieceBuildOptions = {\n /** The bundler: tsdown's `build`, handed in so this module never loads it. */\n bundle: (config: InlineConfig) => Promise<unknown>;\n};\n\nconst toPosix = (p: string) => p.split(sep).join(\"/\");\n\nexport function statSafe(p: string) {\n try {\n return statSync(p);\n } catch {\n return null;\n }\n}\n\n// Expand entry globs (single-`*` segments only — the shape `browserEntry`\n// uses) against files on disk, resolving against `root`.\nexport function expandEntryGlobs(root: string, globs: string[]): string[] {\n const files = new Set<string>();\n for (const pattern of globs) {\n const segments = pattern.split(\"/\").filter(Boolean);\n let dirs = [root];\n for (const seg of segments) {\n const next: string[] = [];\n for (const d of dirs) {\n if (!statSafe(d)?.isDirectory()) continue;\n if (seg === \"*\") {\n for (const e of readdirSync(d, { withFileTypes: true })) {\n next.push(join(d, e.name));\n }\n } else {\n next.push(join(d, seg));\n }\n }\n dirs = next;\n }\n for (const f of dirs) {\n if (statSafe(f)?.isFile()) files.add(f);\n }\n }\n return [...files];\n}\n\n// The pieces a project holds, one per pieces/<dir>/index.ts, sorted by dir so\n// a build log and a manifest read the same from one run to the next.\nexport function planPieces(projectRoot: string, outDir: string): PiecePlan[] {\n return expandEntryGlobs(projectRoot, [PIECE_ENTRY_GLOB])\n .map((file) => {\n const dir = basename(dirname(file));\n return {\n dir,\n entry: relative(projectRoot, file),\n outDir: join(outDir, \"node\", \"pieces\", dir),\n };\n })\n .sort((a, b) => (a.dir < b.dir ? -1 : a.dir > b.dir ? 1 : 0));\n}\n\n// A JSON.stringify replacer that makes a piece's metadata serializable: props\n// carry resolvers, defaults may be class instances, and a schema may cycle.\nexport function createJsonReplacer() {\n const ancestors: object[] = [];\n return function replace(this: unknown, _key: string, value: unknown) {\n if (typeof value === \"function\" || value === undefined) return undefined;\n if (typeof value === \"bigint\") return value.toString();\n if (typeof value !== \"object\" || value === null) return value;\n // `this` is the holder, so popping back to it leaves the current path.\n while (ancestors.length > 0 && ancestors.at(-1) !== this) ancestors.pop();\n if (ancestors.includes(value)) return undefined;\n ancestors.push(value);\n return value;\n };\n}\n\n// The half of the child script that needs nothing from the job: a test\n// evaluates this text on its own, so neither copy can drift from the other.\n\n// `constructor?.name`: a module may export an Object.create(null), and the\n// real piece is usually beside it in the same module.\nexport const DESCRIBE_HELPERS = `\nconst isRecord = (value) => typeof value === \"object\" && value !== null;\n\nfunction findPiece(mod) {\n const candidates = [\n ...Object.values(mod),\n ...(isRecord(mod.default) ? Object.values(mod.default) : []),\n mod.default,\n ];\n for (const candidate of candidates) {\n if (isRecord(candidate) && candidate.constructor?.name === \"Piece\") {\n return candidate;\n }\n }\n for (const candidate of candidates) {\n if (\n isRecord(candidate) &&\n typeof candidate.displayName === \"string\" &&\n (isRecord(candidate.actions) ||\n typeof candidate.actions === \"function\" ||\n typeof candidate.getAction === \"function\")\n ) {\n return candidate;\n }\n }\n return undefined;\n}\n\nfunction describePiece(piece) {\n if (typeof piece.metadata === \"function\") return piece.metadata();\n const call = (value) => (typeof value === \"function\" ? value.call(piece) : value);\n return {\n displayName: piece.displayName,\n logoUrl: piece.logoUrl,\n description: piece.description,\n authors: piece.authors,\n categories: piece.categories,\n auth: piece.auth,\n minimumSupportedRelease: piece.minimumSupportedRelease,\n maximumSupportedRelease: piece.maximumSupportedRelease,\n deprecated: piece.deprecated,\n actions: call(piece.actions) ?? {},\n triggers: call(piece.triggers) ?? {},\n };\n}\n\nfunction createJsonReplacer() {\n const ancestors = [];\n return function replace(_key, value) {\n if (typeof value === \"function\" || value === undefined) return undefined;\n if (typeof value === \"bigint\") return value.toString();\n if (typeof value !== \"object\" || value === null) return value;\n while (ancestors.length > 0 && ancestors.at(-1) !== this) ancestors.pop();\n if (ancestors.includes(value)) return undefined;\n ancestors.push(value);\n return value;\n };\n}\n`;\n\n// Runs in a child node process: loading a piece runs piece-authored top-level\n// code, and the runtime describes pieces in a worker for the same reason.\n\n// A string so it works from `src` under bun or tsx as well as from `dist`. It\n// answers through a file, leaving both its streams to the piece.\nexport const DESCRIBE_SCRIPT = `\nimport { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { isAbsolute, join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nconst job = JSON.parse(readFileSync(process.argv[2], \"utf8\"));\n${DESCRIBE_HELPERS}\n// Says why the child gave up in the one place the parent always reads, so a\n// failure reports the cause and never the text of this script.\nfunction fail(message) {\n writeFileSync(job.outFile, JSON.stringify({ fatal: message }));\n process.exit(1);\n}\n\n// The module to load for a list entry; a bundle names its own main.\nfunction entryFile(piece) {\n const declared = piece.entry ?? piece.bundle;\n if (typeof declared !== \"string\") return undefined;\n const path = isAbsolute(declared) ? declared : join(job.projectRoot, declared);\n if (piece.entry) return path;\n const pkgFile = join(path, \"package.json\");\n if (!existsSync(pkgFile)) return undefined;\n const pkg = JSON.parse(readFileSync(pkgFile, \"utf8\"));\n return join(path, typeof pkg.main === \"string\" ? pkg.main : \"index.mjs\");\n}\n\nlet listModule;\ntry {\n listModule = await import(pathToFileURL(job.listPath).href);\n} catch (error) {\n fail(job.listPath + \" threw on import: \" + (error instanceof Error ? error.message : String(error)));\n}\nconst list = listModule.pieces ?? listModule.default;\nif (!Array.isArray(list)) {\n fail(job.listPath + ' exports no \"pieces\" array');\n}\n\nconst out = { list, pieces: [], errors: [] };\nfor (const piece of list) {\n const file = entryFile(piece);\n // A missing file is the parent's to report, with the message it owns.\n if (!file || !existsSync(file)) continue;\n try {\n const mod = await import(pathToFileURL(file).href);\n const found = findPiece(mod);\n if (!found) {\n throw new Error(\n \"no Piece export found in \" + file + \"; exports: \" + Object.keys(mod).join(\", \"),\n );\n }\n const metadata = JSON.parse(JSON.stringify(describePiece(found), createJsonReplacer()));\n out.pieces.push({ name: piece.name, metadata });\n } catch (error) {\n out.errors.push({\n name: piece.name,\n message: error instanceof Error ? error.message : String(error),\n });\n }\n}\nwriteFileSync(job.outFile, JSON.stringify(out, createJsonReplacer()));\n`;\n\n// What the child said went wrong, if it got that far, and otherwise how it\n// died: an exit status, never the whole script an `Error.message` carries.\nfunction childFailure(error: unknown, outFile: string): string {\n try {\n const answer = JSON.parse(readFileSync(outFile, \"utf8\")) as {\n fatal?: unknown;\n };\n if (typeof answer.fatal === \"string\") return answer.fatal;\n } catch {\n // no answer on disk: fall through to the exit status\n }\n const { status, signal } = error as {\n status?: number | null;\n signal?: string | null;\n };\n if (signal) return `the describe child was killed by ${signal}`;\n return `the describe child exited with code ${status ?? \"unknown\"}`;\n}\n\n// Load the built list and every piece it names in a child process and return\n// what they say about themselves. Throws when the list itself cannot be read.\n\n// Both of the child's streams are the parent's, so a piece that prints at\n// import time is heard rather than mixed into the answer.\nexport function describePieces(\n projectRoot: string,\n listPath: string,\n): DescribeResult {\n const dir = mkdtempSync(join(tmpdir(), \"ph-build-pieces-\"));\n const rel = toPosix(relative(projectRoot, listPath));\n try {\n const jobFile = join(dir, \"job.json\");\n const scriptFile = join(dir, \"describe.mjs\");\n const outFile = join(dir, \"describe.json\");\n writeFileSync(scriptFile, DESCRIBE_SCRIPT);\n writeFileSync(jobFile, JSON.stringify({ projectRoot, listPath, outFile }));\n try {\n execFileSync(process.execPath, [scriptFile, jobFile], {\n timeout: 60_000,\n stdio: \"inherit\",\n });\n } catch (error) {\n throw new Error(\n `pieces: could not load ${rel}: ${childFailure(error, outFile)}`,\n { cause: error },\n );\n }\n return JSON.parse(readFileSync(outFile, \"utf8\")) as DescribeResult;\n } finally {\n rmSync(dir, { recursive: true, force: true });\n }\n}\n\nexport type PieceLocation = {\n /** The piece directory, absolute. */\n dir: string;\n /** The module file, absolute; unset for a bundle, whose package.json names it. */\n entryFile?: string;\n form: \"entry\" | \"bundle\";\n};\n\n// Where a list entry says its built piece is, checked against the disk: a\n// listed piece nobody built would otherwise fail much later, in a host.\nexport function resolvePieceLocation(\n piece: PackagePiece,\n projectRoot: string,\n outDir: string,\n): PieceLocation {\n const declared = piece.entry ?? piece.bundle;\n if (typeof declared !== \"string\" || declared === \"\") {\n throw new Error(\n `pieces: \"${piece.name}\" declares neither an entry nor a bundle`,\n );\n }\n const path = isAbsolute(declared) ? declared : join(projectRoot, declared);\n const form = piece.entry ? \"entry\" : \"bundle\";\n const present =\n form === \"entry\"\n ? statSafe(path)?.isFile()\n : statSafe(join(path, \"package.json\"))?.isFile();\n if (!present) {\n throw new Error(\n `pieces: \"${piece.name}\" declares ${declared}, which is missing`,\n );\n }\n const dir = form === \"entry\" ? dirname(path) : path;\n // Both forms, not just `entry`: a descriptor.json is written into this\n // directory, and outside outDir that lands in tracked source.\n const piecesRoot = resolve(projectRoot, outDir, \"node\", \"pieces\");\n const inside = relative(piecesRoot, dir);\n if (inside === \"\" || inside.startsWith(\"..\") || isAbsolute(inside)) {\n const expected = toPosix(join(outDir, \"node\", \"pieces\"));\n throw new Error(\n `pieces: \"${piece.name}\" declares ${declared}, which is outside ${expected}/; ` +\n `a piece is built to ${expected}/<dir>/index.mjs and its entry must point there`,\n );\n }\n return form === \"entry\" ? { dir, entryFile: path, form } : { dir, form };\n}\n\n// Where the node build leaves the list of pieces a package ships. Its presence\n// on disk, not a pieces/<dir> in the source, is what says a package has them.\nexport function pieceListPath(target: {\n projectRoot: string;\n outDir: string;\n}): string {\n return resolve(\n target.projectRoot,\n target.outDir,\n \"node\",\n \"pieces\",\n \"index.mjs\",\n );\n}\n\n// `dist` is not a default here but a contract: a host reads a piece from\n// dist/node/pieces/<name>, and a list entry names that path literally.\nexport function assertPiecesOutDir(target: {\n outDir: string;\n pieces: PiecePlan[];\n}): void {\n if (target.pieces.length === 0 || target.outDir === \"dist\") return;\n throw new Error(\n `pieces: --out-dir ${target.outDir} cannot hold pieces; a piece is loaded from ` +\n `dist/node/pieces/<name> by the host, so a package that ships pieces builds to dist`,\n );\n}\n\n// A piece's version is its package's, written by the build; a list entry that\n// declares one is refused, so `name@version` always names one tarball.\nexport function assertPieceVersion(\n piece: PackagePiece,\n pkg: PackageIdentity,\n): void {\n if (\"version\" in piece) {\n throw new Error(\n `pieces: \"${piece.name}\" declares version ${String(piece.version)}; a piece takes its package's version (${pkg.version}), so remove \"version\" from pieces/index.ts`,\n );\n }\n}\n\n// The package.json written beside a piece built from an `entry`, giving the\n// directory npm-bundle shape so a registry can serve it on its own.\nexport function piecePackageJson(options: {\n name: string;\n version: string;\n description?: string;\n main: string;\n license?: string;\n}): Record<string, unknown> {\n return {\n name: options.name,\n version: options.version,\n description: options.description ?? \"\",\n type: \"module\",\n main: options.main,\n ...(options.license ? { license: options.license } : {}),\n // Empty on purpose: the runtime treats a bundle that declares dependencies\n // as not self-contained, and everything a piece needs is inlined already.\n dependencies: {},\n };\n}\n\n// A prebuilt bundle's own package.json, restamped with the package's version.\nexport function bundlePackageJson(\n dir: string,\n version: string,\n): Record<string, unknown> {\n const current = JSON.parse(\n readFileSync(join(dir, \"package.json\"), \"utf8\"),\n ) as Record<string, unknown>;\n return { ...current, version };\n}\n\n// The descriptor written beside a piece: the list's name, the package's version,\n// then whatever the piece said about itself, in the framework's PieceMetadata shape.\nexport function pieceDescriptor(\n piece: PackagePiece,\n version: string,\n metadata: PieceMetadata,\n): Record<string, unknown> {\n const { name: _name, version: _version, ...rest } = metadata;\n return { name: piece.name, version, ...rest };\n}\n\n// The manifest's `pieces` with what the build learned: a built piece replaces\n// the source entry with its id in place, or is appended at the end.\n\n// A source entry nothing built is kept as it is and returned as `unbuilt`,\n// for the caller to warn about.\nexport function enrichManifestPieces(\n manifest: Manifest,\n built: BuiltPiece[],\n): { manifest: Manifest; unbuilt: string[] } {\n const byId = new Map(built.map((piece) => [piece.name, piece]));\n const toModule = (piece: BuiltPiece): PieceModule => ({\n id: piece.name,\n name: piece.displayName ?? piece.name,\n version: piece.version,\n ...(piece.description ? { description: piece.description } : {}),\n bundle: piece.bundle,\n descriptor: piece.descriptor,\n });\n const unbuilt: string[] = [];\n const seen = new Set<string>();\n const pieces: PieceModule[] = (manifest.pieces ?? []).map((entry) => {\n const hit = byId.get(entry.id);\n if (!hit) {\n unbuilt.push(entry.id);\n return entry;\n }\n seen.add(entry.id);\n return toModule(hit);\n });\n for (const piece of built) {\n if (!seen.has(piece.name)) pieces.push(toModule(piece));\n }\n return { manifest: { ...manifest, pieces }, unbuilt };\n}\n\nconst count = (record: unknown) =>\n typeof record === \"object\" && record !== null\n ? Object.keys(record).length\n : 0;\n\n// Build every planned piece, then read the built list and describe what it\n// names. Returns what was built, for the manifest.\nexport async function buildPieces(\n target: PieceBuildTarget,\n pkg: PackageIdentity,\n options: PieceBuildOptions,\n): Promise<BuiltPiece[]> {\n const { projectRoot, outDir } = target;\n assertPiecesOutDir(target);\n // resolve, not join: an absolute --out-dir is what the browser and node\n // steps hand tsdown, and joining it onto the project root mangles it.\n for (const piece of target.pieces) {\n console.log(`\\n▶ Building piece ${piece.dir}...`);\n await options.bundle(\n buildPieceBuildConfig({\n entry: resolve(projectRoot, piece.entry),\n outDir: resolve(projectRoot, piece.outDir),\n }),\n );\n }\n\n // The list is the source of truth for names; a package that\n // built pieces without a list has nothing a host could read.\n const listPath = pieceListPath(target);\n if (!existsSync(listPath)) {\n throw new Error(\n `pieces: ${toPosix(relative(projectRoot, listPath))} was not built; ` +\n `pieces/index.ts must export the list of pieces this package ships`,\n );\n }\n const described = describePieces(projectRoot, listPath);\n\n const built: BuiltPiece[] = [];\n const listedDirs = new Set<string>();\n for (const piece of described.list) {\n const location = resolvePieceLocation(piece, projectRoot, outDir);\n assertPieceVersion(piece, pkg);\n const failure = described.errors.find((e) => e.name === piece.name);\n if (failure) {\n throw new Error(\n `pieces: \"${piece.name}\" could not be described: ${failure.message}`,\n );\n }\n const found = described.pieces.find((p) => p.name === piece.name);\n if (!found) {\n throw new Error(`pieces: \"${piece.name}\" was not described`);\n }\n const metadata = found.metadata;\n const relDir = toPosix(relative(projectRoot, location.dir));\n listedDirs.add(relDir);\n\n writeFileSync(\n join(location.dir, \"descriptor.json\"),\n JSON.stringify(\n pieceDescriptor(piece, pkg.version, metadata),\n createJsonReplacer(),\n 2,\n ) + \"\\n\",\n );\n const piecePackage =\n location.form === \"entry\" && location.entryFile\n ? piecePackageJson({\n name: piece.name,\n version: pkg.version,\n description: metadata.description,\n main: relative(location.dir, location.entryFile),\n license: pkg.license,\n })\n : bundlePackageJson(location.dir, pkg.version);\n writeFileSync(\n join(location.dir, \"package.json\"),\n JSON.stringify(piecePackage, null, 2) + \"\\n\",\n );\n console.log(\n `piece: ${piece.name}@${pkg.version} -> ${relDir} ` +\n `(${count(metadata.actions)} actions, ${count(metadata.triggers)} triggers)`,\n );\n built.push({\n name: piece.name,\n version: pkg.version,\n displayName: metadata.displayName,\n description: metadata.description,\n bundle: relDir,\n descriptor: `${relDir}/descriptor.json`,\n });\n }\n\n warnUnlistedPieces(target.pieces, listedDirs);\n return built;\n}\n\n// A built piece no list entry points into ships without a host ever finding it.\nfunction warnUnlistedPieces(\n planned: PiecePlan[],\n listedDirs: Set<string>,\n): void {\n for (const piece of planned) {\n if (!listedDirs.has(toPosix(piece.outDir))) {\n console.warn(\n `⚠ pieces: pieces/${piece.dir} was built but pieces/index.ts does not list it; a host will not find it`,\n );\n }\n }\n}\n\n// Make sure the manifest ships under outDir (tsdown copies it only in the\n// browser build) and, when pieces were built, list them in that copy.\n\n// Always copied afresh: only <outDir>/node is cleaned by the builds, so a copy\n// left by the last build would otherwise outlive an edit to the source.\n\n// The source file is never written. Returns the path of the copy, if any.\nexport function syncDistManifest(\n target: PieceBuildTarget,\n built: BuiltPiece[],\n): string | undefined {\n const { projectRoot, outDir } = target;\n const source = join(projectRoot, \"powerhouse.manifest.json\");\n // resolve, not join: an absolute --out-dir is a location, not a suffix.\n const copy = resolve(projectRoot, outDir, \"powerhouse.manifest.json\");\n // The built list, not the source plan: a package whose pieces are all\n // `bundle:` entries has no pieces/<dir> and still ships pieces.\n const shipsPieces = existsSync(pieceListPath(target));\n if (!existsSync(source)) {\n if (shipsPieces) {\n console.warn(\"⚠ no powerhouse.manifest.json; pieces will not be listed\");\n }\n return undefined;\n }\n mkdirSync(dirname(copy), { recursive: true });\n copyFileSync(source, copy);\n if (!shipsPieces) return copy;\n\n const manifest = JSON.parse(readFileSync(copy, \"utf8\")) as Manifest;\n const enriched = enrichManifestPieces(manifest, built);\n for (const id of enriched.unbuilt) {\n console.warn(`⚠ manifest lists piece \"${id}\" but nothing built it`);\n }\n writeFileSync(copy, JSON.stringify(enriched.manifest, null, 2) + \"\\n\");\n return copy;\n}\n"],"mappings":";;;;;;AA+FA,MAAM,WAAW,MAAc,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;AAEpD,SAAgB,SAAS,GAAW;CAClC,IAAI;EACF,OAAO,SAAS,CAAC;CACnB,QAAQ;EACN,OAAO;CACT;AACF;AAIA,SAAgB,iBAAiB,MAAc,OAA2B;CACxE,MAAM,wBAAQ,IAAI,IAAY;CAC9B,KAAK,MAAM,WAAW,OAAO;EAC3B,MAAM,WAAW,QAAQ,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;EAClD,IAAI,OAAO,CAAC,IAAI;EAChB,KAAK,MAAM,OAAO,UAAU;GAC1B,MAAM,OAAiB,CAAC;GACxB,KAAK,MAAM,KAAK,MAAM;IACpB,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,YAAY,GAAG;IACjC,IAAI,QAAQ,KACV,KAAK,MAAM,KAAK,YAAY,GAAG,EAAE,eAAe,KAAK,CAAC,GACpD,KAAK,KAAK,KAAK,GAAG,EAAE,IAAI,CAAC;SAG3B,KAAK,KAAK,KAAK,GAAG,GAAG,CAAC;GAE1B;GACA,OAAO;EACT;EACA,KAAK,MAAM,K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AO,IAC3C,MAAM,SAAS,OAAO,EAAE,YAAY,MAAM,SAAS,QAAQ,EAAE,WACrE;EACA,MAAM,KAAK;GACT,MAAM,MAAM;GACZ,SAAS,IAAI;GACb,aAAa,SAAS;GACtB,aAAa,SAAS;GACtB,QAAQ;GACR,YAAY,GAAG,OAAO;EACxB,CAAC;CACH;CAEA,mBAAmB,OAAO,QAAQ,UAAU;CAC5C,OAAO;AACT;AAGA,SAAS,mBACP,SACA,YACM;CACN,KAAK,MAAM,SAAS,SAClB,IAAI,CAAC,WAAW,IAAI,QAAQ,MAAM,MAAM,CAAC,GACvC,QAAQ,KACN,oBAAoB,MAAM,IAAI,yEAChC;AAGN;AASA,SAAgB,iBACd,QACA,OACoB;CACpB,MAAM,EAAE,aAAa,WAAW;CAChC,MAAM,SAAS,KAAK,aAAa,0BAA0B;CAE3D,MAAM,OAAO,QAAQ,aAAa,QAAQ,0BAA0B;CAGpE,MAAM,cAAc,WAAW,cAAc,MAAM,CAAC;CACpD,IAAI,CAAC,WAAW,MAAM,GAAG;EACvB,IAAI,aACF,QAAQ,KAAK,0DAA0D;EAEzE;CACF;CACA,UAAU,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;CAC5C,aAAa,QAAQ,IAAI;CACzB,IAAI,CAAC,aAAa,OAAO;CAGzB,MAAM,WAAW,qBADA,KAAK,MAAM,aAAa,MAAM,MAAM,CACR,GAAG,KAAK;CACrD,KAAK,MAAM,MAAM,SAAS,SACxB,QAAQ,KAAK,2BAA2B,GAAG,uBAAuB;CAEpE,cAAc,MAAM,KAAK,UAAU,SAAS,UAAU,MAAM,CAAC,IAAI,IAAI;CACrE,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"build-pieces.mjs","names":[],"sources":["../../clis/external-deps.mts","../../clis/build-pieces.mts"],"sourcesContent":["// External dependencies: a package whose code needs a native addon or a\n// WebAssembly module cannot be inlined, so it stays a bare import the host installs.\nimport { readdirSync, readFileSync, realpathSync } from \"node:fs\";\nimport { isBuiltin } from \"node:module\";\nimport { isAbsolute, join, relative, sep } from \"node:path\";\nimport type { InlineConfig } from \"tsdown\";\n\n/** The files one module needs at run time, and why each was included. */\nexport type FileTrace = {\n /** Absolute paths. */\n fileList: Set<string>;\n /** Absolute path -> the absolute paths of the files that pulled it in. */\n reasons: Map<string, { parents: Set<string> }>;\n};\n\n/** Traces one file: @vercel/nft's nodeFileTrace, handed in by the CLI. */\nexport type TraceFiles = (file: string) => Promise<FileTrace>;\n\n/** A file the bundle cannot carry: a native addon or a WebAssembly module. */\nexport type RequiredFile = { file: string; kind: \"native\" | \"wasm\" };\n\nexport type ExternalDependency = RequiredFile & {\n name: string;\n version: string;\n /** The first of the package's own files seen importing it. */\n importer?: string;\n};\n\n/** What one `ph build` learns about packages, shared by all of its builds. */\nexport type DetectionCache = {\n files: Map<string, Promise<RequiredFile | undefined>>;\n wasm: Map<string, string | undefined>;\n};\n\nexport const createDetectionCache = (): DetectionCache => ({\n files: new Map(),\n wasm: new Map(),\n});\n\nexport type ExternalDepsPluginOptions = {\n /** The project root the dirs below are relative to. */\n root?: string;\n /** Browser build: a native package fails it; WebAssembly is bundled. */\n browser?: boolean;\n /** Dirs whose imports the bundler handles as usual: code no host runs. */\n ignoreDirs?: string[];\n /** Dirs that may not import a native or WebAssembly package. */\n forbidDirs?: string[];\n cache?: DetectionCache;\n};\n\ntype Plugin = NonNullable<InlineConfig[\"plugins\"]>;\n\ntype PackageJson = {\n name?: string;\n version?: string;\n dependencies?: Record<string, string>;\n optionalDependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n};\n\nconst NODE_MODULES = `${sep}node_modules${sep}`;\n\n/** `file` relative to `root`, with forward slashes on every platform. */\nexport function projectPath(root: string, file: string): string {\n return relative(root, file).split(sep).join(\"/\");\n}\n\n// Windows paths compare case-insensitively, drive letter included.\nconst samePath = (file: string) =>\n process.platform === \"win32\" ? file.toLowerCase() : file;\n\n// \"@scope/name/sub\" -> \"@scope/name\", \"name/sub\" -> \"name\".\nexport function packageNameOf(specifier: string): string | undefined {\n if (specifier.startsWith(\".\") || isAbsolute(specifier)) return undefined;\n const parts = specifier.split(\"/\");\n const name = specifier.startsWith(\"@\")\n ? parts.slice(0, 2).join(\"/\")\n : parts[0];\n return name || undefined;\n}\n\n// The root of the installed package a file belongs to, if it is in one.\nexport function packageRootOf(file: string): string | undefined {\n const at = file.lastIndexOf(NODE_MODULES);\n if (at < 0) return undefined;\n const rest = file.slice(at + NODE_MODULES.length).split(sep);\n const depth = rest[0]?.startsWith(\"@\") ? 2 : 1;\n if (rest.length <= depth) return undefined;\n return join(file.slice(0, at + NODE_MODULES.length), ...rest.slice(0, depth));\n}\n\nfunction readPackageJson(root: string): PackageJson | undefined {\n try {\n return JSON.parse(\n readFileSync(join(root, \"package.json\"), \"utf8\"),\n ) as PackageJson;\n } catch {\n return undefined;\n }\n}\n\n// Only links the importer requires count: an optional peer such as\n// ws -> bufferutil is a speed-up the importer runs without.\nfunction requires(importerRoot: string, importedRoot: string): boolean {\n const importer = readPackageJson(importerRoot);\n const name = readPackageJson(importedRoot)?.name;\n if (!importer || !name) return false;\n return (\n importer.dependencies?.[name] !== undefined ||\n importer.optionalDependencies?.[name] !== undefined\n );\n}\n\n// The first .wasm file in a package's own files. Presence is enough: most\n// packages compute the path or let their caller pass it, so a trace misses it.\nfunction wasmIn(root: string, cache?: DetectionCache): string | undefined {\n if (cache?.wasm.has(root)) return cache.wasm.get(root);\n const found = scanForWasm(root);\n cache?.wasm.set(root, found);\n return found;\n}\n\nfunction scanForWasm(root: string): string | undefined {\n try {\n const found = readdirSync(root, { recursive: true, encoding: \"utf8\" }).find(\n (file) =>\n file.endsWith(\".wasm\") && !file.split(sep).includes(\"node_modules\"),\n );\n return found && join(root, found);\n } catch {\n return undefined;\n }\n}\n\n/** The first file `entry` cannot load without that a bundle cannot carry. */\nexport async function findRequiredFile(\n entry: string,\n trace: TraceFiles,\n cache?: DetectionCache,\n): Promise<RequiredFile | undefined> {\n const { fileList, reasons } = await trace(entry);\n // A tracer reports real paths, and the entry may sit behind a symlink.\n const start = samePath(realpathSync(entry));\n // What to report, and the traced file the walk back to the entry starts at.\n const candidates: (RequiredFile & { from: string })[] = [...fileList]\n .filter((file) => file.endsWith(\".node\"))\n .map((file) => ({ file, kind: \"native\" as const, from: file }));\n {\n const traced = new Map<string, string>();\n for (const file of fileList) {\n const root = packageRootOf(file);\n if (root && !traced.has(root) && /\\.[cm]?js$/.test(file)) {\n traced.set(root, file);\n }\n }\n const tracedWasm = [...fileList].filter((file) => file.endsWith(\".wasm\"));\n for (const [root, from] of traced) {\n const file =\n tracedWasm.find((wasm) => packageRootOf(wasm) === root) ??\n wasmIn(root, cache);\n if (file) candidates.push({ file, kind: \"wasm\", from });\n }\n }\n for (const { from, ...required } of candidates) {\n // Back to the entry, crossing into a parent's package only when that\n // package requires the one being left.\n const seen = new Set([from]);\n const queue = [from];\n while (queue.length > 0) {\n const file = queue.shift()!;\n if (samePath(file) === start) return required;\n for (const parent of reasons.get(file)?.parents ?? []) {\n if (seen.has(parent)) continue;\n const fromRoot = packageRootOf(parent);\n const toRoot = packageRootOf(file);\n if (\n fromRoot !== toRoot &&\n (!fromRoot || !toRoot || !requires(fromRoot, toRoot))\n ) {\n continue;\n }\n seen.add(parent);\n queue.push(parent);\n }\n }\n }\n return undefined;\n}\n\n/** Keeps each package the code imports that needs such a file out of the bundle. */\nexport function externalDepsPlugin(\n trace: TraceFiles,\n found: Map<string, ExternalDependency>,\n options: ExternalDepsPluginOptions = {},\n): Plugin {\n const cache = options.cache ?? createDetectionCache();\n const root = options.root ?? process.cwd();\n const show = (file: string) => projectPath(root, file);\n const inDir = (id: string, dirs: string[] = []) =>\n dirs.some((dir) => show(id).startsWith(`${dir}/`));\n // By resolved file: a package's subpaths can differ in what they load.\n const detect = (id: string) => {\n let verdict = cache.files.get(id);\n if (!verdict) {\n verdict = findRequiredFile(id, trace, cache);\n cache.files.set(id, verdict);\n }\n return verdict;\n };\n return {\n name: \"powerhouse:external-deps\",\n async resolveId(source, importer, extra) {\n // The project's own imports only: whatever a dependency pulls in goes\n // wherever that dependency goes.\n if (!importer || importer.includes(NODE_MODULES)) return null;\n if (isBuiltin(source) || inDir(importer, options.ignoreDirs)) return null;\n const name = packageNameOf(source);\n if (!name) return null;\n const resolved = await this.resolve(source, importer, {\n ...extra,\n skipSelf: true,\n });\n if (!resolved || resolved.external) return null;\n const required = await detect(resolved.id);\n const pkgRoot = packageRootOf(resolved.id);\n const version = pkgRoot ? readPackageJson(pkgRoot)?.version : undefined;\n if (!required || !version) return null;\n const what =\n required.kind === \"native\"\n ? `the native addon ${show(required.file)}`\n : `the WebAssembly module ${show(required.file)}`;\n if (options.browser) {\n if (required.kind === \"wasm\") return null;\n throw new Error(\n `${show(importer)} imports ${name}, which needs ${what}. ` +\n \"Native code cannot run in the browser: import it only from subgraphs, switchboard processors or pieces.\",\n );\n }\n if (inDir(importer, options.forbidDirs)) {\n throw new Error(\n `${show(importer)} imports ${name}, which needs ${what}. ` +\n \"Document models and scalars run in Connect and on every host: use it from a subgraph, processor or piece instead.\",\n );\n }\n if (!found.has(name)) {\n found.set(name, { name, version, ...required, importer });\n }\n return { id: source, external: true };\n },\n };\n}\n\n/**\n * The detected packages `pkg` does not install for its consumers: anything\n * outside dependencies, optionalDependencies and peerDependencies.\n */\nexport function undeclaredExternalDependencies(\n found: Iterable<ExternalDependency>,\n pkg: Partial<\n Record<\n \"dependencies\" | \"optionalDependencies\" | \"peerDependencies\",\n Partial<Record<string, string>>\n >\n >,\n): ExternalDependency[] {\n return [...found].filter(\n (dep) =>\n pkg.dependencies?.[dep.name] === undefined &&\n pkg.optionalDependencies?.[dep.name] === undefined &&\n pkg.peerDependencies?.[dep.name] === undefined,\n );\n}\n\n/** name -> version, sorted by name. */\nexport function externalDependencyVersions(\n found: Iterable<ExternalDependency>,\n): Record<string, string> {\n return Object.fromEntries(\n [...found]\n .sort((a, b) => a.name.localeCompare(b.name))\n .map((dep) => [dep.name, dep.version]),\n );\n}\n","// The pieces half of a package build: find and bundle each piece whole, load\n// it once in a child process to learn what it is, and write what a host reads.\nimport { execFileSync } from \"node:child_process\";\nimport {\n copyFileSync,\n existsSync,\n mkdirSync,\n mkdtempSync,\n readdirSync,\n readFileSync,\n realpathSync,\n rmSync,\n statSync,\n writeFileSync,\n} from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport {\n basename,\n dirname,\n isAbsolute,\n join,\n relative,\n resolve,\n sep,\n} from \"node:path\";\nimport type { InlineConfig } from \"tsdown\";\nimport type { Manifest, PieceModule } from \"../document-model/types.js\";\nimport { buildPieceBuildConfig, PIECE_ENTRY_GLOB } from \"./build-config.mjs\";\nimport {\n externalDependencyVersions,\n externalDepsPlugin,\n projectPath,\n type DetectionCache,\n type ExternalDependency,\n type TraceFiles,\n} from \"./external-deps.mjs\";\n\nexport {\n createDetectionCache,\n projectPath,\n findRequiredFile,\n externalDependencyVersions,\n externalDepsPlugin,\n undeclaredExternalDependencies,\n} from \"./external-deps.mjs\";\nexport type {\n DetectionCache,\n FileTrace,\n ExternalDependency,\n ExternalDepsPluginOptions,\n TraceFiles,\n} from \"./external-deps.mjs\";\n\nexport type PiecePlan = {\n /** The directory under pieces/, and so under <outDir>/node/pieces. */\n dir: string;\n /** Source entry, relative to the project root: pieces/<dir>/index.ts. */\n entry: string;\n /** Where the piece lands, relative to the project root. */\n outDir: string;\n};\n\n// What buildPieces needs to know about the package it works in: where it is,\n// where it builds to, and which pieces the plan found.\nexport type PieceBuildTarget = {\n projectRoot: string;\n outDir: string;\n /**\n * @experimental Absolute: the directory that stands in for\n * `<projectRoot>/<outDir>` on disk during this build. Every path the build\n * names stays under `outDir`. Experimental while staged builds are\n * introduced.\n */\n writeTo?: string;\n pieces: PiecePlan[];\n};\n\n// One entry of pieces/index.ts, as @powerhousedao/pieces-framework declares it.\n// Declared here so the build needs no dependency on a package meant for pieces.\nexport type PackagePiece = {\n name: string;\n entry?: string;\n bundle?: string;\n};\n\n// What a piece says about itself, in the framework's PieceMetadata shape.\n// Read from the built piece, so nothing in the build has to know the framework.\nexport type PieceMetadata = Record<string, unknown> & {\n displayName?: string;\n description?: string;\n actions?: Record<string, unknown>;\n triggers?: Record<string, unknown>;\n};\n\nexport type DescribedPiece = {\n name: string;\n metadata: PieceMetadata;\n};\n\nexport type DescribeResult = {\n list: PackagePiece[];\n pieces: DescribedPiece[];\n errors: { name: string; message: string }[];\n};\n\nexport type BuiltPiece = {\n name: string;\n version: string;\n displayName?: string;\n description?: string;\n /** Piece directory, relative to the project root, `/` separated. */\n bundle: string;\n /** The descriptor inside it, relative to the project root, `/` separated. */\n descriptor: string;\n};\n\nexport type PackageIdentity = {\n name: string;\n version: string;\n license?: string;\n};\n\nexport type PieceBuildOptions = {\n /** The bundler: tsdown's `build`, handed in so this module never loads it. */\n bundle: (config: InlineConfig) => Promise<unknown>;\n /** Traces a module's run-time files; without it nothing is kept external. */\n trace?: TraceFiles;\n cache?: DetectionCache;\n};\n\nconst toPosix = (p: string) => p.split(sep).join(\"/\");\n\n/**\n * An output directory, absolute, and the directory written in its place;\n * `toReal` is `to` as `import.meta.url` spells it, through any symlink.\n */\ntype Redirect = { from: string; to: string; toReal: string };\n\n/** `relative(dir, path)` leaves `dir`: `..`, `../…`, or another root. */\nconst leaves = (inside: string) =>\n inside === \"..\" || inside.startsWith(`..${sep}`) || isAbsolute(inside);\n\n// Where a path is on disk: moved to `to` when it lies under `from`.\nfunction onDisk(path: string, redirect: Redirect | undefined): string {\n if (!redirect) return path;\n const inside = relative(redirect.from, path);\n return leaves(inside) ? path : join(redirect.to, inside);\n}\n\n// Where a path in the written directory stands in the output: the inverse of\n// onDisk, for a location a module derived from its own URL.\nfunction toLogical(path: string, redirect: Redirect | undefined): string {\n if (!redirect) return path;\n for (const dir of [redirect.to, redirect.toReal]) {\n const inside = relative(dir, path);\n if (!leaves(inside)) return join(redirect.from, inside);\n }\n return path;\n}\n\nexport function statSafe(p: string) {\n try {\n return statSync(p);\n } catch {\n return null;\n }\n}\n\nfunction realpathSafe(p: string) {\n try {\n return realpathSync(p);\n } catch {\n return p;\n }\n}\n\n// Expand entry globs (single-`*` segments only — the shape `browserEntry`\n// uses) against files on disk, resolving against `root`.\nexport function expandEntryGlobs(root: string, globs: string[]): string[] {\n const files = new Set<string>();\n for (const pattern of globs) {\n const segments = pattern.split(\"/\").filter(Boolean);\n let dirs = [root];\n for (const seg of segments) {\n const next: string[] = [];\n for (const d of dirs) {\n if (!statSafe(d)?.isDirectory()) continue;\n if (seg === \"*\") {\n for (const e of readdirSync(d, { withFileTypes: true })) {\n next.push(join(d, e.name));\n }\n } else {\n next.push(join(d, seg));\n }\n }\n dirs = next;\n }\n for (const f of dirs) {\n if (statSafe(f)?.isFile()) files.add(f);\n }\n }\n return [...files];\n}\n\n// The pieces a project holds, one per pieces/<dir>/index.ts, sorted by dir so\n// a build log and a manifest read the same from one run to the next.\nexport function planPieces(projectRoot: string, outDir: string): PiecePlan[] {\n return expandEntryGlobs(projectRoot, [PIECE_ENTRY_GLOB])\n .map((file) => {\n const dir = basename(dirname(file));\n return {\n dir,\n entry: relative(projectRoot, file),\n outDir: join(outDir, \"node\", \"pieces\", dir),\n };\n })\n .sort((a, b) => (a.dir < b.dir ? -1 : a.dir > b.dir ? 1 : 0));\n}\n\n// A JSON.stringify replacer that makes a piece's metadata serializable: props\n// carry resolvers, defaults may be class instances, and a schema may cycle.\nexport function createJsonReplacer() {\n const ancestors: object[] = [];\n return function replace(this: unknown, _key: string, value: unknown) {\n if (typeof value === \"function\" || value === undefined) return undefined;\n if (typeof value === \"bigint\") return value.toString();\n if (typeof value !== \"object\" || value === null) return value;\n // `this` is the holder, so popping back to it leaves the current path.\n while (ancestors.length > 0 && ancestors.at(-1) !== this) ancestors.pop();\n if (ancestors.includes(value)) return undefined;\n ancestors.push(value);\n return value;\n };\n}\n\n// The half of the child script that needs nothing from the job: a test\n// evaluates this text on its own, so neither copy can drift from the other.\n\n// `constructor?.name`: a module may export an Object.create(null), and the\n// real piece is usually beside it in the same module.\nexport const DESCRIBE_HELPERS = `\nconst isRecord = (value) => typeof value === \"object\" && value !== null;\n\nfunction findPiece(mod) {\n const candidates = [\n ...Object.values(mod),\n ...(isRecord(mod.default) ? Object.values(mod.default) : []),\n mod.default,\n ];\n for (const candidate of candidates) {\n if (isRecord(candidate) && candidate.constructor?.name === \"Piece\") {\n return candidate;\n }\n }\n for (const candidate of candidates) {\n if (\n isRecord(candidate) &&\n typeof candidate.displayName === \"string\" &&\n (isRecord(candidate.actions) ||\n typeof candidate.actions === \"function\" ||\n typeof candidate.getAction === \"function\")\n ) {\n return candidate;\n }\n }\n return undefined;\n}\n\nfunction describePiece(piece) {\n if (typeof piece.metadata === \"function\") return piece.metadata();\n const call = (value) => (typeof value === \"function\" ? value.call(piece) : value);\n return {\n displayName: piece.displayName,\n logoUrl: piece.logoUrl,\n description: piece.description,\n authors: piece.authors,\n categories: piece.categories,\n auth: piece.auth,\n minimumSupportedRelease: piece.minimumSupportedRelease,\n maximumSupportedRelease: piece.maximumSupportedRelease,\n deprecated: piece.deprecated,\n actions: call(piece.actions) ?? {},\n triggers: call(piece.triggers) ?? {},\n };\n}\n\nfunction createJsonReplacer() {\n const ancestors = [];\n return function replace(_key, value) {\n if (typeof value === \"function\" || value === undefined) return undefined;\n if (typeof value === \"bigint\") return value.toString();\n if (typeof value !== \"object\" || value === null) return value;\n while (ancestors.length > 0 && ancestors.at(-1) !== this) ancestors.pop();\n if (ancestors.includes(value)) return undefined;\n ancestors.push(value);\n return value;\n };\n}\n`;\n\n// Runs in a child node process: loading a piece runs piece-authored top-level\n// code, and the runtime describes pieces in a worker for the same reason.\n\n// A string so it works from `src` under bun or tsx as well as from `dist`. It\n// answers through a file, leaving both its streams to the piece.\nexport const DESCRIBE_SCRIPT = `\nimport { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { isAbsolute, join, relative, sep } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nconst job = JSON.parse(readFileSync(process.argv[2], \"utf8\"));\n${DESCRIBE_HELPERS}\n// The parent's onDisk, for the paths a list names under the output directory.\nfunction onDisk(path) {\n if (!job.redirect) return path;\n const inside = relative(job.redirect.from, path);\n const leaves = inside === \"..\" || inside.startsWith(\"..\" + sep) || isAbsolute(inside);\n return leaves ? path : join(job.redirect.to, inside);\n}\n\n// Says why the child gave up in the one place the parent always reads, so a\n// failure reports the cause and never the text of this script.\nfunction fail(message) {\n writeFileSync(job.outFile, JSON.stringify({ fatal: message }));\n process.exit(1);\n}\n\n// The module to load for a list entry; a bundle names its own main.\nfunction entryFile(piece) {\n const declared = piece.entry ?? piece.bundle;\n if (typeof declared !== \"string\") return undefined;\n const path = isAbsolute(declared) ? declared : join(job.projectRoot, declared);\n if (piece.entry) return path;\n const pkgFile = join(onDisk(path), \"package.json\");\n if (!existsSync(pkgFile)) return undefined;\n const pkg = JSON.parse(readFileSync(pkgFile, \"utf8\"));\n return join(path, typeof pkg.main === \"string\" ? pkg.main : \"index.mjs\");\n}\n\nlet listModule;\ntry {\n listModule = await import(pathToFileURL(onDisk(job.listPath)).href);\n} catch (error) {\n fail(job.listPath + \" threw on import: \" + (error instanceof Error ? error.message : String(error)));\n}\nconst list = listModule.pieces ?? listModule.default;\nif (!Array.isArray(list)) {\n fail(job.listPath + ' exports no \"pieces\" array');\n}\n\nconst out = { list, pieces: [], errors: [] };\nfor (const piece of list) {\n const file = entryFile(piece);\n // A missing file is the parent's to report, with the message it owns.\n if (!file || !existsSync(onDisk(file))) continue;\n try {\n const mod = await import(pathToFileURL(onDisk(file)).href);\n const found = findPiece(mod);\n if (!found) {\n throw new Error(\n \"no Piece export found in \" + file + \"; exports: \" + Object.keys(mod).join(\", \"),\n );\n }\n const metadata = JSON.parse(JSON.stringify(describePiece(found), createJsonReplacer()));\n out.pieces.push({ name: piece.name, metadata });\n } catch (error) {\n out.errors.push({\n name: piece.name,\n message: error instanceof Error ? error.message : String(error),\n });\n }\n}\nwriteFileSync(job.outFile, JSON.stringify(out, createJsonReplacer()));\n`;\n\n// What the child said went wrong, if it got that far, and otherwise how it\n// died: an exit status, never the whole script an `Error.message` carries.\nfunction childFailure(error: unknown, outFile: string): string {\n try {\n const answer = JSON.parse(readFileSync(outFile, \"utf8\")) as {\n fatal?: unknown;\n };\n if (typeof answer.fatal === \"string\") return answer.fatal;\n } catch {\n // no answer on disk: fall through to the exit status\n }\n const { status, signal } = error as {\n status?: number | null;\n signal?: string | null;\n };\n if (signal) return `the describe child was killed by ${signal}`;\n return `the describe child exited with code ${status ?? \"unknown\"}`;\n}\n\n// Load the built list and every piece it names in a child process and return\n// what they say about themselves. Throws when the list itself cannot be read.\n\n// Both of the child's streams are the parent's, so a piece that prints at\n// import time is heard rather than mixed into the answer.\nexport function describePieces(\n projectRoot: string,\n listPath: string,\n): DescribeResult {\n return describePiecesThrough(projectRoot, listPath, undefined);\n}\n\nfunction describePiecesThrough(\n projectRoot: string,\n listPath: string,\n redirect: Redirect | undefined,\n): DescribeResult {\n const dir = mkdtempSync(join(tmpdir(), \"ph-build-pieces-\"));\n const rel = toPosix(relative(projectRoot, listPath));\n try {\n const jobFile = join(dir, \"job.json\");\n const scriptFile = join(dir, \"describe.mjs\");\n const outFile = join(dir, \"describe.json\");\n writeFileSync(scriptFile, DESCRIBE_SCRIPT);\n writeFileSync(\n jobFile,\n JSON.stringify({ projectRoot, listPath, outFile, redirect }),\n );\n try {\n execFileSync(process.execPath, [scriptFile, jobFile], {\n timeout: 60_000,\n stdio: \"inherit\",\n });\n } catch (error) {\n throw new Error(\n `pieces: could not load ${rel}: ${childFailure(error, outFile)}`,\n { cause: error },\n );\n }\n return JSON.parse(readFileSync(outFile, \"utf8\")) as DescribeResult;\n } finally {\n rmSync(dir, { recursive: true, force: true });\n }\n}\n\nexport type PieceLocation = {\n /** The piece directory, absolute. */\n dir: string;\n /** The module file, absolute; unset for a bundle, whose package.json names it. */\n entryFile?: string;\n form: \"entry\" | \"bundle\";\n};\n\n// Where a list entry says its built piece is, checked against the disk: a\n// listed piece nobody built would otherwise fail much later, in a host.\nexport function resolvePieceLocation(\n piece: PackagePiece,\n projectRoot: string,\n outDir: string,\n): PieceLocation {\n return locatePieceThrough(piece, projectRoot, outDir, undefined);\n}\n\nfunction locatePieceThrough(\n piece: PackagePiece,\n projectRoot: string,\n outDir: string,\n redirect: Redirect | undefined,\n): PieceLocation {\n const declared = piece.entry ?? piece.bundle;\n if (typeof declared !== \"string\" || declared === \"\") {\n throw new Error(\n `pieces: \"${piece.name}\" declares neither an entry nor a bundle`,\n );\n }\n // A list may derive a location from import.meta.url, which names the\n // written directory: it is read as the output it stands in for.\n const shown = isAbsolute(declared) ? toLogical(declared, redirect) : declared;\n const path = isAbsolute(declared) ? shown : join(projectRoot, declared);\n const form = piece.entry ? \"entry\" : \"bundle\";\n const disk = onDisk(path, redirect);\n const present =\n form === \"entry\"\n ? statSafe(disk)?.isFile()\n : statSafe(join(disk, \"package.json\"))?.isFile();\n if (!present) {\n throw new Error(\n `pieces: \"${piece.name}\" declares ${shown}, which is missing`,\n );\n }\n const dir = form === \"entry\" ? dirname(path) : path;\n // Both forms, not just `entry`: a descriptor.json is written into this\n // directory, and outside outDir that lands in tracked source.\n const piecesRoot = resolve(projectRoot, outDir, \"node\", \"pieces\");\n const inside = relative(piecesRoot, dir);\n if (inside === \"\" || inside.startsWith(\"..\") || isAbsolute(inside)) {\n const expected = toPosix(join(outDir, \"node\", \"pieces\"));\n throw new Error(\n `pieces: \"${piece.name}\" declares ${shown}, which is outside ${expected}/; ` +\n `a piece is built to ${expected}/<dir>/index.mjs and its entry must point there`,\n );\n }\n return form === \"entry\" ? { dir, entryFile: path, form } : { dir, form };\n}\n\n// Where the node build leaves the list of pieces a package ships. Its presence\n// on disk, not a pieces/<dir> in the source, is what says a package has them.\nexport function pieceListPath(target: {\n projectRoot: string;\n outDir: string;\n}): string {\n return resolve(\n target.projectRoot,\n target.outDir,\n \"node\",\n \"pieces\",\n \"index.mjs\",\n );\n}\n\n// `dist` is not a default here but a contract: a host reads a piece from\n// dist/node/pieces/<name>, and a list entry names that path literally.\nexport function assertPiecesOutDir(target: {\n outDir: string;\n pieces: PiecePlan[];\n}): void {\n if (target.pieces.length === 0 || target.outDir === \"dist\") return;\n throw new Error(\n `pieces: --out-dir ${target.outDir} cannot hold pieces; a piece is loaded from ` +\n `dist/node/pieces/<name> by the host, so a package that ships pieces builds to dist`,\n );\n}\n\n// A piece's version is its package's, written by the build; a list entry that\n// declares one is refused, so `name@version` always names one tarball.\nexport function assertPieceVersion(\n piece: PackagePiece,\n pkg: PackageIdentity,\n): void {\n if (\"version\" in piece) {\n throw new Error(\n `pieces: \"${piece.name}\" declares version ${String(piece.version)}; a piece takes its package's version (${pkg.version}), so remove \"version\" from pieces/index.ts`,\n );\n }\n}\n\n// The package.json written beside a piece built from an `entry`, giving the\n// directory npm-bundle shape so a registry can serve it on its own.\nexport function piecePackageJson(options: {\n name: string;\n version: string;\n description?: string;\n main: string;\n license?: string;\n dependencies?: Record<string, string>;\n}): Record<string, unknown> {\n return {\n name: options.name,\n version: options.version,\n description: options.description ?? \"\",\n type: \"module\",\n main: options.main,\n ...(options.license ? { license: options.license } : {}),\n // Only external packages: everything else is inlined, and a host installs\n // what is listed here before it loads the piece.\n dependencies: options.dependencies ?? {},\n };\n}\n\n// A prebuilt bundle's own package.json, restamped with the package's version.\nexport function bundlePackageJson(\n dir: string,\n version: string,\n): Record<string, unknown> {\n const current = JSON.parse(\n readFileSync(join(dir, \"package.json\"), \"utf8\"),\n ) as Record<string, unknown>;\n return { ...current, version };\n}\n\n// The descriptor written beside a piece: the list's name, the package's version,\n// then whatever the piece said about itself, in the framework's PieceMetadata shape.\nexport function pieceDescriptor(\n piece: PackagePiece,\n version: string,\n metadata: PieceMetadata,\n): Record<string, unknown> {\n const { name: _name, version: _version, ...rest } = metadata;\n return { name: piece.name, version, ...rest };\n}\n\n// The manifest's `pieces` with what the build learned: a built piece replaces\n// the source entry with its id in place, or is appended at the end.\n\n// A source entry nothing built is kept as it is and returned as `unbuilt`,\n// for the caller to warn about.\nexport function enrichManifestPieces(\n manifest: Manifest,\n built: BuiltPiece[],\n): { manifest: Manifest; unbuilt: string[] } {\n const byId = new Map(built.map((piece) => [piece.name, piece]));\n const toModule = (piece: BuiltPiece): PieceModule => ({\n id: piece.name,\n name: piece.displayName ?? piece.name,\n version: piece.version,\n ...(piece.description ? { description: piece.description } : {}),\n bundle: piece.bundle,\n descriptor: piece.descriptor,\n });\n const unbuilt: string[] = [];\n const seen = new Set<string>();\n const pieces: PieceModule[] = (manifest.pieces ?? []).map((entry) => {\n const hit = byId.get(entry.id);\n if (!hit) {\n unbuilt.push(entry.id);\n return entry;\n }\n seen.add(entry.id);\n return toModule(hit);\n });\n for (const piece of built) {\n if (!seen.has(piece.name)) pieces.push(toModule(piece));\n }\n return { manifest: { ...manifest, pieces }, unbuilt };\n}\n\nconst count = (record: unknown) =>\n typeof record === \"object\" && record !== null\n ? Object.keys(record).length\n : 0;\n\n// Build every planned piece, then read the built list and describe what it\n// names. Returns what was built, for the manifest.\nexport async function buildPieces(\n target: PieceBuildTarget,\n pkg: PackageIdentity,\n options: PieceBuildOptions,\n): Promise<BuiltPiece[]> {\n const { projectRoot, outDir } = target;\n assertPiecesOutDir(target);\n const redirect = target.writeTo\n ? {\n from: resolve(projectRoot, outDir),\n to: target.writeTo,\n toReal: realpathSafe(target.writeTo),\n }\n : undefined;\n // resolve, not join: an absolute --out-dir is what the browser and node\n // steps hand tsdown, and joining it onto the project root mangles it.\n const externalByDir = new Map<string, Map<string, ExternalDependency>>();\n for (const piece of target.pieces) {\n console.log(`\\n▶ Building piece ${piece.dir}...`);\n const outDir = resolve(projectRoot, piece.outDir);\n const external = new Map<string, ExternalDependency>();\n await options.bundle(\n buildPieceBuildConfig({\n entry: resolve(projectRoot, piece.entry),\n outDir: onDisk(outDir, redirect),\n ...(options.trace\n ? {\n plugins: [\n externalDepsPlugin(options.trace, external, {\n root: projectRoot,\n ...(options.cache ? { cache: options.cache } : {}),\n }),\n ],\n }\n : {}),\n }),\n );\n for (const dep of external.values()) {\n console.log(\n `piece ${piece.dir}: ${dep.name}@${dep.version} stays external, it needs ${projectPath(projectRoot, dep.file)}`,\n );\n }\n externalByDir.set(outDir, external);\n }\n\n // The list is the source of truth for names; a package that\n // built pieces without a list has nothing a host could read.\n const listPath = pieceListPath(target);\n if (!existsSync(onDisk(listPath, redirect))) {\n throw new Error(\n `pieces: ${toPosix(relative(projectRoot, listPath))} was not built; ` +\n `pieces/index.ts must export the list of pieces this package ships`,\n );\n }\n const described = describePiecesThrough(projectRoot, listPath, redirect);\n\n const built: BuiltPiece[] = [];\n const listedDirs = new Set<string>();\n for (const piece of described.list) {\n const location = locatePieceThrough(piece, projectRoot, outDir, redirect);\n const dirOnDisk = onDisk(location.dir, redirect);\n assertPieceVersion(piece, pkg);\n const failure = described.errors.find((e) => e.name === piece.name);\n if (failure) {\n throw new Error(\n `pieces: \"${piece.name}\" could not be described: ${failure.message}`,\n );\n }\n const found = described.pieces.find((p) => p.name === piece.name);\n if (!found) {\n throw new Error(`pieces: \"${piece.name}\" was not described`);\n }\n const metadata = found.metadata;\n const relDir = toPosix(relative(projectRoot, location.dir));\n listedDirs.add(relDir);\n\n writeFileSync(\n join(dirOnDisk, \"descriptor.json\"),\n JSON.stringify(\n pieceDescriptor(piece, pkg.version, metadata),\n createJsonReplacer(),\n 2,\n ) + \"\\n\",\n );\n const piecePackage =\n location.form === \"entry\" && location.entryFile\n ? piecePackageJson({\n name: piece.name,\n version: pkg.version,\n description: metadata.description,\n main: relative(location.dir, location.entryFile),\n license: pkg.license,\n dependencies: externalDependencyVersions(\n externalByDir.get(resolve(location.dir))?.values() ?? [],\n ),\n })\n : bundlePackageJson(dirOnDisk, pkg.version);\n writeFileSync(\n join(dirOnDisk, \"package.json\"),\n JSON.stringify(piecePackage, null, 2) + \"\\n\",\n );\n console.log(\n `piece: ${piece.name}@${pkg.version} -> ${relDir} ` +\n `(${count(metadata.actions)} actions, ${count(metadata.triggers)} triggers)`,\n );\n built.push({\n name: piece.name,\n version: pkg.version,\n displayName: metadata.displayName,\n description: metadata.description,\n bundle: relDir,\n descriptor: `${relDir}/descriptor.json`,\n });\n }\n\n warnUnlistedPieces(target.pieces, listedDirs);\n return built;\n}\n\n// A built piece no list entry points into ships without a host ever finding it.\nfunction warnUnlistedPieces(\n planned: PiecePlan[],\n listedDirs: Set<string>,\n): void {\n for (const piece of planned) {\n if (!listedDirs.has(toPosix(piece.outDir))) {\n console.warn(\n `⚠ pieces: pieces/${piece.dir} was built but pieces/index.ts does not list it; a host will not find it`,\n );\n }\n }\n}\n\n// Make sure the manifest ships under outDir (tsdown copies it only in the\n// browser build) and, when pieces were built, list them in that copy.\n\n// Always copied afresh: only <outDir>/node is cleaned by the builds, so a copy\n// left by the last build would otherwise outlive an edit to the source.\n\n// The source file is never written. Returns the path of the copy, if any.\nexport function syncDistManifest(\n target: PieceBuildTarget,\n built: BuiltPiece[],\n externalDependencies: Record<string, string> = {},\n): string | undefined {\n const { projectRoot, outDir } = target;\n const source = join(projectRoot, \"powerhouse.manifest.json\");\n // resolve, not join: an absolute --out-dir is a location, not a suffix.\n const copy = resolve(projectRoot, outDir, \"powerhouse.manifest.json\");\n // The built list, not the source plan: a package whose pieces are all\n // `bundle:` entries has no pieces/<dir> and still ships pieces.\n const shipsPieces = existsSync(pieceListPath(target));\n const shipsExternal = Object.keys(externalDependencies).length > 0;\n if (!existsSync(source)) {\n if (shipsPieces) {\n console.warn(\"⚠ no powerhouse.manifest.json; pieces will not be listed\");\n }\n if (shipsExternal) {\n console.warn(\n \"⚠ no powerhouse.manifest.json; external dependencies will not be listed\",\n );\n }\n return undefined;\n }\n mkdirSync(dirname(copy), { recursive: true });\n copyFileSync(source, copy);\n if (!shipsPieces && !shipsExternal) return copy;\n\n let manifest = JSON.parse(readFileSync(copy, \"utf8\")) as Manifest;\n if (shipsPieces) {\n const enriched = enrichManifestPieces(manifest, built);\n for (const id of enriched.unbuilt) {\n console.warn(`⚠ manifest lists piece \"${id}\" but nothing built it`);\n }\n manifest = enriched.manifest;\n }\n if (shipsExternal) manifest = { ...manifest, externalDependencies };\n writeFileSync(copy, JSON.stringify(manifest, null, 2) + \"\\n\");\n return copy;\n}\n"],"mappings":";;;;;;;AAkCA,MAAa,8BAA8C;CACzD,uBAAO,IAAI,IAAI;CACf,sBAAM,IAAI,IAAI;AAChB;AAwBA,MAAM,eAAe,GAAG,IAAI,cAAc;;AAG1C,SAAgB,YAAY,MAAc,MAAsB;CAC9D,OAAO,SAAS,MAAM,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;AACjD;AAGA,MAAM,YAAY,SAChB,QAAQ,aAAa,UAAU,KAAK,YAAY,IAAI;AAGtD,SAAgB,cAAc,WAAuC;CACnE,IAAI,UAAU,WAAW,GAAG,KAAK,WAAW,SAAS,GAAG,OAAO,KAAA;CAC/D,MAAM,QAAQ,UAAU,MAAM,GAAG;CAIjC,QAHa,UAAU,WAAW,GAAG,IACjC,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAC1B,MAAM,OACK,KAAA;AACjB;AAGA,SAAgB,cAAc,MAAkC;CAC9D,MAAM,KAAK,KAAK,YAAY,YAAY;CACxC,IAAI,KAAK,GAAG,OAAO,KAAA;CACnB,MAAM,OAAO,KAAK,MAAM,KAAK,aAAa,MAAM,CAAC,CAAC,MAAM,GAAG;CAC3D,MAAM,QAAQ,KAAK,EAAE,EAAE,WAAW,GAAG,IAAI,IAAI;CAC7C,IAAI,KAAK,UAAU,OAAO,OAAO,KAAA;CACjC,OAAO,KAAK,KAAK,MAAM,GAAG,KAAK,aAAa,MAAM,GAAG,GAAG,KAAK,MAAM,GAAG,KAAK,CAAC;AAC9E;AAEA,SAAS,gBAAgB,MAAuC;CAC9D,IAAI;EACF,OAAO,KAAK,MACV,aAAa,KAAK,MAAM,cAAc,GAAG,MAAM,CACjD;CACF,QAAQ;EACN;CACF;AAC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AK;EACrD,KAAK,MAAM,MAAM,SAAS,SACxB,QAAQ,KAAK,2BAA2B,GAAG,uBAAuB;EAEpE,WAAW,SAAS;CACtB;CACA,IAAI,eAAe,WAAW;EAAE,GAAG;EAAU;CAAqB;CAClE,cAAc,MAAM,KAAK,UAAU,UAAU,MAAM,CAAC,IAAI,IAAI;CAC5D,OAAO;AACT"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
//#region clis/command-names.d.ts
|
|
2
|
-
export declare const phCliCommandNames: readonly ["generate", "vetra", "connect", "build", "publish", "list", "l", "access-token", "registry-login", "inspect", "is", "migrate", "switchboard", "reactor", "login", "logout", "install", "add", "i", "uninstall", "remove"];
|
|
2
|
+
export declare const phCliCommandNames: readonly ["run", "host", "generate", "vetra", "connect", "build", "publish", "list", "l", "access-token", "registry-login", "inspect", "is", "keyframes", "mcp", "migrate", "model", "switchboard", "reactor", "login", "logout", "install", "add", "i", "uninstall", "remove"];
|
|
3
|
+
/** Set by ph-cmd on the ph-cli it spawns in the project root: where `ph` was run. */
|
|
4
|
+
export declare const CALLER_CWD_ENV = "PH_CALLER_CWD";
|
|
3
5
|
//#endregion
|
|
4
6
|
export {};
|
|
5
7
|
//# sourceMappingURL=command-names.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-names.d.mts","names":[],"sources":["../../clis/command-names.ts"],"mappings":";qBAEa"}
|
|
1
|
+
{"version":3,"file":"command-names.d.mts","names":[],"sources":["../../clis/command-names.ts"],"mappings":";qBAEa;;qBA8BA"}
|