From 221fd85e0e87ae5efc8c8a379f128cc0563a312e Mon Sep 17 00:00:00 2001 From: Pascal Jufer Date: Fri, 16 Aug 2024 12:06:26 +0200 Subject: [PATCH 1/2] fix: correct scope for existence check of plugin deps --- src/configs/formatters.ts | 6 +++--- src/utils.ts | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/configs/formatters.ts b/src/configs/formatters.ts index 5e5a8c9b78..76cfdd81fb 100644 --- a/src/configs/formatters.ts +++ b/src/configs/formatters.ts @@ -1,7 +1,7 @@ import { isPackageExists } from 'local-pkg' import { GLOB_ASTRO, GLOB_ASTRO_TS, GLOB_CSS, GLOB_GRAPHQL, GLOB_HTML, GLOB_LESS, GLOB_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_XML } from '../globs' import type { VendoredPrettierOptions } from '../vender/prettier-types' -import { ensurePackages, interopDefault, parserPlain } from '../utils' +import { ensurePackages, interopDefault, isPackageInScope, parserPlain } from '../utils' import type { OptionsFormatters, StylisticConfig, TypedFlatConfigItem } from '../types' import { StylisticConfigDefaults } from './stylistic' @@ -11,13 +11,13 @@ export async function formatters( ): Promise { if (options === true) { options = { - astro: isPackageExists('prettier-plugin-astro'), + astro: isPackageInScope('prettier-plugin-astro'), css: true, graphql: true, html: true, markdown: true, slidev: isPackageExists('@slidev/cli'), - xml: isPackageExists('@prettier/plugin-xml'), + xml: isPackageInScope('@prettier/plugin-xml'), } } diff --git a/src/utils.ts b/src/utils.ts index 6a8a183030..d341ff08e0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -107,11 +107,19 @@ export async function interopDefault(m: Awaitable): Promise { - if (process.env.CI || process.stdout.isTTY === false) + if (process.env.CI || process.stdout.isTTY === false || isCwdInScope === false) return - const nonExistingPackages = packages.filter(i => i && !isPackageExists(i)) as string[] + const nonExistingPackages = packages.filter(i => i && !isPackageInScope(i)) as string[] if (nonExistingPackages.length === 0) return From c3a6a72639f97be49967f717df70fe151760aab3 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 16 Aug 2024 14:00:48 +0200 Subject: [PATCH 2/2] chore: refactor --- src/utils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index d341ff08e0..7c1fee8079 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,11 @@ import process from 'node:process' +import { fileURLToPath } from 'node:url' import { isPackageExists } from 'local-pkg' import type { Awaitable, TypedFlatConfigItem } from './types' +const scopeUrl = fileURLToPath(new URL('.', import.meta.url)) +const isCwdInScope = isPackageExists('@antfu/eslint-config') + export const parserPlain = { meta: { name: 'parser-plain', @@ -107,14 +111,10 @@ export async function interopDefault(m: Awaitable): Promise { if (process.env.CI || process.stdout.isTTY === false || isCwdInScope === false) return