Skip to content

Commit

Permalink
fix: binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Jul 9, 2019
1 parent cf08d98 commit a781277
Show file tree
Hide file tree
Showing 50 changed files with 10,608 additions and 63 deletions.
103 changes: 71 additions & 32 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,90 @@ addons:
matrix:
fast_finish: true
include:
#- os: linux
# node_js: "12"
# script: npm run $JOB_PART
# env: JOB_PART=pretest
#- os: linux
# node_js: "12"
# script: npm run $JOB_PART
# env: JOB_PART=test:only
#- os: osx
# node_js: "12"
# script: npm run $JOB_PART
# env: JOB_PART=test:only
# - os: windows
# node_js: "12"
# script: npm run $JOB_PART
# env: JOB_PART=test:only
#- os: linux
# node_js: "10"
# script: npm run $JOB_PART
# env: JOB_PART=test:only
#- os: osx
# node_js: "10"
# script: npm run $JOB_PART
# env: JOB_PART=test:only
# - os: windows
# node_js: "10"
# script: npm run $JOB_PART
# env: JOB_PART=test:only

- os: linux
node_js: "8"
node_js: "12"
script: npm run $JOB_PART
env: JOB_PART=pretest
- os: linux
node_js: "12"
script: npm run $JOB_PART
env: JOB_PART=test:only
- os: osx
node_js: "12"
script: npm run $JOB_PART
env: JOB_PART=test:only
- os: windows
node_js: "12"
script: npm run $JOB_PART
env: JOB_PART=test:only
- os: linux
node_js: "10"
script: npm run $JOB_PART
env: JOB_PART=test:only
- os: osx
node_js: "10"
script: npm run $JOB_PART
env: JOB_PART=test:only
- os: windows
node_js: "10"
script: npm run $JOB_PART
env: JOB_PART=test:only
- stage: test
os: linux
node_js: "8"
script: npm run $JOB_PART
env: JOB_PART=test:only
- stage: test
os: osx
node_js: "8"
script: npm run $JOB_PART
env: JOB_PART=test:only
- os: windows
node_js: "8"
script: npm run $JOB_PART
env: JOB_PART=test:only
- stage: deploy
os: linux
node_js: "8"
script:
- node -p "process.arch"
- node src/install.js
- tar -czvf mozjpeg-linux.tar.gz $COMPILATION_DEST
- wget -c https://github.com/probonopd/uploadtool/raw/master/upload.sh
- bash upload.sh mozjpeg-linux.tar.gz
env:
- COMPILATION_DEST=binaries/linux
- COMPILATION_REQUIRED=true
- stage: deploy
os: osx
node_js: "8"
script:
- node -p "process.arch"
- node src/install.js
- tar -czvf mozjpeg-osx.tar.gz $COMPILATION_DEST
- wget -c https://github.com/probonopd/uploadtool/raw/master/upload.sh
- bash upload.sh mozjpeg-osx.tar.gz
env:
- COMPILATION_DEST=binaries/macos
- COMPILATION_REQUIRED=true
# TODO implement in next release
# - stage: deploy
# os: windows
# node_js: "8"
# script:
# - node -p "process.arch"
# - choco install vcredist140
# - node src/install.js
# - tar -czvf mozjpeg-windows.tar.gz $COMPILATION_DEST
# - wget -c https://github.com/probonopd/uploadtool/raw/master/upload.sh
# - bash upload.sh mozjpeg-windows.tar.gz
# env:
# - COMPILATION_DEST=binaries/windows
# - COMPILATION_REQUIRED=true

before_install:
- if [[ $TRAVIS_OS_NAME == osx ]]; then brew update && brew install nasm; fi;
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then npm install -g npm@latest; fi
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then brew update && brew install nasm; fi;
- if [[ ("$TRAVIS_OS_NAME" == "linux") || ($TRAVIS_OS_NAME == "osx") ]]; then npm install -g npm@latest; fi
- node --version
- npm --version

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org).

## 2.0.0-rc.3 - 2019-07-10

- fix: binaries

## 2.0.0-rc.2 - 2019-07-09

