Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add arm64 linux support #129

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
69 changes: 52 additions & 17 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,56 @@
import fs from 'node:fs';
import { spawn } from 'child_process';
import process from 'node:process';
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://raw.githubusercontent.com/imagemin/optipng-bin/v${pkg.version}/vendor/`;
function getArch() {
switch (process.arch) {
case 'x32':
return 'x86';
case 'x64':
return 'x64'
case 'arm':
return 'arm';
case 'arm64':
return 'arm64';
default:
return null;
}
}

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

export default binWrapper;
const lib = {
path: function () {
const arch = getArch();
const platform = getPlatform();
if (!arch || !platform) {
return null;
}
const url = './vendor'
return platform == 'win'
? `${url}/${platform}/optipng.exe`
: `${url}/${platform}/${arch}/optipng`
},
dest: function () {
return import.meta.url;
},
run: function (args) {
return spawn(this.path(), args);
}
}

export default lib;
Binary file added vendor/linux/arm64/optipng
Binary file not shown.
Loading