Use compression for Node.js binaries
This commit is contained in:
parent
c71a9169a7
commit
871298dae5
|
@ -59,6 +59,7 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
npm install
|
npm install
|
||||||
npm run build-binary
|
npm run build-binary
|
||||||
|
node compress.js
|
||||||
- name: Install B2 CLI (macOS, Linux)
|
- name: Install B2 CLI (macOS, Linux)
|
||||||
if: runner.os != 'Windows'
|
if: runner.os != 'Windows'
|
||||||
run: |
|
run: |
|
||||||
|
@ -73,7 +74,7 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
binary_name="$(node -e 'console.log([process.platform, process.arch, process.versions.modules].join("__"))')"
|
binary_name="$(node -e 'console.log([process.platform, process.arch, process.versions.modules].join("__"))')"
|
||||||
b2 authorize-account ${{ secrets.CICD_CLI_B2_KEY_ID }} ${{ secrets.CICD_CLI_B2_APPLICATION_KEY }}
|
b2 authorize-account ${{ secrets.CICD_CLI_B2_KEY_ID }} ${{ secrets.CICD_CLI_B2_APPLICATION_KEY }}
|
||||||
b2 upload-file ${{ secrets.CICD_CLI_B2_BUCKET_NAME }} ./nodejs/dist/native.node "minify-html/bin/nodejs/${{ steps.version.outputs.VERSION }}/$binary_name.node"
|
b2 upload-file ${{ secrets.CICD_CLI_B2_BUCKET_NAME }} ./nodejs/dist/native.node.gz "minify-html/bin/nodejs/${{ steps.version.outputs.VERSION }}/$binary_name.node.gz"
|
||||||
package:
|
package:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build
|
needs: build
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
const {readFileSync, writeFileSync} = require('fs');
|
||||||
|
const {join} = require('path');
|
||||||
|
const {gzipSync} = require('zlib');
|
||||||
|
|
||||||
|
const src = readFileSync(join(__dirname, 'dist', 'native.node'));
|
||||||
|
const out = gzipSync(src);
|
||||||
|
writeFileSync(join(__dirname, 'dist', 'native.node.gz'), out);
|
|
@ -1,6 +1,7 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const zlib = require('zlib');
|
||||||
const pkg = require('./package.json');
|
const pkg = require('./package.json');
|
||||||
|
|
||||||
const MAX_DOWNLOAD_ATTEMPTS = 4;
|
const MAX_DOWNLOAD_ATTEMPTS = 4;
|
||||||
|
@ -33,7 +34,7 @@ const downloadNativeBinary = async () => {
|
||||||
for (let attempt = 0; ; attempt++) {
|
for (let attempt = 0; ; attempt++) {
|
||||||
let binary;
|
let binary;
|
||||||
try {
|
try {
|
||||||
binary = await fetch(`https://wilsonl.in/minify-html/bin/nodejs/${pkg.version}/${binaryName}.node`);
|
binary = await fetch(`https://wilsonl.in/minify-html/bin/nodejs/${pkg.version}/${binaryName}.node.gz`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof StatusError && attempt < MAX_DOWNLOAD_ATTEMPTS) {
|
if (e instanceof StatusError && attempt < MAX_DOWNLOAD_ATTEMPTS) {
|
||||||
await wait(Math.random() * 2500 + 500);
|
await wait(Math.random() * 2500 + 500);
|
||||||
|
@ -42,7 +43,7 @@ const downloadNativeBinary = async () => {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(binaryPath, binary);
|
fs.writeFileSync(binaryPath, zlib.gunzipSync(binary));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue