@kitschpatrol/knip-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 +80 -18
- package/dist/index.js +14 -0
- package/package.json +4 -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.2";
|
|
5545
5545
|
|
|
5546
5546
|
// ../../src/execa-utils.ts
|
|
5547
5547
|
function isErrorExecaError(error) {
|
|
@@ -5729,6 +5729,29 @@ function getCwdOverride(option) {
|
|
|
5729
5729
|
return process.cwd();
|
|
5730
5730
|
}
|
|
5731
5731
|
|
|
5732
|
+
// ../../src/prettier-utils.ts
|
|
5733
|
+
import fs2 from "node:fs/promises";
|
|
5734
|
+
async function formatTextAndSaveFile(filePath, content) {
|
|
5735
|
+
try {
|
|
5736
|
+
const { default: prettier } = await import("prettier");
|
|
5737
|
+
const prettierConfig = await prettier.resolveConfig(filePath);
|
|
5738
|
+
const formattedContent = await prettier.format(content, {
|
|
5739
|
+
filepath: filePath,
|
|
5740
|
+
...prettierConfig
|
|
5741
|
+
});
|
|
5742
|
+
await fs2.writeFile(filePath, formattedContent, "utf8");
|
|
5743
|
+
} catch {
|
|
5744
|
+
console.warn(`Skipped formatting ${filePath} since Prettier is not installed.`);
|
|
5745
|
+
}
|
|
5746
|
+
}
|
|
5747
|
+
async function formatFileInPlace(filePath) {
|
|
5748
|
+
try {
|
|
5749
|
+
const content = await fs2.readFile(filePath, "utf8");
|
|
5750
|
+
await formatTextAndSaveFile(filePath, content);
|
|
5751
|
+
} catch {
|
|
5752
|
+
}
|
|
5753
|
+
}
|
|
5754
|
+
|
|
5732
5755
|
// ../../src/stream-utils.ts
|
|
5733
5756
|
import { Transform } from "node:stream";
|
|
5734
5757
|
function createStreamTransform(logPrefix, logColor) {
|
|
@@ -5774,7 +5797,11 @@ async function executeFunctionCommand(logStream, positionalArguments, optionFlag
|
|
|
5774
5797
|
targetStream = subStream;
|
|
5775
5798
|
}
|
|
5776
5799
|
if (verbose) {
|
|
5777
|
-
targetStream.write(
|
|
5800
|
+
targetStream.write(
|
|
5801
|
+
source_default.bold(
|
|
5802
|
+
`Running: "${command2.name}() with Positional arguments: ${String(positionalArguments)} and Option flags: ${String(optionFlags)}"`
|
|
5803
|
+
)
|
|
5804
|
+
);
|
|
5778
5805
|
}
|
|
5779
5806
|
try {
|
|
5780
5807
|
exitCode = await command2.execute(targetStream, positionalArguments, optionFlags);
|
|
@@ -5892,9 +5919,6 @@ async function copyAndMergeInitFiles(logStream, location, configFile, configPack
|
|
|
5892
5919
|
const source = path3.join(path3.dirname(sourcePackage), "init");
|
|
5893
5920
|
const destination = path3.dirname(destinationPackage);
|
|
5894
5921
|
const hasConfigLocationOption = (location === "file" || location === "package") && configFile !== void 0 && configPackageJson !== void 0;
|
|
5895
|
-
logStream.write(`Adding initial configuration files from:
|
|
5896
|
-
"${source}" \u2192 "${destination}"
|
|
5897
|
-
`);
|
|
5898
5922
|
try {
|
|
5899
5923
|
if (hasConfigLocationOption) {
|
|
5900
5924
|
const configKey = Object.keys(configPackageJson)[0];
|
|
@@ -5906,7 +5930,8 @@ Package config key "${configKey}" \u2192 "${destination}" (Because --location is
|
|
|
5906
5930
|
`
|
|
5907
5931
|
);
|
|
5908
5932
|
const mergedPackageJson = merge(destinationPackageJson, configPackageJson);
|
|
5909
|
-
fse2.writeJSONSync(destinationPackage, mergedPackageJson, { spaces:
|
|
5933
|
+
fse2.writeJSONSync(destinationPackage, mergedPackageJson, { spaces: " " });
|
|
5934
|
+
await formatFileInPlace(destinationPackage);
|
|
5910
5935
|
} else {
|
|
5911
5936
|
const destinationPackageJson = fse2.readJsonSync(destinationPackage);
|
|
5912
5937
|
if (Object.keys(destinationPackageJson).includes(configKey)) {
|
|
@@ -5916,14 +5941,28 @@ Package config key "${configKey}" in "${destination}" (Because --location is set
|
|
|
5916
5941
|
`
|
|
5917
5942
|
);
|
|
5918
5943
|
delete destinationPackageJson[configKey];
|
|
5919
|
-
fse2.writeJSONSync(destinationPackage, destinationPackageJson, { spaces:
|
|
5944
|
+
fse2.writeJSONSync(destinationPackage, destinationPackageJson, { spaces: " " });
|
|
5945
|
+
await formatFileInPlace(destinationPackage);
|
|
5920
5946
|
}
|
|
5921
5947
|
}
|
|
5922
5948
|
}
|
|
5949
|
+
const sourceExists = await fse2.pathExists(source);
|
|
5950
|
+
if (!sourceExists) {
|
|
5951
|
+
return 0;
|
|
5952
|
+
}
|
|
5953
|
+
const sourceFiles = await fse2.readdir(source);
|
|
5954
|
+
if (sourceFiles.length === 0) {
|
|
5955
|
+
logStream.write(`Source directory "${source}" is empty.
|
|
5956
|
+
`);
|
|
5957
|
+
return 0;
|
|
5958
|
+
}
|
|
5959
|
+
logStream.write(`Adding initial configuration files from:
|
|
5960
|
+
"${source}" \u2192 "${destination}"
|
|
5961
|
+
`);
|
|
5923
5962
|
await fse2.copy(source, destination, {
|
|
5924
|
-
filter(source2, destination2) {
|
|
5925
|
-
const isFile =
|
|
5926
|
-
const destinationExists =
|
|
5963
|
+
async filter(source2, destination2) {
|
|
5964
|
+
const isFile = fs3.statSync(source2).isFile();
|
|
5965
|
+
const destinationExists = fs3.existsSync(destination2);
|
|
5927
5966
|
if (isFile) {
|
|
5928
5967
|
if (hasConfigLocationOption && location === "package" && source2.includes(configFile)) {
|
|
5929
5968
|
if (destinationExists) {
|
|
@@ -5942,25 +5981,28 @@ Package config key "${configKey}" in "${destination}" (Because --location is set
|
|
|
5942
5981
|
}
|
|
5943
5982
|
return false;
|
|
5944
5983
|
}
|
|
5945
|
-
if (destinationExists && destination2.includes(".vscode/") && path3.extname(destination2) === ".json") {
|
|
5984
|
+
if (destinationExists && (destination2.includes(".vscode/") || destination2.includes("package.json")) && path3.extname(destination2) === ".json") {
|
|
5946
5985
|
logStream.write(`Merging:
|
|
5947
5986
|
"${source2}" \u2192 "${destination2}"
|
|
5948
5987
|
`);
|
|
5949
5988
|
const sourceJson = fse2.readJSONSync(source2);
|
|
5950
5989
|
const destinationJson = fse2.readJSONSync(destination2);
|
|
5951
5990
|
const mergedJson = merge(destinationJson, sourceJson);
|
|
5952
|
-
fse2.writeJSONSync(destination2, mergedJson, { spaces:
|
|
5991
|
+
fse2.writeJSONSync(destination2, mergedJson, { spaces: " " });
|
|
5992
|
+
await formatFileInPlace(destination2);
|
|
5953
5993
|
return false;
|
|
5954
5994
|
}
|
|
5955
5995
|
if (destinationExists) {
|
|
5956
5996
|
logStream.write(`Overwriting:
|
|
5957
5997
|
"${source2}" \u2192 "${destination2}"
|
|
5958
5998
|
`);
|
|
5999
|
+
await formatFileInPlace(destination2);
|
|
5959
6000
|
return true;
|
|
5960
6001
|
}
|
|
5961
6002
|
logStream.write(`Copying:
|
|
5962
6003
|
"${source2}" \u2192 "${destination2}"
|
|
5963
6004
|
`);
|
|
6005
|
+
await formatFileInPlace(destination2);
|
|
5964
6006
|
return true;
|
|
5965
6007
|
}
|
|
5966
6008
|
return true;
|
|
@@ -6000,11 +6042,12 @@ async function buildCommands(commandDefinition2) {
|
|
|
6000
6042
|
// Command: init.locationOptionFlag ? 'init [--location]' : 'init',
|
|
6001
6043
|
describe: init.description ?? `Initialize by copying starter config files to your project root${init.locationOptionFlag ? " or to your package.json file." : "."}`,
|
|
6002
6044
|
async handler(argv) {
|
|
6045
|
+
const location = init.locationOptionFlag ? argv.location : void 0;
|
|
6003
6046
|
const copyAndMergeInitFilesCommand = {
|
|
6004
|
-
async execute(logStream2) {
|
|
6047
|
+
async execute(logStream2, _, optionFlags) {
|
|
6005
6048
|
return copyAndMergeInitFiles(
|
|
6006
6049
|
logStream2,
|
|
6007
|
-
|
|
6050
|
+
optionFlags.at(1),
|
|
6008
6051
|
init.configFile,
|
|
6009
6052
|
init.configPackageJson
|
|
6010
6053
|
);
|
|
@@ -6014,7 +6057,7 @@ async function buildCommands(commandDefinition2) {
|
|
|
6014
6057
|
const exitCode = await executeCommands(
|
|
6015
6058
|
logStream,
|
|
6016
6059
|
[],
|
|
6017
|
-
[],
|
|
6060
|
+
location === void 0 ? [] : ["--location", location],
|
|
6018
6061
|
[copyAndMergeInitFilesCommand, ...init.commands ?? []]
|
|
6019
6062
|
);
|
|
6020
6063
|
process.exit(exitCode);
|
|
@@ -6159,6 +6202,11 @@ import path4 from "node:path";
|
|
|
6159
6202
|
// src/index.ts
|
|
6160
6203
|
var sharedKnipConfig = {
|
|
6161
6204
|
entry: [
|
|
6205
|
+
// Default entry... not merging in from default Knip config?
|
|
6206
|
+
"{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!",
|
|
6207
|
+
"src/{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!",
|
|
6208
|
+
// Customized entries
|
|
6209
|
+
"src/{bin,lib,cli}/{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!",
|
|
6162
6210
|
"scripts/**/*.ts",
|
|
6163
6211
|
".remarkrc.js",
|
|
6164
6212
|
"cspell.config.js",
|
|
@@ -6166,6 +6214,15 @@ var sharedKnipConfig = {
|
|
|
6166
6214
|
"mdat.config.ts",
|
|
6167
6215
|
"prettier.config.js",
|
|
6168
6216
|
"stylelint.config.js"
|
|
6217
|
+
],
|
|
6218
|
+
ignoreDependencies: [
|
|
6219
|
+
"@kitschpatrol/cspell-config",
|
|
6220
|
+
"@kitschpatrol/eslint-config",
|
|
6221
|
+
"@kitschpatrol/knip-config",
|
|
6222
|
+
"@kitschpatrol/mdat-config",
|
|
6223
|
+
"@kitschpatrol/prettier-config",
|
|
6224
|
+
"@kitschpatrol/remark-config",
|
|
6225
|
+
"@kitschpatrol/stylelint-config"
|
|
6169
6226
|
]
|
|
6170
6227
|
};
|
|
6171
6228
|
var index_default = sharedKnipConfig;
|
|
@@ -6196,7 +6253,12 @@ var commandDefinition = {
|
|
|
6196
6253
|
{
|
|
6197
6254
|
cwdOverride: "workspace-root",
|
|
6198
6255
|
name: "knip",
|
|
6199
|
-
optionFlags: [
|
|
6256
|
+
optionFlags: [
|
|
6257
|
+
"--fix",
|
|
6258
|
+
"--allow-remove-files",
|
|
6259
|
+
"--no-config-hints",
|
|
6260
|
+
...getWorkspaceOptionFlags()
|
|
6261
|
+
]
|
|
6200
6262
|
}
|
|
6201
6263
|
],
|
|
6202
6264
|
description: `Automatically remove unused code and dependencies. ${DESCRIPTION.packageRun} ${DESCRIPTION.monorepoRun}`,
|
|
@@ -6214,7 +6276,7 @@ var commandDefinition = {
|
|
|
6214
6276
|
// Run from root, then pass --workspace IF in a monorepo and called from a subpackage
|
|
6215
6277
|
cwdOverride: "workspace-root",
|
|
6216
6278
|
name: "knip",
|
|
6217
|
-
optionFlags: ["--no-progress", ...getWorkspaceOptionFlags()]
|
|
6279
|
+
optionFlags: ["--no-progress", "--no-config-hints", ...getWorkspaceOptionFlags()]
|
|
6218
6280
|
}
|
|
6219
6281
|
// "Production" pass is not worth it?
|
|
6220
6282
|
// {
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,11 @@ import { deepmerge } from 'deepmerge-ts';
|
|
|
5
5
|
*/
|
|
6
6
|
const sharedKnipConfig = {
|
|
7
7
|
entry: [
|
|
8
|
+
// Default entry... not merging in from default Knip config?
|
|
9
|
+
'{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!',
|
|
10
|
+
'src/{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!',
|
|
11
|
+
// Customized entries
|
|
12
|
+
'src/{bin,lib,cli}/{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!',
|
|
8
13
|
'scripts/**/*.ts',
|
|
9
14
|
'.remarkrc.js',
|
|
10
15
|
'cspell.config.js',
|
|
@@ -13,6 +18,15 @@ const sharedKnipConfig = {
|
|
|
13
18
|
'prettier.config.js',
|
|
14
19
|
'stylelint.config.js',
|
|
15
20
|
],
|
|
21
|
+
ignoreDependencies: [
|
|
22
|
+
'@kitschpatrol/cspell-config',
|
|
23
|
+
'@kitschpatrol/eslint-config',
|
|
24
|
+
'@kitschpatrol/knip-config',
|
|
25
|
+
'@kitschpatrol/mdat-config',
|
|
26
|
+
'@kitschpatrol/prettier-config',
|
|
27
|
+
'@kitschpatrol/remark-config',
|
|
28
|
+
'@kitschpatrol/stylelint-config',
|
|
29
|
+
],
|
|
16
30
|
};
|
|
17
31
|
/**
|
|
18
32
|
* **\@Kitschpatrol's Shared Knip Configuration**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/knip-config",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "Knip configuration for @kitschpatrol/shared-config.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shared-config",
|
|
@@ -44,8 +44,10 @@
|
|
|
44
44
|
"cosmiconfig": "^9.0.0",
|
|
45
45
|
"deepmerge-ts": "^7.1.4",
|
|
46
46
|
"execa": "^9.5.2",
|
|
47
|
+
"find-workspaces": "^0.3.1",
|
|
47
48
|
"fs-extra": "^11.3.0",
|
|
48
|
-
"knip": "^5.43.6"
|
|
49
|
+
"knip": "^5.43.6",
|
|
50
|
+
"prettier": "^3.4.2"
|
|
49
51
|
},
|
|
50
52
|
"engines": {
|
|
51
53
|
"node": ">=22.0.0",
|