@ecopages/image-processor 0.2.0-beta.6 → 0.2.0-beta.8
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/package.json +3 -3
- package/src/image-processor.js +2 -2
- package/src/plugin.d.ts +1 -0
- package/src/plugin.js +17 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/image-processor",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.8",
|
|
4
4
|
"description": "Image processor, transform and optimize images for web",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"image",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"directory": "packages/processors/image-processor"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@ecopages/core": "0.2.0-beta.
|
|
18
|
+
"@ecopages/core": "0.2.0-beta.8"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@ecopages/file-system": "0.2.0-beta.
|
|
21
|
+
"@ecopages/file-system": "0.2.0-beta.8",
|
|
22
22
|
"@ecopages/logger": "^0.2.3",
|
|
23
23
|
"react": "^19.2.6",
|
|
24
24
|
"react-dom": "^19.2.6",
|
package/src/image-processor.js
CHANGED
|
@@ -37,10 +37,10 @@ class ImageProcessor {
|
|
|
37
37
|
if (this.config.cacheEnabled) {
|
|
38
38
|
const cached = await this.cacheManager.readCache(cacheKey);
|
|
39
39
|
if (cached) {
|
|
40
|
-
const mainFilePath = path.join(
|
|
40
|
+
const mainFilePath = path.join(this.config.outputDir, path.basename(cached.attributes.src));
|
|
41
41
|
const mainFileExists = fileSystem.exists(mainFilePath);
|
|
42
42
|
const variantsExist = cached.variants.every(
|
|
43
|
-
(
|
|
43
|
+
(variant) => fileSystem.exists(path.join(this.config.outputDir, path.basename(variant.src)))
|
|
44
44
|
);
|
|
45
45
|
if (mainFileExists && variantsExist) {
|
|
46
46
|
appLogger.debug(`Cache hit for ${imagePath}`);
|
package/src/plugin.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export declare class ImageProcessorPlugin extends Processor<ImageProcessorConfig
|
|
|
61
61
|
private getRuntimeVirtualModulePath;
|
|
62
62
|
private getGeneratedOutputPath;
|
|
63
63
|
private hasGeneratedOutputs;
|
|
64
|
+
private writeGeneratedFile;
|
|
64
65
|
private rehydrateGeneratedOutputs;
|
|
65
66
|
/**
|
|
66
67
|
* Generate dependencies for processor.
|
package/src/plugin.js
CHANGED
|
@@ -117,6 +117,10 @@ class ImageProcessorPlugin extends Processor {
|
|
|
117
117
|
if (this.buildContributionsPrepared) {
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
|
+
if (process.env.ECOPAGES_LIT_STATIC_RENDER_WORKER === "true") {
|
|
121
|
+
this.buildContributionsPrepared = true;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
120
124
|
if (!this.context) {
|
|
121
125
|
throw new Error("ImageProcessor requires context to be set");
|
|
122
126
|
}
|
|
@@ -174,6 +178,13 @@ class ImageProcessorPlugin extends Processor {
|
|
|
174
178
|
return outputPaths.every((src) => fileSystem.exists(this.getGeneratedOutputPath(src)));
|
|
175
179
|
});
|
|
176
180
|
}
|
|
181
|
+
writeGeneratedFile(filePath, content) {
|
|
182
|
+
fileSystem.ensureDir(path.dirname(filePath));
|
|
183
|
+
if (fileSystem.exists(filePath) && fileSystem.readFileSync(filePath) === content) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
fileSystem.write(filePath, content);
|
|
187
|
+
}
|
|
177
188
|
async rehydrateGeneratedOutputs() {
|
|
178
189
|
if (!this.processor) {
|
|
179
190
|
throw new Error("ImageProcessor not initialized");
|
|
@@ -200,6 +211,9 @@ class ImageProcessorPlugin extends Processor {
|
|
|
200
211
|
* Prepares build contributions if not already done and rehydrates previously generated image outputs.
|
|
201
212
|
*/
|
|
202
213
|
async setup() {
|
|
214
|
+
if (process.env.ECOPAGES_LIT_STATIC_RENDER_WORKER === "true") {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
203
217
|
await this.prepareBuildContributions();
|
|
204
218
|
await this.rehydrateGeneratedOutputs();
|
|
205
219
|
}
|
|
@@ -288,8 +302,7 @@ declare module "ecopages:images" {
|
|
|
288
302
|
module: this.name,
|
|
289
303
|
subPath: "virtual-module.d.ts"
|
|
290
304
|
});
|
|
291
|
-
|
|
292
|
-
fileSystem.write(typesDir, content);
|
|
305
|
+
this.writeGeneratedFile(typesDir, content);
|
|
293
306
|
logger.debug("Generated types for virtual module", { typesDir });
|
|
294
307
|
const indexTypesDir = resolveGeneratedPath("types", {
|
|
295
308
|
root: this.context.rootDir,
|
|
@@ -297,7 +310,7 @@ declare module "ecopages:images" {
|
|
|
297
310
|
subPath: "index.d.ts"
|
|
298
311
|
});
|
|
299
312
|
const indexContent = 'import "./virtual-module.d.js";';
|
|
300
|
-
|
|
313
|
+
this.writeGeneratedFile(indexTypesDir, indexContent);
|
|
301
314
|
logger.debug("Generated index types for virtual module", { indexTypesDir });
|
|
302
315
|
const runtimeVirtualModulePath = resolveGeneratedPath("cache", {
|
|
303
316
|
root: this.context.distDir,
|
|
@@ -307,8 +320,7 @@ declare module "ecopages:images" {
|
|
|
307
320
|
const runtimeModuleContent = Object.entries(this.processedImages).map(([key, value]) => {
|
|
308
321
|
return `export const ${anyCaseToCamelCase(key)} = ${JSON.stringify(value, null, 2)} as const;`;
|
|
309
322
|
}).join("\n\n");
|
|
310
|
-
|
|
311
|
-
fileSystem.write(runtimeVirtualModulePath, runtimeModuleContent);
|
|
323
|
+
this.writeGeneratedFile(runtimeVirtualModulePath, runtimeModuleContent);
|
|
312
324
|
logger.debug("Generated runtime virtual module for images", { runtimeVirtualModulePath });
|
|
313
325
|
}
|
|
314
326
|
/**
|