prettier 3.0.0-alpha.0 → 3.0.0-alpha.1

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.
Files changed (54) hide show
  1. package/LICENSE +49 -65
  2. package/{bin-prettier.js → bin/prettier.cjs} +2 -2
  3. package/doc.js +438 -221
  4. package/doc.mjs +1490 -0
  5. package/index.cjs +532 -0
  6. package/{index.js → index.mjs} +4335 -5702
  7. package/{cli.mjs → internal/cli.mjs} +148 -92
  8. package/{third-party.js → internal/third-party.mjs} +123 -100
  9. package/package.json +139 -6
  10. package/plugins/acorn-and-espree.js +13 -0
  11. package/plugins/acorn-and-espree.mjs +13 -0
  12. package/{parser-angular.js → plugins/angular.js} +0 -0
  13. package/{esm/parser-angular.mjs → plugins/angular.mjs} +1 -1
  14. package/plugins/babel.js +16 -0
  15. package/plugins/babel.mjs +16 -0
  16. package/plugins/flow.js +21 -0
  17. package/plugins/flow.mjs +21 -0
  18. package/{parser-glimmer.js → plugins/glimmer.js} +9 -9
  19. package/{esm/parser-glimmer.mjs → plugins/glimmer.mjs} +10 -10
  20. package/plugins/graphql.js +9 -0
  21. package/plugins/graphql.mjs +9 -0
  22. package/plugins/html.js +29 -0
  23. package/plugins/html.mjs +29 -0
  24. package/plugins/markdown.js +39 -0
  25. package/plugins/markdown.mjs +39 -0
  26. package/plugins/meriyah.js +6 -0
  27. package/plugins/meriyah.mjs +6 -0
  28. package/plugins/postcss.js +50 -0
  29. package/plugins/postcss.mjs +50 -0
  30. package/plugins/typescript.js +242 -0
  31. package/plugins/typescript.mjs +242 -0
  32. package/{parser-yaml.js → plugins/yaml.js} +1 -1
  33. package/{esm/parser-yaml.mjs → plugins/yaml.mjs} +1 -1
  34. package/standalone.js +69 -87
  35. package/standalone.mjs +106 -0
  36. package/esm/parser-babel.mjs +0 -18
  37. package/esm/parser-espree.mjs +0 -15
  38. package/esm/parser-flow.mjs +0 -23
  39. package/esm/parser-graphql.mjs +0 -9
  40. package/esm/parser-html.mjs +0 -28
  41. package/esm/parser-markdown.mjs +0 -60
  42. package/esm/parser-meriyah.mjs +0 -8
  43. package/esm/parser-postcss.mjs +0 -53
  44. package/esm/parser-typescript.mjs +0 -269
  45. package/esm/standalone.mjs +0 -124
  46. package/parser-babel.js +0 -18
  47. package/parser-espree.js +0 -15
  48. package/parser-flow.js +0 -23
  49. package/parser-graphql.js +0 -9
  50. package/parser-html.js +0 -28
  51. package/parser-markdown.js +0 -60
  52. package/parser-meriyah.js +0 -8
  53. package/parser-postcss.js +0 -53
  54. package/parser-typescript.js +0 -269
@@ -5412,6 +5412,45 @@ var require_stream3 = __commonJS({
5412
5412
  }
5413
5413
  });
5414
5414
 
5415
+ // node_modules/fast-glob/out/readers/async.js
5416
+ var require_async5 = __commonJS({
5417
+ "node_modules/fast-glob/out/readers/async.js"(exports) {
5418
+ "use strict";
5419
+ Object.defineProperty(exports, "__esModule", { value: true });
5420
+ var fsWalk = require_out3();
5421
+ var reader_1 = require_reader2();
5422
+ var stream_1 = require_stream3();
5423
+ var ReaderAsync = class extends reader_1.default {
5424
+ constructor() {
5425
+ super(...arguments);
5426
+ this._walkAsync = fsWalk.walk;
5427
+ this._readerStream = new stream_1.default(this._settings);
5428
+ }
5429
+ dynamic(root, options2) {
5430
+ return new Promise((resolve, reject) => {
5431
+ this._walkAsync(root, options2, (error, entries) => {
5432
+ if (error === null) {
5433
+ resolve(entries);
5434
+ } else {
5435
+ reject(error);
5436
+ }
5437
+ });
5438
+ });
5439
+ }
5440
+ async static(patterns, options2) {
5441
+ const entries = [];
5442
+ const stream = this._readerStream.static(patterns, options2);
5443
+ return new Promise((resolve, reject) => {
5444
+ stream.once("error", reject);
5445
+ stream.on("data", (entry) => entries.push(entry));
5446
+ stream.once("end", () => resolve(entries));
5447
+ });
5448
+ }
5449
+ };
5450
+ exports.default = ReaderAsync;
5451
+ }
5452
+ });
5453
+
5415
5454
  // node_modules/fast-glob/out/providers/matchers/matcher.js
