Просмотр исходного кода

feat: 升级代码,兼容node16

lishihao 21 часов назад
Родитель
Сommit
21cc2b24ae
2 измененных файлов с 37 добавлено и 39 удалено
  1. 35 38
      modules/common/fileUtils.js
  2. 2 1
      package.json

+ 35 - 38
modules/common/fileUtils.js

@@ -1,47 +1,44 @@
-'use strict';
+"use strict";
 
 /**
  * Module dependencies.
  */
-var _ = require('lodash'),
-	glob = require('glob');
-
+var _ = require("lodash"),
+  glob = require("glob");
 
 /**
  * Get files by glob patterns
  */
-module.exports.getGlobbedFiles = function(globPatterns, removeRoot) {
-	// For context switching
-	var _this = this;
-
-	// URL paths regex
-	var urlRegex = new RegExp('^(?:[a-z]+:)?\/\/', 'i');
-
-	// The output array
-	var output = [];
-
-	// If glob pattern is array so we use each pattern in a recursive way, otherwise we use glob
-	if (_.isArray(globPatterns)) {
-		globPatterns.forEach(function(globPattern) {
-			output = _.union(output, _this.getGlobbedFiles(globPattern, removeRoot));
-		});
-	} else if (_.isString(globPatterns)) {
-		if (urlRegex.test(globPatterns)) {
-			output.push(globPatterns);
-		} else {
-			glob(globPatterns, {
-				sync: true
-			}, function(err, files) {
-				if (removeRoot) {
-					files = files.map(function(file) {
-						return file.replace(removeRoot, '');
-					});
-				}
-
-				output = _.union(output, files);
-			});
-		}
-	}
-
-	return output;
+module.exports.getGlobbedFiles = function (globPatterns, removeRoot) {
+  // For context switching
+  var _this = this;
+
+  // URL paths regex
+  var urlRegex = new RegExp("^(?:[a-z]+:)?\/\/", "i");
+
+  // The output array
+  var output = [];
+
+  // If glob pattern is array so we use each pattern in a recursive way, otherwise we use glob
+  if (_.isArray(globPatterns)) {
+    globPatterns.forEach(function (globPattern) {
+      output = _.union(output, _this.getGlobbedFiles(globPattern, removeRoot));
+    });
+  } else if (_.isString(globPatterns)) {
+    if (urlRegex.test(globPatterns)) {
+      output.push(globPatterns);
+    } else {
+      var files = glob.sync(globPatterns);
+
+      if (removeRoot) {
+        files = files.map(function (file) {
+          return file.replace(removeRoot, "");
+        });
+      }
+
+      output = _.union(output, files);
+    }
+  }
+
+  return output;
 };

+ 2 - 1
package.json

@@ -14,7 +14,7 @@
     "express": "^4.13.1",
     "express-partials": "^0.3.0",
     "express-session": "^1.15.1",
-    "glob": "~4.0.5",
+    "glob": "^7.2.3",
     "lodash": "^4.17.10",
     "moment": "^2.18.1",
     "mongoose": "~4.13.12",
@@ -27,6 +27,7 @@
     "babel-cli": "^6.26.0",
     "babel-core": "^6.26.0",
     "bluebird": "^3.5.0",
+    "core-js": "^2.5.7",
     "jszip": "^3.1.3",
     "log4js": "~2.3.3",
     "lz-string": "^1.4.4",