-
Notifications
You must be signed in to change notification settings - Fork 581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selective binary by OS and Node version 🤔 #1112
Comments
It downloads all binaries because npm client has no idea of the platform, no support to download only a subset of binaries like literally all other package managers on earth do. So it's a tradeoff between being easily downloaded with npm client and saving disk space. |
So the issue is both npm and yarn. |
|
The platform can be communicated to |
Very interesting! Do you think it will work with the same user experience?
and
? |
@uNetworkingAB Yes, it should work with the same user user experience. |
It will still download the various abi versions, but that's still an improvement! I can make a quick sample setup for you to see
|
In my projects I'm just using this loader and a postinstall to only download a single binary, so that's an option too: import fs from 'node:fs'
import path from 'node:path'
import https from 'node:https'
import { pipeline } from 'node:stream/promises'
import { createRequire } from 'node:module'
const binaryName = `uws_${ process.platform }_${ process.arch }_${ process.versions.modules }.node`
const binaryPath = path.join(import.meta.dirname, binaryName)
fs.existsSync(binaryPath) || await download()
let uws
try {
uws = createRequire(import.meta.url)(binaryPath)
} catch(e) {
await download()
uws = createRequire(import.meta.url)(binaryPath)
}
export default uws
async function download(url = 'https://raw.githubusercontent.com/uNetworking/uWebSockets.js/v20.47.0/' + binaryName, retries = 0) {
return new Promise((resolve, reject) => {
https.get(url, async res => {
if (retries > 10)
return reject(new Error('Could not download uWebSockets binary - too many redirects - latest: ' + res.headers.location))
if (res.statusCode === 302)
return (res.destroy(), resolve(download(res.headers.location, retries + 1)))
if (res.statusCode !== 200)
return reject(new Error('Could not download uWebSockets binary - error code: ' + res.statusCode + ' - ' + url))
pipeline(res, fs.createWriteStream(binaryPath)).then(resolve, reject)
})
.on('error', reject)
.end()
})
} If the postinstall doesn't run, it'll download it on first run after instead. |
@porsager @uNetworkingAB I have put together a demo repo: You can check how it works via: You can then go into Note, that I have used 4 branches, 1 for user-facing package |
There is a way to select also by Node version? |
There is |
Can we use the release tag? Eg:
|
You can have multiple nodejs versions on the same platform so installing all 3 is preferrable IMO. Thanks for making the demo, it works for me on Linux but I had issues getting it to work on arm64 macOS. I made a fork but could not get it to work for some reason. Anyways - If someone wants to make a full demo, using the actual binaries in latest release, and making it so that require("uWebSockets.js") works on macOS arm64, x64, Windows x64, Linux x64, arm64 - please do so and provide a branch I can test against. If that branch works, I will definitely move to this approach, as it would be a seamless optimization. My point re. full demo is that I do not have time to play with this and this is a very low prio issue. So I can take a look at the finished full demo if someone makes it. |
Off topic: Binary without SSL and H3 (pure http 1.1) would also be nice. |
That's way too specific. If you value disk space, use ws. |
Ok - I've made 2 PRs ready master branch changes and binary branch changes, and a sample release on my fork you can try out. npm i porsager/uWebSockets.js#v20.50.0 I've tried to keep it as close to the current setup as possible.
I've left the current uws-release.mp4If anything fails you can simply delete the tags, and run again. Only downside is all the friggin tags, but I think that's definitely worth the tradeoff. The only maintenance should be in adding new ABI versions to the version map in release.yml when a new node version should be supported. |
After
uWebSockets.js
is installed, all OS and Node versions are built.Reproduction
yarn init -y
yarn set version berry
yarn add uWebSockets.js@github:uNetworking/uWebSockets.js#v20.49.0
/.yarn/unplugged/uWebSockets.js-https-<HASH>/node_modules/uWebSockets.js
.node
files are 24 (uws_darwin_*, uws_linux_*, uws_win32_*)Expected
In directory
/.yarn/unplugged/uWebSockets.js-https-<HASH>/node_modules/uWebSockets.js
there is only 1 file filtered by OS and Node versionThe text was updated successfully, but these errors were encountered: