MatrixAI / js-db

Key-Value DB for TypeScript and JavaScript Applications
https://polykey.com
Apache License 2.0
5 stars 0 forks source link

WIP: Introduce optional dependencies to streamline platform-specific installation #63

Open CMCDragonkai opened 1 year ago

CMCDragonkai commented 1 year ago

Description

Our js-quic now published optional packages

  "optionalDependencies": {
    "@matrixai/quic-darwin-arm64": "0.0.7-alpha.0",
    "@matrixai/quic-darwin-x64": "0.0.7-alpha.0",
    "@matrixai/quic-linux-x64": "0.0.7-alpha.0",
    "@matrixai/quic-win32-x64": "0.0.7-alpha.0"
  },

I want to apply this to js-db too, so we can do streamline the installation and also be able to self-publish at least just the Linux one.

  "optionalDependencies": {
    "@matrixai/db-darwin-arm64": "5.1.0",
    "@matrixai/db-darwin-x64": "5.1.0",
    "@matrixai/db-linux-x64": "5.1.0",
    "@matrixai/db-win32-x64": "5.1.0"
  },

This involves replacing how we do our prebuild.js in particular and bringing in the scripts/prebuild.js, scripts/prepublishOnly.js and scripts/version.js.

We may also need to fix up our CI/CD scripts too.

Without the GitLab CI/CD we can only do the linux build and windows builds. So we can delay having the macos ones.

Note that we rely on node-gyp-build package for both detection and auto-building the local dependency when installed. We don't have node-gyp-build in js-quic, thus there's no automatic compilation upon installation. Instead if none of the native dependencies can be found, it's necessary for the user to compile their own (which is a bit of a pain)... since compilation requires running a certain script, specifically npm run prebuild. However that's not really possible while we are installing js-quic as a dependency. We could do something similar with our own install script, but such a script/command has to exist in the packaged distribution and we actually ignore all /scripts in our .npmignore.

At the end of the day, I'm not even sure if it makes sense to enable automatic compilation. Really if it is not available, they have to source it from somewhere and place it in the right location. Specifically the custom loader will look for it in just the local prebuild/ directory. So figure out a compilation routine and then distribute it during npm install. The problem with relying on npm install to compile the native binary is that there's no guarantee that all the tools are available to do this for the end user. So therefore one should think of npm install as the final distribution here, for power users, they should be using the gitlab repository, possibly directly refer to it as a dependency, or submit a build for this opensource repo.

Fixes #43 Fixes #44

Tasks

Final checklist

ghost commented 1 year ago
👇 Click on the image for a new way to code review #### [![Review these changes using an interactive CodeSee Map](https://s3.us-east-2.amazonaws.com/maps.codesee.io/images/github/MatrixAI/js-db/63/deb537c5/d0150235c2c09dc976890a60f59864af0a71021c.svg)](https://app.codesee.io/r/reviews?pr=63&src=https%3A%2F%2Fgithub.com%2FMatrixAI%2Fjs-db) #### Legend CodeSee Map legend
CMCDragonkai commented 1 year ago

Ok turns out it's a little bit more complicated than just copying over the prebuild.js from js-quic. The reason is that the binding.gyp indicates that we end up creating a fat executable on MacOS, that is both x86_64 and arm64. In js-quic, we separated these 2 out and now build 1 specific binary.

I wonder if it is possible to get binding.gyp to specify to outputs instead of just 1 output?

CMCDragonkai commented 1 year ago

I might put this on the backburner for now as it isn't entirely necessary and just release the latest version.

CMCDragonkai commented 1 year ago

New version to be released with the new macos build too.