stitchkit 0.132.3 → 0.133.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/CHANGELOG.md +178 -1
- package/README.md +4 -0
- package/dist/agent-executor/acp/v1-connect.d.ts +12 -1
- package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-driver.d.ts +3 -1
- package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-handlers.d.ts +9 -1
- package/dist/agent-executor/acp/v1-handlers.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-permission.d.ts +3 -2
- package/dist/agent-executor/acp/v1-permission.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-probe.d.ts +10 -1
- package/dist/agent-executor/acp/v1-probe.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-session.d.ts +11 -2
- package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-turn.d.ts +13 -10
- package/dist/agent-executor/acp/v1-turn.d.ts.map +1 -1
- package/dist/agent-executor/claude/cli-driver.d.ts +6 -0
- package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -1
- package/dist/agent-executor/claude/record-router.d.ts +44 -0
- package/dist/agent-executor/claude/record-router.d.ts.map +1 -0
- package/dist/agent-executor/claude/session.d.ts +2 -0
- package/dist/agent-executor/claude/session.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/driver.d.ts +20 -2
- package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/engine-spawn.d.ts +18 -0
- package/dist/agent-executor/claude-sdk/engine-spawn.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/query-loop.d.ts +8 -11
- package/dist/agent-executor/claude-sdk/query-loop.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/query-manager.d.ts +4 -2
- package/dist/agent-executor/claude-sdk/query-manager.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/query-options.d.ts +1 -0
- package/dist/agent-executor/claude-sdk/query-options.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/session.d.ts.map +1 -1
- package/dist/agent-executor/codex/capabilities.d.ts +8 -0
- package/dist/agent-executor/codex/capabilities.d.ts.map +1 -0
- package/dist/agent-executor/codex/connect.d.ts +6 -1
- package/dist/agent-executor/codex/connect.d.ts.map +1 -1
- package/dist/agent-executor/codex/driver.d.ts +10 -0
- package/dist/agent-executor/codex/driver.d.ts.map +1 -1
- package/dist/agent-executor/codex/event-routing.d.ts +23 -1
- package/dist/agent-executor/codex/event-routing.d.ts.map +1 -1
- package/dist/agent-executor/codex/handlers.d.ts +23 -3
- package/dist/agent-executor/codex/handlers.d.ts.map +1 -1
- package/dist/agent-executor/codex/limits.d.ts +17 -0
- package/dist/agent-executor/codex/limits.d.ts.map +1 -1
- package/dist/agent-executor/codex/request-answers.d.ts +23 -3
- package/dist/agent-executor/codex/request-answers.d.ts.map +1 -1
- package/dist/agent-executor/codex/session-bind.d.ts +6 -1
- package/dist/agent-executor/codex/session-bind.d.ts.map +1 -1
- package/dist/agent-executor/codex/session-types.d.ts +5 -1
- package/dist/agent-executor/codex/session-types.d.ts.map +1 -1
- package/dist/agent-executor/codex/session.d.ts.map +1 -1
- package/dist/agent-executor/codex/shared-server.d.ts.map +1 -1
- package/dist/agent-executor/codex/shared-thread.d.ts +6 -8
- package/dist/agent-executor/codex/shared-thread.d.ts.map +1 -1
- package/dist/agent-executor/codex/thread-open.d.ts +12 -3
- package/dist/agent-executor/codex/thread-open.d.ts.map +1 -1
- package/dist/agent-executor/engine-requests.d.ts +42 -0
- package/dist/agent-executor/engine-requests.d.ts.map +1 -1
- package/dist/agent-executor/handoff-schemas.d.ts.map +1 -1
- package/dist/agent-executor/handoff.d.ts.map +1 -1
- package/dist/agent-executor/image-input.d.ts +6 -5
- package/dist/agent-executor/image-input.d.ts.map +1 -1
- package/dist/agent-executor/profile.d.ts +3 -5
- package/dist/agent-executor/profile.d.ts.map +1 -1
- package/dist/agent-executor/session-primitives.d.ts +64 -3
- package/dist/agent-executor/session-primitives.d.ts.map +1 -1
- package/dist/agent-executor/testing/claude-sdk-stubs.d.ts +5 -0
- package/dist/agent-executor/testing/claude-sdk-stubs.d.ts.map +1 -0
- package/dist/agent-executor/testing/conformance-lifecycle.d.ts +11 -0
- package/dist/agent-executor/testing/conformance-lifecycle.d.ts.map +1 -0
- package/dist/agent-executor/testing/conformance-support.d.ts +23 -0
- package/dist/agent-executor/testing/conformance-support.d.ts.map +1 -0
- package/dist/agent-executor/testing/conformance.d.ts +7 -2
- package/dist/agent-executor/testing/conformance.d.ts.map +1 -1
- package/dist/agent-executor/testing/consumer-stubs.d.ts +5 -3
- package/dist/agent-executor/testing/consumer-stubs.d.ts.map +1 -1
- package/dist/agent-executor/testing/fake-codex-app-server.d.ts +5 -1
- package/dist/agent-executor/testing/fake-codex-app-server.d.ts.map +1 -1
- package/dist/agent-executor/testing/replay-driver.d.ts +6 -0
- package/dist/agent-executor/testing/replay-driver.d.ts.map +1 -1
- package/dist/agent-executor/testing/replay-gate.d.ts +4 -1
- package/dist/agent-executor/testing/replay-gate.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tool-types.d.ts +2 -0
- package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tools.d.ts.map +1 -1
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/operation-refusal.d.ts +10 -0
- package/dist/browser/operation-refusal.d.ts.map +1 -0
- package/dist/contract/client-types.d.ts +13 -4
- package/dist/contract/client-types.d.ts.map +1 -1
- package/dist/contract/define-validation.d.ts +6 -0
- package/dist/contract/define-validation.d.ts.map +1 -1
- package/dist/contract/define.d.ts +3 -0
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/errors-factory.d.ts +8 -2
- package/dist/contract/errors-factory.d.ts.map +1 -1
- package/dist/contract/errors.d.ts +9 -0
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/fingerprint.d.ts +4 -1
- package/dist/contract/fingerprint.d.ts.map +1 -1
- package/dist/contract/operation-refusals.d.ts +51 -0
- package/dist/contract/operation-refusals.d.ts.map +1 -0
- package/dist/contract/tool-options.d.ts +4 -0
- package/dist/contract/tool-options.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +253 -210
- package/dist/entrypoints/agent-executor/claude-sdk.js +248 -173
- package/dist/entrypoints/agent-executor/claude.js +57 -109
- package/dist/entrypoints/agent-executor/codex.js +412 -335
- package/dist/entrypoints/agent-executor/testing/claude-sdk.d.ts +3 -0
- package/dist/entrypoints/agent-executor/testing/claude-sdk.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/testing/claude-sdk.js +329 -0
- package/dist/entrypoints/agent-executor/testing.d.ts +1 -2
- package/dist/entrypoints/agent-executor/testing.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/testing.js +413 -667
- package/dist/entrypoints/agent-executor.d.ts +1 -1
- package/dist/entrypoints/agent-executor.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor.js +12 -12
- package/dist/entrypoints/agent-runtime/browser.js +2 -2
- package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
- package/dist/entrypoints/agent-runtime/harness.js +8 -8
- package/dist/entrypoints/agent-runtime/postgres.js +5 -5
- package/dist/entrypoints/agent-runtime/realtime.js +2 -2
- package/dist/entrypoints/agent-runtime/sandbox.js +3 -3
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +6 -6
- package/dist/entrypoints/agent-runtime/sqlite/node.js +6 -6
- package/dist/entrypoints/agent-runtime/testing.js +5 -5
- package/dist/entrypoints/agent-runtime.js +26 -18
- package/dist/entrypoints/application/grammy.js +1 -1
- package/dist/entrypoints/application.js +2 -2
- package/dist/entrypoints/cli.js +8 -8
- package/dist/entrypoints/contract.d.ts +3 -2
- package/dist/entrypoints/contract.d.ts.map +1 -1
- package/dist/entrypoints/contract.js +6 -4
- package/dist/entrypoints/files/packaging.d.ts +4 -1
- package/dist/entrypoints/files/packaging.d.ts.map +1 -1
- package/dist/entrypoints/files/packaging.js +1008 -168
- package/dist/entrypoints/files.js +1 -1
- package/dist/entrypoints/handler.js +7 -7
- package/dist/entrypoints/http.js +2 -2
- package/dist/entrypoints/index.js +10 -8
- package/dist/entrypoints/node.js +11 -11
- package/dist/entrypoints/observability.js +1 -1
- package/dist/entrypoints/process/bootstrap.d.ts +3 -0
- package/dist/entrypoints/process/bootstrap.d.ts.map +1 -0
- package/dist/entrypoints/process/bootstrap.js +16 -0
- package/dist/entrypoints/process.js +7 -7
- package/dist/entrypoints/realtime.js +3 -3
- package/dist/entrypoints/remote.js +8 -7
- package/dist/entrypoints/server.js +30 -14
- package/dist/entrypoints/service-host/macos.js +72 -206
- package/dist/entrypoints/service-host/work.d.ts +15 -0
- package/dist/entrypoints/service-host/work.d.ts.map +1 -0
- package/dist/entrypoints/service-host/work.js +676 -0
- package/dist/entrypoints/service-host.js +146 -536
- package/dist/entrypoints/telegram/screens.js +4 -4
- package/dist/entrypoints/telegram.js +4 -4
- package/dist/entrypoints/testing.d.ts +2 -1
- package/dist/entrypoints/testing.d.ts.map +1 -1
- package/dist/entrypoints/testing.js +27 -8
- package/dist/entrypoints/tools/agent.js +6 -6
- package/dist/entrypoints/tools/connections.js +2 -2
- package/dist/entrypoints/tools/invoker.js +5 -5
- package/dist/entrypoints/tools/mcp.js +8 -6
- package/dist/entrypoints/tools/toolkit.js +11 -9
- package/dist/entrypoints/tools.js +19 -17
- package/dist/entrypoints/tracking/contract.js +1 -1
- package/dist/entrypoints/tracking/performance.js +3 -3
- package/dist/files/client-artifact.d.ts +14 -42
- package/dist/files/client-artifact.d.ts.map +1 -1
- package/dist/files/client-build.d.ts +57 -0
- package/dist/files/client-build.d.ts.map +1 -0
- package/dist/files/client-declarations.d.ts +35 -0
- package/dist/files/client-declarations.d.ts.map +1 -0
- package/dist/files/client-package-bundle.d.ts +25 -0
- package/dist/files/client-package-bundle.d.ts.map +1 -0
- package/dist/files/client-package-contract.d.ts +183 -0
- package/dist/files/client-package-contract.d.ts.map +1 -0
- package/dist/files/client-package-proof.d.ts +40 -0
- package/dist/files/client-package-proof.d.ts.map +1 -0
- package/dist/files/client-package.d.ts +17 -0
- package/dist/files/client-package.d.ts.map +1 -0
- package/dist/files/declaration-specifiers.d.ts +30 -0
- package/dist/files/declaration-specifiers.d.ts.map +1 -0
- package/dist/{index-v759mzed.js → index-02r5sq9p.js} +36 -23
- package/dist/{index-0r15pkjq.js → index-0k1ba0ss.js} +1 -1
- package/dist/{index-znd1b57f.js → index-1dn2wjq6.js} +5 -4
- package/dist/{index-p06z7g7w.js → index-1p8q0yrt.js} +6 -5
- package/dist/{index-wa6h4tz6.js → index-1qwd54n3.js} +6 -5
- package/dist/index-2dzc7mv9.js +174 -0
- package/dist/index-2mz8hj58.js +155 -0
- package/dist/{index-17qgm6xe.js → index-34k82crg.js} +2 -2
- package/dist/index-3mcbr8sx.js +349 -0
- package/dist/{index-ybdq8kk2.js → index-3y2tzhr8.js} +3 -3
- package/dist/{index-fgahdc7s.js → index-5n3a8hd8.js} +5 -3
- package/dist/{index-jb4m241t.js → index-6918kxbf.js} +45 -1
- package/dist/{index-n3bm7zqq.js → index-6kmjcm81.js} +4 -4
- package/dist/{index-akf0xkrm.js → index-78da4g74.js} +1 -1
- package/dist/{index-9pv126eh.js → index-7fjbdga8.js} +7 -1
- package/dist/{index-zhshhxew.js → index-8jf4bt7v.js} +1 -1
- package/dist/{index-p16q492v.js → index-8t9dr41h.js} +18 -5
- package/dist/{index-xq4s9mka.js → index-8yt3rwe7.js} +1 -1
- package/dist/{index-39c2hj6h.js → index-9c76vfxf.js} +7 -3
- package/dist/index-9ft4n9j1.js +432 -0
- package/dist/{index-sd4e5x5j.js → index-9wdrwx3b.js} +8 -7
- package/dist/{index-z114ax5e.js → index-an7vcmwf.js} +49 -2
- package/dist/{index-pzhqydxb.js → index-d04w81fz.js} +1 -1
- package/dist/index-d2drhb9c.js +219 -0
- package/dist/{index-8gmmdz7k.js → index-dacxr7nf.js} +1 -1
- package/dist/{index-dnzxxf8a.js → index-dm6nxkn1.js} +1 -1
- package/dist/index-dxft2mnm.js +42 -0
- package/dist/{index-rxh3qy4x.js → index-fzd477xk.js} +1 -1
- package/dist/{index-xgae0bn7.js → index-g4gstmp1.js} +2 -2
- package/dist/{index-athc412x.js → index-g5fgeb6v.js} +1 -1
- package/dist/{index-z9d74jmb.js → index-gbhj370g.js} +3 -3
- package/dist/{index-3fym4j8n.js → index-gtaaxe9d.js} +1 -1
- package/dist/{index-v59pxmf1.js → index-jpecjm30.js} +2 -2
- package/dist/index-k9g061ma.js +164 -0
- package/dist/{index-669374qc.js → index-ma26mfnt.js} +84 -315
- package/dist/{index-ryxb427v.js → index-msxf2r8x.js} +16 -3
- package/dist/{index-rbd2rq3z.js → index-nr4fhfn4.js} +1 -1
- package/dist/{index-qa2jjb65.js → index-pbekeqzm.js} +1 -1
- package/dist/{index-mkfhpk11.js → index-pq6g1k9t.js} +2 -2
- package/dist/{index-gya4hwh3.js → index-pws5c3x6.js} +21 -1
- package/dist/{index-x2fb37t0.js → index-q427q23r.js} +3 -2
- package/dist/{index-jcrj0b8z.js → index-qggqqja2.js} +39 -2
- package/dist/{index-jxtg307y.js → index-rkjfzs0a.js} +1 -1
- package/dist/{index-5tdc0q43.js → index-rw8ze745.js} +5 -3
- package/dist/index-s43tr4my.js +129 -0
- package/dist/{index-f9p62ean.js → index-stpy56r3.js} +175 -249
- package/dist/index-t5g5rm9n.js +213 -0
- package/dist/{index-z20pdxeb.js → index-tmv3ez1h.js} +3 -3
- package/dist/{index-dcsxj68j.js → index-tqjamnax.js} +1 -1
- package/dist/{index-j15dhkda.js → index-wddcfbng.js} +1 -325
- package/dist/{index-9sfhje6y.js → index-wh70tmpd.js} +24 -234
- package/dist/index-wxjv4sqx.js +82 -0
- package/dist/{index-qhjmmsm2.js → index-x46y9z26.js} +2 -2
- package/dist/{index-nk0cy9g1.js → index-y53cqwke.js} +1 -1
- package/dist/{index-sv5svtq7.js → index-y68gavb5.js} +1 -1
- package/dist/{index-5y7j383h.js → index-yrhw10ef.js} +1 -1
- package/dist/process/bootstrap.d.ts +12 -0
- package/dist/process/bootstrap.d.ts.map +1 -0
- package/dist/process/owner-loss-guard.d.ts +2 -9
- package/dist/process/owner-loss-guard.d.ts.map +1 -1
- package/dist/process/work-root.d.ts +20 -0
- package/dist/process/work-root.d.ts.map +1 -0
- package/dist/server/contract-identity.d.ts.map +1 -1
- package/dist/server/contract-method.d.ts +12 -0
- package/dist/server/contract-method.d.ts.map +1 -1
- package/dist/server/implement.d.ts.map +1 -1
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/server/types.d.ts +10 -9
- package/dist/server/types.d.ts.map +1 -1
- package/dist/service-host/host-adapter.d.ts +2 -0
- package/dist/service-host/host-adapter.d.ts.map +1 -1
- package/dist/service-host/work/command.d.ts +72 -0
- package/dist/service-host/work/command.d.ts.map +1 -0
- package/dist/service-host/work/errors.d.ts +29 -0
- package/dist/service-host/work/errors.d.ts.map +1 -0
- package/dist/service-host/work/host.d.ts +38 -0
- package/dist/service-host/work/host.d.ts.map +1 -0
- package/dist/service-host/work/launch.d.ts +51 -0
- package/dist/service-host/work/launch.d.ts.map +1 -0
- package/dist/service-host/work/membership.d.ts +51 -0
- package/dist/service-host/work/membership.d.ts.map +1 -0
- package/dist/service-host/work/origin.d.ts +79 -0
- package/dist/service-host/work/origin.d.ts.map +1 -0
- package/dist/service-host/work/owner.d.ts +45 -0
- package/dist/service-host/work/owner.d.ts.map +1 -0
- package/dist/service-host/work/placement.d.ts +55 -0
- package/dist/service-host/work/placement.d.ts.map +1 -0
- package/dist/service-host/work/probe.d.ts +24 -0
- package/dist/service-host/work/probe.d.ts.map +1 -0
- package/dist/service-host/work/scope-command.d.ts +68 -0
- package/dist/service-host/work/scope-command.d.ts.map +1 -0
- package/dist/sync/session.d.ts +4 -1
- package/dist/sync/session.d.ts.map +1 -1
- package/dist/testing/surface-manifest-digest.d.ts +2 -0
- package/dist/testing/surface-manifest-digest.d.ts.map +1 -1
- package/dist/testing/surface-manifest.d.ts +32 -3
- package/dist/testing/surface-manifest.d.ts.map +1 -1
- package/dist/tools/agent.d.ts +2 -0
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/cli/stream-surface.d.ts.map +1 -1
- package/dist/tools/internal/mcp-projection.d.ts +58 -0
- package/dist/tools/internal/mcp-projection.d.ts.map +1 -0
- package/dist/tools/internal/surface-projector.d.ts +3 -47
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/dist/tools/invoker.d.ts +2 -0
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/manifest.d.ts +2 -0
- package/dist/tools/manifest.d.ts.map +1 -1
- package/dist/tools/mcp/handler.d.ts.map +1 -1
- package/dist/tools/mcp/lazy-discovery.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts +4 -0
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/prepare.d.ts +5 -2
- package/dist/tools/mcp/prepare.d.ts.map +1 -1
- package/dist/tools/mount.d.ts +2 -0
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/remote.d.ts.map +1 -1
- package/dist/tools/schema/nesting-limit.d.ts +8 -0
- package/dist/tools/schema/nesting-limit.d.ts.map +1 -0
- package/dist/tools/schema/presentation.d.ts +7 -0
- package/dist/tools/schema/presentation.d.ts.map +1 -1
- package/dist/tools/surface.d.ts.map +1 -1
- package/llms/agent-executor-acp.txt +3 -3
- package/llms/agent-executor-claude-sdk.txt +1 -1
- package/llms/agent-executor-claude.txt +1 -1
- package/llms/agent-executor-codex.txt +1 -1
- package/llms/agent-executor-testing-claude-sdk.txt +28 -0
- package/llms/agent-executor-testing.txt +7 -8
- package/llms/agent-executor.txt +27 -4
- package/llms/agent-runtime.txt +1 -1
- package/llms/contract.txt +8 -2
- package/llms/files-packaging.txt +11 -6
- package/llms/process-bootstrap.txt +18 -0
- package/llms/process.2.txt +248 -18
- package/llms/process.txt +130 -92
- package/llms/server.4.txt +49 -1
- package/llms/service-host-work.txt +34 -0
- package/llms/stitchkit.2.txt +31 -0
- package/llms/stitchkit.txt +78 -75
- package/llms/sync.txt +5 -2
- package/llms/testing.txt +1 -0
- package/llms/tools.2.txt +747 -775
- package/llms/tools.3.txt +846 -210
- package/llms/tools.4.txt +226 -0
- package/llms/tools.txt +3 -790
- package/llms/{upgrading-0.128.0-0.132.0.txt → upgrading-0.128.0-0.133.0.txt} +194 -6
- package/llms/upgrading.txt +1 -1
- package/llms-full.txt +779 -135
- package/llms.txt +18 -16
- package/package.json +12 -4
- package/dist/entrypoints/process/owner-loss.d.ts +0 -3
- package/dist/entrypoints/process/owner-loss.d.ts.map +0 -1
- package/dist/entrypoints/process/owner-loss.js +0 -7
- package/llms/process-owner-loss.txt +0 -18
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import"../../index-
|
|
2
|
-
import"../../index-
|
|
1
|
+
import"../../index-jpecjm30.js";
|
|
2
|
+
import"../../index-pbekeqzm.js";
|
|
3
3
|
import {
|
|
4
4
|
NATIVE_NOT_PACKAGED
|
|
5
5
|
} from "../../index-6kec3b14.js";
|
|
6
6
|
import {
|
|
7
7
|
runNativeCommand2
|
|
8
|
-
} from "../../index-
|
|
8
|
+
} from "../../index-d04w81fz.js";
|
|
9
9
|
import {
|
|
10
10
|
safeJsonParse
|
|
11
11
|
} from "../../index-zsarb5xp.js";
|
|
@@ -15,9 +15,13 @@ import {
|
|
|
15
15
|
|
|
16
16
|
// src/files/client-artifact.ts
|
|
17
17
|
import { createHash } from "node:crypto";
|
|
18
|
-
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
18
|
+
import { mkdir, mkdtemp, readFile as readFile2, rm, writeFile } from "node:fs/promises";
|
|
19
19
|
import { tmpdir } from "node:os";
|
|
20
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
20
|
+
import { basename, dirname, join, resolve as resolve2 } from "node:path";
|
|
21
|
+
|
|
22
|
+
// src/files/client-build.ts
|
|
23
|
+
import { readFile } from "node:fs/promises";
|
|
24
|
+
import { resolve } from "node:path";
|
|
21
25
|
import { z } from "zod";
|
|
22
26
|
class ForbiddenModuleError extends Error {
|
|
23
27
|
module;
|
|
@@ -29,12 +33,59 @@ class ForbiddenModuleError extends Error {
|
|
|
29
33
|
this.name = "ForbiddenModuleError";
|
|
30
34
|
}
|
|
31
35
|
}
|
|
36
|
+
async function runClientTool(step, executable, args, cwd) {
|
|
37
|
+
const result = await runNativeCommand2({
|
|
38
|
+
executable,
|
|
39
|
+
args: [...args],
|
|
40
|
+
cwd,
|
|
41
|
+
envPolicy: "ambient",
|
|
42
|
+
capture: true,
|
|
43
|
+
maxOutputBytes: 4 * 1024 * 1024,
|
|
44
|
+
timeoutMs: step.timeoutMs,
|
|
45
|
+
signal: step.signal
|
|
46
|
+
});
|
|
47
|
+
const decoder = new TextDecoder;
|
|
48
|
+
const stdout = decoder.decode(result.stdout);
|
|
49
|
+
return {
|
|
50
|
+
ok: result.exitCode === 0,
|
|
51
|
+
exit: String(result.exitCode ?? result.signal),
|
|
52
|
+
stdout,
|
|
53
|
+
output: `${decoder.decode(result.stderr)}${stdout}`.trim()
|
|
54
|
+
};
|
|
55
|
+
}
|
|
32
56
|
var MetafileSchema = z.object({
|
|
33
57
|
inputs: z.record(z.string(), z.object({
|
|
34
|
-
imports: z.array(z.object({
|
|
35
|
-
|
|
58
|
+
imports: z.array(z.object({
|
|
59
|
+
path: z.string(),
|
|
60
|
+
original: z.string().optional(),
|
|
61
|
+
external: z.boolean().default(false)
|
|
62
|
+
})).default([])
|
|
63
|
+
})),
|
|
64
|
+
outputs: z.record(z.string(), z.object({
|
|
65
|
+
entryPoint: z.string().optional(),
|
|
66
|
+
exports: z.array(z.string()).default([])
|
|
67
|
+
})).default({})
|
|
36
68
|
});
|
|
37
|
-
function
|
|
69
|
+
async function readClientBuildGraph(metafilePath, root) {
|
|
70
|
+
const metafile = MetafileSchema.parse(safeJsonParse(await readFile(metafilePath, "utf8")));
|
|
71
|
+
const absolute = (path) => resolve(root, path).replaceAll("\\", "/");
|
|
72
|
+
const modules = new Map;
|
|
73
|
+
for (const [path, input] of Object.entries(metafile.inputs)) {
|
|
74
|
+
modules.set(absolute(path), input.imports.map((imported) => ({
|
|
75
|
+
path: imported.external ? imported.path : absolute(imported.path),
|
|
76
|
+
original: imported.original,
|
|
77
|
+
external: imported.external
|
|
78
|
+
})));
|
|
79
|
+
}
|
|
80
|
+
const entryOutputs = new Map;
|
|
81
|
+
for (const [path, output] of Object.entries(metafile.outputs)) {
|
|
82
|
+
if (output.entryPoint === undefined)
|
|
83
|
+
continue;
|
|
84
|
+
entryOutputs.set(absolute(output.entryPoint), path.replace(/^\.\//, ""));
|
|
85
|
+
}
|
|
86
|
+
return { modules, entryOutputs };
|
|
87
|
+
}
|
|
88
|
+
function matchesPath(rule, modulePath) {
|
|
38
89
|
if (rule instanceof RegExp)
|
|
39
90
|
return rule.test(modulePath);
|
|
40
91
|
if (rule.startsWith("@") || !rule.includes("/")) {
|
|
@@ -42,161 +93,948 @@ function matches(rule, modulePath) {
|
|
|
42
93
|
}
|
|
43
94
|
return modulePath.includes(rule.startsWith("/") ? rule : `/${rule}`);
|
|
44
95
|
}
|
|
45
|
-
function absoluteModules(metafile, root) {
|
|
46
|
-
const absolute = (path) => resolve(root, path).replaceAll("\\", "/");
|
|
47
|
-
return {
|
|
48
|
-
inputs: Object.fromEntries(Object.entries(metafile.inputs).map(([path, input]) => [
|
|
49
|
-
absolute(path),
|
|
50
|
-
{
|
|
51
|
-
imports: input.imports.map((imported) => ({
|
|
52
|
-
path: absolute(imported.path),
|
|
53
|
-
original: imported.original
|
|
54
|
-
}))
|
|
55
|
-
}
|
|
56
|
-
]))
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
96
|
function namesPackage(specifier, rule) {
|
|
60
97
|
return typeof rule === "string" && specifier !== undefined && (specifier === rule || specifier.startsWith(`${rule}/`));
|
|
61
98
|
}
|
|
62
|
-
function
|
|
63
|
-
for (const [importer,
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
99
|
+
function refuseForbiddenModules(graph, forbidden) {
|
|
100
|
+
for (const [importer, imports] of graph.modules) {
|
|
101
|
+
for (const imported of imports) {
|
|
102
|
+
const specifier = imported.external ? imported.path : imported.original;
|
|
103
|
+
if (forbidden.some((rule) => namesPackage(specifier, rule))) {
|
|
104
|
+
throw new ForbiddenModuleError(imported.path, importer);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
67
107
|
}
|
|
68
|
-
for (const modulePath of
|
|
69
|
-
if (!forbidden.some((rule) =>
|
|
108
|
+
for (const modulePath of graph.modules.keys()) {
|
|
109
|
+
if (!forbidden.some((rule) => matchesPath(rule, modulePath)))
|
|
70
110
|
continue;
|
|
71
|
-
const importer =
|
|
111
|
+
const importer = [...graph.modules].find(([, imports]) => imports.some((imported) => !imported.external && imported.path === modulePath));
|
|
72
112
|
throw new ForbiddenModuleError(modulePath, importer?.[0]);
|
|
73
113
|
}
|
|
74
114
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
executable: step.bun,
|
|
78
|
-
args,
|
|
79
|
-
cwd,
|
|
80
|
-
envPolicy: "ambient",
|
|
81
|
-
capture: true,
|
|
82
|
-
maxOutputBytes: 4 * 1024 * 1024,
|
|
83
|
-
timeoutMs: step.timeoutMs,
|
|
84
|
-
signal: step.signal
|
|
85
|
-
});
|
|
86
|
-
const decoder = new TextDecoder;
|
|
87
|
-
if (result.exitCode !== 0) {
|
|
88
|
-
throw new Error(`Client artifact ${what} failed (exit ${result.exitCode ?? result.signal}): ` + `${decoder.decode(result.stderr)}${decoder.decode(result.stdout)}`.trim());
|
|
89
|
-
}
|
|
90
|
-
return decoder.decode(result.stdout);
|
|
91
|
-
}
|
|
115
|
+
|
|
116
|
+
// src/files/client-artifact.ts
|
|
92
117
|
async function buildClientArtifact(options) {
|
|
93
|
-
const
|
|
94
|
-
bun: options.executable ?? "bun",
|
|
95
|
-
timeoutMs: options.timeoutMs ?? 120000,
|
|
96
|
-
signal: options.signal
|
|
97
|
-
};
|
|
98
|
-
const file = resolve(options.outFile);
|
|
118
|
+
const file = resolve2(options.outFile);
|
|
99
119
|
const sha256File = `${file}.sha256`;
|
|
100
120
|
const work = await mkdtemp(join(tmpdir(), "stitchkit-client-artifact-"));
|
|
101
121
|
try {
|
|
102
122
|
await rm(file, { force: true });
|
|
103
123
|
await rm(sha256File, { force: true });
|
|
104
|
-
const root = dirname(
|
|
124
|
+
const root = dirname(resolve2(options.entry));
|
|
105
125
|
const built = join(work, "client.js");
|
|
106
126
|
const metafilePath = join(work, "meta.json");
|
|
107
|
-
await
|
|
127
|
+
const build = await runClientTool({ timeoutMs: options.timeoutMs ?? 120000, signal: options.signal }, options.executables?.bun ?? "bun", [
|
|
108
128
|
"build",
|
|
109
|
-
|
|
129
|
+
resolve2(options.entry),
|
|
110
130
|
`--target=${options.runtime ?? "node"}`,
|
|
111
131
|
"--format=esm",
|
|
112
132
|
`--outfile=${built}`,
|
|
113
133
|
`--metafile=${metafilePath}`
|
|
114
|
-
], root
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
134
|
+
], root);
|
|
135
|
+
if (!build.ok) {
|
|
136
|
+
throw new Error(`Client artifact build failed (exit ${build.exit}): ${build.output}`);
|
|
137
|
+
}
|
|
138
|
+
const graph = await readClientBuildGraph(metafilePath, root);
|
|
139
|
+
refuseForbiddenModules(graph, options.forbiddenModules ?? []);
|
|
140
|
+
const bytes = await readFile2(built);
|
|
118
141
|
const digest = createHash("sha256").update(bytes).digest("hex");
|
|
119
142
|
await mkdir(dirname(file), { recursive: true });
|
|
120
143
|
await writeFile(file, bytes);
|
|
121
144
|
await writeFile(sha256File, `${digest} ${basename(file)}
|
|
122
145
|
`);
|
|
123
|
-
|
|
146
|
+
return {
|
|
124
147
|
file,
|
|
125
148
|
sha256: digest,
|
|
126
149
|
bytes: bytes.byteLength,
|
|
127
150
|
sha256File,
|
|
128
|
-
modules:
|
|
151
|
+
modules: [...graph.modules.keys()].sort()
|
|
129
152
|
};
|
|
130
|
-
if (options.package === undefined)
|
|
131
|
-
return artifact;
|
|
132
|
-
try {
|
|
133
|
-
return { ...artifact, package: await packAndVerify(step, work, bytes, options.package) };
|
|
134
|
-
} catch (error) {
|
|
135
|
-
await rm(file, { force: true });
|
|
136
|
-
await rm(sha256File, { force: true });
|
|
137
|
-
throw error;
|
|
138
|
-
}
|
|
139
153
|
} finally {
|
|
140
154
|
await rm(work, { recursive: true, force: true });
|
|
141
155
|
}
|
|
142
156
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
157
|
+
// src/files/client-package.ts
|
|
158
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
159
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
160
|
+
import { copyFile as copyFile2, mkdir as mkdir3, mkdtemp as mkdtemp2, readFile as readFile4, realpath as realpath3, rm as rm3, writeFile as writeFile5 } from "node:fs/promises";
|
|
161
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
162
|
+
import { dirname as dirname5, extname, isAbsolute, join as join6, normalize, relative as relative3, resolve as resolve4 } from "node:path";
|
|
163
|
+
|
|
164
|
+
// src/files/client-declarations.ts
|
|
165
|
+
import { randomUUID } from "node:crypto";
|
|
166
|
+
import { rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
167
|
+
import { builtinModules } from "node:module";
|
|
168
|
+
import { dirname as dirname3, join as join3, relative } from "node:path";
|
|
169
|
+
|
|
170
|
+
// src/files/client-package-contract.ts
|
|
171
|
+
import { z as z2 } from "zod";
|
|
172
|
+
var ClientPackageManifestSchema = z2.looseObject({
|
|
173
|
+
description: z2.string().optional(),
|
|
174
|
+
license: z2.string().optional(),
|
|
175
|
+
repository: z2.union([
|
|
176
|
+
z2.string(),
|
|
177
|
+
z2.object({ type: z2.string(), url: z2.string(), directory: z2.string().optional() })
|
|
178
|
+
]).optional(),
|
|
179
|
+
homepage: z2.string().optional(),
|
|
180
|
+
keywords: z2.array(z2.string()).readonly().optional(),
|
|
181
|
+
author: z2.union([
|
|
182
|
+
z2.string(),
|
|
183
|
+
z2.object({ name: z2.string(), email: z2.string().optional(), url: z2.string().optional() })
|
|
184
|
+
]).optional()
|
|
185
|
+
});
|
|
186
|
+
var CLIENT_PACKAGE_OWNED_FIELDS = [
|
|
187
|
+
"name",
|
|
188
|
+
"version",
|
|
189
|
+
"type",
|
|
190
|
+
"main",
|
|
191
|
+
"module",
|
|
192
|
+
"types",
|
|
193
|
+
"typings",
|
|
194
|
+
"exports",
|
|
195
|
+
"files",
|
|
196
|
+
"dependencies",
|
|
197
|
+
"peerDependencies",
|
|
198
|
+
"bundleDependencies",
|
|
199
|
+
"bundledDependencies"
|
|
200
|
+
];
|
|
201
|
+
var ClientPackageRefusalSchema = z2.enum([
|
|
202
|
+
"build",
|
|
203
|
+
"replacement-unused",
|
|
204
|
+
"declarations",
|
|
205
|
+
"declaration-unresolved",
|
|
206
|
+
"declaration-dependency",
|
|
207
|
+
"bundled-peer",
|
|
208
|
+
"manifest-owned-field",
|
|
209
|
+
"install",
|
|
210
|
+
"peer-range",
|
|
211
|
+
"missing-export",
|
|
212
|
+
"shared-export-split",
|
|
213
|
+
"typecheck"
|
|
214
|
+
]);
|
|
215
|
+
|
|
216
|
+
class ClientPackageError extends Error {
|
|
217
|
+
reason;
|
|
218
|
+
details;
|
|
219
|
+
constructor(reason, message, details = {}, options) {
|
|
220
|
+
super(message, options);
|
|
221
|
+
this.reason = reason;
|
|
222
|
+
this.details = details;
|
|
223
|
+
this.name = "ClientPackageError";
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// src/files/declaration-specifiers.ts
|
|
228
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
229
|
+
import { dirname as dirname2, join as join2, resolve as resolve3 } from "node:path";
|
|
230
|
+
var REFERENCE = /^\/\/\/\s*<reference\s+(path|types)\s*=\s*(["'])([^"']*)\2/;
|
|
231
|
+
function tokenize(source, references) {
|
|
232
|
+
const tokens = [];
|
|
233
|
+
const substitutions = [];
|
|
234
|
+
let braces = 0;
|
|
235
|
+
let index = 0;
|
|
236
|
+
const readTemplate = () => {
|
|
237
|
+
while (index < source.length) {
|
|
238
|
+
const char = source[index];
|
|
239
|
+
if (char === "\\") {
|
|
240
|
+
index += 2;
|
|
241
|
+
} else if (char === "`") {
|
|
242
|
+
index += 1;
|
|
243
|
+
return;
|
|
244
|
+
} else if (char === "$" && source[index + 1] === "{") {
|
|
245
|
+
index += 2;
|
|
246
|
+
substitutions.push(braces);
|
|
247
|
+
braces += 1;
|
|
248
|
+
return;
|
|
249
|
+
} else {
|
|
250
|
+
index += 1;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
const readLineComment = () => {
|
|
255
|
+
const lineEnd = source.indexOf(`
|
|
256
|
+
`, index);
|
|
257
|
+
const end = lineEnd === -1 ? source.length : lineEnd;
|
|
258
|
+
const match = REFERENCE.exec(source.slice(index, end));
|
|
259
|
+
if (match) {
|
|
260
|
+
const text = match[3] ?? "";
|
|
261
|
+
const start = index + match[0].length - 1 - text.length;
|
|
262
|
+
references.push({
|
|
263
|
+
kind: match[1] === "path" ? "reference-path" : "reference-types",
|
|
264
|
+
text,
|
|
265
|
+
start,
|
|
266
|
+
end: start + text.length
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
index = end;
|
|
270
|
+
};
|
|
271
|
+
const readString = (quote) => {
|
|
272
|
+
const start = index;
|
|
273
|
+
index += 1;
|
|
274
|
+
let text = "";
|
|
275
|
+
while (index < source.length && source[index] !== quote) {
|
|
276
|
+
if (source[index] === "\\") {
|
|
277
|
+
text += source[index + 1] ?? "";
|
|
278
|
+
index += 2;
|
|
279
|
+
} else {
|
|
280
|
+
text += source[index];
|
|
281
|
+
index += 1;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
index += 1;
|
|
285
|
+
tokens.push({ kind: "string", text, start, end: index });
|
|
286
|
+
};
|
|
287
|
+
while (index < source.length) {
|
|
288
|
+
const char = source[index] ?? "";
|
|
289
|
+
if (char === "/" && source[index + 1] === "/") {
|
|
290
|
+
readLineComment();
|
|
291
|
+
} else if (char === "/" && source[index + 1] === "*") {
|
|
292
|
+
const close = source.indexOf("*/", index + 2);
|
|
293
|
+
index = close === -1 ? source.length : close + 2;
|
|
294
|
+
} else if (char === '"' || char === "'") {
|
|
295
|
+
readString(char);
|
|
296
|
+
} else if (char === "`") {
|
|
297
|
+
index += 1;
|
|
298
|
+
readTemplate();
|
|
299
|
+
tokens.push({ kind: "punctuation", text: "`", start: index, end: index });
|
|
300
|
+
} else if (char === "{") {
|
|
301
|
+
braces += 1;
|
|
302
|
+
index += 1;
|
|
303
|
+
tokens.push({ kind: "punctuation", text: char, start: index - 1, end: index });
|
|
304
|
+
} else if (char === "}") {
|
|
305
|
+
braces -= 1;
|
|
306
|
+
index += 1;
|
|
307
|
+
if (substitutions.at(-1) === braces) {
|
|
308
|
+
substitutions.pop();
|
|
309
|
+
readTemplate();
|
|
310
|
+
}
|
|
311
|
+
tokens.push({ kind: "punctuation", text: char, start: index - 1, end: index });
|
|
312
|
+
} else if (/[A-Za-z_$]/.test(char)) {
|
|
313
|
+
const start = index;
|
|
314
|
+
while (index < source.length && /[\w$]/.test(source[index] ?? ""))
|
|
315
|
+
index += 1;
|
|
316
|
+
tokens.push({ kind: "word", text: source.slice(start, index), start, end: index });
|
|
317
|
+
} else if (/\s/.test(char)) {
|
|
318
|
+
index += 1;
|
|
319
|
+
} else {
|
|
320
|
+
tokens.push({ kind: "punctuation", text: char, start: index, end: index + 1 });
|
|
321
|
+
index += 1;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return tokens;
|
|
325
|
+
}
|
|
326
|
+
function isModuleSpecifier(tokens, position) {
|
|
327
|
+
const before = tokens[position - 1];
|
|
328
|
+
const earlier = tokens[position - 2];
|
|
329
|
+
if (before?.kind === "word") {
|
|
330
|
+
if (before.text === "from" || before.text === "import")
|
|
331
|
+
return true;
|
|
332
|
+
return before.text === "module" && earlier?.kind === "word" && earlier.text === "declare";
|
|
333
|
+
}
|
|
334
|
+
return before?.text === "(" && earlier?.kind === "word" && (earlier.text === "import" || earlier.text === "require");
|
|
335
|
+
}
|
|
336
|
+
function declarationSpecifiers(source) {
|
|
337
|
+
const found = [];
|
|
338
|
+
const tokens = tokenize(source, found);
|
|
339
|
+
tokens.forEach((token, position) => {
|
|
340
|
+
if (token.kind !== "string" || !isModuleSpecifier(tokens, position))
|
|
341
|
+
return;
|
|
342
|
+
found.push({
|
|
343
|
+
kind: "module",
|
|
344
|
+
text: token.text,
|
|
345
|
+
start: token.start + 1,
|
|
346
|
+
end: token.end - 1
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
return found.sort((left, right) => left.start - right.start);
|
|
350
|
+
}
|
|
351
|
+
function isRelativeSpecifier(specifier) {
|
|
352
|
+
return /^\.\.?(?:\/|$)/.test(specifier);
|
|
353
|
+
}
|
|
354
|
+
var EXTENSIONS = [
|
|
355
|
+
[".ts", ".js", ".d.ts"],
|
|
356
|
+
[".tsx", ".js", ".d.ts"],
|
|
357
|
+
[".mts", ".mjs", ".d.mts"],
|
|
358
|
+
[".cts", ".cjs", ".d.cts"],
|
|
359
|
+
[".js", ".js", ".d.ts"],
|
|
360
|
+
[".jsx", ".js", ".d.ts"],
|
|
361
|
+
[".mjs", ".mjs", ".d.mts"],
|
|
362
|
+
[".cjs", ".cjs", ".d.cts"]
|
|
363
|
+
];
|
|
364
|
+
function declarationOutputSpecifier(file, specifier) {
|
|
365
|
+
const target = resolve3(dirname2(file), specifier);
|
|
366
|
+
for (const [extension, output, declaration] of EXTENSIONS) {
|
|
367
|
+
if (!specifier.endsWith(extension))
|
|
368
|
+
continue;
|
|
369
|
+
const stem = target.slice(0, -extension.length);
|
|
370
|
+
if (existsSync(`${stem}${declaration}`)) {
|
|
371
|
+
return `${specifier.slice(0, -extension.length)}${output}`;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (existsSync(`${target}.d.ts`))
|
|
375
|
+
return `${specifier}.js`;
|
|
376
|
+
if (existsSync(join2(target, "index.d.ts")))
|
|
377
|
+
return `${specifier.replace(/\/$/, "")}/index.js`;
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
function declarationFiles(directory) {
|
|
381
|
+
const files = [];
|
|
382
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
383
|
+
const path = join2(directory, entry.name);
|
|
384
|
+
if (entry.isDirectory())
|
|
385
|
+
files.push(...declarationFiles(path));
|
|
386
|
+
else if (/\.d\.[cm]?ts$/.test(entry.name))
|
|
387
|
+
files.push(path);
|
|
388
|
+
}
|
|
389
|
+
return files.sort();
|
|
390
|
+
}
|
|
391
|
+
function rewriteDeclarationTree(directory, rewrite) {
|
|
392
|
+
let files = 0;
|
|
393
|
+
let specifiers = 0;
|
|
394
|
+
for (const file of declarationFiles(directory)) {
|
|
395
|
+
const source = readFileSync(file, "utf8");
|
|
396
|
+
let output = source;
|
|
397
|
+
let changed = 0;
|
|
398
|
+
for (const specifier of declarationSpecifiers(source).reverse()) {
|
|
399
|
+
const text = rewrite(specifier, file);
|
|
400
|
+
if (text === undefined || text === specifier.text)
|
|
401
|
+
continue;
|
|
402
|
+
output = `${output.slice(0, specifier.start)}${text}${output.slice(specifier.end)}`;
|
|
403
|
+
changed += 1;
|
|
404
|
+
}
|
|
405
|
+
if (changed === 0)
|
|
406
|
+
continue;
|
|
407
|
+
writeFileSync(file, output);
|
|
408
|
+
files += 1;
|
|
409
|
+
specifiers += changed;
|
|
410
|
+
}
|
|
411
|
+
return { files, specifiers };
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// src/files/client-declarations.ts
|
|
415
|
+
async function emitClientDeclarations(input) {
|
|
416
|
+
const root = dirname3(input.tsconfig);
|
|
417
|
+
const generated = join3(root, `.client-package-${randomUUID()}.tsconfig.json`);
|
|
418
|
+
await writeFile2(generated, `${JSON.stringify({
|
|
419
|
+
extends: input.tsconfig,
|
|
420
|
+
compilerOptions: {
|
|
421
|
+
noEmit: false,
|
|
422
|
+
declaration: true,
|
|
423
|
+
emitDeclarationOnly: true,
|
|
424
|
+
declarationMap: false,
|
|
425
|
+
composite: false,
|
|
426
|
+
incremental: false,
|
|
427
|
+
rootDir: root,
|
|
428
|
+
outDir: input.outDir,
|
|
429
|
+
declarationDir: input.outDir
|
|
430
|
+
},
|
|
431
|
+
files: input.entries,
|
|
432
|
+
include: []
|
|
154
433
|
}, null, 2)}
|
|
155
434
|
`);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
435
|
+
try {
|
|
436
|
+
const [compiler, ...leading] = input.tsc;
|
|
437
|
+
const emitted = await runClientTool(input.step, compiler, [...leading, "-p", generated], root);
|
|
438
|
+
if (!emitted.ok) {
|
|
439
|
+
throw new ClientPackageError("declarations", `Client package declarations failed (exit ${emitted.exit}): ${emitted.output}`, { output: emitted.output });
|
|
440
|
+
}
|
|
441
|
+
} finally {
|
|
442
|
+
await rm2(generated, { force: true });
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function packageOf(specifier) {
|
|
446
|
+
const [first = "", second] = specifier.split("/");
|
|
447
|
+
return first.startsWith("@") && second !== undefined ? `${first}/${second}` : first;
|
|
448
|
+
}
|
|
449
|
+
function isPlatformModule(specifier, closure) {
|
|
450
|
+
if (specifier.startsWith("node:") || builtinModules.includes(specifier))
|
|
451
|
+
return true;
|
|
452
|
+
return closure.runtime === "bun" && (specifier === "bun" || specifier.startsWith("bun:"));
|
|
453
|
+
}
|
|
454
|
+
function normalizeClientDeclarations(directory, closure) {
|
|
455
|
+
rewriteDeclarationTree(directory, (specifier, file) => {
|
|
456
|
+
const shown = relative(directory, file);
|
|
457
|
+
if (specifier.kind === "reference-types") {
|
|
458
|
+
const declared = closure.packages.has(specifier.text) || closure.packages.has(`@types/${specifier.text}`) || specifier.text === "node" || isPlatformModule(specifier.text, closure);
|
|
459
|
+
if (!declared)
|
|
460
|
+
throw undeclared(shown, specifier.text, specifier.text);
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (specifier.kind === "reference-path" || isRelativeSpecifier(specifier.text)) {
|
|
464
|
+
const output = specifier.kind === "module" ? declarationOutputSpecifier(file, specifier.text) : undefined;
|
|
465
|
+
if (output === undefined) {
|
|
466
|
+
throw new ClientPackageError("declaration-unresolved", `Client package declaration ${shown} names ${JSON.stringify(specifier.text)}, ` + "which has no declaration in the package", { file: shown, specifier: specifier.text });
|
|
467
|
+
}
|
|
468
|
+
return output;
|
|
469
|
+
}
|
|
470
|
+
if (isPlatformModule(specifier.text, closure))
|
|
471
|
+
return;
|
|
472
|
+
const name = packageOf(specifier.text);
|
|
473
|
+
if (!closure.packages.has(name))
|
|
474
|
+
throw undeclared(shown, specifier.text, name);
|
|
475
|
+
return;
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
function undeclared(file, specifier, name) {
|
|
479
|
+
return new ClientPackageError("declaration-dependency", `Client package declaration ${file} names ${JSON.stringify(specifier)}, but "${name}" ` + "is neither a peer dependency nor a dependency of the package", { file, specifier, package: name });
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// src/files/client-package-bundle.ts
|
|
483
|
+
import { realpathSync } from "node:fs";
|
|
484
|
+
import { realpath, writeFile as writeFile3 } from "node:fs/promises";
|
|
485
|
+
import { join as join4 } from "node:path";
|
|
486
|
+
var REPLACEMENT_LOADERS = {
|
|
487
|
+
".json": "json",
|
|
488
|
+
".ts": "ts",
|
|
489
|
+
".tsx": "tsx",
|
|
490
|
+
".js": "js",
|
|
491
|
+
".mjs": "js",
|
|
492
|
+
".cjs": "js",
|
|
493
|
+
".jsx": "jsx"
|
|
494
|
+
};
|
|
495
|
+
var BUNDLE_SCRIPT = `const config = JSON.parse(await Bun.file(process.argv[2]).text());
|
|
496
|
+
const replacements = new Map(Object.entries(config.replacements));
|
|
497
|
+
const escape = (text) => text.replace(/[.*+?^\${}()|[\\]\\\\]/g, '\\\\$&');
|
|
498
|
+
const loaderOf = (path) => config.loaders[path.slice(path.lastIndexOf('.'))];
|
|
499
|
+
const plugins =
|
|
500
|
+
replacements.size === 0
|
|
501
|
+
? []
|
|
502
|
+
: [
|
|
503
|
+
{
|
|
504
|
+
name: 'stitchkit-replace-modules',
|
|
505
|
+
setup(build) {
|
|
506
|
+
const filter = new RegExp(\`^(?:\${[...replacements.keys()].map(escape).join('|')})$\`);
|
|
507
|
+
build.onLoad({ filter }, (args) => ({
|
|
508
|
+
contents: replacements.get(args.path),
|
|
509
|
+
loader: loaderOf(args.path),
|
|
510
|
+
}));
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
];
|
|
514
|
+
try {
|
|
515
|
+
const result = await Bun.build({
|
|
516
|
+
entrypoints: config.entries,
|
|
517
|
+
root: config.root,
|
|
518
|
+
outdir: config.outdir,
|
|
519
|
+
target: config.target,
|
|
520
|
+
format: 'esm',
|
|
521
|
+
splitting: true,
|
|
522
|
+
external: config.external,
|
|
523
|
+
naming: { entry: '[dir]/[name].[ext]', chunk: 'chunks/[name]-[hash].[ext]' },
|
|
524
|
+
tsconfig: config.tsconfig,
|
|
525
|
+
metafile: true,
|
|
526
|
+
plugins,
|
|
527
|
+
throw: false,
|
|
528
|
+
});
|
|
529
|
+
if (!result.success) {
|
|
530
|
+
for (const log of result.logs) console.error(String(log));
|
|
531
|
+
process.exit(1);
|
|
532
|
+
}
|
|
533
|
+
await Bun.write(config.metafile, JSON.stringify(result.metafile));
|
|
534
|
+
} catch (error) {
|
|
535
|
+
console.error(String(error?.stack ?? error));
|
|
536
|
+
process.exit(1);
|
|
537
|
+
}
|
|
538
|
+
`;
|
|
539
|
+
async function bundleClientPackage(input) {
|
|
540
|
+
const script = join4(input.work, "bundle.mjs");
|
|
541
|
+
const config = join4(input.work, "bundle.json");
|
|
542
|
+
const metafile = join4(input.work, "meta.json");
|
|
543
|
+
await writeFile3(script, BUNDLE_SCRIPT);
|
|
544
|
+
await writeFile3(config, JSON.stringify({
|
|
545
|
+
entries: input.entries,
|
|
546
|
+
root: input.root,
|
|
547
|
+
outdir: input.outdir,
|
|
548
|
+
target: input.runtime,
|
|
549
|
+
external: input.external,
|
|
550
|
+
tsconfig: input.tsconfig,
|
|
551
|
+
metafile,
|
|
552
|
+
replacements: Object.fromEntries([...input.replacements].flatMap(([path, contents]) => [
|
|
553
|
+
[path, contents],
|
|
554
|
+
[realpathSync(path), contents]
|
|
555
|
+
])),
|
|
556
|
+
loaders: REPLACEMENT_LOADERS
|
|
557
|
+
}));
|
|
558
|
+
const built = await runClientTool(input.step, input.bun, [script, config], input.root);
|
|
559
|
+
if (!built.ok) {
|
|
560
|
+
throw new ClientPackageError("build", `Client package build failed (exit ${built.exit}): ${built.output}`, { output: built.output });
|
|
561
|
+
}
|
|
562
|
+
const graph = await readClientBuildGraph(metafile, input.root);
|
|
563
|
+
const bundled = new Set;
|
|
564
|
+
for (const module of graph.modules.keys())
|
|
565
|
+
bundled.add(await realpath(module).catch(() => module));
|
|
566
|
+
for (const module of input.replacements.keys()) {
|
|
567
|
+
if (bundled.has(realpathSync(module)))
|
|
568
|
+
continue;
|
|
569
|
+
throw new ClientPackageError("replacement-unused", `Client package replaces ${module}, which no bundled module imports`, { module });
|
|
570
|
+
}
|
|
571
|
+
return graph;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// src/files/client-package-proof.ts
|
|
575
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
576
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
577
|
+
import { copyFile, mkdir as mkdir2, readdir, readFile as readFile3, realpath as realpath2, writeFile as writeFile4 } from "node:fs/promises";
|
|
578
|
+
import { basename as basename2, dirname as dirname4, join as join5, relative as relative2 } from "node:path";
|
|
579
|
+
import { z as z3 } from "zod";
|
|
580
|
+
var InstalledManifestSchema = z3.object({ version: z3.string() });
|
|
581
|
+
async function resolveExternalPackage(from, name) {
|
|
582
|
+
for (let directory = from;; directory = dirname4(directory)) {
|
|
583
|
+
const candidate = join5(directory, "node_modules", name);
|
|
584
|
+
if (existsSync2(join5(candidate, "package.json"))) {
|
|
585
|
+
const real = await realpath2(candidate);
|
|
586
|
+
const manifest = InstalledManifestSchema.parse(safeJsonParse(await readFile3(join5(real, "package.json"), "utf8")));
|
|
587
|
+
return { directory: real, version: manifest.version };
|
|
588
|
+
}
|
|
589
|
+
if (dirname4(directory) === directory) {
|
|
590
|
+
throw new ClientPackageError("install", `Client package needs "${name}" installed where it is built, and ${from} does not resolve it`, { package: name });
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
async function filesUnder(directory, base = directory) {
|
|
595
|
+
const files = [];
|
|
596
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
597
|
+
const path = join5(directory, entry.name);
|
|
598
|
+
if (entry.isDirectory()) {
|
|
599
|
+
if (entry.name !== "node_modules")
|
|
600
|
+
files.push(...await filesUnder(path, base));
|
|
601
|
+
} else {
|
|
602
|
+
files.push(relative2(base, path).replaceAll("\\", "/"));
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return files.sort();
|
|
606
|
+
}
|
|
607
|
+
var IdentityReportSchema = z3.object({
|
|
608
|
+
exports: z3.record(z3.string(), z3.array(z3.string())),
|
|
609
|
+
shared: z3.array(z3.string()),
|
|
610
|
+
split: z3.array(z3.string()),
|
|
611
|
+
unresolved: z3.array(z3.string())
|
|
612
|
+
});
|
|
613
|
+
function identityScript(name, subpaths, files) {
|
|
614
|
+
return `import { fileURLToPath } from 'node:url';
|
|
615
|
+
const name = ${JSON.stringify(name)};
|
|
616
|
+
const subpaths = ${JSON.stringify(subpaths)};
|
|
617
|
+
const files = ${JSON.stringify(files)};
|
|
618
|
+
const namespaces = {};
|
|
619
|
+
for (const subpath of subpaths) {
|
|
620
|
+
namespaces[subpath] = await import(subpath === '.' ? name : name + subpath.slice(1));
|
|
621
|
+
}
|
|
622
|
+
const exported = {};
|
|
623
|
+
const unresolved = [];
|
|
624
|
+
for (const [subpath, path] of Object.entries(files)) {
|
|
625
|
+
const specifier = name + subpath.slice(1);
|
|
626
|
+
const resolved = fileURLToPath(import.meta.resolve(specifier)).replaceAll('\\\\', '/');
|
|
627
|
+
if (!resolved.endsWith('/node_modules/' + name + path.slice(1))) unresolved.push(subpath);
|
|
628
|
+
else if (path.endsWith('.json')) {
|
|
629
|
+
exported[subpath] = Object.keys(await import(specifier, { with: { type: 'json' } })).sort();
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
const owners = new Map();
|
|
633
|
+
for (const subpath of subpaths) {
|
|
634
|
+
exported[subpath] = Object.keys(namespaces[subpath]).sort();
|
|
635
|
+
for (const key of exported[subpath]) owners.set(key, [...(owners.get(key) ?? []), subpath]);
|
|
636
|
+
}
|
|
637
|
+
const shared = [];
|
|
638
|
+
const split = [];
|
|
639
|
+
for (const [key, list] of owners) {
|
|
640
|
+
if (list.length < 2) continue;
|
|
641
|
+
const first = namespaces[list[0]][key];
|
|
642
|
+
(list.every((subpath) => Object.is(namespaces[subpath][key], first)) ? shared : split).push(key);
|
|
643
|
+
}
|
|
644
|
+
process.stdout.write(
|
|
645
|
+
JSON.stringify({ exports: exported, shared: shared.sort(), split: split.sort(), unresolved }),
|
|
646
|
+
);
|
|
647
|
+
`;
|
|
648
|
+
}
|
|
649
|
+
var RangeReportSchema = z3.array(z3.object({ package: z3.string(), range: z3.string(), installed: z3.string() }));
|
|
650
|
+
var RANGE_SCRIPT = `const declared = JSON.parse(await Bun.file('ranges.json').text());
|
|
651
|
+
const outside = declared.filter((entry) => !Bun.semver.satisfies(entry.installed, entry.range));
|
|
652
|
+
process.stdout.write(JSON.stringify(outside));
|
|
653
|
+
`;
|
|
654
|
+
function ranOrRefuse(result, reason, what, details = {}) {
|
|
655
|
+
if (result.ok)
|
|
656
|
+
return result;
|
|
657
|
+
throw new ClientPackageError(reason, `Client package ${what} failed (exit ${result.exit}): ${result.output}`, { ...details, output: result.output });
|
|
658
|
+
}
|
|
659
|
+
async function install(input) {
|
|
660
|
+
const { options, consumer } = input;
|
|
661
|
+
const peers = Object.keys(options.peerDependencies ?? {});
|
|
662
|
+
const fromBuild = (names) => Object.fromEntries(names.map((name) => [name, `file:${input.externals.get(name)?.directory ?? ""}`]));
|
|
663
|
+
const types = {};
|
|
664
|
+
for (const name of options.proof?.types ?? []) {
|
|
665
|
+
types[name] = `file:${(await resolveExternalPackage(input.root, name)).directory}`;
|
|
666
|
+
}
|
|
667
|
+
await writeFile4(join5(consumer, "package.json"), `${JSON.stringify({
|
|
668
|
+
name: "client-package-consumer",
|
|
669
|
+
private: true,
|
|
670
|
+
type: "module",
|
|
671
|
+
dependencies: {
|
|
672
|
+
...types,
|
|
673
|
+
...fromBuild(peers),
|
|
674
|
+
[options.name]: `file:${input.tarball}`
|
|
675
|
+
},
|
|
676
|
+
overrides: fromBuild(Object.keys(options.dependencies ?? {}))
|
|
677
|
+
}, null, 2)}
|
|
168
678
|
`);
|
|
169
|
-
await
|
|
679
|
+
ranOrRefuse(await runClientTool(input.step, input.tools.bun, ["install", "--ignore-scripts"], consumer), "install", "install");
|
|
680
|
+
const installed = join5(consumer, "node_modules", options.name);
|
|
681
|
+
for (const peer of peers) {
|
|
682
|
+
if (!existsSync2(join5(installed, "node_modules", peer)))
|
|
683
|
+
continue;
|
|
684
|
+
throw new ClientPackageError("bundled-peer", `Client package installs its own copy of peer "${peer}" instead of sharing the consumer's`, { package: peer });
|
|
685
|
+
}
|
|
686
|
+
const files = [];
|
|
687
|
+
for (const path of await filesUnder(input.staged)) {
|
|
688
|
+
const packed = await readFile3(join5(input.staged, path));
|
|
689
|
+
const digest = createHash2("sha256").update(packed).digest("hex");
|
|
690
|
+
const unpacked = existsSync2(join5(installed, path)) ? createHash2("sha256").update(await readFile3(join5(installed, path))).digest("hex") : undefined;
|
|
691
|
+
if (unpacked !== digest) {
|
|
692
|
+
throw new ClientPackageError("install", `Client package file ${path} is not in the installed archive as it was built`, { file: path });
|
|
693
|
+
}
|
|
694
|
+
files.push({ path, sha256: digest, bytes: packed.byteLength });
|
|
695
|
+
}
|
|
696
|
+
return files;
|
|
697
|
+
}
|
|
698
|
+
async function proveRanges(input) {
|
|
699
|
+
const { options, consumer } = input;
|
|
700
|
+
const declared = { ...options.dependencies, ...options.peerDependencies };
|
|
701
|
+
const installedVersions = {};
|
|
702
|
+
for (const name of Object.keys(declared)) {
|
|
703
|
+
const manifest = [join5(options.name, "node_modules", name), name].map((path) => join5(consumer, "node_modules", path, "package.json")).find((path) => existsSync2(path));
|
|
704
|
+
if (manifest === undefined) {
|
|
705
|
+
throw new ClientPackageError("install", `Client package was installed without "${name}"`, { package: name });
|
|
706
|
+
}
|
|
707
|
+
installedVersions[name] = InstalledManifestSchema.parse(safeJsonParse(await readFile3(manifest, "utf8"))).version;
|
|
708
|
+
}
|
|
709
|
+
await writeFile4(join5(consumer, "ranges.json"), JSON.stringify(Object.entries(declared).map(([name, range]) => ({
|
|
710
|
+
package: name,
|
|
711
|
+
range,
|
|
712
|
+
installed: installedVersions[name] ?? ""
|
|
713
|
+
}))));
|
|
714
|
+
await writeFile4(join5(consumer, "ranges.mjs"), RANGE_SCRIPT);
|
|
715
|
+
const ran = ranOrRefuse(await runClientTool(input.step, input.tools.bun, ["ranges.mjs"], consumer), "install", "range check");
|
|
716
|
+
const [outside] = RangeReportSchema.parse(safeJsonParse(ran.stdout));
|
|
717
|
+
if (outside !== undefined) {
|
|
718
|
+
throw new ClientPackageError("peer-range", `Client package declares "${outside.package}" as ${outside.range}, ` + `but it is built and proven against ${outside.installed}`, outside);
|
|
719
|
+
}
|
|
720
|
+
return installedVersions;
|
|
721
|
+
}
|
|
722
|
+
async function proveIdentity(input) {
|
|
723
|
+
const { options, consumer } = input;
|
|
724
|
+
const subpaths = Object.keys(options.entries);
|
|
725
|
+
await writeFile4(join5(consumer, "identity.mjs"), identityScript(options.name, subpaths, Object.fromEntries(input.exportedFiles)));
|
|
726
|
+
const runtimes = (options.runtime ?? "node") === "node" ? ["node", "bun"] : ["bun"];
|
|
727
|
+
const distinct = new Set(options.proof?.distinctExports ?? []);
|
|
728
|
+
let first;
|
|
729
|
+
for (const runtime of runtimes) {
|
|
730
|
+
const ran = ranOrRefuse(await runClientTool(input.step, input.tools[runtime], ["identity.mjs"], consumer), "install", `import in ${runtime}`, { runtime });
|
|
731
|
+
const report = IdentityReportSchema.parse(safeJsonParse(ran.stdout));
|
|
732
|
+
const [unresolved] = report.unresolved;
|
|
733
|
+
if (unresolved !== undefined) {
|
|
734
|
+
throw new ClientPackageError("missing-export", `Client package subpath "${unresolved}" does not resolve to its packed file in ${runtime}`, { subpath: unresolved, runtime });
|
|
735
|
+
}
|
|
736
|
+
for (const [subpath, required] of Object.entries(options.proof?.exports ?? {})) {
|
|
737
|
+
const names = required.filter((name) => !report.exports[subpath]?.includes(name));
|
|
738
|
+
if (names.length === 0)
|
|
739
|
+
continue;
|
|
740
|
+
throw new ClientPackageError("missing-export", `Client package subpath "${subpath}" does not export ${names.join(", ")} in ${runtime}`, { subpath, names, runtime });
|
|
741
|
+
}
|
|
742
|
+
const names = report.split.filter((name) => !distinct.has(name));
|
|
743
|
+
if (names.length > 0) {
|
|
744
|
+
throw new ClientPackageError("shared-export-split", `Client package exports ${names.join(", ")} from several subpaths as different values in ${runtime}`, { names, runtime });
|
|
745
|
+
}
|
|
746
|
+
first ??= report;
|
|
747
|
+
}
|
|
748
|
+
return { exports: first?.exports ?? {}, sharedExports: first?.shared ?? [], runtimes };
|
|
749
|
+
}
|
|
750
|
+
var RESOLUTIONS = [
|
|
751
|
+
{ resolution: "bundler", module: "Preserve" },
|
|
752
|
+
{ resolution: "NodeNext", module: "NodeNext" }
|
|
753
|
+
];
|
|
754
|
+
async function proveTypes(input) {
|
|
755
|
+
const { options, consumer } = input;
|
|
756
|
+
const sources = ["exports.ts"];
|
|
757
|
+
const json = [...input.exportedFiles].filter(([, path]) => path.endsWith(".json"));
|
|
758
|
+
await writeFile4(join5(consumer, "exports.ts"), Object.keys(options.entries).map((subpath, index) => {
|
|
759
|
+
const specifier = subpath === "." ? options.name : options.name + subpath.slice(1);
|
|
760
|
+
return `export * as E${index} from ${JSON.stringify(specifier)};
|
|
761
|
+
`;
|
|
762
|
+
}).concat(json.map(([subpath], index) => {
|
|
763
|
+
const specifier = JSON.stringify(options.name + subpath.slice(1));
|
|
764
|
+
return `import J${index} from ${specifier} with { type: 'json' };
|
|
765
|
+
export { J${index} };
|
|
766
|
+
`;
|
|
767
|
+
})).join(""));
|
|
768
|
+
await mkdir2(join5(consumer, "typecheck"));
|
|
769
|
+
for (const [index, source] of (options.proof?.typecheck ?? []).entries()) {
|
|
770
|
+
const copy = `typecheck/${index}-${basename2(source)}`;
|
|
771
|
+
await copyFile(source, join5(consumer, copy));
|
|
772
|
+
sources.push(copy);
|
|
773
|
+
}
|
|
774
|
+
const [compiler, ...leading] = input.tools.tsc;
|
|
775
|
+
const version = ranOrRefuse(await runClientTool(input.step, compiler, [...leading, "--version"], consumer), "typecheck", "compiler").stdout.replace(/^Version\s+/, "");
|
|
776
|
+
for (const { resolution, module } of RESOLUTIONS) {
|
|
777
|
+
const config = `tsconfig.${resolution.toLowerCase()}.json`;
|
|
778
|
+
await writeFile4(join5(consumer, config), JSON.stringify({
|
|
779
|
+
compilerOptions: {
|
|
780
|
+
strict: true,
|
|
781
|
+
noEmit: true,
|
|
782
|
+
skipLibCheck: false,
|
|
783
|
+
target: "ES2022",
|
|
784
|
+
module,
|
|
785
|
+
moduleResolution: resolution,
|
|
786
|
+
lib: ["ES2023", "DOM"],
|
|
787
|
+
types: (options.proof?.types ?? []).map((name) => name.replace(/^@types\//, "")),
|
|
788
|
+
...json.length > 0 ? { resolveJsonModule: true } : {}
|
|
789
|
+
},
|
|
790
|
+
files: sources
|
|
791
|
+
}));
|
|
792
|
+
ranOrRefuse(await runClientTool(input.step, compiler, [...leading, "-p", config], consumer), "typecheck", `consumer typecheck under ${resolution}`, { resolution });
|
|
793
|
+
}
|
|
794
|
+
return version.trim();
|
|
795
|
+
}
|
|
796
|
+
async function proveClientPackage(input) {
|
|
797
|
+
const files = await install(input);
|
|
798
|
+
const externals = await proveRanges(input);
|
|
799
|
+
const identity = await proveIdentity(input);
|
|
800
|
+
const typescript = await proveTypes(input);
|
|
801
|
+
return {
|
|
802
|
+
files,
|
|
803
|
+
exports: identity.exports,
|
|
804
|
+
sharedExports: identity.sharedExports,
|
|
805
|
+
proof: {
|
|
806
|
+
runtimes: identity.runtimes,
|
|
807
|
+
resolutions: RESOLUTIONS.map(({ resolution }) => resolution),
|
|
808
|
+
typescript,
|
|
809
|
+
externals,
|
|
810
|
+
exportedFiles: [...input.exportedFiles.keys()]
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// src/files/client-package.ts
|
|
816
|
+
var PACKAGE_NAME = /^(?:@[a-z0-9~-][a-z0-9._~-]*\/)?[a-z0-9~-][a-z0-9._~-]*$/;
|
|
817
|
+
function plan(options) {
|
|
818
|
+
if (!PACKAGE_NAME.test(options.name)) {
|
|
819
|
+
throw new TypeError(`Client package name ${JSON.stringify(options.name)} is not a package name`);
|
|
820
|
+
}
|
|
821
|
+
const tsconfig = resolve4(options.tsconfig);
|
|
822
|
+
const root = dirname5(tsconfig);
|
|
823
|
+
const entries = new Map;
|
|
824
|
+
for (const [subpath, source] of Object.entries(options.entries)) {
|
|
825
|
+
const entry = resolve4(source);
|
|
826
|
+
const inside = relative3(root, entry);
|
|
827
|
+
if (subpath !== "." && !/^\.\/[^/]/.test(subpath)) {
|
|
828
|
+
throw new TypeError(`Client package entry ${JSON.stringify(subpath)} is not "." or "./name"`);
|
|
829
|
+
}
|
|
830
|
+
if (inside.startsWith("..") || isAbsolute(inside) || !/\.tsx?$/.test(entry)) {
|
|
831
|
+
throw new TypeError(`Client package entry ${source} must be a .ts or .tsx module under ${root}, the tsconfig's directory`);
|
|
832
|
+
}
|
|
833
|
+
if ([...entries.values()].includes(entry)) {
|
|
834
|
+
throw new TypeError(`Client package entry ${source} is listed under two subpaths`);
|
|
835
|
+
}
|
|
836
|
+
entries.set(subpath, entry);
|
|
837
|
+
}
|
|
838
|
+
if (entries.size === 0)
|
|
839
|
+
throw new TypeError("Client package has no entries");
|
|
840
|
+
const peers = Object.keys(options.peerDependencies ?? {});
|
|
841
|
+
const dependencies = Object.keys(options.dependencies ?? {});
|
|
842
|
+
const both = peers.find((name) => dependencies.includes(name));
|
|
843
|
+
if (both !== undefined) {
|
|
844
|
+
throw new TypeError(`Client package lists "${both}" as both a peer and a dependency`);
|
|
845
|
+
}
|
|
846
|
+
const manifest = ClientPackageManifestSchema.parse(options.manifest ?? {});
|
|
847
|
+
const owned = Object.keys(manifest).find((field) => CLIENT_PACKAGE_OWNED_FIELDS.includes(field));
|
|
848
|
+
if (owned !== undefined) {
|
|
849
|
+
throw new ClientPackageError("manifest-owned-field", `Client package manifest sets "${owned}", which the build writes itself`, { field: owned });
|
|
850
|
+
}
|
|
851
|
+
const files = new Map;
|
|
852
|
+
for (const [target, source] of Object.entries(options.files ?? {})) {
|
|
853
|
+
const path = normalize(target).replaceAll("\\", "/");
|
|
854
|
+
if (isAbsolute(path) || path.startsWith("..") || path === "package.json" || /^dist(\/|$)/.test(path)) {
|
|
855
|
+
throw new TypeError(`Client package file ${JSON.stringify(target)} must be a path inside the package, outside dist/`);
|
|
856
|
+
}
|
|
857
|
+
files.set(path, resolve4(source));
|
|
858
|
+
}
|
|
170
859
|
return {
|
|
171
|
-
|
|
172
|
-
|
|
860
|
+
root,
|
|
861
|
+
tsconfig,
|
|
862
|
+
entries,
|
|
863
|
+
external: [...peers, ...dependencies],
|
|
864
|
+
manifest,
|
|
865
|
+
files,
|
|
866
|
+
exportedFiles: planExportedFiles(options, entries, files),
|
|
867
|
+
replacements: planReplacements(options),
|
|
868
|
+
tarball: join6(resolve4(options.outDir), `${options.name.replace(/^@/, "").replaceAll("/", "-")}-${options.version}.tgz`)
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
function planExportedFiles(options, entries, files) {
|
|
872
|
+
const exported = new Map;
|
|
873
|
+
for (const subpath of options.exportedFiles ?? []) {
|
|
874
|
+
const path = normalize(subpath.slice(2)).replaceAll("\\", "/");
|
|
875
|
+
if (!subpath.startsWith("./") || path !== "package.json" && !files.has(path)) {
|
|
876
|
+
throw new TypeError(`Client package exported file ${JSON.stringify(subpath)} is neither "./package.json" nor "./" and a path in files`);
|
|
877
|
+
}
|
|
878
|
+
if (entries.has(subpath) || exported.has(subpath)) {
|
|
879
|
+
throw new TypeError(`Client package subpath ${JSON.stringify(subpath)} is exported twice`);
|
|
880
|
+
}
|
|
881
|
+
exported.set(subpath, `./${path}`);
|
|
882
|
+
}
|
|
883
|
+
return exported;
|
|
884
|
+
}
|
|
885
|
+
function planReplacements(options) {
|
|
886
|
+
const replacements = new Map;
|
|
887
|
+
for (const [module, contents] of Object.entries(options.replaceModules ?? {})) {
|
|
888
|
+
const path = resolve4(module);
|
|
889
|
+
if (!existsSync3(path) || REPLACEMENT_LOADERS[extname(path)] === undefined) {
|
|
890
|
+
throw new TypeError(`Client package replaces ${module}, which is not an existing ${Object.keys(REPLACEMENT_LOADERS).join(", ")} file`);
|
|
891
|
+
}
|
|
892
|
+
replacements.set(path, contents);
|
|
893
|
+
}
|
|
894
|
+
return replacements;
|
|
895
|
+
}
|
|
896
|
+
async function refuseBundledExternals(graph, externals) {
|
|
897
|
+
for (const module of graph.modules.keys()) {
|
|
898
|
+
const real = await realpath3(module);
|
|
899
|
+
for (const [name, external] of externals) {
|
|
900
|
+
if (!real.startsWith(`${external.directory}/`))
|
|
901
|
+
continue;
|
|
902
|
+
throw new ClientPackageError("bundled-peer", `Client package bundles ${module}, which is code of "${name}"; import it by the package name`, { package: name, module });
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
async function stage(options, planned, graph, staged) {
|
|
907
|
+
const exported = {};
|
|
908
|
+
for (const [subpath, entry] of planned.entries) {
|
|
909
|
+
const output = graph.entryOutputs.get(entry);
|
|
910
|
+
const types = output?.replace(/\.js$/, ".d.ts");
|
|
911
|
+
if (output === undefined || types === undefined || !existsSync3(join6(staged, "dist", types))) {
|
|
912
|
+
throw new ClientPackageError("declarations", `Client package entry ${entry} has no built module with a declaration beside it`, { entry, subpath });
|
|
913
|
+
}
|
|
914
|
+
exported[subpath] = { types: `./dist/${types}`, import: `./dist/${output}` };
|
|
915
|
+
}
|
|
916
|
+
for (const [subpath, path] of planned.exportedFiles)
|
|
917
|
+
exported[subpath] = path;
|
|
918
|
+
for (const [target, source] of planned.files) {
|
|
919
|
+
await mkdir3(dirname5(join6(staged, target)), { recursive: true });
|
|
920
|
+
await copyFile2(source, join6(staged, target));
|
|
921
|
+
}
|
|
922
|
+
const present = (record) => record !== undefined && Object.keys(record).length > 0 ? record : undefined;
|
|
923
|
+
await writeFile5(join6(staged, "package.json"), `${JSON.stringify({
|
|
924
|
+
name: options.name,
|
|
925
|
+
version: options.version,
|
|
926
|
+
...planned.manifest,
|
|
927
|
+
type: "module",
|
|
928
|
+
exports: exported,
|
|
929
|
+
files: ["dist", ...planned.files.keys()],
|
|
930
|
+
peerDependencies: present(options.peerDependencies),
|
|
931
|
+
dependencies: present(options.dependencies)
|
|
932
|
+
}, null, 2)}
|
|
933
|
+
`);
|
|
934
|
+
}
|
|
935
|
+
async function buildClientPackage(options) {
|
|
936
|
+
const planned = plan(options);
|
|
937
|
+
const step = {
|
|
938
|
+
timeoutMs: options.timeoutMs ?? 120000,
|
|
939
|
+
signal: options.signal
|
|
173
940
|
};
|
|
941
|
+
const bun = options.executables?.bun ?? "bun";
|
|
942
|
+
const work = await mkdtemp2(join6(tmpdir2(), "stitchkit-client-package-"));
|
|
943
|
+
await rm3(planned.tarball, { force: true });
|
|
944
|
+
try {
|
|
945
|
+
const externals = new Map;
|
|
946
|
+
for (const name of planned.external) {
|
|
947
|
+
externals.set(name, await resolveExternalPackage(planned.root, name));
|
|
948
|
+
}
|
|
949
|
+
const tsc = options.executables?.tsc !== undefined ? [options.executables.tsc] : [
|
|
950
|
+
process.execPath,
|
|
951
|
+
join6((await resolveExternalPackage(planned.root, "typescript")).directory, "bin", "tsc")
|
|
952
|
+
];
|
|
953
|
+
const staged = join6(work, "package");
|
|
954
|
+
const graph = await bundleClientPackage({
|
|
955
|
+
step,
|
|
956
|
+
bun,
|
|
957
|
+
root: planned.root,
|
|
958
|
+
tsconfig: planned.tsconfig,
|
|
959
|
+
entries: [...planned.entries.values()],
|
|
960
|
+
external: planned.external,
|
|
961
|
+
runtime: options.runtime ?? "node",
|
|
962
|
+
replacements: planned.replacements,
|
|
963
|
+
work,
|
|
964
|
+
outdir: join6(staged, "dist")
|
|
965
|
+
});
|
|
966
|
+
refuseForbiddenModules(graph, options.forbiddenModules ?? []);
|
|
967
|
+
await refuseBundledExternals(graph, externals);
|
|
968
|
+
await emitClientDeclarations({
|
|
969
|
+
step,
|
|
970
|
+
tsc,
|
|
971
|
+
tsconfig: planned.tsconfig,
|
|
972
|
+
entries: [...planned.entries.values()],
|
|
973
|
+
outDir: join6(staged, "dist")
|
|
974
|
+
});
|
|
975
|
+
normalizeClientDeclarations(join6(staged, "dist"), {
|
|
976
|
+
packages: new Set(planned.external),
|
|
977
|
+
runtime: options.runtime ?? "node"
|
|
978
|
+
});
|
|
979
|
+
await stage(options, planned, graph, staged);
|
|
980
|
+
await mkdir3(dirname5(planned.tarball), { recursive: true });
|
|
981
|
+
const packed = await runClientTool(step, bun, ["pm", "pack", "--filename", planned.tarball, "--ignore-scripts", "--quiet"], staged);
|
|
982
|
+
if (!packed.ok) {
|
|
983
|
+
throw new ClientPackageError("install", `Client package pack failed (exit ${packed.exit}): ${packed.output}`, { output: packed.output });
|
|
984
|
+
}
|
|
985
|
+
const consumer = join6(work, "consumer");
|
|
986
|
+
await mkdir3(consumer);
|
|
987
|
+
const proven = await proveClientPackage({
|
|
988
|
+
options,
|
|
989
|
+
step,
|
|
990
|
+
tools: { bun, node: options.executables?.node ?? "node", tsc },
|
|
991
|
+
consumer,
|
|
992
|
+
staged,
|
|
993
|
+
tarball: planned.tarball,
|
|
994
|
+
externals,
|
|
995
|
+
root: planned.root,
|
|
996
|
+
exportedFiles: planned.exportedFiles
|
|
997
|
+
});
|
|
998
|
+
const archive = await readFile4(planned.tarball);
|
|
999
|
+
return {
|
|
1000
|
+
tarball: planned.tarball,
|
|
1001
|
+
sha256: createHash3("sha256").update(archive).digest("hex"),
|
|
1002
|
+
bytes: archive.byteLength,
|
|
1003
|
+
modules: [...graph.modules.keys()].sort(),
|
|
1004
|
+
...proven
|
|
1005
|
+
};
|
|
1006
|
+
} catch (error) {
|
|
1007
|
+
await rm3(planned.tarball, { force: true });
|
|
1008
|
+
throw error;
|
|
1009
|
+
} finally {
|
|
1010
|
+
await rm3(work, { recursive: true, force: true });
|
|
1011
|
+
}
|
|
174
1012
|
}
|
|
175
1013
|
// src/files/native-packaging-layout.ts
|
|
176
|
-
import { createHash as
|
|
177
|
-
import { z as
|
|
178
|
-
var RelativePathSchema =
|
|
179
|
-
var NativeLayoutSchema =
|
|
1014
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
1015
|
+
import { z as z4 } from "zod";
|
|
1016
|
+
var RelativePathSchema = z4.string().min(1).refine((value) => !value.startsWith("/") && !/^[a-z]:/i.test(value) && !value.includes("\\") && value.split("/").every((part) => part !== ".." && part !== "." && part.length > 0), "Expected a relative path without traversal");
|
|
1017
|
+
var NativeLayoutSchema = z4.strictObject({
|
|
180
1018
|
loader: RelativePathSchema,
|
|
181
|
-
assets:
|
|
1019
|
+
assets: z4.strictObject({ arm64: RelativePathSchema, x64: RelativePathSchema })
|
|
182
1020
|
});
|
|
183
|
-
var NativeAssetEntrySchema =
|
|
1021
|
+
var NativeAssetEntrySchema = z4.strictObject({
|
|
184
1022
|
path: RelativePathSchema,
|
|
185
|
-
size:
|
|
186
|
-
sha256:
|
|
1023
|
+
size: z4.int().nonnegative(),
|
|
1024
|
+
sha256: z4.string().regex(/^[a-f0-9]{64}$/)
|
|
187
1025
|
});
|
|
188
|
-
var NativeAssetManifestSchema =
|
|
189
|
-
formatVersion:
|
|
1026
|
+
var NativeAssetManifestSchema = z4.strictObject({
|
|
1027
|
+
formatVersion: z4.literal(2, {
|
|
190
1028
|
error: "Native asset manifest formatVersion must be 2 for this Stitchkit"
|
|
191
1029
|
}),
|
|
192
1030
|
loader: RelativePathSchema,
|
|
193
|
-
assets:
|
|
1031
|
+
assets: z4.strictObject({
|
|
194
1032
|
arm64: NativeAssetEntrySchema.optional(),
|
|
195
1033
|
x64: NativeAssetEntrySchema.optional()
|
|
196
1034
|
})
|
|
197
1035
|
});
|
|
198
1036
|
function nativeAssetDigest(bytes) {
|
|
199
|
-
return { size: bytes.byteLength, sha256:
|
|
1037
|
+
return { size: bytes.byteLength, sha256: createHash4("sha256").update(bytes).digest("hex") };
|
|
200
1038
|
}
|
|
201
1039
|
var LOADER_MARK = ["stitchkit", "native", "loader"].join("-");
|
|
202
1040
|
function nativeLoaderMarker(state) {
|
|
@@ -255,17 +1093,17 @@ function inspectNativeArtifact(bytes) {
|
|
|
255
1093
|
return "no-loader";
|
|
256
1094
|
}
|
|
257
1095
|
// src/files/native-packaging.ts
|
|
258
|
-
import { existsSync as
|
|
259
|
-
import { dirname as
|
|
1096
|
+
import { existsSync as existsSync5, readFileSync as readFileSync3 } from "node:fs";
|
|
1097
|
+
import { dirname as dirname6, relative as relative4, resolve as resolve5 } from "node:path";
|
|
260
1098
|
import { fileURLToPath } from "node:url";
|
|
261
|
-
import { z as
|
|
1099
|
+
import { z as z5 } from "zod";
|
|
262
1100
|
|
|
263
1101
|
// src/files/native-packaging-plugin.ts
|
|
264
|
-
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
265
|
-
import { basename as
|
|
266
|
-
var
|
|
1102
|
+
import { existsSync as existsSync4, readFileSync as readFileSync2, realpathSync as realpathSync2 } from "node:fs";
|
|
1103
|
+
import { basename as basename3, join as join7 } from "node:path";
|
|
1104
|
+
var realpath4 = (path) => {
|
|
267
1105
|
try {
|
|
268
|
-
return
|
|
1106
|
+
return realpathSync2(path);
|
|
269
1107
|
} catch {
|
|
270
1108
|
return path;
|
|
271
1109
|
}
|
|
@@ -275,11 +1113,11 @@ function loaderInstallation(path, loaderName) {
|
|
|
275
1113
|
if (!path.endsWith(suffix))
|
|
276
1114
|
return;
|
|
277
1115
|
const root = path.slice(0, -suffix.length);
|
|
278
|
-
const manifest =
|
|
279
|
-
if (!
|
|
1116
|
+
const manifest = join7(root, "package.json");
|
|
1117
|
+
if (!existsSync4(manifest))
|
|
280
1118
|
return;
|
|
281
1119
|
try {
|
|
282
|
-
const parsed = JSON.parse(
|
|
1120
|
+
const parsed = JSON.parse(readFileSync2(manifest, "utf8"));
|
|
283
1121
|
if (typeof parsed !== "object" || parsed === null)
|
|
284
1122
|
return;
|
|
285
1123
|
const name = Reflect.get(parsed, "name");
|
|
@@ -294,8 +1132,8 @@ function loaderInstallation(path, loaderName) {
|
|
|
294
1132
|
function nativePlugin(owner, specifiers, embedded, companionEntry) {
|
|
295
1133
|
const contents = nativeLoaderSource(specifiers, "static");
|
|
296
1134
|
const external = new Set(Object.values(specifiers));
|
|
297
|
-
const ownLoader =
|
|
298
|
-
const loaderFile =
|
|
1135
|
+
const ownLoader = realpath4(owner.loaderPath);
|
|
1136
|
+
const loaderFile = basename3(owner.loaderName);
|
|
299
1137
|
return {
|
|
300
1138
|
name: "stitchkit-native-packaging",
|
|
301
1139
|
setup(build) {
|
|
@@ -312,9 +1150,9 @@ function nativePlugin(owner, specifiers, embedded, companionEntry) {
|
|
|
312
1150
|
build.onLoad({ filter: /\.[cm]?js$/ }, (args) => {
|
|
313
1151
|
if (args.path === owner.loaderPath)
|
|
314
1152
|
return { contents, loader: "js" };
|
|
315
|
-
if (
|
|
1153
|
+
if (basename3(args.path) !== loaderFile)
|
|
316
1154
|
return;
|
|
317
|
-
if (
|
|
1155
|
+
if (realpath4(args.path) === ownLoader)
|
|
318
1156
|
return { contents, loader: "js" };
|
|
319
1157
|
const foreign = loaderInstallation(args.path, owner.loaderName);
|
|
320
1158
|
if (!foreign)
|
|
@@ -327,18 +1165,18 @@ function nativePlugin(owner, specifiers, embedded, companionEntry) {
|
|
|
327
1165
|
return bytes ? { contents: bytes, loader: "napi" } : undefined;
|
|
328
1166
|
});
|
|
329
1167
|
if (companionEntry !== undefined)
|
|
330
|
-
build.onResolve({ filter: /./ }, (args) => (args.importer === owner.loaderPath ||
|
|
1168
|
+
build.onResolve({ filter: /./ }, (args) => (args.importer === owner.loaderPath || realpath4(args.importer) === ownLoader) && external.has(args.path) ? { path: args.path, external: true } : undefined);
|
|
331
1169
|
}
|
|
332
1170
|
};
|
|
333
1171
|
}
|
|
334
1172
|
|
|
335
1173
|
// src/files/native-packaging.ts
|
|
336
|
-
var PackageManifestSchema =
|
|
337
|
-
name:
|
|
338
|
-
version:
|
|
1174
|
+
var PackageManifestSchema = z5.object({
|
|
1175
|
+
name: z5.literal("stitchkit"),
|
|
1176
|
+
version: z5.string().min(1)
|
|
339
1177
|
});
|
|
340
|
-
var ArchitectureSchema =
|
|
341
|
-
var PlatformSchema =
|
|
1178
|
+
var ArchitectureSchema = z5.enum(["arm64", "x64"]);
|
|
1179
|
+
var PlatformSchema = z5.enum(["darwin"]);
|
|
342
1180
|
var CommonOptions = {
|
|
343
1181
|
platform: PlatformSchema,
|
|
344
1182
|
entryPath: RelativePathSchema.refine((value) => !value.includes("[") && !value.includes("]"), "Expected a fixed entry path without Bun naming templates")
|
|
@@ -346,24 +1184,24 @@ var CommonOptions = {
|
|
|
346
1184
|
var ASSET_HASH_TOKEN = "[hash]";
|
|
347
1185
|
var ASSET_HASH_LENGTH = 16;
|
|
348
1186
|
var AssetPathSchema = RelativePathSchema.refine((value) => !/[[\]]/.test(value.replaceAll(ASSET_HASH_TOKEN, "")), "Expected an addon path whose only template is [hash]");
|
|
349
|
-
var SingleOptionsSchema =
|
|
1187
|
+
var SingleOptionsSchema = z5.object({
|
|
350
1188
|
...CommonOptions,
|
|
351
|
-
architecture:
|
|
352
|
-
delivery:
|
|
1189
|
+
architecture: z5.string().min(1),
|
|
1190
|
+
delivery: z5.literal("companion"),
|
|
353
1191
|
assetPath: AssetPathSchema
|
|
354
1192
|
});
|
|
355
|
-
var EmbeddedOptionsSchema =
|
|
1193
|
+
var EmbeddedOptionsSchema = z5.strictObject({
|
|
356
1194
|
platform: PlatformSchema,
|
|
357
|
-
architecture:
|
|
358
|
-
delivery:
|
|
1195
|
+
architecture: z5.string().min(1),
|
|
1196
|
+
delivery: z5.literal("embedded")
|
|
359
1197
|
});
|
|
360
|
-
var MultipleOptionsSchema =
|
|
1198
|
+
var MultipleOptionsSchema = z5.object({
|
|
361
1199
|
...CommonOptions,
|
|
362
|
-
architecture:
|
|
363
|
-
delivery:
|
|
364
|
-
assetPath:
|
|
1200
|
+
architecture: z5.array(z5.string().min(1)).refine((targets) => targets.length > 0),
|
|
1201
|
+
delivery: z5.literal("companion"),
|
|
1202
|
+
assetPath: z5.record(z5.string().min(1), AssetPathSchema)
|
|
365
1203
|
});
|
|
366
|
-
var CompanionOptionsSchema =
|
|
1204
|
+
var CompanionOptionsSchema = z5.union([SingleOptionsSchema, MultipleOptionsSchema]).check((ctx) => {
|
|
367
1205
|
const input = ctx.value;
|
|
368
1206
|
const targets = typeof input.architecture === "string" ? [input.architecture] : input.architecture;
|
|
369
1207
|
if (new Set(targets).size !== targets.length)
|
|
@@ -395,35 +1233,35 @@ var CompanionOptionsSchema = z3.union([SingleOptionsSchema, MultipleOptionsSchem
|
|
|
395
1233
|
}
|
|
396
1234
|
}
|
|
397
1235
|
});
|
|
398
|
-
var EmbeddedAssetSchema =
|
|
399
|
-
size:
|
|
400
|
-
sha256:
|
|
401
|
-
bytes:
|
|
1236
|
+
var EmbeddedAssetSchema = z5.object({
|
|
1237
|
+
size: z5.int().nonnegative(),
|
|
1238
|
+
sha256: z5.string().regex(/^[a-f0-9]{64}$/),
|
|
1239
|
+
bytes: z5.custom((value) => value instanceof Uint8Array)
|
|
402
1240
|
});
|
|
403
|
-
var AssetSchema = EmbeddedAssetSchema.extend({ outputPath:
|
|
1241
|
+
var AssetSchema = EmbeddedAssetSchema.extend({ outputPath: z5.string() });
|
|
404
1242
|
var TargetAssetSchema = AssetSchema.extend({ architecture: ArchitectureSchema });
|
|
405
|
-
var DigestSchema =
|
|
406
|
-
size:
|
|
407
|
-
sha256:
|
|
1243
|
+
var DigestSchema = z5.object({
|
|
1244
|
+
size: z5.int().nonnegative(),
|
|
1245
|
+
sha256: z5.string().regex(/^[a-f0-9]{64}$/)
|
|
408
1246
|
});
|
|
409
|
-
var RefusalSchema =
|
|
410
|
-
|
|
411
|
-
state:
|
|
1247
|
+
var RefusalSchema = z5.discriminatedUnion("state", [
|
|
1248
|
+
z5.object({
|
|
1249
|
+
state: z5.literal("unsupported"),
|
|
412
1250
|
platform: PlatformSchema,
|
|
413
|
-
architecture:
|
|
414
|
-
code:
|
|
1251
|
+
architecture: z5.string(),
|
|
1252
|
+
code: z5.literal("NATIVE_TARGET_UNSUPPORTED")
|
|
415
1253
|
}),
|
|
416
|
-
|
|
417
|
-
state:
|
|
1254
|
+
z5.object({
|
|
1255
|
+
state: z5.literal("missing"),
|
|
418
1256
|
platform: PlatformSchema,
|
|
419
1257
|
architecture: ArchitectureSchema,
|
|
420
|
-
code:
|
|
1258
|
+
code: z5.literal("NATIVE_ASSET_MISSING")
|
|
421
1259
|
}),
|
|
422
|
-
|
|
423
|
-
state:
|
|
1260
|
+
z5.object({
|
|
1261
|
+
state: z5.literal("mismatch"),
|
|
424
1262
|
platform: PlatformSchema,
|
|
425
1263
|
architecture: ArchitectureSchema,
|
|
426
|
-
code:
|
|
1264
|
+
code: z5.literal("NATIVE_ASSET_DIGEST_MISMATCH"),
|
|
427
1265
|
expected: DigestSchema,
|
|
428
1266
|
actual: DigestSchema
|
|
429
1267
|
})
|
|
@@ -451,11 +1289,11 @@ function resolveTargets(platform, declared) {
|
|
|
451
1289
|
return { targets };
|
|
452
1290
|
}
|
|
453
1291
|
function installedPackageRoot() {
|
|
454
|
-
let directory =
|
|
1292
|
+
let directory = dirname6(fileURLToPath(import.meta.url));
|
|
455
1293
|
for (let depth = 0;depth < 64; depth++) {
|
|
456
|
-
if (
|
|
1294
|
+
if (existsSync5(resolve5(directory, "native-assets.json")))
|
|
457
1295
|
return directory;
|
|
458
|
-
const parent =
|
|
1296
|
+
const parent = dirname6(directory);
|
|
459
1297
|
if (parent === directory)
|
|
460
1298
|
break;
|
|
461
1299
|
directory = parent;
|
|
@@ -468,10 +1306,10 @@ function readVerifiedAsset(root, published, platform, architecture) {
|
|
|
468
1306
|
};
|
|
469
1307
|
if (!published)
|
|
470
1308
|
return missing;
|
|
471
|
-
const sourcePath =
|
|
1309
|
+
const sourcePath = resolve5(root, published.path);
|
|
472
1310
|
let bytes;
|
|
473
1311
|
try {
|
|
474
|
-
bytes =
|
|
1312
|
+
bytes = readFileSync3(sourcePath);
|
|
475
1313
|
} catch (cause) {
|
|
476
1314
|
if (errnoOf(cause) === "ENOENT")
|
|
477
1315
|
return missing;
|
|
@@ -493,13 +1331,13 @@ function readVerifiedAsset(root, published, platform, architecture) {
|
|
|
493
1331
|
}
|
|
494
1332
|
function installedPackage() {
|
|
495
1333
|
const root = installedPackageRoot();
|
|
496
|
-
const published = NativeAssetManifestSchema.parse(JSON.parse(
|
|
497
|
-
const manifest = PackageManifestSchema.parse(JSON.parse(
|
|
1334
|
+
const published = NativeAssetManifestSchema.parse(JSON.parse(readFileSync3(resolve5(root, "native-assets.json"), "utf8")));
|
|
1335
|
+
const manifest = PackageManifestSchema.parse(JSON.parse(readFileSync3(resolve5(root, "package.json"), "utf8")));
|
|
498
1336
|
return {
|
|
499
1337
|
root,
|
|
500
1338
|
published,
|
|
501
1339
|
version: manifest.version,
|
|
502
|
-
loaderPath:
|
|
1340
|
+
loaderPath: resolve5(root, published.loader),
|
|
503
1341
|
loaderName: published.loader
|
|
504
1342
|
};
|
|
505
1343
|
}
|
|
@@ -542,7 +1380,7 @@ function packageCompanion(input) {
|
|
|
542
1380
|
const outputPath = template.replaceAll(ASSET_HASH_TOKEN, sha256.slice(0, ASSET_HASH_LENGTH));
|
|
543
1381
|
if (assets.some((asset) => asset.outputPath === outputPath))
|
|
544
1382
|
throw new Error("Addons must have distinct output paths");
|
|
545
|
-
const specifier =
|
|
1383
|
+
const specifier = relative4(dirname6(input.entryPath), outputPath).split("\\").join("/");
|
|
546
1384
|
specifiers[architecture] = specifier.startsWith(".") ? specifier : `./${specifier}`;
|
|
547
1385
|
const asset = { outputPath, size, sha256, bytes };
|
|
548
1386
|
assets.push(typeof input.architecture === "string" ? asset : { ...asset, architecture });
|
|
@@ -560,8 +1398,10 @@ function createNativePackaging(options) {
|
|
|
560
1398
|
return options.delivery === "embedded" ? embedNative(EmbeddedOptionsSchema.parse(options)) : packageCompanion(CompanionOptionsSchema.parse(options));
|
|
561
1399
|
}
|
|
562
1400
|
export {
|
|
1401
|
+
ClientPackageError,
|
|
563
1402
|
ForbiddenModuleError,
|
|
564
1403
|
buildClientArtifact,
|
|
1404
|
+
buildClientPackage,
|
|
565
1405
|
createNativePackaging,
|
|
566
1406
|
inspectNativeArtifact
|
|
567
1407
|
};
|