@minimalstuff/tooling 0.4.0 → 0.6.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
@@ -43,7 +43,7 @@ Options:
43
43
  | --------------- | --------- | ------- | --------------------------------------- |
44
44
  | `react` | `boolean` | `false` | Enable React-specific oxlint plugins |
45
45
  | `adonisjs` | `boolean` | `false` | Enable AdonisJS-specific rules |
46
- | `perfectionist` | `boolean` | `false` | Enable import sorting via perfectionist |
46
+ | `perfectionist` | `boolean` | `true` | Enable import sorting via perfectionist |
47
47
 
48
48
  ```ts
49
49
  import {
@@ -1,5 +1,5 @@
1
1
  //#region src/cli/index.d.ts
2
- type ConfigTool = 'editorconfig' | 'oxc';
2
+ type ConfigTool = 'editorconfig' | 'oxc' | 'vscode';
3
3
  declare const DEFAULT_SELECTED_TOOLS: ConfigTool[];
4
4
  interface PromptResult {
5
5
  tools: ConfigTool[];
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import color from "picocolors";
3
+ import { existsSync } from "node:fs";
4
+ import { dirname, join } from "node:path";
3
5
  import * as p from "@clack/prompts";
4
6
  import { cancel, confirm, intro, isCancel, log, multiselect } from "@clack/prompts";
5
- import { join } from "node:path";
6
- import { existsSync } from "node:fs";
7
7
  import { installPackage } from "@antfu/install-pkg";
8
8
  import { mkdir, readFile, writeFile } from "node:fs/promises";
9
9
  import { parse, printParseErrorCode } from "jsonc-parser";
@@ -15,25 +15,58 @@ const OXC_FMT_IMPORT = `${TOOLING_PACKAGE_NAME}/oxc/fmt`;
15
15
  `${TOOLING_PACKAGE_NAME}`;
16
16
  //#endregion
17
17
  //#region src/cli/update_oxc.ts
18
- const oxlintConfigContent = `import { defineConfig } from 'oxlint'
18
+ function buildOxlintConfigContent(options) {
19
+ const presetOptions = [];
20
+ if (options.adonisjs) presetOptions.push("adonisjs: true");
21
+ if (options.react) presetOptions.push("react: true");
22
+ const presetCall = presetOptions.length > 0 ? `minimalstuffPreset({ ${presetOptions.join(", ")} })` : "minimalstuffPreset()";
23
+ if (!options.adonisjs) return `import { defineConfig } from 'oxlint'
19
24
  import { minimalstuffPreset } from '${OXC_LINT_IMPORT}'
20
25
 
21
26
  export default defineConfig({
22
- extends: [minimalstuffPreset()],
27
+ extends: [${presetCall}],
23
28
  })
24
29
  `;
30
+ return `import { defineConfig } from 'oxlint'
31
+ import {
32
+ ADONISJS_DEFAULT_IGNORE_PATTERNS,
33
+ minimalstuffPreset,
34
+ } from '${OXC_LINT_IMPORT}'
35
+
36
+ export default defineConfig({
37
+ ignorePatterns: [...ADONISJS_DEFAULT_IGNORE_PATTERNS],
38
+ extends: [${presetCall}],
39
+ })
40
+ `;
41
+ }
25
42
  const oxfmtConfigContent = `import { minimalstuffPreset } from '${OXC_FMT_IMPORT}'
26
43
 
27
44
  export default minimalstuffPreset()
28
45
  `;
46
+ const oxfmtAdonisConfigContent = `import {
47
+ ADONISJS_DEFAULT_IGNORE_PATTERNS,
48
+ minimalstuffPreset,
49
+ OXFMT_DEFAULT_IGNORE_PATTERNS,
50
+ } from '${OXC_FMT_IMPORT}'
51
+
52
+ export default minimalstuffPreset({
53
+ ignorePatterns: [
54
+ ...OXFMT_DEFAULT_IGNORE_PATTERNS,
55
+ ...ADONISJS_DEFAULT_IGNORE_PATTERNS,
56
+ ],
57
+ })
58
+ `;
29
59
  const vscodeSettings = {
30
60
  "oxc.typeAware": true,
31
61
  "editor.defaultFormatter": "oxc.oxc-vscode"
32
62
  };
