@minimalstuff/tooling 0.4.0 → 0.5.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 +1 -1
- package/dist/cli/index.mjs +58 -8
- package/dist/oxc/lint.mjs +7 -3
- package/package.json +1 -1
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` | `
|
|
46
|
+
| `perfectionist` | `boolean` | `true` | Enable import sorting via perfectionist |
|
|
47
47
|
|
|
48
48
|
```ts
|
|
49
49
|
import {
|
package/dist/cli/index.mjs
CHANGED
|
@@ -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
|
-
|
|
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: [
|
|
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
|
-
|
|
35
|
-
lint: "oxlint --
|
|
36
|
-
"lint: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,8 +77,9 @@ const oxcPackages = [
|
|
|
44
77
|
async function updateOxc(result) {
|
|
45
78
|
if (!result.tools.includes("oxc")) return;
|
|
46
79
|
const cwd = process.cwd();
|
|
47
|
-
await
|
|
48
|
-
await writeFile(join(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);
|
|
49
83
|
await updateVscodeSettings(cwd);
|
|
50
84
|
await addScriptsToPackageJson(cwd);
|
|
51
85
|
await installPackage(oxcPackages, {
|
|
@@ -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.
|
|
138
|
+
var version = "0.5.0";
|
|
89
139
|
//#endregion
|
|
90
140
|
//#region src/cli/update_pkg.json.ts
|
|
91
141
|
async function updatePkgJson(_) {
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
normalizedConfig.react ? reactPreset() : null,
|
|
111
|
+
normalizedConfig.adonisjs ? adonisjsPreset() : null,
|
|
112
|
+
normalizedConfig.perfectionist ? perfectionistPreset() : null
|
|
109
113
|
].filter(Boolean),
|
|
110
114
|
rules: {}
|
|
111
115
|
});
|