Skip to content

Commit d104612

Browse files
committed
Fixup
1 parent 526b9eb commit d104612

File tree

13 files changed

+130
-200
lines changed

13 files changed

+130
-200
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ jobs:
77
strategy:
88
matrix:
99
node-version:
10+
- 20.x
1011
- 22.x
1112
- latest
1213
steps:

CHANGELOG.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
faucet-pipeline-images version history
22
======================================
33

4+
v2.3.0
5+
------
6+
7+
_TBD_
8+
9+
maintenance release to update dependencies
10+
11+
* bumped Node requirement to v20 or later, dropping support for obsolete versions
12+
413
v2.2.0
514
------
615

716
_2024-03-20_
817

9-
Maintenance release to update dependencies; bump minimum supported Node version
18+
maintenance release to update dependencies; bump minimum supported Node version
1019
to 18 due to end of life.
1120

1221
v2.1.0
1322
------
1423

1524
_2021-01-12_
1625

17-
Maintenance release to update dependencies; no significant changes
26+
maintenance release to update dependencies; no significant changes
1827

1928

2029
v2.0.0

lib/index.js renamed to index.js

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1-
let path = require("node:path");
2-
let sharp = require("sharp");
3-
let svgo = require("svgo");
4-
let { readFile } = require("node:fs/promises");
5-
let { buildProcessPipeline } = require("faucet-pipeline-static/lib/util.js");
6-
let { abort } = require("faucet-pipeline-core/lib/util/index.js");
1+
import path from "node:path";
2+
import sharp from "sharp";
3+
import svgo from "svgo";
4+
import { readFile } from "node:fs/promises";
5+
import { buildProcessPipeline } from "faucet-pipeline-static/lib/util.js";
6+
import { abort, repr } from "faucet-pipeline-core/lib/util/index.js";
7+
8+
export const key = "images";
9+
export const bucket = "static";
10+
11+
export function plugin(config, assetManager) {
12+
let pipeline = config.map(optimizerConfig => {
13+
let processFile = buildProcessFile(optimizerConfig);
14+
let { source, target } = optimizerConfig;
15+
let filter = optimizerConfig.filter ||
16+
withFileExtension("avif", "jpg", "jpeg", "png", "webp", "svg");
17+
return buildProcessPipeline(source, target, processFile, assetManager, filter);
18+
});
19+
20+
return filepaths => Promise.all(pipeline.map(optimize => optimize(filepaths)));
21+
}
722

823
// we can optimize the settings here, but some would require libvips
924
// to be compiled with additional stuff
@@ -51,30 +66,8 @@ let settings = {
5166
avif: {}
5267
};
5368

