Skip to content

Commit 5b5f110

Browse files
committed
Fixes #3 (not a breaking change)
1 parent dfdf907 commit 5b5f110

File tree

4 files changed

+125
-55
lines changed

4 files changed

+125
-55
lines changed

lib/copy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ var EventEmitter = require('node:events').EventEmitter;
66
var fs = require('fs');
77
var junk = require('junk');
88
var errno = require('errno');
9-
var maximatch = require('maximatch');
109
var slash = require('slash');
10+
var maximatch = require('./maximatch.js');
1111

1212
var CopyError = errno.custom.createError('CopyError');
1313

lib/maximatch.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
var minimatch = require("minimatch");
2+
3+
// via https://github.com/sindresorhus/array-union (MIT license)
4+
function arrayUnion(...args) {
5+
return [...new Set(args.flat())];
6+
}
7+
8+
// via https://github.com/sindresorhus/array-differ/blob/main/index.js (MIT license)
9+
function arrayDiffer(array, ...values) {
10+
const rest = new Set(values.flat());
11+
return array.filter(element => !rest.has(element));
12+
}
13+
14+
// via https://github.com/sindresorhus/arrify/blob/main/index.js (MIT license)
15+
function arrify(value) {
16+
if (value === null || value === undefined) {
17+
return [];
18+
}
19+
20+
if (Array.isArray(value)) {
21+
return value;
22+
}
23+
24+
if (typeof value === 'string') {
25+
return [value];
26+
}
27+
28+
if (typeof value[Symbol.iterator] === 'function') {
29+
return [...value];
30+
}
31+
32+
return [value];
33+
}
34+
35+
// via https://www.npmjs.com/package/maximatch (MIT license)
36+
module.exports = function (list, patterns, options) {
37+
list = arrify(list);
38+
39+
patterns = arrify(patterns);
40+
41+
if (list.length === 0 || patterns.length === 0) {
42+
return [];
43+
}
44+
45+
options = options || {};
46+
47+
return patterns.reduce(function (ret, pattern) {
48+
if (typeof pattern === "function") {
49+
return arrayUnion(ret, list.filter(pattern));
50+
} else if (pattern instanceof RegExp) {
51+
return arrayUnion(
52+
ret,
53+
list.filter(function (item) {
54+
return pattern.test(item);
55+
}),
56+
);
57+
} else {
58+
var process = arrayUnion;
59+
60+
if (pattern[0] === "!") {
61+
pattern = pattern.slice(1);
62+
63+
process = arrayDiffer;
64+
}
65+
66+
return process(ret, minimatch.match(list, pattern, options));
67+
}
68+
}, []);
69+
};

package-lock.json

Lines changed: 54 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"dependencies": {
5555
"errno": "^1.0.0",
5656
"junk": "^3.1.0",
57-
"maximatch": "^0.1.0",
57+
"minimatch": "^10.1.1",
5858
"slash": "^3.0.0"
5959
},
6060
"devDependencies": {

0 commit comments

Comments
 (0)