@kitschpatrol/prettier-config 5.0.0 → 5.0.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.
- package/bin/cli.js +59 -16
- package/dist/index.js +27 -0
- package/package.json +3 -2
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
|
|
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.
|
|
5544
|
+
var version = "5.0.1";
|
|
5545
5545
|
|
|
5546
5546
|
// ../../src/execa-utils.ts
|
|
5547
5547
|
function isErrorExecaError(error) {
|
|
@@ -5733,6 +5733,29 @@ function getCwdOverride(option) {
|
|
|
5733
5733
|
return process.cwd();
|
|
5734
5734
|
}
|
|
5735
5735
|
|
|
5736
|
+
// ../../src/prettier-utils.ts
|
|
5737
|
+
import fs2 from "node:fs/promises";
|
|
5738
|
+
async function formatTextAndSaveFile(filePath, content) {
|
|
5739
|
+
try {
|
|
5740
|
+
const { default: prettier } = await import("prettier");
|
|
5741
|
+
const prettierConfig = await prettier.resolveConfig(filePath);
|
|
5742
|
+
const formattedContent = await prettier.format(content, {
|
|
5743
|
+
filepath: filePath,
|
|
5744
|
+
...prettierConfig
|
|
5745
|
+
});
|
|
5746
|
+
await fs2.writeFile(filePath, formattedContent, "utf8");
|
|
5747
|
+
} catch {
|
|
5748
|
+
console.warn(`Skipped formatting ${filePath} since Prettier is not installed.`);
|
|
5749
|
+
}
|
|
5750
|
+
}
|
|
5751
|
+
async function formatFileInPlace(filePath) {
|
|
5752
|
+
try {
|
|
5753
|
+
const content = await fs2.readFile(filePath, "utf8");
|
|
5754
|
+
await formatTextAndSaveFile(filePath, content);
|
|
5755
|
+
} catch {
|
|
5756
|
+
}
|
|
5757
|
+
}
|
|
5758
|
+
|
|
5736
5759
|
// ../../src/stream-utils.ts
|
|
5737
5760
|
import { Transform } from "node:stream";
|
|
5738
5761
|
function createStreamTransform(logPrefix, logColor) {
|
|
@@ -5778,7 +5801,11 @@ async function executeFunctionCommand(logStream, positionalArguments, optionFlag
|
|
|
5778
5801
|
targetStream = subStream;
|
|
5779
5802
|
}
|
|
5780
5803
|
if (verbose) {
|
|
5781
|
-
targetStream.write(
|
|
5804
|
+
targetStream.write(
|
|
5805
|
+
source_default.bold(
|
|
5806
|
+
`Running: "${command2.name}() with Positional arguments: ${String(positionalArguments)} and Option flags: ${String(optionFlags)}"`
|
|
5807
|
+
)
|
|
5808
|
+
);
|
|
5782
5809
|
}
|
|
5783
5810
|
try {
|
|
5784
5811
|
exitCode = await command2.execute(targetStream, positionalArguments, optionFlags);
|
|
@@ -5896,9 +5923,6 @@ async function copyAndMergeInitFiles(logStream, location, configFile, configPack
|
|
|
5896
5923
|
const source = path3.join(path3.dirname(sourcePackage), "init");
|
|
5897
5924
|
const destination = path3.dirname(destinationPackage);
|
|
5898
5925
|
const hasConfigLocationOption = (location === "file" || location === "package") && configFile !== void 0 && configPackageJson !== void 0;
|
|
5899
|
-
logStream.write(`Adding initial configuration files from:
|
|
5900
|
-
"${source}" \u2192 "${destination}"
|
|
5901
|
-
`);
|
|
5902
5926
|
try {
|
|
5903
5927
|
if (hasConfigLocationOption) {
|
|
5904
5928
|
const configKey = Object.keys(configPackageJson)[0];
|
|
@@ -5910,7 +5934,8 @@ Package config key "${configKey}" \u2192 "${destination}" (Because --location is
|
|
|
5910
5934
|
`
|
|
5911
5935
|
);
|
|
5912
5936
|
const mergedPackageJson = merge(destinationPackageJson, configPackageJson);
|
|
5913
|
-
fse2.writeJSONSync(destinationPackage, mergedPackageJson, { spaces:
|
|
5937
|
+
fse2.writeJSONSync(destinationPackage, mergedPackageJson, { spaces: " " });
|
|
5938
|
+
await formatFileInPlace(destinationPackage);
|
|
5914
5939
|
} else {
|
|
5915
5940
|
const destinationPackageJson = fse2.readJsonSync(destinationPackage);
|
|
5916
5941
|
if (Object.keys(destinationPackageJson).includes(configKey)) {
|
|
@@ -5920,14 +5945,28 @@ Package config key "${configKey}" in "${destination}" (Because --location is set
|
|
|
5920
5945
|
`
|
|
5921
5946
|
);
|
|
5922
5947
|
delete destinationPackageJson[configKey];
|
|
5923
|
-
fse2.writeJSONSync(destinationPackage, destinationPackageJson, { spaces:
|
|
5948
|
+
fse2.writeJSONSync(destinationPackage, destinationPackageJson, { spaces: " " });
|
|
5949
|
+
await formatFileInPlace(destinationPackage);
|
|
5924
5950
|
}
|
|
5925
5951
|
}
|
|
5926
5952
|
}
|
|
5953
|
+
const sourceExists = await fse2.pathExists(source);
|
|
5954
|
+
if (!sourceExists) {
|
|
5955
|
+
return 0;
|
|
5956
|
+
}
|
|
5957
|
+
const sourceFiles = await fse2.readdir(source);
|
|
5958
|
+
if (sourceFiles.length === 0) {
|
|
5959
|
+
logStream.write(`Source directory "${source}" is empty.
|
|
5960
|
+
`);
|
|
5961
|
+
return 0;
|
|
5962
|
+
}
|
|
5963
|
+
logStream.write(`Adding initial configuration files from:
|
|
5964
|
+
"${source}" \u2192 "${destination}"
|
|
5965
|
+
`);
|
|
5927
5966
|
await fse2.copy(source, destination, {
|
|
5928
|
-
filter(source2, destination2) {
|
|
5929
|
-
const isFile =
|
|
5930
|
-
const destinationExists =
|
|
5967
|
+
async filter(source2, destination2) {
|
|
5968
|
+
const isFile = fs3.statSync(source2).isFile();
|
|
5969
|
+
const destinationExists = fs3.existsSync(destination2);
|
|
5931
5970
|
if (isFile) {
|
|
5932
5971
|
if (hasConfigLocationOption && location === "package" && source2.includes(configFile)) {
|
|
5933
5972
|
if (destinationExists) {
|
|
@@ -5946,25 +5985,28 @@ Package config key "${configKey}" in "${destination}" (Because --location is set
|
|
|
5946
5985
|
}
|
|
5947
5986
|
return false;
|
|
5948
5987
|
}
|
|
5949
|
-
if (destinationExists && destination2.includes(".vscode/") && path3.extname(destination2) === ".json") {
|
|
5988
|
+
if (destinationExists && (destination2.includes(".vscode/") || destination2.includes("package.json")) && path3.extname(destination2) === ".json") {
|
|
5950
5989
|
logStream.write(`Merging:
|
|
5951
5990
|
"${source2}" \u2192 "${destination2}"
|
|
5952
5991
|
`);
|
|
5953
5992
|
const sourceJson = fse2.readJSONSync(source2);
|
|
5954
5993
|
const destinationJson = fse2.readJSONSync(destination2);
|
|
5955
5994
|
const mergedJson = merge(destinationJson, sourceJson);
|
|
5956
|
-
fse2.writeJSONSync(destination2, mergedJson, { spaces:
|
|
5995
|
+
fse2.writeJSONSync(destination2, mergedJson, { spaces: " " });
|
|
5996
|
+
await formatFileInPlace(destination2);
|
|
5957
5997
|
return false;
|
|
5958
5998
|
}
|
|
5959
5999
|
if (destinationExists) {
|
|
5960
6000
|
logStream.write(`Overwriting:
|
|
5961
6001
|
"${source2}" \u2192 "${destination2}"
|
|
5962
6002
|
`);
|
|
6003
|
+
await formatFileInPlace(destination2);
|
|
5963
6004
|
return true;
|
|
5964
6005
|
}
|
|
5965
6006
|
logStream.write(`Copying:
|
|
5966
6007
|
"${source2}" \u2192 "${destination2}"
|
|
5967
6008
|
`);
|
|
6009
|
+
await formatFileInPlace(destination2);
|
|
5968
6010
|
return true;
|
|
5969
6011
|
}
|
|
5970
6012
|
return true;
|
|
@@ -6004,11 +6046,12 @@ async function buildCommands(commandDefinition2) {
|
|
|
6004
6046
|
// Command: init.locationOptionFlag ? 'init [--location]' : 'init',
|
|
6005
6047
|
describe: init.description ?? `Initialize by copying starter config files to your project root${init.locationOptionFlag ? " or to your package.json file." : "."}`,
|
|
6006
6048
|
async handler(argv) {
|
|
6049
|
+
const location = init.locationOptionFlag ? argv.location : void 0;
|
|
6007
6050
|
const copyAndMergeInitFilesCommand = {
|
|
6008
|
-
async execute(logStream2) {
|
|
6051
|
+
async execute(logStream2, _, optionFlags) {
|
|
6009
6052
|
return copyAndMergeInitFiles(
|
|
6010
6053
|
logStream2,
|
|
6011
|
-
|
|
6054
|
+
optionFlags.at(1),
|
|
6012
6055
|
init.configFile,
|
|
6013
6056
|
init.configPackageJson
|
|
6014
6057
|
);
|
|
@@ -6018,7 +6061,7 @@ async function buildCommands(commandDefinition2) {
|
|
|
6018
6061
|
const exitCode = await executeCommands(
|
|
6019
6062
|
logStream,
|
|
6020
6063
|
[],
|
|
6021
|
-
[],
|
|
6064
|
+
location === void 0 ? [] : ["--location", location],
|
|
6022
6065
|
[copyAndMergeInitFilesCommand, ...init.commands ?? []]
|
|
6023
6066
|
);
|
|
6024
6067
|
process.exit(exitCode);
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { deepmerge } from 'deepmerge-ts';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
|
+
import { sortOrder as sortPackageJsonSortOrder } from 'sort-package-json';
|
|
3
4
|
// export { commandDefinition } from './command.js'
|
|
5
|
+
/**
|
|
6
|
+
* Merge custom keys into the `sort-package-json` `order` array. Where
|
|
7
|
+
* duplicated, delete existing and prioritize new keys.
|
|
8
|
+
*/
|
|
9
|
+
function customizeSortOrder(keys, newKeys) {
|
|
10
|
+
// If new keys are in keys, remove them
|
|
11
|
+
const filteredKeys = keys.filter((key) => !newKeys.includes(key));
|
|
12
|
+
// Append new keys to the end
|
|
13
|
+
return [...filteredKeys, ...newKeys];
|
|
14
|
+
}
|
|
4
15
|
const sharedPrettierConfig = {
|
|
5
16
|
bracketSpacing: true,
|
|
6
17
|
overrides: [
|
|
@@ -37,6 +48,22 @@ const sharedPrettierConfig = {
|
|
|
37
48
|
plugins: ['prettier-plugin-sh'],
|
|
38
49
|
},
|
|
39
50
|
},
|
|
51
|
+
// Make this match eslint 'json-package/order-properties'
|
|
52
|
+
// https://github.com/matzkoh/prettier-plugin-packagejson/issues/188
|
|
53
|
+
// This must stay in sync with packages/eslint-config/src/configs/json.ts
|
|
54
|
+
{
|
|
55
|
+
files: 'package.json',
|
|
56
|
+
options: {
|
|
57
|
+
packageSortOrder: customizeSortOrder(sortPackageJsonSortOrder, [
|
|
58
|
+
'cspell',
|
|
59
|
+
'knip',
|
|
60
|
+
'mdat',
|
|
61
|
+
'prettier',
|
|
62
|
+
'remarkConfig',
|
|
63
|
+
'stylelint',
|
|
64
|
+
]),
|
|
65
|
+
},
|
|
66
|
+
},
|
|
40
67
|
],
|
|
41
68
|
plugins: [
|
|
42
69
|
'@prettier/plugin-php',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/prettier-config",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Prettier configuration for @kitschpatrol/shared-config.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shared-config",
|
|
@@ -55,7 +55,8 @@
|
|
|
55
55
|
"prettier-plugin-sql": "^0.18.1",
|
|
56
56
|
"prettier-plugin-svelte": "^3.3.3",
|
|
57
57
|
"prettier-plugin-tailwindcss": "^0.6.11",
|
|
58
|
-
"prettier-plugin-toml": "^2.0.1"
|
|
58
|
+
"prettier-plugin-toml": "^2.0.1",
|
|
59
|
+
"sort-package-json": "^2.14.0"
|
|
59
60
|
},
|
|
60
61
|
"engines": {
|
|
61
62
|
"node": ">=22.0.0",
|