prettier 3.0.3 → 4.0.0-alpha.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 +171 -310
- package/README.md +1 -1
- package/bin/prettier.cjs +9 -4
- package/doc.js +17 -29
- package/doc.mjs +12 -24
- package/index.cjs +22 -29
- package/index.d.ts +13 -18
- package/index.mjs +3257 -834
- package/internal/cli.mjs +84 -82
- package/internal/internal.mjs +188 -6073
- package/package.json +9 -2
- package/plugins/acorn.js +12 -12
- package/plugins/acorn.mjs +12 -12
- package/plugins/angular.js +1 -2
- package/plugins/angular.mjs +1 -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 +5 -5
- package/plugins/meriyah.mjs +5 -5
- package/plugins/postcss.js +20 -20
- package/plugins/postcss.mjs +21 -21
- package/plugins/typescript.js +20 -20
- package/plugins/typescript.mjs +20 -20
- package/standalone.js +29 -29
- package/standalone.mjs +29 -29
package/internal/cli.mjs
CHANGED
|
@@ -1371,23 +1371,19 @@ var require_src = __commonJS({
|
|
|
1371
1371
|
return void 0;
|
|
1372
1372
|
}
|
|
1373
1373
|
if (isArray) {
|
|
1374
|
-
|
|
1375
|
-
for (let row of data) {
|
|
1374
|
+
return data.map((row, index) => {
|
|
1376
1375
|
if (typeof row === "string") {
|
|
1377
1376
|
row = this.opts.deserialize(row);
|
|
1378
1377
|
}
|
|
1379
1378
|
if (row === void 0 || row === null) {
|
|
1380
|
-
|
|
1381
|
-
continue;
|
|
1379
|
+
return void 0;
|
|
1382
1380
|
}
|
|
1383
1381
|
if (typeof row.expires === "number" && Date.now() > row.expires) {
|
|
1384
|
-
this.delete(key).then(() => void 0);
|
|
1385
|
-
|
|
1386
|
-
} else {
|
|
1387
|
-
result.push(options && options.raw ? row : row.value);
|
|
1382
|
+
this.delete(key[index]).then(() => void 0);
|
|
1383
|
+
return void 0;
|
|
1388
1384
|
}
|
|
1389
|
-
|
|
1390
|
-
|
|
1385
|
+
return options && options.raw ? row : row.value;
|
|
1386
|
+
});
|
|
1391
1387
|
}
|
|
1392
1388
|
if (typeof data.expires === "number" && Date.now() > data.expires) {
|
|
1393
1389
|
return this.delete(key).then(() => void 0);
|
|
@@ -6204,18 +6200,27 @@ import path2 from "path";
|
|
|
6204
6200
|
async function* expandPatterns(context) {
|
|
6205
6201
|
const seen = /* @__PURE__ */ new Set();
|
|
6206
6202
|
let noResults = true;
|
|
6207
|
-
for await (const
|
|
6203
|
+
for await (const {
|
|
6204
|
+
filePath,
|
|
6205
|
+
ignoreUnknown,
|
|
6206
|
+
error
|
|
6207
|
+
} of expandPatternsInternal(context)) {
|
|
6208
6208
|
noResults = false;
|
|
6209
|
-
if (
|
|
6210
|
-
yield
|
|
6209
|
+
if (error) {
|
|
6210
|
+
yield {
|
|
6211
|
+
error
|
|
6212
|
+
};
|
|
6211
6213
|
continue;
|
|
6212
6214
|
}
|
|
6213
|
-
const
|
|
6214
|
-
if (seen.has(
|
|
6215
|
+
const filename = path2.resolve(filePath);
|
|
6216
|
+
if (seen.has(filename)) {
|
|
6215
6217
|
continue;
|
|
6216
6218
|
}
|
|
6217
|
-
seen.add(
|
|
6218
|
-
yield
|
|
6219
|
+
seen.add(filename);
|
|
6220
|
+
yield {
|
|
6221
|
+
filename,
|
|
6222
|
+
ignoreUnknown
|
|
6223
|
+
};
|
|
6219
6224
|
}
|
|
6220
6225
|
if (noResults && context.argv.errorOnUnmatchedPattern !== false) {
|
|
6221
6226
|
yield {
|
|
@@ -6233,7 +6238,6 @@ async function* expandPatternsInternal(context) {
|
|
|
6233
6238
|
ignore: silentlyIgnoredDirs.map((dir) => "**/" + dir),
|
|
6234
6239
|
followSymbolicLinks: false
|
|
6235
6240
|
};
|
|
6236
|
-
let supportedFilesGlob;
|
|
6237
6241
|
const cwd2 = process.cwd();
|
|
6238
6242
|
const entries = [];
|
|
6239
6243
|
for (const pattern of context.filePatterns) {
|
|
@@ -6258,8 +6262,9 @@ async function* expandPatternsInternal(context) {
|
|
|
6258
6262
|
const prefix = escapePathForGlob(fixWindowsSlashes(relativePath));
|
|
6259
6263
|
entries.push({
|
|
6260
6264
|
type: "dir",
|
|
6261
|
-
glob:
|
|
6262
|
-
input: pattern
|
|
6265
|
+
glob: `${prefix}/**/*`,
|
|
6266
|
+
input: pattern,
|
|
6267
|
+
ignoreUnknown: true
|
|
6263
6268
|
});
|
|
6264
6269
|
}
|
|
6265
6270
|
} else if (pattern[0] === "!") {
|
|
@@ -6275,7 +6280,8 @@ async function* expandPatternsInternal(context) {
|
|
|
6275
6280
|
for (const {
|
|
6276
6281
|
type,
|
|
6277
6282
|
glob,
|
|
6278
|
-
input
|
|
6283
|
+
input,
|
|
6284
|
+
ignoreUnknown
|
|
6279
6285
|
} of entries) {
|
|
6280
6286
|
let result;
|
|
6281
6287
|
try {
|
|
@@ -6296,22 +6302,10 @@ ${message}`
|
|
|
6296
6302
|
};
|
|
6297
6303
|
}
|
|
6298
6304
|
} 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
|
-
}
|
|
6305
|
+
yield* sortPaths(result).map((filePath) => ({
|
|
6306
|
+
filePath,
|
|
6307
|
+
ignoreUnknown
|
|
6308
|
+
}));
|
|
6315
6309
|
}
|
|
6316
6310
|
}
|
|
6317
6311
|
}
|
|
@@ -6420,7 +6414,7 @@ async function getOptionsOrDie(context, filePath) {
|
|
|
6420
6414
|
return options;
|
|
6421
6415
|
} catch (error) {
|
|
6422
6416
|
context.logger.error(
|
|
6423
|
-
`Invalid configuration for file "${filePath}":
|
|
6417
|
+
`Invalid configuration${filePath ? ` for file "${filePath}"` : ""}:
|
|
6424
6418
|
` + error.message
|
|
6425
6419
|
);
|
|
6426
6420
|
process.exit(2);
|
|
@@ -6649,9 +6643,6 @@ function useDirectory(directory, options) {
|
|
|
6649
6643
|
if (options.create) {
|
|
6650
6644
|
fs3.mkdirSync(directory, { recursive: true });
|
|
6651
6645
|
}
|
|
6652
|
-
if (options.thunk) {
|
|
6653
|
-
return (...arguments_) => path6.join(directory, ...arguments_);
|
|
6654
|
-
}
|
|
6655
6646
|
return directory;
|
|
6656
6647
|
}
|
|
6657
6648
|
function getNodeModuleDirectory(directory) {
|
|
@@ -6665,9 +6656,12 @@ function findCacheDirectory(options = {}) {
|
|
|
6665
6656
|
if (env2.CACHE_DIR && !["true", "false", "1", "0"].includes(env2.CACHE_DIR)) {
|
|
6666
6657
|
return useDirectory(path6.join(env2.CACHE_DIR, options.name), options);
|
|
6667
6658
|
}
|
|
6668
|
-
let { cwd: directory = cwd() } = options;
|
|
6669
|
-
if (
|
|
6670
|
-
|
|
6659
|
+
let { cwd: directory = cwd(), files } = options;
|
|
6660
|
+
if (files) {
|
|
6661
|
+
if (!Array.isArray(files)) {
|
|
6662
|
+
throw new TypeError(`Expected \`files\` option to be an array, got \`${typeof files}\`.`);
|
|
6663
|
+
}
|
|
6664
|
+
directory = (0, import_common_path_prefix.default)(files.map((file) => path6.resolve(directory, file)));
|
|
6671
6665
|
}
|
|
6672
6666
|
directory = packageDirectorySync({ cwd: directory });
|
|
6673
6667
|
if (!directory) {
|
|
@@ -6793,17 +6787,18 @@ function diff(a, b) {
|
|
|
6793
6787
|
var DebugError = class extends Error {
|
|
6794
6788
|
name = "DebugError";
|
|
6795
6789
|
};
|
|
6796
|
-
function handleError(context, filename, error, printedFilename) {
|
|
6790
|
+
function handleError(context, filename, error, printedFilename, ignoreUnknown) {
|
|
6791
|
+
ignoreUnknown || (ignoreUnknown = context.argv.ignoreUnknown);
|
|
6797
6792
|
const errorIsUndefinedParseError = error instanceof errors.UndefinedParserError;
|
|
6798
6793
|
if (printedFilename) {
|
|
6799
|
-
if ((context.argv.write ||
|
|
6794
|
+
if ((context.argv.write || ignoreUnknown) && errorIsUndefinedParseError) {
|
|
6800
6795
|
printedFilename.clear();
|
|
6801
6796
|
} else {
|
|
6802
6797
|
process.stdout.write("\n");
|
|
6803
6798
|
}
|
|
6804
6799
|
}
|
|
6805
6800
|
if (errorIsUndefinedParseError) {
|
|
6806
|
-
if (
|
|
6801
|
+
if (ignoreUnknown) {
|
|
6807
6802
|
return;
|
|
6808
6803
|
}
|
|
6809
6804
|
if (!context.argv.check && !context.argv.listDifferent) {
|
|
@@ -6981,7 +6976,7 @@ async function formatStdin(context) {
|
|
|
6981
6976
|
}
|
|
6982
6977
|
const options = await get_options_for_file_default(
|
|
6983
6978
|
context,
|
|
6984
|
-
filepath ? path8.resolve(
|
|
6979
|
+
filepath ? path8.resolve(filepath) : void 0
|
|
6985
6980
|
);
|
|
6986
6981
|
if (await listDifferent(context, input, options, "(stdin)")) {
|
|
6987
6982
|
return;
|
|
@@ -7014,27 +7009,20 @@ async function formatFiles(context) {
|
|
|
7014
7009
|
cacheFilePath,
|
|
7015
7010
|
context.argv.cacheStrategy || "content"
|
|
7016
7011
|
);
|
|
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
|
-
}
|
|
7012
|
+
} else if (!context.argv.cacheLocation) {
|
|
7013
|
+
const stat = await statSafe(cacheFilePath);
|
|
7014
|
+
if (stat) {
|
|
7015
|
+
await fs5.unlink(cacheFilePath);
|
|
7029
7016
|
}
|
|
7030
7017
|
}
|
|
7031
|
-
for await (const
|
|
7032
|
-
|
|
7033
|
-
|
|
7018
|
+
for await (const { error, filename, ignoreUnknown } of expandPatterns(
|
|
7019
|
+
context
|
|
7020
|
+
)) {
|
|
7021
|
+
if (error) {
|
|
7022
|
+
context.logger.error(error);
|
|
7034
7023
|
process.exitCode = 2;
|
|
7035
7024
|
continue;
|
|
7036
7025
|
}
|
|
7037
|
-
const filename = pathOrError;
|
|
7038
7026
|
const isFileIgnored = isIgnored(filename);
|
|
7039
7027
|
if (isFileIgnored && (context.argv.debugCheck || context.argv.write || context.argv.check || context.argv.listDifferent)) {
|
|
7040
7028
|
continue;
|
|
@@ -7054,11 +7042,11 @@ async function formatFiles(context) {
|
|
|
7054
7042
|
let input;
|
|
7055
7043
|
try {
|
|
7056
7044
|
input = await fs5.readFile(filename, "utf8");
|
|
7057
|
-
} catch (
|
|
7045
|
+
} catch (error2) {
|
|
7058
7046
|
context.logger.log("");
|
|
7059
7047
|
context.logger.error(
|
|
7060
7048
|
`Unable to read file "${fileNameToDisplay}":
|
|
7061
|
-
${
|
|
7049
|
+
${error2.message}`
|
|
7062
7050
|
);
|
|
7063
7051
|
process.exitCode = 2;
|
|
7064
7052
|
continue;
|
|
@@ -7082,8 +7070,14 @@ ${error.message}`
|
|
|
7082
7070
|
result = await format2(context, input, options);
|
|
7083
7071
|
}
|
|
7084
7072
|
output = result.formatted;
|
|
7085
|
-
} catch (
|
|
7086
|
-
handleError(
|
|
7073
|
+
} catch (error2) {
|
|
7074
|
+
handleError(
|
|
7075
|
+
context,
|
|
7076
|
+
fileNameToDisplay,
|
|
7077
|
+
error2,
|
|
7078
|
+
printedFilename,
|
|
7079
|
+
ignoreUnknown
|
|
7080
|
+
);
|
|
7087
7081
|
continue;
|
|
7088
7082
|
}
|
|
7089
7083
|
const isDifferent = output !== input;
|
|
@@ -7103,15 +7097,15 @@ ${error.message}`
|
|
|
7103
7097
|
try {
|
|
7104
7098
|
await writeFormattedFile(filename, output);
|
|
7105
7099
|
shouldSetCache = true;
|
|
7106
|
-
} catch (
|
|
7100
|
+
} catch (error2) {
|
|
7107
7101
|
context.logger.error(
|
|
7108
7102
|
`Unable to write file "${fileNameToDisplay}":
|
|
7109
|
-
${
|
|
7103
|
+
${error2.message}`
|
|
7110
7104
|
);
|
|
7111
7105
|
process.exitCode = 2;
|
|
7112
7106
|
}
|
|
7113
7107
|
} else if (!context.argv.check && !context.argv.listDifferent) {
|
|
7114
|
-
const message = `${source_default.grey(fileNameToDisplay)} ${Date.now() - start}ms`;
|
|
7108
|
+
const message = `${source_default.grey(fileNameToDisplay)} ${Date.now() - start}ms (unchanged)`;
|
|
7115
7109
|
if (isCacheExists) {
|
|
7116
7110
|
context.logger.log(`${message} (cached)`);
|
|
7117
7111
|
} else {
|
|
@@ -7209,7 +7203,7 @@ async function printSupportInfo() {
|
|
|
7209
7203
|
var print_support_info_default = printSupportInfo;
|
|
7210
7204
|
|
|
7211
7205
|
// src/cli/index.js
|
|
7212
|
-
async function run(rawArguments) {
|
|
7206
|
+
async function run(rawArguments = process.argv.slice(2)) {
|
|
7213
7207
|
let logger = logger_default();
|
|
7214
7208
|
try {
|
|
7215
7209
|
const { logLevel } = parseArgvWithoutPlugins(
|
|
@@ -7245,6 +7239,9 @@ async function main(context) {
|
|
|
7245
7239
|
if (context.argv.fileInfo && context.filePatterns.length > 0) {
|
|
7246
7240
|
throw new Error("Cannot use --file-info with multiple files");
|
|
7247
7241
|
}
|
|
7242
|
+
if (!context.argv.cache && context.argv.cacheStrategy) {
|
|
7243
|
+
throw new Error("`--cache-strategy` cannot be used without `--cache`.");
|
|
7244
|
+
}
|
|
7248
7245
|
if (context.argv.version) {
|
|
7249
7246
|
printToScreen(prettier2.version);
|
|
7250
7247
|
return;
|
|
@@ -7258,24 +7255,29 @@ async function main(context) {
|
|
|
7258
7255
|
if (context.argv.supportInfo) {
|
|
7259
7256
|
return print_support_info_default();
|
|
7260
7257
|
}
|
|
7261
|
-
const hasFilePatterns = context.filePatterns.length > 0;
|
|
7262
|
-
const useStdin = !hasFilePatterns && (!process.stdin.isTTY || context.argv.filePath);
|
|
7263
7258
|
if (context.argv.findConfigPath) {
|
|
7264
7259
|
await find_config_path_default(context);
|
|
7265
|
-
|
|
7260
|
+
return;
|
|
7261
|
+
}
|
|
7262
|
+
if (context.argv.fileInfo) {
|
|
7266
7263
|
await file_info_default(context);
|
|
7267
|
-
|
|
7264
|
+
return;
|
|
7265
|
+
}
|
|
7266
|
+
const hasFilePatterns = context.filePatterns.length > 0;
|
|
7267
|
+
const useStdin = !hasFilePatterns && (!process.stdin.isTTY || context.argv.filepath);
|
|
7268
|
+
if (useStdin) {
|
|
7268
7269
|
if (context.argv.cache) {
|
|
7269
|
-
|
|
7270
|
-
process.exit(2);
|
|
7270
|
+
throw new Error("`--cache` cannot be used when formatting stdin.");
|
|
7271
7271
|
}
|
|
7272
7272
|
await formatStdin(context);
|
|
7273
|
-
|
|
7273
|
+
return;
|
|
7274
|
+
}
|
|
7275
|
+
if (hasFilePatterns) {
|
|
7274
7276
|
await formatFiles(context);
|
|
7275
|
-
|
|
7276
|
-
process.exitCode = 1;
|
|
7277
|
-
printToScreen(createUsage(context));
|
|
7277
|
+
return;
|
|
7278
7278
|
}
|
|
7279
|
+
process.exitCode = 1;
|
|
7280
|
+
printToScreen(createUsage(context));
|
|
7279
7281
|
}
|
|
7280
7282
|
export {
|
|
7281
7283
|
run
|