nuxt-og-image 2.0.0-beta.35 → 2.0.0-beta.37
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/dist/module.json +1 -1
- package/dist/module.mjs +30 -5
- package/dist/runtime/composables/defineOgImage.mjs +1 -0
- package/dist/runtime/nitro/middleware/og.png.mjs +3 -2
- package/dist/runtime/nitro/providers/browser/lambda.d.ts +1 -1
- package/dist/runtime/nitro/providers/browser/lambda.mjs +5 -5
- package/package.json +2 -2
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -238,6 +238,10 @@ const DefaultRuntimeCompatibility = {
|
|
|
238
238
|
png: "resvg"
|
|
239
239
|
};
|
|
240
240
|
const RuntimeCompatibility = {
|
|
241
|
+
"nitro-dev": {
|
|
242
|
+
wasm: "fetch",
|
|
243
|
+
browser: "universal"
|
|
244
|
+
},
|
|
241
245
|
"stackblitz": {
|
|
242
246
|
browser: false,
|
|
243
247
|
satori: "yoga-wasm",
|
|
@@ -268,6 +272,24 @@ const RuntimeCompatibility = {
|
|
|
268
272
|
}
|
|
269
273
|
};
|
|
270
274
|
|
|
275
|
+
const autodetectableProviders = {
|
|
276
|
+
azure_static: "azure",
|
|
277
|
+
cloudflare_pages: "cloudflare-pages",
|
|
278
|
+
netlify: "netlify",
|
|
279
|
+
stormkit: "stormkit",
|
|
280
|
+
vercel: "vercel",
|
|
281
|
+
cleavr: "cleavr"
|
|
282
|
+
};
|
|
283
|
+
const autodetectableStaticProviders = {
|
|
284
|
+
netlify: "netlify-static",
|
|
285
|
+
vercel: "vercel-static"
|
|
286
|
+
};
|
|
287
|
+
function detectTarget(options = {}) {
|
|
288
|
+
return options?.static ? autodetectableStaticProviders[provider] : autodetectableProviders[provider];
|
|
289
|
+
}
|
|
290
|
+
function getNitroPreset(nuxt) {
|
|
291
|
+
return process.env.NITRO_PRESET || nuxt.options.nitro.preset || detectTarget() || "node-server";
|
|
292
|
+
}
|
|
271
293
|
function getNitroProviderCompatibility(nuxt) {
|
|
272
294
|
if (nuxt.options.dev || nuxt.options._prepare || nuxt.options._generate) {
|
|
273
295
|
return defu({
|
|
@@ -277,14 +299,16 @@ function getNitroProviderCompatibility(nuxt) {
|
|
|
277
299
|
}
|
|
278
300
|
if (provider === "stackblitz")
|
|
279
301
|
return defu(RuntimeCompatibility.stackblitz, DefaultRuntimeCompatibility);
|
|
280
|
-
const target =
|
|
302
|
+
const target = getNitroPreset(nuxt);
|
|
281
303
|
const compatibility = RuntimeCompatibility[target];
|
|
282
304
|
if (compatibility === false)
|
|
283
305
|
return false;
|
|
284
306
|
return defu(compatibility || {}, DefaultRuntimeCompatibility);
|
|
285
307
|
}
|
|
286
|
-
function
|
|
287
|
-
return
|
|
308
|
+
function ensureDependencies(nuxt, dep) {
|
|
309
|
+
return Promise.all(dep.map((d) => {
|
|
310
|
+
return addDependency(d, { cwd: nuxt.options.rootDir });
|
|
311
|
+
}));
|
|
288
312
|
}
|
|
289
313
|
|
|
290
314
|
const PATH = "/__nuxt_og_image__";
|
|
@@ -323,8 +347,9 @@ const module = defineNuxtModule({
|
|
|
323
347
|
const logger = useLogger("nuxt-og-image");
|
|
324
348
|
logger.level = config.debug ? 4 : 3;
|
|
325
349
|
const { resolve } = createResolver(import.meta.url);
|
|
350
|
+
logger.debug("Using Nitro preset", getNitroPreset(nuxt));
|
|
326
351
|
const nitroCompatibility = getNitroProviderCompatibility(nuxt);
|
|
327
|
-
logger.debug("Nitro compatibility
|
|
352
|
+
logger.debug("Nitro compatibility", nitroCompatibility);
|
|
328
353
|
if (!nitroCompatibility) {
|
|
329
354
|
const target = process.env.NITRO_PRESET || nuxt.options.nitro.preset;
|
|
330
355
|
logger.warn(`It looks like the nitro target ${target} doesn't support \`nuxt-og-image\`.`);
|
|
@@ -336,7 +361,7 @@ const module = defineNuxtModule({
|
|
|
336
361
|
}
|
|
337
362
|
if (config.runtimeBrowser && nitroCompatibility.browser === "lambda") {
|
|
338
363
|
logger.info("It looks like you're deploying to an environment which requires `chrome-aws-lambda`, checking for dependency...");
|
|
339
|
-
await
|
|
364
|
+
await ensureDependencies(nuxt, ["puppeteer-core@10.1.0", "chrome-aws-lambda@10.1.0"]);
|
|
340
365
|
}
|
|
341
366
|
config.siteUrl = config.siteUrl || config.host;
|
|
342
367
|
if (!nuxt.options.dev && nuxt.options._generate && !config.siteUrl)
|
|
@@ -23,10 +23,11 @@ export default defineEventHandler(async (e) => {
|
|
|
23
23
|
statusMessage: `Provider ${options.provider} is missing.`
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
+
const useCache = runtimeCacheStorage && !process.dev && options.cacheTtl && options.cacheTtl > 0;
|
|
26
27
|
const cache = prefixStorage(useStorage(), "og-image-cache:images");
|
|
27
28
|
const key = options.cacheKey || e.node.req.url;
|
|
28
29
|
let png;
|
|
29
|
-
if (
|
|
30
|
+
if (useCache && await cache.hasItem(key)) {
|
|
30
31
|
const { value, expiresAt } = await cache.getItem(key);
|
|
31
32
|
if (expiresAt > Date.now()) {
|
|
32
33
|
setHeader(e, "Cache-Control", "public, max-age=31536000");
|
|
@@ -39,7 +40,7 @@ export default defineEventHandler(async (e) => {
|
|
|
39
40
|
if (!png) {
|
|
40
41
|
try {
|
|
41
42
|
png = await provider.createPng(withBase(basePath, useHostname(e)), options);
|
|
42
|
-
if (
|
|
43
|
+
if (useCache && png) {
|
|
43
44
|
const base64png = Buffer.from(png).toString("base64");
|
|
44
45
|
await cache.setItem(key, { value: base64png, expiresAt: Date.now() + (options.cacheTtl || 0) });
|
|
45
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function createBrowser(): Promise<
|
|
1
|
+
export default function createBrowser(): Promise<any>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import edgeChromium from "chrome-aws-lambda";
|
|
2
|
+
import puppeteer from "puppeteer-core";
|
|
3
3
|
export default async function createBrowser() {
|
|
4
|
-
return await
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
return await puppeteer.launch({
|
|
5
|
+
executablePath: await edgeChromium.executablePath,
|
|
6
|
+
args: edgeChromium.args,
|
|
7
7
|
headless: true
|
|
8
8
|
});
|
|
9
9
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-og-image",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.37",
|
|
5
5
|
"packageManager": "pnpm@8.1.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -84,6 +84,6 @@
|
|
|
84
84
|
"dev:build": "nuxi build .playground",
|
|
85
85
|
"dev:prepare": "nuxt-module-build --stub && nuxi prepare .playground",
|
|
86
86
|
"release": "bumpp package.json --commit --push --tag",
|
|
87
|
-
"test": "
|
|
87
|
+
"test": "vitest"
|
|
88
88
|
}
|
|
89
89
|
}
|