Skip to content

Commit 535212c

Browse files
authored
allow glob-style input for --in-situ (#5646)
closes #5645
1 parent 1d42e9a commit 535212c

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

bin/uglifyjs

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ if (specified["self"]) {
278278
if (paths.length) UglifyJS.AST_Node.warn("Ignoring input files since --self was passed");
279279
if (!options.wrap) options.wrap = "UglifyJS";
280280
paths = UglifyJS.FILES;
281+
} else if (paths.length) {
282+
paths = simple_glob(paths);
281283
}
282284
if (specified["in-situ"]) {
283285
if (output && output != "spidermonkey" || specified["reduce-test"] || specified["self"]) {
@@ -292,7 +294,7 @@ if (specified["in-situ"]) {
292294
run();
293295
});
294296
} else if (paths.length) {
295-
simple_glob(paths).forEach(function(name) {
297+
paths.forEach(function(name) {
296298
files[convert_path(name)] = read_file(name);
297299
});
298300
run();
@@ -491,33 +493,42 @@ function fatal(message) {
491493

492494
// A file glob function that only supports "*" and "?" wildcards in the basename.
493495
// Example: "foo/bar/*baz??.*.js"
494-
// Argument `glob` may be a string or an array of strings.
496+
// Argument `paths` must be an array of strings.
495497
// Returns an array of strings. Garbage in, garbage out.
496-
function simple_glob(glob) {
497-
if (Array.isArray(glob)) {
498-
return [].concat.apply([], glob.map(simple_glob));
499-
}
500-
if (glob.match(/\*|\?/)) {
501-
var dir = path.dirname(glob);
502-
try {
503-
var entries = fs.readdirSync(dir);
504-
} catch (ex) {}
505-
if (entries) {
506-
var pattern = "^" + path.basename(glob)
507-
.replace(/[.+^$[\]\\(){}]/g, "\\$&")
508-
.replace(/\*/g, "[^/\\\\]*")
509-
.replace(/\?/g, "[^/\\\\]") + "$";
510-
var mod = process.platform === "win32" ? "i" : "";
511-
var rx = new RegExp(pattern, mod);
512-
var results = entries.sort().filter(function(name) {
513-
return rx.test(name);
514-
}).map(function(name) {
515-
return path.join(dir, name);
516-
});
517-
if (results.length) return results;
498+
function simple_glob(paths) {
499+
return paths.reduce(function(paths, glob) {
500+
if (/\*|\?/.test(glob)) {
501+
var dir = path.dirname(glob);
502+
try {
503+
var entries = fs.readdirSync(dir).filter(function(name) {
504+
try {
505+
return fs.statSync(path.join(dir, name)).isFile();
506+
} catch (ex) {
507+
return false;
508+
}
509+
});
510+
} catch (ex) {}
511+
if (entries) {
512+
var pattern = "^" + path.basename(glob)
513+
.replace(/[.+^$[\]\\(){}]/g, "\\$&")
514+
.replace(/\*/g, "[^/\\\\]*")
515+
.replace(/\?/g, "[^/\\\\]") + "$";
516+
var mod = process.platform === "win32" ? "i" : "";
517+
var rx = new RegExp(pattern, mod);
518+
var results = entries.filter(function(name) {
519+
return rx.test(name);
520+
}).sort().map(function(name) {
521+
return path.join(dir, name);
522+
});
523+
if (results.length) {
524+
[].push.apply(paths, results);
525+
return paths;
526+
}
527+
}
518528
}
519-
}
520-
return [ glob ];
529+
paths.push(glob);
530+
return paths;
531+
}, []);
521532
}
522533

523534
function read_file(path, default_value) {

0 commit comments

Comments
 (0)