diff --git a/index.js b/index.js index d60c689..1912d48 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ hexo.config.uglify = Object.assign({ mangle: true, output: {}, compress: {}, - exclude: ['*.min.js'] + exclude: '*.min.js' }, hexo.config.uglify); hexo.extend.filter.register('after_render:js', require('./lib/filter')); diff --git a/lib/filter.js b/lib/filter.js index 9123ae6..6f3349b 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -1,7 +1,7 @@ 'use strict'; var UglifyJS = require('uglify-js'); -var minimatch = require('minimatch'); +var micromatch = require('micromatch'); module.exports = function(str, data) { var options = Object.assign({ @@ -10,12 +10,9 @@ module.exports = function(str, data) { var path = data.path; var exclude = options.exclude; - if (exclude && !Array.isArray(exclude)) exclude = [exclude]; if (path && exclude && exclude.length) { - for (var i = 0, len = exclude.length; i < len; i++) { - if (minimatch(path, exclude[i])) return str; - } + if (micromatch.isMatch(path, exclude, { basename: true })) return str; } var result = UglifyJS.minify(str, options); diff --git a/package-lock.json b/package-lock.json index 2416d60..eabf06b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -299,7 +299,8 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true }, "bcrypt-pbkdf": { "version": "1.0.2", @@ -314,11 +315,20 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "requires": { + "fill-range": "^7.0.1" + } + }, "browser-stdout": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", @@ -453,7 +463,8 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true }, "convert-source-map": { "version": "1.6.0", @@ -945,6 +956,14 @@ "flat-cache": "^2.0.1" } }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "requires": { + "to-regex-range": "^5.0.1" + } + }, "find-cache-dir": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.1.0.tgz", @@ -1388,6 +1407,11 @@ "number-is-nan": "^1.0.0" } }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==" + }, "is-promise": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", @@ -1740,6 +1764,15 @@ } } }, + "micromatch": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz", + "integrity": "sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==", + "requires": { + "braces": "^3.0.1", + "picomatch": "^2.0.5" + } + }, "mime-db": { "version": "1.40.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz", @@ -1765,6 +1798,7 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2625,6 +2659,11 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", "dev": true }, + "picomatch": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.0.7.tgz", + "integrity": "sha512-oLHIdio3tZ0qH76NybpeneBhYVj0QFTfXEFTc/B3zKQspYfYYkWYgFsmzo+4kvId/bQRcNkVeguI3y+CD22BtA==" + }, "pkg-dir": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz", @@ -3146,6 +3185,14 @@ "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", "dev": true }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "requires": { + "is-number": "^7.0.0" + } + }, "tough-cookie": { "version": "2.4.3", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", diff --git a/package.json b/package.json index 6fcb6ee..8a31c58 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ ], "license": "MIT", "dependencies": { - "minimatch": "^3.0.4", + "micromatch": "^4.0.2", "uglify-js": "^2.8.29" }, "devDependencies": { diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 0000000..fef0a05 --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "hexo/test" +} diff --git a/test/index.js b/test/index.js index 8f4d0e7..c40e7be 100644 --- a/test/index.js +++ b/test/index.js @@ -1,8 +1,10 @@ 'use strict'; +const should = require('chai').should(); // eslint-disable-line + describe('hexo-uglifyjs', function() { - // Tests. - it('should uglify js.', function() { - return true; - }); -}); \ No newline at end of file + // Tests. + it('should uglify js.', function() { + return true; + }); +});