nuxt-og-image 6.6.0 → 6.7.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.
- package/README.md +2 -0
- package/dist/chunks/tw4.cjs +7 -7
- package/dist/chunks/tw4.mjs +7 -7
- package/dist/chunks/uno.cjs +6 -6
- package/dist/chunks/uno.mjs +6 -6
- package/dist/cli.cjs +12 -5
- package/dist/cli.mjs +10 -3
- package/dist/module.cjs +5 -5
- package/dist/module.d.cts +5 -3
- package/dist/module.d.mts +5 -3
- package/dist/module.d.ts +5 -3
- package/dist/module.json +1 -1
- package/dist/module.mjs +5 -5
- package/dist/runtime/server/og-image/bindings/font-assets/cloudflare.d.ts +1 -1
- package/dist/runtime/server/og-image/bindings/font-assets/cloudflare.js +6 -1
- package/dist/runtime/server/og-image/bindings/font-assets/dev-prerender.js +13 -6
- package/dist/runtime/server/og-image/bindings/font-assets/external-url.d.ts +36 -0
- package/dist/runtime/server/og-image/bindings/font-assets/external-url.js +47 -0
- package/dist/runtime/server/og-image/bindings/font-assets/node.d.ts +1 -1
- package/dist/runtime/server/og-image/bindings/font-assets/node.js +14 -7
- package/dist/runtime/server/og-image/bindings/takumi/node-dev.js +7 -1
- package/dist/runtime/server/og-image/fonts.d.ts +4 -0
- package/dist/runtime/server/og-image/fonts.js +21 -5
- package/dist/runtime/server/og-image/satori/instances.d.ts +1 -2
- package/dist/runtime/server/og-image/takumi/renderer.js +61 -19
- package/dist/runtime/server/util/ssrf.d.ts +10 -0
- package/dist/runtime/server/util/ssrf.js +9 -1
- package/dist/runtime/types.d.ts +13 -0
- package/dist/shared/{nuxt-og-image.DdbTs-xp.mjs → nuxt-og-image.CPSxZhVO.mjs} +122 -496
- package/dist/shared/nuxt-og-image.DM30kcDz.mjs +660 -0
- package/dist/shared/nuxt-og-image.RI9DgjgV.cjs +689 -0
- package/dist/shared/{nuxt-og-image.CfTPCtaS.cjs → nuxt-og-image.yDJBWXBt.cjs} +181 -555
- package/package.json +43 -39
- package/dist/shared/nuxt-og-image.CJa2KCie.mjs +0 -189
- package/dist/shared/nuxt-og-image.CMYbz66P.cjs +0 -193
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-og-image",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.7.0",
|
|
5
5
|
"description": "Enlightened OG Image generation for Nuxt.",
|
|
6
6
|
"author": {
|
|
7
7
|
"website": "https://harlanzw.com",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@resvg/resvg-js": "^2.6.0",
|
|
52
52
|
"@resvg/resvg-wasm": "^2.6.0",
|
|
53
|
-
"@takumi-rs/core": "^1.0.0-beta.3",
|
|
54
|
-
"@takumi-rs/wasm": "^1.0.0-beta.3",
|
|
53
|
+
"@takumi-rs/core": "^1.0.0-beta.3 || ^2.0.0-beta.6",
|
|
54
|
+
"@takumi-rs/wasm": "^1.0.0-beta.3 || ^2.0.0-beta.6",
|
|
55
55
|
"@unhead/vue": "^2.0.5 || ^3.0.0",
|
|
56
56
|
"fontless": "^0.2.0",
|
|
57
57
|
"nitropack": "^2.13.4",
|
|
@@ -102,27 +102,27 @@
|
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
104
|
"dependencies": {
|
|
105
|
-
"@clack/prompts": "^1.
|
|
105
|
+
"@clack/prompts": "^1.6.0",
|
|
106
106
|
"@nuxt/kit": "^4.4.8",
|
|
107
|
-
"@unocss/config": "^66.7.
|
|
108
|
-
"@unocss/core": "^66.7.
|
|
109
|
-
"@vue/compiler-sfc": "^3.5.
|
|
107
|
+
"@unocss/config": "^66.7.2",
|
|
108
|
+
"@unocss/core": "^66.7.2",
|
|
109
|
+
"@vue/compiler-sfc": "^3.5.38",
|
|
110
110
|
"chrome-launcher": "^1.2.1",
|
|
111
111
|
"consola": "^3.4.2",
|
|
112
112
|
"culori": "^4.0.2",
|
|
113
113
|
"defu": "^6.1.7",
|
|
114
114
|
"devalue": "^5.8.1",
|
|
115
|
-
"exsolve": "^1.0
|
|
115
|
+
"exsolve": "^1.1.0",
|
|
116
116
|
"lightningcss": "^1.32.0",
|
|
117
117
|
"magic-string": "^0.30.21",
|
|
118
118
|
"magicast": "^0.5.3",
|
|
119
119
|
"mocked-exports": "^0.1.1",
|
|
120
|
-
"nuxt-site-config": "^4.0
|
|
121
|
-
"nuxtseo-shared": "^5.
|
|
122
|
-
"nypm": "^0.6.
|
|
120
|
+
"nuxt-site-config": "^4.1.0",
|
|
121
|
+
"nuxtseo-shared": "^5.3.0",
|
|
122
|
+
"nypm": "^0.6.7",
|
|
123
123
|
"ofetch": "^1.5.1",
|
|
124
124
|
"ohash": "^2.0.11",
|
|
125
|
-
"oxc-parser": "^0.
|
|
125
|
+
"oxc-parser": "^0.137.0",
|
|
126
126
|
"oxc-walker": "^1.0.0",
|
|
127
127
|
"pathe": "^2.0.3",
|
|
128
128
|
"pkg-types": "^2.3.1",
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
"@iconify-json/ri": "^1.2.10",
|
|
145
145
|
"@iconify-json/tabler": "^1.2.35",
|
|
146
146
|
"@iconify/types": "^2.0.0",
|
|
147
|
-
"@img/sharp-linux-x64": "^0.
|
|
147
|
+
"@img/sharp-linux-x64": "^0.35.2",
|
|
148
148
|
"@nuxt/content": "^3.14.0",
|
|
149
149
|
"@nuxt/devtools": "4.0.0-alpha.7",
|
|
150
150
|
"@nuxt/devtools-kit": "4.0.0-alpha.7",
|
|
@@ -153,55 +153,56 @@
|
|
|
153
153
|
"@nuxt/image": "^2.0.0",
|
|
154
154
|
"@nuxt/module-builder": "^1.0.2",
|
|
155
155
|
"@nuxt/test-utils": "^4.0.3",
|
|
156
|
-
"@nuxt/ui": "^4.
|
|
156
|
+
"@nuxt/ui": "^4.9.0",
|
|
157
157
|
"@nuxtjs/color-mode": "^4.0.1",
|
|
158
158
|
"@nuxtjs/eslint-config-typescript": "^12.1.0",
|
|
159
159
|
"@nuxtjs/i18n": "^10.4.0",
|
|
160
160
|
"@nuxtjs/tailwindcss": "7.0.0-beta.1",
|
|
161
161
|
"@resvg/resvg-js": "^2.6.2",
|
|
162
162
|
"@resvg/resvg-wasm": "^2.6.2",
|
|
163
|
-
"@
|
|
164
|
-
"@
|
|
165
|
-
"@
|
|
166
|
-
"@takumi-rs/
|
|
167
|
-
"@takumi-rs/helpers": "
|
|
168
|
-
"@takumi-rs/wasm": "^
|
|
169
|
-
"@
|
|
170
|
-
"@unocss/
|
|
171
|
-
"@unocss/preset-
|
|
172
|
-
"@unocss/preset-
|
|
163
|
+
"@tailwindcss/vite": "^4.3.1",
|
|
164
|
+
"@takumi-rs/core": "^2.0.0-beta.6",
|
|
165
|
+
"@takumi-rs/core-v1": "npm:@takumi-rs/core@1.8.7",
|
|
166
|
+
"@takumi-rs/helpers": "^2.0.0-beta.6",
|
|
167
|
+
"@takumi-rs/helpers-v1": "npm:@takumi-rs/helpers@1.8.7",
|
|
168
|
+
"@takumi-rs/wasm": "^2.0.0-beta.6",
|
|
169
|
+
"@takumi-rs/wasm-v1": "npm:@takumi-rs/wasm@1.8.7",
|
|
170
|
+
"@unocss/nuxt": "^66.7.2",
|
|
171
|
+
"@unocss/preset-icons": "^66.7.2",
|
|
172
|
+
"@unocss/preset-wind": "^66.7.2",
|
|
173
|
+
"@unocss/preset-wind4": "^66.7.2",
|
|
173
174
|
"@vitejs/plugin-vue": "^6.0.7",
|
|
174
|
-
"@vue/compiler-core": "^3.5.
|
|
175
|
+
"@vue/compiler-core": "^3.5.38",
|
|
175
176
|
"@vueuse/nuxt": "^14.3.0",
|
|
176
177
|
"birpc": "^4.0.0",
|
|
177
178
|
"bumpp": "^11.1.0",
|
|
178
|
-
"eslint": "^10.
|
|
179
|
+
"eslint": "^10.5.0",
|
|
179
180
|
"eslint-plugin-harlanzw": "^0.17.0",
|
|
180
181
|
"fontless": "^0.2.1",
|
|
181
182
|
"get-image-colors": "^4.0.1",
|
|
182
183
|
"globby": "^16.2.0",
|
|
183
|
-
"happy-dom": "^20.10.
|
|
184
|
+
"happy-dom": "^20.10.6",
|
|
184
185
|
"hookable": "^6.1.1",
|
|
185
186
|
"jest-image-snapshot": "^6.5.2",
|
|
186
187
|
"lightningcss": "^1.32.0",
|
|
187
188
|
"nitropack": "^2.13.4",
|
|
188
189
|
"nuxt": "^4.4.8",
|
|
189
|
-
"nuxtseo-layer-devtools": "^5.
|
|
190
|
-
"playwright": "^1.
|
|
191
|
-
"playwright-core": "^1.
|
|
192
|
-
"sass": "^1.
|
|
190
|
+
"nuxtseo-layer-devtools": "^5.3.0",
|
|
191
|
+
"playwright": "^1.61.0",
|
|
192
|
+
"playwright-core": "^1.61.0",
|
|
193
|
+
"sass": "^1.101.0",
|
|
193
194
|
"satori": "^0.26.0",
|
|
194
|
-
"sharp": "^0.
|
|
195
|
+
"sharp": "^0.35.2",
|
|
195
196
|
"sirv": "^3.0.2",
|
|
196
|
-
"tailwindcss": "^4.3.
|
|
197
|
+
"tailwindcss": "^4.3.1",
|
|
197
198
|
"typescript": "^6.0.3",
|
|
198
199
|
"unbuild": "^3.6.1",
|
|
199
200
|
"unifont": "^0.7.4",
|
|
200
|
-
"unocss": "^66.7.
|
|
201
|
-
"vitest": "^4.1.
|
|
202
|
-
"vue": "^3.5.
|
|
203
|
-
"vue-tsc": "^3.3.
|
|
204
|
-
"wrangler": "^4.
|
|
201
|
+
"unocss": "^66.7.2",
|
|
202
|
+
"vitest": "^4.1.9",
|
|
203
|
+
"vue": "^3.5.38",
|
|
204
|
+
"vue-tsc": "^3.3.5",
|
|
205
|
+
"wrangler": "^4.103.0",
|
|
205
206
|
"yoga-wasm-web": "^0.3.3",
|
|
206
207
|
"zod": "^4.4.3"
|
|
207
208
|
},
|
|
@@ -220,6 +221,9 @@
|
|
|
220
221
|
"release": "pnpm build && bumpp -x \"npx changelogen --output=CHANGELOG.md\"",
|
|
221
222
|
"typecheck": "nuxt-module-build prepare && nuxt typecheck",
|
|
222
223
|
"test": "pnpm run prepare:fixtures && vitest",
|
|
223
|
-
"test:chrome": "HAS_CHROME=true vitest"
|
|
224
|
+
"test:chrome": "HAS_CHROME=true vitest",
|
|
225
|
+
"test:takumi:e2e": "node scripts/test-takumi-e2e.mjs",
|
|
226
|
+
"test:takumi:e2e:matrix": "node scripts/test-takumi-e2e.mjs --matrix",
|
|
227
|
+
"test:takumi:e2e:compare": "node scripts/test-takumi-e2e.mjs --compare"
|
|
224
228
|
}
|
|
225
229
|
}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { loadFile, writeFile } from 'magicast';
|
|
3
|
-
import { addNuxtModule } from 'magicast/helpers';
|
|
4
|
-
import { join } from 'pathe';
|
|
5
|
-
import { logger } from '../../dist/runtime/logger.js';
|
|
6
|
-
|
|
7
|
-
function parseFontString(font) {
|
|
8
|
-
const parts = font.split(":");
|
|
9
|
-
if (parts.length === 3) {
|
|
10
|
-
return {
|
|
11
|
-
name: parts[0] || font,
|
|
12
|
-
style: parts[1] === "ital" ? "italic" : "normal",
|
|
13
|
-
weight: Number.parseInt(parts[2] || "") || 400
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
return {
|
|
17
|
-
name: parts[0] || font,
|
|
18
|
-
weight: Number.parseInt(parts[1] || "") || 400,
|
|
19
|
-
style: "normal"
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function groupFontsByFamily(fonts) {
|
|
23
|
-
const families = /* @__PURE__ */ new Map();
|
|
24
|
-
for (const font of fonts) {
|
|
25
|
-
const parsed = parseFontString(font);
|
|
26
|
-
const existing = families.get(parsed.name);
|
|
27
|
-
if (existing) {
|
|
28
|
-
existing.weights.add(parsed.weight);
|
|
29
|
-
existing.styles.add(parsed.style);
|
|
30
|
-
} else {
|
|
31
|
-
families.set(parsed.name, {
|
|
32
|
-
weights: /* @__PURE__ */ new Set([parsed.weight]),
|
|
33
|
-
styles: /* @__PURE__ */ new Set([parsed.style])
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return Array.from(families.entries(), ([name, { weights, styles }]) => ({
|
|
38
|
-
name,
|
|
39
|
-
weights: [...weights].toSorted((a, b) => a - b),
|
|
40
|
-
styles: [...styles]
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
async function migrateFontsConfig(rootDir) {
|
|
44
|
-
const configPaths = [
|
|
45
|
-
"nuxt.config.ts",
|
|
46
|
-
"nuxt.config.js",
|
|
47
|
-
"nuxt.config.mjs"
|
|
48
|
-
];
|
|
49
|
-
let configPath;
|
|
50
|
-
for (const p of configPaths) {
|
|
51
|
-
const fullPath = join(rootDir, p);
|
|
52
|
-
if (existsSync(fullPath)) {
|
|
53
|
-
configPath = fullPath;
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (!configPath) {
|
|
58
|
-
return { migrated: false, message: "No nuxt.config found" };
|
|
59
|
-
}
|
|
60
|
-
const mod = await loadFile(configPath);
|
|
61
|
-
const config = mod.exports.default;
|
|
62
|
-
if (!config?.ogImage?.fonts) {
|
|
63
|
-
return { migrated: false, message: "No ogImage.fonts config found" };
|
|
64
|
-
}
|
|
65
|
-
const oldFonts = config.ogImage.fonts;
|
|
66
|
-
if (!Array.isArray(oldFonts) || oldFonts.length === 0) {
|
|
67
|
-
return { migrated: false, message: "ogImage.fonts is empty or invalid" };
|
|
68
|
-
}
|
|
69
|
-
const groupedFonts = groupFontsByFamily(oldFonts);
|
|
70
|
-
if (!config.fonts) {
|
|
71
|
-
config.fonts = {};
|
|
72
|
-
}
|
|
73
|
-
if (!config.fonts.families) {
|
|
74
|
-
config.fonts.families = [];
|
|
75
|
-
}
|
|
76
|
-
const existingFamilies = config.fonts.families;
|
|
77
|
-
for (const font of groupedFonts) {
|
|
78
|
-
const existing = existingFamilies.find((f) => f.name === font.name);
|
|
79
|
-
if (existing) {
|
|
80
|
-
const existingWeights = new Set(existing.weights || []);
|
|
81
|
-
for (const w of font.weights) {
|
|
82
|
-
existingWeights.add(w);
|
|
83
|
-
}
|
|
84
|
-
existing.weights = [...existingWeights].toSorted((a, b) => a - b);
|
|
85
|
-
if (font.styles.includes("italic")) {
|
|
86
|
-
const existingStyles = new Set(existing.styles || ["normal"]);
|
|
87
|
-
existingStyles.add("italic");
|
|
88
|
-
existing.styles = [...existingStyles];
|
|
89
|
-
}
|
|
90
|
-
existing.global = true;
|
|
91
|
-
} else {
|
|
92
|
-
const family = {
|
|
93
|
-
name: font.name,
|
|
94
|
-
weights: font.weights,
|
|
95
|
-
global: true
|
|
96
|
-
};
|
|
97
|
-
if (font.styles.includes("italic")) {
|
|
98
|
-
family.styles = font.styles;
|
|
99
|
-
}
|
|
100
|
-
existingFamilies.push(family);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
addNuxtModule(mod, "@nuxt/fonts");
|
|
104
|
-
delete config.ogImage.fonts;
|
|
105
|
-
if (Object.keys(config.ogImage).length === 0) {
|
|
106
|
-
delete config.ogImage;
|
|
107
|
-
}
|
|
108
|
-
await writeFile(mod, configPath);
|
|
109
|
-
const familyNames = groupedFonts.map((f) => f.name).join(", ");
|
|
110
|
-
return {
|
|
111
|
-
migrated: true,
|
|
112
|
-
message: `Migrated fonts (${familyNames}) from ogImage.fonts to @nuxt/fonts`
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
async function migrateDefaultsComponent(rootDir) {
|
|
116
|
-
const configPaths = [
|
|
117
|
-
"nuxt.config.ts",
|
|
118
|
-
"nuxt.config.js",
|
|
119
|
-
"nuxt.config.mjs"
|
|
120
|
-
];
|
|
121
|
-
let configPath;
|
|
122
|
-
for (const cp of configPaths) {
|
|
123
|
-
const fullPath = join(rootDir, cp);
|
|
124
|
-
if (existsSync(fullPath)) {
|
|
125
|
-
configPath = fullPath;
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (!configPath)
|
|
130
|
-
return { migrated: false, componentName: null, message: "No nuxt.config found" };
|
|
131
|
-
const mod = await loadFile(configPath);
|
|
132
|
-
const config = mod.exports.default;
|
|
133
|
-
if (!config?.ogImage?.defaults?.component)
|
|
134
|
-
return { migrated: false, componentName: null, message: "No defaults.component found" };
|
|
135
|
-
const componentName = String(config.ogImage.defaults.component);
|
|
136
|
-
delete config.ogImage.defaults.component;
|
|
137
|
-
if (config.ogImage.defaults && Object.keys(config.ogImage.defaults).length === 0)
|
|
138
|
-
delete config.ogImage.defaults;
|
|
139
|
-
if (config.ogImage && Object.keys(config.ogImage).length === 0)
|
|
140
|
-
delete config.ogImage;
|
|
141
|
-
await writeFile(mod, configPath);
|
|
142
|
-
return { migrated: true, componentName, message: `Removed defaults.component: '${componentName}'` };
|
|
143
|
-
}
|
|
144
|
-
async function promptFontsMigration(rootDir) {
|
|
145
|
-
logger.info("");
|
|
146
|
-
logger.info("Detected deprecated ogImage.fonts configuration.");
|
|
147
|
-
logger.info("");
|
|
148
|
-
logger.info("Inter fonts now work out of the box without any configuration.");
|
|
149
|
-
logger.info("For custom fonts, use @nuxt/fonts:");
|
|
150
|
-
logger.info("");
|
|
151
|
-
logger.info("Before:");
|
|
152
|
-
logger.info(" ogImage: {");
|
|
153
|
-
logger.info(" fonts: ['Inter:400', 'Inter:700']");
|
|
154
|
-
logger.info(" }");
|
|
155
|
-
logger.info("");
|
|
156
|
-
logger.info("After (Inter only): Remove the config entirely \u2014 it works by default.");
|
|
157
|
-
logger.info("");
|
|
158
|
-
logger.info("After (custom fonts):");
|
|
159
|
-
logger.info(" modules: ['@nuxt/fonts', 'nuxt-og-image'],");
|
|
160
|
-
logger.info(" fonts: {");
|
|
161
|
-
logger.info(" families: [");
|
|
162
|
-
logger.info(" { name: 'Roboto', weights: [400, 700], global: true }");
|
|
163
|
-
logger.info(" ]");
|
|
164
|
-
logger.info(" }");
|
|
165
|
-
logger.info("");
|
|
166
|
-
const migrate = await logger.prompt("Automatically migrate nuxt.config?", {
|
|
167
|
-
type: "confirm",
|
|
168
|
-
initial: true
|
|
169
|
-
});
|
|
170
|
-
if (migrate) {
|
|
171
|
-
const result = await migrateFontsConfig(rootDir).catch((err) => {
|
|
172
|
-
logger.error(`Migration failed: ${err.message}`);
|
|
173
|
-
return { migrated: false, message: err.message };
|
|
174
|
-
});
|
|
175
|
-
if (result.migrated) {
|
|
176
|
-
logger.success(result.message);
|
|
177
|
-
logger.info("");
|
|
178
|
-
logger.info("Please install @nuxt/fonts:");
|
|
179
|
-
logger.info(" npm add @nuxt/fonts");
|
|
180
|
-
} else {
|
|
181
|
-
logger.warn(`Could not migrate: ${result.message}`);
|
|
182
|
-
logger.info("Please migrate manually.");
|
|
183
|
-
}
|
|
184
|
-
} else {
|
|
185
|
-
logger.info("Skipping automatic migration. Please migrate manually.");
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export { migrateFontsConfig as a, migrateDefaultsComponent as m, promptFontsMigration as p };
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs');
|
|
4
|
-
const magicast = require('magicast');
|
|
5
|
-
const helpers = require('magicast/helpers');
|
|
6
|
-
const pathe = require('pathe');
|
|
7
|
-
const logger_js = require('../../dist/runtime/logger.js');
|
|
8
|
-
|
|
9
|
-
function parseFontString(font) {
|
|
10
|
-
const parts = font.split(":");
|
|
11
|
-
if (parts.length === 3) {
|
|
12
|
-
return {
|
|
13
|
-
name: parts[0] || font,
|
|
14
|
-
style: parts[1] === "ital" ? "italic" : "normal",
|
|
15
|
-
weight: Number.parseInt(parts[2] || "") || 400
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
name: parts[0] || font,
|
|
20
|
-
weight: Number.parseInt(parts[1] || "") || 400,
|
|
21
|
-
style: "normal"
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function groupFontsByFamily(fonts) {
|
|
25
|
-
const families = /* @__PURE__ */ new Map();
|
|
26
|
-
for (const font of fonts) {
|
|
27
|
-
const parsed = parseFontString(font);
|
|
28
|
-
const existing = families.get(parsed.name);
|
|
29
|
-
if (existing) {
|
|
30
|
-
existing.weights.add(parsed.weight);
|
|
31
|
-
existing.styles.add(parsed.style);
|
|
32
|
-
} else {
|
|
33
|
-
families.set(parsed.name, {
|
|
34
|
-
weights: /* @__PURE__ */ new Set([parsed.weight]),
|
|
35
|
-
styles: /* @__PURE__ */ new Set([parsed.style])
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return Array.from(families.entries(), ([name, { weights, styles }]) => ({
|
|
40
|
-
name,
|
|
41
|
-
weights: [...weights].toSorted((a, b) => a - b),
|
|
42
|
-
styles: [...styles]
|
|
43
|
-
}));
|
|
44
|
-
}
|
|
45
|
-
async function migrateFontsConfig(rootDir) {
|
|
46
|
-
const configPaths = [
|
|
47
|
-
"nuxt.config.ts",
|
|
48
|
-
"nuxt.config.js",
|
|
49
|
-
"nuxt.config.mjs"
|
|
50
|
-
];
|
|
51
|
-
let configPath;
|
|
52
|
-
for (const p of configPaths) {
|
|
53
|
-
const fullPath = pathe.join(rootDir, p);
|
|
54
|
-
if (fs.existsSync(fullPath)) {
|
|
55
|
-
configPath = fullPath;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (!configPath) {
|
|
60
|
-
return { migrated: false, message: "No nuxt.config found" };
|
|
61
|
-
}
|
|
62
|
-
const mod = await magicast.loadFile(configPath);
|
|
63
|
-
const config = mod.exports.default;
|
|
64
|
-
if (!config?.ogImage?.fonts) {
|
|
65
|
-
return { migrated: false, message: "No ogImage.fonts config found" };
|
|
66
|
-
}
|
|
67
|
-
const oldFonts = config.ogImage.fonts;
|
|
68
|
-
if (!Array.isArray(oldFonts) || oldFonts.length === 0) {
|
|
69
|
-
return { migrated: false, message: "ogImage.fonts is empty or invalid" };
|
|
70
|
-
}
|
|
71
|
-
const groupedFonts = groupFontsByFamily(oldFonts);
|
|
72
|
-
if (!config.fonts) {
|
|
73
|
-
config.fonts = {};
|
|
74
|
-
}
|
|
75
|
-
if (!config.fonts.families) {
|
|
76
|
-
config.fonts.families = [];
|
|
77
|
-
}
|
|
78
|
-
const existingFamilies = config.fonts.families;
|
|
79
|
-
for (const font of groupedFonts) {
|
|
80
|
-
const existing = existingFamilies.find((f) => f.name === font.name);
|
|
81
|
-
if (existing) {
|
|
82
|
-
const existingWeights = new Set(existing.weights || []);
|
|
83
|
-
for (const w of font.weights) {
|
|
84
|
-
existingWeights.add(w);
|
|
85
|
-
}
|
|
86
|
-
existing.weights = [...existingWeights].toSorted((a, b) => a - b);
|
|
87
|
-
if (font.styles.includes("italic")) {
|
|
88
|
-
const existingStyles = new Set(existing.styles || ["normal"]);
|
|
89
|
-
existingStyles.add("italic");
|
|
90
|
-
existing.styles = [...existingStyles];
|
|
91
|
-
}
|
|
92
|
-
existing.global = true;
|
|
93
|
-
} else {
|
|
94
|
-
const family = {
|
|
95
|
-
name: font.name,
|
|
96
|
-
weights: font.weights,
|
|
97
|
-
global: true
|
|
98
|
-
};
|
|
99
|
-
if (font.styles.includes("italic")) {
|
|
100
|
-
family.styles = font.styles;
|
|
101
|
-
}
|
|
102
|
-
existingFamilies.push(family);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
helpers.addNuxtModule(mod, "@nuxt/fonts");
|
|
106
|
-
delete config.ogImage.fonts;
|
|
107
|
-
if (Object.keys(config.ogImage).length === 0) {
|
|
108
|
-
delete config.ogImage;
|
|
109
|
-
}
|
|
110
|
-
await magicast.writeFile(mod, configPath);
|
|
111
|
-
const familyNames = groupedFonts.map((f) => f.name).join(", ");
|
|
112
|
-
return {
|
|
113
|
-
migrated: true,
|
|
114
|
-
message: `Migrated fonts (${familyNames}) from ogImage.fonts to @nuxt/fonts`
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
async function migrateDefaultsComponent(rootDir) {
|
|
118
|
-
const configPaths = [
|
|
119
|
-
"nuxt.config.ts",
|
|
120
|
-
"nuxt.config.js",
|
|
121
|
-
"nuxt.config.mjs"
|
|
122
|
-
];
|
|
123
|
-
let configPath;
|
|
124
|
-
for (const cp of configPaths) {
|
|
125
|
-
const fullPath = pathe.join(rootDir, cp);
|
|
126
|
-
if (fs.existsSync(fullPath)) {
|
|
127
|
-
configPath = fullPath;
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (!configPath)
|
|
132
|
-
return { migrated: false, componentName: null, message: "No nuxt.config found" };
|
|
133
|
-
const mod = await magicast.loadFile(configPath);
|
|
134
|
-
const config = mod.exports.default;
|
|
135
|
-
if (!config?.ogImage?.defaults?.component)
|
|
136
|
-
return { migrated: false, componentName: null, message: "No defaults.component found" };
|
|
137
|
-
const componentName = String(config.ogImage.defaults.component);
|
|
138
|
-
delete config.ogImage.defaults.component;
|
|
139
|
-
if (config.ogImage.defaults && Object.keys(config.ogImage.defaults).length === 0)
|
|
140
|
-
delete config.ogImage.defaults;
|
|
141
|
-
if (config.ogImage && Object.keys(config.ogImage).length === 0)
|
|
142
|
-
delete config.ogImage;
|
|
143
|
-
await magicast.writeFile(mod, configPath);
|
|
144
|
-
return { migrated: true, componentName, message: `Removed defaults.component: '${componentName}'` };
|
|
145
|
-
}
|
|
146
|
-
async function promptFontsMigration(rootDir) {
|
|
147
|
-
logger_js.logger.info("");
|
|
148
|
-
logger_js.logger.info("Detected deprecated ogImage.fonts configuration.");
|
|
149
|
-
logger_js.logger.info("");
|
|
150
|
-
logger_js.logger.info("Inter fonts now work out of the box without any configuration.");
|
|
151
|
-
logger_js.logger.info("For custom fonts, use @nuxt/fonts:");
|
|
152
|
-
logger_js.logger.info("");
|
|
153
|
-
logger_js.logger.info("Before:");
|
|
154
|
-
logger_js.logger.info(" ogImage: {");
|
|
155
|
-
logger_js.logger.info(" fonts: ['Inter:400', 'Inter:700']");
|
|
156
|
-
logger_js.logger.info(" }");
|
|
157
|
-
logger_js.logger.info("");
|
|
158
|
-
logger_js.logger.info("After (Inter only): Remove the config entirely \u2014 it works by default.");
|
|
159
|
-
logger_js.logger.info("");
|
|
160
|
-
logger_js.logger.info("After (custom fonts):");
|
|
161
|
-
logger_js.logger.info(" modules: ['@nuxt/fonts', 'nuxt-og-image'],");
|
|
162
|
-
logger_js.logger.info(" fonts: {");
|
|
163
|
-
logger_js.logger.info(" families: [");
|
|
164
|
-
logger_js.logger.info(" { name: 'Roboto', weights: [400, 700], global: true }");
|
|
165
|
-
logger_js.logger.info(" ]");
|
|
166
|
-
logger_js.logger.info(" }");
|
|
167
|
-
logger_js.logger.info("");
|
|
168
|
-
const migrate = await logger_js.logger.prompt("Automatically migrate nuxt.config?", {
|
|
169
|
-
type: "confirm",
|
|
170
|
-
initial: true
|
|
171
|
-
});
|
|
172
|
-
if (migrate) {
|
|
173
|
-
const result = await migrateFontsConfig(rootDir).catch((err) => {
|
|
174
|
-
logger_js.logger.error(`Migration failed: ${err.message}`);
|
|
175
|
-
return { migrated: false, message: err.message };
|
|
176
|
-
});
|
|
177
|
-
if (result.migrated) {
|
|
178
|
-
logger_js.logger.success(result.message);
|
|
179
|
-
logger_js.logger.info("");
|
|
180
|
-
logger_js.logger.info("Please install @nuxt/fonts:");
|
|
181
|
-
logger_js.logger.info(" npm add @nuxt/fonts");
|
|
182
|
-
} else {
|
|
183
|
-
logger_js.logger.warn(`Could not migrate: ${result.message}`);
|
|
184
|
-
logger_js.logger.info("Please migrate manually.");
|
|
185
|
-
}
|
|
186
|
-
} else {
|
|
187
|
-
logger_js.logger.info("Skipping automatic migration. Please migrate manually.");
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
exports.migrateDefaultsComponent = migrateDefaultsComponent;
|
|
192
|
-
exports.migrateFontsConfig = migrateFontsConfig;
|
|
193
|
-
exports.promptFontsMigration = promptFontsMigration;
|