33
63
  const oxcScripts = {
34
- format: "oxfmt --write .",
35
- lint: "oxlint --type-aware",
36
- "lint:fix": "oxlint --type-aware --fix"
64
+ lint: "oxlint .",
65
+ "lint:fix": "oxlint . --fix --fix-suggestions --fix-dangerously",
66
+ format: "pnpm lint:fix; oxfmt .",
67
+ "format:check": "oxfmt . --check",
68
+ typecheck: "tsc --noEmit",
69
+ check: "pnpm run lint && pnpm run format:check && pnpm run typecheck"
37
70
  };
38
71
  const oxcPackages = [
39
72
  "oxfmt",
@@ -44,9 +77,10 @@ const oxcPackages = [
44
77
  async function updateOxc(result) {
45
78
  if (!result.tools.includes("oxc")) return;
46
79
  const cwd = process.cwd();
47
- await writeFile(join(cwd, "oxlint.config.ts"), oxlintConfigContent);
48
- await writeFile(join(cwd, "oxfmt.config.ts"), oxfmtConfigContent);
49
- await updateVscodeSettings(cwd);
80
+ const projectType = await getProjectType(cwd);
81
+ await writeFile(join(cwd, "oxlint.config.ts"), buildOxlintConfigContent(projectType));
82
+ await writeFile(join(cwd, "oxfmt.config.ts"), projectType.adonisjs ? oxfmtAdonisConfigContent : oxfmtConfigContent);
83
+ if (result.tools.includes("vscode")) await updateVscodeSettings(cwd);
50
84
  await addScriptsToPackageJson(cwd);
51
85
  await installPackage(oxcPackages, {
52
86
  dev: true,
@@ -54,6 +88,22 @@ async function updateOxc(result) {
54
88
  });
55
89
  p.log.success("OXC configured (oxlint + oxfmt) 🦀");
56
90
  }
91
+ function hasAdonisDependency(deps) {
92
+ if (!deps) return false;
93
+ return Object.keys(deps).some((name) => name.startsWith("@adonisjs/"));
94
+ }
95
+ function hasReactDependency(deps) {
96
+ if (!deps) return false;
97
+ return "react" in deps || "react-dom" in deps || "@types/react" in deps || "@types/react-dom" in deps;
98
+ }
99
+ async function getProjectType(cwd) {
100
+ const raw = await readFile(join(cwd, "package.json"), "utf-8");
101
+ const pkg = JSON.parse(raw);
102
+ return {
103
+ adonisjs: hasAdonisDependency(pkg.dependencies) || hasAdonisDependency(pkg.devDependencies) || hasAdonisDependency(pkg.peerDependencies),
104
+ react: hasReactDependency(pkg.dependencies) || hasReactDependency(pkg.devDependencies) || hasReactDependency(pkg.peerDependencies)
105
+ };
106
+ }
57
107
  async function updateVscodeSettings(cwd) {
58
108
  const vscodePath = join(cwd, ".vscode");
59
109
  const settingsPath = join(vscodePath, "settings.json");
@@ -85,7 +135,7 @@ async function addScriptsToPackageJson(cwd) {
85
135
  }
86
136
  //#endregion
87
137
  //#region package.json
88
- var version = "0.4.0";
138
+ var version = "0.6.0";
89
139
  //#endregion
90
140
  //#region src/cli/update_pkg.json.ts
91
141
  async function updatePkgJson(_) {
@@ -116,26 +166,57 @@ async function updateEditorConfig(result) {
116
166
  }
117
167
  //#endregion
118
168
  //#region src/cli/index.ts
119
- const DEFAULT_SELECTED_TOOLS = ["editorconfig", "oxc"];
169
+ const DEFAULT_SELECTED_TOOLS = [
170
+ "editorconfig",
171
+ "oxc",
172
+ "vscode"
173
+ ];
120
174
  function exit() {
121
175
  cancel("Cancelled");
122
176
  return process.exit(0);
123
177
  }
178
+ function findGitRoot(startDir) {
179
+ let dir = startDir;
180
+ while (true) {
181
+ if (existsSync(join(dir, ".git"))) return dir;
182
+ const parent = dirname(dir);
183
+ if (parent === dir) return null;
184
+ dir = parent;
185
+ }
186
+ }
124
187
  async function main() {
125
188
  const cwd = process.cwd();
126
189
  intro(color.blue(TOOLING_PACKAGE_NAME));
127
190
  log.info(`You are about to configure ${TOOLING_PACKAGE_NAME} in the current directory: ${color.green(cwd)}`);
128
191
  if (isCancel(await confirm({ message: `Continue ?` }))) return exit();
192
+ const gitRoot = findGitRoot(cwd);
193
+ const rootToCheck = gitRoot && gitRoot !== cwd ? gitRoot : null;
194
+ const hasEditorConfig = existsSync(join(cwd, ".editorconfig")) || rootToCheck !== null && existsSync(join(rootToCheck, ".editorconfig"));
195
+ const hasVscode = existsSync(join(cwd, ".vscode")) || rootToCheck !== null && existsSync(join(rootToCheck, ".vscode"));
196
+ const initialValues = DEFAULT_SELECTED_TOOLS.filter((tool) => {
197
+ if (tool === "editorconfig" && hasEditorConfig) return false;
198
+ if (tool === "vscode" && hasVscode) return false;
199
+ return true;
200
+ });
129
201
  const tools = await multiselect({
130
202
  message: "Select tools to configure",
131
- options: [{
132
- value: "editorconfig",
133
- label: "EditorConfig"
134
- }, {
135
- value: "oxc",
136
- label: "OXC (oxlint + oxfmt)"
137
- }],
138
- initialValues: DEFAULT_SELECTED_TOOLS,
203
+ options: [
204
+ {
205
+ value: "editorconfig",
206
+ label: "EditorConfig",
207
+ ...hasEditorConfig && { hint: "already exists" }
208
+ },
209
+ {
210
+ value: "oxc",
211
+ label: "OXC (oxlint + oxfmt)"
212
+ },
213
+ {
214
+ value: "vscode",
215
+ label: "VSCode settings (.vscode/settings.json)",
216
+ ...hasVscode && { hint: "already exists" }
217
+ }
218
+ ],
219
+ initialValues,
139
220
  required: true
140
221
  });
141
222
  if (isCancel(tools)) return exit();
package/dist/oxc/lint.mjs CHANGED
@@ -100,12 +100,16 @@ function defaultPreset() {
100
100
  });
101
101
  }
102
102
  function minimalstuffPreset(config = {}) {
103
+ const normalizedConfig = {
104
+ perfectionist: true,
105
+ ...config
106
+ };
103
107
  return defineConfig({
104
108
  extends: [
105
109
  defaultPreset(),
106
- config.react ? reactPreset() : null,
107
- config.adonisjs ? adonisjsPreset() : null,
108
- config.perfectionist ? perfectionistPreset() : null
110
+ normalizedConfig.react ? reactPreset() : null,
111
+ normalizedConfig.adonisjs ? adonisjsPreset() : null,
112
+ normalizedConfig.perfectionist ? perfectionistPreset() : null
109
113
  ].filter(Boolean),
110
114
  rules: {}
111
115
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minimalstuff/tooling",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Shared tooling configs: EditorConfig, OXC (oxlint + oxfmt)",
5
5
  "keywords": [
6
6
  "editorconfig",