Skip to content

Prefer using a platform package over postinstalls #1217

Open
@arcanis

Description

@arcanis

Is your feature request related to a problem? Please describe.
The Supabase package currently runs a postinstall script to download the binary for the current platform. This strategy should be avoided: postinstall scripts are dangerous, but also very inconvenient (they are unstable, slow, don't work well with caches, disable optimizations in package managers).

  • Not all of npm's settings can be forwarded due to npm bugs such as [BUG] Config environment variable forwarding breaks with false config values npm/cli#2284, and npm has said these bugs will never be fixed.
  • Some people have configured their network environments such that downloading from https://registry.npmjs.org/ will hang instead of either succeeding or failing.
  • The installed package was broken if you used npm --ignore-scripts because then the post-install script wasn't run. Some people enable this option so that malicious packages must be run first before being able to do malicious stuff.

For more details, see this thread, which is fairly detailed: evanw/esbuild#1621.

Describe the solution you'd like
Instead, you should use the same strategy as tools like esbuild or swc. It's been documented in detail in the thread I mentioned, but to give you an idea, you'd have to do the following:

  • Create a set of @supabase/cli-<platform> package, each one with the relevant bin for the given platform
  • Each of those packages should set the os, cpu, and possibly libc fields from the package.json accordingly
  • In the supabase package, remove the postinstall script and instead list the platform packages in the optionalDependencies field.
  • Finally, the bin field of supabase should point to a JS script that would check which platform package is installed, and execute its accompanying native bin using child_process.spawn.

As a result, package managers will only download the single package

Additional context
I wonder if perhaps Yarn could implement something to make publishing such packages easier. You don't use Yarn though, so I don't know if that would help you.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions