Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion js2bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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']);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
37 changes: 18 additions & 19 deletions src/NodeBuilder.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -105,15 +104,15 @@ 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);
if (fs.existsSync(filename)) {
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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -312,15 +311,15 @@ 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) {
this.placeHolderSizeMB += 1;
}
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);

Expand Down