Skip to content

Commit

Permalink
Revert "Refactor Cosmiconfig types" (#7661)
Browse files Browse the repository at this point in the history
This reverts commit 9afaa08.
  • Loading branch information
ybiquitous committed May 1, 2024
1 parent f87f784 commit c56f714
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 50 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-mirrors-deny.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `CosmiconfigResult` type error
8 changes: 6 additions & 2 deletions lib/getConfigForFile.cjs
Expand Up @@ -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<import('stylelint').CosmiconfigResult>}
* @returns {Promise<StylelintCosmiconfigResult>}
*/
async function getConfigForFile(
stylelint,
Expand Down
8 changes: 6 additions & 2 deletions lib/getConfigForFile.mjs
Expand Up @@ -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<import('stylelint').CosmiconfigResult>}
* @returns {Promise<StylelintCosmiconfigResult>}
*/
export default async function getConfigForFile(
stylelint,
Expand Down
16 changes: 2 additions & 14 deletions lib/standalone.cjs
Expand Up @@ -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);
}
}

Expand Down
16 changes: 2 additions & 14 deletions lib/standalone.mjs
Expand Up @@ -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);
}
}
15 changes: 0 additions & 15 deletions patches/cosmiconfig+9.0.0.patch

This file was deleted.

8 changes: 5 additions & 3 deletions 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[];

Expand Down Expand Up @@ -129,7 +129,9 @@ declare namespace stylelint {
export type DisablePropertyName = PropertyNamesOfType<Config, DisableSettings>;

/** @internal */
export type CosmiconfigResult = Cosmiconfig.CosmiconfigResult<Config>;
export type CosmiconfigResult =
| (ReturnType<CosmiconfigTransformSync> & { config: Config })
| null;

/** @internal */
export type DisabledRange = {
Expand Down Expand Up @@ -768,7 +770,7 @@ declare namespace stylelint {
*/
export type InternalApi = {
_options: LinterOptions & { cwd: string };
_extendExplorer: Cosmiconfig.PublicExplorer;
_extendExplorer: ReturnType<typeof cosmiconfig>;
_specifiedConfigCache: Map<Config, Promise<CosmiconfigResult>>;
_postcssResultCache: Map<string, PostCSS.Result>;
_fileCache: FileCache;
Expand Down

0 comments on commit c56f714

Please sign in to comment.