5416
5455
  var require_matcher = __commonJS({
5417
5456
  "node_modules/fast-glob/out/providers/matchers/matcher.js"(exports) {
@@ -5594,7 +5633,8 @@ var require_entry = __commonJS({
5594
5633
  return false;
5595
5634
  }
5596
5635
  const filepath = this._settings.baseNameMatch ? entry.name : entry.path;
5597
- const isMatched = this._isMatchToPatterns(filepath, positiveRe) && !this._isMatchToPatterns(entry.path, negativeRe);
5636
+ const isDirectory = entry.dirent.isDirectory();
5637
+ const isMatched = this._isMatchToPatterns(filepath, positiveRe, isDirectory) && !this._isMatchToPatterns(entry.path, negativeRe, isDirectory);
5598
5638
  if (this._settings.unique && isMatched) {
5599
5639
  this._createIndexRecord(entry);
5600
5640
  }
@@ -5619,9 +5659,13 @@ var require_entry = __commonJS({
5619
5659
  const fullpath = utils.path.makeAbsolute(this._settings.cwd, entryPath);
5620
5660
  return utils.pattern.matchAny(fullpath, patternsRe);
5621
5661
  }
5622
- _isMatchToPatterns(entryPath, patternsRe) {
5662
+ _isMatchToPatterns(entryPath, patternsRe, isDirectory) {
5623
5663
  const filepath = utils.path.removeLeadingDotSegment(entryPath);
5624
- return utils.pattern.matchAny(filepath, patternsRe) || utils.pattern.matchAny(filepath + "/", patternsRe);
5664
+ const isMatched = utils.pattern.matchAny(filepath, patternsRe);
5665
+ if (!isMatched && isDirectory) {
5666
+ return utils.pattern.matchAny(filepath + "/", patternsRe);
5667
+ }
5668
+ return isMatched;
5625
5669
  }
5626
5670
  };
5627
5671
  exports.default = EntryFilter;
@@ -5736,27 +5780,22 @@ var require_provider = __commonJS({
5736
5780
  });
5737
5781
 
5738
5782
  // node_modules/fast-glob/out/providers/async.js
5739
- var require_async5 = __commonJS({
5783
+ var require_async6 = __commonJS({
5740
5784
  "node_modules/fast-glob/out/providers/async.js"(exports) {
5741
5785
  "use strict";
5742
5786
  Object.defineProperty(exports, "__esModule", { value: true });
5743
- var stream_1 = require_stream3();
5787
+ var async_1 = require_async5();
5744
5788
  var provider_1 = require_provider();
5745
5789
  var ProviderAsync = class extends provider_1.default {
5746
5790
  constructor() {
5747
5791
  super(...arguments);
5748
- this._reader = new stream_1.default(this._settings);
5792
+ this._reader = new async_1.default(this._settings);
5749
5793
  }
5750
- read(task) {
5794
+ async read(task) {
5751
5795
  const root = this._getRootDirectory(task);
5752
5796
  const options2 = this._getReaderOptions(task);
5753
- const entries = [];
5754
- return new Promise((resolve, reject) => {
5755
- const stream = this.api(root, task, options2);
5756
- stream.once("error", reject);
5757
- stream.on("data", (entry) => entries.push(options2.transform(entry)));
5758
- stream.once("end", () => resolve(entries));
5759
- });
5797
+ const entries = await this.api(root, task, options2);
5798
+ return entries.map((entry) => options2.transform(entry));
5760
5799
  }
5761
5800
  api(root, task, options2) {
5762
5801
  if (task.dynamic) {
@@ -5945,7 +5984,7 @@ var require_out4 = __commonJS({
5945
5984
  "use strict";
5946
5985
  var taskManager = require_tasks();
5947
5986
  var patternManager = require_patterns();
5948
- var async_1 = require_async5();
5987
+ var async_1 = require_async6();
5949
5988
  var stream_1 = require_stream4();
5950
5989
  var sync_1 = require_sync6();
5951
5990
  var settings_1 = require_settings4();
@@ -11222,7 +11261,7 @@ var require_create = __commonJS({
11222
11261
  });
11223
11262
 
11224
11263
  // src/cli/index.js
11225
- import * as prettier2 from "./index.js";
11264
+ import * as prettier2 from "../index.mjs";
11226
11265
 
11227
11266
  // src/cli/logger.js
11228
11267
  import readline from "readline";
@@ -11787,65 +11826,21 @@ function createLogger(logLevel = "log") {
11787
11826
  }
11788
11827
  var logger_default = createLogger;
11789
11828
 
11790
- // src/cli/utils.js
11791
- import fs from "fs/promises";
11792
-
11793
- // node_modules/sdbm/index.js
11794
- function sdbm(string) {
11795
- let hash = 0;
11796
- for (let i = 0; i < string.length; i++) {
11797
- hash = string.charCodeAt(i) + (hash << 6) + (hash << 16) - hash;
11798
- }
11799
- return hash >>> 0;
11800
- }
11801
-
11802
- // src/cli/utils.js
11803
- import { __internal as sharedWithCli } from "./index.js";
11804
- var { arrayify, getLast, isNonEmptyArray, partition } = sharedWithCli.utils;
11805
- var printToScreen = console.log.bind(console);
11806
- function groupBy(array2, iteratee) {
11807
- const result = /* @__PURE__ */ Object.create(null);
11808
- for (const value of array2) {
11809
- const key = iteratee(value);
11810
- if (Array.isArray(result[key])) {
11811
- result[key].push(value);
11812
- } else {
11813
- result[key] = [value];
11814
- }
11815
- }
11816
- return result;
11817
- }
11818
- function pick(object, keys) {
11819
- const entries = keys.map((key) => [key, object[key]]);
11820
- return Object.fromEntries(entries);
11821
- }
11822
- function createHash(source) {
11823
- return String(sdbm(source));
11824
- }
11825
- async function statSafe(filePath) {
11826
- try {
11827
- return await fs.stat(filePath);
11828
- } catch (error) {
11829
- if (error.code !== "ENOENT") {
11830
- throw error;
11831
- }
11832
- }
11833
- }
11834
- function isJson(value) {
11835
- try {
11836
- JSON.parse(value);
11837
- return true;
11838
- } catch {
11839
- return false;
11829
+ // scripts/build/shims/at.js
11830
+ var at = (isOptionalObject, object, index, ...args) => {
11831
+ if (isOptionalObject && (object === void 0 || object === null)) {
11832
+ return;
11840
11833
  }
11841
- }
11834
+ return object.at ? object.at(index, ...args) : object[index < 0 ? object.length + index : index];
11835
+ };
11836
+ var at_default = at;
11842
11837
 
11843
11838
  // src/cli/options/get-context-options.js
11844
11839
  var import_dashify = __toESM(require_dashify(), 1);
11845
- import { getSupportInfo } from "./index.js";
11840
+ import { getSupportInfo } from "../index.mjs";
11846
11841
 
11847
11842
  // src/cli/prettier-internal.js
11848
- import { __internal as sharedWithCli2 } from "./index.js";
11843
+ import { __internal as sharedWithCli } from "../index.mjs";
11849
11844
  var {
11850
11845
  errors,
11851
11846
  coreOptions,
@@ -11854,7 +11849,7 @@ var {
11854
11849
  normalizeApiOptions,
11855
11850
  normalizeCliOptions,
11856
11851
  getSupportInfoWithoutPlugins
11857
- } = sharedWithCli2;
11852
+ } = sharedWithCli;
11858
11853
 
11859
11854
  // src/cli/constant.js
11860
11855
  var import_outdent = __toESM(require_lib(), 1);
@@ -12041,6 +12036,59 @@ var usageSummary = import_outdent.outdent`
12041
12036
  Stdin is read if it is piped to Prettier and no files are given.
12042
12037
  `;
12043
12038
 
12039
+ // src/cli/utils.js
12040
+ import fs from "fs/promises";
12041
+
12042
+ // node_modules/sdbm/index.js
12043
+ function sdbm(string) {
12044
+ let hash = 0;
12045
+ for (let i = 0; i < string.length; i++) {
12046
+ hash = string.charCodeAt(i) + (hash << 6) + (hash << 16) - hash;
12047
+ }
12048
+ return hash >>> 0;
12049
+ }
12050
+
12051
+ // src/cli/utils.js
12052
+ import { __internal as sharedWithCli2 } from "../index.mjs";
12053
+ var { arrayify, isNonEmptyArray, partition } = sharedWithCli2.utils;
12054
+ var printToScreen = console.log.bind(console);
12055
+ function groupBy(array2, iteratee) {
12056
+ const result = /* @__PURE__ */ Object.create(null);
12057
+ for (const value of array2) {
12058
+ const key = iteratee(value);
12059
+ if (Array.isArray(result[key])) {
12060
+ result[key].push(value);
12061
+ } else {
12062
+ result[key] = [value];
12063
+ }
12064
+ }
12065
+ return result;
12066
+ }
12067
+ function pick(object, keys) {
12068
+ const entries = keys.map((key) => [key, object[key]]);
12069
+ return Object.fromEntries(entries);
12070
+ }
12071
+ function createHash(source) {
12072
+ return String(sdbm(source));
12073
+ }
12074
+ async function statSafe(filePath) {
12075
+ try {
12076
+ return await fs.stat(filePath);
12077
+ } catch (error) {
12078
+ if (error.code !== "ENOENT") {
12079
+ throw error;
12080
+ }
12081
+ }
12082
+ }
12083
+ function isJson(value) {
12084
+ try {
12085
+ JSON.parse(value);
12086
+ return true;
12087
+ } catch {
12088
+ return false;
12089
+ }
12090
+ }
12091
+
12044
12092
  // src/cli/options/get-context-options.js
12045
12093
  var detailedCliOptions = arrayify(options, "name").map(
12046
12094
  (option) => normalizeDetailedOption(option)
@@ -12329,18 +12377,23 @@ function parseArgvWithoutPlugins(rawArguments, logger, keys) {
12329
12377
  // src/cli/context.js
12330
12378
  var _stack;
12331
12379
  var Context = class {
12332
- constructor({ rawArguments, logger }) {
12380
+ constructor({
12381
+ rawArguments,
12382
+ logger
12383
+ }) {
12333
12384
  __privateAdd(this, _stack, []);
12334
12385
  this.rawArguments = rawArguments;
12335
12386
  this.logger = logger;
12336
12387
  }
12337
12388
  async init() {
12338
- const { rawArguments, logger } = this;
12339
- const { plugins, pluginSearchDirs } = parseArgvWithoutPlugins(
12389
+ const {
12340
12390
  rawArguments,
12341
- logger,
12342
- ["plugin", "plugin-search-dir"]
12343
- );
12391
+ logger
12392
+ } = this;
12393
+ const {
12394
+ plugins,
12395
+ pluginSearchDirs
12396
+ } = parseArgvWithoutPlugins(rawArguments, logger, ["plugin", "plugin-search-dir"]);
12344
12397
  await this.pushContextPlugins(plugins, pluginSearchDirs);
12345
12398
  const argv = parseArgv(rawArguments, this.detailedOptions, logger);
12346
12399
  this.argv = argv;
@@ -12353,10 +12406,13 @@ var Context = class {
12353
12406
  }
12354
12407
  popContextPlugins() {
12355
12408
  __privateGet(this, _stack).pop();
12356
- Object.assign(this, getLast(__privateGet(this, _stack)));
12409
+ Object.assign(this, at_default(false, __privateGet(this, _stack), -1));
12357
12410
  }
12358
12411
  get performanceTestFlag() {
12359
- const { debugBenchmark, debugRepeat } = this.argv;
12412
+ const {
12413
+ debugBenchmark,
12414
+ debugRepeat
12415
+ } = this.argv;
12360
12416
  if (debugBenchmark) {
12361
12417
  return {
12362
12418
  name: "--debug-benchmark",
@@ -12369,7 +12425,9 @@ var Context = class {
12369
12425
  debugRepeat
12370
12426
  };
12371
12427
  }
12372
- const { PRETTIER_PERF_REPEAT } = process.env;
12428
+ const {
12429
+ PRETTIER_PERF_REPEAT
12430
+ } = process.env;
12373
12431
  if (PRETTIER_PERF_REPEAT && /^\d+$/.test(PRETTIER_PERF_REPEAT)) {
12374
12432
  return {
12375
12433
  name: "PRETTIER_PERF_REPEAT (environment variable)",
@@ -12530,8 +12588,8 @@ Default: ${createDefaultValueDisplay(optionDefaultValue)}` : "";
12530
12588
  // src/cli/format.js
12531
12589
  import fs3 from "fs/promises";
12532
12590
  import path3 from "path";
12533
- import * as prettier from "./index.js";
12534
- import thirdParty2 from "./third-party.js";
12591
+ import * as prettier from "../index.mjs";
12592
+ import thirdParty2 from "./third-party.mjs";
12535
12593
 
12536
12594
  // src/cli/expand-patterns.js
12537
12595
  var import_fast_glob = __toESM(require_out4(), 1);
@@ -12665,7 +12723,7 @@ function fixWindowsSlashes(pattern) {
12665
12723
 
12666
12724
  // src/cli/options/get-options-for-file.js
12667
12725
  var import_dashify2 = __toESM(require_dashify(), 1);
12668
- import { resolveConfig } from "./index.js";
12726
+ import { resolveConfig } from "../index.mjs";
12669
12727
  function getOptions(argv, detailedOptions) {
12670
12728
  return Object.fromEntries(
12671
12729
  detailedOptions.filter(({ forwardToApi }) => forwardToApi).map(({ forwardToApi, name }) => [forwardToApi, argv[name]])
@@ -12770,7 +12828,7 @@ async function getOptionsForFile(context, filepath) {
12770
12828
  var get_options_for_file_default = getOptionsForFile;
12771
12829
 
12772
12830
  // src/cli/is-tty.js
12773
- import thirdParty from "./third-party.js";
12831
+ import thirdParty from "./third-party.mjs";
12774
12832
  function isTTY() {
12775
12833
  return process.stdout.isTTY && !thirdParty.isCI();
12776
12834
  }
@@ -12813,7 +12871,7 @@ var find_cache_file_default = findCacheFile;
12813
12871
  // src/cli/format-results-cache.js
12814
12872
  var import_file_entry_cache = __toESM(require_cache2(), 1);
12815
12873
  var import_fast_json_stable_stringify = __toESM(require_fast_json_stable_stringify(), 1);
12816
- import { version as prettierVersion } from "./index.js";
12874
+ import { version as prettierVersion } from "../index.mjs";
12817
12875
  var optionsHashCache = /* @__PURE__ */ new WeakMap();
12818
12876
  var nodeVersion = process && process.version;
12819
12877
  function getHashOfOptions(options2) {
@@ -12925,11 +12983,9 @@ async function listDifferent(context, input, options2, filename) {
12925
12983
  "No parser and no file path given, couldn't infer a parser."
12926
12984
  );
12927
12985
  }
12928
- if (!await prettier.check(input, options2)) {
12929
- if (!context.argv.write) {
12930
- context.logger.log(filename);
12931
- process.exitCode = 1;
12932
- }
12986
+ if (!await prettier.check(input, options2) && !context.argv.write) {
12987
+ context.logger.log(filename);
12988
+ process.exitCode = 1;
12933
12989
  }
12934
12990
  } catch (error) {
12935
12991
  context.logger.error(error.message);
@@ -13239,7 +13295,7 @@ ${error.message}`
13239
13295
 
13240
13296
  // src/cli/file-info.js
13241
13297
  var import_fast_json_stable_stringify2 = __toESM(require_fast_json_stable_stringify(), 1);
13242
- import { format as format3, getFileInfo } from "./index.js";
13298
+ import { format as format3, getFileInfo } from "../index.mjs";
13243
13299
  async function logFileInfoOrDie(context) {
13244
13300
  const {
13245
13301
  fileInfo: file,
@@ -13262,7 +13318,7 @@ var file_info_default = logFileInfoOrDie;
13262
13318
 
13263
13319
  // src/cli/find-config-path.js
13264
13320
  import path4 from "path";
13265
- import { resolveConfigFile } from "./index.js";
13321
+ import { resolveConfigFile } from "../index.mjs";
13266
13322
  async function logResolvedConfigPathOrDie(context) {
13267
13323
  const file = context.argv.findConfigPath;
13268
13324
  const configFile = await resolveConfigFile(file);
@@ -13276,7 +13332,7 @@ var find_config_path_default = logResolvedConfigPathOrDie;
13276
13332
 
13277
13333
  // src/cli/print-support-info.js
13278
13334
  var import_fast_json_stable_stringify3 = __toESM(require_fast_json_stable_stringify(), 1);
13279
- import { getSupportInfo as getSupportInfo2, format as format4 } from "./index.js";
13335
+ import { getSupportInfo as getSupportInfo2, format as format4 } from "../index.mjs";
13280
13336
  async function printSupportInfo() {
13281
13337
  const supportInfo = await getSupportInfo2();
13282
13338
  supportInfo.languages.sort(