@prettier/cli
Advanced tools
Comparing version 0.3.0 to 0.5.0
#!/usr/bin/env node | ||
import { toKebabCase } from "kasi"; | ||
import { bin, color, parseArgv } from "specialist"; | ||
import { PRETTIER_VERSION, IS_BUN } from "./constants.js"; | ||
import { getPlugin, isNumber, normalizeOptions, normalizeFormatOptions, normalizePluginOptions } from "./utils.js"; | ||
import { run } from "./index.js"; | ||
import { bin, color, exit, parseArgv } from "specialist"; | ||
import { PRETTIER_VERSION } from "./constants.js"; | ||
import { getPlugin, isBoolean, isNumber, isString, normalizeOptions, normalizeFormatOptions, normalizePluginOptions } from "./utils.js"; | ||
const makeBin = () => { | ||
@@ -25,3 +24,2 @@ return (bin("prettier", "An opinionated code formatter") | ||
/* FORMAT OPTIONS */ | ||
.option("--experimental-ternaries", 'Use curious ternaries, with the question mark after the condition\nDefaults to "false"', { section: "Format" }) | ||
.option("--arrow-parens <always|avoid>", 'Include parentheses around a sole arrow function parameter\nDefaults to "always"', { | ||
@@ -41,2 +39,5 @@ section: "Format", | ||
}) | ||
.option("--experimental-ternaries", 'Use curious ternaries, with the question mark after the condition\nDefaults to "false"', { | ||
section: "Format", | ||
}) | ||
.option("--html-whitespace-sensitivity <css|strict|ignore>", 'How to handle whitespaces in HTML\nDefaults to "css"', { | ||
@@ -72,4 +73,2 @@ section: "Format", | ||
/* CONFIG OPTIONS */ | ||
//TODO: Maybe Rename the following to "config", but it conflicts with the "no-config" flag | ||
.option("--config-path <path>", "Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js)", { section: "Config" }) | ||
.option("--no-config", "Do not look for a configuration file", { | ||
@@ -79,2 +78,7 @@ section: "Config", | ||
}) | ||
.option("--config-path <path>", "Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js)", { section: "Config" }) | ||
.option("--config-precedence <cli-override|file-override>", 'Define in which order config files and CLI options should be evaluated.\nDefaults to "cli-override"', { | ||
section: "Config", | ||
enum: ["cli-override", "file-override"], | ||
}) | ||
.option("--no-editorconfig", "Don't take .editorconfig into account when parsing configuration", { | ||
@@ -110,17 +114,16 @@ section: "Config", | ||
.option("--no-parallel", 'Process files in parallel\nDefaults to "true"', { | ||
default: !IS_BUN, //TOOD: always set this to "true", once "worker_threads" work in Bun | ||
default: true, | ||
}) | ||
.option("--parallel-workers <int>", 'Number of parallel workers to use\nDefaults to "0"') | ||
.option("--require-pragma", 'Require either "@prettier" or "@format" to be present in the file\'s first docblock comment in order for it to be formatted\nDefaults to "false"') | ||
// .option( | ||
// "--stdin-filepath <path>", | ||
// "Path to the file to pretend that stdin comes from", | ||
// ) | ||
.option("--stdin-filepath <path>", "Path to the file to pretend that stdin comes from") | ||
// .option("--support-info", "Print support information as JSON") | ||
/* DEFAULT COMMAND */ | ||
.argument("[file/dir/glob...]", "Files, directories or globs to format") | ||
.action((options, files) => { | ||
const baseOptions = normalizeOptions(options, files); | ||
const pluginsOptions = {}; | ||
return run(baseOptions, pluginsOptions); | ||
.action(async (options, files) => { | ||
const { run } = await import("./index.js"); | ||
const baseOptions = await normalizeOptions(options, files); | ||
const pluginsDefaultOptions = {}; | ||
const pluginsCustomOptions = {}; | ||
return run(baseOptions, pluginsDefaultOptions, pluginsCustomOptions); | ||
})); | ||
@@ -133,3 +136,3 @@ }; | ||
const formatOptions = normalizeFormatOptions(args); | ||
const pluginsStaticOptions = {}; | ||
const pluginsDefaultOptions = {}; | ||
const pluginsNames = formatOptions.plugins || []; | ||
@@ -142,3 +145,3 @@ const optionsNames = []; | ||
optionsNames.push(option); | ||
Object.assign(pluginsStaticOptions, plugin.defaultOptions); | ||
Object.assign(pluginsDefaultOptions, plugin.defaultOptions); | ||
const schema = plugin.options[option]; | ||
@@ -157,3 +160,4 @@ const type = schema.type; | ||
const args = variadic ? "<int...>" : "<int>"; | ||
bin = bin.option(`--${toKebabCase(option)} ${args}`, description, { deprecated, section, default: initial }); | ||
pluginsDefaultOptions[option] = initial; | ||
bin = bin.option(`--${toKebabCase(option)} ${args}`, description, { deprecated, section }); | ||
} | ||
@@ -164,3 +168,4 @@ else if (type === "boolean") { | ||
const description = `${descriptionInfo}\n${descriptionDefault}`.trim(); | ||
bin = bin.option(`--${toKebabCase(option)}`, description, { deprecated, section, default: initial }); | ||
pluginsDefaultOptions[option] = initial; | ||
bin = bin.option(`--${toKebabCase(option)}`, description, { deprecated, section }); | ||
} | ||
@@ -172,3 +177,4 @@ else if (type === "string" || type === "path") { | ||
const args = variadic ? "<value...>" : "<value>"; | ||
bin = bin.option(`--${toKebabCase(option)} ${args}`, description, { deprecated, section, default: initial }); | ||
pluginsDefaultOptions[option] = initial; | ||
bin = bin.option(`--${toKebabCase(option)} ${args}`, description, { deprecated, section }); | ||
} | ||
@@ -180,18 +186,37 @@ else if (type === "choice") { | ||
const args = values.length ? `<${values.join("|")}>` : "<value>"; | ||
bin = bin.option(`--${toKebabCase(option)} ${args}`, description, { deprecated, section, default: initial }); | ||
pluginsDefaultOptions[option] = initial; | ||
bin = bin.option(`--${toKebabCase(option)} ${args}`, description, { deprecated, section }); | ||
} | ||
} | ||
} | ||
bin = bin.action((options, files) => { | ||
const baseOptions = normalizeOptions(options, files); | ||
const pluginsDynamicOptions = normalizePluginOptions(options, optionsNames); | ||
const pluginsOptions = { ...pluginsStaticOptions, ...pluginsDynamicOptions }; | ||
return run(baseOptions, pluginsOptions); | ||
bin = bin.action(async (options, files) => { | ||
const { run } = await import("./index.js"); | ||
const baseOptions = await normalizeOptions(options, files); | ||
const pluginsCustomOptions = normalizePluginOptions(options, optionsNames); | ||
return run(baseOptions, pluginsDefaultOptions, pluginsCustomOptions); | ||
}); | ||
return bin; | ||
}; | ||
const makeWarnedPluggableBin = async () => { | ||
const argv = process.argv.slice(2); | ||
const args = parseArgv(argv); | ||
if (isString(args["config"])) { | ||
exit('The "--config" option has been renamed to "--config-path" instead'); | ||
} | ||
if (isString(args["cache-strategy"])) { | ||
exit('The "--cache-strategy" option has been deleted, since the "metadata" strategy is no longer supported'); | ||
} | ||
if (isBoolean(args["find-config-path"])) { | ||
exit('The "--find-config-path" is not currently supported, please open an issue on GitHub if you need it'); | ||
} | ||
if (args["config-precedence"] === "prefer-file") { | ||
exit('The "prefer-file" value for "--config-precedence" is not currently supported, please open an issue on GitHub if you need it'); | ||
} | ||
const bin = await makePluggableBin(); | ||
return bin; | ||
}; | ||
const runBin = async () => { | ||
const bin = await makePluggableBin(); | ||
const bin = await makeWarnedPluggableBin(); | ||
bin.run(); | ||
}; | ||
runBin(); |
import * as EditorConfig from "tiny-editorconfig"; | ||
import type { Config, ConfigWithOverrides } from "tiny-editorconfig"; | ||
import type { FormatOptions, PromiseMaybe } from "./types.js"; | ||
declare const getEditorConfig: ((folderPath: string, filesNames: string[]) => PromiseMaybe<EditorConfig.ConfigWithOverrides | undefined>) & { | ||
cache: Map<string, PromiseMaybe<EditorConfig.ConfigWithOverrides | undefined>>; | ||
declare const getEditorConfig: import("lomemo/dist/types.js").FN<[folderPath: string, filesNames: string[]], PromiseMaybe<EditorConfig.ConfigWithOverrides | undefined>> & { | ||
cache: Map<unknown, unknown>; | ||
}; | ||
declare const getEditorConfigsMap: (foldersPaths: string[], filesNames: string[]) => Promise<Partial<Record<string, ConfigWithOverrides>>>; | ||
declare const getEditorConfigsUp: ((folderPath: string, filesNames: string[]) => Promise<EditorConfig.ConfigWithOverrides[]>) & { | ||
cache: Map<string, Promise<EditorConfig.ConfigWithOverrides[]>>; | ||
declare const getEditorConfigsUp: import("lomemo/dist/types.js").FN<[folderPath: string, filesNames: string[]], Promise<EditorConfig.ConfigWithOverrides[]>> & { | ||
cache: Map<unknown, unknown>; | ||
}; | ||
@@ -11,0 +11,0 @@ declare const getEditorConfigResolved: (filePath: string, filesNames: string[]) => Promise<Config>; |
import type { Ignore } from "./types.js"; | ||
declare const getIgnoresContent: ((folderPath: string, filesNames: string[]) => Promise<string[] | undefined>) & { | ||
cache: Map<string, Promise<string[] | undefined>>; | ||
declare const getIgnoresContent: import("lomemo/dist/types.js").FN<[folderPath: string, filesNames: string[]], Promise<string[] | undefined>> & { | ||
cache: Map<unknown, unknown>; | ||
}; | ||
@@ -8,9 +8,9 @@ declare const getIgnoresContentMap: (foldersPaths: string[], filesNames: string[]) => Promise<Partial<Record<string, string[]>>>; | ||
declare const getIgnoreBys: (foldersPaths: string[], filesContents: string[][]) => Ignore | undefined; | ||
declare const getIgnores: ((folderPath: string, filesNames: string[]) => Promise<Ignore | undefined>) & { | ||
cache: Map<string, Promise<Ignore | undefined>>; | ||
declare const getIgnores: import("lomemo/dist/types.js").FN<[folderPath: string, filesNames: string[]], Promise<Ignore | undefined>> & { | ||
cache: Map<unknown, unknown>; | ||
}; | ||
declare const getIgnoresUp: ((folderPath: string, filesNames: string[]) => Promise<Ignore | undefined>) & { | ||
cache: Map<string, Promise<Ignore | undefined>>; | ||
declare const getIgnoresUp: import("lomemo/dist/types.js").FN<[folderPath: string, filesNames: string[]], Promise<Ignore | undefined>> & { | ||
cache: Map<unknown, unknown>; | ||
}; | ||
declare const getIgnoreResolved: (filePath: string, filesNames: string[]) => Promise<boolean>; | ||
export { getIgnoresContent, getIgnoresContentMap, getIgnoreBy, getIgnoreBys, getIgnores, getIgnoresUp, getIgnoreResolved }; |
@@ -14,6 +14,6 @@ import type { PrettierConfig, PrettierConfigWithOverrides, PromiseMaybe } from "./types.js"; | ||
declare const getPrettierConfigsMap: (foldersPaths: string[], filesNames: string[]) => Promise<Partial<Record<string, PrettierConfig[]>>>; | ||
declare const getPrettierConfigsUp: ((folderPath: string, filesNames: string[]) => Promise<PrettierConfigWithOverrides[]>) & { | ||
cache: Map<string, Promise<PrettierConfigWithOverrides[]>>; | ||
declare const getPrettierConfigsUp: import("lomemo/dist/types.js").FN<[folderPath: string, filesNames: string[]], Promise<PrettierConfigWithOverrides[]>> & { | ||
cache: Map<unknown, unknown>; | ||
}; | ||
declare const getPrettierConfigResolved: (filePath: string, filesNames: string[]) => Promise<PrettierConfig>; | ||
export { Loaders, getPrettierConfig, getPrettierConfigsMap, getPrettierConfigsUp, getPrettierConfigResolved }; |
@@ -1,4 +0,1 @@ | ||
import TOML from "@iarna/toml"; | ||
import yaml from "js-yaml"; | ||
import JSON5 from "json5"; | ||
import fs from "node:fs"; | ||
@@ -9,3 +6,3 @@ import path from "node:path"; | ||
import Known from "./known.js"; | ||
import { fastJoinedPath, fastRelativeChildPath, getModule, getModulePath } from "./utils.js"; | ||
import { fastJoinedPath, fastRelativeChildPath, getModulePath } from "./utils.js"; | ||
import { isObject, isString, isTruthy, isUndefined, memoize, noop, normalizePrettierOptions, omit, zipObjectUnless } from "./utils.js"; | ||
@@ -35,2 +32,3 @@ const Loaders = { | ||
const fileContent = fs.readFileSync(filePath, "utf8"); | ||
const JSON5 = (await import("json5")).default; | ||
const config = JSON5.parse(fileContent); | ||
@@ -52,3 +50,3 @@ return config; | ||
const modulePath = getModulePath(config, filePath); | ||
return Loaders.js(modulePath); | ||
return Loaders.auto(modulePath); | ||
} | ||
@@ -59,5 +57,7 @@ } | ||
const fileContent = fs.readFileSync(filePath, "utf8"); | ||
const TOML = (await import("@iarna/toml")).default; | ||
return TOML.parse(fileContent); | ||
}, | ||
yaml: async (filePath) => { | ||
const yaml = (await import("js-yaml")).default; | ||
const fileContent = fs.readFileSync(filePath, "utf8"); | ||
@@ -64,0 +64,0 @@ return yaml.load(fileContent, { |
declare const PRETTIER_VERSION: any; | ||
declare const CLI_VERSION: any; | ||
declare const IS_BUN: boolean; | ||
export { PRETTIER_VERSION, CLI_VERSION, IS_BUN }; | ||
export { PRETTIER_VERSION, CLI_VERSION }; |
@@ -7,3 +7,2 @@ import { createRequire } from "node:module"; | ||
const CLI_VERSION = cliPackage.version; | ||
const IS_BUN = !!process.versions["bun"]; | ||
export { PRETTIER_VERSION, CLI_VERSION, IS_BUN }; | ||
export { PRETTIER_VERSION, CLI_VERSION }; |
import type { Options, PluginsOptions } from "./types.js"; | ||
declare function run(options: Options, pluginsOptions: PluginsOptions): Promise<void>; | ||
export { run }; | ||
declare function run(options: Options, pluginsDefaultOptions: PluginsOptions, pluginsCustomOptions: PluginsOptions): Promise<void>; | ||
declare function runStdin(options: Options, pluginsDefaultOptions: PluginsOptions, pluginsCustomOptions: PluginsOptions): Promise<void>; | ||
declare function runGlobs(options: Options, pluginsDefaultOptions: PluginsOptions, pluginsCustomOptions: PluginsOptions): Promise<void>; | ||
export { run, runStdin, runGlobs }; |
@@ -14,6 +14,30 @@ import fs from "node:fs/promises"; | ||
import { makePrettier } from "./prettier.js"; | ||
import { castArray, getExpandedFoldersPaths, getFoldersChildrenPaths, getPluginsVersions, getProjectPath, getTargetsPaths } from "./utils.js"; | ||
import { castArray, getExpandedFoldersPaths, getFoldersChildrenPaths, getPluginsVersions, getProjectPath, getStdin, getTargetsPaths } from "./utils.js"; | ||
import { fastRelativePath, isString, isUndefined, negate, pluralize, uniq } from "./utils.js"; | ||
async function run(options, pluginsOptions) { | ||
async function run(options, pluginsDefaultOptions, pluginsCustomOptions) { | ||
const stdin = await getStdin(); | ||
if (isString(stdin)) { | ||
return runStdin(options, pluginsDefaultOptions, pluginsCustomOptions); | ||
} | ||
else { | ||
return runGlobs(options, pluginsDefaultOptions, pluginsCustomOptions); | ||
} | ||
} | ||
async function runStdin(options, pluginsDefaultOptions, pluginsCustomOptions) { | ||
const logger = new Logger(options.logLevel); | ||
const prettier = await import("./prettier_serial.js"); | ||
const fileName = options.stdinFilepath || "stdin"; | ||
const fileContent = (await getStdin()) || ""; | ||
try { | ||
const formatted = await prettier.format(fileName, fileContent, options.formatOptions, options.contextOptions, pluginsDefaultOptions, pluginsCustomOptions); | ||
logger.always(formatted); | ||
process.exitCode = options.check && formatted !== fileContent ? 1 : 0; | ||
} | ||
catch (error) { | ||
logger.prefixed.error(String(error)); | ||
process.exitCode = 1; | ||
} | ||
} | ||
async function runGlobs(options, pluginsDefaultOptions, pluginsCustomOptions) { | ||
const logger = new Logger(options.logLevel); | ||
const spinner = options.check ? logger.spinner.log() : undefined; | ||
@@ -58,3 +82,3 @@ spinner?.start("Checking formatting..."); | ||
const cliFormatConfig = options.formatOptions; | ||
const cacheVersion = stringify({ prettierVersion, cliVersion, pluginsNames, pluginsVersions, editorConfigs, ignoreContents, prettierConfigs, ignoreManualFilesPaths, ignoreManualFilesContents, prettierManualFilesPaths, prettierManualFilesContents, cliContextConfig, cliFormatConfig, pluginsOptions }); // prettier-ignore | ||
const cacheVersion = stringify({ prettierVersion, cliVersion, pluginsNames, pluginsVersions, editorConfigs, ignoreContents, prettierConfigs, ignoreManualFilesPaths, ignoreManualFilesContents, prettierManualFilesPaths, prettierManualFilesContents, cliContextConfig, cliFormatConfig, pluginsDefaultOptions, pluginsCustomOptions }); // prettier-ignore | ||
const shouldCache = isUndefined(cliContextConfig.cursorOffset); | ||
@@ -78,9 +102,9 @@ const cache = shouldCache ? new Cache(cacheVersion, projectPath, options, logger) : undefined; | ||
if (options.check || options.list) { | ||
return await prettier.checkWithPath(filePath, getFormatOptions, cliContextConfig, pluginsOptions); | ||
return await prettier.checkWithPath(filePath, getFormatOptions, cliContextConfig, pluginsDefaultOptions, pluginsCustomOptions); | ||
} | ||
else if (options.write) { | ||
return await prettier.writeWithPath(filePath, getFormatOptions, cliContextConfig, pluginsOptions); | ||
return await prettier.writeWithPath(filePath, getFormatOptions, cliContextConfig, pluginsDefaultOptions, pluginsCustomOptions); | ||
} | ||
else { | ||
return await prettier.formatWithPath(filePath, getFormatOptions, cliContextConfig, pluginsOptions); | ||
return await prettier.formatWithPath(filePath, getFormatOptions, cliContextConfig, pluginsDefaultOptions, pluginsCustomOptions); | ||
} | ||
@@ -181,2 +205,2 @@ } | ||
} | ||
export { run }; | ||
export { run, runStdin, runGlobs }; |
@@ -10,3 +10,2 @@ import Spinner from "tiny-spinner"; | ||
absract: (message: FunctionMaybe<string>, strength: number) => void; | ||
silent: (message: FunctionMaybe<string>) => void; | ||
debug: (message: FunctionMaybe<string>) => void; | ||
@@ -16,6 +15,6 @@ log: (message: FunctionMaybe<string>) => void; | ||
error: (message: FunctionMaybe<string>) => void; | ||
silent: (message: FunctionMaybe<string>) => void; | ||
always: (message: FunctionMaybe<string>) => void; | ||
prefixed: { | ||
abstract: (prefix: string, message: FunctionMaybe<string>, strength: number) => void; | ||
silent: (message: FunctionMaybe<string>) => void; | ||
debug: (message: FunctionMaybe<string>) => void; | ||
@@ -25,2 +24,3 @@ log: (message: FunctionMaybe<string>) => void; | ||
error: (message: FunctionMaybe<string>) => void; | ||
silent: (message: FunctionMaybe<string>) => void; | ||
always: (message: FunctionMaybe<string>) => void; | ||
@@ -30,3 +30,2 @@ }; | ||
abstract: (strength: number) => Spinner | undefined; | ||
silent: () => Spinner | undefined; | ||
debug: () => Spinner | undefined; | ||
@@ -36,2 +35,3 @@ log: () => Spinner | undefined; | ||
error: () => Spinner | undefined; | ||
silent: () => Spinner | undefined; | ||
always: () => Spinner | undefined; | ||
@@ -38,0 +38,0 @@ }; |
@@ -8,3 +8,3 @@ import Pioppo from "pioppo"; | ||
this.pioppo = new Pioppo(); | ||
this.levels = ["silent", "debug", "log", "warn", "error"]; | ||
this.levels = ["debug", "log", "warn", "error", "silent"]; | ||
this.absract = (message, strength) => { | ||
@@ -18,15 +18,15 @@ if (strength < this.strength) | ||
}; | ||
this.silent = (message) => { | ||
this.debug = (message) => { | ||
this.absract(message, 0); | ||
}; | ||
this.debug = (message) => { | ||
this.log = (message) => { | ||
this.absract(message, 1); | ||
}; | ||
this.log = (message) => { | ||
this.warn = (message) => { | ||
this.absract(message, 2); | ||
}; | ||
this.warn = (message) => { | ||
this.error = (message) => { | ||
this.absract(message, 3); | ||
}; | ||
this.error = (message) => { | ||
this.silent = (message) => { | ||
this.absract(message, 4); | ||
@@ -48,20 +48,20 @@ }; | ||
}, | ||
silent: (message) => { | ||
const prefix = `[${color.dim("silent")}]`; | ||
this.prefixed.abstract(prefix, message, 0); | ||
}, | ||
debug: (message) => { | ||
const prefix = `[${color.magenta("debug")}]`; | ||
this.prefixed.abstract(prefix, message, 1); | ||
this.prefixed.abstract(prefix, message, 0); | ||
}, | ||
log: (message) => { | ||
const prefix = `[${color.cyan("log")}]`; | ||
this.prefixed.abstract(prefix, message, 2); | ||
this.prefixed.abstract(prefix, message, 1); | ||
}, | ||
warn: (message) => { | ||
const prefix = `[${color.yellow("warn")}]`; | ||
this.prefixed.abstract(prefix, message, 3); | ||
this.prefixed.abstract(prefix, message, 2); | ||
}, | ||
error: (message) => { | ||
const prefix = `[${color.red("error")}]`; | ||
this.prefixed.abstract(prefix, message, 3); | ||
}, | ||
silent: (message) => { | ||
const prefix = `[${color.dim("silent")}]`; | ||
this.prefixed.abstract(prefix, message, 4); | ||
@@ -79,15 +79,15 @@ }, | ||
}, | ||
silent: () => { | ||
debug: () => { | ||
return this.spinner.abstract(0); | ||
}, | ||
debug: () => { | ||
log: () => { | ||
return this.spinner.abstract(1); | ||
}, | ||
log: () => { | ||
warn: () => { | ||
return this.spinner.abstract(2); | ||
}, | ||
warn: () => { | ||
error: () => { | ||
return this.spinner.abstract(3); | ||
}, | ||
error: () => { | ||
silent: () => { | ||
return this.spinner.abstract(4); | ||
@@ -94,0 +94,0 @@ }, |
@@ -8,3 +8,3 @@ import { readFile, writeFile } from "atomically"; | ||
write: prettier.write, | ||
async checkWithPath(filePath, formatOptions, contextOptions, pluginsOptions) { | ||
async checkWithPath(filePath, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
const data = await cache.get(filePath); | ||
@@ -14,7 +14,7 @@ if (isBoolean(data?.formatted)) | ||
const fileContent = data?.content?.toString() ?? (await readFile(filePath, "utf8")); | ||
const formatted = await prettier.check(filePath, fileContent, formatOptions, contextOptions, pluginsOptions); | ||
const formatted = await prettier.check(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions); | ||
await data?.save(formatted, fileContent); | ||
return formatted; | ||
}, | ||
async formatWithPath(filePath, formatOptions, contextOptions, pluginsOptions) { | ||
async formatWithPath(filePath, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
const data = await cache.get(filePath); | ||
@@ -24,3 +24,3 @@ const fileContent = data?.content?.toString() ?? (await readFile(filePath, "utf8")); | ||
return fileContent; | ||
const fileContentFormatted = await prettier.format(filePath, fileContent, formatOptions, contextOptions, pluginsOptions); | ||
const fileContentFormatted = await prettier.format(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions); | ||
if (fileContent === fileContentFormatted) { | ||
@@ -35,3 +35,3 @@ await data?.save(true, fileContent); | ||
}, | ||
async writeWithPath(filePath, formatOptions, contextOptions, pluginsOptions) { | ||
async writeWithPath(filePath, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
const data = await cache.get(filePath); | ||
@@ -41,3 +41,3 @@ if (data?.formatted) | ||
const fileContent = data?.content?.toString() ?? (await readFile(filePath, "utf8")); | ||
const fileContentFormatted = await prettier.format(filePath, fileContent, formatOptions, contextOptions, pluginsOptions); | ||
const fileContentFormatted = await prettier.format(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions); | ||
if (fileContent === fileContentFormatted) { | ||
@@ -44,0 +44,0 @@ await data?.save(true, fileContent); |
@@ -12,19 +12,19 @@ import os from "node:os"; | ||
return { | ||
async check(filePath, fileContent, formatOptions, contextOptions, pluginsOptions) { | ||
return pool.exec("check", [filePath, fileContent, await resolve(formatOptions), contextOptions, pluginsOptions]); | ||
async check(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
return pool.exec("check", [filePath, fileContent, await resolve(formatOptions), contextOptions, pluginsDefaultOptions, pluginsCustomOptions]); | ||
}, | ||
async checkWithPath(filePath, formatOptions, contextOptions, pluginsOptions) { | ||
return pool.exec("checkWithPath", [filePath, await resolve(formatOptions), contextOptions, pluginsOptions]); | ||
async checkWithPath(filePath, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
return pool.exec("checkWithPath", [filePath, await resolve(formatOptions), contextOptions, pluginsDefaultOptions, pluginsCustomOptions]); | ||
}, | ||
async format(filePath, fileContent, formatOptions, contextOptions, pluginsOptions) { | ||
return pool.exec("format", [filePath, fileContent, await resolve(formatOptions), contextOptions, pluginsOptions]); | ||
async format(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
return pool.exec("format", [filePath, fileContent, await resolve(formatOptions), contextOptions, pluginsDefaultOptions, pluginsCustomOptions]); | ||
}, | ||
async formatWithPath(filePath, formatOptions, contextOptions, pluginsOptions) { | ||
return pool.exec("formatWithPath", [filePath, await resolve(formatOptions), contextOptions, pluginsOptions]); | ||
async formatWithPath(filePath, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
return pool.exec("formatWithPath", [filePath, await resolve(formatOptions), contextOptions, pluginsDefaultOptions, pluginsCustomOptions]); | ||
}, | ||
async write(filePath, fileContent, formatOptions, contextOptions, pluginsOptions) { | ||
return pool.exec("write", [filePath, fileContent, await resolve(formatOptions), contextOptions, pluginsOptions]); | ||
async write(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
return pool.exec("write", [filePath, fileContent, await resolve(formatOptions), contextOptions, pluginsDefaultOptions, pluginsCustomOptions]); | ||
}, | ||
async writeWithPath(filePath, formatOptions, contextOptions, pluginsOptions) { | ||
return pool.exec("writeWithPath", [filePath, await resolve(formatOptions), contextOptions, pluginsOptions]); | ||
async writeWithPath(filePath, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
return pool.exec("writeWithPath", [filePath, await resolve(formatOptions), contextOptions, pluginsDefaultOptions, pluginsCustomOptions]); | ||
}, | ||
@@ -31,0 +31,0 @@ }; |
import type { ContextOptions, LazyFormatOptions, PluginsOptions } from "./types.js"; | ||
declare function check(filePath: string, fileContent: string, formatOptions: LazyFormatOptions, contextOptions: ContextOptions, pluginsOptions: PluginsOptions): Promise<boolean>; | ||
declare function checkWithPath(filePath: string, formatOptions: LazyFormatOptions, contextOptions: ContextOptions, pluginsOptions: PluginsOptions): Promise<boolean>; | ||
declare function format(filePath: string, fileContent: string, formatOptions: LazyFormatOptions, contextOptions: ContextOptions, pluginsOptions: PluginsOptions): Promise<string>; | ||
declare function formatWithPath(filePath: string, formatOptions: LazyFormatOptions, contextOptions: ContextOptions, pluginsOptions: PluginsOptions): Promise<string>; | ||
declare function write(filePath: string, fileContent: string, formatOptions: LazyFormatOptions, contextOptions: ContextOptions, pluginsOptions: PluginsOptions): Promise<boolean>; | ||
declare function writeWithPath(filePath: string, formatOptions: LazyFormatOptions, contextOptions: ContextOptions, pluginsOptions: PluginsOptions): Promise<boolean>; | ||
declare function check(filePath: string, fileContent: string, formatOptions: LazyFormatOptions, contextOptions: ContextOptions, pluginsDefaultOptions: PluginsOptions, pluginsCustomOptions: PluginsOptions): Promise<boolean>; | ||
declare function checkWithPath(filePath: string, formatOptions: LazyFormatOptions, contextOptions: ContextOptions, pluginsDefaultOptions: PluginsOptions, pluginsCustomOptions: PluginsOptions): Promise<boolean>; | ||
declare function format(filePath: string, fileContent: string, formatOptions: LazyFormatOptions, contextOptions: ContextOptions, pluginsDefaultOptions: PluginsOptions, pluginsCustomOptions: PluginsOptions): Promise<string>; | ||
declare function formatWithPath(filePath: string, formatOptions: LazyFormatOptions, contextOptions: ContextOptions, pluginsDefaultOptions: PluginsOptions, pluginsCustomOptions: PluginsOptions): Promise<string>; | ||
declare function write(filePath: string, fileContent: string, formatOptions: LazyFormatOptions, contextOptions: ContextOptions, pluginsDefaultOptions: PluginsOptions, pluginsCustomOptions: PluginsOptions): Promise<boolean>; | ||
declare function writeWithPath(filePath: string, formatOptions: LazyFormatOptions, contextOptions: ContextOptions, pluginsDefaultOptions: PluginsOptions, pluginsCustomOptions: PluginsOptions): Promise<boolean>; | ||
export { check, checkWithPath, format, formatWithPath, write, writeWithPath }; |
import { readFile, writeFile } from "atomically"; | ||
import process from "node:process"; | ||
import prettier from "prettier/standalone"; | ||
import prettierAcorn from "prettier/plugins/acorn"; | ||
import prettierAngular from "prettier/plugins/angular"; | ||
import prettierBabel from "prettier/plugins/babel"; | ||
import prettierEstree from "prettier/plugins/estree"; | ||
import prettierFlow from "prettier/plugins/flow"; | ||
import prettierGlimmer from "prettier/plugins/glimmer"; | ||
import prettierGraphql from "prettier/plugins/graphql"; | ||
import prettierHtml from "prettier/plugins/html"; | ||
import prettierMarkdown from "prettier/plugins/markdown"; | ||
import prettierMeriyah from "prettier/plugins/meriyah"; | ||
import prettierPostcss from "prettier/plugins/postcss"; | ||
import prettierTypescript from "prettier/plugins/typescript"; | ||
import prettierYaml from "prettier/plugins/yaml"; | ||
import { getPlugins, resolve } from "./utils.js"; | ||
//TODO: Avoid loading plugins until they are actually needed | ||
async function check(filePath, fileContent, formatOptions, contextOptions, pluginsOptions) { | ||
const fileContentFormatted = await format(filePath, fileContent, formatOptions, contextOptions, pluginsOptions); | ||
import { getPlugins, getPluginsBuiltin, resolve } from "./utils.js"; | ||
async function check(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
const fileContentFormatted = await format(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions); | ||
return fileContent === fileContentFormatted; | ||
} | ||
async function checkWithPath(filePath, formatOptions, contextOptions, pluginsOptions) { | ||
async function checkWithPath(filePath, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
const fileContent = await readFile(filePath, "utf8"); | ||
return check(filePath, fileContent, formatOptions, contextOptions, pluginsOptions); | ||
return check(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions); | ||
} | ||
async function format(filePath, fileContent, formatOptions, contextOptions, pluginsOptions) { | ||
async function format(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
formatOptions = await resolve(formatOptions); | ||
const pluginsBuiltin = await getPluginsBuiltin(); | ||
const plugins = await getPlugins(formatOptions.plugins || []); | ||
const pluginsOverride = contextOptions.configPrecedence !== 'file-override'; | ||
const options = { | ||
...formatOptions, | ||
...pluginsOptions, | ||
...pluginsDefaultOptions, | ||
...(pluginsOverride ? formatOptions : pluginsCustomOptions), | ||
...(pluginsOverride ? pluginsCustomOptions : formatOptions), | ||
...contextOptions, | ||
filepath: filePath, | ||
plugins: [ | ||
prettierAcorn, | ||
prettierAngular, | ||
prettierBabel, | ||
prettierEstree, | ||
prettierFlow, | ||
prettierGlimmer, | ||
prettierGraphql, | ||
prettierHtml, | ||
prettierMarkdown, | ||
prettierMeriyah, | ||
prettierPostcss, | ||
prettierTypescript, | ||
prettierYaml, | ||
...pluginsBuiltin, | ||
...plugins, | ||
@@ -58,8 +35,8 @@ ], | ||
} | ||
async function formatWithPath(filePath, formatOptions, contextOptions, pluginsOptions) { | ||
async function formatWithPath(filePath, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
const fileContent = await readFile(filePath, "utf8"); | ||
return format(filePath, fileContent, formatOptions, contextOptions, pluginsOptions); | ||
return format(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions); | ||
} | ||
async function write(filePath, fileContent, formatOptions, contextOptions, pluginsOptions) { | ||
const fileContentFormatted = await format(filePath, fileContent, formatOptions, contextOptions, pluginsOptions); | ||
async function write(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
const fileContentFormatted = await format(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions); | ||
if (fileContent === fileContentFormatted) | ||
@@ -70,6 +47,6 @@ return true; | ||
} | ||
async function writeWithPath(filePath, formatOptions, contextOptions, pluginsOptions) { | ||
async function writeWithPath(filePath, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions) { | ||
const fileContent = await readFile(filePath, "utf8"); | ||
return write(filePath, fileContent, formatOptions, contextOptions, pluginsOptions); | ||
return write(filePath, fileContent, formatOptions, contextOptions, pluginsDefaultOptions, pluginsCustomOptions); | ||
} | ||
export { check, checkWithPath, format, formatWithPath, write, writeWithPath }; |
type Bin = ReturnType<typeof import("tiny-bin").default>; | ||
type ContextOptions = { | ||
configPrecedence?: "cli-override" | "file-override"; | ||
cursorOffset?: number; | ||
@@ -54,2 +55,3 @@ rangeEnd?: number; | ||
parallelWorkers: number; | ||
stdinFilepath: string | undefined; | ||
contextOptions: ContextOptions; | ||
@@ -56,0 +58,0 @@ formatOptions: FormatOptions; |
@@ -0,8 +1,6 @@ | ||
import once from "function-once"; | ||
import memoize from "lomemo"; | ||
import type { FormatOptions, FunctionMaybe, Key, Options, PrettierConfigWithOverrides, PrettierPlugin } from "./types.js"; | ||
import type { PluginsOptions, PromiseMaybe } from "./types.js"; | ||
declare function memoize<Args extends unknown[], Return>(fn: (...args: Args) => Return): ((...args: Args) => Return) & { | ||
cache: Map<Args[0], Return>; | ||
}; | ||
declare function castArray<T>(value: T | T[]): T[]; | ||
declare function everyOf<T>(fns: ((arg: T) => unknown)[]): (arg: T) => boolean; | ||
declare function fastJoinedPath(folderPath: string, fileName: string): string; | ||
@@ -16,7 +14,7 @@ declare function fastRelativePath(fromPath: string, toPath: string): string; | ||
declare function getFoldersChildrenPaths(foldersPaths: string[]): Promise<string[]>; | ||
declare function getGlobPaths(rootPath: string, globs: string[], withNodeModules: boolean): Promise<import("tiny-readdir-glob/dist/types.js").Result>; | ||
declare function getGlobPaths(rootPath: string, globs: string[], withNodeModules: boolean): Promise<import("tiny-readdir-glob").Result>; | ||
declare function getModule<T = unknown>(modulePath: string): Promise<T>; | ||
declare function getModulePath(name: string, rootPath: string): string; | ||
declare const getPlugin: ((name: string) => Promise<import("prettier").Plugin<any>>) & { | ||
cache: Map<string, Promise<import("prettier").Plugin<any>>>; | ||
declare const getPlugin: import("lomemo/dist/types.js").FN<[name: string], Promise<import("prettier").Plugin<any>>> & { | ||
cache: Map<unknown, unknown>; | ||
}; | ||
@@ -26,9 +24,10 @@ declare function getPluginPath(name: string): string; | ||
declare function getPlugins(names: string[]): PromiseMaybe<PrettierPlugin[]>; | ||
declare const getPluginsBuiltin: () => Promise<import("prettier").Plugin<any>[]>; | ||
declare function getPluginsPaths(names: string[]): string[]; | ||
declare function getPluginsVersions(names: string[]): string[]; | ||
declare function getProjectPath(rootPath: string): string; | ||
declare const getStdin: () => Promise<string | undefined>; | ||
declare function getTargetsPaths(rootPath: string, globs: string[], withNodeModules: boolean): Promise<[string[], string[], Record<string, string[]>, string[], string[]]>; | ||
declare function isArray(value: unknown): value is unknown[]; | ||
declare function isBoolean(value: unknown): value is boolean; | ||
declare function isFalsy<T>(value: T): value is Extract<T, 0 | -0 | 0n | -0n | "" | false | null | undefined | void>; | ||
declare function isFunction(value: unknown): value is Function; | ||
@@ -38,3 +37,2 @@ declare function isInteger(value: unknown): value is number; | ||
declare function isObject(value: unknown): value is object; | ||
declare function isPromise(value: unknown): value is Promise<unknown>; | ||
declare function isString(value: unknown): value is string; | ||
@@ -45,3 +43,3 @@ declare function isTruthy<T>(value: T): value is Exclude<T, 0 | -0 | 0n | -0n | "" | false | null | undefined | void>; | ||
declare function noop(): undefined; | ||
declare function normalizeOptions(options: unknown, targets: unknown[]): Options; | ||
declare function normalizeOptions(options: unknown, targets: unknown[]): Promise<Options>; | ||
declare function normalizeFormatOptions(options: unknown): FormatOptions; | ||
@@ -51,3 +49,2 @@ declare function normalizePluginOptions(options: unknown, names: string[]): PluginsOptions; | ||
declare function omit<T extends object, K extends keyof T>(object: T, keys: K[]): Omit<T, K>; | ||
declare function once<T>(fn: () => T): () => T; | ||
declare function pluralize(value: string, length: number): string; | ||
@@ -59,4 +56,3 @@ declare function resolve<T>(value: FunctionMaybe<T>): T; | ||
declare function uniq<T>(values: T[]): T[]; | ||
declare function zipObject<T extends Key, U>(keys: T[], values: U[]): Partial<Record<T, U>>; | ||
declare function zipObjectUnless<T extends Key, U>(keys: T[], values: U[], unless: (value: U) => boolean): Partial<Record<T, U>>; | ||
export { castArray, everyOf, fastJoinedPath, fastRelativePath, fastRelativeChildPath, findLastIndex, getCachePath, getFolderChildrenPaths, getFoldersChildrenPaths, getExpandedFoldersPaths, getGlobPaths, getModule, getModulePath, getPlugin, getPluginPath, getPluginVersion, getPlugins, getPluginsPaths, getPluginsVersions, getProjectPath, getTargetsPaths, isArray, isBoolean, isFalsy, isFunction, isInteger, isNumber, isObject, isPromise, isString, isTruthy, isUndefined, memoize, negate, noop, normalizeOptions, normalizeFormatOptions, normalizePluginOptions, normalizePrettierOptions, omit, once, pluralize, resolve, sha1hex, sha1base64, someOf, uniq, zipObject, zipObjectUnless, }; | ||
export { castArray, fastJoinedPath, fastRelativePath, fastRelativeChildPath, findLastIndex, getCachePath, getFolderChildrenPaths, getFoldersChildrenPaths, getExpandedFoldersPaths, getGlobPaths, getModule, getModulePath, getPlugin, getPluginPath, getPluginVersion, getPlugins, getPluginsBuiltin, getPluginsPaths, getPluginsVersions, getProjectPath, getStdin, getTargetsPaths, isArray, isBoolean, isFunction, isInteger, isNumber, isObject, isString, isTruthy, isUndefined, memoize, negate, noop, normalizeOptions, normalizeFormatOptions, normalizePluginOptions, normalizePrettierOptions, omit, once, pluralize, resolve, sha1hex, sha1base64, someOf, uniq, zipObjectUnless, }; |
import findUp from "find-up-json"; | ||
import once from "function-once"; | ||
import { moduleResolve } from "import-meta-resolve"; | ||
import memoize from "lomemo"; | ||
import crypto from "node:crypto"; | ||
@@ -7,30 +9,12 @@ import fs from "node:fs"; | ||
import process from "node:process"; | ||
import { text as stream2text } from "node:stream/consumers"; | ||
import url from "node:url"; | ||
import resolveTimeout from "promise-resolve-timeout"; | ||
import { exit } from "specialist"; | ||
import readdir from "tiny-readdir-glob"; | ||
import zeptomatch from "zeptomatch"; | ||
//FIXME: Ensure all arguments are actually taken into account | ||
//TODO: Publish something like this as a standalone module, rather than manually hoisting this up | ||
function memoize(fn) { | ||
const memoized = (...args) => { | ||
const { cache } = memoized; | ||
const id = args[0]; | ||
const cached = cache.get(id); | ||
if (!isUndefined(cached) || cache.has(id)) | ||
return cached; | ||
const result = fn(...args); | ||
cache.set(id, result); | ||
return result; | ||
}; | ||
memoized.cache = new Map(); | ||
return memoized; | ||
} | ||
import zeptomatchEscape from "zeptomatch-escape"; | ||
import zeptomatchIsStatic from "zeptomatch-is-static"; | ||
function castArray(value) { | ||
return isArray(value) ? value : [value]; | ||
} | ||
function everyOf(fns) { | ||
return (arg) => { | ||
return fns.every((fn) => fn(arg)); | ||
}; | ||
} | ||
function fastJoinedPath(folderPath, fileName) { | ||
@@ -137,2 +121,5 @@ return `${folderPath}${path.sep}${fileName}`; | ||
} | ||
const getPluginsBuiltin = once(async () => { | ||
return [(await import("./prettier_plugins_builtin.js")).default]; | ||
}); | ||
function getPluginsPaths(names) { | ||
@@ -172,2 +159,10 @@ const pluginsPaths = names.map(getPluginPath); | ||
} | ||
const getStdin = once(async () => { | ||
// Without a TTY, the process is likely, but not certainly, being piped | ||
if (!process.stdin.isTTY) { | ||
const stdin = stream2text(process.stdin); | ||
const fallback = resolveTimeout(1000, undefined); | ||
return Promise.race([stdin, fallback]); | ||
} | ||
}); | ||
async function getTargetsPaths(rootPath, globs, withNodeModules) { | ||
@@ -210,5 +205,2 @@ const targetFiles = []; | ||
} | ||
function isFalsy(value) { | ||
return !value; | ||
} | ||
function isFile(targetPath) { | ||
@@ -226,6 +218,2 @@ try { | ||
} | ||
function isGlobStatic(glob) { | ||
//TODO: Make this perfect, grammar-based, rather than letting some glob-looking paths slip through | ||
return /^(?:\\.|[ a-zA-Z0-9/._-])*$/.test(glob); | ||
} | ||
function isInteger(value) { | ||
@@ -243,5 +231,2 @@ return Number.isInteger(value); | ||
} | ||
function isPromise(value) { | ||
return value instanceof Promise; | ||
} | ||
function isString(value) { | ||
@@ -264,9 +249,10 @@ return typeof value === "string"; | ||
} | ||
function normalizeOptions(options, targets) { | ||
async function normalizeOptions(options, targets) { | ||
if (!isObject(options)) | ||
exit("Invalid options object"); | ||
const targetsGlobs = targets.filter(isString); | ||
const targetsStatic = "--" in options && Array.isArray(options["--"]) ? options["--"].filter(isString).map(zeptomatch.escape) : []; | ||
const targetsStatic = "--" in options && Array.isArray(options["--"]) ? options["--"].filter(isString).map(zeptomatchEscape) : []; | ||
const globs = [...targetsGlobs, ...targetsStatic]; | ||
if (!globs.length) | ||
const stdin = await getStdin(); | ||
if (!isString(stdin) && !globs.length) | ||
exit("Expected at least one target file/dir/glob"); | ||
@@ -290,6 +276,7 @@ const check = "check" in options && !!options.check; | ||
const errorOnUnmatchedPattern = "errorOnUnmatchedPattern" in options ? !!options.errorOnUnmatchedPattern : true; | ||
const ignoreUnknown = "ignoreUnknown" in options && isBoolean(options.ignoreUnknown) ? !!options.ignoreUnknown : globs.some(isGlobStatic); | ||
const ignoreUnknown = "ignoreUnknown" in options && isBoolean(options.ignoreUnknown) ? !!options.ignoreUnknown : globs.some(zeptomatchIsStatic); | ||
const logLevel = "logLevel" in options ? (options.logLevel || "log") : "log"; | ||
const parallel = "parallel" in options && !!options.parallel; | ||
const parallelWorkers = ("parallelWorkers" in options && Math.round(Number(options.parallelWorkers))) || 0; | ||
const stdinFilepath = "stdinFilepath" in options && isString(options.stdinFilepath) ? options.stdinFilepath : undefined; | ||
const contextOptions = normalizeContextOptions(options); | ||
@@ -314,2 +301,3 @@ const formatOptions = normalizeFormatOptions(options); | ||
parallelWorkers, | ||
stdinFilepath, | ||
contextOptions, | ||
@@ -323,2 +311,8 @@ formatOptions, | ||
const contextOptions = {}; | ||
if ("configPrecedence" in options) { | ||
const value = options.configPrecedence; | ||
if (isString(value) && (value === "cli-override" || value === "file-override")) { | ||
contextOptions.configPrecedence = value; | ||
} | ||
} | ||
if ("cursorOffset" in options) { | ||
@@ -540,13 +534,2 @@ const value = Number(options.cursorOffset); | ||
} | ||
function once(fn) { | ||
let inited = false; | ||
let result; | ||
return () => { | ||
if (!inited) { | ||
inited = true; | ||
result = fn(); | ||
} | ||
return result; | ||
}; | ||
} | ||
function pluralize(value, length) { | ||
@@ -574,9 +557,2 @@ return `${value}${length === 1 ? "" : "s"}`; | ||
} | ||
function zipObject(keys, values) { | ||
const map = {}; | ||
for (let i = 0, l = keys.length; i < l; i++) { | ||
map[keys[i]] = values[i]; | ||
} | ||
return map; | ||
} | ||
function zipObjectUnless(keys, values, unless) { | ||
@@ -592,2 +568,2 @@ const map = {}; | ||
} | ||
export { castArray, everyOf, fastJoinedPath, fastRelativePath, fastRelativeChildPath, findLastIndex, getCachePath, getFolderChildrenPaths, getFoldersChildrenPaths, getExpandedFoldersPaths, getGlobPaths, getModule, getModulePath, getPlugin, getPluginPath, getPluginVersion, getPlugins, getPluginsPaths, getPluginsVersions, getProjectPath, getTargetsPaths, isArray, isBoolean, isFalsy, isFunction, isInteger, isNumber, isObject, isPromise, isString, isTruthy, isUndefined, memoize, negate, noop, normalizeOptions, normalizeFormatOptions, normalizePluginOptions, normalizePrettierOptions, omit, once, pluralize, resolve, sha1hex, sha1base64, someOf, uniq, zipObject, zipObjectUnless, }; | ||
export { castArray, fastJoinedPath, fastRelativePath, fastRelativeChildPath, findLastIndex, getCachePath, getFolderChildrenPaths, getFoldersChildrenPaths, getExpandedFoldersPaths, getGlobPaths, getModule, getModulePath, getPlugin, getPluginPath, getPluginVersion, getPlugins, getPluginsBuiltin, getPluginsPaths, getPluginsVersions, getProjectPath, getStdin, getTargetsPaths, isArray, isBoolean, isFunction, isInteger, isNumber, isObject, isString, isTruthy, isUndefined, memoize, negate, noop, normalizeOptions, normalizeFormatOptions, normalizePluginOptions, normalizePrettierOptions, omit, once, pluralize, resolve, sha1hex, sha1base64, someOf, uniq, zipObjectUnless, }; |
@@ -6,8 +6,9 @@ { | ||
"license": "MIT", | ||
"version": "0.3.0", | ||
"version": "0.5.0", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"bin": { | ||
"prettier-next": "dist/bin.js" | ||
}, | ||
"main": "dist/index.js", | ||
"exports": { | ||
@@ -21,3 +22,6 @@ ".": "./dist/index.js", | ||
], | ||
"types": "./dist/index.d.ts", | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
"scripts": { | ||
@@ -30,7 +34,11 @@ "clean": "rm -rf dist", | ||
}, | ||
"peerDependencies": { | ||
"prettier": "^3.1.0 || ^4.0.0" | ||
}, | ||
"dependencies": { | ||
"@iarna/toml": "^2.2.5", | ||
"atomically": "^2.0.2", | ||
"fast-ignore": "^1.1.1", | ||
"find-up-json": "^2.0.2", | ||
"atomically": "^2.0.3", | ||
"fast-ignore": "^1.1.3", | ||
"find-up-json": "^2.0.4", | ||
"function-once": "^3.0.0", | ||
"import-meta-resolve": "^4.0.0", | ||
@@ -42,24 +50,21 @@ "is-binary-path": "^2.1.0", | ||
"kasi": "^1.1.0", | ||
"pioppo": "^1.1.0", | ||
"lomemo": "^1.0.0", | ||
"pioppo": "^1.1.1", | ||
"promise-resolve-timeout": "^2.0.0", | ||
"specialist": "^1.4.0", | ||
"tiny-editorconfig": "^1.0.0", | ||
"tiny-jsonc": "^1.0.1", | ||
"tiny-readdir-glob": "^1.2.1", | ||
"tiny-readdir-glob": "^1.22.24", | ||
"tiny-spinner": "^2.0.3", | ||
"worktank": "^2.6.0", | ||
"zeptomatch": "^1.2.2" | ||
"worktank": "^2.6.1", | ||
"zeptomatch": "^2.0.0", | ||
"zeptomatch-escape": "^1.0.0", | ||
"zeptomatch-is-static": "^1.0.0" | ||
}, | ||
"peerDependencies": { | ||
"prettier": "^3.1.0 || ^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/js-yaml": "^4.0.9", | ||
"@types/node": "^20.9.3", | ||
"@types/node": "^20.12.7", | ||
"prettier": "3.1.0", | ||
"typescript": "^5.3.2" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
"typescript": "^5.4.5" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122607
37
2905
24
+ Addedfunction-once@^3.0.0
+ Addedlomemo@^1.0.0
+ Addedzeptomatch-escape@^1.0.0
+ Addedzeptomatch-is-static@^1.0.0
+ Addedfunction-once@3.0.0(transitive)
+ Addedlomemo@1.0.0(transitive)
+ Addedpromise-resolve-timeout@2.0.0(transitive)
+ Addedzeptomatch@2.0.0(transitive)
+ Addedzeptomatch-escape@1.0.0(transitive)
Updatedatomically@^2.0.3
Updatedfast-ignore@^1.1.3
Updatedfind-up-json@^2.0.4
Updatedpioppo@^1.1.1
Updatedtiny-readdir-glob@^1.22.24
Updatedworktank@^2.6.1
Updatedzeptomatch@^2.0.0