support updates.config.js with include/exclude/types options - fixes #59

This commit is contained in:
silverwind 2023-04-23 23:29:15 +02:00
parent 89c7512ada
commit a74d5227a8
Signed by: silverwind
GPG Key ID: 2E62B41C93869443
2 changed files with 37 additions and 29 deletions

@ -57,32 +57,22 @@ usage: updates [options]
$ updates -u && npm i
```
## JSON Output
## Config File
The JSON output is an object with possible properties `results`, `message` and `error`:
Put a `updates.config.js` or `updates.config.mjs` in the root of your project, usually besides `package.json` to configure certain options of the module. CLI arguments have precedence over them.
```bash
updates -j | jq
{
"results": {
"dependencies": {
"p-map": {
"old": "3.0.0",
"new": "4.0.0",
"info": "https://github.com/sindresorhus/p-map",
"age": "3 days"
}
},
"devDependencies": {
"eslint": {
"old": "6.7.2",
"new": "6.8.0",
"info": "https://github.com/eslint/eslint",
"age": "3 months"
}
}
}
}
```js
export default {
exclude: [
"versions",
],
};
```
### Config Options
- `include` *[]String*: Array of dependencies to include
- `exclude` *[]String*: Array of dependencies to exclude
- `types` *[]String*: Array of dependency types
© [silverwind](https://github.com/silverwind), distributed under BSD licence

@ -42,6 +42,7 @@ const normalizeUrl = memoize(url => url.endsWith("/") ? url.substring(0, url.len
const patchSemvers = new Set(["patch"]);
const minorSemvers = new Set(["patch", "minor"]);
const majorSemvers = new Set(["patch", "minor", "major"]);
let config;
const args = minimist(argv.slice(2), {
boolean: [
@ -622,14 +623,23 @@ async function main() {
} else {
const pwd = cwd();
packageFile = findSync("package.json", pwd);
if (!packageFile) {
finish(new Error(`Unable to find package.json in ${pwd} or any of its parent directories`));
}
if (!packageFile) return finish(new Error(`Unable to find package.json in ${pwd} or any of its parent directories`));
}
let config = {};
try {
config = (await import(join(dirname(packageFile), "updates.config.js"))).default;
} catch {
try {
config = (await import(join(dirname(packageFile), "updates.config.mjs"))).default;
} catch {}
}
let dependencyTypes;
if (args.types) {
dependencyTypes = Array.isArray(args.types) ? args.types : args.types.split(",");
} else if ("types" in config) {
dependencyTypes = config.types;
} else {
dependencyTypes = [
"dependencies",
@ -653,8 +663,16 @@ async function main() {
}
let include, exclude;
if (args.include && args.include !== true) include = new Set(((Array.isArray(args.include) ? args.include : [args.include]).flatMap(item => item.split(","))));
if (args.exclude && args.exclude !== true) exclude = new Set(((Array.isArray(args.exclude) ? args.exclude : [args.exclude]).flatMap(item => item.split(","))));
if (args.include && args.include !== true) {
include = new Set(((Array.isArray(args.include) ? args.include : [args.include]).flatMap(item => item.split(","))));
} else if ("include" in config && Array.isArray(config.include)) {
include = new Set(config.include);
}
if (args.exclude && args.exclude !== true) {
exclude = new Set(((Array.isArray(args.exclude) ? args.exclude : [args.exclude]).flatMap(item => item.split(","))));
} else if ("exclude" in config && Array.isArray(config.exclude)) {
exclude = new Set(config.exclude);
}
function canInclude(name) {
if (exclude?.has?.(name) === true) return false;