@kitschpatrol/shared-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.
Files changed (2) hide show
  1. package/bin/cli.js +107 -25
  2. package/package.json +12 -10
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) {
@@ -5753,6 +5753,29 @@ function getCwdOverride(option) {
5753
5753
  return process.cwd();
5754
5754
  }
5755
5755
 
5756
+ // ../../src/prettier-utils.ts
5757
+ import fs2 from "node:fs/promises";
5758
+ async function formatTextAndSaveFile(filePath, content) {
5759
+ try {
5760
+ const { default: prettier } = await import("prettier");
5761
+ const prettierConfig = await prettier.resolveConfig(filePath);
5762
+ const formattedContent = await prettier.format(content, {
5763
+ filepath: filePath,
5764
+ ...prettierConfig
5765
+ });
5766
+ await fs2.writeFile(filePath, formattedContent, "utf8");
5767
+ } catch {
5768
+ console.warn(`Skipped formatting ${filePath} since Prettier is not installed.`);
5769
+ }
5770
+ }
5771
+ async function formatFileInPlace(filePath) {
5772
+ try {
5773
+ const content = await fs2.readFile(filePath, "utf8");
5774
+ await formatTextAndSaveFile(filePath, content);
5775
+ } catch {
5776
+ }
5777
+ }
5778
+
5756
5779
  // ../../src/stream-utils.ts
5757
5780
  import { Transform } from "node:stream";
5758
5781
  function createStreamFilter(matcher) {
@@ -5810,7 +5833,11 @@ async function executeFunctionCommand(logStream, positionalArguments, optionFlag
5810
5833
  targetStream = subStream;
5811
5834
  }
5812
5835
  if (verbose) {
5813
- targetStream.write(source_default.bold(`Running: "${command2.name}()"`));
5836
+ targetStream.write(
5837
+ source_default.bold(
5838
+ `Running: "${command2.name}() with Positional arguments: ${String(positionalArguments)} and Option flags: ${String(optionFlags)}"`
5839
+ )
5840
+ );
5814
5841
  }
5815
5842
  try {
5816
5843
  exitCode = await command2.execute(targetStream, positionalArguments, optionFlags);
@@ -5928,9 +5955,6 @@ async function copyAndMergeInitFiles(logStream, location, configFile, configPack
5928
5955
  const source = path3.join(path3.dirname(sourcePackage), "init");
5929
5956
  const destination = path3.dirname(destinationPackage);
5930
5957
  const hasConfigLocationOption = (location === "file" || location === "package") && configFile !== void 0 && configPackageJson !== void 0;
5931
- logStream.write(`Adding initial configuration files from:
5932
- "${source}" \u2192 "${destination}"
5933
- `);
5934
5958
  try {
5935
5959
  if (hasConfigLocationOption) {
5936
5960
  const configKey = Object.keys(configPackageJson)[0];
@@ -5942,7 +5966,8 @@ Package config key "${configKey}" \u2192 "${destination}" (Because --location is
5942
5966
  `
5943
5967
  );
5944
5968
  const mergedPackageJson = merge(destinationPackageJson, configPackageJson);
5945
- fse2.writeJSONSync(destinationPackage, mergedPackageJson, { spaces: 2 });
5969
+ fse2.writeJSONSync(destinationPackage, mergedPackageJson, { spaces: " " });
5970
+ await formatFileInPlace(destinationPackage);
5946
5971
  } else {
5947
5972
  const destinationPackageJson = fse2.readJsonSync(destinationPackage);
5948
5973
  if (Object.keys(destinationPackageJson).includes(configKey)) {
@@ -5952,14 +5977,28 @@ Package config key "${configKey}" in "${destination}" (Because --location is set
5952
5977
  `
5953
5978
  );
5954
5979
  delete destinationPackageJson[configKey];
5955
- fse2.writeJSONSync(destinationPackage, destinationPackageJson, { spaces: 2 });
5980
+ fse2.writeJSONSync(destinationPackage, destinationPackageJson, { spaces: " " });
5981
+ await formatFileInPlace(destinationPackage);
5956
5982
  }
5957
5983
  }
5958
5984
  }
5985
+ const sourceExists = await fse2.pathExists(source);
5986
+ if (!sourceExists) {
5987
+ return 0;
5988
+ }
5989
+ const sourceFiles = await fse2.readdir(source);
5990
+ if (sourceFiles.length === 0) {
5991
+ logStream.write(`Source directory "${source}" is empty.
5992
+ `);
5993
+ return 0;
5994
+ }
5995
+ logStream.write(`Adding initial configuration files from:
5996
+ "${source}" \u2192 "${destination}"
5997
+ `);
5959
5998
  await fse2.copy(source, destination, {
5960
- filter(source2, destination2) {
5961
- const isFile = fs2.statSync(source2).isFile();
5962
- const destinationExists = fs2.existsSync(destination2);
5999
+ async filter(source2, destination2) {
6000
+ const isFile = fs3.statSync(source2).isFile();
6001
+ const destinationExists = fs3.existsSync(destination2);
5963
6002
  if (isFile) {
5964
6003
  if (hasConfigLocationOption && location === "package" && source2.includes(configFile)) {
5965
6004
  if (destinationExists) {
@@ -5978,25 +6017,28 @@ Package config key "${configKey}" in "${destination}" (Because --location is set
5978
6017
  }
5979
6018
  return false;
5980
6019
  }
5981
- if (destinationExists && destination2.includes(".vscode/") && path3.extname(destination2) === ".json") {
6020
+ if (destinationExists && (destination2.includes(".vscode/") || destination2.includes("package.json")) && path3.extname(destination2) === ".json") {
5982
6021
  logStream.write(`Merging:
5983
6022
  "${source2}" \u2192 "${destination2}"
5984
6023
  `);
5985
6024
  const sourceJson = fse2.readJSONSync(source2);
5986
6025
  const destinationJson = fse2.readJSONSync(destination2);
5987
6026
  const mergedJson = merge(destinationJson, sourceJson);
5988
- fse2.writeJSONSync(destination2, mergedJson, { spaces: 2 });
6027
+ fse2.writeJSONSync(destination2, mergedJson, { spaces: " " });
6028
+ await formatFileInPlace(destination2);
5989
6029
  return false;
5990
6030
  }
5991
6031
  if (destinationExists) {
5992
6032
  logStream.write(`Overwriting:
5993
6033
  "${source2}" \u2192 "${destination2}"
5994
6034
  `);
6035
+ await formatFileInPlace(destination2);
5995
6036
  return true;
5996
6037
  }
5997
6038
  logStream.write(`Copying:
5998
6039
  "${source2}" \u2192 "${destination2}"
5999
6040
  `);
6041
+ await formatFileInPlace(destination2);
6000
6042
  return true;
6001
6043
  }
6002
6044
  return true;
@@ -6036,11 +6078,12 @@ async function buildCommands(commandDefinition11) {
6036
6078
  // Command: init.locationOptionFlag ? 'init [--location]' : 'init',
6037
6079
  describe: init.description ?? `Initialize by copying starter config files to your project root${init.locationOptionFlag ? " or to your package.json file." : "."}`,
6038
6080
  async handler(argv) {
6081
+ const location = init.locationOptionFlag ? argv.location : void 0;
6039
6082
  const copyAndMergeInitFilesCommand = {
6040
- async execute(logStream2) {
6083
+ async execute(logStream2, _, optionFlags) {
6041
6084
  return copyAndMergeInitFiles(
6042
6085
  logStream2,
6043
- init.locationOptionFlag ? argv.location : void 0,
6086
+ optionFlags.at(1),
6044
6087
  init.configFile,
6045
6088
  init.configPackageJson
6046
6089
  );
@@ -6050,7 +6093,7 @@ async function buildCommands(commandDefinition11) {
6050
6093
  const exitCode = await executeCommands(
6051
6094
  logStream,
6052
6095
  [],
6053
- [],
6096
+ location === void 0 ? [] : ["--location", location],
6054
6097
  [copyAndMergeInitFilesCommand, ...init.commands ?? []]
6055
6098
  );
6056
6099
  process.exit(exitCode);
@@ -6231,6 +6274,21 @@ async function checkForUnusedWords(fileGlobs = ["."]) {
6231
6274
  }
6232
6275
 
6233
6276
  // ../cspell-config/src/command.ts
6277
+ async function getCspellIgnorePaths() {
6278
+ const config = await getDefaultConfigLoader2().searchForConfigFile(void 0);
6279
+ if (config === void 0) {
6280
+ throw new Error("No CSpell configuration found.");
6281
+ }
6282
+ const resolvedConfig = await resolveConfigFileImports(config);
6283
+ if (resolvedConfig.ignorePaths === void 0) {
6284
+ return "";
6285
+ }
6286
+ const globStrings = [];
6287
+ for (const globDefOrString of resolvedConfig.ignorePaths) {
6288
+ globStrings.push(typeof globDefOrString === "string" ? globDefOrString : globDefOrString.glob);
6289
+ }
6290
+ return globStrings.join(",");
6291
+ }
6234
6292
  async function checkForUnusedWordsCommand(logStream, positionalArguments) {
6235
6293
  const unusedWords = await checkForUnusedWords(positionalArguments);
6236
6294
  if (unusedWords.length > 0) {
@@ -6275,7 +6333,12 @@ async function casePoliceCommand(logStream, positionalArguments) {
6275
6333
  logColor: "cyanBright",
6276
6334
  logPrefix,
6277
6335
  name: "case-police",
6278
- optionFlags: ["--dict", await getCasePoliceDictionaryPath()],
6336
+ optionFlags: [
6337
+ "--dict",
6338
+ await getCasePoliceDictionaryPath(),
6339
+ "--ignore",
6340
+ await getCspellIgnorePaths()
6341
+ ],
6279
6342
  receivePositionalArguments: true
6280
6343
  }
6281
6344
  ]
@@ -6300,7 +6363,7 @@ async function printCspellConfigCommand(logStream) {
6300
6363
  var commandDefinition = {
6301
6364
  commands: {
6302
6365
  init: {
6303
- configFile: "cspell.config.json",
6366
+ configFile: "cspell.config.js",
6304
6367
  configPackageJson: {
6305
6368
  cspell: {
6306
6369
  import: "@kitschpatrol/cspell-config"
@@ -6426,6 +6489,11 @@ import path6 from "node:path";
6426
6489
  // ../knip-config/src/index.ts
6427
6490
  var sharedKnipConfig = {
6428
6491
  entry: [
6492
+ // Default entry... not merging in from default Knip config?
6493
+ "{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!",
6494
+ "src/{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!",
6495
+ // Customized entries
6496
+ "src/{bin,lib,cli}/{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!",
6429
6497
  "scripts/**/*.ts",
6430
6498
  ".remarkrc.js",
6431
6499
  "cspell.config.js",
@@ -6433,6 +6501,15 @@ var sharedKnipConfig = {
6433
6501
  "mdat.config.ts",
6434
6502
  "prettier.config.js",
6435
6503
  "stylelint.config.js"
6504
+ ],
6505
+ ignoreDependencies: [
6506
+ "@kitschpatrol/cspell-config",
6507
+ "@kitschpatrol/eslint-config",
6508
+ "@kitschpatrol/knip-config",
6509
+ "@kitschpatrol/mdat-config",
6510
+ "@kitschpatrol/prettier-config",
6511
+ "@kitschpatrol/remark-config",
6512
+ "@kitschpatrol/stylelint-config"
6436
6513
  ]
6437
6514
  };
6438
6515
  var src_default = sharedKnipConfig;
@@ -6463,7 +6540,12 @@ var commandDefinition3 = {
6463
6540
  {
6464
6541
  cwdOverride: "workspace-root",
6465
6542
  name: "knip",
6466
- optionFlags: ["--fix", "--allow-remove-files", ...getWorkspaceOptionFlags()]
6543
+ optionFlags: [
6544
+ "--fix",
6545
+ "--allow-remove-files",
6546
+ "--no-config-hints",
6547
+ ...getWorkspaceOptionFlags()
6548
+ ]
6467
6549
  }
6468
6550
  ],
6469
6551
  description: `Automatically remove unused code and dependencies. ${DESCRIPTION.packageRun} ${DESCRIPTION.monorepoRun}`,
@@ -6481,7 +6563,7 @@ var commandDefinition3 = {
6481
6563
  // Run from root, then pass --workspace IF in a monorepo and called from a subpackage
6482
6564
  cwdOverride: "workspace-root",
6483
6565
  name: "knip",
6484
- optionFlags: ["--no-progress", ...getWorkspaceOptionFlags()]
6566
+ optionFlags: ["--no-progress", "--no-config-hints", ...getWorkspaceOptionFlags()]
6485
6567
  }
6486
6568
  // "Production" pass is not worth it?
6487
6569
  // {
@@ -6658,7 +6740,7 @@ var commandDefinition6 = {
6658
6740
  plugins: ["@kitschpatrol/remark-config"]
6659
6741
  }
6660
6742
  },
6661
- locationOptionFlag: false
6743
+ locationOptionFlag: true
6662
6744
  },
6663
6745
  printConfig: {
6664
6746
  commands: [getCosmiconfigCommand("remark")],
@@ -6674,7 +6756,7 @@ var commandDefinition6 = {
6674
6756
  };
6675
6757
 
6676
6758
  // ../repo-config/src/copyright-year-updater.ts
6677
- import fs3 from "node:fs/promises";
6759
+ import fs4 from "node:fs/promises";
6678
6760
 
6679
6761
  // ../../src/node-utils.ts
6680
6762
  import process5 from "node:process";
@@ -6735,7 +6817,7 @@ async function copyrightYear(logStream, fix = false) {
6735
6817
  "!node_modules/**"
6736
6818
  ];
6737
6819
  suppressNodeWarnings();
6738
- for await (const filePath of fs3.glob(patterns, {
6820
+ for await (const filePath of fs4.glob(patterns, {
6739
6821
  cwd: getPackageDirectory(),
6740
6822
  // Will find monorepo packages
6741
6823
  withFileTypes: false
@@ -6746,12 +6828,12 @@ async function copyrightYear(logStream, fix = false) {
6746
6828
  const outdatedLicenseFiles = [];
6747
6829
  for (const filePath of licenseFiles) {
6748
6830
  try {
6749
- const originalContent = await fs3.readFile(filePath, "utf8");
6831
+ const originalContent = await fs4.readFile(filePath, "utf8");
6750
6832
  const updatedContent = updateLicenseContent(originalContent, currentYear);
6751
6833
  if (updatedContent !== originalContent) {
6752
6834
  outdatedLicenseFiles.push(filePath);
6753
6835
  if (fix) {
6754
- await fs3.writeFile(filePath, updatedContent, "utf8");
6836
+ await fs4.writeFile(filePath, updatedContent, "utf8");
6755
6837
  }
6756
6838
  }
6757
6839
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitschpatrol/shared-config",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "description": "A collection of shared configurations for various linters and formatting tools. All managed as a single dependency, and invoked via a single command.",
5
5
  "keywords": [
6
6
  "shared-config",
@@ -38,16 +38,18 @@
38
38
  "@pinojs/json-colorizer": "^4.0.0",
39
39
  "cosmiconfig": "^9.0.0",
40
40
  "execa": "^9.5.2",
41
+ "find-workspaces": "^0.3.1",
41
42
  "fs-extra": "^11.3.0",
42
- "@kitschpatrol/eslint-config": "5.0.0",
43
- "@kitschpatrol/prettier-config": "5.0.0",
44
- "@kitschpatrol/knip-config": "5.0.0",
45
- "@kitschpatrol/repo-config": "5.0.0",
46
- "@kitschpatrol/cspell-config": "5.0.0",
47
- "@kitschpatrol/remark-config": "5.0.0",
48
- "@kitschpatrol/mdat-config": "5.0.0",
49
- "@kitschpatrol/stylelint-config": "5.0.0",
50
- "@kitschpatrol/typescript-config": "5.0.0"
43
+ "prettier": "^3.4.2",
44
+ "@kitschpatrol/cspell-config": "5.0.2",
45
+ "@kitschpatrol/knip-config": "5.0.2",
46
+ "@kitschpatrol/mdat-config": "5.0.2",
47
+ "@kitschpatrol/eslint-config": "5.0.2",
48
+ "@kitschpatrol/repo-config": "5.0.2",
49
+ "@kitschpatrol/remark-config": "5.0.2",
50
+ "@kitschpatrol/stylelint-config": "5.0.2",
51
+ "@kitschpatrol/prettier-config": "5.0.2",
52
+ "@kitschpatrol/typescript-config": "5.0.2"
51
53
  },
52
54
  "devDependencies": {
53
55
  "chalk": "^5.4.1",