prettier 3.0.0-alpha.8-for-vscode → 3.0.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/internal/cli.mjs CHANGED
@@ -16,7 +16,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
16
16
  }) : x)(function(x) {
17
17
  if (typeof require !== "undefined")
18
18
  return require.apply(this, arguments);
19
- throw new Error('Dynamic require of "' + x + '" is not supported');
19
+ throw Error('Dynamic require of "' + x + '" is not supported');
20
20
  });
21
21
  var __commonJS = (cb, mod) => function __require2() {
22
22
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
@@ -5016,11 +5016,12 @@ function ansiRegex({ onlyFirst = false } = {}) {
5016
5016
  }
5017
5017
 
5018
5018
  // node_modules/strip-ansi/index.js
5019
+ var regex = ansiRegex();
5019
5020
  function stripAnsi(string) {
5020
5021
  if (typeof string !== "string") {
5021
5022
  throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
5022
5023
  }
5023
- return string.replace(ansiRegex(), "");
5024
+ return string.replace(regex, "");
5024
5025
  }
5025
5026
 
5026
5027
  // src/cli/logger.js
@@ -5251,6 +5252,7 @@ var cli_options_evaluate_default = {
5251
5252
  "default": [
5252
5253
  {
5253
5254
  "value": [
5255
+ ".gitignore",
5254
5256
  ".prettierignore"
5255
5257
  ]
5256
5258
  }
@@ -5281,10 +5283,6 @@ var cli_options_evaluate_default = {
5281
5283
  "description": "What level of logs to report.",
5282
5284
  "type": "choice"
5283
5285
  },
5284
- "pluginSearch": {
5285
- "oppositeDescription": "Disable plugin autoloading.",
5286
- "type": "boolean"
5287
- },
5288
5286
  "supportInfo": {
5289
5287
  "description": "Print support information as JSON.",
5290
5288
  "type": "boolean"
@@ -5356,11 +5354,10 @@ function supportInfoToContextOptions({ options: supportOptions, languages }) {
5356
5354
  detailedOptions
5357
5355
  };
5358
5356
  }
5359
- async function getContextOptions(plugins, pluginSearchDirs) {
5357
+ async function getContextOptions(plugins) {
5360
5358
  const supportInfo = await getSupportInfo({
5361
5359
  showDeprecated: true,
5362
- plugins,
5363
- pluginSearchDirs
5360
+ plugins
5364
5361
  });
5365
5362
  return supportInfoToContextOptions(supportInfo);
5366
5363
  }
@@ -5495,6 +5492,15 @@ async function statSafe(filePath) {
5495
5492
  }
5496
5493
  }
5497
5494
  }
5495
+ async function lstatSafe(filePath) {
5496
+ try {
5497
+ return await fs.lstat(filePath);
5498
+ } catch (error) {
5499
+ if (error.code !== "ENOENT") {
5500
+ throw error;
5501
+ }
5502
+ }
5503
+ }
5498
5504
  function isJson(value) {
5499
5505
  try {
5500
5506
  JSON.parse(value);
@@ -5547,7 +5553,7 @@ function createMinimistOptions(detailedOptions) {
5547
5553
  if (alias) {
5548
5554
  names.push(alias);
5549
5555
  }
5550
- if (!option.deprecated && (!option.forwardToApi || name === "plugin" || name === "plugin-search-dir") && option.default !== void 0) {
5556
+ if (!option.deprecated && (!option.forwardToApi || name === "plugin") && option.default !== void 0) {
5551
5557
  defaultValues[option.name] = option.default;
5552
5558
  }
5553
5559
  }
@@ -5659,9 +5665,6 @@ function parseArgv(rawArguments, detailedOptions, logger, keys) {
5659
5665
  const minimistOptions = createMinimistOptions(detailedOptions);
5660
5666
  let argv = minimistParse(rawArguments, minimistOptions);
5661
5667
  if (keys) {
5662
- if (keys.includes("plugin-search-dir") && !keys.includes("plugin-search")) {
5663
- keys.push("plugin-search");
5664
- }
5665
5668
  detailedOptions = detailedOptions.filter(
5666
5669
  (option) => keys.includes(option.name)
5667
5670
  );
@@ -5708,20 +5711,18 @@ var Context = class {
5708
5711
  logger
5709
5712
  } = this;
5710
5713
  const {
5711
- plugins,
5712
- pluginSearchDirs
5713
- } = parseArgvWithoutPlugins(rawArguments, logger, ["plugin", "plugin-search-dir"]);
5714
- await this.pushContextPlugins(plugins, pluginSearchDirs);
5714
+ plugins
5715
+ } = parseArgvWithoutPlugins(rawArguments, logger, ["plugin"]);
5716
+ await this.pushContextPlugins(plugins);
5715
5717
  const argv = parseArgv(rawArguments, this.detailedOptions, logger);
5716
5718
  this.argv = argv;
5717
5719
  this.filePatterns = argv._;
5718
5720
  }
5719
5721
  /**
5720
5722
  * @param {string[]} plugins
5721
- * @param {string[]=} pluginSearchDirs
5722
5723
  */
5723
- async pushContextPlugins(plugins, pluginSearchDirs) {
5724
- const options = await getContextOptions(plugins, pluginSearchDirs);
5724
+ async pushContextPlugins(plugins) {
5725
+ const options = await getContextOptions(plugins);
5725
5726
  __privateGet(this, _stack).push(options);
5726
5727
  Object.assign(this, options);
5727
5728
  }
@@ -5937,7 +5938,8 @@ async function* expandPatternsInternal(context) {
5937
5938
  }
5938
5939
  const globOptions = {
5939
5940
  dot: true,
5940
- ignore: silentlyIgnoredDirs.map((dir) => "**/" + dir)
5941
+ ignore: silentlyIgnoredDirs.map((dir) => "**/" + dir),
5942
+ followSymbolicLinks: false
5941
5943
  };
5942
5944
  let supportedFilesGlob;
5943
5945
  const cwd2 = process.cwd();
@@ -5947,9 +5949,13 @@ async function* expandPatternsInternal(context) {
5947
5949
  if (containsIgnoredPathSegment(absolutePath, cwd2, silentlyIgnoredDirs)) {
5948
5950
  continue;
5949
5951
  }
5950
- const stat = await statSafe(absolutePath);
5952
+ const stat = await lstatSafe(absolutePath);
5951
5953
  if (stat) {
5952
- if (stat.isFile()) {
5954
+ if (stat.isSymbolicLink()) {
5955
+ yield {
5956
+ error: `Explicitly specified pattern "${pattern}" is a symbolic link.`
5957
+ };
5958
+ } else if (stat.isFile()) {
5953
5959
  entries.push({
5954
5960
  type: "file",
5955
5961
  glob: escapePathForGlob(fixWindowsSlashes(pattern)),
@@ -6269,7 +6275,12 @@ function locatePathSync(paths, {
6269
6275
  const statFunction = allowSymlinks ? fs2.statSync : fs2.lstatSync;
6270
6276
  for (const path_ of paths) {
6271
6277
  try {
6272
- const stat = statFunction(path3.resolve(cwd2, path_));
6278
+ const stat = statFunction(path3.resolve(cwd2, path_), {
6279
+ throwIfNoEntry: false
6280
+ });
6281
+ if (!stat) {
6282
+ continue;
6283
+ }
6273
6284
  if (matchType(type, stat)) {
6274
6285
  return path_;
6275
6286
  }
@@ -6480,12 +6491,18 @@ function diff(a, b) {
6480
6491
  return (0, import_diff.createTwoFilesPatch)("", "", a, b, "", "", { context: 2 });
6481
6492
  }
6482
6493
  var DebugError = class extends Error {
6494
+ name = "DebugError";
6483
6495
  };
6484
6496
  function handleError(context, filename, error, printedFilename) {
6485
- if (error instanceof errors.UndefinedParserError) {
6486
- if ((context.argv.write || context.argv.ignoreUnknown) && printedFilename) {
6497
+ const errorIsUndefinedParseError = error instanceof errors.UndefinedParserError;
6498
+ if (printedFilename) {
6499
+ if ((context.argv.write || context.argv.ignoreUnknown) && errorIsUndefinedParseError) {
6487
6500
  printedFilename.clear();
6501
+ } else {
6502
+ process.stdout.write("\n");
6488
6503
  }
6504
+ }
6505
+ if (errorIsUndefinedParseError) {
6489
6506
  if (context.argv.ignoreUnknown) {
6490
6507
  return;
6491
6508
  }
@@ -6495,9 +6512,6 @@ function handleError(context, filename, error, printedFilename) {
6495
6512
  context.logger.error(error.message);
6496
6513
  return;
6497
6514
  }
6498
- if (context.argv.write) {
6499
- process.stdout.write("\n");
6500
- }
6501
6515
  const isParseError = Boolean(error == null ? void 0 : error.loc);
6502
6516
  const isValidationError = /^Invalid \S+ value\./.test(error == null ? void 0 : error.message);
6503
6517
  if (isParseError) {
@@ -6746,6 +6760,7 @@ ${error.message}`
6746
6760
  continue;
6747
6761
  }
6748
6762
  if (isFileIgnored) {
6763
+ printedFilename == null ? void 0 : printedFilename.clear();
6749
6764
  writeOutput(context, { formatted: input }, options);
6750
6765
  continue;
6751
6766
  }
@@ -6769,9 +6784,7 @@ ${error.message}`
6769
6784
  }
6770
6785
  const isDifferent = output !== input;
6771
6786
  let shouldSetCache = !isDifferent;
6772
- if (printedFilename) {
6773
- printedFilename.clear();
6774
- }
6787
+ printedFilename == null ? void 0 : printedFilename.clear();
6775
6788
  if (performanceTestFlag) {
6776
6789
  context.logger.log(
6777
6790
  `'${performanceTestFlag.name}' option found, skipped print code or write files.`
@@ -6849,14 +6862,12 @@ async function logFileInfoOrDie(context) {
6849
6862
  ignorePath,
6850
6863
  withNodeModules,
6851
6864
  plugins,
6852
- pluginSearchDirs,
6853
6865
  config
6854
6866
  } = context.argv;
6855
6867
  const fileInfo = await getFileInfo(file, {
6856
6868
  ignorePath,
6857
6869
  withNodeModules,
6858
6870
  plugins,
6859
- pluginSearchDirs,
6860
6871
  resolveConfig: config !== false
6861
6872
  });
6862
6873
  printToScreen(await format3((0, import_fast_json_stable_stringify2.default)(fileInfo), { parser: "json" }));
@@ -6918,14 +6929,6 @@ async function run(rawArguments) {
6918
6929
  }
6919
6930
  async function main(context) {
6920
6931
  context.logger.debug(`normalized argv: ${JSON.stringify(context.argv)}`);
6921
- if (context.argv.pluginSearch === false) {
6922
- const rawPluginSearchDirs = context.argv.__raw["plugin-search-dir"];
6923
- if (typeof rawPluginSearchDirs === "string" || isNonEmptyArray(rawPluginSearchDirs)) {
6924
- throw new Error(
6925
- "Cannot use --no-plugin-search and --plugin-search-dir together."
6926
- );
6927
- }
6928
- }
6929
6932
  if (context.argv.check && context.argv.listDifferent) {
6930
6933
  throw new Error("Cannot use --check and --list-different together.");
6931
6934
  }
@@ -16,7 +16,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
16
16
  }) : x)(function(x) {
17
17
  if (typeof require !== "undefined")
18
18
  return require.apply(this, arguments);
19
- throw new Error('Dynamic require of "' + x + '" is not supported');
19
+ throw Error('Dynamic require of "' + x + '" is not supported');
20
20
  });
21
21
  var __commonJS = (cb, mod) => function __require2() {
22
22
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
@@ -68,6 +68,29 @@ var require_cacheWrapper = __commonJS({
68
68
  }
69
69
  });
70
70
 
71
+ // node_modules/cosmiconfig/dist/getPropertyByPath.js
72
+ var require_getPropertyByPath = __commonJS({
73
+ "node_modules/cosmiconfig/dist/getPropertyByPath.js"(exports) {
74
+ "use strict";
75
+ Object.defineProperty(exports, "__esModule", {
76
+ value: true
77
+ });
78
+ exports.getPropertyByPath = getPropertyByPath;
79
+ function getPropertyByPath(source, path) {
80
+ if (typeof path === "string" && Object.prototype.hasOwnProperty.call(source, path)) {
81
+ return source[path];
82
+ }
83
+ const parsedPath = typeof path === "string" ? path.split(".") : path;
84
+ return parsedPath.reduce((previous, key) => {
85
+ if (previous === void 0) {
86
+ return previous;
87
+ }
88
+ return previous[key];
89
+ }, source);
90
+ }
91
+ }
92
+ });
93
+
71
94
  // node_modules/import-fresh/node_modules/resolve-from/index.js
72
95
  var require_resolve_from = __commonJS({
73
96
  "node_modules/import-fresh/node_modules/resolve-from/index.js"(exports, module) {
@@ -5362,14 +5385,25 @@ var require_loaders = __commonJS({
5362
5385
  value: true
5363
5386
  });
5364
5387
  exports.loaders = void 0;
5388
+ var _url = __require("url");
5365
5389
  var importFresh;
5366
- var loadJs = function loadJs2(filepath) {
5390
+ var loadJsSync = function loadJsSync2(filepath) {
5367
5391
  if (importFresh === void 0) {
5368
5392
  importFresh = require_import_fresh();
5369
5393
  }
5370
5394
  const result = importFresh(filepath);
5371
5395
  return result;
5372
5396
  };
5397
+ var loadJs = async function loadJs2(filepath) {
5398
+ try {
5399
+ const {
5400
+ href
5401
+ } = (0, _url.pathToFileURL)(filepath);
5402
+ return (await import(href)).default;
5403
+ } catch (error) {
5404
+ return loadJsSync(filepath, "");
5405
+ }
5406
+ };
5373
5407
  var parseJson;
5374
5408
  var loadJson = function loadJson2(filepath, content) {
5375
5409
  if (parseJson === void 0) {
@@ -5400,6 +5434,7 @@ ${error.message}`;
5400
5434
  };
5401
5435
  var loaders = {
5402
5436
  loadJs,
5437
+ loadJsSync,
5403
5438
  loadJson,
5404
5439
  loadYaml
5405
5440
  };
@@ -5407,29 +5442,6 @@ ${error.message}`;
5407
5442
  }
5408
5443
  });
5409
5444
 
5410
- // node_modules/cosmiconfig/dist/getPropertyByPath.js
5411
- var require_getPropertyByPath = __commonJS({
5412
- "node_modules/cosmiconfig/dist/getPropertyByPath.js"(exports) {
5413
- "use strict";
5414
- Object.defineProperty(exports, "__esModule", {
5415
- value: true
5416
- });
5417
- exports.getPropertyByPath = getPropertyByPath;
5418
- function getPropertyByPath(source, path) {
5419
- if (typeof path === "string" && Object.prototype.hasOwnProperty.call(source, path)) {
5420
- return source[path];
5421
- }
5422
- const parsedPath = typeof path === "string" ? path.split(".") : path;
5423
- return parsedPath.reduce((previous, key) => {
5424
- if (previous === void 0) {
5425
- return previous;
5426
- }
5427
- return previous[key];
5428
- }, source);
5429
- }
5430
- }
5431
- });
5432
-
5433
5445
  // node_modules/cosmiconfig/dist/ExplorerBase.js
5434
5446
  var require_ExplorerBase = __commonJS({
5435
5447
  "node_modules/cosmiconfig/dist/ExplorerBase.js"(exports) {
@@ -5440,14 +5452,14 @@ var require_ExplorerBase = __commonJS({
5440
5452
  exports.ExplorerBase = void 0;
5441
5453
  exports.getExtensionDescription = getExtensionDescription;
5442
5454
  var _path = _interopRequireDefault(__require("path"));
5443
- var _loaders = require_loaders();
5444
5455
  var _getPropertyByPath = require_getPropertyByPath();
5456
+ var _loaders = require_loaders();
5445
5457
  function _interopRequireDefault(obj) {
5446
5458
  return obj && obj.__esModule ? obj : { default: obj };
5447
5459
  }
5448
5460
  var ExplorerBase = class {
5449
5461
  constructor(options) {
5450
- if (options.cache === true) {
5462
+ if (options.cache) {
5451
5463
  this.loadCache = /* @__PURE__ */ new Map();
5452
5464
  this.searchCache = /* @__PURE__ */ new Map();
5453
5465
  }
@@ -5484,9 +5496,7 @@ var require_ExplorerBase = __commonJS({
5484
5496
  shouldSearchStopWithResult(result) {
5485
5497
  if (result === null)
5486
5498
  return false;
5487
- if (result.isEmpty && this.config.ignoreEmptySearchPlaces)
5488
- return false;
5489
- return true;
5499
+ return !(result.isEmpty && this.config.ignoreEmptySearchPlaces);
5490
5500
  }
5491
5501
  nextDirectoryToSearch(currentDir, currentResult) {
5492
5502
  if (this.shouldSearchStopWithResult(currentResult)) {
@@ -5505,8 +5515,7 @@ var require_ExplorerBase = __commonJS({
5505
5515
  }
5506
5516
  getLoaderEntryForFile(filepath) {
5507
5517
  if (_path.default.basename(filepath) === "package.json") {
5508
- const loader2 = this.loadPackageProp.bind(this);
5509
- return loader2;
5518
+ return this.loadPackageProp.bind(this);
5510
5519
  }
5511
5520
  const loaderKey = _path.default.extname(filepath) || "noExt";
5512
5521
  const loader = this.config.loaders[loaderKey];
@@ -5515,7 +5524,7 @@ var require_ExplorerBase = __commonJS({
5515
5524
  }
5516
5525
  return loader;
5517
5526
  }
5518
- loadedContentToCosmiconfigResult(filepath, loadedContent) {
5527
+ loadedContentToCosmiconfigResult(filepath, loadedContent, forceProp) {
5519
5528
  if (loadedContent === null) {
5520
5529
  return null;
5521
5530
  }
@@ -5526,6 +5535,16 @@ var require_ExplorerBase = __commonJS({
5526
5535
  isEmpty: true
5527
5536
  };
5528
5537
  }
5538
+ if (this.config.usePackagePropInConfigFiles || forceProp) {
5539
+ loadedContent = (0, _getPropertyByPath.getPropertyByPath)(loadedContent, this.config.packageProp);
5540
+ }
5541
+ if (loadedContent === void 0) {
5542
+ return {
5543
+ filepath,
5544
+ config: void 0,
5545
+ isEmpty: true
5546
+ };
5547
+ }
5529
5548
  return {
5530
5549
  config: loadedContent,
5531
5550
  filepath
@@ -5695,9 +5714,13 @@ var require_Explorer = __commonJS({
5695
5714
  super(options);
5696
5715
  }
5697
5716
  async search(searchFrom = process.cwd()) {
5698
- const startDirectory = await (0, _getDirectory.getDirectory)(searchFrom);
5699
- const result = await this.searchFromDirectory(startDirectory);
5700
- return result;
5717
+ if (this.config.metaConfigFilePath) {
5718
+ const config = await this._loadFile(this.config.metaConfigFilePath, true);
5719
+ if (config && !config.isEmpty) {
5720
+ return config;
5721
+ }
5722
+ }
5723
+ return await this.searchFromDirectory(await (0, _getDirectory.getDirectory)(searchFrom));
5701
5724
  }
5702
5725
  async searchFromDirectory(dir) {
5703
5726
  const absoluteDir = _path.default.resolve(process.cwd(), dir);
@@ -5707,8 +5730,7 @@ var require_Explorer = __commonJS({
5707
5730
  if (nextDir) {
5708
5731
  return this.searchFromDirectory(nextDir);
5709
5732
  }
5710
- const transformResult = await this.config.transform(result);
5711
- return transformResult;
5733
+ return await this.config.transform(result);
5712
5734
  };
5713
5735
  if (this.searchCache) {
5714
5736
  return (0, _cacheWrapper.cacheWrapper)(this.searchCache, absoluteDir, run);
@@ -5718,7 +5740,7 @@ var require_Explorer = __commonJS({
5718
5740
  async searchDirectory(dir) {
5719
5741
  for await (const place of this.config.searchPlaces) {
5720
5742
  const placeResult = await this.loadSearchPlace(dir, place);
5721
- if (this.shouldSearchStopWithResult(placeResult) === true) {
5743
+ if (this.shouldSearchStopWithResult(placeResult)) {
5722
5744
  return placeResult;
5723
5745
  }
5724
5746
  }
@@ -5727,8 +5749,7 @@ var require_Explorer = __commonJS({
5727
5749
  async loadSearchPlace(dir, place) {
5728
5750
  const filepath = _path.default.join(dir, place);
5729
5751
  const fileContents = await (0, _readFile.readFile)(filepath);
5730
- const result = await this.createCosmiconfigResult(filepath, fileContents);
5731
- return result;
5752
+ return await this.createCosmiconfigResult(filepath, fileContents, false);
5732
5753
  }
5733
5754
  async loadFileContent(filepath, content) {
5734
5755
  if (content === null) {
@@ -5745,21 +5766,22 @@ var require_Explorer = __commonJS({
5745
5766
  throw e;
5746
5767
  }
5747
5768
  }
5748
- async createCosmiconfigResult(filepath, content) {
5769
+ async createCosmiconfigResult(filepath, content, forceProp) {
5749
5770
  const fileContent = await this.loadFileContent(filepath, content);
5750
- const result = this.loadedContentToCosmiconfigResult(filepath, fileContent);
5751
- return result;
5771
+ return this.loadedContentToCosmiconfigResult(filepath, fileContent, forceProp);
5752
5772
  }
5753
5773
  async load(filepath) {
5774
+ return this._loadFile(filepath, false);
5775
+ }
5776
+ async _loadFile(filepath, forceProp) {
5754
5777
  this.validateFilePath(filepath);
5755
5778
  const absoluteFilePath = _path.default.resolve(process.cwd(), filepath);
5756
5779
  const runLoad = async () => {
5757
5780
  const fileContents = await (0, _readFile.readFile)(absoluteFilePath, {
5758
5781
  throwNotFound: true
5759
5782
  });
5760
- const result = await this.createCosmiconfigResult(absoluteFilePath, fileContents);
5761
- const transformResult = await this.config.transform(result);
5762
- return transformResult;
5783
+ const result = await this.createCosmiconfigResult(absoluteFilePath, fileContents, forceProp);
5784
+ return await this.config.transform(result);
5763
5785
  };
5764
5786
  if (this.loadCache) {
5765
5787
  return (0, _cacheWrapper.cacheWrapper)(this.loadCache, absoluteFilePath, runLoad);
@@ -5792,9 +5814,13 @@ var require_ExplorerSync = __commonJS({
5792
5814
  super(options);
5793
5815
  }
5794
5816
  searchSync(searchFrom = process.cwd()) {
5795
- const startDirectory = (0, _getDirectory.getDirectorySync)(searchFrom);
5796
- const result = this.searchFromDirectorySync(startDirectory);
5797
- return result;
5817
+ if (this.config.metaConfigFilePath) {
5818
+ const config = this._loadFileSync(this.config.metaConfigFilePath, true);
5819
+ if (config && !config.isEmpty) {
5820
+ return config;
5821
+ }
5822
+ }
5823
+ return this.searchFromDirectorySync((0, _getDirectory.getDirectorySync)(searchFrom));
5798
5824
  }
5799
5825
  searchFromDirectorySync(dir) {
5800
5826
  const absoluteDir = _path.default.resolve(process.cwd(), dir);
@@ -5804,8 +5830,7 @@ var require_ExplorerSync = __commonJS({
5804
5830
  if (nextDir) {
5805
5831
  return this.searchFromDirectorySync(nextDir);
5806
5832
  }
5807
- const transformResult = this.config.transform(result);
5808
- return transformResult;
5833
+ return this.config.transform(result);
5809
5834
  };
5810
5835
  if (this.searchCache) {
5811
5836
  return (0, _cacheWrapper.cacheWrapperSync)(this.searchCache, absoluteDir, run);
@@ -5815,7 +5840,7 @@ var require_ExplorerSync = __commonJS({
5815
5840
  searchDirectorySync(dir) {
5816
5841
  for (const place of this.config.searchPlaces) {
5817
5842
  const placeResult = this.loadSearchPlaceSync(dir, place);
5818
- if (this.shouldSearchStopWithResult(placeResult) === true) {
5843
+ if (this.shouldSearchStopWithResult(placeResult)) {
5819
5844
  return placeResult;
5820
5845
  }
5821
5846
  }
@@ -5824,8 +5849,7 @@ var require_ExplorerSync = __commonJS({
5824
5849
  loadSearchPlaceSync(dir, place) {
5825
5850
  const filepath = _path.default.join(dir, place);
5826
5851
  const content = (0, _readFile.readFileSync)(filepath);
5827
- const result = this.createCosmiconfigResultSync(filepath, content);
5828
- return result;
5852
+ return this.createCosmiconfigResultSync(filepath, content, false);
5829
5853
  }
5830
5854
  loadFileContentSync(filepath, content) {
5831
5855
  if (content === null) {
@@ -5842,21 +5866,22 @@ var require_ExplorerSync = __commonJS({
5842
5866
  throw e;
5843
5867
  }
5844
5868
  }
5845
- createCosmiconfigResultSync(filepath, content) {
5869
+ createCosmiconfigResultSync(filepath, content, forceProp) {
5846
5870
  const fileContent = this.loadFileContentSync(filepath, content);
5847
- const result = this.loadedContentToCosmiconfigResult(filepath, fileContent);
5848
- return result;
5871
+ return this.loadedContentToCosmiconfigResult(filepath, fileContent, forceProp);
5849
5872
  }
5850
5873
  loadSync(filepath) {
5874
+ return this._loadFileSync(filepath, false);
5875
+ }
5876
+ _loadFileSync(filepath, forceProp) {
5851
5877
  this.validateFilePath(filepath);
5852
5878
  const absoluteFilePath = _path.default.resolve(process.cwd(), filepath);
5853
5879
  const runLoadSync = () => {
5854
5880
  const content = (0, _readFile.readFileSync)(absoluteFilePath, {
5855
5881
  throwNotFound: true
5856
5882
  });
5857
- const cosmiconfigResult = this.createCosmiconfigResultSync(absoluteFilePath, content);
5858
- const transformResult = this.config.transform(cosmiconfigResult);
5859
- return transformResult;
5883
+ const cosmiconfigResult = this.createCosmiconfigResultSync(absoluteFilePath, content, forceProp);
5884
+ return this.config.transform(cosmiconfigResult);
5860
5885
  };
5861
5886
  if (this.loadCache) {
5862
5887
  return (0, _cacheWrapper.cacheWrapperSync)(this.loadCache, absoluteFilePath, runLoadSync);
@@ -5887,7 +5912,7 @@ var require_dist = __commonJS({
5887
5912
  });
5888
5913
  exports.cosmiconfig = cosmiconfig2;
5889
5914
  exports.cosmiconfigSync = cosmiconfigSync;
5890
- exports.defaultLoaders = void 0;
5915
+ exports.metaSearchPlaces = exports.defaultLoadersSync = exports.defaultLoaders = void 0;
5891
5916
  var _os = _interopRequireDefault(__require("os"));
5892
5917
  var _Explorer = require_Explorer();
5893
5918
  var _ExplorerSync = require_ExplorerSync();
@@ -5896,8 +5921,66 @@ var require_dist = __commonJS({
5896
5921
  function _interopRequireDefault(obj) {
5897
5922
  return obj && obj.__esModule ? obj : { default: obj };
5898
5923
  }
5924
+ var metaSearchPlaces = ["package.json", ".config.json", ".config.yaml", ".config.yml", ".config.js", ".config.cjs", ".config.mjs"];
5925
+ exports.metaSearchPlaces = metaSearchPlaces;
5926
+ var defaultLoaders = Object.freeze({
5927
+ ".mjs": _loaders.loaders.loadJs,
5928
+ ".cjs": _loaders.loaders.loadJs,
5929
+ ".js": _loaders.loaders.loadJs,
5930
+ ".json": _loaders.loaders.loadJson,
5931
+ ".yaml": _loaders.loaders.loadYaml,
5932
+ ".yml": _loaders.loaders.loadYaml,
5933
+ noExt: _loaders.loaders.loadYaml
5934
+ });
5935
+ exports.defaultLoaders = defaultLoaders;
5936
+ var defaultLoadersSync = Object.freeze({
5937
+ ".cjs": _loaders.loaders.loadJsSync,
5938
+ ".js": _loaders.loaders.loadJsSync,
5939
+ ".json": _loaders.loaders.loadJson,
5940
+ ".yaml": _loaders.loaders.loadYaml,
5941
+ ".yml": _loaders.loaders.loadYaml,
5942
+ noExt: _loaders.loaders.loadYaml
5943
+ });
5944
+ exports.defaultLoadersSync = defaultLoadersSync;
5945
+ var identity = function identity2(x) {
5946
+ return x;
5947
+ };
5948
+ function replaceMetaPlaceholders(paths, moduleName) {
5949
+ return paths.map((path) => path.replace("{name}", moduleName));
5950
+ }
5951
+ function getExplorerOptions(moduleName, options) {
5952
+ var _metaConfig$config;
5953
+ const metaExplorer = new _ExplorerSync.ExplorerSync({
5954
+ packageProp: "cosmiconfig",
5955
+ stopDir: process.cwd(),
5956
+ searchPlaces: metaSearchPlaces,
5957
+ ignoreEmptySearchPlaces: false,
5958
+ usePackagePropInConfigFiles: true,
5959
+ loaders: defaultLoaders,
5960
+ transform: identity,
5961
+ cache: true,
5962
+ metaConfigFilePath: null
5963
+ });
5964
+ const metaConfig = metaExplorer.searchSync();
5965
+ if (!metaConfig) {
5966
+ return options;
5967
+ }
5968
+ if ((_metaConfig$config = metaConfig.config) !== null && _metaConfig$config !== void 0 && _metaConfig$config.loaders) {
5969
+ throw new Error("Can not specify loaders in meta config file");
5970
+ }
5971
+ const overrideOptions = metaConfig.config ?? {};
5972
+ if (overrideOptions.searchPlaces) {
5973
+ overrideOptions.searchPlaces = replaceMetaPlaceholders(overrideOptions.searchPlaces, moduleName);
5974
+ }
5975
+ overrideOptions.metaConfigFilePath = metaConfig.filepath;
5976
+ return {
5977
+ ...options,
5978
+ ...overrideOptions
5979
+ };
5980
+ }
5899
5981
  function cosmiconfig2(moduleName, options = {}) {
5900
- const normalizedOptions = normalizeOptions(moduleName, options);
5982
+ const explorerOptions = getExplorerOptions(moduleName, options);
5983
+ const normalizedOptions = normalizeOptions(moduleName, explorerOptions);
5901
5984
  const explorer = new _Explorer.Explorer(normalizedOptions);
5902
5985
  return {
5903
5986
  search: explorer.search.bind(explorer),
@@ -5908,7 +5991,8 @@ var require_dist = __commonJS({
5908
5991
  };
5909
5992
  }
5910
5993
  function cosmiconfigSync(moduleName, options = {}) {
5911
- const normalizedOptions = normalizeOptions(moduleName, options);
5994
+ const explorerOptions = getExplorerOptions(moduleName, options);
5995
+ const normalizedOptions = normalizeOptionsSync(moduleName, explorerOptions);
5912
5996
  const explorerSync = new _ExplorerSync.ExplorerSync(normalizedOptions);
5913
5997
  return {
5914
5998
  search: explorerSync.searchSync.bind(explorerSync),
@@ -5918,19 +6002,28 @@ var require_dist = __commonJS({
5918
6002
  clearCaches: explorerSync.clearCaches.bind(explorerSync)
5919
6003
  };
5920
6004
  }
5921
- var defaultLoaders = Object.freeze({
5922
- ".cjs": _loaders.loaders.loadJs,
5923
- ".js": _loaders.loaders.loadJs,
5924
- ".json": _loaders.loaders.loadJson,
5925
- ".yaml": _loaders.loaders.loadYaml,
5926
- ".yml": _loaders.loaders.loadYaml,
5927
- noExt: _loaders.loaders.loadYaml
5928
- });
5929
- exports.defaultLoaders = defaultLoaders;
5930
- var identity = function identity2(x) {
5931
- return x;
5932
- };
5933
6005
  function normalizeOptions(moduleName, options) {
6006
+ const defaults = {
6007
+ packageProp: moduleName,
6008
+ searchPlaces: ["package.json", `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, `.${moduleName}rc.js`, `.${moduleName}rc.cjs`, `.${moduleName}rc.mjs`, `.config/${moduleName}rc`, `.config/${moduleName}rc.json`, `.config/${moduleName}rc.yaml`, `.config/${moduleName}rc.yml`, `.config/${moduleName}rc.js`, `.config/${moduleName}rc.cjs`, `.config/${moduleName}rc.mjs`, `${moduleName}.config.js`, `${moduleName}.config.cjs`, `${moduleName}.config.mjs`].filter(Boolean),
6009
+ ignoreEmptySearchPlaces: true,
6010
+ stopDir: _os.default.homedir(),
6011
+ cache: true,
6012
+ transform: identity,
6013
+ loaders: defaultLoaders,
6014
+ metaConfigFilePath: null
6015
+ };
6016
+ const normalizedOptions = {
6017
+ ...defaults,
6018
+ ...options,
6019
+ loaders: {
6020
+ ...defaults.loaders,
6021
+ ...options.loaders
6022
+ }
6023
+ };
6024
+ return normalizedOptions;
6025
+ }
6026
+ function normalizeOptionsSync(moduleName, options) {
5934
6027
  const defaults = {
5935
6028
  packageProp: moduleName,
5936
6029
  searchPlaces: ["package.json", `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, `.${moduleName}rc.js`, `.${moduleName}rc.cjs`, `.config/${moduleName}rc`, `.config/${moduleName}rc.json`, `.config/${moduleName}rc.yaml`, `.config/${moduleName}rc.yml`, `.config/${moduleName}rc.js`, `.config/${moduleName}rc.cjs`, `${moduleName}.config.js`, `${moduleName}.config.cjs`],
@@ -5938,7 +6031,8 @@ var require_dist = __commonJS({
5938
6031
  stopDir: _os.default.homedir(),
5939
6032
  cache: true,
5940
6033
  transform: identity,
5941
- loaders: defaultLoaders
6034
+ loaders: defaultLoadersSync,
6035
+ metaConfigFilePath: null
5942
6036
  };
5943
6037
  const normalizedOptions = {
5944
6038
  ...defaults,