Skip to content

Commit

Permalink
Define hoist function
Browse files Browse the repository at this point in the history
  • Loading branch information
nafarlee committed Nov 30, 2023
1 parent 1fd4b99 commit 4c22baf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
55 changes: 28 additions & 27 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21420,7 +21420,7 @@ var require_micromatch = __commonJS({
var picomatch = require_picomatch2();
var utils = require_utils4();
var isEmptyString = (val) => val === "" || val === "./";
var micromatch = (list, patterns, options) => {
var micromatch2 = (list, patterns, options) => {
patterns = [].concat(patterns);
list = [].concat(list);
let omit = /* @__PURE__ */ new Set();
Expand Down Expand Up @@ -21463,11 +21463,11 @@ var require_micromatch = __commonJS({
}
return matches;
};
micromatch.match = micromatch;
micromatch.matcher = (pattern, options) => picomatch(pattern, options);
micromatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
micromatch.any = micromatch.isMatch;
micromatch.not = (list, patterns, options = {}) => {
micromatch2.match = micromatch2;
micromatch2.matcher = (pattern, options) => picomatch(pattern, options);
micromatch2.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
micromatch2.any = micromatch2.isMatch;
micromatch2.not = (list, patterns, options = {}) => {
patterns = [].concat(patterns).map(String);
let result = /* @__PURE__ */ new Set();
let items = [];
Expand All @@ -21476,20 +21476,20 @@ var require_micromatch = __commonJS({
options.onResult(state);
items.push(state.output);
};
let matches = new Set(micromatch(list, patterns, { ...options, onResult }));
let matches = new Set(micromatch2(list, patterns, { ...options, onResult }));
for (let item of items) {
if (!matches.has(item)) {
result.add(item);
}
}
return [...result];
};
micromatch.contains = (str, pattern, options) => {
micromatch2.contains = (str, pattern, options) => {
if (typeof str !== "string") {
throw new TypeError(`Expected a string: "${util.inspect(str)}"`);
}
if (Array.isArray(pattern)) {
return pattern.some((p) => micromatch.contains(str, p, options));
return pattern.some((p) => micromatch2.contains(str, p, options));
}
if (typeof pattern === "string") {
if (isEmptyString(str) || isEmptyString(pattern)) {
Expand All @@ -21499,19 +21499,19 @@ var require_micromatch = __commonJS({
return true;
}
}
return micromatch.isMatch(str, pattern, { ...options, contains: true });
return micromatch2.isMatch(str, pattern, { ...options, contains: true });
};
micromatch.matchKeys = (obj, patterns, options) => {
micromatch2.matchKeys = (obj, patterns, options) => {
if (!utils.isObject(obj)) {
throw new TypeError("Expected the first argument to be an object");
}
let keys = micromatch(Object.keys(obj), patterns, options);
let keys = micromatch2(Object.keys(obj), patterns, options);
let res = {};
for (let key of keys)
res[key] = obj[key];
return res;
};
micromatch.some = (list, patterns, options) => {
micromatch2.some = (list, patterns, options) => {
let items = [].concat(list);
for (let pattern of [].concat(patterns)) {
let isMatch = picomatch(String(pattern), options);
Expand All @@ -21521,7 +21521,7 @@ var require_micromatch = __commonJS({
}
return false;
};
micromatch.every = (list, patterns, options) => {
micromatch2.every = (list, patterns, options) => {
let items = [].concat(list);
for (let pattern of [].concat(patterns)) {
let isMatch = picomatch(String(pattern), options);
Expand All @@ -21531,23 +21531,23 @@ var require_micromatch = __commonJS({
}
return true;
};
micromatch.all = (str, patterns, options) => {
micromatch2.all = (str, patterns, options) => {
if (typeof str !== "string") {
throw new TypeError(`Expected a string: "${util.inspect(str)}"`);
}
return [].concat(patterns).every((p) => picomatch(p, options)(str));
};
micromatch.capture = (glob, input, options) => {
micromatch2.capture = (glob, input, options) => {
let posix = utils.isWindows(options);
let regex = picomatch.makeRe(String(glob), { ...options, capture: true });
let match = regex.exec(posix ? utils.toPosixSlashes(input) : input);
if (match) {
return match.slice(1).map((v) => v === void 0 ? "" : v);
}
};
micromatch.makeRe = (...args) => picomatch.makeRe(...args);
micromatch.scan = (...args) => picomatch.scan(...args);
micromatch.parse = (patterns, options) => {
micromatch2.makeRe = (...args) => picomatch.makeRe(...args);
micromatch2.scan = (...args) => picomatch.scan(...args);
micromatch2.parse = (patterns, options) => {
let res = [];
for (let pattern of [].concat(patterns || [])) {
for (let str of braces(String(pattern), options)) {
Expand All @@ -21556,20 +21556,20 @@ var require_micromatch = __commonJS({
}
return res;
};
micromatch.braces = (pattern, options) => {
micromatch2.braces = (pattern, options) => {
if (typeof pattern !== "string")
throw new TypeError("Expected a string");
if (options && options.nobrace === true || !/\{.*\}/.test(pattern)) {
return [pattern];
}
return braces(pattern, options);
};
micromatch.braceExpand = (pattern, options) => {
micromatch2.braceExpand = (pattern, options) => {
if (typeof pattern !== "string")
throw new TypeError("Expected a string");
return micromatch.braces(pattern, { ...options, expand: true });
return micromatch2.braces(pattern, { ...options, expand: true });
};
module2.exports = micromatch;
module2.exports = micromatch2;
}
});

Expand All @@ -21581,7 +21581,7 @@ var require_pattern = __commonJS({
exports.removeDuplicateSlashes = exports.matchAny = exports.convertPatternsToRe = exports.makeRe = exports.getPatternParts = exports.expandBraceExpansion = exports.expandPatternsWithBraceExpansion = exports.isAffectDepthOfReadingPattern = exports.endsWithSlashGlobStar = exports.hasGlobStar = exports.getBaseDirectory = exports.isPatternRelatedToParentDirectory = exports.getPatternsOutsideCurrentDirectory = exports.getPatternsInsideCurrentDirectory = exports.getPositivePatterns = exports.getNegativePatterns = exports.isPositivePattern = exports.isNegativePattern = exports.convertToNegativePattern = exports.convertToPositivePattern = exports.isDynamicPattern = exports.isStaticPattern = void 0;
var path2 = require("path");
var globParent = require_glob_parent();
var micromatch = require_micromatch();
var micromatch2 = require_micromatch();
var GLOBSTAR = "**";
var ESCAPE_SYMBOL = "\\";
var COMMON_GLOB_SYMBOLS_RE = /[*?]|^!/;
Expand Down Expand Up @@ -21685,13 +21685,13 @@ var require_pattern = __commonJS({
}
exports.expandPatternsWithBraceExpansion = expandPatternsWithBraceExpansion;
function expandBraceExpansion(pattern) {
const patterns = micromatch.braces(pattern, { expand: true, nodupes: true, keepEscaping: true });
const patterns = micromatch2.braces(pattern, { expand: true, nodupes: true, keepEscaping: true });
patterns.sort((a, b) => a.length - b.length);
return patterns.filter((pattern2) => pattern2 !== "");
}
exports.expandBraceExpansion = expandBraceExpansion;
function getPatternParts(pattern, options) {
let { parts } = micromatch.scan(pattern, Object.assign(Object.assign({}, options), { parts: true }));
let { parts } = micromatch2.scan(pattern, Object.assign(Object.assign({}, options), { parts: true }));
if (parts.length === 0) {
parts = [pattern];
}
Expand All @@ -21703,7 +21703,7 @@ var require_pattern = __commonJS({
}
exports.getPatternParts = getPatternParts;
function makeRe(pattern, options) {
return micromatch.makeRe(pattern, options);
return micromatch2.makeRe(pattern, options);
}
exports.makeRe = makeRe;
function convertPatternsToRe(patterns, options) {
Expand Down Expand Up @@ -24688,6 +24688,7 @@ var generateGlobTasksSync = normalizeArgumentsSync(generateTasksSync);
var { convertPathToPattern } = import_fast_glob2.default;

// main.mjs
var import_micromatch = __toESM(require_micromatch(), 1);
function isEmpty(xs) {
return xs.length === 0;
}
Expand Down
15 changes: 15 additions & 0 deletions main.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env node
import { dirname } from 'path';
import * as core from '@actions/core';
import { globby } from 'globby';
import micromatch from 'micromatch';

function isEmpty(xs) {
return xs.length === 0;
Expand Down Expand Up @@ -36,6 +38,19 @@ async function directMatch(patterns) {
core.setOutput('matches', matches);
}

function hoist(rootPatterns, paths) {
const roots = [];
let remaining = [...paths, './'];
do {
roots.push(...micromatch(remaining, rootPatterns));
remaining = micromatch
.not(remaining, rootPatterns)
.map((x) => `${dirname(x)}/`)
.filter((x) => x !== './');
} while (remaining.length > 0);
return Array.from(new Set(roots));
}

(async () => {
const { patterns, rootPatterns } = getInputs();
switch (true) {
Expand Down

0 comments on commit 4c22baf

Please sign in to comment.