54-
module.exports = {
55-
key: "images",
56-
bucket: "static",
57-
plugin: faucetImages
58-
};
59-
60-
/** @type FaucetPlugin<Config> */
61-
function faucetImages(config, assetManager) {
62-
let pipeline = config.map(optimizerConfig => {
63-
let processFile = buildProcessFile(optimizerConfig);
64-
let { source, target } = optimizerConfig;
65-
let filter = optimizerConfig.filter ||
66-
withFileExtension("avif", "jpg", "jpeg", "png", "webp", "svg");
67-
return buildProcessPipeline(source, target, processFile, assetManager, filter);
68-
});
69-
70-
return filepaths => Promise.all(pipeline.map(optimize => optimize(filepaths)));
71-
}
72-
7369
/**
7470
* Returns a function that processes a single file
75-
*
76-
* @param {Config} config
77-
* @returns {ProcessFile}
7871
*/
7972
function buildProcessFile(config) {
8073
return async function(filename,
@@ -88,7 +81,6 @@ function buildProcessFile(config) {
8881
await optimizeSVG(sourcePath) :
8982
await optimizeBitmap(sourcePath, format, config);
9083

91-
/** @type WriteFileOpts */
9284
let writeOptions = { targetDir };
9385
if(config.fingerprint !== undefined) {
9486
writeOptions.fingerprint = config.fingerprint;
@@ -98,6 +90,8 @@ function buildProcessFile(config) {
9890
}
9991

10092
/**
93+
* Optimize a single SVG
94+
*
10195
* @param {string} sourcePath
10296
* @returns {Promise<string>}
10397
*/
@@ -108,15 +102,16 @@ async function optimizeSVG(sourcePath) {
108102
let output = await svgo.optimize(input, settings.svg);
109103
return output.data;
110104
} catch(error) {
111-
abort(`Only SVG can be converted to SVG: ${sourcePath}`);
112-
return ""; // XXX: this is for typescript :joy:
105+
abort(`Only SVG can be converted to SVG: ${repr(sourcePath)}`);
113106
}
114107
}
115108

116109
/**
110+
* Optimize a single bitmap image
111+
*
117112
* @param {string} sourcePath
118113
* @param {string} format
119-
* @param {ImageOptions} options
114+
* @param {Object} options
120115
* @returns {Promise<Buffer>}
121116
*/
122117
async function optimizeBitmap(sourcePath, format,
@@ -138,8 +133,6 @@ async function optimizeBitmap(sourcePath, format,
138133

139134
if(width || height) {
140135
let fit = crop ? "cover" : "inside";
141-
// XXX: Fixme
142-
// @ts-ignore
143136
image.resize({ width, height, fit: sharp.fit[fit] });
144137
}
145138

@@ -158,15 +151,15 @@ async function optimizeBitmap(sourcePath, format,
158151
image.avif({ ...settings.avif, quality });
159152
break;
160153
default:
161-
abort(`unsupported format ${format}. We support: AVIF, JPG, PNG, WebP, SVG`);
154+
abort(`unsupported format ${repr(format)}. We support: AVIF, JPG, PNG, WebP, SVG`);
162155
}
163156

164157
return image.toBuffer();
165158
}
166159

167160
/**
168161
* @param {string} filepath
169-
* @param {TargetPathOpts} opts
162+
* @param {Object} options
170163
* @returns {string}
171164
*/
172165
function determineTargetPath(filepath, { format, suffix = "" }) {
@@ -186,26 +179,11 @@ function withFileExtension(...extensions) {
186179
}
187180

188181
/**
189-
* extname follows this annoying idea that the dot belongs to the extension
182+
* File extension of a filename without the dot
190183
*
191184
* @param {string} filename
192185
* @returns {string}
193186
*/
194187
function extname(filename) {
195188
return path.extname(filename).slice(1).toLowerCase();
196189
}
197-
198-
/** @import {
199-
* FaucetPlugin,
200-
* FaucetPluginOptions,
201-
* WriteFileOpts,
202-
* Filter,
203-
* ProcessFile
204-
* } from "faucet-pipeline-static/lib/types.ts"
205-
**/
206-
/** @import {
207-
* Config,
208-
* ImageOptions,
209-
* TargetPathOpts
210-
* } from "./types.ts"
211-
**/

lib/types.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "faucet-pipeline-images",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "image optimization for faucet-pipeline",
5-
"main": "lib/index.js",
5+
"main": "./index.js",
6+
"type": "module",
67
"scripts": {
78
"test": "npm run lint && npm run test:cli",
89
"test:cli": "./test/run",
910
"test:prepare": "./test/prepare",
10-
"lint": "eslint --cache lib test && echo ✓",
11-
"typecheck": "tsc"
11+
"lint": "eslint --cache ./index.js ./test && echo ✓"
1212
},
1313
"repository": {
1414
"type": "git",
@@ -21,18 +21,16 @@
2121
},
2222
"homepage": "https://www.faucet-pipeline.org",
2323
"engines": {
24-
"node": ">= 22"
24+
"node": ">= 20.19.0"
2525
},
2626
"dependencies": {
2727
"faucet-pipeline-core": "^3.0.0",
2828
"faucet-pipeline-static": "git+https://github.com/faucet-pipeline/faucet-pipeline-static.git#dual-versions",
29-
"sharp": "^0.34.0",
29+
"sharp": "^0.34.1",
3030
"svgo": "^3.3.2"
3131
},
3232
"devDependencies": {
33-
"@types/node": "^22.13.10",
3433
"eslint-config-fnd": "^1.13.0",
35-
"release-util-fnd": "^3.0.0",
36-
"typescript": "^5.8.2"
34+
"release-util-fnd": "^3.0.0"
3735
}
3836
}

test/test_avif/faucet.config.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
"use strict";
2-
let path = require("path");
1+
import { resolve } from "node:path";
32

4-
module.exports = {
5-
images: [{
6-
source: "./src",
7-
target: "./dist",
8-
format: "avif"
9-
}],
10-
plugins: [path.resolve(__dirname, "../..")]
11-
};
3+
export const images = [{
4+
source: "./src",
5+
target: "./dist",
6+
format: "avif"
7+
}];
8+
9+
export const plugins = [resolve(import.meta.dirname, "../..")];

test/test_basic/faucet.config.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
"use strict";
2-
let path = require("path");
1+
import { resolve } from "node:path";
32

4-
module.exports = {
5-
images: [{
6-
source: "./src",
7-
target: "./dist"
8-
}],
9-
plugins: [path.resolve(__dirname, "../..")]
10-
};
3+
export const images = [{
4+
source: "./src",
5+
target: "./dist"
6+
}];
7+
8+
export const plugins = [resolve(import.meta.dirname, "../..")];

test/test_filter/faucet.config.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
"use strict";
2-
let path = require("path");
1+
import { resolve } from "node:path";
32

4-
module.exports = {
5-
images: [{
6-
source: "./src",
7-
target: "./dist",
8-
filter: file => file.endsWith(".jpg")
9-
}],
10-
plugins: [path.resolve(__dirname, "../..")]
11-
};
3+
export const images = [{
4+
source: "./src",
5+
target: "./dist",
6+
filter: file => file.endsWith(".jpg")
7+
}];
8+
9+
export const plugins = [resolve(import.meta.dirname, "../..")];
Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
"use strict";
2-
let path = require("path");
1+
import { resolve } from "node:path";
32

4-
module.exports = {
5-
images: [{
6-
source: "./src",
7-
target: "./dist"
8-
}, {
9-
source: "./src",
10-
target: "./dist",
11-
format: "webp"
12-
}, {
13-
source: "./src",
14-
target: "./dist",
15-
suffix: "-suffix"
16-
}, {
17-
source: "./src",
18-
target: "./dist",
19-
format: "webp",
20-
suffix: "-suffix"
21-
}],
22-
plugins: [path.resolve(__dirname, "../..")]
23-
};
3+
export const images = [{
4+
source: "./src",
5+
target: "./dist"
6+
}, {
7+
source: "./src",
8+
target: "./dist",
9+
format: "webp"
10+
}, {
11+
source: "./src",
12+
target: "./dist",
13+
suffix: "-suffix"
14+
}, {
15+
source: "./src",
16+
target: "./dist",
17+
format: "webp",
18+
suffix: "-suffix"
19+
}];
20+
21+
export const plugins = [resolve(import.meta.dirname, "../..")];

test/test_quality/faucet.config.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
"use strict";
2-
let path = require("path");
1+
import { resolve } from "node:path";
32

4-
module.exports = {
5-
images: [{
6-
source: "./src",
7-
target: "./dist",
8-
quality: 20
9-
}],
10-
plugins: [path.resolve(__dirname, "../..")]
11-
};
3+
export const images = [{
4+
source: "./src",
5+
target: "./dist",
6+
quality: 20
7+
}];
8+
9+
export const plugins = [resolve(import.meta.dirname, "../..")];

0 commit comments

Comments
 (0)