[Pkg-javascript-commits] [uglifyjs] 15/49: Add simple file globbing to bin/uglifyjs for Windows
Jonas Smedegaard
dr at jones.dk
Fri Dec 9 11:43:25 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository uglifyjs.
commit 72306b9885dffcc206b6637a9c22e54fa54a168d
Author: kzc <zaxxon2011 at gmail.com>
Date: Fri Jul 29 16:18:56 2016 -0400
Add simple file globbing to bin/uglifyjs for Windows
---
bin/uglifyjs | 3 +++
tools/node.js | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/bin/uglifyjs b/bin/uglifyjs
index 30d234f..3f0c825 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -273,6 +273,9 @@ if (ARGS.comments != null) {
var files = ARGS._.slice();
+if (process.platform === "win32")
+ files = UglifyJS.simple_glob(files);
+
if (ARGS.self) {
if (files.length > 0) {
print_error("WARN: Ignoring input files since --self was passed");
diff --git a/tools/node.js b/tools/node.js
index 179c69d..5a14375 100644
--- a/tools/node.js
+++ b/tools/node.js
@@ -261,3 +261,47 @@ exports.writeNameCache = function(filename, key, cache) {
fs.writeFileSync(filename, JSON.stringify(data, null, 2), "utf8");
}
};
+
+// A file glob function that only supports "*" and "?" wildcards in the basename.
+// Example: "foo/bar/*baz??.*.js"
+// Argument `glob` may be a string or an array of strings.
+// Returns an array of strings. Garbage in, garbage out.
+exports.simple_glob = function simple_glob(glob) {
+ var results = [];
+ if (Array.isArray(glob)) {
+ glob.forEach(function(elem) {
+ results = results.concat(simple_glob(elem));
+ });
+ return results;
+ }
+ if (glob.match(/\*|\?/)) {
+ var dir = path.dirname(glob);
+ try {
+ var entries = fs.readdirSync(dir);
+ } catch (ex) {}
+ if (entries) {
+ var pattern = "^" + (path.basename(glob)
+ .replace(/\(/g, "\\(")
+ .replace(/\)/g, "\\)")
+ .replace(/\{/g, "\\{")
+ .replace(/\}/g, "\\}")
+ .replace(/\[/g, "\\[")
+ .replace(/\]/g, "\\]")
+ .replace(/\+/g, "\\+")
+ .replace(/\^/g, "\\^")
+ .replace(/\$/g, "\\$")
+ .replace(/\*/g, "[^/\\\\]*")
+ .replace(/\./g, "\\.")
+ .replace(/\?/g, ".")) + "$";
+ var mod = process.platform === "win32" ? "i" : "";
+ var rx = new RegExp(pattern, mod);
+ for (var i in entries) {
+ if (rx.test(entries[i]))
+ results.push(dir + "/" + entries[i]);
+ }
+ }
+ }
+ if (results.length === 0)
+ results = [ glob ];
+ return results;
+};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list