Skip to content

Commit

Permalink
fix(preset-icons): force to not warn in ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 23, 2024
1 parent e29f5de commit 93bfc35
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
19 changes: 18 additions & 1 deletion packages/preset-icons/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export function createPresetIcons(lookupIconLoader: (options: IconsOptions) => P
unit,
} = options

const flags = getEnvFlags()

const loaderOptions: IconifyLoaderOptions = {
addXmlNs: true,
scale,
Expand Down Expand Up @@ -86,7 +88,7 @@ export function createPresetIcons(lookupIconLoader: (options: IconsOptions) => P
}

if (!svg) {
if (warn)
if (warn && !flags.isESLint)
warnOnce(`failed to load icon "${full}"`)
return
}
Expand Down Expand Up @@ -167,3 +169,18 @@ export function createCDNFetchLoader(fetcher: (url: string) => Promise<any>, cdn
return result
}
}

export function getEnvFlags() {
// eslint-disable-next-line node/prefer-global/process
const isNode = typeof process !== 'undefined' && process.stdout && !process.versions.deno
// eslint-disable-next-line node/prefer-global/process
const isVSCode = isNode && !!process.env.VSCODE_CWD
// eslint-disable-next-line node/prefer-global/process
const isESLint = isNode && !!process.env.ESLINT

return {
isNode,
isVSCode,
isESLint,
}
}
15 changes: 7 additions & 8 deletions packages/preset-icons/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { UniversalIconLoader } from '@iconify/utils'
import { loadIcon } from '@iconify/utils'
import { createCDNLoader } from './cdn'
import { combineLoaders, createPresetIcons } from './core'
import { combineLoaders, createPresetIcons, getEnvFlags } from './core'

export * from './core'

Expand All @@ -17,19 +17,18 @@ async function createNodeLoader() {
catch { }
}

export const presetIcons = createPresetIcons(async (options) => {
export const presetIcons = /* @__PURE__ */ createPresetIcons(async (options) => {
const {
cdn,
} = options

const loaders: UniversalIconLoader[] = []

// eslint-disable-next-line node/prefer-global/process
const isNode = typeof process !== 'undefined' && process.stdout && !process.versions.deno
// eslint-disable-next-line node/prefer-global/process
const isVSCode = isNode && !!process.env.VSCODE_CWD
// eslint-disable-next-line node/prefer-global/process
const isESLint = isNode && !!process.env.ESLINT
const {
isNode,
isVSCode,
isESLint,
} = getEnvFlags()

if (isNode && !isVSCode && !isESLint) {
const nodeLoader = await createNodeLoader()
Expand Down

0 comments on commit 93bfc35

Please sign in to comment.