cloudflare-next-intl 0.8.54 → 0.8.55
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.
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { run } from "../dist/src/image_optimizer/run.js";
|
|
4
|
+
import { resolveOptions } from "../dist/src/image_optimizer/types.js";
|
|
5
|
+
|
|
6
|
+
const root = process.cwd();
|
|
7
|
+
const options = resolveOptions();
|
|
8
|
+
const cacheFile = path.resolve(root, options.cacheDir, "manifest.json");
|
|
9
|
+
|
|
10
|
+
console.log("[cfni-image-optimizer] scanning images in", options.dirs.join(", "));
|
|
11
|
+
const entries = await run(root, options, cacheFile);
|
|
12
|
+
console.log(`[cfni-image-optimizer] processed ${entries.length} images into ${options.outDir}`);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { OptimizedImage, ResolvedOptions } from "./types.js";
|
|
2
2
|
export declare function collectImages(dirs: string[], root: string): Promise<string[]>;
|
|
3
|
-
export declare function run(root: string, options: ResolvedOptions, cacheFile
|
|
3
|
+
export declare function run(root: string, options: ResolvedOptions, cacheFile?: string): Promise<OptimizedImage[]>;
|
|
@@ -41,27 +41,33 @@ function targetAndSiblingPaths(absolutePath, publicRoot, options, root) {
|
|
|
41
41
|
}
|
|
42
42
|
return result;
|
|
43
43
|
}
|
|
44
|
-
export async function run(root, options, cacheFile) {
|
|
45
|
-
const publicRoot = path.
|
|
46
|
-
const
|
|
44
|
+
export async function run(root, options, cacheFile = path.resolve(root, options.cacheDir, "manifest.json")) {
|
|
45
|
+
const publicRoot = path.resolve(root, "public");
|
|
46
|
+
const manifestPath = path.resolve(root, options.manifest);
|
|
47
47
|
const cache = await loadCache(cacheFile);
|
|
48
|
-
const
|
|
48
|
+
const nextCache = {};
|
|
49
|
+
const files = await collectImages(options.dirs, root);
|
|
49
50
|
const entries = [];
|
|
50
51
|
for (const file of files) {
|
|
51
|
-
const
|
|
52
|
-
const cached = cache[
|
|
52
|
+
const relativeKey = path.relative(root, file);
|
|
53
|
+
const cached = cache[relativeKey];
|
|
53
54
|
const targets = targetAndSiblingPaths(file, publicRoot, options, root);
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const fresh = await isFresh(file, cached, targets);
|
|
56
|
+
if (fresh && cached) {
|
|
56
57
|
entries.push(cached.result);
|
|
58
|
+
nextCache[relativeKey] = cached;
|
|
57
59
|
continue;
|
|
58
60
|
}
|
|
59
61
|
const result = await processImage(file, publicRoot, options, root);
|
|
60
|
-
const
|
|
61
|
-
next[key] = { mtimeMs: stats.mtimeMs, size: stats.size, result };
|
|
62
|
+
const fileStat = await stat(file);
|
|
62
63
|
entries.push(result);
|
|
64
|
+
nextCache[relativeKey] = {
|
|
65
|
+
mtimeMs: fileStat.mtimeMs,
|
|
66
|
+
size: fileStat.size,
|
|
67
|
+
result,
|
|
68
|
+
};
|
|
63
69
|
}
|
|
64
|
-
await saveCache(cacheFile,
|
|
65
|
-
await writeManifest(
|
|
70
|
+
await saveCache(cacheFile, nextCache);
|
|
71
|
+
await writeManifest(manifestPath, entries);
|
|
66
72
|
return entries;
|
|
67
73
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudflare-next-intl",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.55",
|
|
4
4
|
"description": "Optimized Next Intl Package Special for App Router and Cloudflare",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"sideEffects": false,
|
|
8
9
|
"bin": {
|
|
9
10
|
"cfni-db-codegen": "bin/db_codegen.mjs",
|
|
10
|
-
"cfni-db-install-exec": "bin/db_install_exec.mjs"
|
|
11
|
+
"cfni-db-install-exec": "bin/db_install_exec.mjs",
|
|
12
|
+
"cfni-image-optimizer": "bin/image_optimizer.mjs",
|
|
13
|
+
"optimize-images": "bin/image_optimizer.mjs"
|
|
11
14
|
},
|
|
12
15
|
"files": [
|
|
13
16
|
"dist",
|