@travetto/image 3.4.0-rc.7 → 3.4.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 ArcSine Technologies
3
+ Copyright (c) 2023 ArcSine Technologies
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/image",
3
- "version": "3.4.0-rc.7",
3
+ "version": "3.4.1",
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.4.0-rc.7",
27
- "@travetto/command": "^3.4.0-rc.7"
26
+ "@travetto/base": "^3.4.1",
27
+ "@travetto/command": "^3.4.1"
28
28
  },
29
29
  "travetto": {
30
30
  "displayName": "Image"
package/src/resource.ts CHANGED
@@ -2,19 +2,19 @@ import fs from 'fs/promises';
2
2
  import { Readable } from 'stream';
3
3
 
4
4
  import { ManifestFileUtil, RootIndex, path } from '@travetto/manifest';
5
- import { Env, FileResourceProvider, StreamUtil } from '@travetto/base';
5
+ import { Env, ResourceLoader, StreamUtil } from '@travetto/base';
6
6
 
7
7
  import { ImageConverter } from './convert';
8
8
 
9
9
  /**
10
10
  * Resource provider for images that allows for real-time optimization
11
11
  */
12
- export class ImageOptimizingResourceProvider extends FileResourceProvider {
12
+ export class ImageOptimizingResourceLoader extends ResourceLoader {
13
13
 
14
14
  #cacheRoot: string;
15
15
 
16
- constructor(paths?: string[], cacheRoot?: string) {
17
- super({ paths, includeCommon: true });
16
+ constructor(paths: string[] = [], cacheRoot?: string) {
17
+ super(paths);
18
18
 
19
19
  this.#cacheRoot = cacheRoot ?? path.resolve(Env.get('TRV_IMAGE_CACHE', ManifestFileUtil.toolPath(RootIndex, 'image_cache')));
20
20
  }
@@ -27,7 +27,6 @@ export class ImageOptimizingResourceProvider extends FileResourceProvider {
27
27
  * Fetch image, compress and return as buffer
28
28
  */
29
29
  async readOptimized(rel: string): Promise<Buffer> {
30
- const pth = await this.resolve(rel);
31
30
  const cachedOutput = path.resolve(this.#cacheRoot, rel);
32
31
  await fs.mkdir(path.dirname(cachedOutput), { recursive: true });
33
32
 
@@ -36,9 +35,9 @@ export class ImageOptimizingResourceProvider extends FileResourceProvider {
36
35
 
37
36
  if (!exists) {
38
37
  let stream: Buffer | Readable = await this.readStream(rel);
39
- if (/[.]png$/.test(pth)) {
38
+ if (/[.]png$/.test(rel)) {
40
39
  stream = await ImageConverter.optimize('png', stream);
41
- } else if (/[.]jpe?g$/i.test(pth)) {
40
+ } else if (/[.]jpe?g$/i.test(rel)) {
42
41
  stream = await ImageConverter.optimize('jpeg', stream);
43
42
  }
44
43
  await StreamUtil.pipe(stream, handle.createWriteStream());