Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace minimatch with micromatch #40

Merged
merged 2 commits into from Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -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'));
7 changes: 2 additions & 5 deletions 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({
Expand All @@ -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);
Expand Down
51 changes: 49 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -26,7 +26,7 @@
],
"license": "MIT",
"dependencies": {
"minimatch": "^3.0.4",
"micromatch": "^4.0.2",
"uglify-js": "^2.8.29"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions test/.eslintrc
@@ -0,0 +1,3 @@
{
"extends": "hexo/test"
}
12 changes: 7 additions & 5 deletions 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;
});
});
// Tests.
it('should uglify js.', function() {
return true;
});
});