From ce16a6dd3d21e456fcc65564cbe1ae7cb61e749d Mon Sep 17 00:00:00 2001 From: Amir Valizadeh Date: Tue, 29 Apr 2025 16:18:37 -0700 Subject: [PATCH] added rest of patches --- js2bin.js | 4 +++- package.json | 2 +- src/NodeBuilder.js | 37 ++++++++++++++++++------------------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/js2bin.js b/js2bin.js index e0d7174..3db443b 100755 --- a/js2bin.js +++ b/js2bin.js @@ -23,6 +23,8 @@ command-args: take the form of --name=value e.g. --dir=/tmp/js2bin --cache (opt) Cache any pre-built binaries used, to avoid redownload --arch: (opt) Architecture to build for + --download-url: (opt) Custom URL to download pre-built binaries from + e.g. --download-url=https://example.com/binaries/ --ci: build NodeJS with preallocated space for embedding applications --node: NodeJS version to build from source, can specify more than one. @@ -99,7 +101,7 @@ if (args.build) { const arch = args.arch || 'x64'; log(`building for version=${version}, plat=${plat} app=${app}} arch=${arch}`); const outName = args.name ? `${args.name}-${plat}-${arch}` : undefined; - return builder.buildFromCached(plat, arch, outName, args.cache, args.size); + return builder.buildFromCached(plat, arch, outName, args.cache, args.size, args['download-url']); }); }); }); diff --git a/package.json b/package.json index 1dcc1e6..8b57346 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js2bin", - "version": "1.0.9", + "version": "1.0.10", "description": "Native binary for your NodeJS apps", "main": "index.js", "scripts": { diff --git a/src/NodeBuilder.js b/src/NodeBuilder.js index 74cad54..1c740bc 100644 --- a/src/NodeBuilder.js +++ b/src/NodeBuilder.js @@ -1,4 +1,3 @@ - const { log, download, upload, fetch, mkdirp, rmrf, copyFileAsync, runCommand, renameAsync, patchFile } = require('./util'); const { gzipSync, createGunzip } = require('zlib'); const { join, dirname, basename, parse, resolve } = require('path'); @@ -105,7 +104,7 @@ class NodeJsBuilder { .then(() => this.version.split('.')[0] >= 15 ? this.applyPatches() : Promise.resolve()) } - downloadCachedBuild(platform, arch, placeHolderSizeMB) { + downloadCachedBuild(platform, arch, customDownloadUrl, placeHolderSizeMB) { placeHolderSizeMB = placeHolderSizeMB || this.placeHolderSizeMB; const name = buildName(platform, arch, placeHolderSizeMB, this.version); const filename = join(this.cacheDir, name); @@ -113,7 +112,7 @@ class NodeJsBuilder { log(`build name=${name} already downloaded, using it`); return Promise.resolve(filename); } - const baseUrl = `https://github.com/criblio/js2bin/releases/download/v${pkg.version}/`; + const baseUrl = customDownloadUrl || `https://github.com/criblio/js2bin/releases/download/v${pkg.version}/`; const url = `${baseUrl}${name}`; return download(url, filename); } @@ -238,26 +237,26 @@ class NodeJsBuilder { buildInContainer(ptrCompression) { const containerTag = `cribl/js2bin-builder:${this.builderImageVersion}`; return runCommand( - 'docker', ['run', - '-v', `${process.cwd()}:/js2bin/`, - '-t', containerTag, - '/bin/bash', '-c', + 'docker', ['run', + '-v', `${process.cwd()}:/js2bin/`, + '-t', containerTag, + '/bin/bash', '-c', `source /opt/rh/devtoolset-10/enable && cd /js2bin && npm install && ./js2bin.js --ci --node=${this.version} --size=${this.placeHolderSizeMB}MB ${ptrCompression ? '--pointer-compress=true' : ''}` - ] - ); + ] + ); } buildInContainerNonX64(arch, ptrCompression) { const containerTag = `cribl/js2bin-builder:${this.builderImageVersion}-nonx64`; return runCommand( - 'docker', ['run', - '--platform', arch, - '-v', `${process.cwd()}:/js2bin/`, - '-t', containerTag, - '/bin/bash', '-c', - `source /opt/rh/devtoolset-10/enable && cd /js2bin && npm install && ./js2bin.js --ci --node=${this.version} --size=${this.placeHolderSizeMB}MB ${ptrCompression ? '--pointer-compress=true' : ''}` - ] - ); + 'docker', ['run', + '--platform', arch, + '-v', `${process.cwd()}:/js2bin/`, + '-t', containerTag, + '/bin/bash', '-c', + `source /opt/rh/devtoolset-10/enable && cd /js2bin && npm install && ./js2bin.js --ci --node=${this.version} --size=${this.placeHolderSizeMB}MB ${ptrCompression ? '--pointer-compress=true' : ''}` + ] + ); } // 1. download node source @@ -312,7 +311,7 @@ class NodeJsBuilder { .catch(err => this.printDiskUsage().then(() => { throw err; })); } - buildFromCached(platform = 'linux', arch = 'x64', outFile = undefined, cache = false, size) { + buildFromCached(platform = 'linux', arch = 'x64', outFile = undefined, cache = false, size, customDownloadUrl) { const mainAppFileCont = this.getAppContentToBundle(); this.placeHolderSizeMB = Math.ceil(mainAppFileCont.length / 1024 / 1024); // 2, 4, 6, 8... if (this.placeHolderSizeMB % 2 !== 0) { @@ -320,7 +319,7 @@ class NodeJsBuilder { } if (size) this.placeHolderSizeMB = parseInt( size.toUpperCase().replaceAll('MB', '') ) - return this.downloadCachedBuild(platform, arch) + return this.downloadCachedBuild(platform, arch, customDownloadUrl) .then(cachedFile => { const placeholder = this.getPlaceholderContent(this.placeHolderSizeMB);