* Replace `groupBy` * Replace `partition` * Replace `pick` * Move `partition` * Replace `uniqBy` * Replace `fromPairs` * Remove usage from website * Reuse `partition` * Remove from package.json * Fix * Use `ignore.default` * Add `resolveConfig` to `FileInfoOptions` * Explicit tuple types * Make `cache` optional * Fix cosmiconfig type * Use `@ts-expect-error` for private property access * Add type annotation for validate * Fix type errors for `OptionInfo` * Add `@ts-expect-error` * Fix type of `normalizeOptions` * Fix `OptionInfo` type * Add `@ts-expect-error` for `option-normalizer` * Avoid type error * Fix typo * Add types for lodash fns Co-authored-by: fisker Cheung <lionkay@gmail.com>
97 lines
2.4 KiB
JavaScript
97 lines
2.4 KiB
JavaScript
"use strict";
|
|
|
|
const { version } = require("../package.json");
|
|
|
|
const core = require("./main/core.js");
|
|
const { getSupportInfo } = require("./main/support.js");
|
|
const getFileInfo = require("./common/get-file-info.js");
|
|
const sharedUtil = require("./common/util-shared.js");
|
|
const plugins = require("./common/load-plugins.js");
|
|
const config = require("./config/resolve-config.js");
|
|
const doc = require("./document/index.js");
|
|
|
|
function _withPlugins(
|
|
fn,
|
|
optsArgIdx = 1 // Usually `opts` is the 2nd argument
|
|
) {
|
|
return (...args) => {
|
|
const opts = args[optsArgIdx] || {};
|
|
args[optsArgIdx] = {
|
|
...opts,
|
|
plugins: plugins.loadPlugins(opts.plugins, opts.pluginSearchDirs),
|
|
};
|
|
return fn(...args);
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @param {*} fn
|
|
* @param {*} optsArgIdx
|
|
* @returns {*}
|
|
*/
|
|
function withPlugins(fn, optsArgIdx) {
|
|
const resultingFn = _withPlugins(fn, optsArgIdx);
|
|
if (fn.sync) {
|
|
// @ts-expect-error
|
|
resultingFn.sync = _withPlugins(fn.sync, optsArgIdx);
|
|
}
|
|
return resultingFn;
|
|
}
|
|
|
|
const formatWithCursor = withPlugins(core.formatWithCursor);
|
|
|
|
module.exports = {
|
|
formatWithCursor,
|
|
|
|
format(text, opts) {
|
|
return formatWithCursor(text, opts).formatted;
|
|
},
|
|
|
|
check(text, opts) {
|
|
const { formatted } = formatWithCursor(text, opts);
|
|
return formatted === text;
|
|
},
|
|
|
|
doc,
|
|
|
|
resolveConfig: config.resolveConfig,
|
|
resolveConfigFile: config.resolveConfigFile,
|
|
clearConfigCache() {
|
|
config.clearCache();
|
|
plugins.clearCache();
|
|
},
|
|
|
|
/** @type {typeof getFileInfo} */
|
|
getFileInfo: withPlugins(getFileInfo),
|
|
/** @type {typeof getSupportInfo} */
|
|
getSupportInfo: withPlugins(getSupportInfo, 0),
|
|
|
|
version,
|
|
|
|
util: sharedUtil,
|
|
|
|
// Internal shared
|
|
__internal: {
|
|
errors: require("./common/errors.js"),
|
|
coreOptions: require("./main/core-options.js"),
|
|
createIgnorer: require("./common/create-ignorer.js"),
|
|
optionsModule: require("./main/options.js"),
|
|
optionsNormalizer: require("./main/options-normalizer.js"),
|
|
utils: {
|
|
arrayify: require("./utils/arrayify.js"),
|
|
getLast: require("./utils/get-last.js"),
|
|
partition: require("./utils/partition.js"),
|
|
isNonEmptyArray: require("./common/util.js").isNonEmptyArray,
|
|
},
|
|
},
|
|
|
|
/* istanbul ignore next */
|
|
__debug: {
|
|
parse: withPlugins(core.parse),
|
|
formatAST: withPlugins(core.formatAST),
|
|
formatDoc: withPlugins(core.formatDoc),
|
|
printToDoc: withPlugins(core.printToDoc),
|
|
printDocToString: withPlugins(core.printDocToString),
|
|
},
|
|
};
|