bonzai-burn 1.0.28 → 1.0.29
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/package.json +1 -1
- package/src/analyzer.js +87 -8
package/package.json
CHANGED
package/src/analyzer.js
CHANGED
|
@@ -42,6 +42,66 @@ function installPackage(pkg, rootDir) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Check if ESLint config file exists (supports ESLint v9 flat config)
|
|
47
|
+
*/
|
|
48
|
+
function hasEslintConfig(rootDir) {
|
|
49
|
+
const configFiles = [
|
|
50
|
+
'eslint.config.js',
|
|
51
|
+
'eslint.config.mjs',
|
|
52
|
+
'eslint.config.cjs',
|
|
53
|
+
// Legacy configs (ESLint < 9)
|
|
54
|
+
'.eslintrc.js',
|
|
55
|
+
'.eslintrc.cjs',
|
|
56
|
+
'.eslintrc.json',
|
|
57
|
+
'.eslintrc.yml',
|
|
58
|
+
'.eslintrc.yaml',
|
|
59
|
+
'.eslintrc'
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
return configFiles.some(file => fs.existsSync(path.join(rootDir, file)));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Create a minimal ESLint v9 flat config
|
|
67
|
+
*/
|
|
68
|
+
function createEslintConfig(rootDir, config) {
|
|
69
|
+
const rules = config.eslint?.rules || ['no-unused-vars'];
|
|
70
|
+
|
|
71
|
+
// Build rules object
|
|
72
|
+
const rulesObj = {};
|
|
73
|
+
for (const rule of rules) {
|
|
74
|
+
rulesObj[rule] = 'error';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const rulesJson = JSON.stringify(rulesObj, null, 2).replace(/\n/g, '\n ');
|
|
78
|
+
const configContent = `// Auto-generated by bonzai-burn for ESLint v9+
|
|
79
|
+
export default [
|
|
80
|
+
{
|
|
81
|
+
files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx', '**/*.mjs', '**/*.cjs'],
|
|
82
|
+
languageOptions: {
|
|
83
|
+
ecmaVersion: 'latest',
|
|
84
|
+
sourceType: 'module',
|
|
85
|
+
parserOptions: {
|
|
86
|
+
ecmaFeatures: {
|
|
87
|
+
jsx: true
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
rules: ${rulesJson}
|
|
92
|
+
}
|
|
93
|
+
];
|
|
94
|
+
`;
|
|
95
|
+
|
|
96
|
+
const configPath = path.join(rootDir, 'eslint.config.js');
|
|
97
|
+
try {
|
|
98
|
+
fs.writeFileSync(configPath, configContent, 'utf-8');
|
|
99
|
+
return true;
|
|
100
|
+
} catch (e) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
45
105
|
/**
|
|
46
106
|
* Ensure ESLint is available
|
|
47
107
|
*/
|
|
@@ -52,17 +112,32 @@ function ensureEslint(rootDir, config) {
|
|
|
52
112
|
}
|
|
53
113
|
|
|
54
114
|
// Check if eslint exists globally or locally
|
|
55
|
-
|
|
56
|
-
|
|
115
|
+
let eslintInstalled = commandExists('eslint') || isInstalledLocally('eslint', rootDir);
|
|
116
|
+
let installed = false;
|
|
117
|
+
|
|
118
|
+
if (!eslintInstalled) {
|
|
119
|
+
// Try to install
|
|
120
|
+
console.log('📦 ESLint not found, installing...');
|
|
121
|
+
if (installPackage('eslint', rootDir)) {
|
|
122
|
+
eslintInstalled = true;
|
|
123
|
+
installed = true;
|
|
124
|
+
} else {
|
|
125
|
+
return { available: false, reason: 'Failed to install ESLint' };
|
|
126
|
+
}
|
|
57
127
|
}
|
|
58
128
|
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
129
|
+
// Ensure ESLint config exists (required for ESLint v9+)
|
|
130
|
+
let configCreated = false;
|
|
131
|
+
if (!hasEslintConfig(rootDir)) {
|
|
132
|
+
console.log('📄 Creating eslint.config.js...');
|
|
133
|
+
if (createEslintConfig(rootDir, config)) {
|
|
134
|
+
configCreated = true;
|
|
135
|
+
} else {
|
|
136
|
+
return { available: false, reason: 'Failed to create ESLint config' };
|
|
137
|
+
}
|
|
63
138
|
}
|
|
64
139
|
|
|
65
|
-
return { available:
|
|
140
|
+
return { available: true, installed, configCreated };
|
|
66
141
|
}
|
|
67
142
|
|
|
68
143
|
/**
|
|
@@ -361,8 +436,12 @@ export async function analyze(rootDir = process.cwd(), config = {}) {
|
|
|
361
436
|
|
|
362
437
|
const eslintStatus = ensureEslint(rootDir, config);
|
|
363
438
|
toolStatus.eslint = eslintStatus;
|
|
364
|
-
if (eslintStatus.installed) {
|
|
439
|
+
if (eslintStatus.installed && eslintStatus.configCreated) {
|
|
440
|
+
console.log(' ✓ ESLint installed + config created');
|
|
441
|
+
} else if (eslintStatus.installed) {
|
|
365
442
|
console.log(' ✓ ESLint installed');
|
|
443
|
+
} else if (eslintStatus.configCreated) {
|
|
444
|
+
console.log(' ✓ ESLint ready (config created)');
|
|
366
445
|
} else if (eslintStatus.available) {
|
|
367
446
|
console.log(' ✓ ESLint ready');
|
|
368
447
|
} else if (config.eslint?.enabled) {
|