@dhzh/eslint-config 1.27.1 → 2.0.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/README.md CHANGED
@@ -29,6 +29,7 @@ I use ESLint to format and lint my code:
29
29
  ## Usage
30
30
 
31
31
  > Requires ESLint v9.5.0+
32
+ > This package is ESM-only.
32
33
 
33
34
  ### Starter Wizard
34
35
 
package/bin/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import '../dist/cli/index.js';
2
+ import '../dist/cli/index.mjs';
@@ -6,7 +6,7 @@ import fsp from "node:fs/promises";
6
6
  import path from "node:path";
7
7
  import fs from "node:fs";
8
8
  //#region package.json
9
- var version = "1.27.1";
9
+ var version = "2.0.0";
10
10
  var devDependencies = {
11
11
  "@eslint/config-inspector": "^2.0.0",
12
12
  "@prettier/plugin-xml": "^3.4.2",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dhzh/eslint-config",
3
3
  "type": "module",
4
- "version": "1.27.1",
4
+ "version": "2.0.0",
5
5
  "description": "tinywaves's ESLint config",
6
6
  "author": {
7
7
  "name": "Lyle Zheng",
@@ -23,12 +23,13 @@
23
23
  "sideEffects": false,
24
24
  "exports": {
25
25
  ".": {
26
- "import": "./dist/index.js",
27
- "require": "./dist/index.cjs"
26
+ "types": "./dist/index.d.mts",
27
+ "import": "./dist/index.mjs"
28
28
  }
29
29
  },
30
- "main": "./dist/index.js",
31
- "types": "./dist/index.d.ts",
30
+ "main": "./dist/index.mjs",
31
+ "module": "./dist/index.mjs",
32
+ "types": "./dist/index.d.mts",
32
33
  "bin": "./bin/index.js",
33
34
  "files": [
34
35
  "bin",
@@ -1,28 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
- //#endregion
23
- Object.defineProperty(exports, "__toESM", {
24
- enumerable: true,
25
- get: function() {
26
- return __toESM;
27
- }
28
- });
@@ -1,275 +0,0 @@
1
- const require_chunk = require("../chunk-CKQMccvm.cjs");
2
- let node_process = require("node:process");
3
- node_process = require_chunk.__toESM(node_process, 1);
4
- let _clack_prompts = require("@clack/prompts");
5
- _clack_prompts = require_chunk.__toESM(_clack_prompts, 1);
6
- let ansis = require("ansis");
7
- ansis = require_chunk.__toESM(ansis, 1);
8
- let cac = require("cac");
9
- let node_fs_promises = require("node:fs/promises");
10
- node_fs_promises = require_chunk.__toESM(node_fs_promises, 1);
11
- let node_path = require("node:path");
12
- node_path = require_chunk.__toESM(node_path, 1);
13
- let node_fs = require("node:fs");
14
- node_fs = require_chunk.__toESM(node_fs, 1);
15
- //#region package.json
16
- var version = "1.27.1";
17
- var devDependencies = {
18
- "@eslint/config-inspector": "^2.0.0",
19
- "@prettier/plugin-xml": "^3.4.2",
20
- "@types/eslint-plugin-tailwindcss": "^3.17.0",
21
- "@types/node": "^24.12.2",
22
- "@typescript-eslint/types": "^8.59.0",
23
- "bumpp": "^11.0.1",
24
- "bundle-require": "^5.1.0",
25
- "eslint": "^10.2.1",
26
- "eslint-typegen": "^2.3.1",
27
- "lint-staged": "^16.4.0",
28
- "simple-git-hooks": "^2.13.1",
29
- "tailwindcss": "^4.2.4",
30
- "tsdown": "^0.21.10",
31
- "tsx": "^4.21.0",
32
- "typescript": "^6.0.3"
33
- };
34
- //#endregion
35
- //#region src/cli/stages/update-package-json.ts
36
- async function ensureScript(scripts, name, command) {
37
- if (scripts[name] == null) {
38
- scripts[name] = command;
39
- return;
40
- }
41
- if (scripts[name] === command) return;
42
- const shouldOverride = await _clack_prompts.confirm({
43
- message: `Script "${name}" already exists as "${String(scripts[name])}". Replace it with "${command}"?`,
44
- initialValue: true
45
- });
46
- if (_clack_prompts.isCancel(shouldOverride)) {
47
- _clack_prompts.cancel("Operation cancelled");
48
- throw new Error("Operation cancelled");
49
- }
50
- if (shouldOverride) scripts[name] = command;
51
- }
52
- async function updatePackageJson() {
53
- const cwd = node_process.default.cwd();
54
- const pathPackageJSON = node_path.default.join(cwd, "package.json");
55
- _clack_prompts.log.step(ansis.default.cyan`Bumping @dhzh/eslint-config to v${version}`);
56
- const pkgContent = await node_fs_promises.default.readFile(pathPackageJSON, "utf8");
57
- const pkg = JSON.parse(pkgContent);
58
- pkg.devDependencies ??= {};
59
- pkg.devDependencies["@dhzh/eslint-config"] = `^${version}`;
60
- pkg.devDependencies.eslint ??= devDependencies.eslint;
61
- pkg.scripts ??= {};
62
- await ensureScript(pkg.scripts, "lint", "eslint");
63
- await ensureScript(pkg.scripts, "lint-fix", "eslint --fix .");
64
- await node_fs_promises.default.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
65
- _clack_prompts.log.success(ansis.default.green`Changes wrote to package.json`);
66
- }
67
- //#endregion
68
- //#region src/cli/constants.ts
69
- const vscodeSettingsString = `
70
- // Entry
71
- "eslint.format.enable": true,
72
- "eslint.ignoreUntitled": true,
73
- "eslint.enable": true,
74
-
75
- // Disable the default formatter, use eslint instead
76
- "prettier.enable": false,
77
-
78
- // Auto fix
79
- "editor.codeActionsOnSave": {
80
- "source.fixAll.eslint": "explicit",
81
- "source.organizeImports": "never"
82
- },
83
-
84
- // Silent the stylistic rules in you IDE, but still auto fix them
85
- // "eslint.rules.customizations": [
86
- // { "rule": "style/*", "severity": "off", "fixable": true },
87
- // { "rule": "format/*", "severity": "off", "fixable": true },
88
- // { "rule": "*-indent", "severity": "off", "fixable": true },
89
- // { "rule": "*-spacing", "severity": "off", "fixable": true },
90
- // { "rule": "*-spaces", "severity": "off", "fixable": true },
91
- // { "rule": "*-order", "severity": "off", "fixable": true },
92
- // { "rule": "*-dangle", "severity": "off", "fixable": true },
93
- // { "rule": "*-newline", "severity": "off", "fixable": true },
94
- // { "rule": "*quotes", "severity": "off", "fixable": true },
95
- // { "rule": "*semi", "severity": "off", "fixable": true }
96
- // ],
97
-
98
- // Enable eslint for all supported languages
99
- "eslint.validate": [
100
- "javascript",
101
- "javascriptreact",
102
- "typescript",
103
- "typescriptreact",
104
- "html",
105
- "json",
106
- "json5",
107
- "jsonc",
108
- "yaml",
109
- "toml",
110
- "xml",
111
- "css",
112
- "less",
113
- "scss",
114
- "pcss",
115
- "postcss",
116
- "gql",
117
- "graphql",
118
- "vue"
119
- ],
120
-
121
- // Enable eslint as the default formatter
122
- "[javascript]": {
123
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
124
- },
125
- "[javascriptreact]": {
126
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
127
- },
128
- "[typescript]": {
129
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
130
- },
131
- "[typescriptreact]": {
132
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
133
- },
134
- "[html]": {
135
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
136
- },
137
- "[json]": {
138
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
139
- },
140
- "[jsonc]": {
141
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
142
- },
143
- "[yaml]": {
144
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
145
- },
146
- "[toml]": {
147
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
148
- },
149
- "[xml]": {
150
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
151
- },
152
- "[css]": {
153
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
154
- },
155
- "[less]": {
156
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
157
- },
158
- "[scss]": {
159
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
160
- },
161
- "[pcss]": {
162
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
163
- },
164
- "[postcss]": {
165
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
166
- },
167
- "[gql]": {
168
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
169
- },
170
- "[graphql]": {
171
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
172
- },
173
- "[vue]": {
174
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
175
- }
176
- `;
177
- const eslintConfigContent = (options) => `import { defineConfig } from '@dhzh/eslint-config';
178
-
179
- export default defineConfig(${options.hasNest ? `{
180
- configs: {
181
- json: {
182
- packageJsonRequireType: false,
183
- },
184
- },
185
- }` : ""});
186
- `;
187
- const npmignoreString = `# If these files (ESLint flat config files) are not included in .npmignore,
188
- # they will be published, and importing devDependencies in published files will trigger \`n/no-unpublished-import\` errors.
189
- eslint.config.js
190
- eslint.config.mjs
191
- `;
192
- //#endregion
193
- //#region src/cli/stages/update-eslint-config.ts
194
- async function updateEslintConfig(options) {
195
- const cwd = node_process.default.cwd();
196
- const pathPackageJSON = node_path.default.join(cwd, "package.json");
197
- const pkgContent = await node_fs_promises.default.readFile(pathPackageJSON, "utf8");
198
- const configFileName = JSON.parse(pkgContent).type === "module" ? "eslint.config.js" : "eslint.config.mjs";
199
- const pathFlatConfig = node_path.default.join(cwd, configFileName);
200
- await node_fs_promises.default.writeFile(pathFlatConfig, eslintConfigContent(options));
201
- _clack_prompts.log.success(ansis.default.green`Created ${configFileName}`);
202
- }
203
- //#endregion
204
- //#region src/cli/stages/update-npmignore.ts
205
- async function updateNpmignore() {
206
- const cwd = node_process.default.cwd();
207
- const npmignoreFileName = ".npmignore";
208
- const npmignoreFilePath = node_path.default.join(cwd, npmignoreFileName);
209
- let action = "Created";
210
- try {
211
- await node_fs_promises.default.access(npmignoreFilePath);
212
- const trimmedContent = (await node_fs_promises.default.readFile(npmignoreFilePath, "utf8")).trimEnd();
213
- await node_fs_promises.default.writeFile(npmignoreFilePath, `${trimmedContent}\n${npmignoreString}`);
214
- action = "Updated";
215
- } catch {
216
- await node_fs_promises.default.writeFile(npmignoreFilePath, npmignoreString);
217
- }
218
- _clack_prompts.log.success(ansis.default.green`${action} ${npmignoreFileName}`);
219
- }
220
- //#endregion
221
- //#region src/cli/stages/update-vscode-settings.ts
222
- async function updateVscodeSettings() {
223
- const cwd = node_process.default.cwd();
224
- const dotVscodePath = node_path.default.join(cwd, ".vscode");
225
- const settingsPath = node_path.default.join(dotVscodePath, "settings.json");
226
- if (!node_fs.default.existsSync(dotVscodePath)) await node_fs_promises.default.mkdir(dotVscodePath, { recursive: true });
227
- if (node_fs.default.existsSync(settingsPath)) {
228
- let settingsContent = await node_fs_promises.default.readFile(settingsPath, "utf8");
229
- settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
230
- settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
231
- settingsContent += `${vscodeSettingsString}}\n`;
232
- await node_fs_promises.default.writeFile(settingsPath, settingsContent, "utf8");
233
- _clack_prompts.log.success(ansis.green`Updated .vscode/settings.json`);
234
- } else {
235
- await node_fs_promises.default.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf8");
236
- _clack_prompts.log.success(ansis.green`Created .vscode/settings.json`);
237
- }
238
- }
239
- //#endregion
240
- //#region src/cli/run.ts
241
- async function run(options) {
242
- await updatePackageJson();
243
- await updateEslintConfig(options);
244
- await updateNpmignore();
245
- await updateVscodeSettings();
246
- _clack_prompts.log.success(ansis.default.green`Setup completed`);
247
- _clack_prompts.outro(`Now you can update the dependencies by run ${ansis.default.blue("pnpm i")} and run ${ansis.default.blue("eslint --fix")}\n`);
248
- }
249
- //#endregion
250
- //#region src/cli/index.ts
251
- const cli = (0, cac.cac)("@dhzh/eslint-config");
252
- cli.command("", "Run the initialization or migration").action(async () => {
253
- console.log("\n");
254
- _clack_prompts.intro(`${ansis.default.green`@dhzh/eslint-config `}${ansis.default.dim`v${version}`}`);
255
- const options = { hasNest: false };
256
- const hasNest = await _clack_prompts.confirm({
257
- message: "Is NestJS a part of the current project?",
258
- initialValue: false
259
- });
260
- if (_clack_prompts.isCancel(hasNest)) {
261
- _clack_prompts.cancel("Operation cancelled");
262
- throw new Error("Operation cancelled");
263
- } else options.hasNest = hasNest;
264
- try {
265
- await run(options);
266
- } catch (error) {
267
- _clack_prompts.log.error(ansis.default.inverse.red(" Failed to migrate "));
268
- _clack_prompts.log.error(ansis.default.red`✘ ${String(error)}`);
269
- throw error;
270
- }
271
- });
272
- cli.help();
273
- cli.version(version);
274
- cli.parse();
275
- //#endregion
@@ -1 +0,0 @@
1
- export { };