Skip to content

How Releases are built

A Release is bundled into one small module that shares a single copy of Effect with the instance, and is identified by the digest of its bytes.

When you run scwrap deploy, the instance bundles each Release with esbuild into an artifact (Builds): the code the instance installs, plus its digest. This page explains what goes into an artifact and why.

You rarely need this to write a Scraper. You need it when a build fails with a message about Effect, or when you wonder why a Release is only a few kilobytes.

One shared copy of Effect ​

An instance's Worker holds many Releases at once. If every Release bundled its own Effect, the Worker would carry many copies, and worse, they would not work together. Effect finds services by identity, and a service from one copy is invisible to another.

So the instance has exactly one copy, in a module called scwrap-sdk.mjs, and every Worker release imports from it.

Imported by your codeIn a Worker release it becomes
effect, effect/ai, effect/crypto, effect/encoding, effect/http, effect/http-api, effect/observability, effect/persistence, effect/rpcAn import from scwrap-sdk.mjs
A module of those, such as effect/Effect, effect/http/HttpClient, effect/ai/DecisionModel or effect/persistence/KeyValueStoreAn import from scwrap-sdk.mjs
@scwrap/domainAn import from scwrap-sdk.mjs
cloudflare:* and node:*Left as imports, which the release Worker provides at runtime (it runs with nodejs_compat)
Your Scraper package and its other dependencies, such as @scwrap/browser, @scwrap/platform-apify, @scwrap/captcha-templates with jpeg-js, or @scwrap/ai-cloudflare with @effect/ai-cloudflareBundled into the Release

This is why the quotes Worker release from the guide is about 2 KB: it contains the schemas and the handler, and nothing of Effect.

The bundler resolves packages with the workerd, worker and browser export conditions, so a dependency with a Worker build gets that build.

Supported Effect imports ​

scwrap-sdk.mjs shares all of @scwrap/domain, effect, effect/ai, effect/encoding, effect/http, effect/http-api, effect/observability, effect/persistence, Digest and SecureRandom from effect/crypto, and every module of effect/rpc except Utils, whose name effect already exports. A deep import of one of those modules, such as effect/Effect or effect/persistence/RateLimiter, links against the same shared copy.

A Release runs with SecureRandom and Digest already provided.

Every Capability provider in the SDKs builds as a Worker release on that set: browserRun, browserUse, apifyProxy, AiGateway with CloudflareDecisionModel, both from @scwrap/ai-cloudflare, and @scwrap/captcha-templates with TextCaptchaSolver.fromDecisionModel and firstConfident. probes.test.ts builds one Release for each, and the fresh-instance check runs them on a new instance.

Other Effect subpaths, such as effect/cli, effect/sql, effect/cluster, effect/workflow or effect/process, are not shared. Most need a process, a socket or a database driver that a Worker release does not have.

Unsupported Effect imports fail the build ​

A Worker release that imports an Effect subpath or name scwrap-sdk.mjs does not share cannot use the shared copy. The bundler does not quietly embed a second copy. It fails, names the import and says what to do:

text
Unsupported shared SDK import: effect/cli. A Worker release links Effect from the instance's scwrap-sdk.mjs and cannot bundle a second copy. Import from @scwrap/domain, effect, effect/ai, effect/crypto, effect/encoding, effect/http, effect/http-api, effect/observability, effect/persistence, effect/rpc instead, or share it: add it to src/shared.ts and src/sdk-contract.json in @scwrap/deploy and upgrade the instance (How Releases are built, in the Scwrap docs).

A second check catches Effect arriving another way, for example through a dependency that brings its own copy. It names the file and the fix:

text
Release embeds Effect instead of the shared SDK module: <path>/node_modules/effect/dist/Effect.js. A dependency imports its own copy of effect by path. Make it import effect by package name, with effect 4.2.0 as a peer dependency, so the build links it to scwrap-sdk.mjs.

Sharing another module is a change to the instance platform, not to your Scraper: add it to shared.ts and its names to sdk-contract.json, publish @scwrap/deploy and upgrade the instance, as the next section describes.

The shared module is a versioned contract ​

An installed Release imports its names from the platform's scwrap-sdk.mjs when its sandbox loads, so the names it exports are a contract between the platform and every Release installed on it. A platform whose scwrap-sdk.mjs lacks a name an installed Release imports cannot load that Release, and the instance answers every request to run it with 503 release_unavailable.

sdk-contract.json in @scwrap/deploy lists every exported name. A test builds scwrap-sdk.mjs and fails when its exports differ from that list, so every change to them is an explicit edit of the contract:

FieldHolds
exportsEvery name scwrap-sdk.mjs exports, deprecated ones included.
deprecatedNames still exported that a later version removes, each with the @scwrap/deploy version that deprecated it.
removedNames no longer exported, each with the version that deprecated it and the version that removed it.

A name leaves in two versions:

  1. Deprecate it. Add it to deprecated with the package's current version and keep exporting it. Publish that version. A build warns about every Release that imports it, and scwrap deploy prints the warning.
  2. Remove it in a later version: drop it from exports and deprecated and add it to removed. The test refuses a removal whose deprecating version is not older than its removing version.

Adding a name only adds it to exports. Effect's own exports are part of the contract too, so an Effect upgrade that drops a name follows the same two steps.

The instance enforces the contract as well: it refuses any deploy that would install a Release next to a scwrap-sdk.mjs that lacks one of its imports, and names the Release and the names (Compatibility check). CI upgrades the platform before it deploys Releases, so a platform that drops a name an installed Release imports stops there: deploy the rebuilt Release first, or deprecate the name for one version.

What an artifact contains ​

A Worker release is one ES module that exports three things: the definition, the stream function that runs a Run, and the revision.

Build tools, the upload client and credentials never enter an artifact.

Digests ​

An artifact's digest is the SHA-256 of its module's exact bytes.

The digest is the Release's real identity:

  • The same source built twice gives the same digest, and scwrap deploy --changed skips it.
  • Any change to the Scraper's code, or to a dependency that is bundled in, gives a new digest.
  • Every result record carries the digest of the Release that produced it.

revision is the label people read. The digest is what --changed compares.

Versions an instance accepts ​

Every artifact records the SDK version and the Effect version it was built with. The instance accepts an artifact only when its Effect version matches its own, so a Release built against another Effect version is refused instead of failing at run time.

The SDK version is the deploy protocol. The instance accepts 0.5.0 and 0.4.0, the current version and the one before it, so a repository that has not upgraded its SDKs yet keeps deploying Worker releases. It refuses an artifact a scwrap CLI before 0.4.0 built. Every Worker release it accepts runs in its own sandbox.

Both are constants in @scwrap/deploy/protocol: sdkVersion and effectVersion.

Trying a build without deploying ​

createDeployer(...).prepare(release) builds an artifact and uploads nothing. It returns the artifact, the list of files that went into it, and the deprecated scwrap-sdk.mjs names it imports. See Deploying from code.

Source ​