From 07d37ae3aaf3ac013c95295169b505755a4ddd9d Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Tue, 6 Aug 2024 22:11:39 +1200 Subject: [PATCH] fix: make more dependencies peer dependencies and allow auto installing them as needed --- package.json | 12 ++++++++---- pnpm-lock.yaml | 18 +++++++++--------- src/configs/markdown.ts | 9 +++++---- src/configs/vue.ts | 32 +++++++++++++++++++------------- src/factory.ts | 19 +++++++++++++++---- 5 files changed, 56 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index e41dce7f..503773ea 100644 --- a/package.json +++ b/package.json @@ -49,10 +49,7 @@ "dependencies": { "@antfu/install-pkg": "^0.3.3", "@clack/prompts": "^0.7.0", - "eslint-flat-config-utils": "^0.3.0", - "eslint-merge-processors": "^0.1.0", - "globals": "^15.9.0", - "local-pkg": "^0.5.0" + "globals": "^15.9.0" }, "devDependencies": { "@commitlint/cli": "19.3.0", @@ -80,7 +77,9 @@ "deassert": "1.0.2", "eslint": "9.8.0", "eslint-config-prettier": "9.1.0", + "eslint-flat-config-utils": "^0.3.0", "eslint-import-resolver-typescript": "3.6.1", + "eslint-merge-processors": "^0.1.0", "eslint-plugin-eslint-comments": "3.2.0", "eslint-plugin-format": "0.1.2", "eslint-plugin-functional": "7.0.0-rc.1", @@ -107,6 +106,7 @@ "jsonc-eslint-parser": "2.4.0", "knip": "5.27.0", "lint-staged": "15.2.8", + "local-pkg": "^0.5.0", "markdownlint": "0.34.0", "markdownlint-cli": "0.41.0", "prettier": "3.3.3", @@ -154,6 +154,7 @@ "eslint-plugin-yml": "*", "eslint-processor-vue-blocks": "*", "jsonc-eslint-parser": "*", + "local-pkg": "*", "prettier": "*", "prettier-plugin-packagejson": "*", "toml-eslint-parser": "*", @@ -164,6 +165,9 @@ "@stylistic/eslint-plugin": { "optional": true }, + "local-pkg": { + "optional": true + }, "@typescript-eslint/eslint-plugin": { "optional": true }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 89f9be4a..b3f3ba9d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,18 +14,9 @@ importers: '@clack/prompts': specifier: ^0.7.0 version: 0.7.0 - eslint-flat-config-utils: - specifier: ^0.3.0 - version: 0.3.0 - eslint-merge-processors: - specifier: ^0.1.0 - version: 0.1.0(eslint@9.8.0) globals: specifier: ^15.9.0 version: 15.9.0 - local-pkg: - specifier: ^0.5.0 - version: 0.5.0 devDependencies: '@commitlint/cli': specifier: 19.3.0 @@ -102,9 +93,15 @@ importers: eslint-config-prettier: specifier: 9.1.0 version: 9.1.0(eslint@9.8.0) + eslint-flat-config-utils: + specifier: ^0.3.0 + version: 0.3.0 eslint-import-resolver-typescript: specifier: 3.6.1 version: 3.6.1(@typescript-eslint/parser@8.0.1(eslint@9.8.0)(typescript@5.4.5))(eslint-plugin-import@2.29.1)(eslint@9.8.0) + eslint-merge-processors: + specifier: ^0.1.0 + version: 0.1.0(eslint@9.8.0) eslint-plugin-eslint-comments: specifier: 3.2.0 version: 3.2.0(eslint@9.8.0) @@ -183,6 +180,9 @@ importers: lint-staged: specifier: 15.2.8 version: 15.2.8 + local-pkg: + specifier: ^0.5.0 + version: 0.5.0 markdownlint: specifier: 0.34.0 version: 0.34.0 diff --git a/src/configs/markdown.ts b/src/configs/markdown.ts index 83f4bc40..2bc41e4c 100644 --- a/src/configs/markdown.ts +++ b/src/configs/markdown.ts @@ -1,5 +1,4 @@ import type { ESLint, Linter } from "eslint"; -import { mergeProcessors, processorPassThrough } from "eslint-merge-processors"; import { GLOB_MARKDOWN, @@ -27,9 +26,11 @@ export async function markdown( ): Promise { const { componentExts, files, overrides, enableTypeRequiredRules } = options; - const [pluginMarkdown] = (await loadPackages(["eslint-plugin-markdown"])) as [ - ESLint.Plugin, - ]; + const [pluginMarkdown, { mergeProcessors, processorPassThrough }] = + (await loadPackages([ + "eslint-plugin-markdown", + "eslint-merge-processors", + ])) as [ESLint.Plugin, typeof import("eslint-merge-processors")]; const [pluginTs, pluginFunctional] = await Promise.all([ interopDefault(import("@typescript-eslint/eslint-plugin")).catch( diff --git a/src/configs/vue.ts b/src/configs/vue.ts index 1ebc727b..e3ea2a2f 100644 --- a/src/configs/vue.ts +++ b/src/configs/vue.ts @@ -1,5 +1,4 @@ import type { ESLint, Linter } from "eslint"; -import { mergeProcessors } from "eslint-merge-processors"; import type { FlatConfigItem, @@ -52,18 +51,25 @@ export async function vue( const { indent = 2 } = typeof stylistic === "boolean" ? {} : stylistic; - const [pluginVue, pluginVueI18n, parserVue, processorVueBlocks] = - (await loadPackages([ - "eslint-plugin-vue", - "@intlify/eslint-plugin-vue-i18n", - "vue-eslint-parser", - "eslint-processor-vue-blocks", - ])) as [ - PluginVue, - ESLint.Plugin, - typeof import("vue-eslint-parser"), - (typeof import("eslint-processor-vue-blocks"))["default"], - ]; + const [ + pluginVue, + pluginVueI18n, + parserVue, + processorVueBlocks, + { mergeProcessors }, + ] = (await loadPackages([ + "eslint-plugin-vue", + "@intlify/eslint-plugin-vue-i18n", + "vue-eslint-parser", + "eslint-processor-vue-blocks", + "eslint-merge-processors", + ])) as [ + PluginVue, + ESLint.Plugin, + typeof import("vue-eslint-parser"), + (typeof import("eslint-processor-vue-blocks"))["default"], + typeof import("eslint-merge-processors"), + ]; const parserTs = await interopDefault( import("@typescript-eslint/parser"), diff --git a/src/factory.ts b/src/factory.ts index 2c9ecc7f..2168ac33 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -1,7 +1,6 @@ import * as path from "node:path"; -import { FlatConfigComposer } from "eslint-flat-config-utils"; -import { isPackageExists } from "local-pkg"; +import type { FlatConfigComposer } from "eslint-flat-config-utils"; import { StylisticConfigDefaults, @@ -55,6 +54,7 @@ import type { OptionsTypeScriptShorthands, OptionsTypescript, } from "./types"; +import { loadPackages } from "./utils"; const VuePackages = ["vue", "nuxt", "vitepress", "@slidev/cli"]; @@ -77,10 +77,21 @@ export const defaultPluginRenaming = { * @param {Awaitable[]} userConfigs - The user configurations to be merged with the generated configurations. * @returns {Promise} The merged ESLint configurations. */ -export function rsEslint( +export async function rsEslint( options: OptionsConfig, ...userConfigs: ReadonlyArray> -): FlatConfigComposer { +): Promise> { + const [FlatConfigComposer, isPackageExists] = await loadPackages([ + "eslint-flat-config-utils", + "local-pkg", + ]).then( + ([a, b]) => + [ + (a as typeof import("eslint-flat-config-utils")).FlatConfigComposer, + (b as typeof import("local-pkg")).isPackageExists, + ] as const, + ); + const { autoRenamePlugins = true, componentExts = [],