charify 2.0.1 → 2.0.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "charify",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "High-quality image to ASCII art CLI",
5
5
  "keywords": [
6
6
  "ascii",
package/src/charify.js CHANGED
@@ -1,8 +1,10 @@
1
- import sharp from "sharp";
2
1
  import { PRESETS, DEFAULTS } from "./constants.js";
3
2
  import { SharpMissingError } from "./errors.js";
3
+ import { loadSharp } from "./loadSharp.js";
4
4
 
5
5
  export async function convertToAscii(buffer, options = {}) {
6
+ const sharp = await loadSharp();
7
+
6
8
  if (!sharp) {
7
9
  throw new SharpMissingError();
8
10
  }
@@ -0,0 +1,27 @@
1
+ import { execSync } from "child_process";
2
+
3
+ let sharpInstance;
4
+
5
+ export async function loadSharp() {
6
+ if (sharpInstance) return sharpInstance;
7
+
8
+ try {
9
+ sharpInstance = (await import("sharp")).default;
10
+ return sharpInstance;
11
+ } catch {
12
+ console.warn(
13
+ "[Warning]: 'sharp' package not found. Installing it now, please wait..."
14
+ );
15
+
16
+ try {
17
+ execSync("npm install sharp", { stdio: "inherit" });
18
+ sharpInstance = (await import("sharp")).default;
19
+ console.log("'sharp' installed successfully.");
20
+ return sharpInstance;
21
+ } catch (installErr) {
22
+ throw new Error(
23
+ "Failed to install 'sharp'. Please install it manually and try again."
24
+ );
25
+ }
26
+ }
27
+ }