@dhzh/eslint-config 1.27.0 → 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.0";
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",
@@ -26,6 +26,22 @@ var devDependencies = {
26
26
  };
27
27
  //#endregion
28
28
  //#region src/cli/stages/update-package-json.ts
29
+ async function ensureScript(scripts, name, command) {
30
+ if (scripts[name] == null) {
31
+ scripts[name] = command;
32
+ return;
33
+ }
34
+ if (scripts[name] === command) return;
35
+ const shouldOverride = await p.confirm({
36
+ message: `Script "${name}" already exists as "${String(scripts[name])}". Replace it with "${command}"?`,
37
+ initialValue: true
38
+ });
39
+ if (p.isCancel(shouldOverride)) {
40
+ p.cancel("Operation cancelled");
41
+ throw new Error("Operation cancelled");
42
+ }
43
+ if (shouldOverride) scripts[name] = command;
44
+ }
29
45
  async function updatePackageJson() {
30
46
  const cwd = process.cwd();
31
47
  const pathPackageJSON = path.join(cwd, "package.json");
@@ -36,8 +52,8 @@ async function updatePackageJson() {
36
52
  pkg.devDependencies["@dhzh/eslint-config"] = `^${version}`;
37
53
  pkg.devDependencies.eslint ??= devDependencies.eslint;
38
54
  pkg.scripts ??= {};
39
- pkg.scripts.lint = "eslint .";
40
- pkg.scripts["lint-fix"] = "eslint --fix .";
55
+ await ensureScript(pkg.scripts, "lint", "eslint");
56
+ await ensureScript(pkg.scripts, "lint-fix", "eslint --fix .");
41
57
  await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
42
58
  p.log.success(c.green`Changes wrote to package.json`);
43
59
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dhzh/eslint-config",
3
3
  "type": "module",
4
- "version": "1.27.0",
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,259 +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.0";
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 updatePackageJson() {
37
- const cwd = node_process.default.cwd();
38
- const pathPackageJSON = node_path.default.join(cwd, "package.json");
39
- _clack_prompts.log.step(ansis.default.cyan`Bumping @dhzh/eslint-config to v${version}`);
40
- const pkgContent = await node_fs_promises.default.readFile(pathPackageJSON, "utf8");
41
- const pkg = JSON.parse(pkgContent);
42
- pkg.devDependencies ??= {};
43
- pkg.devDependencies["@dhzh/eslint-config"] = `^${version}`;
44
- pkg.devDependencies.eslint ??= devDependencies.eslint;
45
- pkg.scripts ??= {};
46
- pkg.scripts.lint = "eslint .";
47
- pkg.scripts["lint-fix"] = "eslint --fix .";
48
- await node_fs_promises.default.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2));
49
- _clack_prompts.log.success(ansis.default.green`Changes wrote to package.json`);
50
- }
51
- //#endregion
52
- //#region src/cli/constants.ts
53
- const vscodeSettingsString = `
54
- // Entry
55
- "eslint.format.enable": true,
56
- "eslint.ignoreUntitled": true,
57
- "eslint.enable": true,
58
-
59
- // Disable the default formatter, use eslint instead
60
- "prettier.enable": false,
61
-
62
- // Auto fix
63
- "editor.codeActionsOnSave": {
64
- "source.fixAll.eslint": "explicit",
65
- "source.organizeImports": "never"
66
- },
67
-
68
- // Silent the stylistic rules in you IDE, but still auto fix them
69
- // "eslint.rules.customizations": [
70
- // { "rule": "style/*", "severity": "off", "fixable": true },
71
- // { "rule": "format/*", "severity": "off", "fixable": true },
72
- // { "rule": "*-indent", "severity": "off", "fixable": true },
73
- // { "rule": "*-spacing", "severity": "off", "fixable": true },
74
- // { "rule": "*-spaces", "severity": "off", "fixable": true },
75
- // { "rule": "*-order", "severity": "off", "fixable": true },
76
- // { "rule": "*-dangle", "severity": "off", "fixable": true },
77
- // { "rule": "*-newline", "severity": "off", "fixable": true },
78
- // { "rule": "*quotes", "severity": "off", "fixable": true },
79
- // { "rule": "*semi", "severity": "off", "fixable": true }
80
- // ],
81
-
82
- // Enable eslint for all supported languages
83
- "eslint.validate": [
84
- "javascript",
85
- "javascriptreact",
86
- "typescript",
87
- "typescriptreact",
88
- "html",
89
- "json",
90
- "json5",
91
- "jsonc",
92
- "yaml",
93
- "toml",
94
- "xml",
95
- "css",
96
- "less",
97
- "scss",
98
- "pcss",
99
- "postcss",
100
- "gql",
101
- "graphql",
102
- "vue"
103
- ],
104
-
105
- // Enable eslint as the default formatter
106
- "[javascript]": {
107
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
108
- },
109
- "[javascriptreact]": {
110
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
111
- },
112
- "[typescript]": {
113
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
114
- },
115
- "[typescriptreact]": {
116
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
117
- },
118
- "[html]": {
119
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
120
- },
121
- "[json]": {
122
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
123
- },
124
- "[jsonc]": {
125
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
126
- },
127
- "[yaml]": {
128
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
129
- },
130
- "[toml]": {
131
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
132
- },
133
- "[xml]": {
134
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
135
- },
136
- "[css]": {
137
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
138
- },
139
- "[less]": {
140
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
141
- },
142
- "[scss]": {
143
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
144
- },
145
- "[pcss]": {
146
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
147
- },
148
- "[postcss]": {
149
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
150
- },
151
- "[gql]": {
152
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
153
- },
154
- "[graphql]": {
155
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
156
- },
157
- "[vue]": {
158
- "editor.defaultFormatter": "dbaeumer.vscode-eslint"
159
- }
160
- `;
161
- const eslintConfigContent = (options) => `import { defineConfig } from '@dhzh/eslint-config';
162
-
163
- export default defineConfig(${options.hasNest ? `{
164
- configs: {
165
- json: {
166
- packageJsonRequireType: false,
167
- },
168
- },
169
- }` : ""});
170
- `;
171
- const npmignoreString = `# If these files (ESLint flat config files) are not included in .npmignore,
172
- # they will be published, and importing devDependencies in published files will trigger \`n/no-unpublished-import\` errors.
173
- eslint.config.js
174
- eslint.config.mjs
175
- `;
176
- //#endregion
177
- //#region src/cli/stages/update-eslint-config.ts
178
- async function updateEslintConfig(options) {
179
- const cwd = node_process.default.cwd();
180
- const pathPackageJSON = node_path.default.join(cwd, "package.json");
181
- const pkgContent = await node_fs_promises.default.readFile(pathPackageJSON, "utf8");
182
- const configFileName = JSON.parse(pkgContent).type === "module" ? "eslint.config.js" : "eslint.config.mjs";
183
- const pathFlatConfig = node_path.default.join(cwd, configFileName);
184
- await node_fs_promises.default.writeFile(pathFlatConfig, eslintConfigContent(options));
185
- _clack_prompts.log.success(ansis.default.green`Created ${configFileName}`);
186
- }
187
- //#endregion
188
- //#region src/cli/stages/update-npmignore.ts
189
- async function updateNpmignore() {
190
- const cwd = node_process.default.cwd();
191
- const npmignoreFileName = ".npmignore";
192
- const npmignoreFilePath = node_path.default.join(cwd, npmignoreFileName);
193
- let action = "Created";
194
- try {
195
- await node_fs_promises.default.access(npmignoreFilePath);
196
- const trimmedContent = (await node_fs_promises.default.readFile(npmignoreFilePath, "utf8")).trimEnd();
197
- await node_fs_promises.default.writeFile(npmignoreFilePath, `${trimmedContent}\n${npmignoreString}`);
198
- action = "Updated";
199
- } catch {
200
- await node_fs_promises.default.writeFile(npmignoreFilePath, npmignoreString);
201
- }
202
- _clack_prompts.log.success(ansis.default.green`${action} ${npmignoreFileName}`);
203
- }
204
- //#endregion
205
- //#region src/cli/stages/update-vscode-settings.ts
206
- async function updateVscodeSettings() {
207
- const cwd = node_process.default.cwd();
208
- const dotVscodePath = node_path.default.join(cwd, ".vscode");
209
- const settingsPath = node_path.default.join(dotVscodePath, "settings.json");
210
- if (!node_fs.default.existsSync(dotVscodePath)) await node_fs_promises.default.mkdir(dotVscodePath, { recursive: true });
211
- if (node_fs.default.existsSync(settingsPath)) {
212
- let settingsContent = await node_fs_promises.default.readFile(settingsPath, "utf8");
213
- settingsContent = settingsContent.trim().replace(/\s*\}$/, "");
214
- settingsContent += settingsContent.endsWith(",") || settingsContent.endsWith("{") ? "" : ",";
215
- settingsContent += `${vscodeSettingsString}}\n`;
216
- await node_fs_promises.default.writeFile(settingsPath, settingsContent, "utf8");
217
- _clack_prompts.log.success(ansis.green`Updated .vscode/settings.json`);
218
- } else {
219
- await node_fs_promises.default.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, "utf8");
220
- _clack_prompts.log.success(ansis.green`Created .vscode/settings.json`);
221
- }
222
- }
223
- //#endregion
224
- //#region src/cli/run.ts
225
- async function run(options) {
226
- await updatePackageJson();
227
- await updateEslintConfig(options);
228
- await updateNpmignore();
229
- await updateVscodeSettings();
230
- _clack_prompts.log.success(ansis.default.green`Setup completed`);
231
- _clack_prompts.outro(`Now you can update the dependencies by run ${ansis.default.blue("pnpm i")} and run ${ansis.default.blue("eslint --fix")}\n`);
232
- }
233
- //#endregion
234
- //#region src/cli/index.ts
235
- const cli = (0, cac.cac)("@dhzh/eslint-config");
236
- cli.command("", "Run the initialization or migration").action(async () => {
237
- console.log("\n");
238
- _clack_prompts.intro(`${ansis.default.green`@dhzh/eslint-config `}${ansis.default.dim`v${version}`}`);
239
- const options = { hasNest: false };
240
- const hasNest = await _clack_prompts.confirm({
241
- message: "Is NestJS a part of the current project?",
242
- initialValue: false
243
- });
244
- if (_clack_prompts.isCancel(hasNest)) {
245
- _clack_prompts.cancel("Operation cancelled");
246
- throw new Error("Operation cancelled");
247
- } else options.hasNest = hasNest;
248
- try {
249
- await run(options);
250
- } catch (error) {
251
- _clack_prompts.log.error(ansis.default.inverse.red(" Failed to migrate "));
252
- _clack_prompts.log.error(ansis.default.red`✘ ${String(error)}`);
253
- throw error;
254
- }
255
- });
256
- cli.help();
257
- cli.version(version);
258
- cli.parse();
259
- //#endregion
@@ -1 +0,0 @@
1
- export { };