Skip to content
Closed
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
63 changes: 48 additions & 15 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
import fs from 'node:fs';
import { execa } from 'execa';

Check failure on line 1 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 16 on macos-latest

There should be no space after '{'.

Check failure on line 1 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 16 on macos-latest

There should be no space before '}'.

Check failure on line 1 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

There should be no space after '{'.

Check failure on line 1 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

There should be no space before '}'.
import process from 'node:process';

Check failure on line 2 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 16 on macos-latest

`node:process` import should occur before import of `execa`

Check failure on line 2 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

`node:process` import should occur before import of `execa`
import {fileURLToPath} from 'node:url';
import BinWrapper from 'bin-wrapper';

const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));
const url = `https://github.com/imagemin/mozjpeg-bin/raw/${pkg.version}/vendor/`;
function getArch() {
switch (process.arch) {
case 'x32':
return 'x86';
case 'x64':
return 'x64'

Check failure on line 9 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 16 on macos-latest

Missing semicolon.

Check failure on line 9 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

Missing semicolon.
case 'arm':
return 'arm';
case 'arm64':
return 'arm64';
default:
return null;
}
}

const binWrapper = new BinWrapper()
.src(`${url}macos/amd64/cjpeg`, 'darwin', 'x64')
.src(`${url}macos/arm64/cjpeg`, 'darwin', 'arm64')
.src(`${url}linux/amd64/cjpeg`, 'linux', 'x64')
.src(`${url}linux/arm64/cjpeg`, 'linux', 'arm64')
.src(`${url}win/x86/cjpeg.exe`, 'win32', 'x86')
.src(`${url}win/x64/cjpeg.exe`, 'win32', 'x64')
.dest(fileURLToPath(new URL('../vendor', import.meta.url)))
.use(process.platform === 'win32' ? 'cjpeg.exe' : 'cjpeg');
function getPlatform() {
switch (process.platform) {
case 'darwin':
return 'macos';
case 'linux':
return 'linux';
case 'win32':
return 'win';
default:
return null;
}
}

export default binWrapper;
const bin = {
path: function () {

Check failure on line 33 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 16 on macos-latest

Expected method shorthand.

Check failure on line 33 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

Expected method shorthand.
const arch = getArch();
const platform = getPlatform();
if (!arch || !platform) {
return null;
}
const url = './vendor'

Check failure on line 39 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 16 on macos-latest

Expected blank line before this statement.

Check failure on line 39 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 16 on macos-latest

Missing semicolon.

Check failure on line 39 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

Expected blank line before this statement.

Check failure on line 39 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

Missing semicolon.
return platform == 'win'

Check failure on line 40 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 16 on macos-latest

Expected '===' and instead saw '=='.

Check failure on line 40 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

Expected '===' and instead saw '=='.
? `${url}/${platform}/cjpeg.exe`
: `${url}/${platform}/${arch}/cjpeg`

Check failure on line 42 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 16 on macos-latest

Missing semicolon.

Check failure on line 42 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

Missing semicolon.
},
dest: function () {

Check failure on line 44 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 16 on macos-latest

Expected method shorthand.

Check failure on line 44 in lib/index.js

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

Expected method shorthand.
return import.meta.url;
},
run: function (args) {
return execa(this.path(), args);
}
}

export default bin;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"ava": "^4.3.3",
"bin-check": "^4.1.0",
"compare-size": "^3.0.0",
"execa": "^7.1.1",
"execa": "^7.2.0",
"tempy": "^3.1.0",
"xo": "^0.45.0"
},
Expand Down
Binary file modified vendor/linux/arm64/cjpeg
Binary file not shown.
Loading