astro-lqip 1.7.0 → 1.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-lqip",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Native extended Astro components for generating low quality image placeholders (LQIP).",
5
5
  "keywords": [
6
6
  "astro",
@@ -13,6 +13,19 @@ function normalizeFsPath(path: string) {
13
13
  return path
14
14
  }
15
15
 
16
+ function isNode() {
17
+ return typeof process !== 'undefined' && !!process.versions?.node
18
+ }
19
+
20
+ async function readIfExists(path: string): Promise<Buffer | undefined> {
21
+ if (!isNode()) return undefined
22
+ try {
23
+ return await readFile(path)
24
+ } catch {
25
+ return undefined
26
+ }
27
+ }
28
+
16
29
  export async function generateLqip(
17
30
  imagePath: string,
18
31
  lqipType: LqipType,
@@ -22,7 +35,7 @@ export async function generateLqip(
22
35
  try {
23
36
  const normalizedPath = normalizeFsPath(imagePath)
24
37
 
25
- const buffer = await readFile(normalizedPath)
38
+ const buffer = await readIfExists(normalizedPath)
26
39
 
27
40
  if (!buffer) {
28
41
  console.warn(`${PREFIX} image not found for:`, imagePath)