@antfu/eslint-config 7.7.0 → 7.7.3
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.mjs +20 -30
- package/dist/index.d.mts +1000 -1975
- package/dist/index.mjs +118 -150
- package/dist/{lib-B1Rme4qD.mjs → lib-D3Kr7UIJ.mjs} +559 -850
- package/package.json +31 -19
package/dist/cli.mjs
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
|
-
import
|
|
3
|
-
import fs from "node:fs";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import fs$1 from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import * as p from "@clack/prompts";
|
|
6
6
|
import c, { green } from "ansis";
|
|
7
7
|
import { cac } from "cac";
|
|
8
8
|
import parse from "parse-gitignore";
|
|
9
9
|
import { execSync } from "node:child_process";
|
|
10
|
-
|
|
11
10
|
//#region package.json
|
|
12
|
-
var version = "7.7.
|
|
13
|
-
|
|
11
|
+
var version = "7.7.3";
|
|
14
12
|
//#endregion
|
|
15
13
|
//#region src/cli/constants.ts
|
|
16
14
|
const vscodeSettingsString = `
|
|
@@ -116,7 +114,6 @@ const dependenciesMap = {
|
|
|
116
114
|
unocss: ["@unocss/eslint-plugin"],
|
|
117
115
|
vue: []
|
|
118
116
|
};
|
|
119
|
-
|
|
120
117
|
//#endregion
|
|
121
118
|
//#region src/cli/utils.ts
|
|
122
119
|
function isGitClean() {
|
|
@@ -136,7 +133,6 @@ ${mainConfig}
|
|
|
136
133
|
}${additionalConfigs?.map((config) => `,{\n${config}\n}`)})
|
|
137
134
|
`.trimStart();
|
|
138
135
|
}
|
|
139
|
-
|
|
140
136
|
//#endregion
|
|
141
137
|
//#region src/cli/stages/update-eslint-files.ts
|
|
142
138
|
const ESLINT_OR_PRETTIER = /eslint|prettier/;
|
|
@@ -145,13 +141,13 @@ async function updateEslintFiles(result) {
|
|
|
145
141
|
const cwd = process.cwd();
|
|
146
142
|
const pathESLintIgnore = path.join(cwd, ".eslintignore");
|
|
147
143
|
const pathPackageJSON = path.join(cwd, "package.json");
|
|
148
|
-
const pkgContent = await
|
|
144
|
+
const pkgContent = await fs.readFile(pathPackageJSON, "utf-8");
|
|
149
145
|
const configFileName = JSON.parse(pkgContent).type === "module" ? "eslint.config.js" : "eslint.config.mjs";
|
|
150
146
|
const pathFlatConfig = path.join(cwd, configFileName);
|
|
151
147
|
const eslintIgnores = [];
|
|
152
|
-
if (fs.existsSync(pathESLintIgnore)) {
|
|
148
|
+
if (fs$1.existsSync(pathESLintIgnore)) {
|
|
153
149
|
p.log.step(c.cyan`Migrating existing .eslintignore`);
|
|
154
|
-
const globs = parse(await
|
|
150
|
+
const globs = parse(await fs.readFile(pathESLintIgnore, "utf-8")).globs();
|
|
155
151
|
for (const glob of globs) if (glob.type === "ignore") eslintIgnores.push(...glob.patterns);
|
|
156
152
|
else if (glob.type === "unignore") eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
|
|
157
153
|
}
|
|
@@ -161,42 +157,40 @@ async function updateEslintFiles(result) {
|
|
|
161
157
|
if (result.extra.includes("unocss")) configLines.push(`unocss: true,`);
|
|
162
158
|
for (const framework of result.frameworks) configLines.push(`${framework}: true,`);
|
|
163
159
|
const eslintConfigContent = getEslintConfigContent(configLines.map((i) => ` ${i}`).join("\n"), []);
|
|
164
|
-
await
|
|
160
|
+
await fs.writeFile(pathFlatConfig, eslintConfigContent);
|
|
165
161
|
p.log.success(c.green`Created ${configFileName}`);
|
|
166
|
-
const files = fs.readdirSync(cwd);
|
|
162
|
+
const files = fs$1.readdirSync(cwd);
|
|
167
163
|
const legacyConfig = [];
|
|
168
164
|
files.forEach((file) => {
|
|
169
165
|
if (ESLINT_OR_PRETTIER.test(file) && !ESLINT_CONFIG.test(file)) legacyConfig.push(file);
|
|
170
166
|
});
|
|
171
167
|
if (legacyConfig.length) p.note(c.dim(legacyConfig.join(", ")), "You can now remove those files manually");
|
|
172
168
|
}
|
|
173
|
-
|
|
174
169
|
//#endregion
|
|
175
170
|
//#region src/cli/constants-generated.ts
|
|
176
171
|
const versionsMap = {
|
|
177
172
|
"@eslint-react/eslint-plugin": "^2.13.0",
|
|
178
173
|
"@next/eslint-plugin-next": "^16.1.6",
|
|
179
|
-
"@unocss/eslint-plugin": "^66.6.
|
|
174
|
+
"@unocss/eslint-plugin": "^66.6.6",
|
|
180
175
|
"astro-eslint-parser": "^1.3.0",
|
|
181
|
-
"eslint": "^10.0.
|
|
176
|
+
"eslint": "^10.0.3",
|
|
182
177
|
"eslint-plugin-astro": "^1.6.0",
|
|
183
178
|
"eslint-plugin-format": "^2.0.1",
|
|
184
179
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
185
180
|
"eslint-plugin-react-refresh": "^0.5.2",
|
|
186
181
|
"eslint-plugin-solid": "^0.14.5",
|
|
187
|
-
"eslint-plugin-svelte": "^3.15.
|
|
182
|
+
"eslint-plugin-svelte": "^3.15.2",
|
|
188
183
|
"prettier-plugin-astro": "^0.14.1",
|
|
189
184
|
"prettier-plugin-slidev": "^1.0.5",
|
|
190
185
|
"svelte-eslint-parser": "^1.6.0"
|
|
191
186
|
};
|
|
192
|
-
|
|
193
187
|
//#endregion
|
|
194
188
|
//#region src/cli/stages/update-package-json.ts
|
|
195
189
|
async function updatePackageJson(result) {
|
|
196
190
|
const cwd = process.cwd();
|
|
197
191
|
const pathPackageJSON = path.join(cwd, "package.json");
|
|
198
192
|
p.log.step(c.cyan`Bumping @antfu/eslint-config to v${version}`);
|
|
199
|
-
const pkgContent = await
|
|
193
|
+
const pkgContent = await fs.readFile(pathPackageJSON, "utf-8");
|
|
200
194
|
const pkg = JSON.parse(pkgContent);
|
|
201
195
|
pkg.devDependencies ??= {};
|
|
202
196
|
pkg.devDependencies["@antfu/eslint-config"] = `^${version}`;
|
|
@@ -227,10 +221,9 @@ async function updatePackageJson(result) {
|
|
|
227
221
|
});
|
|
228
222
|
}
|
|
229
223
|
if (addedPackages.length) p.note(c.dim(addedPackages.join(", ")), "Added packages");
|
|
230
|
-
await
|
|
224
|
+
await fs.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
|
|
231
225
|
p.log.success(c.green`Changes wrote to package.json`);
|
|
232
226
|
}
|
|
233
|
-
|
|
234
227
|
//#endregion
|
|
235
228
|
//#region src/cli/stages/update-vscode-settings.ts
|
|
236
229
|
const LAST_LINE_PATTERN = /\s*\}$/;
|
|
@@ -239,27 +232,26 @@ async function updateVscodeSettings(result) {
|
|
|
239
232
|
if (!result.updateVscodeSettings) return;
|
|
240
233
|
const dotVscodePath = path.join(cwd, ".vscode");
|
|
241
234
|
const settingsPath = path.join(dotVscodePath, "settings.json");
|
|
242
|
-
if (!fs.existsSync(dotVscodePath)) await
|
|
243
|
-
if (!fs.existsSync(settingsPath)) {
|
|
244
|
-
await
|
|
235
|
+
if (!fs$1.existsSync(dotVscodePath)) await fs.mkdir(dotVscodePath, { recursive: true });
|
|
236
|
+
if (!fs$1.existsSync(settingsPath)) {
|
|
237
|
+
await fs.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf-8");
|
|
245
238
|
p.log.success(green`Created .vscode/settings.json`);
|
|
246
239
|
} else {
|
|
247
|
-
let settingsContent = await
|
|
240
|
+
let settingsContent = await fs.readFile(settingsPath, "utf8");
|
|
248
241
|
settingsContent = settingsContent.trim().replace(LAST_LINE_PATTERN, "");
|
|
249
242
|
settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
|
|
250
243
|
settingsContent += `${vscodeSettingsString}}\n`;
|
|
251
|
-
await
|
|
244
|
+
await fs.writeFile(settingsPath, settingsContent, "utf-8");
|
|
252
245
|
p.log.success(green`Updated .vscode/settings.json`);
|
|
253
246
|
}
|
|
254
247
|
}
|
|
255
|
-
|
|
256
248
|
//#endregion
|
|
257
249
|
//#region src/cli/run.ts
|
|
258
250
|
async function run(options = {}) {
|
|
259
251
|
const argSkipPrompt = !!process.env.SKIP_PROMPT || options.yes;
|
|
260
252
|
const argTemplate = options.frameworks?.map((m) => m?.trim()).filter(Boolean);
|
|
261
253
|
const argExtra = options.extra?.map((m) => m?.trim()).filter(Boolean);
|
|
262
|
-
if (fs.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
|
|
254
|
+
if (fs$1.existsSync(path.join(process.cwd(), "eslint.config.js"))) {
|
|
263
255
|
p.log.warn(c.yellow`eslint.config.js already exists, migration wizard exited.`);
|
|
264
256
|
return process.exit(1);
|
|
265
257
|
}
|
|
@@ -317,7 +309,6 @@ async function run(options = {}) {
|
|
|
317
309
|
p.log.success(c.green`Setup completed`);
|
|
318
310
|
p.outro(`Now you can update the dependencies by run ${c.blue("pnpm install")} and run ${c.blue("eslint --fix")}\n`);
|
|
319
311
|
}
|
|
320
|
-
|
|
321
312
|
//#endregion
|
|
322
313
|
//#region src/cli/index.ts
|
|
323
314
|
function header() {
|
|
@@ -338,6 +329,5 @@ cli.command("", "Run the initialization or migration").option("--yes, -y", "Skip
|
|
|
338
329
|
cli.help();
|
|
339
330
|
cli.version(version);
|
|
340
331
|
cli.parse();
|
|
341
|
-
|
|
342
332
|
//#endregion
|
|
343
|
-
export {
|
|
333
|
+
export {};
|