Skip to content

Commit

Permalink
Add support for (root-patterns/filter-patterns) mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nafarlee committed Nov 30, 2023
1 parent 4727312 commit 2033138
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
26 changes: 24 additions & 2 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24332,6 +24332,7 @@ var require_ignore = __commonJS({
});

// main.mjs
var import_path = require("path");
var core = __toESM(require_core(), 1);

// node_modules/globby/index.js
Expand Down Expand Up @@ -24719,14 +24720,35 @@ async function directMatch(patterns) {
core.debug(JSON.stringify({ patterns, matches }, null, 2));
core.setOutput("matches", matches);
}
function hoist(rootPatterns, paths) {
const roots = [];
let remaining = [...paths, "./"];
do {
roots.push(...(0, import_micromatch.default)(remaining, rootPatterns));
remaining = import_micromatch.default.not(remaining, rootPatterns).map((x) => `${(0, import_path.dirname)(x)}/`).filter((x) => x !== "./");
} while (remaining.length > 0);
return Array.from(new Set(roots));
}
async function hoistMatch(rootPatterns, filterPatterns) {
const fromFilters = await fsGlob(filterPatterns);
const matches = hoist(rootPatterns, fromFilters);
core.debug(JSON.stringify({
rootPatterns,
filterPatterns,
fromFilters,
matches
}, null, 2));
core.setOutput("matches", matches);
}
(async () => {
const { patterns, rootPatterns } = getInputs();
const { filterPatterns, patterns, rootPatterns } = getInputs();
switch (true) {
case !isEmpty(patterns):
directMatch(patterns);
break;
case !isEmpty(rootPatterns):
throw new Error("Not implemented");
hoistMatch(rootPatterns, filterPatterns);
break;
default:
throw new Error("Unreachable");
}
Expand Down
5 changes: 3 additions & 2 deletions main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ async function hoistMatch(rootPatterns, filterPatterns) {
}

(async () => {
const { patterns, rootPatterns } = getInputs();
const { filterPatterns, patterns, rootPatterns } = getInputs();
switch (true) {
case !isEmpty(patterns):
directMatch(patterns);
break;
case !isEmpty(rootPatterns):
throw new Error('Not implemented');
hoistMatch(rootPatterns, filterPatterns);
break;
default:
throw new Error('Unreachable');
}
Expand Down

0 comments on commit 2033138

Please sign in to comment.