@ecopages/image-processor 0.2.0-rc.0 → 0.2.0-rc.10

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 CHANGED
@@ -68,6 +68,17 @@ import { heroImage, profilePicture } from 'ecopages:images';
68
68
  > **No manual dependencies required.**
69
69
  > Ecopages automatically detects these virtual module imports and processes them during the build, enabling effective tree-shaking for only the required images.
70
70
 
71
+ ## TypeScript Setup
72
+
73
+ Add one import to the app `modules.d.ts`:
74
+
75
+ ```typescript
76
+ import '@ecopages/image-processor/types';
77
+ ```
78
+
79
+ That declares `ecopages:images`. Named exports are generated at dev/build time into
80
+ `node_modules/@types/ecopages-image-processor`, which TypeScript loads automatically.
81
+
71
82
  ### Components
72
83
 
73
84
  The plugin provides ready-to-use components for string HTML (KitaJS), Ecopages JSX, and React.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/image-processor",
3
- "version": "0.2.0-rc.0",
3
+ "version": "0.2.0-rc.10",
4
4
  "description": "Image processor, transform and optimize images for web",
5
5
  "keywords": [
6
6
  "image",
@@ -9,14 +9,17 @@
9
9
  "license": "MIT",
10
10
  "main": "./src/image-processor.js",
11
11
  "type": "module",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
12
15
  "repository": {
13
16
  "type": "git",
14
17
  "url": "git+https://github.com/ecopages/ecopages.git",
15
18
  "directory": "packages/processors/image-processor"
16
19
  },
17
20
  "peerDependencies": {
18
- "@ecopages/core": "0.2.0-rc.0",
19
- "@ecopages/jsx": ">=0.3.0-rc.0"
21
+ "@ecopages/core": "0.2.0-rc.10",
22
+ "@ecopages/jsx": "^0.3.0-rc.9"
20
23
  },
21
24
  "peerDependenciesMeta": {
22
25
  "@ecopages/jsx": {
@@ -24,7 +27,7 @@
24
27
  }
25
28
  },
26
29
  "dependencies": {
27
- "@ecopages/file-system": "0.2.0-rc.0",
30
+ "@ecopages/file-system": "0.2.0-rc.10",
28
31
  "@ecopages/logger": "^0.2.3",
29
32
  "react": "^19.2.6",
30
33
  "react-dom": "^19.2.6",
@@ -36,7 +39,7 @@
36
39
  "types": "./src/index.d.ts"
37
40
  },
38
41
  "./types": {
39
- "types": "./src/types.d.ts"
42
+ "types": "./src/image-types.d.ts"
40
43
  },
41
44
  "./component/html": {
42
45
  "default": "./src/component/html.js",
@@ -51,7 +54,7 @@
51
54
  "types": "./src/component/react.d.ts"
52
55
  },
53
56
  "./types.ts": {
54
- "types": "./src/types.d.ts"
57
+ "types": "./src/image-types.d.ts"
55
58
  },
56
59
  "./component/html.ts": {
57
60
  "default": "./src/component/html.js",
@@ -66,12 +69,5 @@
66
69
  "types": "./src/component/react.d.ts"
67
70
  }
68
71
  },
69
- "typesVersions": {
70
- "*": {
71
- "ecopages:images": [
72
- "./virtual-module.d.ts"
73
- ]
74
- }
75
- },
76
72
  "types": "./src/index.d.ts"
77
- }
73
+ }
@@ -0,0 +1,3 @@
1
+ export type { ImageAttributes, ImageSize, ImageSpecifications, ImageVariant } from './types.js';
2
+
3
+ declare module 'ecopages:images' {}
package/src/plugin.d.ts CHANGED
@@ -75,6 +75,16 @@ export declare class ImageProcessorPlugin extends Processor<ImageProcessorConfig
75
75
  private syncProcessedImagesFromDisk;
76
76
  private ensureGeneratedOutputs;
77
77
  private writeGeneratedFile;
78
+ /**
79
+ * Generates virtual-module declarations from source filenames before image
80
+ * processing runs.
81
+ *
82
+ * @remarks
83
+ * Editors need the ambient `ecopages:images` module during config build, but
84
+ * actual image optimization is deferred until {@link setup}. Declaring exports
85
+ * from the source directory preserves typed named imports on a clean checkout.
86
+ */
87
+ private generateSourceTypes;
78
88
  /**
79
89
  * Ensures optimized image outputs and virtual-module state exist on disk.
80
90
  */
@@ -93,6 +103,10 @@ export declare class ImageProcessorPlugin extends Processor<ImageProcessorConfig
93
103
  * Generate types for the virtual module.
94
104
  */
95
105
  private generateTypes;
106
+ /**
107
+ * Writes the ambient declaration package for `ecopages:images`.
108
+ */
109
+ private writeVirtualModuleTypes;
96
110
  /**
97
111
  * Teardown the image processor.
98
112
  */
package/src/plugin.js CHANGED
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import path from 'node:path';
6
6
  import { fileSystem } from '@ecopages/file-system';
7
- import { mergeProcessorOptions, Processor, resolveGeneratedPath, } from '@ecopages/core/plugins/processor';
7
+ import { mergeProcessorOptions, Processor, resolveGeneratedPath, writeGeneratedTypesPackage, } from '@ecopages/core/plugins/processor';
8
8
  import { isLitStaticRenderWorkerThread } from '@ecopages/core/build/lit-static-render-worker-context';
