@coderwyd/eslint-config 4.2.1 → 4.3.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/dist/cli.d.ts +1 -2
- package/dist/cli.js +155 -197
- package/dist/index.d.ts +7668 -8047
- package/dist/index.js +1625 -1862
- package/package.json +39 -36
package/dist/cli.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { }
|
|
1
|
+
export { };
|
package/dist/cli.js
CHANGED
|
@@ -1,46 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import c3 from "picocolors";
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import c from "picocolors";
|
|
4
3
|
import yargs from "yargs";
|
|
5
4
|
import { hideBin } from "yargs/helpers";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import fsp from "node:fs/promises";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import parse from "parse-gitignore";
|
|
9
|
+
import prompts from "prompts";
|
|
10
|
+
import { execSync } from "node:child_process";
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// package.json
|
|
11
|
-
var version = "4.2.1";
|
|
12
|
+
//#region package.json
|
|
13
|
+
var version = "4.3.0";
|
|
12
14
|
var devDependencies = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
"@antfu/ni": "^25.0.0",
|
|
16
|
+
"@eslint-react/eslint-plugin": "^1.50.0",
|
|
17
|
+
"@eslint/config-inspector": "^1.0.2",
|
|
18
|
+
"@types/eslint-config-prettier": "^6.11.3",
|
|
19
|
+
"@types/node": "^22.15.23",
|
|
20
|
+
"@types/prompts": "^2.4.9",
|
|
21
|
+
"@types/yargs": "^17.0.33",
|
|
22
|
+
"@unocss/eslint-plugin": "^66.1.2",
|
|
23
|
+
"bumpp": "^10.1.1",
|
|
24
|
+
"eslint": "^9.27.0",
|
|
25
|
+
"eslint-plugin-react-compiler": "19.0.0-beta-ebf51a3-20250411",
|
|
26
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
27
|
+
"eslint-plugin-react-refresh": "^0.4.20",
|
|
28
|
+
"eslint-plugin-svelte": "^3.9.0",
|
|
29
|
+
"eslint-plugin-tailwindcss": "^3.18.0",
|
|
30
|
+
"jiti": "^2.4.2",
|
|
31
|
+
"nano-staged": "^0.8.0",
|
|
32
|
+
"simple-git-hooks": "^2.13.0",
|
|
33
|
+
"svelte": "^5.33.4",
|
|
34
|
+
"svelte-eslint-parser": "^1.2.0",
|
|
35
|
+
"tsdown": "0.12.3",
|
|
36
|
+
"typescript": "^5.8.3"
|
|
35
37
|
};
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/cli/constants.ts
|
|
41
|
+
const ARROW = c.cyan("→");
|
|
42
|
+
const CHECK = c.green("✔");
|
|
43
|
+
const CROSS = c.red("✘");
|
|
44
|
+
const WARN = c.yellow("ℹ");
|
|
45
|
+
const eslintVersion = devDependencies.eslint;
|
|
46
|
+
const vscodeSettingsString = `
|
|
44
47
|
"editor.formatOnSave": true,
|
|
45
48
|
|
|
46
49
|
// Auto fix
|
|
@@ -50,178 +53,133 @@ var vscodeSettingsString = `
|
|
|
50
53
|
},
|
|
51
54
|
`;
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
import fsp from "node:fs/promises";
|
|
56
|
-
import path from "node:path";
|
|
57
|
-
import process from "node:process";
|
|
58
|
-
import parse from "parse-gitignore";
|
|
59
|
-
import c2 from "picocolors";
|
|
60
|
-
import prompts from "prompts";
|
|
61
|
-
|
|
62
|
-
// src/cli/utils.ts
|
|
63
|
-
import { execSync } from "node:child_process";
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/cli/utils.ts
|
|
64
58
|
function isGitClean() {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
try {
|
|
60
|
+
execSync("git diff-index --quiet HEAD --");
|
|
61
|
+
return true;
|
|
62
|
+
} catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
71
65
|
}
|
|
72
66
|
|
|
73
|
-
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/cli/run.ts
|
|
74
69
|
async function run(options = {}) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
eslintIgnores.push(...glob.patterns);
|
|
115
|
-
} else if (glob.type === "unignore") {
|
|
116
|
-
eslintIgnores.push(
|
|
117
|
-
...glob.patterns.map((pattern) => `!${pattern}`)
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
let eslintConfigContent = "";
|
|
123
|
-
const coderwydConfig = `${eslintIgnores.length > 0 ? `ignores: ${JSON.stringify(eslintIgnores)}` : ""}`;
|
|
124
|
-
if (pkg.type === "module") {
|
|
125
|
-
eslintConfigContent = `
|
|
70
|
+
const SKIP_PROMPT = !!process.env.SKIP_PROMPT || options.yes;
|
|
71
|
+
const SKIP_GIT_CHECK = !!process.env.SKIP_GIT_CHECK;
|
|
72
|
+
const cwd = process.cwd();
|
|
73
|
+
const pathFlatConfig = path.join(cwd, "eslint.config.js");
|
|
74
|
+
const pathPackageJSON = path.join(cwd, "package.json");
|
|
75
|
+
const pathESLintIngore = path.join(cwd, ".eslintignore");
|
|
76
|
+
if (fs.existsSync(pathFlatConfig)) {
|
|
77
|
+
console.log(c.yellow(`${WARN} eslint.config.js already exists, migration wizard exited.`));
|
|
78
|
+
return process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
if (!SKIP_GIT_CHECK && !isGitClean()) {
|
|
81
|
+
const { confirmed } = await prompts({
|
|
82
|
+
initial: false,
|
|
83
|
+
message: "There are uncommitted changes in the current repository, are you sure to continue?",
|
|
84
|
+
name: "confirmed",
|
|
85
|
+
type: "confirm"
|
|
86
|
+
});
|
|
87
|
+
if (!confirmed) return process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
console.log(c.cyan(`${ARROW} bumping @coderwyd/eslint-config to v${version}`));
|
|
90
|
+
const pkgContent = await fsp.readFile(pathPackageJSON, "utf-8");
|
|
91
|
+
const pkg = JSON.parse(pkgContent);
|
|
92
|
+
pkg.devDependencies ??= {};
|
|
93
|
+
pkg.devDependencies["@coderwyd/eslint-config"] = `^${version}`;
|
|
94
|
+
if (!pkg.devDependencies.eslint) pkg.devDependencies.eslint = eslintVersion;
|
|
95
|
+
await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
96
|
+
console.log(c.green(`${CHECK} changes wrote to package.json`));
|
|
97
|
+
const eslintIgnores = [];
|
|
98
|
+
if (fs.existsSync(pathESLintIngore)) {
|
|
99
|
+
console.log(c.cyan(`${ARROW} migrating existing .eslintignore`));
|
|
100
|
+
const content = await fsp.readFile(pathESLintIngore, "utf-8");
|
|
101
|
+
const parsed = parse(content);
|
|
102
|
+
const globs = parsed.globs();
|
|
103
|
+
for (const glob of globs) if (glob.type === "ignore") eslintIgnores.push(...glob.patterns);
|
|
104
|
+
else if (glob.type === "unignore") eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
|
|
105
|
+
}
|
|
106
|
+
let eslintConfigContent = "";
|
|
107
|
+
const coderwydConfig = `${eslintIgnores.length > 0 ? `ignores: ${JSON.stringify(eslintIgnores)}` : ""}`;
|
|
108
|
+
if (pkg.type === "module") eslintConfigContent = `
|
|
126
109
|
import { defineConfig } from '@coderwyd/eslint-config'
|
|
127
110
|
|
|
128
|
-
export default defineConfig({
|
|
129
|
-
${coderwydConfig}
|
|
130
|
-
})
|
|
111
|
+
export default defineConfig({\n${coderwydConfig}\n})
|
|
131
112
|
`.trimStart();
|
|
132
|
-
|
|
133
|
-
eslintConfigContent = `
|
|
113
|
+
else eslintConfigContent = `
|
|
134
114
|
const { defineConfig } = require('@coderwyd/eslint-config')
|
|
135
115
|
|
|
136
|
-
module.exports = defineConfig({
|
|
137
|
-
${coderwydConfig}
|
|
138
|
-
})
|
|
116
|
+
module.exports = defineConfig({\n${coderwydConfig}\n})
|
|
139
117
|
`.trimStart();
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
`, "utf-8");
|
|
184
|
-
console.log(c2.green(`${CHECK} created .vscode/settings.json`));
|
|
185
|
-
} else {
|
|
186
|
-
let settingsContent = await fsp.readFile(settingsPath, "utf8");
|
|
187
|
-
settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
|
|
188
|
-
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
189
|
-
settingsContent += `${vscodeSettingsString}}
|
|
190
|
-
`;
|
|
191
|
-
await fsp.writeFile(settingsPath, settingsContent, "utf-8");
|
|
192
|
-
console.log(c2.green(`${CHECK} updated .vscode/settings.json`));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
console.log(c2.green(`${CHECK} migration completed`));
|
|
196
|
-
console.log(
|
|
197
|
-
`Now you can update the dependencies and run ${c2.blue("eslint . --fix")}
|
|
198
|
-
`
|
|
199
|
-
);
|
|
118
|
+
await fsp.writeFile(pathFlatConfig, eslintConfigContent);
|
|
119
|
+
console.log(c.green(`${CHECK} created eslint.config.js`));
|
|
120
|
+
const files = fs.readdirSync(cwd);
|
|
121
|
+
const legacyConfig = [];
|
|
122
|
+
files.forEach((file) => {
|
|
123
|
+
if (/eslint|prettier/.test(file) && !/eslint.config./.test(file)) legacyConfig.push(file);
|
|
124
|
+
});
|
|
125
|
+
if (legacyConfig.length > 0) {
|
|
126
|
+
console.log(`${WARN} you can now remove those files manually:`);
|
|
127
|
+
console.log(` ${c.dim(legacyConfig.join(", "))}`);
|
|
128
|
+
}
|
|
129
|
+
let promptResult = { updateVscodeSettings: true };
|
|
130
|
+
if (!SKIP_PROMPT) try {
|
|
131
|
+
promptResult = await prompts({
|
|
132
|
+
initial: true,
|
|
133
|
+
message: "Update .vscode/settings.json for better VS Code experience?",
|
|
134
|
+
name: "updateVscodeSettings",
|
|
135
|
+
type: "confirm"
|
|
136
|
+
}, { onCancel: () => {
|
|
137
|
+
throw new Error(`Cancelled`);
|
|
138
|
+
} });
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.log(error.message);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (promptResult?.updateVscodeSettings ?? true) {
|
|
144
|
+
const dotVscodePath = path.join(cwd, ".vscode");
|
|
145
|
+
const settingsPath = path.join(dotVscodePath, "settings.json");
|
|
146
|
+
if (!fs.existsSync(dotVscodePath)) await fsp.mkdir(dotVscodePath, { recursive: true });
|
|
147
|
+
if (!fs.existsSync(settingsPath)) {
|
|
148
|
+
await fsp.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf-8");
|
|
149
|
+
console.log(c.green(`${CHECK} created .vscode/settings.json`));
|
|
150
|
+
} else {
|
|
151
|
+
let settingsContent = await fsp.readFile(settingsPath, "utf8");
|
|
152
|
+
settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
|
|
153
|
+
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
154
|
+
settingsContent += `${vscodeSettingsString}}\n`;
|
|
155
|
+
await fsp.writeFile(settingsPath, settingsContent, "utf-8");
|
|
156
|
+
console.log(c.green(`${CHECK} updated .vscode/settings.json`));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
console.log(c.green(`${CHECK} migration completed`));
|
|
160
|
+
console.log(`Now you can update the dependencies and run ${c.blue("eslint . --fix")}\n`);
|
|
200
161
|
}
|
|
201
162
|
|
|
202
|
-
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/cli/index.ts
|
|
203
165
|
function header() {
|
|
204
|
-
|
|
205
|
-
${c3.green(`@coderwyd/eslint-config `)}${c3.dim(`v${version}`)}`);
|
|
166
|
+
console.log(`\n${c.green(`@coderwyd/eslint-config `)}${c.dim(`v${version}`)}`);
|
|
206
167
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
console.error(c3.red(`${CROSS} ${String(error)}`));
|
|
223
|
-
process2.exit(1);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
).showHelpOnFail(false).alias("h", "help").version("version", version).alias("v", "version");
|
|
168
|
+
const instance = yargs(hideBin(process.argv)).scriptName("@coderwyd/eslint-config").usage("").command("*", "Run the initialization or migration", (args) => args.option("yes", {
|
|
169
|
+
alias: "y",
|
|
170
|
+
description: "Skip prompts and use default values",
|
|
171
|
+
type: "boolean"
|
|
172
|
+
}).help(), async (args) => {
|
|
173
|
+
header();
|
|
174
|
+
console.log();
|
|
175
|
+
try {
|
|
176
|
+
await run(args);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
console.error(c.inverse(c.red(" Failed to migrate ")));
|
|
179
|
+
console.error(c.red(`${CROSS} ${String(error)}`));
|
|
180
|
+
process.exit(1);
|
|
181
|
+
}
|
|
182
|
+
}).showHelpOnFail(false).alias("h", "help").version("version", version).alias("v", "version");
|
|
227
183
|
instance.help().argv;
|
|
184
|
+
|
|
185
|
+
//#endregion
|