@ecopages/image-processor 0.6.1 → 0.7.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 +2 -2
- package/package.json +7 -4
- package/src/image-plugins.d.ts +1 -5
- package/src/image-plugins.js +1 -21
- package/src/image-processor.js +4 -3
- package/src/image-public-src.d.ts +9 -0
- package/src/image-public-src.js +12 -0
- package/src/image-runtime-state.js +1 -1
- package/src/plugin.js +3 -9
package/README.md
CHANGED
|
@@ -33,8 +33,8 @@ const imageProcessor = new ImageProcessorPlugin({
|
|
|
33
33
|
name: 'ecopages-image-processor',
|
|
34
34
|
type: 'image',
|
|
35
35
|
options: {
|
|
36
|
-
sourceDir: path.resolve(
|
|
37
|
-
outputDir: path.resolve(
|
|
36
|
+
sourceDir: path.resolve(process.cwd(), 'src/images'),
|
|
37
|
+
outputDir: path.resolve(process.cwd(), 'dist/client/images'),
|
|
38
38
|
publicPath: '/images',
|
|
39
39
|
acceptedFormats: ['jpg', 'jpeg', 'png', 'webp'],
|
|
40
40
|
quality: 80,
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/image-processor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Image processor, transform and optimize images for web",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"image",
|
|
7
7
|
"processor"
|
|
8
8
|
],
|
|
9
9
|
"license": "MIT",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": "^24.22.0 || >=26.0.0"
|
|
12
|
+
},
|
|
10
13
|
"main": "./src/image-processor.js",
|
|
11
14
|
"type": "module",
|
|
12
15
|
"publishConfig": {
|
|
@@ -18,8 +21,8 @@
|
|
|
18
21
|
"directory": "packages/processors/image-processor"
|
|
19
22
|
},
|
|
20
23
|
"peerDependencies": {
|
|
21
|
-
"@ecopages/core": "0.
|
|
22
|
-
"@ecopages/jsx": "^0.
|
|
24
|
+
"@ecopages/core": "0.7.0",
|
|
25
|
+
"@ecopages/jsx": "^0.8.2"
|
|
23
26
|
},
|
|
24
27
|
"peerDependenciesMeta": {
|
|
25
28
|
"@ecopages/jsx": {
|
|
@@ -27,7 +30,7 @@
|
|
|
27
30
|
}
|
|
28
31
|
},
|
|
29
32
|
"dependencies": {
|
|
30
|
-
"@ecopages/file-system": "0.
|
|
33
|
+
"@ecopages/file-system": "0.7.0",
|
|
31
34
|
"@ecopages/logger": "^0.2.3",
|
|
32
35
|
"react": "^19.2.6",
|
|
33
36
|
"sharp": "^0.35.3"
|
package/src/image-plugins.d.ts
CHANGED
|
@@ -7,11 +7,7 @@ import type { ImageMap } from './plugin.js';
|
|
|
7
7
|
/** Fills the image map before the module is loaded. */
|
|
8
8
|
type EnsureImagesReady = () => Promise<void>;
|
|
9
9
|
/**
|
|
10
|
-
* Declares `ecopages:images` as a virtual module for server builds.
|
|
10
|
+
* Declares `ecopages:images` as a virtual module for server and browser builds.
|
|
11
11
|
*/
|
|
12
12
|
export declare function createImagePlugin(exports: ImageMap, ensureReady: EnsureImagesReady): EcoBuildPlugin;
|
|
13
|
-
/**
|
|
14
|
-
* Resolves `ecopages:images` with `onResolve` and `onLoad` for browser builds.
|
|
15
|
-
*/
|
|
16
|
-
export declare function createImagePluginBundler(exports: ImageMap, ensureReady: EnsureImagesReady): EcoBuildPlugin;
|
|
17
13
|
export {};
|
package/src/image-plugins.js
CHANGED
|
@@ -15,7 +15,7 @@ function createPluginResult(exports) {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* Declares `ecopages:images` as a virtual module for server builds.
|
|
18
|
+
* Declares `ecopages:images` as a virtual module for server and browser builds.
|
|
19
19
|
*/
|
|
20
20
|
export function createImagePlugin(exports, ensureReady) {
|
|
21
21
|
return {
|
|
@@ -28,23 +28,3 @@ export function createImagePlugin(exports, ensureReady) {
|
|
|
28
28
|
},
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Resolves `ecopages:images` with `onResolve` and `onLoad` for browser builds.
|
|
33
|
-
*/
|
|
34
|
-
export function createImagePluginBundler(exports, ensureReady) {
|
|
35
|
-
return {
|
|
36
|
-
name: 'ecopages:images',
|
|
37
|
-
setup(build) {
|
|
38
|
-
build.onResolve({ filter: /^ecopages:images$/ }, () => {
|
|
39
|
-
return {
|
|
40
|
-
namespace: 'ecopages-images',
|
|
41
|
-
path: 'ecopages:images',
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
build.onLoad({ filter: /.*/, namespace: 'ecopages-images' }, async () => {
|
|
45
|
-
await ensureReady();
|
|
46
|
-
return createPluginResult(exports);
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
}
|
package/src/image-processor.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import path from '
|
|
1
|
+
import { path } from '@ecopages/file-system/path';
|
|
2
2
|
import { writeHashedBrowserAsset } from '@ecopages/core/processor';
|
|
3
3
|
import { mergeProcessorOptions } from '@ecopages/core/processor';
|
|
4
4
|
import { fileSystem } from '@ecopages/file-system';
|
|
5
5
|
import { Logger } from '@ecopages/logger';
|
|
6
6
|
import { isEcopagesEnvEnabled } from '@ecopages/core/processor';
|
|
7
7
|
import sharp, {} from 'sharp';
|
|
8
|
+
import { toPublicImageSrc } from './image-public-src.js';
|
|
8
9
|
import { ImageUtils } from './image-utils.js';
|
|
9
10
|
const appLogger = new Logger('[@ecopages/image-processor]', {
|
|
10
11
|
debug: isEcopagesEnvEnabled('ECOPAGES_LOGGER_DEBUG'),
|
|
@@ -72,7 +73,7 @@ export class ImageProcessor {
|
|
|
72
73
|
.toFormat(this.config.format, { quality: this.config.quality })
|
|
73
74
|
.toBuffer();
|
|
74
75
|
const outputPath = this.writeEncodedVariant(encoded);
|
|
75
|
-
const src =
|
|
76
|
+
const src = toPublicImageSrc(this.config.publicPath, outputPath);
|
|
76
77
|
const imageSpecifications = {
|
|
77
78
|
attributes: {
|
|
78
79
|
src,
|
|
@@ -101,7 +102,7 @@ export class ImageProcessor {
|
|
|
101
102
|
.toFormat(this.config.format, { quality: this.config.quality })
|
|
102
103
|
.toBuffer();
|
|
103
104
|
const outputPath = this.writeEncodedVariant(encoded);
|
|
104
|
-
const src =
|
|
105
|
+
const src = toPublicImageSrc(this.config.publicPath, outputPath);
|
|
105
106
|
return {
|
|
106
107
|
width,
|
|
107
108
|
height,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public URL of an optimized file written under the output directory.
|
|
3
|
+
*
|
|
4
|
+
* @param outputPath - Native filesystem path of the written file.
|
|
5
|
+
* @remarks
|
|
6
|
+
* Joins with `/` on every platform: `path.join` would give a backslash URL on Windows. Kept apart from
|
|
7
|
+
* `image-utils.ts`, which client code imports and so cannot use `node:path`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function toPublicImageSrc(publicPath: string, outputPath: string): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { path } from '@ecopages/file-system/path';
|
|
2
|
+
/**
|
|
3
|
+
* Public URL of an optimized file written under the output directory.
|
|
4
|
+
*
|
|
5
|
+
* @param outputPath - Native filesystem path of the written file.
|
|
6
|
+
* @remarks
|
|
7
|
+
* Joins with `/` on every platform: `path.join` would give a backslash URL on Windows. Kept apart from
|
|
8
|
+
* `image-utils.ts`, which client code imports and so cannot use `node:path`.
|
|
9
|
+
*/
|
|
10
|
+
export function toPublicImageSrc(publicPath, outputPath) {
|
|
11
|
+
return path.join(publicPath, path.basename(outputPath));
|
|
12
|
+
}
|
package/src/plugin.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* ImageProcessorPlugin
|
|
3
3
|
* @module @ecopages/image-processor
|
|
4
4
|
*/
|
|
5
|
-
import path from '
|
|
5
|
+
import { path } from '@ecopages/file-system/path';
|
|
6
6
|
import { fileSystem } from '@ecopages/file-system';
|
|
7
7
|
import { mergeProcessorOptions, Processor, resolveGeneratedPath, writeGeneratedTypesPackage, } from '@ecopages/core/processor';
|
|
8
8
|
import { Logger } from '@ecopages/logger';
|
|
9
9
|
import { isEcopagesEnvEnabled } from '@ecopages/core/processor';
|
|
10
|
-
import { createImagePlugin
|
|
10
|
+
import { createImagePlugin } from './image-plugins.js';
|
|
11
11
|
import { ImageProcessor } from './image-processor.js';
|
|
12
12
|
import { getOutputSources, getSourceImagePaths, loadProcessedImagesFromDisk, } from './image-runtime-state.js';
|
|
13
13
|
import { anyCaseToCamelCase } from './utils.js';
|
|
@@ -98,13 +98,7 @@ export class ImageProcessorPlugin extends Processor {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
plugins() {
|
|
101
|
-
return [
|
|
102
|
-
{ ...createImagePlugin(this.processedImages, () => this.ensurePrepared()), environments: ['server'] },
|
|
103
|
-
{
|
|
104
|
-
...createImagePluginBundler(this.processedImages, () => this.ensurePrepared()),
|
|
105
|
-
environments: ['browser'],
|
|
106
|
-
},
|
|
107
|
-
];
|
|
101
|
+
return [createImagePlugin(this.processedImages, () => this.ensurePrepared())];
|
|
108
102
|
}
|
|
109
103
|
/**
|
|
110
104
|
* Replaces image-map contents without swapping the backing object.
|