Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Refactor Cosmiconfig types" #7661

Merged
merged 2 commits into from May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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