Skip to content

Commit

Permalink
fix: make more dependencies peer dependencies and allow auto installi…
Browse files Browse the repository at this point in the history
…ng them as needed
  • Loading branch information
RebeccaStevens committed Aug 6, 2024
1 parent c596538 commit 07d37ae
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 34 deletions.
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -154,6 +154,7 @@
"eslint-plugin-yml": "*",
"eslint-processor-vue-blocks": "*",
"jsonc-eslint-parser": "*",
"local-pkg": "*",
"prettier": "*",
"prettier-plugin-packagejson": "*",
"toml-eslint-parser": "*",
Expand All @@ -164,6 +165,9 @@
"@stylistic/eslint-plugin": {
"optional": true
},
"local-pkg": {
"optional": true
},
"@typescript-eslint/eslint-plugin": {
"optional": true
},
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions src/configs/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ESLint, Linter } from "eslint";
import { mergeProcessors, processorPassThrough } from "eslint-merge-processors";

import {
GLOB_MARKDOWN,
Expand Down Expand Up @@ -27,9 +26,11 @@ export async function markdown(
): Promise<FlatConfigItem[]> {
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(
Expand Down
32 changes: 19 additions & 13 deletions src/configs/vue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ESLint, Linter } from "eslint";
import { mergeProcessors } from "eslint-merge-processors";

import type {
FlatConfigItem,
Expand Down Expand Up @@ -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"),
Expand Down
19 changes: 15 additions & 4 deletions src/factory.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -55,6 +54,7 @@ import type {
OptionsTypeScriptShorthands,
OptionsTypescript,
} from "./types";
import { loadPackages } from "./utils";

const VuePackages = ["vue", "nuxt", "vitepress", "@slidev/cli"];

Expand All @@ -77,10 +77,21 @@ export const defaultPluginRenaming = {
* @param {Awaitable<FlatConfigItem | FlatConfigItem[]>[]} userConfigs - The user configurations to be merged with the generated configurations.
* @returns {Promise<FlatConfigItem[]>} The merged ESLint configurations.
*/
export function rsEslint(
export async function rsEslint(
options: OptionsConfig,
...userConfigs: ReadonlyArray<Awaitable<FlatConfigItem | FlatConfigItem[]>>
): FlatConfigComposer<FlatConfigItem> {
): Promise<FlatConfigComposer<FlatConfigItem>> {
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 = [],
Expand Down

0 comments on commit 07d37ae

Please sign in to comment.