- fix: binaries
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ You probably want [`imagemin-mozjpeg-full`](https://github.com/itgalaxy/imagemin

What is difference between [mozjpeg-bin](https://github.com/imagemin/mozjpeg-bin/):

- Contains all binaries delivered by `mozjpeg`: `cjpeg`, `djpeg`, `jpegtran`, `rdjpgcom`, `tjbench` and `wrjpgcom` (`rdjpgcom`, `tjbench`, `wrjpgcom` is unavailable on `windows`).
- Contains all binaries delivered by `mozjpeg`: `cjpeg`, `djpeg`, `jpegtran`, `rdjpgcom`, `tjbench` and `wrjpgcom` (only `x64` supported).
- No security vulnerabilities.
- Latest version.

Expand Down
22 changes: 16 additions & 6 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
const path = require("path");
const paths = require("../src");

const isWin = process.platform === "win32";

describe("paths", () => {
it("should be exported", () => {
expect(path.basename(paths.cjpeg)).toBe("cjpeg");
expect(path.basename(paths.djpeg)).toBe("djpeg");
expect(path.basename(paths.jpegtran)).toBe("jpegtran");
expect(path.basename(paths.rdjpgcom)).toBe("rdjpgcom");
expect(path.basename(paths.tjbench)).toBe("tjbench");
expect(path.basename(paths.wrjpgcom)).toBe("wrjpgcom");
expect(path.basename(paths.cjpeg)).toBe(isWin ? "cjpeg.exe" : "cjpeg");
expect(path.basename(paths.djpeg)).toBe(isWin ? "djpeg.exe" : "djpeg");
expect(path.basename(paths.jpegtran)).toBe(
isWin ? "jpegtran.exe" : "jpegtran"
);
expect(path.basename(paths.rdjpgcom)).toBe(
isWin ? "rdjpgcom.exe" : "rdjpgcom"
);
expect(path.basename(paths.tjbench)).toBe(
isWin ? "tjbench.exe" : "tjbench"
);
expect(path.basename(paths.wrjpgcom)).toBe(
isWin ? "wrjpgcom.exe" : "wrjpgcom"
);
});
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mozjpeg-binaries",
"version": "2.0.0-rc.2",
"version": "2.0.0-rc.3",
"description": "Wrapper for mozjpeg binaries (cjpeg, djpeg, jpegtran, rdjpgcom, tjbench and wrjpgcom).",
"repository": {
"type": "git",
Expand Down Expand Up @@ -71,7 +71,7 @@
"scripts": {
"postinstall": "node src/install.js",
"lint:prettier": "prettier --list-different '{bin,src,__tests__}/**/*.{js,mjs,jsx,md,yml}' '*.{js,mjs,jsx,md,yml}'",
"lint:md": "remark . -i .gitignore -f -q",
"lint:md": "remark '*.md' -i .gitignore -f -q",
"lint:js": "eslint . --cache --cache-location 'node_modules/.cache/eslint/.eslintcache' --report-unused-disable-directives --ignore-pattern '!.*' --ignore-path .gitignore --ext '.js,.mjs,.jsx'",
"lint": "npm-run-all -l -p 'lint:**'",
"prettier": "npm run lint:prettier -- --write",
Expand Down
21 changes: 10 additions & 11 deletions src/bin-wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const path = require("path");
const BinWrappers = require("bin-wrapper");
const pkg = require("../package.json");

const dest = path.join(__dirname, "../vendor");
const dest =
typeof process.env.COMPILATION_DEST !== "undefined"
? process.env.COMPILATION_DEST
: path.join(__dirname, "../vendor");
const isWin = process.platform === "win32";

const url = `https://raw.githubusercontent.com/itgalaxy/mozjpeg-binaries/v${pkg.version}/vendor/`;
Expand All @@ -13,46 +16,42 @@ module.exports = {
cjpeg: new BinWrappers()
.src(`${url}linux/cjpeg`, "linux")
.src(`${url}macos/cjpeg`, "darwin")
.src(`${url}windows/x64/cjpeg.exe`, "win32", "x64")
.src(`${url}windows/x86/cjpeg.exe`, "win32", "x86")
.src(`${url}windows/cjpeg.exe`, "win32")
.dest(dest)
.use(isWin ? "cjpeg.exe" : "cjpeg"),

djpeg: new BinWrappers()
.src(`${url}linux/djpeg`, "linux")
.src(`${url}macos/djpeg`, "darwin")
.src(`${url}windows/x64/djpeg.exe`, "win32", "x64")
.src(`${url}windows/x86/djpeg.exe`, "win32", "x86")
.src(`${url}windows/djpeg.exe`, "win32")
.dest(dest)
.use(isWin ? "djpeg.exe" : "djpeg"),

jpegtran: new BinWrappers()
.src(`${url}linux/jpegtran`, "linux")
.src(`${url}macos/jpegtran`, "darwin")
.src(`${url}windows/x64/jpegtran.exe`, "win32", "x64")
.src(`${url}windows/x86/jpegtran.exe`, "win32", "x86")
.src(`${url}windows/jpegtran.exe`, "win32")
.dest(dest)
.use(isWin ? "jpegtran.exe" : "jpegtran"),

rdjpgcom: new BinWrappers()
.src(`${url}linux/rdjpgcom`, "linux")
.src(`${url}macos/rdjpgcom`, "darwin")
.src(`${url}windows/x64/rdjpgcom.exe`, "win32", "x64")
.src(`${url}windows/x86/rdjpgcom.exe`, "win32", "x86")
.src(`${url}windows/rdjpgcom.exe`, "win32")
.dest(dest)
.use(isWin ? "rdjpgcom.exe" : "rdjpgcom"),

tjbench: new BinWrappers()
.src(`${url}linux/tjbench`, "linux")
.src(`${url}macos/tjbench`, "darwin")
.src(`${url}windows/tjbench.exe`, "win32")
.dest(dest)
.use(isWin ? "tjbench.exe" : "tjbench"),

wrjpgcom: new BinWrappers()
.src(`${url}linux/wrjpgcom`, "linux")
.src(`${url}macos/wrjpgcom`, "darwin")
.src(`${url}windows/x64/wrjpgcom.exe`, "win32", "x64")
.src(`${url}windows/x86/wrjpgcom.exe`, "win32", "x86")
.src(`${url}windows/wrjpgcom.exe`, "win32")
.dest(dest)
.use(isWin ? "wrjpgcom.exe" : "wrjpgcom")
};
31 changes: 21 additions & 10 deletions src/install.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

const path = require("path");
const fs = require("fs");
const os = require("os");
const binBuild = require("bin-build");
Expand All @@ -15,9 +16,14 @@ const buildCommands = () => {
cfgExtras = "libpng_LIBS='/usr/local/lib/libpng16.a -lz' --enable-static";
}

const dest = binWrappers.cjpeg.dest();
const compilationDest = path.isAbsolute(dest)
? dest
: path.join(process.cwd(), dest);

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

return binBuild.url(
Expand All @@ -33,6 +39,14 @@ Object.keys(binWrappers).forEach(program => {

queue.add(() =>
Promise.resolve()
.then(() => {
if (process.env.COMPILATION_REQUIRED) {
throw new Error("Compilation required");
}

// eslint-disable-next-line promise/no-return-wrap
return Promise.resolve();
})
// Workaround https://github.com/kevva/bin-wrapper/issues/67
// Need use bin.run(['--version']) after resolve
.then(() => binWrapper.findExisting())
Expand All @@ -46,9 +60,6 @@ Object.keys(binWrappers).forEach(program => {
].includes(program);
const checkCommand = commandWihtoutCheck ? ["-help"] : ["-version"];

// eslint-disable-next-line no-console
console.log(binWrapper.path());

return binWrapper
.runCheck(checkCommand)
.then(binCheck => {
Expand All @@ -59,10 +70,7 @@ Object.keys(binWrappers).forEach(program => {
.catch(error => {
const { message } = error;

// eslint-disable-next-line no-console
console.log(error);

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

return;
Expand All @@ -74,8 +82,11 @@ Object.keys(binWrappers).forEach(program => {
.catch(error => {
queue.pause();

console.log(error.message); // eslint-disable-line no-console
console.log("pre-build test failed"); // eslint-disable-line no-console
if (!process.env.COMPILATION_REQUIRED) {
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()
Expand Down
Binary file modified vendor/macos/cjpeg
Binary file not shown.
Binary file modified vendor/macos/djpeg
Binary file not shown.
Loading

0 comments on commit a781277

Please sign in to comment.