Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

npx lint-staged
3 changes: 3 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

npm test && npm run license-check
2 changes: 1 addition & 1 deletion .github/workflows/ci-nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [20.19.0, latest]
node-version: [22.22.1, latest]
os: [
ubuntu-latest, # x64
ubuntu-24.04-arm, # arm64
Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [13.0.0] - 2026-06-27

### Changed

- **BREAKING:** Increased the minimum Node.js version to 22.22.1.
- **BREAKING:** Increased the minimum Node.js version to 22.22.1 (required by `lint-staged`).
- **BREAKING:** Restricted package exports so Optimizt is only exposed as a CLI package.
- Pinned the Docker base image to `node:22.22.1-alpine3.23` for reproducible builds.
- Replaced `simple-git-hooks` with versioned hooks in `.githooks`; contributors working on Optimizt code can run `npm run enable-git-hooks` after cloning to configure `core.hooksPath`.
- Updated dependencies no longer ship `postinstall` scripts, following the ecosystem move away from dependency lifecycle scripts in npm and other package managers (see [npm RFC #868](https://github.com/npm/rfcs/pull/868)).

### Removed

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:current-alpine
FROM node:22.22.1-alpine3.23
LABEL maintainer="Andrey Warkentin (https://github.com/343dev)"

WORKDIR /app
Expand Down
14 changes: 14 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Migration

## 12.1.1 → 13.0.0

Node.js version must be 22.22.1 or higher.

Optimizt is now exposed only as a CLI package. If you imported Optimizt internals from JavaScript, switch to the `optimizt` CLI instead.

Git hooks are no longer configured through `simple-git-hooks`. This affects only contributors working on Optimizt code, not users installing Optimizt as a package. After cloning the repository, contributors can run:

```shell
npm run enable-git-hooks
```

This configures Git to use versioned hooks from the `.githooks` directory through `core.hooksPath`.

## 11.0.0 → 12.0.0

The SVGO configuration has been updated to be compatible with SVGO v4 (see [migration guide](https://svgo.dev/docs/migrations/migration-from-v3-to-v4/)). If you use a custom [.optimiztrc.cjs](.optimiztrc.cjs) file, update your SVG plugins configuration to match the new format.
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ When using `--config path/to/.optimiztrc.cjs`, the specified configuration file
Ensure the [ignore-scripts](https://docs.npmjs.com/cli/v6/using-npm/config#ignore-scripts) npm option is disabled.
Details: [funbox/optimizt/issues/9](https://github.com/funbox/optimizt/issues/9).

## Development

After cloning the repository, enable Git hooks once:

```sh
npm run enable-git-hooks
```

This configures Git to use the versioned hooks from the [.githooks](./.githooks) directory.

## Docker

### Pre-Built Image
Expand Down
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import optimizt from './index.js';
import { setProgramOptions } from './lib/program-options.js';

const dirname = path.dirname(fileURLToPath(import.meta.url));
const packageJson = JSON.parse(await fs.readFile(path.join(dirname, 'package.json')));
const packageJson = JSON.parse(await fs.readFile(path.join(dirname, 'package.json'), 'utf8'));

program
.option('--avif', 'create AVIF and exit')
Expand Down
36 changes: 18 additions & 18 deletions lib/colorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ export function colorize(...arguments_) {
const buildColor = (start, end) => `${isTTY ? start : ''}${string_}${isTTY ? end : ''}`;

return {
dim: buildColor('\u001B[2m', '\u001B[22m'),
reset: buildColor('\u001B[0m', '\u001B[0m'),
dim: buildColor('\u{1B}[2m', '\u{1B}[22m'),
reset: buildColor('\u{1B}[0m', '\u{1B}[0m'),

black: buildColor('\u001B[30m', '\u001B[39m'),
blue: buildColor('\u001B[34m', '\u001B[39m'),
cyan: buildColor('\u001B[36m', '\u001B[39m'),
green: buildColor('\u001B[32m', '\u001B[39m'),
magenta: buildColor('\u001B[35m', '\u001B[39m'),
red: buildColor('\u001B[31m', '\u001B[39m'),
white: buildColor('\u001B[37m', '\u001B[39m'),
yellow: buildColor('\u001B[33m', '\u001B[39m'),
black: buildColor('\u{1B}[30m', '\u{1B}[39m'),
blue: buildColor('\u{1B}[34m', '\u{1B}[39m'),
cyan: buildColor('\u{1B}[36m', '\u{1B}[39m'),
green: buildColor('\u{1B}[32m', '\u{1B}[39m'),
magenta: buildColor('\u{1B}[35m', '\u{1B}[39m'),
red: buildColor('\u{1B}[31m', '\u{1B}[39m'),
white: buildColor('\u{1B}[37m', '\u{1B}[39m'),
yellow: buildColor('\u{1B}[33m', '\u{1B}[39m'),

bgBlack: buildColor('\u001B[40m', '\u001B[0m'),
bgBlue: buildColor('\u001B[44m', '\u001B[0m'),
bgCyan: buildColor('\u001B[46m', '\u001B[0m'),
bgGreen: buildColor('\u001B[42m', '\u001B[0m'),
bgMagenta: buildColor('\u001B[45m', '\u001B[0m'),
bgRed: buildColor('\u001B[41m', '\u001B[0m'),
bgWhite: buildColor('\u001B[47m', '\u001B[0m'),
bgYellow: buildColor('\u001B[43m', '\u001B[0m'),
bgBlack: buildColor('\u{1B}[40m', '\u{1B}[0m'),
bgBlue: buildColor('\u{1B}[44m', '\u{1B}[0m'),
bgCyan: buildColor('\u{1B}[46m', '\u{1B}[0m'),
bgGreen: buildColor('\u{1B}[42m', '\u{1B}[0m'),
bgMagenta: buildColor('\u{1B}[45m', '\u{1B}[0m'),
bgRed: buildColor('\u{1B}[41m', '\u{1B}[0m'),
bgWhite: buildColor('\u{1B}[47m', '\u{1B}[0m'),
bgYellow: buildColor('\u{1B}[43m', '\u{1B}[0m'),
};
}
2 changes: 1 addition & 1 deletion lib/create-progress-bar-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getPlural } from './get-plural.js';

export function createProgressBarContainer(totalCount) {
return new CliProgress.MultiBar({
format: `{bar} {percentage}% | Processed {value} of {total} ${getPlural(totalCount, 'image', 'images')}`,
format: '{bar} {percentage}% | Processed {value} of {total} ' + getPlural(totalCount, 'image', 'images'),
clearOnComplete: true,
}, CliProgress.Presets.shades_classic);
}
2 changes: 1 addition & 1 deletion lib/format-bytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function formatBytes(bytes) {
}

const index = Math.floor(Math.log(bytes) / LOG_K);
const value = Number.parseFloat((bytes / (K ** index)).toFixed(DECIMALS)); // Use parseFloat to show "1 KB" instead of "1.000 KB"
const value = Number((bytes / (K ** index)).toFixed(DECIMALS)); // Use Number to show "1 KB" instead of "1.000 KB"

return `${value} ${SIZES[index]}`;
}
8 changes: 5 additions & 3 deletions lib/prepare-file-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ export async function prepareFilePaths({
if (outputDirectoryPath) {
if (hasDirectories) {
for (const directory of directories) {
if (filePath.startsWith(directory)) {
outputPath = path.join(outputDirectoryPath, filePath.slice(directory.length));
break;
if (!filePath.startsWith(directory)) {
continue;
}

outputPath = path.join(outputDirectoryPath, filePath.slice(directory.length));
break;
}
} else {
outputPath = path.join(outputDirectoryPath, filePath.slice(path.dirname(filePath).length));
Expand Down
Loading
Loading