Code Monkey home page Code Monkey logo

yarn-prebuilds's Introduction

@yarnpkg/plugin-prebuilds

For Yarn v2.

To install, import from the repository.

yarn plugin import https://raw.githubusercontent.com/electricui/yarn-prebuilds/master/bundles/%40yarnpkg/plugin-prebuilds.js

The bindings package creates a runtime error in order to reflect its caller's filepath, which is used to search the filesystem for the correct .node native binding.

This plugin intercepts packages with dependencies to bindings and automatically grabs the prebuild for that version. If electron is in your dependencies list, the runtime is set to electron.

It rewrites the bindings dependency for each package to statically refer to the .node binding, removing all runtime searching.

Node-abi is bundled into this plugin, so it will need to be updated each time Electron releases a new ABI version.

Once the dependency is referred to statically, a Webpack plugin or Rollup plugin can be used to consume and load the .node file like any other asset.

For example, we use webpack-dev-server and have a loader that provides an absolute path during development. During bundling, we copy the .node file to a relative path and package it with the bundle.

All Configuration

Configuration can be set in your .yarnrc.yml file.

prebuildScopes:
  '@serialport':
    prebuildTagPrefix: '@serialport/bindings@'
    prebuildHostMirrorUrl: 'https://custom-prebuild-mirror.com/prebuilds'
    prebuildHostMirrorTemplate: '{mirror_url}/{scopeWithAtAndSlash}{name}-v{version}-{runtime}-v{abi}-{platform}{libc}-{arch}.tar.gz'
prebuildHostMirrorUrl: 'https://other-custom-prebuild-mirror.com/prebuilds'
prebuildHostMirrorTemplate: '{mirror_url}/{version}/{scopeWithAtAndSlash}{name}-v{version}-{runtime}-v{abi}-{platform}{libc}-{arch}.tar.gz'

Custom Mirrors

The prebuildHostMirrorUrl config can be used to set a custom prebuild mirror URL.

prebuildHostMirrorUrl: 'https://custom-prebuild-mirror.com/prebuilds'

The prebuildHostMirrorTemplate config key can be used to set a custom template to fetch the prebuild tar.

The template variables injected are as follows:

{mirror_url}
{name}
{version}
{abi}
{runtime}
{platform}
{arch}
{libc}
{tag_prefix}
{scope}
{scopeWithAt}
{scopeWithAtAndSlash}
{scopeWithSlash}

For example

prebuildHostMirrorTemplate: '{mirror_url}/{scopeWithAtAndSlash}{name}-v{version}-{runtime}-v{abi}-{platform}{libc}-{arch}.tar.gz'

The default template is:

{mirror_url}/{tag_prefix}{version}/{name}-v{version}-{runtime}-v{abi}-{platform}{libc}-{arch}.tar.gz

Scoped configuration

Configuration can be done per scope with the prebuildScopes config key.

prebuildScopes:
  '@serialport':
    prebuildTagPrefix: '@serialport/bindings@'

yarn-prebuilds's People

Contributors

mike-dax avatar

Stargazers

Emily Marigold Klassen avatar Jonathan Cantrell avatar Steven Vancoillie avatar Alec Mev avatar  avatar

Watchers

James Cloos avatar  avatar

yarn-prebuilds's Issues

Don't download binaries for platform-specific packages

Thanks for making this!

I'm on Linux and yarn-prebuilds attempts to download a binary for fsevents, a macOS-only package. The most obvious workaround would be to check the os field in bindings owner's package.json. I've tried to patch the reduceDependency hook, but there's no quick fix. scriptUtils.initializePackageEnvironment looked promising, as a way to get my hands on the manifest, but it isn't exported.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.