prettier 3.0.2 → 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 +189 -244
- package/README.md +1 -1
- package/bin/prettier.cjs +3 -2
- package/doc.d.ts +3 -0
- package/doc.js +12 -24
- package/doc.mjs +12 -24
- package/index.cjs +22 -29
- package/index.d.ts +18 -14
- package/index.mjs +3198 -648
- package/internal/cli.mjs +353 -65
- package/internal/internal.mjs +195 -6038
- package/package.json +7 -2
- 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 +20 -20
- package/plugins/typescript.mjs +20 -20
- package/standalone.js +29 -29
- package/standalone.mjs +29 -29
package/internal/cli.mjs
CHANGED
|
@@ -1197,6 +1197,264 @@ var require_common_path_prefix = __commonJS({
|
|
|
1197
1197
|
}
|
|
1198
1198
|
});
|
|
1199
1199
|
|
|
1200
|
+
// node_modules/json-buffer/index.js
|
|
1201
|
+
var require_json_buffer = __commonJS({
|
|
1202
|
+
"node_modules/json-buffer/index.js"(exports) {
|
|
1203
|
+
exports.stringify = function stringify4(o) {
|
|
1204
|
+
if ("undefined" == typeof o)
|
|
1205
|
+
return o;
|
|
1206
|
+
if (o && Buffer.isBuffer(o))
|
|
1207
|
+
return JSON.stringify(":base64:" + o.toString("base64"));
|
|
1208
|
+
if (o && o.toJSON)
|
|
1209
|
+
o = o.toJSON();
|
|
1210
|
+
if (o && "object" === typeof o) {
|
|
1211
|
+
var s = "";
|
|
1212
|
+
var array2 = Array.isArray(o);
|
|
1213
|
+
s = array2 ? "[" : "{";
|
|
1214
|
+
var first = true;
|
|
1215
|
+
for (var k in o) {
|
|
1216
|
+
var ignore = "function" == typeof o[k] || !array2 && "undefined" === typeof o[k];
|
|
1217
|
+
if (Object.hasOwnProperty.call(o, k) && !ignore) {
|
|
1218
|
+
if (!first)
|
|
1219
|
+
s += ",";
|
|
1220
|
+
first = false;
|
|
1221
|
+
if (array2) {
|
|
1222
|
+
if (o[k] == void 0)
|
|
1223
|
+
s += "null";
|
|
1224
|
+
else
|
|
1225
|
+
s += stringify4(o[k]);
|
|
1226
|
+
} else if (o[k] !== void 0) {
|
|
1227
|
+
s += stringify4(k) + ":" + stringify4(o[k]);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
s += array2 ? "]" : "}";
|
|
1232
|
+
return s;
|
|
1233
|
+
} else if ("string" === typeof o) {
|
|
1234
|
+
return JSON.stringify(/^:/.test(o) ? ":" + o : o);
|
|
1235
|
+
} else if ("undefined" === typeof o) {
|
|
1236
|
+
return "null";
|
|
1237
|
+
} else
|
|
1238
|
+
return JSON.stringify(o);
|
|
1239
|
+
};
|
|
1240
|
+
exports.parse = function(s) {
|
|
1241
|
+
return JSON.parse(s, function(key, value) {
|
|
1242
|
+
if ("string" === typeof value) {
|
|
1243
|
+
if (/^:base64:/.test(value))
|
|
1244
|
+
return Buffer.from(value.substring(8), "base64");
|
|
1245
|
+
else
|
|
1246
|
+
return /^:/.test(value) ? value.substring(1) : value;
|
|
1247
|
+
}
|
|
1248
|
+
return value;
|
|
1249
|
+
});
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
|
|
1254
|
+
// node_modules/keyv/src/index.js
|
|
1255
|
+
var require_src = __commonJS({
|
|
1256
|
+
"node_modules/keyv/src/index.js"(exports, module) {
|
|
1257
|
+
"use strict";
|
|
1258
|
+
var EventEmitter = __require("events");
|
|
1259
|
+
var JSONB = require_json_buffer();
|
|
1260
|
+
var loadStore = (options) => {
|
|
1261
|
+
const adapters = {
|
|
1262
|
+
redis: "@keyv/redis",
|
|
1263
|
+
rediss: "@keyv/redis",
|
|
1264
|
+
mongodb: "@keyv/mongo",
|
|
1265
|
+
mongo: "@keyv/mongo",
|
|
1266
|
+
sqlite: "@keyv/sqlite",
|
|
1267
|
+
postgresql: "@keyv/postgres",
|
|
1268
|
+
postgres: "@keyv/postgres",
|
|
1269
|
+
mysql: "@keyv/mysql",
|
|
1270
|
+
etcd: "@keyv/etcd",
|
|
1271
|
+
offline: "@keyv/offline",
|
|
1272
|
+
tiered: "@keyv/tiered"
|
|
1273
|
+
};
|
|
1274
|
+
if (options.adapter || options.uri) {
|
|
1275
|
+
const adapter = options.adapter || /^[^:+]*/.exec(options.uri)[0];
|
|
1276
|
+
return new (__require(adapters[adapter]))(options);
|
|
1277
|
+
}
|
|
1278
|
+
return /* @__PURE__ */ new Map();
|
|
1279
|
+
};
|
|
1280
|
+
var iterableAdapters = [
|
|
1281
|
+
"sqlite",
|
|
1282
|
+
"postgres",
|
|
1283
|
+
"mysql",
|
|
1284
|
+
"mongo",
|
|
1285
|
+
"redis",
|
|
1286
|
+
"tiered"
|
|
1287
|
+
];
|
|
1288
|
+
var Keyv = class extends EventEmitter {
|
|
1289
|
+
constructor(uri, { emitErrors = true, ...options } = {}) {
|
|
1290
|
+
super();
|
|
1291
|
+
this.opts = {
|
|
1292
|
+
namespace: "keyv",
|
|
1293
|
+
serialize: JSONB.stringify,
|
|
1294
|
+
deserialize: JSONB.parse,
|
|
1295
|
+
...typeof uri === "string" ? { uri } : uri,
|
|
1296
|
+
...options
|
|
1297
|
+
};
|
|
1298
|
+
if (!this.opts.store) {
|
|
1299
|
+
const adapterOptions = { ...this.opts };
|
|
1300
|
+
this.opts.store = loadStore(adapterOptions);
|
|
1301
|
+
}
|
|
1302
|
+
if (this.opts.compression) {
|
|
1303
|
+
const compression = this.opts.compression;
|
|
1304
|
+
this.opts.serialize = compression.serialize.bind(compression);
|
|
1305
|
+
this.opts.deserialize = compression.deserialize.bind(compression);
|
|
1306
|
+
}
|
|
1307
|
+
if (typeof this.opts.store.on === "function" && emitErrors) {
|
|
1308
|
+
this.opts.store.on("error", (error) => this.emit("error", error));
|
|
1309
|
+
}
|
|
1310
|
+
this.opts.store.namespace = this.opts.namespace;
|
|
1311
|
+
const generateIterator = (iterator) => async function* () {
|
|
1312
|
+
for await (const [key, raw] of typeof iterator === "function" ? iterator(this.opts.store.namespace) : iterator) {
|
|
1313
|
+
const data = await this.opts.deserialize(raw);
|
|
1314
|
+
if (this.opts.store.namespace && !key.includes(this.opts.store.namespace)) {
|
|
1315
|
+
continue;
|
|
1316
|
+
}
|
|
1317
|
+
if (typeof data.expires === "number" && Date.now() > data.expires) {
|
|
1318
|
+
this.delete(key);
|
|
1319
|
+
continue;
|
|
1320
|
+
}
|
|
1321
|
+
yield [this._getKeyUnprefix(key), data.value];
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
if (typeof this.opts.store[Symbol.iterator] === "function" && this.opts.store instanceof Map) {
|
|
1325
|
+
this.iterator = generateIterator(this.opts.store);
|
|
1326
|
+
} else if (typeof this.opts.store.iterator === "function" && this.opts.store.opts && this._checkIterableAdaptar()) {
|
|
1327
|
+
this.iterator = generateIterator(this.opts.store.iterator.bind(this.opts.store));
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
_checkIterableAdaptar() {
|
|
1331
|
+
return iterableAdapters.includes(this.opts.store.opts.dialect) || iterableAdapters.findIndex((element) => this.opts.store.opts.url.includes(element)) >= 0;
|
|
1332
|
+
}
|
|
1333
|
+
_getKeyPrefix(key) {
|
|
1334
|
+
return `${this.opts.namespace}:${key}`;
|
|
1335
|
+
}
|
|
1336
|
+
_getKeyPrefixArray(keys) {
|
|
1337
|
+
return keys.map((key) => `${this.opts.namespace}:${key}`);
|
|
1338
|
+
}
|
|
1339
|
+
_getKeyUnprefix(key) {
|
|
1340
|
+
return key.split(":").splice(1).join(":");
|
|
1341
|
+
}
|
|
1342
|
+
get(key, options) {
|
|
1343
|
+
const { store } = this.opts;
|
|
1344
|
+
const isArray = Array.isArray(key);
|
|
1345
|
+
const keyPrefixed = isArray ? this._getKeyPrefixArray(key) : this._getKeyPrefix(key);
|
|
1346
|
+
if (isArray && store.getMany === void 0) {
|
|
1347
|
+
const promises = [];
|
|
1348
|
+
for (const key2 of keyPrefixed) {
|
|
1349
|
+
promises.push(
|
|
1350
|
+
Promise.resolve().then(() => store.get(key2)).then((data) => typeof data === "string" ? this.opts.deserialize(data) : this.opts.compression ? this.opts.deserialize(data) : data).then((data) => {
|
|
1351
|
+
if (data === void 0 || data === null) {
|
|
1352
|
+
return void 0;
|
|
1353
|
+
}
|
|
1354
|
+
if (typeof data.expires === "number" && Date.now() > data.expires) {
|
|
1355
|
+
return this.delete(key2).then(() => void 0);
|
|
1356
|
+
}
|
|
1357
|
+
return options && options.raw ? data : data.value;
|
|
1358
|
+
})
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
return Promise.allSettled(promises).then((values) => {
|
|
1362
|
+
const data = [];
|
|
1363
|
+
for (const value of values) {
|
|
1364
|
+
data.push(value.value);
|
|
1365
|
+
}
|
|
1366
|
+
return data;
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
return Promise.resolve().then(() => isArray ? store.getMany(keyPrefixed) : store.get(keyPrefixed)).then((data) => typeof data === "string" ? this.opts.deserialize(data) : this.opts.compression ? this.opts.deserialize(data) : data).then((data) => {
|
|
1370
|
+
if (data === void 0 || data === null) {
|
|
1371
|
+
return void 0;
|
|
1372
|
+
}
|
|
1373
|
+
if (isArray) {
|
|
1374
|
+
const result = [];
|
|
1375
|
+
for (let row of data) {
|
|
1376
|
+
if (typeof row === "string") {
|
|
1377
|
+
row = this.opts.deserialize(row);
|
|
1378
|
+
}
|
|
1379
|
+
if (row === void 0 || row === null) {
|
|
1380
|
+
result.push(void 0);
|
|
1381
|
+
continue;
|
|
1382
|
+
}
|
|
1383
|
+
if (typeof row.expires === "number" && Date.now() > row.expires) {
|
|
1384
|
+
this.delete(key).then(() => void 0);
|
|
1385
|
+
result.push(void 0);
|
|
1386
|
+
} else {
|
|
1387
|
+
result.push(options && options.raw ? row : row.value);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
return result;
|
|
1391
|
+
}
|
|
1392
|
+
if (typeof data.expires === "number" && Date.now() > data.expires) {
|
|
1393
|
+
return this.delete(key).then(() => void 0);
|
|
1394
|
+
}
|
|
1395
|
+
return options && options.raw ? data : data.value;
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
set(key, value, ttl) {
|
|
1399
|
+
const keyPrefixed = this._getKeyPrefix(key);
|
|
1400
|
+
if (typeof ttl === "undefined") {
|
|
1401
|
+
ttl = this.opts.ttl;
|
|
1402
|
+
}
|
|
1403
|
+
if (ttl === 0) {
|
|
1404
|
+
ttl = void 0;
|
|
1405
|
+
}
|
|
1406
|
+
const { store } = this.opts;
|
|
1407
|
+
return Promise.resolve().then(() => {
|
|
1408
|
+
const expires = typeof ttl === "number" ? Date.now() + ttl : null;
|
|
1409
|
+
if (typeof value === "symbol") {
|
|
1410
|
+
this.emit("error", "symbol cannot be serialized");
|
|
1411
|
+
}
|
|
1412
|
+
value = { value, expires };
|
|
1413
|
+
return this.opts.serialize(value);
|
|
1414
|
+
}).then((value2) => store.set(keyPrefixed, value2, ttl)).then(() => true);
|
|
1415
|
+
}
|
|
1416
|
+
delete(key) {
|
|
1417
|
+
const { store } = this.opts;
|
|
1418
|
+
if (Array.isArray(key)) {
|
|
1419
|
+
const keyPrefixed2 = this._getKeyPrefixArray(key);
|
|
1420
|
+
if (store.deleteMany === void 0) {
|
|
1421
|
+
const promises = [];
|
|
1422
|
+
for (const key2 of keyPrefixed2) {
|
|
1423
|
+
promises.push(store.delete(key2));
|
|
1424
|
+
}
|
|
1425
|
+
return Promise.allSettled(promises).then((values) => values.every((x) => x.value === true));
|
|
1426
|
+
}
|
|
1427
|
+
return Promise.resolve().then(() => store.deleteMany(keyPrefixed2));
|
|
1428
|
+
}
|
|
1429
|
+
const keyPrefixed = this._getKeyPrefix(key);
|
|
1430
|
+
return Promise.resolve().then(() => store.delete(keyPrefixed));
|
|
1431
|
+
}
|
|
1432
|
+
clear() {
|
|
1433
|
+
const { store } = this.opts;
|
|
1434
|
+
return Promise.resolve().then(() => store.clear());
|
|
1435
|
+
}
|
|
1436
|
+
has(key) {
|
|
1437
|
+
const keyPrefixed = this._getKeyPrefix(key);
|
|
1438
|
+
const { store } = this.opts;
|
|
1439
|
+
return Promise.resolve().then(async () => {
|
|
1440
|
+
if (typeof store.has === "function") {
|
|
1441
|
+
return store.has(keyPrefixed);
|
|
1442
|
+
}
|
|
1443
|
+
const value = await store.get(keyPrefixed);
|
|
1444
|
+
return value !== void 0;
|
|
1445
|
+
});
|
|
1446
|
+
}
|
|
1447
|
+
disconnect() {
|
|
1448
|
+
const { store } = this.opts;
|
|
1449
|
+
if (typeof store.disconnect === "function") {
|
|
1450
|
+
return store.disconnect();
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
};
|
|
1454
|
+
module.exports = Keyv;
|
|
1455
|
+
}
|
|
1456
|
+
});
|
|
1457
|
+
|
|
1200
1458
|
// node_modules/flatted/cjs/index.js
|
|
1201
1459
|
var require_cjs = __commonJS({
|
|
1202
1460
|
"node_modules/flatted/cjs/index.js"(exports) {
|
|
@@ -4008,6 +4266,7 @@ var require_cache = __commonJS({
|
|
|
4008
4266
|
"node_modules/flat-cache/src/cache.js"(exports, module) {
|
|
4009
4267
|
var path10 = __require("path");
|
|
4010
4268
|
var fs6 = __require("fs");
|
|
4269
|
+
var Keyv = require_src();
|
|
4011
4270
|
var utils = require_utils();
|
|
4012
4271
|
var del = require_del();
|
|
4013
4272
|
var writeJSON = utils.writeJSON;
|
|
@@ -4023,13 +4282,28 @@ var require_cache = __commonJS({
|
|
|
4023
4282
|
*/
|
|
4024
4283
|
load: function(docId, cacheDir) {
|
|
4025
4284
|
var me = this;
|
|
4026
|
-
me.
|
|
4027
|
-
me.
|
|
4285
|
+
me.keyv = new Keyv();
|
|
4286
|
+
me.__visited = {};
|
|
4287
|
+
me.__persisted = {};
|
|
4028
4288
|
me._pathToFile = cacheDir ? path10.resolve(cacheDir, docId) : path10.resolve(__dirname, "../.cache/", docId);
|
|
4029
4289
|
if (fs6.existsSync(me._pathToFile)) {
|
|
4030
4290
|
me._persisted = utils.tryParse(me._pathToFile, {});
|
|
4031
4291
|
}
|
|
4032
4292
|
},
|
|
4293
|
+
get _persisted() {
|
|
4294
|
+
return this.__persisted;
|
|
4295
|
+
},
|
|
4296
|
+
set _persisted(value) {
|
|
4297
|
+
this.__persisted = value;
|
|
4298
|
+
this.keyv.set("persisted", value);
|
|
4299
|
+
},
|
|
4300
|
+
get _visited() {
|
|
4301
|
+
return this.__visited;
|
|
4302
|
+
},
|
|
4303
|
+
set _visited(value) {
|
|
4304
|
+
this.__visited = value;
|
|
4305
|
+
this.keyv.set("visited", value);
|
|
4306
|
+
},
|
|
4033
4307
|
/**
|
|
4034
4308
|
* Load the cache from the provided file
|
|
4035
4309
|
* @method loadFile
|
|
@@ -5930,18 +6204,27 @@ import path2 from "path";
|
|
|
5930
6204
|
async function* expandPatterns(context) {
|
|
5931
6205
|
const seen = /* @__PURE__ */ new Set();
|
|
5932
6206
|
let noResults = true;
|
|
5933
|
-
for await (const
|
|
6207
|
+
for await (const {
|
|
6208
|
+
filePath,
|
|
6209
|
+
ignoreUnknown,
|
|
6210
|
+
error
|
|
6211
|
+
} of expandPatternsInternal(context)) {
|
|
5934
6212
|
noResults = false;
|
|
5935
|
-
if (
|
|
5936
|
-
yield
|
|
6213
|
+
if (error) {
|
|
6214
|
+
yield {
|
|
6215
|
+
error
|
|
6216
|
+
};
|
|
5937
6217
|
continue;
|
|
5938
6218
|
}
|
|
5939
|
-
const
|
|
5940
|
-
if (seen.has(
|
|
6219
|
+
const filename = path2.resolve(filePath);
|
|
6220
|
+
if (seen.has(filename)) {
|
|
5941
6221
|
continue;
|
|
5942
6222
|
}
|
|
5943
|
-
seen.add(
|
|
5944
|
-
yield
|
|
6223
|
+
seen.add(filename);
|
|
6224
|
+
yield {
|
|
6225
|
+
filename,
|
|
6226
|
+
ignoreUnknown
|
|
6227
|
+
};
|
|
5945
6228
|
}
|
|
5946
6229
|
if (noResults && context.argv.errorOnUnmatchedPattern !== false) {
|
|
5947
6230
|
yield {
|
|
@@ -5959,7 +6242,6 @@ async function* expandPatternsInternal(context) {
|
|
|
5959
6242
|
ignore: silentlyIgnoredDirs.map((dir) => "**/" + dir),
|
|
5960
6243
|
followSymbolicLinks: false
|
|
5961
6244
|
};
|
|
5962
|
-
let supportedFilesGlob;
|
|
5963
6245
|
const cwd2 = process.cwd();
|
|
5964
6246
|
const entries = [];
|
|
5965
6247
|
for (const pattern of context.filePatterns) {
|
|
@@ -5981,10 +6263,12 @@ async function* expandPatternsInternal(context) {
|
|
|
5981
6263
|
});
|
|
5982
6264
|
} else if (stat.isDirectory()) {
|
|
5983
6265
|
const relativePath = path2.relative(cwd2, absolutePath) || ".";
|
|
6266
|
+
const prefix = escapePathForGlob(fixWindowsSlashes(relativePath));
|
|
5984
6267
|
entries.push({
|
|
5985
6268
|
type: "dir",
|
|
5986
|
-
glob:
|
|
5987
|
-
input: pattern
|
|
6269
|
+
glob: `${prefix}/**/*`,
|
|
6270
|
+
input: pattern,
|
|
6271
|
+
ignoreUnknown: true
|
|
5988
6272
|
});
|
|
5989
6273
|
}
|
|
5990
6274
|
} else if (pattern[0] === "!") {
|
|
@@ -6000,7 +6284,8 @@ async function* expandPatternsInternal(context) {
|
|
|
6000
6284
|
for (const {
|
|
6001
6285
|
type,
|
|
6002
6286
|
glob,
|
|
6003
|
-
input
|
|
6287
|
+
input,
|
|
6288
|
+
ignoreUnknown
|
|
6004
6289
|
} of entries) {
|
|
6005
6290
|
let result;
|
|
6006
6291
|
try {
|
|
@@ -6021,17 +6306,12 @@ ${message}`
|
|
|
6021
6306
|
};
|
|
6022
6307
|
}
|
|
6023
6308
|
} else {
|
|
6024
|
-
yield* sortPaths(result)
|
|
6309
|
+
yield* sortPaths(result).map((filePath) => ({
|
|
6310
|
+
filePath,
|
|
6311
|
+
ignoreUnknown
|
|
6312
|
+
}));
|
|
6025
6313
|
}
|
|
6026
6314
|
}
|
|
6027
|
-
function getSupportedFilesGlob() {
|
|
6028
|
-
if (!supportedFilesGlob) {
|
|
6029
|
-
const extensions = context.languages.flatMap((lang) => lang.extensions || []);
|
|
6030
|
-
const filenames = context.languages.flatMap((lang) => lang.filenames || []);
|
|
6031
|
-
supportedFilesGlob = `**/{${[...extensions.map((ext) => "*" + (ext[0] === "." ? ext : "." + ext)), ...filenames]}}`;
|
|
6032
|
-
}
|
|
6033
|
-
return supportedFilesGlob;
|
|
6034
|
-
}
|
|
6035
6315
|
}
|
|
6036
6316
|
var errorMessages = {
|
|
6037
6317
|
globError: {
|
|
@@ -6367,9 +6647,6 @@ function useDirectory(directory, options) {
|
|
|
6367
6647
|
if (options.create) {
|
|
6368
6648
|
fs3.mkdirSync(directory, { recursive: true });
|
|
6369
6649
|
}
|
|
6370
|
-
if (options.thunk) {
|
|
6371
|
-
return (...arguments_) => path6.join(directory, ...arguments_);
|
|
6372
|
-
}
|
|
6373
6650
|
return directory;
|
|
6374
6651
|
}
|
|
6375
6652
|
function getNodeModuleDirectory(directory) {
|
|
@@ -6383,9 +6660,12 @@ function findCacheDirectory(options = {}) {
|
|
|
6383
6660
|
if (env2.CACHE_DIR && !["true", "false", "1", "0"].includes(env2.CACHE_DIR)) {
|
|
6384
6661
|
return useDirectory(path6.join(env2.CACHE_DIR, options.name), options);
|
|
6385
6662
|
}
|
|
6386
|
-
let { cwd: directory = cwd() } = options;
|
|
6387
|
-
if (
|
|
6388
|
-
|
|
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)));
|
|
6389
6669
|
}
|
|
6390
6670
|
directory = packageDirectorySync({ cwd: directory });
|
|
6391
6671
|
if (!directory) {
|
|
@@ -6511,17 +6791,18 @@ function diff(a, b) {
|
|
|
6511
6791
|
var DebugError = class extends Error {
|
|
6512
6792
|
name = "DebugError";
|
|
6513
6793
|
};
|
|
6514
|
-
function handleError(context, filename, error, printedFilename) {
|
|
6794
|
+
function handleError(context, filename, error, printedFilename, ignoreUnknown) {
|
|
6795
|
+
ignoreUnknown || (ignoreUnknown = context.argv.ignoreUnknown);
|
|
6515
6796
|
const errorIsUndefinedParseError = error instanceof errors.UndefinedParserError;
|
|
6516
6797
|
if (printedFilename) {
|
|
6517
|
-
if ((context.argv.write ||
|
|
6798
|
+
if ((context.argv.write || ignoreUnknown) && errorIsUndefinedParseError) {
|
|
6518
6799
|
printedFilename.clear();
|
|
6519
6800
|
} else {
|
|
6520
6801
|
process.stdout.write("\n");
|
|
6521
6802
|
}
|
|
6522
6803
|
}
|
|
6523
6804
|
if (errorIsUndefinedParseError) {
|
|
6524
|
-
if (
|
|
6805
|
+
if (ignoreUnknown) {
|
|
6525
6806
|
return;
|
|
6526
6807
|
}
|
|
6527
6808
|
if (!context.argv.check && !context.argv.listDifferent) {
|
|
@@ -6732,27 +7013,20 @@ async function formatFiles(context) {
|
|
|
6732
7013
|
cacheFilePath,
|
|
6733
7014
|
context.argv.cacheStrategy || "content"
|
|
6734
7015
|
);
|
|
6735
|
-
} else {
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
);
|
|
6740
|
-
process.exit(2);
|
|
6741
|
-
}
|
|
6742
|
-
if (!context.argv.cacheLocation) {
|
|
6743
|
-
const stat = await statSafe(cacheFilePath);
|
|
6744
|
-
if (stat) {
|
|
6745
|
-
await fs5.unlink(cacheFilePath);
|
|
6746
|
-
}
|
|
7016
|
+
} else if (!context.argv.cacheLocation) {
|
|
7017
|
+
const stat = await statSafe(cacheFilePath);
|
|
7018
|
+
if (stat) {
|
|
7019
|
+
await fs5.unlink(cacheFilePath);
|
|
6747
7020
|
}
|
|
6748
7021
|
}
|
|
6749
|
-
for await (const
|
|
6750
|
-
|
|
6751
|
-
|
|
7022
|
+
for await (const { error, filename, ignoreUnknown } of expandPatterns(
|
|
7023
|
+
context
|
|
7024
|
+
)) {
|
|
7025
|
+
if (error) {
|
|
7026
|
+
context.logger.error(error);
|
|
6752
7027
|
process.exitCode = 2;
|
|
6753
7028
|
continue;
|
|
6754
7029
|
}
|
|
6755
|
-
const filename = pathOrError;
|
|
6756
7030
|
const isFileIgnored = isIgnored(filename);
|
|
6757
7031
|
if (isFileIgnored && (context.argv.debugCheck || context.argv.write || context.argv.check || context.argv.listDifferent)) {
|
|
6758
7032
|
continue;
|
|
@@ -6772,11 +7046,11 @@ async function formatFiles(context) {
|
|
|
6772
7046
|
let input;
|
|
6773
7047
|
try {
|
|
6774
7048
|
input = await fs5.readFile(filename, "utf8");
|
|
6775
|
-
} catch (
|
|
7049
|
+
} catch (error2) {
|
|
6776
7050
|
context.logger.log("");
|
|
6777
7051
|
context.logger.error(
|
|
6778
7052
|
`Unable to read file "${fileNameToDisplay}":
|
|
6779
|
-
${
|
|
7053
|
+
${error2.message}`
|
|
6780
7054
|
);
|
|
6781
7055
|
process.exitCode = 2;
|
|
6782
7056
|
continue;
|
|
@@ -6800,8 +7074,14 @@ ${error.message}`
|
|
|
6800
7074
|
result = await format2(context, input, options);
|
|
6801
7075
|
}
|
|
6802
7076
|
output = result.formatted;
|
|
6803
|
-
} catch (
|
|
6804
|
-
handleError(
|
|
7077
|
+
} catch (error2) {
|
|
7078
|
+
handleError(
|
|
7079
|
+
context,
|
|
7080
|
+
fileNameToDisplay,
|
|
7081
|
+
error2,
|
|
7082
|
+
printedFilename,
|
|
7083
|
+
ignoreUnknown
|
|
7084
|
+
);
|
|
6805
7085
|
continue;
|
|
6806
7086
|
}
|
|
6807
7087
|
const isDifferent = output !== input;
|
|
@@ -6821,15 +7101,15 @@ ${error.message}`
|
|
|
6821
7101
|
try {
|
|
6822
7102
|
await writeFormattedFile(filename, output);
|
|
6823
7103
|
shouldSetCache = true;
|
|
6824
|
-
} catch (
|
|
7104
|
+
} catch (error2) {
|
|
6825
7105
|
context.logger.error(
|
|
6826
7106
|
`Unable to write file "${fileNameToDisplay}":
|
|
6827
|
-
${
|
|
7107
|
+
${error2.message}`
|
|
6828
7108
|
);
|
|
6829
7109
|
process.exitCode = 2;
|
|
6830
7110
|
}
|
|
6831
7111
|
} else if (!context.argv.check && !context.argv.listDifferent) {
|
|
6832
|
-
const message = `${source_default.grey(fileNameToDisplay)} ${Date.now() - start}ms`;
|
|
7112
|
+
const message = `${source_default.grey(fileNameToDisplay)} ${Date.now() - start}ms (unchanged)`;
|
|
6833
7113
|
if (isCacheExists) {
|
|
6834
7114
|
context.logger.log(`${message} (cached)`);
|
|
6835
7115
|
} else {
|
|
@@ -6927,7 +7207,7 @@ async function printSupportInfo() {
|
|
|
6927
7207
|
var print_support_info_default = printSupportInfo;
|
|
6928
7208
|
|
|
6929
7209
|
// src/cli/index.js
|
|
6930
|
-
async function run(rawArguments) {
|
|
7210
|
+
async function run(rawArguments = process.argv.slice(2)) {
|
|
6931
7211
|
let logger = logger_default();
|
|
6932
7212
|
try {
|
|
6933
7213
|
const { logLevel } = parseArgvWithoutPlugins(
|
|
@@ -6963,6 +7243,9 @@ async function main(context) {
|
|
|
6963
7243
|
if (context.argv.fileInfo && context.filePatterns.length > 0) {
|
|
6964
7244
|
throw new Error("Cannot use --file-info with multiple files");
|
|
6965
7245
|
}
|
|
7246
|
+
if (!context.argv.cache && context.argv.cacheStrategy) {
|
|
7247
|
+
throw new Error("`--cache-strategy` cannot be used without `--cache`.");
|
|
7248
|
+
}
|
|
6966
7249
|
if (context.argv.version) {
|
|
6967
7250
|
printToScreen(prettier2.version);
|
|
6968
7251
|
return;
|
|
@@ -6976,24 +7259,29 @@ async function main(context) {
|
|
|
6976
7259
|
if (context.argv.supportInfo) {
|
|
6977
7260
|
return print_support_info_default();
|
|
6978
7261
|
}
|
|
6979
|
-
const hasFilePatterns = context.filePatterns.length > 0;
|
|
6980
|
-
const useStdin = !hasFilePatterns && (!process.stdin.isTTY || context.argv.filePath);
|
|
6981
7262
|
if (context.argv.findConfigPath) {
|
|
6982
7263
|
await find_config_path_default(context);
|
|
6983
|
-
|
|
7264
|
+
return;
|
|
7265
|
+
}
|
|
7266
|
+
if (context.argv.fileInfo) {
|
|
6984
7267
|
await file_info_default(context);
|
|
6985
|
-
|
|
7268
|
+
return;
|
|
7269
|
+
}
|
|
7270
|
+
const hasFilePatterns = context.filePatterns.length > 0;
|
|
7271
|
+
const useStdin = !hasFilePatterns && (!process.stdin.isTTY || context.argv.filepath);
|
|
7272
|
+
if (useStdin) {
|
|
6986
7273
|
if (context.argv.cache) {
|
|
6987
|
-
|
|
6988
|
-
process.exit(2);
|
|
7274
|
+
throw new Error("`--cache` cannot be used when formatting stdin.");
|
|
6989
7275
|
}
|
|
6990
7276
|
await formatStdin(context);
|
|
6991
|
-
|
|
7277
|
+
return;
|
|
7278
|
+
}
|
|
7279
|
+
if (hasFilePatterns) {
|
|
6992
7280
|
await formatFiles(context);
|
|
6993
|
-
|
|
6994
|
-
process.exitCode = 1;
|
|
6995
|
-
printToScreen(createUsage(context));
|
|
7281
|
+
return;
|
|
6996
7282
|
}
|
|
7283
|
+
process.exitCode = 1;
|
|
7284
|
+
printToScreen(createUsage(context));
|
|
6997
7285
|
}
|
|
6998
7286
|
export {
|
|
6999
7287
|
run
|