From 263628a7aee54b5ca53fc885ed44bf5a86a83584 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Thu, 2 May 2024 02:58:52 +0900 Subject: [PATCH] Revert "Refactor Cosmiconfig types" (#7661) This reverts commit 9afaa08c196626fac36e9f6b8b8db9dc164cc11d. --- .changeset/little-mirrors-deny.md | 5 +++++ lib/getConfigForFile.cjs | 8 ++++++-- lib/getConfigForFile.mjs | 8 ++++++-- lib/standalone.cjs | 16 ++-------------- lib/standalone.mjs | 16 ++-------------- patches/cosmiconfig+9.0.0.patch | 15 --------------- types/stylelint/index.d.ts | 8 +++++--- 7 files changed, 26 insertions(+), 50 deletions(-) create mode 100644 .changeset/little-mirrors-deny.md delete mode 100644 patches/cosmiconfig+9.0.0.patch diff --git a/.changeset/little-mirrors-deny.md b/.changeset/little-mirrors-deny.md new file mode 100644 index 0000000000..6daa3eeb23 --- /dev/null +++ b/.changeset/little-mirrors-deny.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: `CosmiconfigResult` type error diff --git a/lib/getConfigForFile.cjs b/lib/getConfigForFile.cjs index b2a941f568..c6e52eecb8 100644 --- a/lib/getConfigForFile.cjs +++ b/lib/getConfigForFile.cjs @@ -11,11 +11,15 @@ const configurationError = require('./utils/configurationError.cjs'); const IS_TEST = process.env.NODE_ENV === 'test'; const STOP_DIR = IS_TEST ? process.cwd() : undefined; +/** @typedef {import('stylelint').InternalApi} StylelintInternalApi */ +/** @typedef {import('stylelint').Config} StylelintConfig */ +/** @typedef {import('stylelint').CosmiconfigResult} StylelintCosmiconfigResult */ + /** - * @param {import('stylelint').InternalApi} stylelint + * @param {StylelintInternalApi} stylelint * @param {string} [searchPath] * @param {string} [filePath] - * @returns {Promise} + * @returns {Promise} */ async function getConfigForFile( stylelint, diff --git a/lib/getConfigForFile.mjs b/lib/getConfigForFile.mjs index 4b80f0b9d5..63f7da0112 100644 --- a/lib/getConfigForFile.mjs +++ b/lib/getConfigForFile.mjs @@ -9,11 +9,15 @@ import configurationError from './utils/configurationError.mjs'; const IS_TEST = process.env.NODE_ENV === 'test'; const STOP_DIR = IS_TEST ? process.cwd() : undefined; +/** @typedef {import('stylelint').InternalApi} StylelintInternalApi */ +/** @typedef {import('stylelint').Config} StylelintConfig */ +/** @typedef {import('stylelint').CosmiconfigResult} StylelintCosmiconfigResult */ + /** - * @param {import('stylelint').InternalApi} stylelint + * @param {StylelintInternalApi} stylelint * @param {string} [searchPath] * @param {string} [filePath] - * @returns {Promise} + * @returns {Promise} */ export default async function getConfigForFile( stylelint, diff --git a/lib/standalone.cjs b/lib/standalone.cjs index 869e798aef..ae9f59c751 100644 --- a/lib/standalone.cjs +++ b/lib/standalone.cjs @@ -350,20 +350,8 @@ async function postProcessStylelintResult(stylelint, stylelintResult, filePath) return; } - let root = stylelintResult?._postcssResult?.root; - - if (root) { - if ('type' in root) { - if (root.type !== 'root') { - root = undefined; - } - } else { - root = undefined; - } - } - - for (const postprocess of config._processorFunctions.values()) { - postprocess?.(stylelintResult, root); + for (let postprocess of config._processorFunctions.values()) { + postprocess?.(stylelintResult, stylelintResult._postcssResult?.root); } } diff --git a/lib/standalone.mjs b/lib/standalone.mjs index 6e3b2d1792..7862bad277 100644 --- a/lib/standalone.mjs +++ b/lib/standalone.mjs @@ -348,19 +348,7 @@ async function postProcessStylelintResult(stylelint, stylelintResult, filePath) return; } - let root = stylelintResult?._postcssResult?.root; - - if (root) { - if ('type' in root) { - if (root.type !== 'root') { - root = undefined; - } - } else { - root = undefined; - } - } - - for (const postprocess of config._processorFunctions.values()) { - postprocess?.(stylelintResult, root); + for (let postprocess of config._processorFunctions.values()) { + postprocess?.(stylelintResult, stylelintResult._postcssResult?.root); } } diff --git a/patches/cosmiconfig+9.0.0.patch b/patches/cosmiconfig+9.0.0.patch deleted file mode 100644 index 9c640119a5..0000000000 --- a/patches/cosmiconfig+9.0.0.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/node_modules/cosmiconfig/dist/types.d.ts b/node_modules/cosmiconfig/dist/types.d.ts -index a7ddb91..f59591a 100644 ---- a/node_modules/cosmiconfig/dist/types.d.ts -+++ b/node_modules/cosmiconfig/dist/types.d.ts -@@ -5,8 +5,8 @@ export type Config = any; - /** - * @public - */ --export type CosmiconfigResult = { -- config: Config; -+export type CosmiconfigResult = { -+ config: T; - filepath: string; - isEmpty?: boolean; - } | null; diff --git a/types/stylelint/index.d.ts b/types/stylelint/index.d.ts index 9672aef53c..d291d054bd 100644 --- a/types/stylelint/index.d.ts +++ b/types/stylelint/index.d.ts @@ -1,6 +1,6 @@ import type * as PostCSS from 'postcss'; import type { GlobbyOptions } from 'globby'; -import type * as Cosmiconfig from 'cosmiconfig'; +import type { cosmiconfig, TransformSync as CosmiconfigTransformSync } from 'cosmiconfig'; type ConfigExtends = string | string[]; @@ -133,7 +133,9 @@ declare namespace stylelint { export type DisablePropertyName = PropertyNamesOfType; /** @internal */ - export type CosmiconfigResult = Cosmiconfig.CosmiconfigResult; + export type CosmiconfigResult = + | (ReturnType & { config: Config }) + | null; /** @internal */ export type DisabledRange = { @@ -776,7 +778,7 @@ declare namespace stylelint { */ export type InternalApi = { _options: LinterOptions & { cwd: string }; - _extendExplorer: Cosmiconfig.PublicExplorer; + _extendExplorer: ReturnType; _specifiedConfigCache: Map>; _postcssResultCache: Map; _fileCache: FileCache;