@kitschpatrol/eslint-config 5.0.0 → 5.0.2

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/bin/cli.js CHANGED
@@ -627,7 +627,7 @@ var source_default = chalk;
627
627
  import { cosmiconfig } from "cosmiconfig";
628
628
  import { execa } from "execa";
629
629
  import fse2 from "fs-extra";
630
- import fs2 from "node:fs";
630
+ import fs3 from "node:fs";
631
631
  import path3 from "node:path";
632
632
  import { PassThrough } from "node:stream";
633
633
  import { fileURLToPath as fileURLToPath3 } from "node:url";
@@ -5541,7 +5541,7 @@ var Yargs = YargsFactory(esm_default);
5541
5541
  var yargs_default = Yargs;
5542
5542
 
5543
5543
  // ../../package.json
5544
- var version = "5.0.0";
5544
+ var version = "5.0.2";
5545
5545
 
5546
5546
  // ../../src/execa-utils.ts
5547
5547
  function isErrorExecaError(error) {
@@ -5726,6 +5726,29 @@ function getCwdOverride(option) {
5726
5726
  return process.cwd();
5727
5727
  }
5728
5728
 
5729
+ // ../../src/prettier-utils.ts
5730
+ import fs2 from "node:fs/promises";
5731
+ async function formatTextAndSaveFile(filePath, content) {
5732
+ try {
5733
+ const { default: prettier } = await import("prettier");
5734
+ const prettierConfig = await prettier.resolveConfig(filePath);
5735
+ const formattedContent = await prettier.format(content, {
5736
+ filepath: filePath,
5737
+ ...prettierConfig
5738
+ });
5739
+ await fs2.writeFile(filePath, formattedContent, "utf8");
5740
+ } catch {
5741
+ console.warn(`Skipped formatting ${filePath} since Prettier is not installed.`);
5742
+ }
5743
+ }
5744
+ async function formatFileInPlace(filePath) {
5745
+ try {
5746
+ const content = await fs2.readFile(filePath, "utf8");
5747
+ await formatTextAndSaveFile(filePath, content);
5748
+ } catch {
5749
+ }
5750
+ }
5751
+
5729
5752
  // ../../src/stream-utils.ts
5730
5753
  import { Transform } from "node:stream";
5731
5754
  function createStreamTransform(logPrefix, logColor) {
@@ -5771,7 +5794,11 @@ async function executeFunctionCommand(logStream, positionalArguments, optionFlag
5771
5794
  targetStream = subStream;
5772
5795
  }
5773
5796
  if (verbose) {
5774
- targetStream.write(source_default.bold(`Running: "${command2.name}()"`));
5797
+ targetStream.write(
5798
+ source_default.bold(
5799
+ `Running: "${command2.name}() with Positional arguments: ${String(positionalArguments)} and Option flags: ${String(optionFlags)}"`
5800
+ )
5801
+ );
5775
5802
  }
5776
5803
  try {
5777
5804
  exitCode = await command2.execute(targetStream, positionalArguments, optionFlags);
@@ -5889,9 +5916,6 @@ async function copyAndMergeInitFiles(logStream, location, configFile, configPack
5889
5916
  const source = path3.join(path3.dirname(sourcePackage), "init");
5890
5917
  const destination = path3.dirname(destinationPackage);
5891
5918
  const hasConfigLocationOption = (location === "file" || location === "package") && configFile !== void 0 && configPackageJson !== void 0;
5892
- logStream.write(`Adding initial configuration files from:
5893
- "${source}" \u2192 "${destination}"
5894
- `);
5895
5919
  try {
5896
5920
  if (hasConfigLocationOption) {
5897
5921
  const configKey = Object.keys(configPackageJson)[0];
@@ -5903,7 +5927,8 @@ Package config key "${configKey}" \u2192 "${destination}" (Because --location is
5903
5927
  `
5904
5928
  );
5905
5929
  const mergedPackageJson = merge(destinationPackageJson, configPackageJson);
5906
- fse2.writeJSONSync(destinationPackage, mergedPackageJson, { spaces: 2 });
5930
+ fse2.writeJSONSync(destinationPackage, mergedPackageJson, { spaces: " " });
5931
+ await formatFileInPlace(destinationPackage);
5907
5932
  } else {
5908
5933
  const destinationPackageJson = fse2.readJsonSync(destinationPackage);
5909
5934
  if (Object.keys(destinationPackageJson).includes(configKey)) {
@@ -5913,14 +5938,28 @@ Package config key "${configKey}" in "${destination}" (Because --location is set
5913
5938
  `
5914
5939
  );
5915
5940
  delete destinationPackageJson[configKey];
5916
- fse2.writeJSONSync(destinationPackage, destinationPackageJson, { spaces: 2 });
5941
+ fse2.writeJSONSync(destinationPackage, destinationPackageJson, { spaces: " " });
5942
+ await formatFileInPlace(destinationPackage);
5917
5943
  }
5918
5944
  }
5919
5945
  }
5946
+ const sourceExists = await fse2.pathExists(source);
5947
+ if (!sourceExists) {
5948
+ return 0;
5949
+ }
5950
+ const sourceFiles = await fse2.readdir(source);
5951
+ if (sourceFiles.length === 0) {
5952
+ logStream.write(`Source directory "${source}" is empty.
5953
+ `);
5954
+ return 0;
5955
+ }
5956
+ logStream.write(`Adding initial configuration files from:
5957
+ "${source}" \u2192 "${destination}"
5958
+ `);
5920
5959
  await fse2.copy(source, destination, {
5921
- filter(source2, destination2) {
5922
- const isFile = fs2.statSync(source2).isFile();
5923
- const destinationExists = fs2.existsSync(destination2);
5960
+ async filter(source2, destination2) {
5961
+ const isFile = fs3.statSync(source2).isFile();
5962
+ const destinationExists = fs3.existsSync(destination2);
5924
5963
  if (isFile) {
5925
5964
  if (hasConfigLocationOption && location === "package" && source2.includes(configFile)) {
5926
5965
  if (destinationExists) {
@@ -5939,25 +5978,28 @@ Package config key "${configKey}" in "${destination}" (Because --location is set
5939
5978
  }
5940
5979
  return false;
5941
5980
  }
5942
- if (destinationExists && destination2.includes(".vscode/") && path3.extname(destination2) === ".json") {
5981
+ if (destinationExists && (destination2.includes(".vscode/") || destination2.includes("package.json")) && path3.extname(destination2) === ".json") {
5943
5982
  logStream.write(`Merging:
5944
5983
  "${source2}" \u2192 "${destination2}"
5945
5984
  `);
5946
5985
  const sourceJson = fse2.readJSONSync(source2);
5947
5986
  const destinationJson = fse2.readJSONSync(destination2);
5948
5987
  const mergedJson = merge(destinationJson, sourceJson);
5949
- fse2.writeJSONSync(destination2, mergedJson, { spaces: 2 });
5988
+ fse2.writeJSONSync(destination2, mergedJson, { spaces: " " });
5989
+ await formatFileInPlace(destination2);
5950
5990
  return false;
5951
5991
  }
5952
5992
  if (destinationExists) {
5953
5993
  logStream.write(`Overwriting:
5954
5994
  "${source2}" \u2192 "${destination2}"
5955
5995
  `);
5996
+ await formatFileInPlace(destination2);
5956
5997
  return true;
5957
5998
  }
5958
5999
  logStream.write(`Copying:
5959
6000
  "${source2}" \u2192 "${destination2}"
5960
6001
  `);
6002
+ await formatFileInPlace(destination2);
5961
6003
  return true;
5962
6004
  }
5963
6005
  return true;
@@ -5997,11 +6039,12 @@ async function buildCommands(commandDefinition2) {
5997
6039
  // Command: init.locationOptionFlag ? 'init [--location]' : 'init',
5998
6040
  describe: init.description ?? `Initialize by copying starter config files to your project root${init.locationOptionFlag ? " or to your package.json file." : "."}`,
5999
6041
  async handler(argv) {
6042
+ const location = init.locationOptionFlag ? argv.location : void 0;
6000
6043
  const copyAndMergeInitFilesCommand = {
6001
- async execute(logStream2) {
6044
+ async execute(logStream2, _, optionFlags) {
6002
6045
  return copyAndMergeInitFiles(
6003
6046
  logStream2,
6004
- init.locationOptionFlag ? argv.location : void 0,
6047
+ optionFlags.at(1),
6005
6048
  init.configFile,
6006
6049
  init.configPackageJson
6007
6050
  );
@@ -6011,7 +6054,7 @@ async function buildCommands(commandDefinition2) {
6011
6054
  const exitCode = await executeCommands(
6012
6055
  logStream,
6013
6056
  [],
6014
- [],
6057
+ location === void 0 ? [] : ["--location", location],
6015
6058
  [copyAndMergeInitFilesCommand, ...init.commands ?? []]
6016
6059
  );
6017
6060
  process.exit(exitCode);