From cd48e520b41294d97e6affbdd1069bf924cee69c Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 9 Mar 2024 02:52:24 +0100 Subject: [PATCH] support .config directory --- README.md | 11 ++++++++++- updates.js | 13 +++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 752a038..c81c8d1 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ All `pkg` options support glob matching via [picomatch](https://github.com/micro ## Config File -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 options in the config file, except for `include` and `exclude` options which are merged. +The config file is used to configure certain options of the module. CLI arguments have precedence over options in the config file, except for `include` and `exclude` options which are merged. ```js export default { @@ -44,6 +44,15 @@ export default { }; ``` +### Config File Locations + +The config file can be placed in these locations, relative to `package.json` is: + +- `updates.config.js` +- `updates.config.mjs` +- `.config/updates.js` +- `.config/updates.mjs` + ### Config File Options - `include` *Array[String|Regexp]*: Array of dependencies to include diff --git a/updates.js b/updates.js index 60a80d2..7e7da46 100755 --- a/updates.js +++ b/updates.js @@ -776,12 +776,13 @@ async function main() { let config = {}; try { - config = (await import(join(projectDir, "updates.config.js"))).default; - } catch { - try { - config = (await import(join(projectDir, "updates.config.mjs"))).default; - } catch {} - } + ({default: config} = await Promise.any([ + "updates.config.js", + "updates.config.mjs", + ".config/updates.js", + ".config/updates.mjs", + ].map(str => import(join(projectDir, ...str.split("/")))))); + } catch {} let includeCli, excludeCli; if (args.include && args.include !== true) { // cli