ipx 3.1.0 → 4.0.0-alpha.1
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 +67 -42
- package/dist/_chunks/libs/@fastify/accept-negotiator.mjs +1 -0
- package/dist/_chunks/libs/boolbase.mjs +1 -0
- package/dist/_chunks/libs/css-select.mjs +6 -0
- package/dist/_chunks/libs/css-tree.mjs +126 -0
- package/dist/_chunks/libs/csso.mjs +3 -0
- package/dist/_chunks/libs/etag.mjs +1 -0
- package/dist/_chunks/libs/h3.mjs +2 -0
- package/dist/_chunks/libs/image-meta.mjs +3 -0
- package/dist/_chunks/libs/sax.mjs +10 -0
- package/dist/_chunks/libs/svgo.mjs +78 -0
- package/dist/_chunks/libs/ufo.mjs +1 -0
- package/dist/_chunks/node-fs.mjs +728 -0
- package/dist/_chunks/rolldown-runtime.mjs +46 -0
- package/dist/_chunks/svgo-node.mjs +11 -0
- package/dist/cli.d.mts +1 -2
- package/dist/cli.mjs +76 -58
- package/dist/index.d.mts +226 -320
- package/dist/index.mjs +44 -48
- package/package.json +43 -48
- package/bin/ipx.mjs +0 -2
- package/dist/cli.cjs +0 -63
- package/dist/cli.d.cts +0 -2
- package/dist/cli.d.ts +0 -2
- package/dist/index.cjs +0 -62
- package/dist/index.d.cts +0 -397
- package/dist/index.d.ts +0 -397
- package/dist/shared/ipx.C8X6338M.mjs +0 -764
- package/dist/shared/ipx.CHfn1B1U.cjs +0 -778
package/dist/index.mjs
CHANGED
|
@@ -1,52 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import 'destr';
|
|
7
|
-
import '@fastify/accept-negotiator';
|
|
8
|
-
import 'etag';
|
|
9
|
-
import 'ofetch';
|
|
10
|
-
import 'pathe';
|
|
1
|
+
import "./_chunks/rolldown-runtime.mjs";
|
|
2
|
+
import { t as HTTPError } from "./_chunks/libs/h3.mjs";
|
|
3
|
+
import { a as serveIPX, i as createIPXNodeHandler, n as ipxHttpStorage, o as createIPX, r as createIPXFetchHandler, t as ipxFSStorage } from "./_chunks/node-fs.mjs";
|
|
4
|
+
import "./_chunks/libs/etag.mjs";
|
|
5
|
+
import "./_chunks/libs/@fastify/accept-negotiator.mjs";
|
|
11
6
|
|
|
7
|
+
//#region src/storage/unstorage.ts
|
|
8
|
+
/**
|
|
9
|
+
* Adapts an Unstorage driver or storage system to comply with the IPXStorage interface required by IPX.
|
|
10
|
+
* This allows various Unstorage-compatible storage systems to be used to manage image data with IPX.
|
|
11
|
+
*
|
|
12
|
+
* @param {Storage | Driver} storage - The Unstorage driver or storage instance to adapt. See {@link Storage} and {@link Driver}.
|
|
13
|
+
* @param {UnstorageIPXStorageOptions | string} [_options={}] - Configuration options for the adapter, which can be a simple string prefix or an options object. See {@link UnstorageIPXStorageOptions}.
|
|
14
|
+
* @returns {IPXStorage}. An IPXStorage compliant object that implements the necessary methods to interact with the provided unstorage driver or storage system. See {@link IPXStorage}.
|
|
15
|
+
* @throws {H3Error} If there is a problem retrieving or converting the storage data, detailed error information is thrown. See {@link H3Error}.
|
|
16
|
+
*/
|
|
12
17
|
function unstorageToIPXStorage(storage, _options = {}) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
throw createError({
|
|
41
|
-
statusCode: 500,
|
|
42
|
-
statusText: `IPX_STORAGE_ERROR`,
|
|
43
|
-
message: `Failed to parse storage data to Buffer:
|
|
44
|
-
${error.message}`,
|
|
45
|
-
cause: error
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
18
|
+
const options = typeof _options === "string" ? { prefix: _options } : _options;
|
|
19
|
+
const resolveKey = (id) => options.prefix ? `${options.prefix}:${id}` : id;
|
|
20
|
+
return {
|
|
21
|
+
name: "ipx:" + (storage.name || "unstorage"),
|
|
22
|
+
async getMeta(id, opts = {}) {
|
|
23
|
+
if (!storage.getMeta) return;
|
|
24
|
+
const storageKey = resolveKey(id);
|
|
25
|
+
return await storage.getMeta(storageKey, opts);
|
|
26
|
+
},
|
|
27
|
+
async getData(id, opts = {}) {
|
|
28
|
+
if (!storage.getItemRaw) return;
|
|
29
|
+
const storageKey = resolveKey(id);
|
|
30
|
+
let data = await storage.getItemRaw(storageKey, opts);
|
|
31
|
+
if (!data) return;
|
|
32
|
+
if (data instanceof Blob) data = await data.arrayBuffer();
|
|
33
|
+
try {
|
|
34
|
+
return Buffer.from(data);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
throw new HTTPError({
|
|
37
|
+
statusCode: 500,
|
|
38
|
+
statusText: `IPX_STORAGE_ERROR`,
|
|
39
|
+
message: `Failed to parse storage data to Buffer:\n${error.message}`,
|
|
40
|
+
cause: error
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
50
45
|
}
|
|
51
46
|
|
|
52
|
-
|
|
47
|
+
//#endregion
|
|
48
|
+
export { createIPX, createIPXFetchHandler, createIPXNodeHandler, ipxFSStorage, ipxHttpStorage, serveIPX, unstorageToIPXStorage };
|
package/package.json
CHANGED
|
@@ -1,71 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ipx",
|
|
3
|
-
"version": "
|
|
4
|
-
"repository": "unjs/ipx",
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
5
4
|
"description": "High performance, secure and easy-to-use image optimizer.",
|
|
5
|
+
"repository": "unjs/ipx",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"type": "module",
|
|
7
9
|
"exports": {
|
|
8
|
-
".":
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"types": "./dist/index.d.cts",
|
|
15
|
-
"default": "./dist/index.cjs"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
".": "./dist/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"types": "./dist/index.d.mts",
|
|
14
|
+
"bin": {
|
|
15
|
+
"ipx": "./dist/cli.mjs"
|
|
18
16
|
},
|
|
19
|
-
"main": "./dist/index.cjs",
|
|
20
|
-
"module": "./dist/index.mjs",
|
|
21
|
-
"types": "./dist/index.d.ts",
|
|
22
|
-
"bin": "./bin/ipx.mjs",
|
|
23
17
|
"files": [
|
|
24
|
-
"dist"
|
|
25
|
-
"bin"
|
|
18
|
+
"dist"
|
|
26
19
|
],
|
|
27
20
|
"scripts": {
|
|
28
|
-
"build": "
|
|
29
|
-
"
|
|
30
|
-
"ipx": "jiti ./src/cli.ts",
|
|
21
|
+
"build": "obuild",
|
|
22
|
+
"ipx": "node ./src/cli.ts",
|
|
31
23
|
"lint": "eslint . && prettier -c src test",
|
|
32
|
-
"lint:fix": "eslint . --fix && prettier -w src test",
|
|
24
|
+
"lint:fix": "automd && eslint . --fix && prettier -w src test",
|
|
33
25
|
"prepack": "pnpm build",
|
|
34
|
-
"release": "pnpm test && changelogen --release --
|
|
26
|
+
"release": "pnpm test && pnpm build && changelogen --release --prerelease --publish --publishTag alpha --push",
|
|
35
27
|
"start": "node bin/ipx.js",
|
|
36
|
-
"test": "pnpm lint && vitest run --coverage"
|
|
28
|
+
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
|
|
29
|
+
"test:types": "tsc --noEmit"
|
|
37
30
|
},
|
|
38
31
|
"dependencies": {
|
|
39
|
-
"@fastify/accept-negotiator": "^2.0.1",
|
|
40
|
-
"citty": "^0.1.6",
|
|
41
|
-
"consola": "^3.4.2",
|
|
42
|
-
"defu": "^6.1.4",
|
|
43
|
-
"destr": "^2.0.5",
|
|
44
|
-
"etag": "^1.8.1",
|
|
45
|
-
"h3": "^1.15.3",
|
|
46
|
-
"image-meta": "^0.2.1",
|
|
47
|
-
"listhen": "^1.9.0",
|
|
48
|
-
"ofetch": "^1.4.1",
|
|
49
32
|
"pathe": "^2.0.3",
|
|
50
|
-
"sharp": "^0.34.
|
|
51
|
-
"
|
|
52
|
-
"ufo": "^1.6.1",
|
|
53
|
-
"unstorage": "^1.16.1",
|
|
54
|
-
"xss": "^1.0.15"
|
|
33
|
+
"sharp": "^0.34.5",
|
|
34
|
+
"srvx": "^0.9.7"
|
|
55
35
|
},
|
|
56
36
|
"devDependencies": {
|
|
37
|
+
"@fastify/accept-negotiator": "^2.0.1",
|
|
57
38
|
"@types/etag": "^1.8.4",
|
|
58
39
|
"@types/is-valid-path": "^0.1.2",
|
|
59
|
-
"@vitest/coverage-v8": "^
|
|
40
|
+
"@vitest/coverage-v8": "^4.0.15",
|
|
41
|
+
"automd": "^0.4.2",
|
|
60
42
|
"changelogen": "^0.6.2",
|
|
61
|
-
"eslint": "^9.
|
|
43
|
+
"eslint": "^9.39.1",
|
|
62
44
|
"eslint-config-unjs": "^0.5.0",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
45
|
+
"etag": "^1.8.1",
|
|
46
|
+
"h3": "^2.0.1-rc.5",
|
|
47
|
+
"image-meta": "^0.2.2",
|
|
48
|
+
"obuild": "^0.4.7",
|
|
49
|
+
"oxc-minify": "^0.101.0",
|
|
50
|
+
"prettier": "^3.7.4",
|
|
51
|
+
"svgo": "^4.0.0",
|
|
52
|
+
"typescript": "^5.9.3",
|
|
53
|
+
"ufo": "^1.6.1",
|
|
54
|
+
"unstorage": "^1.17.3",
|
|
55
|
+
"vitest": "^4.0.15"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"unstorage": "*"
|
|
59
|
+
},
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"unstorage": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
69
64
|
},
|
|
70
|
-
"packageManager": "pnpm@10.
|
|
65
|
+
"packageManager": "pnpm@10.24.0"
|
|
71
66
|
}
|
package/bin/ipx.mjs
DELETED
package/dist/cli.cjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const listhen = require('listhen');
|
|
4
|
-
const citty = require('citty');
|
|
5
|
-
const cli = require('listhen/cli');
|
|
6
|
-
const nodeFs = require('./shared/ipx.CHfn1B1U.cjs');
|
|
7
|
-
require('defu');
|
|
8
|
-
require('ufo');
|
|
9
|
-
require('h3');
|
|
10
|
-
require('image-meta');
|
|
11
|
-
require('destr');
|
|
12
|
-
require('@fastify/accept-negotiator');
|
|
13
|
-
require('etag');
|
|
14
|
-
require('ofetch');
|
|
15
|
-
require('pathe');
|
|
16
|
-
|
|
17
|
-
const name = "ipx";
|
|
18
|
-
const version = "3.1.0";
|
|
19
|
-
const description = "High performance, secure and easy-to-use image optimizer.";
|
|
20
|
-
|
|
21
|
-
const serve = citty.defineCommand({
|
|
22
|
-
meta: {
|
|
23
|
-
description: "Start IPX Server"
|
|
24
|
-
},
|
|
25
|
-
args: {
|
|
26
|
-
dir: {
|
|
27
|
-
type: "string",
|
|
28
|
-
required: false,
|
|
29
|
-
description: "Directory to serve (default: current directory) ENV: IPX_FS_DIR"
|
|
30
|
-
},
|
|
31
|
-
domains: {
|
|
32
|
-
type: "string",
|
|
33
|
-
required: false,
|
|
34
|
-
description: "Allowed domains (comma separated) ENV: IPX_HTTP_DOMAINS"
|
|
35
|
-
},
|
|
36
|
-
...cli.getArgs()
|
|
37
|
-
},
|
|
38
|
-
async run({ args }) {
|
|
39
|
-
const ipx = nodeFs.createIPX({
|
|
40
|
-
storage: nodeFs.ipxFSStorage({
|
|
41
|
-
dir: args.dir
|
|
42
|
-
}),
|
|
43
|
-
httpStorage: nodeFs.ipxHttpStorage({
|
|
44
|
-
domains: args.domains
|
|
45
|
-
})
|
|
46
|
-
});
|
|
47
|
-
await listhen.listen(nodeFs.createIPXNodeServer(ipx), {
|
|
48
|
-
name: "IPX",
|
|
49
|
-
...cli.parseArgs(args)
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const main = citty.defineCommand({
|
|
54
|
-
meta: {
|
|
55
|
-
name,
|
|
56
|
-
version,
|
|
57
|
-
description
|
|
58
|
-
},
|
|
59
|
-
subCommands: {
|
|
60
|
-
serve
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
citty.runMain(main);
|
package/dist/cli.d.cts
DELETED
package/dist/cli.d.ts
DELETED
package/dist/index.cjs
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const nodeFs = require('./shared/ipx.CHfn1B1U.cjs');
|
|
4
|
-
const h3 = require('h3');
|
|
5
|
-
require('defu');
|
|
6
|
-
require('ufo');
|
|
7
|
-
require('image-meta');
|
|
8
|
-
require('destr');
|
|
9
|
-
require('@fastify/accept-negotiator');
|
|
10
|
-
require('etag');
|
|
11
|
-
require('ofetch');
|
|
12
|
-
require('pathe');
|
|
13
|
-
|
|
14
|
-
function unstorageToIPXStorage(storage, _options = {}) {
|
|
15
|
-
const options = typeof _options === "string" ? { prefix: _options } : _options;
|
|
16
|
-
const resolveKey = (id) => options.prefix ? `${options.prefix}:${id}` : id;
|
|
17
|
-
return {
|
|
18
|
-
name: "ipx:" + (storage.name || "unstorage"),
|
|
19
|
-
async getMeta(id, opts = {}) {
|
|
20
|
-
if (!storage.getMeta) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const storageKey = resolveKey(id);
|
|
24
|
-
const meta = await storage.getMeta(storageKey, opts);
|
|
25
|
-
return meta;
|
|
26
|
-
},
|
|
27
|
-
async getData(id, opts = {}) {
|
|
28
|
-
if (!storage.getItemRaw) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const storageKey = resolveKey(id);
|
|
32
|
-
let data = await storage.getItemRaw(storageKey, opts);
|
|
33
|
-
if (!data) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (data instanceof Blob) {
|
|
37
|
-
data = await data.arrayBuffer();
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
return Buffer.from(data);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
throw h3.createError({
|
|
43
|
-
statusCode: 500,
|
|
44
|
-
statusText: `IPX_STORAGE_ERROR`,
|
|
45
|
-
message: `Failed to parse storage data to Buffer:
|
|
46
|
-
${error.message}`,
|
|
47
|
-
cause: error
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
exports.createIPX = nodeFs.createIPX;
|
|
55
|
-
exports.createIPXH3App = nodeFs.createIPXH3App;
|
|
56
|
-
exports.createIPXH3Handler = nodeFs.createIPXH3Handler;
|
|
57
|
-
exports.createIPXNodeServer = nodeFs.createIPXNodeServer;
|
|
58
|
-
exports.createIPXPlainServer = nodeFs.createIPXPlainServer;
|
|
59
|
-
exports.createIPXWebServer = nodeFs.createIPXWebServer;
|
|
60
|
-
exports.ipxFSStorage = nodeFs.ipxFSStorage;
|
|
61
|
-
exports.ipxHttpStorage = nodeFs.ipxHttpStorage;
|
|
62
|
-
exports.unstorageToIPXStorage = unstorageToIPXStorage;
|