@travetto/image 3.0.0-rc.4 → 3.0.0-rc.6
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/resource.ts +4 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/image",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.6",
|
|
4
4
|
"description": "Image support, resizing, and optimization",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"images",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"directory": "module/image"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@travetto/base": "^3.0.0-rc.
|
|
27
|
-
"@travetto/command": "^3.0.0-rc.
|
|
26
|
+
"@travetto/base": "^3.0.0-rc.6",
|
|
27
|
+
"@travetto/command": "^3.0.0-rc.6"
|
|
28
28
|
},
|
|
29
29
|
"travetto": {
|
|
30
30
|
"displayName": "Image"
|
package/src/resource.ts
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import { Readable } from 'stream';
|
|
3
|
-
import { mkdirSync } from 'fs';
|
|
4
3
|
|
|
5
4
|
import { path } from '@travetto/manifest';
|
|
6
|
-
import {
|
|
5
|
+
import { Env, FileResourceProvider, StreamUtil } from '@travetto/base';
|
|
7
6
|
|
|
8
7
|
import { ImageConverter } from './convert';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Resource provider for images that allows for real-time optimization
|
|
12
11
|
*/
|
|
13
|
-
export class ImageOptimizingResourceProvider extends
|
|
12
|
+
export class ImageOptimizingResourceProvider extends FileResourceProvider {
|
|
14
13
|
|
|
15
14
|
#cacheRoot: string;
|
|
16
15
|
|
|
17
16
|
constructor(paths?: string[], cacheRoot?: string) {
|
|
18
|
-
super(paths);
|
|
17
|
+
super({ paths, includeCommon: true });
|
|
19
18
|
|
|
20
19
|
this.#cacheRoot = cacheRoot ?? path.resolve(Env.get('TRV_IMAGE_CACHE', '.trv_images'));
|
|
21
|
-
mkdirSync(this.#cacheRoot, { recursive: true });
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
async #openFile(pth: string): Promise<fs.FileHandle> {
|
|
@@ -31,7 +29,7 @@ export class ImageOptimizingResourceProvider extends CommonFileResourceProvider
|
|
|
31
29
|
async readOptimized(rel: string): Promise<Buffer> {
|
|
32
30
|
const { path: pth } = await this.describe(rel);
|
|
33
31
|
const cachedOutput = path.resolve(this.#cacheRoot, rel);
|
|
34
|
-
await fs.mkdir(path.dirname(cachedOutput));
|
|
32
|
+
await fs.mkdir(path.dirname(cachedOutput), { recursive: true });
|
|
35
33
|
|
|
36
34
|
const handle = await this.#openFile(cachedOutput);
|
|
37
35
|
const exists = !!(await handle.stat().catch(() => false));
|