fix include/exclude option

This commit is contained in:
silverwind 2023-09-05 01:14:35 +02:00
parent c7629926e0
commit 7ec294133e
Signed by: silverwind
GPG Key ID: 2E62B41C93869443
3 changed files with 36 additions and 25 deletions

@ -109,6 +109,21 @@ exports[`dual 1`] = `
}
`;
exports[`dual 2`] = `
{
"npm": {
"dependencies": {
"noty": {
"age": "5 years",
"info": "https://github.com/needim/noty",
"new": "3.2.0-beta",
"old": "3.1.0",
},
},
},
}
`;
exports[`exclude 1`] = `
{
"npm": {
@ -263,7 +278,7 @@ exports[`include 1`] = `
}
`;
exports[`include 2 1`] = `
exports[`include 2`] = `
{
"npm": {
"dependencies": {
@ -278,7 +293,7 @@ exports[`include 2 1`] = `
}
`;
exports[`include 3 1`] = `
exports[`include 3`] = `
{
"npm": {
"dependencies": {

@ -760,17 +760,17 @@ async function main() {
for (const file of resolveFiles) {
const projectDir = dirname(resolve(file));
const filename = basename(file);
let config = {};
let mode;
if (filename === "package.json") {
mode = "npm";
} else {
if (filename === "pyproject.toml") {
mode = "pypi";
} else {
mode = "npm";
}
filePerMode[mode] = file;
if (!deps[mode]) deps[mode] = {};
let config = {};
try {
config = (await import(join(projectDir, "updates.config.js"))).default;
} catch {
@ -779,6 +779,16 @@ async function main() {
} catch {}
}
let includeCli, excludeCli;
if (args.include && args.include !== true) { // cli
includeCli = (Array.isArray(args.include) ? args.include : [args.include]).flatMap(item => item.split(","));
}
if (args.exclude && args.exclude !== true) {
excludeCli = (Array.isArray(args.exclude) ? args.exclude : [args.exclude]).flatMap(item => item.split(","));
}
const include = matchersToRegexSet(includeCli, config?.include);
const exclude = matchersToRegexSet(excludeCli, config?.exclude);
const agentOpts = {};
if (mode === "npm") {
if (npmrc["strict-ssl"] === false) {
@ -835,17 +845,6 @@ async function main() {
throw new Error(`Error parsing ${file}: ${err.message}`);
}
let includeCli, excludeCli;
if (args.include && args.include !== true) { // cli
includeCli = (Array.isArray(args.include) ? args.include : [args.include]).flatMap(item => item.split(","));
}
if (args.exclude && args.exclude !== true) {
excludeCli = (Array.isArray(args.exclude) ? args.exclude : [args.exclude]).flatMap(item => item.split(","));
}
const include = matchersToRegexSet(includeCli, config?.include);
const exclude = matchersToRegexSet(excludeCli, config?.exclude);
for (const depType of dependencyTypes) {
let obj;
if (mode === "npm") {
@ -872,11 +871,7 @@ async function main() {
numDependencies += Object.keys(maybeUrlDeps).length;
if (!Object.keys(deps[mode]).length && !Object.keys(maybeUrlDeps).length) {
if (include.size || exclude.size) {
throw new Error(`No dependencies match the given include/exclude filters`);
} else {
continue;
}
continue;
}
let registry;
@ -957,7 +952,7 @@ async function main() {
}
if (numDependencies === 0) {
console.info("No dependencies present, nothing to do");
console.info("No dependencies found, nothing to do");
doExit();
}

@ -171,11 +171,12 @@ test("prerelease", makeTest("-j -g -p"));
test("release", makeTest("-j -R"));
test("patch", makeTest("-j -P"));
test("include", makeTest("-j -i noty"));
test("include 2", makeTest("-j -i noty -i noty,noty"));
test("include 3", makeTest("-j -i /^noty/"));
test("include", makeTest("-j -i noty -i noty,noty"));
test("include", makeTest("-j -i /^noty/"));
test("exclude", makeTest("-j -e gulp-sourcemaps,prismjs,svgstore,html-webpack-plugin,noty,jpeg-buffer-orientation,styled-components,@babel/preset-env,versions/updates,react"));
test("exclude", makeTest("-j -e gulp-sourcemaps -i /react/"));
test("exclude", makeTest("-j -i gulp*"));
test("exclude", makeTest("-j -i /^gulp/ -P gulp*"));
test("pypi", makeTest(`-j -f ${poetryFile}`));
test("dual", makeTest(`-j -f ${dualFile}`));
test("dual", makeTest(`-j -f ${dualFile} -i noty`));