@keeex/eslint-config 2.7.2 → 2.8.1
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 +4 -0
- package/package.json +4 -5
- package/src/dependencies.js +67 -11
package/README.md
CHANGED
|
@@ -12,6 +12,10 @@ Manage the eslint and prettier configuration used through all KeeeX projects.
|
|
|
12
12
|
- run `npx kxeslint-setup auto` to install all required dependencies
|
|
13
13
|
- enable eslint and prettier in whatever you use
|
|
14
14
|
|
|
15
|
+
## Migration
|
|
16
|
+
|
|
17
|
+
When a release changes some underlying dependencies' versions, it is advised to run `npx kxeslint-setup auto`.
|
|
18
|
+
|
|
15
19
|
## Installation
|
|
16
20
|
|
|
17
21
|
The package is available on npmjs and can be installed with any package manager that supports it.
|
package/package.json
CHANGED
|
@@ -31,14 +31,13 @@
|
|
|
31
31
|
"name": "@keeex/eslint-config",
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@eslint/compat": "^2.0.0",
|
|
34
|
-
"@eslint/js": "9.x",
|
|
35
|
-
"@typescript-eslint/parser": "^8.
|
|
36
|
-
"eslint": "
|
|
34
|
+
"@eslint/js": "9.x||10.x",
|
|
35
|
+
"@typescript-eslint/parser": "^8.70.0",
|
|
36
|
+
"eslint": "9.x||10.x",
|
|
37
37
|
"eslint-import-resolver-typescript": "3.x || 4.x",
|
|
38
38
|
"eslint-plugin-import-x": "4.x",
|
|
39
39
|
"eslint-plugin-mocha": "10.x || >11.0.0",
|
|
40
40
|
"eslint-plugin-promise": "7.x",
|
|
41
|
-
"eslint-plugin-react": "7.x",
|
|
42
41
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
43
42
|
"eslint-plugin-tsdoc": "0.x",
|
|
44
43
|
"globals": "16.x || 17.x",
|
|
@@ -94,5 +93,5 @@
|
|
|
94
93
|
},
|
|
95
94
|
"scripts": {},
|
|
96
95
|
"type": "module",
|
|
97
|
-
"version": "2.
|
|
96
|
+
"version": "2.8.1"
|
|
98
97
|
}
|
package/src/dependencies.js
CHANGED
|
@@ -17,7 +17,6 @@ const removedDependencies = [
|
|
|
17
17
|
"eslint-plugin-chai-friendly",
|
|
18
18
|
"eslint-plugin-deprecation",
|
|
19
19
|
"eslint-plugin-i",
|
|
20
|
-
"eslint-plugin-import",
|
|
21
20
|
"eslint-plugin-react-native",
|
|
22
21
|
];
|
|
23
22
|
|
|
@@ -57,7 +56,7 @@ const getInstalledVersion = (name) => {
|
|
|
57
56
|
/**
|
|
58
57
|
* Check if a particular dependency is installed in the project.
|
|
59
58
|
*
|
|
60
|
-
* @returns {{installed: "prod" | "dev" | false; version: string}}
|
|
59
|
+
* @returns {{installed: "prod" | "dev" | false; version: string; keeex: boolean}}
|
|
61
60
|
*/
|
|
62
61
|
const dependencyStatus = (name) => {
|
|
63
62
|
const pkg = getPkgJson();
|
|
@@ -65,7 +64,8 @@ const dependencyStatus = (name) => {
|
|
|
65
64
|
if (pkg.devDependencies && name in pkg.devDependencies) installed = "dev";
|
|
66
65
|
if (pkg.dependencies && name in pkg.dependencies) installed = "prod";
|
|
67
66
|
const version = installed === "missing" ? undefined : getInstalledVersion(name);
|
|
68
|
-
|
|
67
|
+
const keeex = pkg.name.startsWith("@keeex/");
|
|
68
|
+
return {installed, keeex, version};
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
/**
|
|
@@ -96,6 +96,39 @@ const runProcess = (cmd, ...args) => {
|
|
|
96
96
|
return true;
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
+
/**
|
|
100
|
+
* @param version {string} - Either the version as-is, or "KEEEX@<version>".
|
|
101
|
+
*
|
|
102
|
+
* @returns {{version: string; keeex: boolean}}
|
|
103
|
+
*/
|
|
104
|
+
const getExpectedVersion = (version) => {
|
|
105
|
+
if (version.startsWith("KEEEX")) {
|
|
106
|
+
const split = version.split("@");
|
|
107
|
+
return {version: split[1], keeex: true};
|
|
108
|
+
}
|
|
109
|
+
return {version, keeex: false};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Check if a dependency is properly installed
|
|
114
|
+
*
|
|
115
|
+
* @param installedStatus - output of `dependencyStatus()`
|
|
116
|
+
* @param expectedVersion - output of `getExpectedVersion()`
|
|
117
|
+
*
|
|
118
|
+
* @returns {boolean}
|
|
119
|
+
* `true` if the package must be installed/updated
|
|
120
|
+
*/
|
|
121
|
+
const checkNeedUpdate = (installedStatus, expectedVersion) => {
|
|
122
|
+
if (
|
|
123
|
+
installedStatus.installed !== "dev"
|
|
124
|
+
|| (expectedVersion.keeex && !installedStatus.keeex)
|
|
125
|
+
|| !satisfies(installedStatus.version, expectedVersion)
|
|
126
|
+
) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
};
|
|
131
|
+
|
|
99
132
|
/**
|
|
100
133
|
* List all missing/extra dependencies.
|
|
101
134
|
*
|
|
@@ -112,13 +145,22 @@ export const listDependencies = () => {
|
|
|
112
145
|
}
|
|
113
146
|
}
|
|
114
147
|
for (const required of Object.keys(requiredDependencies)) {
|
|
115
|
-
const expectedVersion = requiredDependencies[required].version;
|
|
148
|
+
const expectedVersion = getExpectedVersion(requiredDependencies[required].version);
|
|
116
149
|
const status = dependencyStatus(required);
|
|
117
|
-
const needUpdate =
|
|
150
|
+
const needUpdate = checkNeedUpdate(status, expectedVersion);
|
|
118
151
|
console.log(
|
|
119
|
-
`dep:${required} (${status.installed}=${status.version}) (required=${expectedVersion})`,
|
|
152
|
+
`dep:${required} (${status.installed}=${status.version}) (required=${JSON.stringify(expectedVersion)})`,
|
|
120
153
|
);
|
|
121
|
-
if (needUpdate)
|
|
154
|
+
if (needUpdate) {
|
|
155
|
+
if (expectedVersion.keeex) {
|
|
156
|
+
if (status.installed !== "missing") {
|
|
157
|
+
res.push({name: required, action: "remove"});
|
|
158
|
+
}
|
|
159
|
+
res.push({name: required, action: "keeex-install"});
|
|
160
|
+
} else {
|
|
161
|
+
res.push({name: required, action: "install"});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
122
164
|
}
|
|
123
165
|
return res.toSorted((a, b) => a.name.localeCompare(b.name));
|
|
124
166
|
} finally {
|
|
@@ -150,6 +192,7 @@ const runNpmInstall = (pkgNames) => {
|
|
|
150
192
|
export const installAndRemoveDeps = () => {
|
|
151
193
|
const deps = listDependencies();
|
|
152
194
|
const toInstall = deps.filter((c) => c.action === "install").map((c) => c.name);
|
|
195
|
+
const toInstallKeeex = deps.filter((c) => c.action === "keeex-install").map((c) => c.name);
|
|
153
196
|
const toRemove = deps.filter((c) => c.action === "remove").map((c) => c.name);
|
|
154
197
|
if (toRemove.length > 0) {
|
|
155
198
|
console.log(`Removing dependencies: ${toRemove.join(", ")}`);
|
|
@@ -170,12 +213,24 @@ export const installAndRemoveDeps = () => {
|
|
|
170
213
|
return false;
|
|
171
214
|
}
|
|
172
215
|
}
|
|
216
|
+
if (toInstallKeeex.length > 0) {
|
|
217
|
+
console.log(`Installing @keeex dependencies: ${toInstallKeeex.join(", ")}`);
|
|
218
|
+
const installNames = toInstallKeeex.map((c) => {
|
|
219
|
+
const {version: target} = getExpectedVersion(requiredDependencies[c].version);
|
|
220
|
+
if (typeof target === "string") return `${c}@npm:@keeex/${c}@${target}`;
|
|
221
|
+
return c;
|
|
222
|
+
});
|
|
223
|
+
if (!runNpmInstall(installNames)) {
|
|
224
|
+
process.exitCode = 1;
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
173
228
|
return true;
|
|
174
229
|
};
|
|
175
230
|
|
|
176
231
|
/** Add all dependencies needed by the provided config */
|
|
177
232
|
export const configToDependencies = (eslintConfig) => {
|
|
178
|
-
addDependency("eslint", "
|
|
233
|
+
addDependency("eslint", "10.x");
|
|
179
234
|
addDependency("prettier", "3.x");
|
|
180
235
|
if (eslintConfig.globals) addDependency("globals", "17.x");
|
|
181
236
|
if (eslintConfig.import !== false) {
|
|
@@ -184,16 +239,17 @@ export const configToDependencies = (eslintConfig) => {
|
|
|
184
239
|
}
|
|
185
240
|
if (eslintConfig.mocha) addDependency("eslint-plugin-mocha", "11.x");
|
|
186
241
|
if (!eslintConfig.noBase) {
|
|
187
|
-
addDependency("@eslint/js", "
|
|
242
|
+
addDependency("@eslint/js", "10.x");
|
|
188
243
|
addDependency("eslint-plugin-promise", "7.x");
|
|
189
244
|
}
|
|
190
245
|
const react = getReactFullConfig(eslintConfig.react);
|
|
191
246
|
if (react.react) {
|
|
192
|
-
addDependency("eslint-plugin-react", "7.x");
|
|
247
|
+
addDependency("eslint-plugin-react", "KEEEX@7.x");
|
|
248
|
+
addDependency("eslint-plugin-import", "KEEEX@2.x");
|
|
193
249
|
if (eslintConfig.import) addDependency("eslint-import-resolver-webpack", "0.x");
|
|
194
250
|
if (react.reactHooks) addDependency("eslint-plugin-react-hooks", "5.x");
|
|
195
251
|
if (react.reactNative) {
|
|
196
|
-
addDependency("@eslint/js", "
|
|
252
|
+
addDependency("@eslint/js", "10.x");
|
|
197
253
|
}
|
|
198
254
|
}
|
|
199
255
|
if (eslintConfig.typescript) {
|