@macrulez/devtoolz 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -8
- package/dist/cli.js +265 -8
- package/dist/cli.js.map +1 -1
- package/dist/commands/case-check/report.js +8 -6
- package/dist/commands/case-check/report.js.map +1 -1
- package/dist/commands/circular-imports/report.js +11 -12
- package/dist/commands/circular-imports/report.js.map +1 -1
- package/dist/commands/console-strip/report.js +9 -7
- package/dist/commands/console-strip/report.js.map +1 -1
- package/dist/commands/dead-exports/report.js +6 -4
- package/dist/commands/dead-exports/report.js.map +1 -1
- package/dist/commands/empty-catch/report.js +5 -3
- package/dist/commands/empty-catch/report.js.map +1 -1
- package/dist/commands/exports-doctor/report.js +7 -5
- package/dist/commands/exports-doctor/report.js.map +1 -1
- package/dist/commands/full-check/report.d.ts +3 -0
- package/dist/commands/full-check/report.js +55 -0
- package/dist/commands/full-check/report.js.map +1 -0
- package/dist/commands/full-check/run.d.ts +32 -0
- package/dist/commands/full-check/run.js +251 -0
- package/dist/commands/full-check/run.js.map +1 -0
- package/dist/commands/image-hash/cache.d.ts +14 -0
- package/dist/commands/image-hash/cache.js +40 -0
- package/dist/commands/image-hash/cache.js.map +1 -0
- package/dist/commands/image-hash/core.d.ts +56 -0
- package/dist/commands/image-hash/core.js +293 -0
- package/dist/commands/image-hash/core.js.map +1 -0
- package/dist/commands/image-hash/hash.d.ts +19 -0
- package/dist/commands/image-hash/hash.js +97 -0
- package/dist/commands/image-hash/hash.js.map +1 -0
- package/dist/commands/image-hash/report.d.ts +3 -0
- package/dist/commands/image-hash/report.js +94 -0
- package/dist/commands/image-hash/report.js.map +1 -0
- package/dist/commands/image-hash/run.d.ts +60 -0
- package/dist/commands/image-hash/run.js +315 -0
- package/dist/commands/image-hash/run.js.map +1 -0
- package/dist/commands/image-hash/sharp-loader.d.ts +59 -0
- package/dist/commands/image-hash/sharp-loader.js +79 -0
- package/dist/commands/image-hash/sharp-loader.js.map +1 -0
- package/dist/commands/orphan-tests/report.js +7 -5
- package/dist/commands/orphan-tests/report.js.map +1 -1
- package/dist/commands/readme-check/report.js +7 -5
- package/dist/commands/readme-check/report.js.map +1 -1
- package/dist/commands/scripts-check/report.js +7 -5
- package/dist/commands/scripts-check/report.js.map +1 -1
- package/dist/commands/stale-ts-ignore/report.js +7 -5
- package/dist/commands/stale-ts-ignore/report.js.map +1 -1
- package/dist/commands/strip-comments/report.js +6 -4
- package/dist/commands/strip-comments/report.js.map +1 -1
- package/dist/commands/todo-report/report.js +7 -5
- package/dist/commands/todo-report/report.js.map +1 -1
- package/dist/commands/unused-deps/report.js +7 -5
- package/dist/commands/unused-deps/report.js.map +1 -1
- package/dist/format/colors.d.ts +4 -0
- package/dist/format/colors.js +4 -3
- package/dist/format/colors.js.map +1 -1
- package/dist/format/diff-render.js +2 -2
- package/dist/format/diff-render.js.map +1 -1
- package/dist/format/file-list.d.ts +1 -9
- package/dist/format/file-list.js +5 -16
- package/dist/format/file-list.js.map +1 -1
- package/dist/format/findings-list.d.ts +1 -8
- package/dist/format/findings-list.js +5 -14
- package/dist/format/findings-list.js.map +1 -1
- package/dist/format/style.d.ts +20 -0
- package/dist/format/style.js +36 -0
- package/dist/format/style.js.map +1 -0
- package/dist/format/table.d.ts +8 -0
- package/dist/format/table.js +44 -0
- package/dist/format/table.js.map +1 -0
- package/dist/format/vibes.d.ts +4 -1
- package/dist/format/vibes.js +25 -10
- package/dist/format/vibes.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/walk.d.ts +2 -0
- package/dist/utils/walk.js +4 -3
- package/dist/utils/walk.js.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/commands/image-hash/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CA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AC,CAAA;YACjC,MAAM,MAAM,GAA4B,EAAE,CAAA;YAC1C,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YACvD,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC,CAAW,EAAE,MAAM,CAAC,CAAA;QACrD,CAAC,CAAC,CAAA;IACJ,CAAC;IACD,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAA;IACzB,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,MAAM,KAAK,GAAG,gDAAgD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACzE,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,EAAE,CAAA;QACzB,IAAI,GAAG,KAAK,CAAC,CAAC,CAAW,CAAA;IAC3B,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAA4C,CAAA;QAC1E,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAA;IACtF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,EAAE,CAAA;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Components, type HashType } from './core.js';
|
|
2
|
+
import type { SharpFactory } from './sharp-loader.js';
|
|
3
|
+
export interface ComputeOptions {
|
|
4
|
+
types: HashType[];
|
|
5
|
+
size: number;
|
|
6
|
+
components: Components;
|
|
7
|
+
maxPixels?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ComputedHashes {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
blurhash?: string;
|
|
13
|
+
thumbhash?: string;
|
|
14
|
+
color?: string;
|
|
15
|
+
preview?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function dominantColor(rgba: ArrayLike<number>): string | undefined;
|
|
18
|
+
export declare function friendlyMessage(error: unknown, maxPixels: number | undefined): string;
|
|
19
|
+
export declare function computeHashes(sharp: SharpFactory, input: string | Uint8Array, options: ComputeOptions): Promise<ComputedHashes>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { encode as encodeBlurhash } from 'blurhash';
|
|
2
|
+
import { rgbaToThumbHash, thumbHashToRGBA } from 'thumbhash';
|
|
3
|
+
import { resolveComponents } from './core.js';
|
|
4
|
+
export function dominantColor(rgba) {
|
|
5
|
+
const buckets = new Map();
|
|
6
|
+
for (let i = 0; i + 3 < rgba.length; i += 4) {
|
|
7
|
+
if (rgba[i + 3] < 128)
|
|
8
|
+
continue;
|
|
9
|
+
const r = rgba[i];
|
|
10
|
+
const g = rgba[i + 1];
|
|
11
|
+
const b = rgba[i + 2];
|
|
12
|
+
const key = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4);
|
|
13
|
+
const bucket = buckets.get(key);
|
|
14
|
+
if (bucket) {
|
|
15
|
+
bucket.count++;
|
|
16
|
+
bucket.r += r;
|
|
17
|
+
bucket.g += g;
|
|
18
|
+
bucket.b += b;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
buckets.set(key, { count: 1, r, g, b });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
let best;
|
|
25
|
+
for (const bucket of buckets.values()) {
|
|
26
|
+
if (!best || bucket.count > best.count)
|
|
27
|
+
best = bucket;
|
|
28
|
+
}
|
|
29
|
+
if (!best)
|
|
30
|
+
return undefined;
|
|
31
|
+
const hex = (sum) => Math.round(sum / best.count)
|
|
32
|
+
.toString(16)
|
|
33
|
+
.padStart(2, '0');
|
|
34
|
+
return `#${hex(best.r)}${hex(best.g)}${hex(best.b)}`;
|
|
35
|
+
}
|
|
36
|
+
export function friendlyMessage(error, maxPixels) {
|
|
37
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
38
|
+
if (/pixel limit/i.test(message)) {
|
|
39
|
+
const limit = maxPixels === undefined ? 'the default limit' : `${maxPixels} pixels`;
|
|
40
|
+
return `image is larger than ${limit} — raise it with --max-pixels (0 removes the limit)`;
|
|
41
|
+
}
|
|
42
|
+
if (/unsupported image format|corrupt header|bad seek|not a known file format/i.test(message)) {
|
|
43
|
+
return 'not a readable image — the file is corrupt or in an unsupported format';
|
|
44
|
+
}
|
|
45
|
+
if (/premature end|truncated|VipsJpeg|VipsPng|end of stream/i.test(message)) {
|
|
46
|
+
return 'the image file is truncated or damaged';
|
|
47
|
+
}
|
|
48
|
+
return message;
|
|
49
|
+
}
|
|
50
|
+
export async function computeHashes(sharp, input, options) {
|
|
51
|
+
const inputOptions = { failOn: 'truncated' };
|
|
52
|
+
if (options.maxPixels !== undefined) {
|
|
53
|
+
inputOptions.limitInputPixels = options.maxPixels === 0 ? false : options.maxPixels;
|
|
54
|
+
}
|
|
55
|
+
const metadata = await sharp(input, inputOptions).metadata();
|
|
56
|
+
const swapped = (metadata.orientation ?? 1) >= 5;
|
|
57
|
+
const width = (swapped ? metadata.height : metadata.width) ?? 0;
|
|
58
|
+
const height = (swapped ? metadata.width : metadata.height) ?? 0;
|
|
59
|
+
const { data, info } = await sharp(input, inputOptions)
|
|
60
|
+
.rotate()
|
|
61
|
+
.resize({ width: options.size, height: options.size, fit: 'inside', withoutEnlargement: true })
|
|
62
|
+
.toColourspace('srgb')
|
|
63
|
+
.ensureAlpha()
|
|
64
|
+
.raw()
|
|
65
|
+
.toBuffer({ resolveWithObject: true });
|
|
66
|
+
const result = {
|
|
67
|
+
width: width || info.width,
|
|
68
|
+
height: height || info.height,
|
|
69
|
+
};
|
|
70
|
+
if (options.types.includes('blurhash')) {
|
|
71
|
+
const components = resolveComponents(options.components, info.width, info.height);
|
|
72
|
+
result.blurhash = encodeBlurhash(new Uint8ClampedArray(data), info.width, info.height, components.x, components.y);
|
|
73
|
+
}
|
|
74
|
+
const needsThumbhash = options.types.includes('thumbhash') || options.types.includes('preview');
|
|
75
|
+
if (needsThumbhash) {
|
|
76
|
+
const hash = rgbaToThumbHash(info.width, info.height, data);
|
|
77
|
+
if (options.types.includes('thumbhash')) {
|
|
78
|
+
result.thumbhash = Buffer.from(hash).toString('base64');
|
|
79
|
+
}
|
|
80
|
+
if (options.types.includes('preview')) {
|
|
81
|
+
const decoded = thumbHashToRGBA(hash);
|
|
82
|
+
const png = await sharp(decoded.rgba, {
|
|
83
|
+
raw: { width: decoded.w, height: decoded.h, channels: 4 },
|
|
84
|
+
})
|
|
85
|
+
.png({ compressionLevel: 9 })
|
|
86
|
+
.toBuffer();
|
|
87
|
+
result.preview = `data:image/png;base64,${Buffer.from(png).toString('base64')}`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (options.types.includes('color')) {
|
|
91
|
+
const color = dominantColor(data);
|
|
92
|
+
if (color !== undefined)
|
|
93
|
+
result.color = color;
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../src/commands/image-hash/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,iBAAiB,EAAkC,MAAM,WAAW,CAAA;AAmB7E,MAAM,UAAU,aAAa,CAAC,IAAuB;IACnD,MAAM,OAAO,GAAG,IAAI,GAAG,EAA8D,CAAA;IACrF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5C,IA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AAC,CAAA;QACjC,IAAI,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,KAAK,GAAG,KAAK,CAAA;IAC/C,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { banner } from '../../format/vibes.js';
|
|
2
|
+
import { createStyle } from '../../format/style.js';
|
|
3
|
+
import { renderTable } from '../../format/table.js';
|
|
4
|
+
import { ALL_TYPES } from './core.js';
|
|
5
|
+
const TYPE_LABEL = {
|
|
6
|
+
blurhash: 'BlurHash',
|
|
7
|
+
thumbhash: 'ThumbHash',
|
|
8
|
+
color: 'Color',
|
|
9
|
+
preview: 'Preview',
|
|
10
|
+
};
|
|
11
|
+
const PREVIEW_CELL_WIDTH = 28;
|
|
12
|
+
function hashTypesIn(report) {
|
|
13
|
+
return ALL_TYPES.filter((type) => report.entries.some((entry) => entry[type] !== undefined));
|
|
14
|
+
}
|
|
15
|
+
function cellText(type, value) {
|
|
16
|
+
if (value === undefined)
|
|
17
|
+
return '';
|
|
18
|
+
if (type === 'preview' && value.length > PREVIEW_CELL_WIDTH) {
|
|
19
|
+
return `${value.slice(0, PREVIEW_CELL_WIDTH - 1)}…`;
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function imageHashTable(report, options) {
|
|
24
|
+
const s = createStyle(options);
|
|
25
|
+
const types = hashTypesIn(report);
|
|
26
|
+
const typeStyle = {
|
|
27
|
+
blurhash: s.name,
|
|
28
|
+
thumbhash: s.accent,
|
|
29
|
+
color: s.value,
|
|
30
|
+
preview: s.tag,
|
|
31
|
+
};
|
|
32
|
+
const columns = [
|
|
33
|
+
{ header: 'File', shrink: true, style: s.path },
|
|
34
|
+
{ header: 'Size', align: 'right', style: s.tag },
|
|
35
|
+
...types.map((type) => ({ header: TYPE_LABEL[type], style: typeStyle[type] })),
|
|
36
|
+
];
|
|
37
|
+
const rows = report.entries.map((entry) => [
|
|
38
|
+
entry.file,
|
|
39
|
+
`${entry.width}×${entry.height}`,
|
|
40
|
+
...types.map((type) => cellText(type, entry[type])),
|
|
41
|
+
]);
|
|
42
|
+
return renderTable(columns, rows, options);
|
|
43
|
+
}
|
|
44
|
+
export function renderImageHashReport(report, options = {}) {
|
|
45
|
+
const s = createStyle(options);
|
|
46
|
+
const lines = [];
|
|
47
|
+
const isClean = report.errors.length === 0 && report.outdated.length === 0;
|
|
48
|
+
if (options.quiet && isClean)
|
|
49
|
+
return '';
|
|
50
|
+
if (!options.quiet && !options.plain)
|
|
51
|
+
lines.push(banner(options), '');
|
|
52
|
+
if (report.dryRun && report.entries.length > 0) {
|
|
53
|
+
lines.push(...imageHashTable(report, options), '');
|
|
54
|
+
}
|
|
55
|
+
const count = report.entries.length;
|
|
56
|
+
const cachedNote = report.cached > 0 ? `, ${report.cached} from the cache` : '';
|
|
57
|
+
lines.push(s.info(`Hashed ${count} image${count === 1 ? '' : 's'}${cachedNote}.`));
|
|
58
|
+
if (report.check) {
|
|
59
|
+
if (report.outdated.length === 0) {
|
|
60
|
+
lines.push('', s.success(`All ${report.checked} output file${report.checked === 1 ? ' is' : 's are'} up to date.`));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
lines.push('', s.problem(`${report.outdated.length} of ${report.checked} output file${report.checked === 1 ? '' : 's'} out of date:`));
|
|
64
|
+
for (const item of report.outdated) {
|
|
65
|
+
const reason = item.reason === 'missing' ? 'missing' : 'differs from the images';
|
|
66
|
+
lines.push(` ${s.path(item.file)} ${s.muted('—')} ${s.error(reason)}`);
|
|
67
|
+
}
|
|
68
|
+
lines.push('', s.hint('(regenerate them by running the same command without --check)'));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (report.written.length > 0) {
|
|
72
|
+
const verb = report.dryRun ? 'Would write' : 'Wrote';
|
|
73
|
+
const heading = `${verb} ${report.written.length} file${report.written.length === 1 ? '' : 's'}:`;
|
|
74
|
+
lines.push('', report.dryRun ? s.heading(heading) : s.success(heading));
|
|
75
|
+
for (const file of report.written)
|
|
76
|
+
lines.push(` ${s.path(file)}`);
|
|
77
|
+
}
|
|
78
|
+
if (report.pruned > 0) {
|
|
79
|
+
lines.push('', s.info(`Removed ${report.pruned} entr${report.pruned === 1 ? 'y' : 'ies'} whose image no longer exists.`));
|
|
80
|
+
}
|
|
81
|
+
if (report.dryRun) {
|
|
82
|
+
lines.push('', s.hint(report.written.length > 0
|
|
83
|
+
? '(dry run — nothing written; drop --dry-run to write the files)'
|
|
84
|
+
: '(dry run — nothing written)'));
|
|
85
|
+
}
|
|
86
|
+
if (report.errors.length > 0) {
|
|
87
|
+
lines.push('', s.problem(`${report.errors.length} problem${report.errors.length === 1 ? '' : 's'}:`));
|
|
88
|
+
for (const error of report.errors) {
|
|
89
|
+
lines.push(` ${s.path(error.file)} ${s.muted('—')} ${s.error(error.message)}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return lines.join('\n');
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../../src/commands/image-hash/report.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,MAAM,uBAAuB,CAAA;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAoB,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,SAAS,EAAiB,MAAM,WAAW,CAAA;AAGpD,MAAM,UAAU,GAA6B;IAC3C,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;CACnB,CAAA;AAED,MAAM,kBAAkB,GAAG,EAAE,CAAA;AAE7B,SAAS,WAAW,CAAC,MAAuB;IAC1C,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,OAA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,EAAE,EACF,CAAC,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,WAAW,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CACtF,CAAA;QACD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAClC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QACjF,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type Components, type HashEntry, type HashType, type OutputFormat } from './core.js';
|
|
2
|
+
import { type SharpFactory } from './sharp-loader.js';
|
|
3
|
+
export interface ImageHashProgress {
|
|
4
|
+
done: number;
|
|
5
|
+
total: number;
|
|
6
|
+
cached: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ImageHashRunOptions {
|
|
9
|
+
paths: string[];
|
|
10
|
+
cwd: string;
|
|
11
|
+
types: HashType[];
|
|
12
|
+
recursive?: boolean;
|
|
13
|
+
extensions?: string[];
|
|
14
|
+
ignoreGlobs?: string[];
|
|
15
|
+
respectGitignore?: boolean;
|
|
16
|
+
components?: Components;
|
|
17
|
+
size?: number;
|
|
18
|
+
maxPixels?: number;
|
|
19
|
+
format?: OutputFormat;
|
|
20
|
+
exportName?: string;
|
|
21
|
+
out?: string;
|
|
22
|
+
perFile?: boolean;
|
|
23
|
+
outDir?: string;
|
|
24
|
+
suffix?: string;
|
|
25
|
+
outExtension?: string;
|
|
26
|
+
keyBase?: string;
|
|
27
|
+
keyPrefix?: string;
|
|
28
|
+
cache?: string;
|
|
29
|
+
update?: boolean;
|
|
30
|
+
prune?: boolean;
|
|
31
|
+
check?: boolean;
|
|
32
|
+
concurrency?: number;
|
|
33
|
+
assumeYes?: boolean;
|
|
34
|
+
dryRun?: boolean;
|
|
35
|
+
sharp?: SharpFactory;
|
|
36
|
+
onProgress?: (progress: ImageHashProgress) => void;
|
|
37
|
+
}
|
|
38
|
+
export interface ImageHashError {
|
|
39
|
+
file: string;
|
|
40
|
+
message: string;
|
|
41
|
+
}
|
|
42
|
+
export interface OutdatedOutput {
|
|
43
|
+
file: string;
|
|
44
|
+
reason: 'missing' | 'changed';
|
|
45
|
+
}
|
|
46
|
+
export interface ImageHashReport {
|
|
47
|
+
filesScanned: number;
|
|
48
|
+
entries: HashEntry[];
|
|
49
|
+
written: string[];
|
|
50
|
+
errors: ImageHashError[];
|
|
51
|
+
stdout: string | null;
|
|
52
|
+
dryRun: boolean;
|
|
53
|
+
check: boolean;
|
|
54
|
+
checked: number;
|
|
55
|
+
outdated: OutdatedOutput[];
|
|
56
|
+
cached: number;
|
|
57
|
+
pruned: number;
|
|
58
|
+
exitCode: number;
|
|
59
|
+
}
|
|
60
|
+
export declare function runImageHash(options: ImageHashRunOptions): Promise<ImageHashReport>;
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, join, relative, resolve } from 'node:path';
|
|
3
|
+
import { walk } from '../../utils/walk.js';
|
|
4
|
+
import { ALL_TYPES, DEFAULT_BLURHASH_COMPONENTS, DEFAULT_EXPORT_NAME, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SAMPLE_SIZE, ImageHashUsageError, componentsLabel, formatAggregate, formatPerFile, isUrl, normalizeOutExtension, orderTypes, outputFileName, parseAggregate, splitPathArguments, validateExportName, validateSuffix, withUpperCaseVariants, } from './core.js';
|
|
5
|
+
import { cacheHit, emptyCache, loadCache, saveCache } from './cache.js';
|
|
6
|
+
import { computeHashes, friendlyMessage } from './hash.js';
|
|
7
|
+
import { loadSharp } from './sharp-loader.js';
|
|
8
|
+
const DOWNLOAD_TIMEOUT_MS = 30000;
|
|
9
|
+
const MAX_DOWNLOAD_BYTES = 100 * 1024 * 1024;
|
|
10
|
+
function toPosix(path) {
|
|
11
|
+
return path.split('\\').join('/');
|
|
12
|
+
}
|
|
13
|
+
function urlBaseName(url) {
|
|
14
|
+
try {
|
|
15
|
+
const name = basename(decodeURIComponent(new URL(url).pathname));
|
|
16
|
+
return name === '' ? 'image' : name;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return 'image';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function collectImages(options, errors) {
|
|
23
|
+
const extensions = withUpperCaseVariants(options.extensions ?? DEFAULT_IMAGE_EXTENSIONS);
|
|
24
|
+
const images = [];
|
|
25
|
+
const seen = new Set();
|
|
26
|
+
for (const input of splitPathArguments(options.paths)) {
|
|
27
|
+
if (isUrl(input)) {
|
|
28
|
+
if (!seen.has(input)) {
|
|
29
|
+
seen.add(input);
|
|
30
|
+
images.push({ abs: input, root: '', url: true });
|
|
31
|
+
}
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const abs = resolve(options.cwd, input);
|
|
35
|
+
const stat = statSync(abs, { throwIfNoEntry: false });
|
|
36
|
+
if (!stat) {
|
|
37
|
+
errors.push({ file: input, message: 'path does not exist' });
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const root = stat.isDirectory() ? abs : dirname(abs);
|
|
41
|
+
const found = walk([abs], {
|
|
42
|
+
cwd: options.cwd,
|
|
43
|
+
extensions,
|
|
44
|
+
ignoreGlobs: options.ignoreGlobs ?? [],
|
|
45
|
+
recursive: options.recursive ?? false,
|
|
46
|
+
...(options.respectGitignore !== undefined
|
|
47
|
+
? { respectGitignore: options.respectGitignore }
|
|
48
|
+
: {}),
|
|
49
|
+
});
|
|
50
|
+
for (const file of found) {
|
|
51
|
+
if (seen.has(file))
|
|
52
|
+
continue;
|
|
53
|
+
seen.add(file);
|
|
54
|
+
images.push({ abs: file, root, url: false });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return images.sort((a, b) => a.abs.localeCompare(b.abs));
|
|
58
|
+
}
|
|
59
|
+
async function fetchImage(url) {
|
|
60
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS) }).catch((error) => {
|
|
61
|
+
const cause = error.cause;
|
|
62
|
+
const reason = cause?.code ??
|
|
63
|
+
cause?.errors?.[0]?.code ??
|
|
64
|
+
(error instanceof Error ? error.message : String(error));
|
|
65
|
+
throw new Error(`download failed: ${reason}`);
|
|
66
|
+
});
|
|
67
|
+
if (!response.ok)
|
|
68
|
+
throw new Error(`download failed: HTTP ${response.status}`);
|
|
69
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
70
|
+
if (bytes.length > MAX_DOWNLOAD_BYTES)
|
|
71
|
+
throw new Error('download is larger than 100 MB');
|
|
72
|
+
return bytes;
|
|
73
|
+
}
|
|
74
|
+
async function mapWithConcurrency(items, limit, task) {
|
|
75
|
+
const results = new Array(items.length);
|
|
76
|
+
let next = 0;
|
|
77
|
+
const workers = Array.from({ length: Math.max(1, Math.min(limit, items.length)) }, async () => {
|
|
78
|
+
while (next < items.length) {
|
|
79
|
+
const index = next++;
|
|
80
|
+
results[index] = await task(items[index]);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
await Promise.all(workers);
|
|
84
|
+
return results;
|
|
85
|
+
}
|
|
86
|
+
function writeText(path, content) {
|
|
87
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
88
|
+
writeFileSync(path, content);
|
|
89
|
+
}
|
|
90
|
+
function normalizeNewlines(text) {
|
|
91
|
+
return text.replace(/\r\n/g, '\n');
|
|
92
|
+
}
|
|
93
|
+
function pick(computed, key, types) {
|
|
94
|
+
const entry = { file: key, width: computed.width, height: computed.height };
|
|
95
|
+
for (const type of types) {
|
|
96
|
+
const value = computed[type];
|
|
97
|
+
if (value !== undefined)
|
|
98
|
+
entry[type] = value;
|
|
99
|
+
}
|
|
100
|
+
return entry;
|
|
101
|
+
}
|
|
102
|
+
function validate(options, perFile) {
|
|
103
|
+
if (options.out !== undefined && perFile) {
|
|
104
|
+
throw new ImageHashUsageError('--out cannot be combined with --per-file or --out-dir');
|
|
105
|
+
}
|
|
106
|
+
if (options.check) {
|
|
107
|
+
if (options.out === undefined && !perFile) {
|
|
108
|
+
throw new ImageHashUsageError('--check needs the output to compare against: pass -o, --per-file or --out-dir');
|
|
109
|
+
}
|
|
110
|
+
if (options.dryRun)
|
|
111
|
+
throw new ImageHashUsageError('--check cannot be combined with --dry-run');
|
|
112
|
+
if (options.update)
|
|
113
|
+
throw new ImageHashUsageError('--check cannot be combined with --update');
|
|
114
|
+
}
|
|
115
|
+
if (options.update && (options.out === undefined || perFile)) {
|
|
116
|
+
throw new ImageHashUsageError('--update merges into the single file given with -o');
|
|
117
|
+
}
|
|
118
|
+
if (options.prune && !options.update) {
|
|
119
|
+
throw new ImageHashUsageError('--prune only makes sense together with --update');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export async function runImageHash(options) {
|
|
123
|
+
const format = options.format ?? 'json';
|
|
124
|
+
const exportName = validateExportName(options.exportName ?? DEFAULT_EXPORT_NAME);
|
|
125
|
+
const perFile = Boolean(options.perFile) || options.outDir !== undefined;
|
|
126
|
+
const dryRun = Boolean(options.dryRun);
|
|
127
|
+
const check = Boolean(options.check);
|
|
128
|
+
validate(options, perFile);
|
|
129
|
+
const suffix = validateSuffix(options.suffix, options.types, format);
|
|
130
|
+
const outExtension = normalizeOutExtension(options.outExtension, format);
|
|
131
|
+
const size = options.size ?? DEFAULT_SAMPLE_SIZE;
|
|
132
|
+
const components = options.components ?? DEFAULT_BLURHASH_COMPONENTS;
|
|
133
|
+
const params = `${size}|${componentsLabel(components)}`;
|
|
134
|
+
const keyBase = resolve(options.cwd, options.keyBase ?? '.');
|
|
135
|
+
const keyPrefix = options.keyPrefix ?? '';
|
|
136
|
+
const keyOf = (source) => source.url ? source.abs : `${keyPrefix}${toPosix(relative(keyBase, source.abs))}`;
|
|
137
|
+
const errors = [];
|
|
138
|
+
const images = collectImages(options, errors);
|
|
139
|
+
const cachePath = options.cache !== undefined ? resolve(options.cwd, options.cache) : null;
|
|
140
|
+
const cache = cachePath ? loadCache(cachePath) : emptyCache();
|
|
141
|
+
const newRecords = {};
|
|
142
|
+
let sharpPromise = null;
|
|
143
|
+
const loadConfiguredSharp = async () => {
|
|
144
|
+
const loaded = options.sharp ??
|
|
145
|
+
(await loadSharp({ assumeYes: options.assumeYes ?? false, cwd: options.cwd }));
|
|
146
|
+
loaded.cache?.(false);
|
|
147
|
+
return loaded;
|
|
148
|
+
};
|
|
149
|
+
const getSharp = () => {
|
|
150
|
+
if (!sharpPromise)
|
|
151
|
+
sharpPromise = loadConfiguredSharp();
|
|
152
|
+
return sharpPromise;
|
|
153
|
+
};
|
|
154
|
+
const computeOptions = {
|
|
155
|
+
types: options.types,
|
|
156
|
+
size,
|
|
157
|
+
components,
|
|
158
|
+
...(options.maxPixels !== undefined ? { maxPixels: options.maxPixels } : {}),
|
|
159
|
+
};
|
|
160
|
+
let done = 0;
|
|
161
|
+
let cached = 0;
|
|
162
|
+
const total = images.length;
|
|
163
|
+
const entries = [];
|
|
164
|
+
const sources = new Map();
|
|
165
|
+
const results = await mapWithConcurrency(images, options.concurrency ?? 4, async (image) => {
|
|
166
|
+
const key = keyOf(image);
|
|
167
|
+
const display = image.url ? image.abs : toPosix(relative(options.cwd, image.abs));
|
|
168
|
+
try {
|
|
169
|
+
let computed;
|
|
170
|
+
if (image.url) {
|
|
171
|
+
const bytes = await fetchImage(image.abs);
|
|
172
|
+
computed = await computeHashes(await getSharp(), bytes, computeOptions);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
const stat = statSync(image.abs);
|
|
176
|
+
const sig = `${stat.mtimeMs}:${stat.size}`;
|
|
177
|
+
const cacheKey = toPosix(relative(options.cwd, image.abs));
|
|
178
|
+
const previous = cache.files[cacheKey];
|
|
179
|
+
const hit = cachePath ? cacheHit(previous, sig, params, options.types) : null;
|
|
180
|
+
if (hit) {
|
|
181
|
+
computed = hit;
|
|
182
|
+
cached++;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
computed = await computeHashes(await getSharp(), image.abs, computeOptions);
|
|
186
|
+
const base = previous && previous.sig === sig && previous.params === params ? previous : {};
|
|
187
|
+
newRecords[cacheKey] = { ...base, ...computed, sig, params };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return { image, entry: pick(computed, key, options.types) };
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
return { image, error: { file: display, message: friendlyMessage(error, options.maxPixels) } };
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
done++;
|
|
197
|
+
options.onProgress?.({ done, total, cached });
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
for (const result of results) {
|
|
201
|
+
if ('entry' in result) {
|
|
202
|
+
entries.push(result.entry);
|
|
203
|
+
sources.set(result.entry.file, result.image);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
errors.push(result.error);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
entries.sort((a, b) => a.file.localeCompare(b.file));
|
|
210
|
+
const outputs = [];
|
|
211
|
+
let stdout = null;
|
|
212
|
+
let pruned = 0;
|
|
213
|
+
if (perFile) {
|
|
214
|
+
const claimed = new Set();
|
|
215
|
+
const outDirAbs = options.outDir !== undefined ? resolve(options.cwd, options.outDir) : null;
|
|
216
|
+
for (const entry of entries) {
|
|
217
|
+
const source = sources.get(entry.file);
|
|
218
|
+
if (source.url && outDirAbs === null) {
|
|
219
|
+
errors.push({
|
|
220
|
+
file: entry.file,
|
|
221
|
+
message: 'a URL input needs --out-dir for its output file',
|
|
222
|
+
});
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
const targetDir = source.url
|
|
226
|
+
? outDirAbs
|
|
227
|
+
: outDirAbs !== null
|
|
228
|
+
? join(outDirAbs, relative(source.root, dirname(source.abs)))
|
|
229
|
+
: dirname(source.abs);
|
|
230
|
+
const imageName = source.url ? urlBaseName(source.abs) : source.abs;
|
|
231
|
+
for (const unit of formatPerFile(entry, options.types, format)) {
|
|
232
|
+
const target = join(targetDir, outputFileName(imageName, suffix, unit.token, outExtension));
|
|
233
|
+
if (claimed.has(target)) {
|
|
234
|
+
errors.push({ file: entry.file, message: `output ${target} is already taken` });
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
claimed.add(target);
|
|
238
|
+
outputs.push({ path: target, content: unit.content });
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
let outputEntries = entries;
|
|
244
|
+
if (options.update) {
|
|
245
|
+
const target = resolve(options.cwd, options.out);
|
|
246
|
+
const existing = existsSync(target)
|
|
247
|
+
? parseAggregate(readFileSync(target, 'utf8'), format)
|
|
248
|
+
: [];
|
|
249
|
+
const merged = new Map(existing.map((entry) => [entry.file, entry]));
|
|
250
|
+
const freshKeys = new Set(entries.map((entry) => entry.file));
|
|
251
|
+
for (const entry of entries)
|
|
252
|
+
merged.set(entry.file, { ...merged.get(entry.file), ...entry });
|
|
253
|
+
if (options.prune) {
|
|
254
|
+
for (const key of [...merged.keys()]) {
|
|
255
|
+
if (freshKeys.has(key) || isUrl(key))
|
|
256
|
+
continue;
|
|
257
|
+
const local = key.startsWith(keyPrefix) ? key.slice(keyPrefix.length) : key;
|
|
258
|
+
if (!existsSync(resolve(keyBase, local))) {
|
|
259
|
+
merged.delete(key);
|
|
260
|
+
pruned++;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
outputEntries = [...merged.values()].sort((a, b) => a.file.localeCompare(b.file));
|
|
265
|
+
}
|
|
266
|
+
const outputTypes = options.update
|
|
267
|
+
? orderTypes([
|
|
268
|
+
...options.types,
|
|
269
|
+
...outputEntries.flatMap((entry) => ALL_TYPES.filter((type) => entry[type] !== undefined)),
|
|
270
|
+
])
|
|
271
|
+
: options.types;
|
|
272
|
+
const content = formatAggregate(outputEntries, outputTypes, format, exportName);
|
|
273
|
+
if (options.out !== undefined) {
|
|
274
|
+
outputs.push({ path: resolve(options.cwd, options.out), content });
|
|
275
|
+
}
|
|
276
|
+
else if (!dryRun && !check) {
|
|
277
|
+
stdout = content;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const written = [];
|
|
281
|
+
const outdated = [];
|
|
282
|
+
for (const output of outputs) {
|
|
283
|
+
const display = toPosix(relative(options.cwd, output.path));
|
|
284
|
+
if (check) {
|
|
285
|
+
if (!existsSync(output.path)) {
|
|
286
|
+
outdated.push({ file: display, reason: 'missing' });
|
|
287
|
+
}
|
|
288
|
+
else if (normalizeNewlines(readFileSync(output.path, 'utf8')) !== normalizeNewlines(output.content)) {
|
|
289
|
+
outdated.push({ file: display, reason: 'changed' });
|
|
290
|
+
}
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (!dryRun)
|
|
294
|
+
writeText(output.path, output.content);
|
|
295
|
+
written.push(display);
|
|
296
|
+
}
|
|
297
|
+
if (cachePath && !dryRun && !check && Object.keys(newRecords).length > 0) {
|
|
298
|
+
saveCache(cachePath, { version: 1, files: { ...cache.files, ...newRecords } });
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
filesScanned: images.length,
|
|
302
|
+
entries,
|
|
303
|
+
written,
|
|
304
|
+
errors,
|
|
305
|
+
stdout,
|
|
306
|
+
dryRun,
|
|
307
|
+
check,
|
|
308
|
+
checked: check ? outputs.length : 0,
|
|
309
|
+
outdated,
|
|
310
|
+
cached,
|
|
311
|
+
pruned,
|
|
312
|
+
exitCode: errors.length > 0 || outdated.length > 0 ? 1 : 0,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=run.js.map
|