From db24779d0b3f07421fd7919f2c27ebb576a18fb2 Mon Sep 17 00:00:00 2001 From: Arash Ari Sheyda <38922203+arashsheyda@users.noreply.github.com> Date: Tue, 31 Mar 2026 22:59:32 -0600 Subject: [PATCH] fix: detect package manager for missing collection install suggestion --- src/runtime/server/api.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/runtime/server/api.ts b/src/runtime/server/api.ts index e3cf5f8a..6e1bad7a 100644 --- a/src/runtime/server/api.ts +++ b/src/runtime/server/api.ts @@ -12,6 +12,14 @@ const warnOnceSet = /* @__PURE__ */ new Set() const DEFAULT_ENDPOINT = 'https://api.iconify.design' +function getInstallCommand(pkg: string): string { + const ua = process.env.npm_config_user_agent || '' + if (ua.startsWith('pnpm')) return `pnpm add -D ${pkg}` + if (ua.startsWith('yarn')) return `yarn add -D ${pkg}` + if (ua.startsWith('bun')) return `bun add -D ${pkg}` + return `npm i -D ${pkg}` +} + export default defineCachedEventHandler(async (event: H3Event) => { const url = getRequestURL(event) as URL if (!url) @@ -41,7 +49,7 @@ export default defineCachedEventHandler(async (event: H3Event) => { if (collectionName && !warnOnceSet.has(collectionName) && apiEndPoint === DEFAULT_ENDPOINT) { consola.warn([ `[Icon] Collection \`${collectionName}\` is not found locally`, - `We suggest to install it via \`npm i -D @iconify-json/${collectionName}\` to provide the best end-user experience.`, + `We suggest to install it via \`${getInstallCommand(`@iconify-json/${collectionName}`)}\` to provide the best end-user experience.`, ].join('\n')) warnOnceSet.add(collectionName) }