Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/runtime/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ const warnOnceSet = /* @__PURE__ */ new Set<string>()

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)
Expand Down Expand Up @@ -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)
}
Expand Down
Loading