Skip to content

Commit 669eeca

Browse files
authored
Merge pull request #39 from 343dev/bugfix/alpine
Add Alpine Linux support without additional packages
2 parents 063d274 + c4b82ab commit 669eeca

11 files changed

Lines changed: 394 additions & 2470 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [12.1.1] - 2025-01-02
9+
10+
### Changed
11+
12+
- Updated `@343dev/gifsicle` and `@343dev/guetzli` packages, which now allow Optimizt to work on Alpine Linux without installing additional packages. Previously, the `gcompat` package was required as the `guetzli` and `gifsicle` binaries were built for glibc-based systems, which is absent on Alpine Linux.
13+
814
## [12.1.0] - 2025-12-24
915

1016
### Added

cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ if (program.args.length === 0) {
5252
});
5353
}
5454

55-
process.on('unhandledRejection', error => {
55+
process.on('unhandledRejection', (error) => {
5656
console.error(error);
5757
});

convert.js

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,45 +54,43 @@ export async function convert({ filePaths, config }) {
5454
const cpuCount = os.cpus().length;
5555
const tasksSimultaneousLimit = pLimit(cpuCount);
5656

57-
await Promise.all(
58-
filePaths.reduce((accumulator, filePath) => {
59-
if (shouldConvertToAvif) {
60-
accumulator.push(
61-
tasksSimultaneousLimit(
62-
() => processFile({
63-
filePath,
64-
config: avifConfig || {},
65-
progressBarContainer,
66-
progressBar,
67-
totalSize,
68-
isForced,
69-
format: 'AVIF',
70-
processFunction: processAvif,
71-
}),
72-
),
73-
);
74-
}
75-
76-
if (shouldConvertToWebp) {
77-
accumulator.push(
78-
tasksSimultaneousLimit(
79-
() => processFile({
80-
filePath,
81-
config: webpConfig || {},
82-
progressBarContainer,
83-
progressBar,
84-
totalSize,
85-
isForced,
86-
format: 'WebP',
87-
processFunction: processWebp,
88-
}),
89-
),
90-
);
91-
}
92-
93-
return accumulator;
94-
}, []),
95-
);
57+
const tasks = [];
58+
for (const filePath of filePaths) {
59+
if (shouldConvertToAvif) {
60+
tasks.push(
61+
tasksSimultaneousLimit(
62+
() => processFile({
63+
filePath,
64+
config: avifConfig || {},
65+
progressBarContainer,
66+
progressBar,
67+
totalSize,
68+
isForced,
69+
format: 'AVIF',
70+
processFunction: processAvif,
71+
}),
72+
),
73+
);
74+
}
75+
76+
if (shouldConvertToWebp) {
77+
tasks.push(
78+
tasksSimultaneousLimit(
79+
() => processFile({
80+
filePath,
81+
config: webpConfig || {},
82+
progressBarContainer,
83+
progressBar,
84+
totalSize,
85+
isForced,
86+
format: 'WebP',
87+
processFunction: processWebp,
88+
}),
89+
),
90+
);
91+
}
92+
}
93+
await Promise.all(tasks);
9694

9795
progressBarContainer.update(); // Prevent logs lost. See: https://github.com/npkgz/cli-progress/issues/145#issuecomment-1859594159
9896
progressBarContainer.stop();

eslint.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ export default [
44
...config,
55

66
{
7-
ignores: ['.optimiztrc.cjs'],
7+
ignores: [
8+
'coverage/',
9+
'.optimiztrc.cjs',
10+
],
811
},
912
];

lib/find-config-file-path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function findConfigFilePath(providedConfigPath) {
3131
const currentConfigPath = path.join(currentDirectoryPath, DEFAULT_CONFIG_FILENAME);
3232

3333
try {
34-
const stat = await fs.promises.stat(currentConfigPath); // eslint-disable-line no-await-in-loop
34+
const stat = await fs.promises.stat(currentConfigPath);
3535

3636
if (stat.isFile()) {
3737
return currentConfigPath;

lib/log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function log(title, { type, description } = {}) {
4949

5050
export function logErrorAndExit(title) {
5151
log(title, { type: LOG_TYPES.ERROR });
52-
process.exit(1); // eslint-disable-line unicorn/no-process-exit
52+
process.exit(1); // eslint-disable-line n/no-process-exit
5353
}
5454

5555
export function logEmptyLine() {

lib/prepare-file-paths.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function prepareFilePaths({
2020
const inputPathsSet = new Set(inputPaths);
2121

2222
await Promise.all(
23-
[...inputPathsSet].map(async currentPath => {
23+
[...inputPathsSet].map(async (currentPath) => {
2424
try {
2525
const stat = await fs.promises.stat(currentPath);
2626
const resolvedPath = path.resolve(currentPath);
@@ -30,11 +30,13 @@ export async function prepareFilePaths({
3030
} else if (stat.isFile() && checkFileType(resolvedPath, extensions)) {
3131
files.add(resolvedPath);
3232
}
33-
} catch {}
33+
} catch {
34+
// ¯\_(ツ)_/¯
35+
}
3436
}),
3537
);
3638

37-
const crawler = new fdir() // eslint-disable-line new-cap
39+
const crawler = new fdir()
3840
.withFullPaths()
3941
.withDirs()
4042
.filter(currentPath => checkFileType(currentPath, extensions));
@@ -49,7 +51,7 @@ export async function prepareFilePaths({
4951

5052
const hasDirectories = directories.size > 0;
5153

52-
const result = [...files].map(filePath => {
54+
const result = [...files].map((filePath) => {
5355
let outputPath = filePath;
5456

5557
if (outputDirectoryPath) {

optimize.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function optimize({ filePaths, config }) {
4646
const guetzliTasksSimultaneousLimit = pLimit(1); // Guetzli uses a large amount of memory and a significant amount of CPU time. To reduce system load, we only allow one instance of guetzli to run at the same time.
4747

4848
await Promise.all(
49-
filePaths.map(filePath => {
49+
filePaths.map((filePath) => {
5050
const extension = path.extname(filePath.input).toLowerCase();
5151
const isJpeg = extension === '.jpg' || extension === '.jpeg';
5252

@@ -231,15 +231,15 @@ function pipe({ command, commandOptions, inputBuffer }) {
231231
process.stdin.end();
232232

233233
const stdoutChunks = [];
234-
process.stdout.on('data', chunk => {
234+
process.stdout.on('data', (chunk) => {
235235
stdoutChunks.push(chunk);
236236
});
237237

238-
process.on('error', error => {
238+
process.on('error', (error) => {
239239
reject(new Error(`Error processing image: ${error.message}`));
240240
});
241241

242-
process.on('close', code => {
242+
process.on('close', (code) => {
243243
if (code !== 0) {
244244
reject(new Error(`Image optimization process exited with code ${code}`));
245245
return;

0 commit comments

Comments
 (0)