allow glob-style input for --in-situ (#5646)

closes #5645
This commit is contained in:
Alex Lam S.L
2022-09-05 15:54:35 +01:00
committed by GitHub
parent 1d42e9ad55
commit 535212c69e

View File

@@ -278,6 +278,8 @@ if (specified["self"]) {
if (paths.length) UglifyJS.AST_Node.warn("Ignoring input files since --self was passed"); if (paths.length) UglifyJS.AST_Node.warn("Ignoring input files since --self was passed");
if (!options.wrap) options.wrap = "UglifyJS"; if (!options.wrap) options.wrap = "UglifyJS";
paths = UglifyJS.FILES; paths = UglifyJS.FILES;
} else if (paths.length) {
paths = simple_glob(paths);
} }
if (specified["in-situ"]) { if (specified["in-situ"]) {
if (output && output != "spidermonkey" || specified["reduce-test"] || specified["self"]) { if (output && output != "spidermonkey" || specified["reduce-test"] || specified["self"]) {
@@ -292,7 +294,7 @@ if (specified["in-situ"]) {
run(); run();
}); });
} else if (paths.length) { } else if (paths.length) {
simple_glob(paths).forEach(function(name) { paths.forEach(function(name) {
files[convert_path(name)] = read_file(name); files[convert_path(name)] = read_file(name);
}); });
run(); run();
@@ -491,16 +493,20 @@ function fatal(message) {
// A file glob function that only supports "*" and "?" wildcards in the basename. // A file glob function that only supports "*" and "?" wildcards in the basename.
// Example: "foo/bar/*baz??.*.js" // Example: "foo/bar/*baz??.*.js"
// Argument `glob` may be a string or an array of strings. // Argument `paths` must be an array of strings.
// Returns an array of strings. Garbage in, garbage out. // Returns an array of strings. Garbage in, garbage out.
function simple_glob(glob) { function simple_glob(paths) {
if (Array.isArray(glob)) { return paths.reduce(function(paths, glob) {
return [].concat.apply([], glob.map(simple_glob)); if (/\*|\?/.test(glob)) {
}
if (glob.match(/\*|\?/)) {
var dir = path.dirname(glob); var dir = path.dirname(glob);
try { try {
var entries = fs.readdirSync(dir); var entries = fs.readdirSync(dir).filter(function(name) {
try {
return fs.statSync(path.join(dir, name)).isFile();
} catch (ex) {
return false;
}
});
} catch (ex) {} } catch (ex) {}
if (entries) { if (entries) {
var pattern = "^" + path.basename(glob) var pattern = "^" + path.basename(glob)
@@ -509,15 +515,20 @@ function simple_glob(glob) {
.replace(/\?/g, "[^/\\\\]") + "$"; .replace(/\?/g, "[^/\\\\]") + "$";
var mod = process.platform === "win32" ? "i" : ""; var mod = process.platform === "win32" ? "i" : "";
var rx = new RegExp(pattern, mod); var rx = new RegExp(pattern, mod);
var results = entries.sort().filter(function(name) { var results = entries.filter(function(name) {
return rx.test(name); return rx.test(name);
}).map(function(name) { }).sort().map(function(name) {
return path.join(dir, name); return path.join(dir, name);
}); });
if (results.length) return results; if (results.length) {
[].push.apply(paths, results);
return paths;
} }
} }
return [ glob ]; }
paths.push(glob);
return paths;
}, []);
} }
function read_file(path, default_value) { function read_file(path, default_value) {