Skip to content

Commit

Permalink
fix: don't use remote binary, not all libraries provided
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Sep 18, 2018
1 parent 00c9fab commit d71e304
Show file tree
Hide file tree
Showing 32 changed files with 65 additions and 10,531 deletions.
26 changes: 4 additions & 22 deletions src/bin-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,19 @@

const path = require("path");
const BinWrapper = require("bin-wrapper");
const pkg = require("../package.json");

const dest = path.join(__dirname, "../vendor");
const isWin = process.platform === "win32";
const url = `https://raw.githubusercontent.com/itgalaxy/mozjpeg-binaries/v${
pkg.version
}/vendor/`;

module.exports = {
cjpeg: new BinWrapper()
.src(`${url}linux/cjpeg`, "linux")
.dest(dest)
.use(isWin ? "cjpeg.exe" : "cjpeg"),
djpeg: new BinWrapper()
.src(`${url}linux/djpeg`, "linux")
.dest(dest)
.use(isWin ? "djpeg.exe" : "djpeg"),
cjpeg: new BinWrapper().dest(dest).use(isWin ? "cjpeg.exe" : "cjpeg"),
djpeg: new BinWrapper().dest(dest).use(isWin ? "djpeg.exe" : "djpeg"),
jpegtran: new BinWrapper()
.src(`${url}linux/jpegtran`, "linux")
.dest(dest)
.use(isWin ? "jpegtran.exe" : "jpegtran"),
rdjpgcom: new BinWrapper()
.src(`${url}linux/rdjpgcom`, "linux")
.dest(dest)
.use(isWin ? "rdjpgcom.exe" : "rdjpgcom"),
tjbench: new BinWrapper()
.src(`${url}linux/tjbench`, "linux")
.dest(dest)
.use(isWin ? "tjbench.exe" : "tjbench"),
wrjpgcom: new BinWrapper()
.src(`${url}linux/wrjpgcom`, "linux")
.dest(dest)
.use(isWin ? "wrjpgcom.exe" : "wrjpgcom")
tjbench: new BinWrapper().dest(dest).use(isWin ? "tjbench.exe" : "tjbench"),
wrjpgcom: new BinWrapper().dest(dest).use(isWin ? "wrjpgcom.exe" : "wrjpgcom")
};
88 changes: 61 additions & 27 deletions src/install.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"use strict";

const fs = require("fs");
const os = require("os");
const binBuild = require("bin-build");
const bin = require("./bin-wrapper");
const binWrappers = require("./bin-wrapper");

const buildCommands = () => {
const cpus = (os.cpus() || { length: 1 }).length;
Expand All @@ -15,7 +16,7 @@ const buildCommands = () => {

const cfg = [
`./configure --enable-static --disable-shared --disable-dependency-tracking --with-jpeg8 ${cfgExtras}`,
`--prefix="${bin.cjpeg.dest()}" --bindir="${bin.cjpeg.dest()}" --libdir="${bin.cjpeg.dest()}"`
`--prefix="${binWrappers.cjpeg.dest()}" --bindir="${binWrappers.cjpeg.dest()}" --libdir="${binWrappers.cjpeg.dest()}"`
].join(" ");

return binBuild.url(
Expand All @@ -24,30 +25,63 @@ const buildCommands = () => {
);
};

Promise.resolve()
.then(() => bin.cjpeg.run(["-version"]))
.then(result => {
console.log("mozjpeg pre-build test passed successfully"); // eslint-disable-line no-console
Promise.all(
Object.keys(binWrappers).map(program => {
const binWrapper = binWrappers[program];

return result;
return (
Promise.resolve()
// Workaround https://github.com/kevva/bin-wrapper/issues/67
// Need use bin.run(['--version']) after resolve
.then(() => binWrapper.findExisting())
// eslint-disable-next-line no-sync
.then(() => fs.chmodSync(binWrapper.path(), "755"))
.then(() => {
const commandWihtoutCheck = [
"rdjpgcom",
"wrjpgcom",
"tjbench"
].includes(program);
const checkCommand = commandWihtoutCheck ? ["-help"] : ["-version"];

return binWrapper
.runCheck(checkCommand)
.then(binCheck => {
console.log(`${program} pre-build test passed successfully`); // eslint-disable-line no-console

return binCheck;
})
.catch(error => {
const { message } = error;

if (commandWihtoutCheck && /usage/iu.test(message)) {
console.log(`${program} pre-build test passed successfully`); // eslint-disable-line no-console

return;
}

throw error;
});
})
);
})
.catch(error => {
console.log(error.message); // eslint-disable-line no-console
console.log("mozjpeg pre-build test failed"); // eslint-disable-line no-console
console.log("compiling from source"); // eslint-disable-line no-console

buildCommands()
.then(result => {
console.log("mozjpeg built successfully"); // eslint-disable-line no-console

return result;
})
.catch(buildError => {
console.log(buildError.stack); // eslint-disable-line no-console

const exitCode =
typeof buildError.code === "number" ? buildError.code : 1;

process.exit(exitCode); // eslint-disable-line no-process-exit
});
});
).catch(error => {
console.log(error.message); // eslint-disable-line no-console
console.log("pre-build test failed"); // eslint-disable-line no-console
console.log("compiling from source"); // eslint-disable-line no-console

buildCommands()
.then(result => {
console.log("built successfully"); // eslint-disable-line no-console

return result;
})
.catch(buildError => {
console.log(buildError.stack); // eslint-disable-line no-console

const exitCode =
typeof buildError.code === "number" ? buildError.code : 1;

process.exit(exitCode); // eslint-disable-line no-process-exit
});
});
Binary file removed vendor/linux/cjpeg
Binary file not shown.
Binary file removed vendor/linux/djpeg
Binary file not shown.
77 changes: 0 additions & 77 deletions vendor/linux/include/jconfig.h

This file was deleted.

Loading

0 comments on commit d71e304

Please sign in to comment.