prettier 3.0.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +138 -238
- package/README.md +1 -1
- package/bin/prettier.cjs +3 -2
- package/doc.js +12 -24
- package/doc.mjs +12 -24
- package/index.cjs +22 -29
- package/index.d.ts +9 -14
- package/index.mjs +3111 -616
- package/internal/cli.mjs +76 -70
- package/internal/internal.mjs +195 -6038
- package/package.json +5 -1
- package/plugins/acorn.js +12 -12
- package/plugins/acorn.mjs +12 -12
- package/plugins/angular.js +2 -2
- package/plugins/angular.mjs +2 -2
- package/plugins/babel.js +11 -11
- package/plugins/babel.mjs +11 -11
- package/plugins/estree.js +25 -25
- package/plugins/estree.mjs +25 -25
- package/plugins/flow.js +17 -17
- package/plugins/flow.mjs +17 -17
- package/plugins/glimmer.js +22 -22
- package/plugins/glimmer.mjs +22 -22
- package/plugins/html.js +17 -17
- package/plugins/html.mjs +17 -17
- package/plugins/markdown.js +46 -46
- package/plugins/markdown.mjs +46 -46
- package/plugins/meriyah.js +4 -4
- package/plugins/meriyah.mjs +4 -4
- package/plugins/postcss.js +20 -20
- package/plugins/postcss.mjs +21 -21
- package/plugins/typescript.js +3 -3
- package/plugins/typescript.mjs +3 -3
- package/standalone.js +29 -29
- package/standalone.mjs +29 -29
package/internal/cli.mjs
CHANGED
|
@@ -6204,18 +6204,27 @@ import path2 from "path";
|
|
|
6204
6204
|
async function* expandPatterns(context) {
|
|
6205
6205
|
const seen = /* @__PURE__ */ new Set();
|
|
6206
6206
|
let noResults = true;
|
|
6207
|
-
for await (const
|
|
6207
|
+
for await (const {
|
|
6208
|
+
filePath,
|
|
6209
|
+
ignoreUnknown,
|
|
6210
|
+
error
|
|
6211
|
+
} of expandPatternsInternal(context)) {
|
|
6208
6212
|
noResults = false;
|
|
6209
|
-
if (
|
|
6210
|
-
yield
|
|
6213
|
+
if (error) {
|
|
6214
|
+
yield {
|
|
6215
|
+
error
|
|
6216
|
+
};
|
|
6211
6217
|
continue;
|
|
6212
6218
|
}
|
|
6213
|
-
const
|
|
6214
|
-
if (seen.has(
|
|
6219
|
+
const filename = path2.resolve(filePath);
|
|
6220
|
+
if (seen.has(filename)) {
|
|
6215
6221
|
continue;
|
|
6216
6222
|
}
|
|
6217
|
-
seen.add(
|
|
6218
|
-
yield
|
|
6223
|
+
seen.add(filename);
|
|
6224
|
+
yield {
|
|
6225
|
+
filename,
|
|
6226
|
+
ignoreUnknown
|
|
6227
|
+
};
|
|
6219
6228
|
}
|
|
6220
6229
|
if (noResults && context.argv.errorOnUnmatchedPattern !== false) {
|
|
6221
6230
|
yield {
|
|
@@ -6233,7 +6242,6 @@ async function* expandPatternsInternal(context) {
|
|
|
6233
6242
|
ignore: silentlyIgnoredDirs.map((dir) => "**/" + dir),
|
|
6234
6243
|
followSymbolicLinks: false
|
|
6235
6244
|
};
|
|
6236
|
-
let supportedFilesGlob;
|
|
6237
6245
|
const cwd2 = process.cwd();
|
|
6238
6246
|
const entries = [];
|
|
6239
6247
|
for (const pattern of context.filePatterns) {
|
|
@@ -6258,8 +6266,9 @@ async function* expandPatternsInternal(context) {
|
|
|
6258
6266
|
const prefix = escapePathForGlob(fixWindowsSlashes(relativePath));
|
|
6259
6267
|
entries.push({
|
|
6260
6268
|
type: "dir",
|
|
6261
|
-
glob:
|
|
6262
|
-
input: pattern
|
|
6269
|
+
glob: `${prefix}/**/*`,
|
|
6270
|
+
input: pattern,
|
|
6271
|
+
ignoreUnknown: true
|
|
6263
6272
|
});
|
|
6264
6273
|
}
|
|
6265
6274
|
} else if (pattern[0] === "!") {
|
|
@@ -6275,7 +6284,8 @@ async function* expandPatternsInternal(context) {
|
|
|
6275
6284
|
for (const {
|
|
6276
6285
|
type,
|
|
6277
6286
|
glob,
|
|
6278
|
-
input
|
|
6287
|
+
input,
|
|
6288
|
+
ignoreUnknown
|
|
6279
6289
|
} of entries) {
|
|
6280
6290
|
let result;
|
|
6281
6291
|
try {
|
|
@@ -6296,22 +6306,10 @@ ${message}`
|
|
|
6296
6306
|
};
|
|
6297
6307
|
}
|
|
6298
6308
|
} else {
|
|
6299
|
-
yield* sortPaths(result)
|
|
6300
|
-
|
|
6301
|
-
|
|
6302
|
-
|
|
6303
|
-
supportedFilesGlob ?? (supportedFilesGlob = [...getSupportedFilesGlobWithoutCache()]);
|
|
6304
|
-
return supportedFilesGlob;
|
|
6305
|
-
}
|
|
6306
|
-
function* getSupportedFilesGlobWithoutCache() {
|
|
6307
|
-
for (const {
|
|
6308
|
-
extensions = [],
|
|
6309
|
-
filenames = []
|
|
6310
|
-
} of context.languages) {
|
|
6311
|
-
yield* filenames;
|
|
6312
|
-
for (const extension of extensions) {
|
|
6313
|
-
yield `*${extension.startsWith(".") ? extension : `.${extension}`}`;
|
|
6314
|
-
}
|
|
6309
|
+
yield* sortPaths(result).map((filePath) => ({
|
|
6310
|
+
filePath,
|
|
6311
|
+
ignoreUnknown
|
|
6312
|
+
}));
|
|
6315
6313
|
}
|
|
6316
6314
|
}
|
|
6317
6315
|
}
|
|
@@ -6649,9 +6647,6 @@ function useDirectory(directory, options) {
|
|
|
6649
6647
|
if (options.create) {
|
|
6650
6648
|
fs3.mkdirSync(directory, { recursive: true });
|
|
6651
6649
|
}
|
|
6652
|
-
if (options.thunk) {
|
|
6653
|
-
return (...arguments_) => path6.join(directory, ...arguments_);
|
|
6654
|
-
}
|
|
6655
6650
|
return directory;
|
|
6656
6651
|
}
|
|
6657
6652
|
function getNodeModuleDirectory(directory) {
|
|
@@ -6665,9 +6660,12 @@ function findCacheDirectory(options = {}) {
|
|
|
6665
6660
|
if (env2.CACHE_DIR && !["true", "false", "1", "0"].includes(env2.CACHE_DIR)) {
|
|
6666
6661
|
return useDirectory(path6.join(env2.CACHE_DIR, options.name), options);
|
|
6667
6662
|
}
|
|
6668
|
-
let { cwd: directory = cwd() } = options;
|
|
6669
|
-
if (
|
|
6670
|
-
|
|
6663
|
+
let { cwd: directory = cwd(), files } = options;
|
|
6664
|
+
if (files) {
|
|
6665
|
+
if (!Array.isArray(files)) {
|
|
6666
|
+
throw new TypeError(`Expected \`files\` option to be an array, got \`${typeof files}\`.`);
|
|
6667
|
+
}
|
|
6668
|
+
directory = (0, import_common_path_prefix.default)(files.map((file) => path6.resolve(directory, file)));
|
|
6671
6669
|
}
|
|
6672
6670
|
directory = packageDirectorySync({ cwd: directory });
|
|
6673
6671
|
if (!directory) {
|
|
@@ -6793,17 +6791,18 @@ function diff(a, b) {
|
|
|
6793
6791
|
var DebugError = class extends Error {
|
|
6794
6792
|
name = "DebugError";
|
|
6795
6793
|
};
|
|
6796
|
-
function handleError(context, filename, error, printedFilename) {
|
|
6794
|
+
function handleError(context, filename, error, printedFilename, ignoreUnknown) {
|
|
6795
|
+
ignoreUnknown || (ignoreUnknown = context.argv.ignoreUnknown);
|
|
6797
6796
|
const errorIsUndefinedParseError = error instanceof errors.UndefinedParserError;
|
|
6798
6797
|
if (printedFilename) {
|
|
6799
|
-
if ((context.argv.write ||
|
|
6798
|
+
if ((context.argv.write || ignoreUnknown) && errorIsUndefinedParseError) {
|
|
6800
6799
|
printedFilename.clear();
|
|
6801
6800
|
} else {
|
|
6802
6801
|
process.stdout.write("\n");
|
|
6803
6802
|
}
|
|
6804
6803
|
}
|
|
6805
6804
|
if (errorIsUndefinedParseError) {
|
|
6806
|
-
if (
|
|
6805
|
+
if (ignoreUnknown) {
|
|
6807
6806
|
return;
|
|
6808
6807
|
}
|
|
6809
6808
|
if (!context.argv.check && !context.argv.listDifferent) {
|
|
@@ -7014,27 +7013,20 @@ async function formatFiles(context) {
|
|
|
7014
7013
|
cacheFilePath,
|
|
7015
7014
|
context.argv.cacheStrategy || "content"
|
|
7016
7015
|
);
|
|
7017
|
-
} else {
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
);
|
|
7022
|
-
process.exit(2);
|
|
7023
|
-
}
|
|
7024
|
-
if (!context.argv.cacheLocation) {
|
|
7025
|
-
const stat = await statSafe(cacheFilePath);
|
|
7026
|
-
if (stat) {
|
|
7027
|
-
await fs5.unlink(cacheFilePath);
|
|
7028
|
-
}
|
|
7016
|
+
} else if (!context.argv.cacheLocation) {
|
|
7017
|
+
const stat = await statSafe(cacheFilePath);
|
|
7018
|
+
if (stat) {
|
|
7019
|
+
await fs5.unlink(cacheFilePath);
|
|
7029
7020
|
}
|
|
7030
7021
|
}
|
|
7031
|
-
for await (const
|
|
7032
|
-
|
|
7033
|
-
|
|
7022
|
+
for await (const { error, filename, ignoreUnknown } of expandPatterns(
|
|
7023
|
+
context
|
|
7024
|
+
)) {
|
|
7025
|
+
if (error) {
|
|
7026
|
+
context.logger.error(error);
|
|
7034
7027
|
process.exitCode = 2;
|
|
7035
7028
|
continue;
|
|
7036
7029
|
}
|
|
7037
|
-
const filename = pathOrError;
|
|
7038
7030
|
const isFileIgnored = isIgnored(filename);
|
|
7039
7031
|
if (isFileIgnored && (context.argv.debugCheck || context.argv.write || context.argv.check || context.argv.listDifferent)) {
|
|
7040
7032
|
continue;
|
|
@@ -7054,11 +7046,11 @@ async function formatFiles(context) {
|
|
|
7054
7046
|
let input;
|
|
7055
7047
|
try {
|
|
7056
7048
|
input = await fs5.readFile(filename, "utf8");
|
|
7057
|
-
} catch (
|
|
7049
|
+
} catch (error2) {
|
|
7058
7050
|
context.logger.log("");
|
|
7059
7051
|
context.logger.error(
|
|
7060
7052
|
`Unable to read file "${fileNameToDisplay}":
|
|
7061
|
-
${
|
|
7053
|
+
${error2.message}`
|
|
7062
7054
|
);
|
|
7063
7055
|
process.exitCode = 2;
|
|
7064
7056
|
continue;
|
|
@@ -7082,8 +7074,14 @@ ${error.message}`
|
|
|
7082
7074
|
result = await format2(context, input, options);
|
|
7083
7075
|
}
|
|
7084
7076
|
output = result.formatted;
|
|
7085
|
-
} catch (
|
|
7086
|
-
handleError(
|
|
7077
|
+
} catch (error2) {
|
|
7078
|
+
handleError(
|
|
7079
|
+
context,
|
|
7080
|
+
fileNameToDisplay,
|
|
7081
|
+
error2,
|
|
7082
|
+
printedFilename,
|
|
7083
|
+
ignoreUnknown
|
|
7084
|
+
);
|
|
7087
7085
|
continue;
|
|
7088
7086
|
}
|
|
7089
7087
|
const isDifferent = output !== input;
|
|
@@ -7103,15 +7101,15 @@ ${error.message}`
|
|
|
7103
7101
|
try {
|
|
7104
7102
|
await writeFormattedFile(filename, output);
|
|
7105
7103
|
shouldSetCache = true;
|
|
7106
|
-
} catch (
|
|
7104
|
+
} catch (error2) {
|
|
7107
7105
|
context.logger.error(
|
|
7108
7106
|
`Unable to write file "${fileNameToDisplay}":
|
|
7109
|
-
${
|
|
7107
|
+
${error2.message}`
|
|
7110
7108
|
);
|
|
7111
7109
|
process.exitCode = 2;
|
|
7112
7110
|
}
|
|
7113
7111
|
} else if (!context.argv.check && !context.argv.listDifferent) {
|
|
7114
|
-
const message = `${source_default.grey(fileNameToDisplay)} ${Date.now() - start}ms`;
|
|
7112
|
+
const message = `${source_default.grey(fileNameToDisplay)} ${Date.now() - start}ms (unchanged)`;
|
|
7115
7113
|
if (isCacheExists) {
|
|
7116
7114
|
context.logger.log(`${message} (cached)`);
|
|
7117
7115
|
} else {
|
|
@@ -7209,7 +7207,7 @@ async function printSupportInfo() {
|
|
|
7209
7207
|
var print_support_info_default = printSupportInfo;
|
|
7210
7208
|
|
|
7211
7209
|
// src/cli/index.js
|
|
7212
|
-
async function run(rawArguments) {
|
|
7210
|
+
async function run(rawArguments = process.argv.slice(2)) {
|
|
7213
7211
|
let logger = logger_default();
|
|
7214
7212
|
try {
|
|
7215
7213
|
const { logLevel } = parseArgvWithoutPlugins(
|
|
@@ -7245,6 +7243,9 @@ async function main(context) {
|
|
|
7245
7243
|
if (context.argv.fileInfo && context.filePatterns.length > 0) {
|
|
7246
7244
|
throw new Error("Cannot use --file-info with multiple files");
|
|
7247
7245
|
}
|
|
7246
|
+
if (!context.argv.cache && context.argv.cacheStrategy) {
|
|
7247
|
+
throw new Error("`--cache-strategy` cannot be used without `--cache`.");
|
|
7248
|
+
}
|
|
7248
7249
|
if (context.argv.version) {
|
|
7249
7250
|
printToScreen(prettier2.version);
|
|
7250
7251
|
return;
|
|
@@ -7258,24 +7259,29 @@ async function main(context) {
|
|
|
7258
7259
|
if (context.argv.supportInfo) {
|
|
7259
7260
|
return print_support_info_default();
|
|
7260
7261
|
}
|
|
7261
|
-
const hasFilePatterns = context.filePatterns.length > 0;
|
|
7262
|
-
const useStdin = !hasFilePatterns && (!process.stdin.isTTY || context.argv.filePath);
|
|
7263
7262
|
if (context.argv.findConfigPath) {
|
|
7264
7263
|
await find_config_path_default(context);
|
|
7265
|
-
|
|
7264
|
+
return;
|
|
7265
|
+
}
|
|
7266
|
+
if (context.argv.fileInfo) {
|
|
7266
7267
|
await file_info_default(context);
|
|
7267
|
-
|
|
7268
|
+
return;
|
|
7269
|
+
}
|
|
7270
|
+
const hasFilePatterns = context.filePatterns.length > 0;
|
|
7271
|
+
const useStdin = !hasFilePatterns && (!process.stdin.isTTY || context.argv.filepath);
|
|
7272
|
+
if (useStdin) {
|
|
7268
7273
|
if (context.argv.cache) {
|
|
7269
|
-
|
|
7270
|
-
process.exit(2);
|
|
7274
|
+
throw new Error("`--cache` cannot be used when formatting stdin.");
|
|
7271
7275
|
}
|
|
7272
7276
|
await formatStdin(context);
|
|
7273
|
-
|
|
7277
|
+
return;
|
|
7278
|
+
}
|
|
7279
|
+
if (hasFilePatterns) {
|
|
7274
7280
|
await formatFiles(context);
|
|
7275
|
-
|
|
7276
|
-
process.exitCode = 1;
|
|
7277
|
-
printToScreen(createUsage(context));
|
|
7281
|
+
return;
|
|
7278
7282
|
}
|
|
7283
|
+
process.exitCode = 1;
|
|
7284
|
+
printToScreen(createUsage(context));
|
|
7279
7285
|
}
|
|
7280
7286
|
export {
|
|
7281
7287
|
run
|