Add types for config related functions (#18376)
This commit is contained in:
1 parent
9266e3e85b
commit
f4a7afaebf
2 files changed
+35
-3
No files matched your search
@@ -6,6 +6,13 @@ import {
|
||||
} from "../find-project-root.js";
|
||||
import editorConfigToPrettier from "./editorconfig-to-prettier.js";
|
||||
|
||||
/**
|
||||
@typedef {ReturnType<editorConfigToPrettier>} EditorConfig
|
||||
*/
|
||||
|
||||
/**
|
||||
@type {Map<string, Promise<EditorConfig>>}
|
||||
*/
|
||||
const editorconfigCache = new Map();
|
||||
|
||||
function clearEditorconfigCache() {
|
||||
@@ -22,9 +29,9 @@ async function loadEditorconfigInternal(file, { shouldCache }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} file
|
||||
* @param {{shouldCache?: boolean}} options
|
||||
*/
|
||||
@param {string} file
|
||||
@param {{shouldCache?: boolean}} options
|
||||
*/
|
||||
function loadEditorconfig(file, { shouldCache }) {
|
||||
file = path.resolve(file);
|
||||
|
||||
|
||||
@@ -17,6 +17,13 @@ function clearCache() {
|
||||
clearEditorconfigCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@param {string} file
|
||||
@param {{
|
||||
editorconfig?: boolean,
|
||||
useCache?: boolean,
|
||||
}} options
|
||||
*/
|
||||
function loadEditorconfig(file, options) {
|
||||
if (!file || !options.editorconfig) {
|
||||
return;
|
||||
@@ -26,6 +33,17 @@ function loadEditorconfig(file, options) {
|
||||
return loadEditorconfigForFile(file, { shouldCache });
|
||||
}
|
||||
|
||||
/**
|
||||
@param {string} file
|
||||
@param {{
|
||||
useCache?: boolean,
|
||||
config?: string | URL
|
||||
}} options
|
||||
@returns {{
|
||||
config: any,
|
||||
configFile: string,
|
||||
} | void}
|
||||
*/
|
||||
async function loadPrettierConfig(file, options) {
|
||||
const shouldCache = options.useCache;
|
||||
let configFile = options.config;
|
||||
@@ -45,6 +63,10 @@ async function loadPrettierConfig(file, options) {
|
||||
return { config, configFile };
|
||||
}
|
||||
|
||||
/**
|
||||
@param {string | URL} fileUrlOrPath
|
||||
@param {*} options
|
||||
*/
|
||||
async function resolveConfig(fileUrlOrPath, options) {
|
||||
options = { useCache: true, ...options };
|
||||
const filePath = toPath(fileUrlOrPath);
|
||||
@@ -74,6 +96,9 @@ async function resolveConfig(fileUrlOrPath, options) {
|
||||
return merged;
|
||||
}
|
||||
|
||||
/**
|
||||
@param {string | URL} fileUrlOrPath
|
||||
*/
|
||||
async function resolveConfigFile(fileUrlOrPath) {
|
||||
const directory = fileUrlOrPath
|
||||
? path.dirname(path.resolve(toPath(fileUrlOrPath)))
|
||||
|
||||
Reference in new issue
Block a user