Skip to content

Suggestion: separate packages for prebuilt binaries. #6133

Closed
@cometkim

Description

@cometkim

The rescript package provides prebuilt binaries for major platforms.

Not relying on the postinstall hook is good, but it significantly increases package installation time. An additional 20-30MB of bandwidth per platform is required for it.

Installing binaries for not matched platforms is obviously unnecessary work, so users can skip close to 100MB of downloading by omitting 4 out of 5 supported platforms.

Thankfully Yarn & pnpm support feature for this (I'm not sure npm also does). They can skip installation if the os and cpu entries specified in the package.json do not match (and this behavior can be customized)

Packages using prebuilt bins like esbuild provide it separately in the form of @esbuild/{os}-{cpu} for this purpose.

So @esbuild/linux-x64's package.json:

{
  "name": "@esbuild/linux-x64",
  "version": "0.17.16",
  "description": "The Linux 64-bit binary for esbuild, a JavaScript bundler.",
  "repository": "https://github.com/evanw/esbuild",
  "license": "MIT",
  "preferUnplugged": true,
  "engines": {
    "node": ">=12"
  },
  "os": [
    "linux"
  ],
  "cpu": [
    "x64"
  ]
}

And esbuild's:

  "optionalDependencies": {
    "@esbuild/android-arm": "0.17.16",
    "@esbuild/android-arm64": "0.17.16",
    "@esbuild/android-x64": "0.17.16",
    "@esbuild/darwin-arm64": "0.17.16",
    "@esbuild/darwin-x64": "0.17.16",
    "@esbuild/freebsd-arm64": "0.17.16",
    "@esbuild/freebsd-x64": "0.17.16",
    "@esbuild/linux-arm": "0.17.16",
    "@esbuild/linux-arm64": "0.17.16",
    "@esbuild/linux-ia32": "0.17.16",
    "@esbuild/linux-loong64": "0.17.16",
    "@esbuild/linux-mips64el": "0.17.16",
    "@esbuild/linux-ppc64": "0.17.16",
    "@esbuild/linux-riscv64": "0.17.16",
    "@esbuild/linux-s390x": "0.17.16",
    "@esbuild/linux-x64": "0.17.16",
    "@esbuild/netbsd-x64": "0.17.16",
    "@esbuild/openbsd-x64": "0.17.16",
    "@esbuild/sunos-x64": "0.17.16",
    "@esbuild/win32-arm64": "0.17.16",
    "@esbuild/win32-ia32": "0.17.16",
    "@esbuild/win32-x64": "0.17.16"
  },

It is specified as optionalDependencies because it can be omitted depending on the environment.

As the result, when I run yarn add esbuild on my env, I can see yarn only install @esbuild/linux-x64 additionally

➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 3s 250ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ esbuild@npm:0.17.16 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ @esbuild/linux-x64@npm:0.17.16 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed in 2s 577ms

The downside of this approach is that it makes the release workflow more complex.

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleOld issues that went stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions