@bgord/bun 1.3.2 → 1.4.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.
Files changed (44) hide show
  1. package/dist/command-envelope.d.ts +1 -1
  2. package/dist/csv-stringifier.adapter.d.ts +1 -1
  3. package/dist/image-alpha-sharp.adapter.d.ts +1 -0
  4. package/dist/image-alpha-sharp.adapter.d.ts.map +1 -1
  5. package/dist/image-alpha-sharp.adapter.js +18 -77
  6. package/dist/image-alpha-sharp.adapter.js.map +1 -1
  7. package/dist/image-blur-sharp.adapter.d.ts +1 -0
  8. package/dist/image-blur-sharp.adapter.d.ts.map +1 -1
  9. package/dist/image-blur-sharp.adapter.js +14 -73
  10. package/dist/image-blur-sharp.adapter.js.map +1 -1
  11. package/dist/image-compressor-sharp.adapter.d.ts +1 -0
  12. package/dist/image-compressor-sharp.adapter.d.ts.map +1 -1
  13. package/dist/image-compressor-sharp.adapter.js +15 -74
  14. package/dist/image-compressor-sharp.adapter.js.map +1 -1
  15. package/dist/image-exif-clear-sharp.adapter.d.ts +1 -0
  16. package/dist/image-exif-clear-sharp.adapter.d.ts.map +1 -1
  17. package/dist/image-exif-clear-sharp.adapter.js +12 -71
  18. package/dist/image-exif-clear-sharp.adapter.js.map +1 -1
  19. package/dist/image-formatter-sharp.adapter.d.ts +1 -0
  20. package/dist/image-formatter-sharp.adapter.d.ts.map +1 -1
  21. package/dist/image-formatter-sharp.adapter.js +17 -76
  22. package/dist/image-formatter-sharp.adapter.js.map +1 -1
  23. package/dist/image-info-sharp.adapter.d.ts +1 -0
  24. package/dist/image-info-sharp.adapter.d.ts.map +1 -1
  25. package/dist/image-info-sharp.adapter.js +14 -73
  26. package/dist/image-info-sharp.adapter.js.map +1 -1
  27. package/dist/image-processor-sharp.adapter.d.ts +1 -0
  28. package/dist/image-processor-sharp.adapter.d.ts.map +1 -1
  29. package/dist/image-processor-sharp.adapter.js +28 -87
  30. package/dist/image-processor-sharp.adapter.js.map +1 -1
  31. package/dist/image-resizer-sharp.adapter.d.ts +1 -0
  32. package/dist/image-resizer-sharp.adapter.d.ts.map +1 -1
  33. package/dist/image-resizer-sharp.adapter.js +23 -82
  34. package/dist/image-resizer-sharp.adapter.js.map +1 -1
  35. package/dist/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +9 -3
  37. package/src/image-alpha-sharp.adapter.ts +9 -3
  38. package/src/image-blur-sharp.adapter.ts +7 -2
  39. package/src/image-compressor-sharp.adapter.ts +7 -2
  40. package/src/image-exif-clear-sharp.adapter.ts +6 -1
  41. package/src/image-formatter-sharp.adapter.ts +7 -2
  42. package/src/image-info-sharp.adapter.ts +6 -1
  43. package/src/image-processor-sharp.adapter.ts +7 -2
  44. package/src/image-resizer-sharp.adapter.ts +7 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/bun",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": "Bartosz Gordon",
@@ -31,6 +31,7 @@
31
31
  "knip": "5.73.0",
32
32
  "lefthook": "2.0.9",
33
33
  "only-allow": "1.2.2",
34
+ "sharp": "0.34.5",
34
35
  "shellcheck": "4.1.0",
35
36
  "typescript": "5.9.3",
36
37
  "zod": "4.1.13"
@@ -49,11 +50,16 @@
49
50
  "marked": "17.0.1",
50
51
  "node-cache": "5.1.2",
51
52
  "nodemailer": "7.0.11",
52
- "sharp": "0.34.5",
53
53
  "winston": "3.19.0",
54
54
  "yazl": "3.3.1"
55
55
  },
56
56
  "peerDependencies": {
57
- "zod": "4.1.13"
57
+ "zod": "4.1.13",
58
+ "sharp": "0.34.5"
59
+ },
60
+ "peerDependenciesMeta": {
61
+ "sharp": {
62
+ "optional": true
63
+ }
58
64
  }
59
65
  }
@@ -1,4 +1,3 @@
1
- import sharp from "sharp";
2
1
  import type { FileRenamerPort } from "./file-renamer.port";
3
2
  import type { ImageAlphaPort, ImageAlphaStrategy } from "./image-alpha.port";
4
3
 
@@ -7,23 +6,30 @@ type Dependencies = { FileRenamer: FileRenamerPort };
7
6
  export class ImageAlphaSharpAdapter implements ImageAlphaPort {
8
7
  constructor(private readonly deps: Dependencies) {}
9
8
 
9
+ private async load() {
10
+ return (await import("sharp")).default;
11
+ }
12
+
10
13
  async flatten(recipe: ImageAlphaStrategy) {
14
+ const sharp = await this.load();
15
+
11
16
  const final = recipe.strategy === "output_path" ? recipe.output : recipe.input;
12
17
 
13
18
  const filename = final.getFilename();
14
19
  const temporary = final.withFilename(filename.withSuffix("-flattened"));
15
20
 
16
21
  const extension = final.getFilename().getExtension();
17
- const format = (extension === "jpg" ? "jpeg" : extension) as keyof sharp.FormatEnum;
22
+ const format = (extension === "jpg" ? "jpeg" : extension) as keyof import("sharp").FormatEnum;
18
23
 
19
24
  const pipeline = sharp(recipe.input.get());
20
- using _sharp_ = { [Symbol.dispose]: () => pipeline.destroy() };
25
+ using _pipeline_dispose = { [Symbol.dispose]: () => pipeline.destroy() };
21
26
 
22
27
  await pipeline
23
28
  .rotate()
24
29
  .flatten({ background: recipe.background })
25
30
  .toFormat(format)
26
31
  .toFile(temporary.get());
32
+
27
33
  await this.deps.FileRenamer.rename(temporary, final);
28
34
 
29
35
  return final;
@@ -1,4 +1,3 @@
1
- import sharp from "sharp";
2
1
  import type { FileRenamerPort } from "./file-renamer.port";
3
2
  import type { ImageBlurPort, ImageBlurStrategy } from "./image-blur.port";
4
3
 
@@ -7,14 +6,20 @@ type Dependencies = { FileRenamer: FileRenamerPort };
7
6
  export class ImageBlurSharpAdapter implements ImageBlurPort {
8
7
  constructor(private readonly deps: Dependencies) {}
9
8
 
9
+ private async load() {
10
+ return (await import("sharp")).default;
11
+ }
12
+
10
13
  async blur(recipe: ImageBlurStrategy) {
14
+ const sharp = await this.load();
15
+
11
16
  const final = recipe.strategy === "output_path" ? recipe.output : recipe.input;
12
17
 
13
18
  const filename = final.getFilename();
14
19
  const temporary = final.withFilename(filename.withSuffix("-blurred"));
15
20
 
16
21
  const extension = final.getFilename().getExtension();
17
- const format = (extension === "jpg" ? "jpeg" : extension) as keyof sharp.FormatEnum;
22
+ const format = (extension === "jpg" ? "jpeg" : extension) as keyof import("sharp").FormatEnum;
18
23
 
19
24
  const pipeline = sharp(recipe.input.get());
20
25
  using _sharp_ = { [Symbol.dispose]: () => pipeline.destroy() };
@@ -1,4 +1,3 @@
1
- import sharp from "sharp";
2
1
  import type { FileRenamerPort } from "./file-renamer.port";
3
2
  import type { ImageCompressorPort, ImageCompressorStrategy } from "./image-compressor.port";
4
3
 
@@ -7,9 +6,15 @@ type Dependencies = { FileRenamer: FileRenamerPort };
7
6
  export class ImageCompressorSharpAdapter implements ImageCompressorPort {
8
7
  constructor(private readonly deps: Dependencies) {}
9
8
 
9
+ private async load() {
10
+ return (await import("sharp")).default;
11
+ }
12
+
10
13
  private static readonly DEFAULT_QUALITY = 85;
11
14
 
12
15
  async compress(recipe: ImageCompressorStrategy) {
16
+ const sharp = await this.load();
17
+
13
18
  const quality = recipe.quality ?? ImageCompressorSharpAdapter.DEFAULT_QUALITY;
14
19
 
15
20
  const final = recipe.strategy === "output_path" ? recipe.output : recipe.input;
@@ -17,7 +22,7 @@ export class ImageCompressorSharpAdapter implements ImageCompressorPort {
17
22
  const temporary = final.withFilename(filename.withSuffix("-compressed"));
18
23
 
19
24
  const extension = final.getFilename().getExtension();
20
- const format = (extension === "jpg" ? "jpeg" : extension) as keyof sharp.FormatEnum;
25
+ const format = (extension === "jpg" ? "jpeg" : extension) as keyof import("sharp").FormatEnum;
21
26
 
22
27
  const pipeline = sharp(recipe.input.get());
23
28
  using _sharp_ = { [Symbol.dispose]: () => pipeline.destroy() };
@@ -1,4 +1,3 @@
1
- import sharp from "sharp";
2
1
  import type { FileRenamerPort } from "./file-renamer.port";
3
2
  import type { ImageExifClearPort, ImageExifClearStrategy } from "./image-exif-clear.port";
4
3
 
@@ -7,7 +6,13 @@ type Dependencies = { FileRenamer: FileRenamerPort };
7
6
  export class ImageExifClearSharpAdapter implements ImageExifClearPort {
8
7
  constructor(private readonly deps: Dependencies) {}
9
8
 
9
+ private async load() {
10
+ return (await import("sharp")).default;
11
+ }
12
+
10
13
  async clear(recipe: ImageExifClearStrategy) {
14
+ const sharp = await this.load();
15
+
11
16
  const final = recipe.strategy === "output_path" ? recipe.output : recipe.input;
12
17
 
13
18
  const filename = final.getFilename();
@@ -1,4 +1,3 @@
1
- import sharp from "sharp";
2
1
  import type { FileCleanerPort } from "./file-cleaner.port";
3
2
  import type { FileRenamerPort } from "./file-renamer.port";
4
3
  import type { ImageFormatterPort, ImageFormatterStrategy } from "./image-formatter.port";
@@ -8,7 +7,13 @@ type Dependencies = { FileCleaner: FileCleanerPort; FileRenamer: FileRenamerPort
8
7
  export class ImageFormatterSharpAdapter implements ImageFormatterPort {
9
8
  constructor(private readonly deps: Dependencies) {}
10
9
 
10
+ private async load() {
11
+ return (await import("sharp")).default;
12
+ }
13
+
11
14
  async format(recipe: ImageFormatterStrategy) {
15
+ const sharp = await this.load();
16
+
12
17
  const final =
13
18
  recipe.strategy === "output_path"
14
19
  ? recipe.output
@@ -17,7 +22,7 @@ export class ImageFormatterSharpAdapter implements ImageFormatterPort {
17
22
  const temporary = final.withFilename(final.getFilename().withSuffix("-formatted"));
18
23
 
19
24
  const extension = final.getFilename().getExtension();
20
- const encoder = (extension === "jpg" ? "jpeg" : extension) as keyof sharp.FormatEnum;
25
+ const encoder = (extension === "jpg" ? "jpeg" : extension) as keyof import("sharp").FormatEnum;
21
26
 
22
27
  const pipeline = sharp((recipe.strategy === "output_path" ? recipe.input : recipe.input).get());
23
28
  using _sharp_ = { [Symbol.dispose]: () => pipeline.destroy() };
@@ -1,9 +1,14 @@
1
1
  import * as tools from "@bgord/tools";
2
- import sharp from "sharp";
3
2
  import type { ImageInfoPort } from "./image-info.port";
4
3
 
5
4
  export class ImageInfoSharpAdapter implements ImageInfoPort {
5
+ private async load() {
6
+ return (await import("sharp")).default;
7
+ }
8
+
6
9
  async inspect(filePath: tools.FilePathRelative | tools.FilePathAbsolute) {
10
+ const sharp = await this.load();
11
+
7
12
  const path = filePath.get();
8
13
 
9
14
  const pipeline = sharp(path);
@@ -1,5 +1,4 @@
1
1
  import type * as tools from "@bgord/tools";
2
- import sharp from "sharp";
3
2
  import type { FileCleanerPort } from "./file-cleaner.port";
4
3
  import type { FileRenamerPort } from "./file-renamer.port";
5
4
  import type { ImageProcessorPort, ImageProcessorStrategy } from "./image-processor.port";
@@ -11,7 +10,13 @@ export class ImageProcessorSharpAdapter implements ImageProcessorPort {
11
10
 
12
11
  constructor(private readonly deps: Dependencies) {}
13
12
 
13
+ private async load() {
14
+ return (await import("sharp")).default;
15
+ }
16
+
14
17
  async process(recipe: ImageProcessorStrategy): Promise<tools.FilePathRelative | tools.FilePathAbsolute> {
18
+ const sharp = await this.load();
19
+
15
20
  const final =
16
21
  recipe.strategy === "output_path"
17
22
  ? recipe.output
@@ -20,7 +25,7 @@ export class ImageProcessorSharpAdapter implements ImageProcessorPort {
20
25
  const temporary = final.withFilename(final.getFilename().withSuffix("-processed"));
21
26
 
22
27
  const extension = final.getFilename().getExtension();
23
- const encoder = (extension === "jpg" ? "jpeg" : extension) as keyof sharp.FormatEnum;
28
+ const encoder = (extension === "jpg" ? "jpeg" : extension) as keyof import("sharp").FormatEnum;
24
29
 
25
30
  const quality = recipe.quality ?? ImageProcessorSharpAdapter.DEFAULT_QUALITY;
26
31
 
@@ -1,4 +1,3 @@
1
- import sharp from "sharp";
2
1
  import type { FileRenamerPort } from "./file-renamer.port";
3
2
  import type { ImageResizerPort, ImageResizerStrategy } from "./image-resizer.port";
4
3
 
@@ -7,13 +6,19 @@ type Dependencies = { FileRenamer: FileRenamerPort };
7
6
  export class ImageResizerSharpAdapter implements ImageResizerPort {
8
7
  constructor(private readonly deps: Dependencies) {}
9
8
 
9
+ private async load() {
10
+ return (await import("sharp")).default;
11
+ }
12
+
10
13
  async resize(recipe: ImageResizerStrategy) {
14
+ const sharp = await this.load();
15
+
11
16
  const final = recipe.strategy === "output_path" ? recipe.output : recipe.input;
12
17
  const filename = final.getFilename();
13
18
  const temporary = final.withFilename(filename.withSuffix("-resized"));
14
19
 
15
20
  const extension = final.getFilename().getExtension();
16
- const format = (extension === "jpg" ? "jpeg" : extension) as keyof sharp.FormatEnum;
21
+ const format = (extension === "jpg" ? "jpeg" : extension) as keyof import("sharp").FormatEnum;
17
22
 
18
23
  const pipeline = sharp(recipe.input.get());
19
24
  using _sharp_ = { [Symbol.dispose]: () => pipeline.destroy() };