9
9
  import { Logger } from '@ecopages/logger';
10
10
  import { createImagePlugin, createImagePluginBundler } from './image-plugins.js';
@@ -160,6 +160,7 @@ export class ImageProcessorPlugin extends Processor {
160
160
  return;
161
161
  }
162
162
  this.initializeProcessor();
163
+ await this.generateSourceTypes();
163
164
  await this.syncProcessedImagesFromDisk();
164
165
  this.buildContributionsPrepared = true;
165
166
  }
@@ -222,6 +223,22 @@ export class ImageProcessorPlugin extends Processor {
222
223
  }
223
224
  fileSystem.write(filePath, content);
224
225
  }
226
+ /**
227
+ * Generates virtual-module declarations from source filenames before image
228
+ * processing runs.
229
+ *
230
+ * @remarks
231
+ * Editors need the ambient `ecopages:images` module during config build, but
232
+ * actual image optimization is deferred until {@link setup}. Declaring exports
233
+ * from the source directory preserves typed named imports on a clean checkout.
234
+ */
235
+ async generateSourceTypes() {
236
+ if (!this.resolvedConfig) {
237
+ return;
238
+ }
239
+ const sourceImages = await getSourceImagePaths(this.resolvedConfig);
240
+ this.writeVirtualModuleTypes(sourceImages.map((imagePath) => path.basename(imagePath)));
241
+ }
225
242
  /**
226
243
  * Ensures optimized image outputs and virtual-module state exist on disk.
227
244
  */
@@ -299,9 +316,26 @@ export class ImageProcessorPlugin extends Processor {
299
316
  * Generate types for the virtual module.
300
317
  */
301
318
  generateTypes() {
302
- if (!this.options?.outputDir) {
303
- throw new Error('Output directory not set');
304
- }
319
+ this.writeVirtualModuleTypes(Object.keys(this.processedImages));
320
+ if (!this.context)
321
+ throw new Error('Processor is not configured correctly');
322
+ const runtimeVirtualModulePath = resolveGeneratedPath('cache', {
323
+ root: this.context.distDir,
324
+ module: this.name,
325
+ subPath: 'virtual-module.ts',
326
+ });
327
+ const runtimeModuleContent = Object.entries(this.processedImages)
328
+ .map(([key, value]) => {
329
+ return `export const ${anyCaseToCamelCase(key)} = ${JSON.stringify(value, null, 2)} as const;`;
330
+ })
331
+ .join('\n\n');
332
+ this.writeGeneratedFile(runtimeVirtualModulePath, runtimeModuleContent);
333
+ logger.debug('Generated runtime virtual module for images', { runtimeVirtualModulePath });
334
+ }
335
+ /**
336
+ * Writes the ambient declaration package for `ecopages:images`.
337
+ */
338
+ writeVirtualModuleTypes(imageKeys) {
305
339
  const content = `
306
340
  /**
307
341
  * Do not edit manually. This file is auto-generated.
@@ -311,9 +345,7 @@ export class ImageProcessorPlugin extends Processor {
311
345
  ${IMAGE_VIRTUAL_MODULE_TYPES}
312
346
 
313
347
  declare module "ecopages:images" {
314
- ${Object.keys(this.processedImages)
315
- .map((key) => `export const ${anyCaseToCamelCase(key)}: ImageSpecifications;`)
316
- .join('\n ')}
348
+ ${imageKeys.map((key) => `export const ${anyCaseToCamelCase(key)}: ImageSpecifications;`).join('\n ')}
317
349
  }`;
318
350
  if (!this.context)
319
351
  throw new Error('Processor is not configured correctly');
@@ -329,21 +361,15 @@ declare module "ecopages:images" {
329
361
  module: this.name,
330
362
  subPath: 'index.d.ts',
331
363
  });
332
- const indexContent = 'import "./virtual-module.d.js";';
364
+ const indexContent = 'import "./virtual-module.d.js";\n';
333
365
  this.writeGeneratedFile(indexTypesDir, indexContent);
334
366
  logger.debug('Generated index types for virtual module', { indexTypesDir });
335
- const runtimeVirtualModulePath = resolveGeneratedPath('cache', {
336
- root: this.context.distDir,
367
+ writeGeneratedTypesPackage({
368
+ root: this.context.rootDir,
337
369
  module: this.name,
338
- subPath: 'virtual-module.ts',
370
+ packageName: '@types/ecopages-image-processor',
371
+ writeFile: (filePath, content) => this.writeGeneratedFile(filePath, content),
339
372
  });
340
- const runtimeModuleContent = Object.entries(this.processedImages)
341
- .map(([key, value]) => {
342
- return `export const ${anyCaseToCamelCase(key)} = ${JSON.stringify(value, null, 2)} as const;`;
343
- })
344
- .join('\n\n');
345
- this.writeGeneratedFile(runtimeVirtualModulePath, runtimeModuleContent);
346
- logger.debug('Generated runtime virtual module for images', { runtimeVirtualModulePath });
347
373
  }
348
374
  /**
349
375
  * Teardown the image processor.