Skip to content
This repository has been archived by the owner on Jul 24, 2022. It is now read-only.

refactor: replace minimatch with micromatch #56

Merged
merged 3 commits into from
Jan 4, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ revisioning:
'video[poster]': 'poster'
```

#### Note: To match paths in `exclude` option, glob matching is done using [minmatch](https://github.com/isaacs/minimatch).
#### Note: To match paths in `exclude` option, glob matching is done using [micromatch](https://github.com/micromatch/micromatch).

#### TODO
* Eslint configs
Expand Down
8 changes: 2 additions & 6 deletions lib/filters/css.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const CleanCSS = require('clean-css');
const minimatch = require('minimatch');
const micromatch = require('micromatch');
const Promise = require('bluebird');
const cloneDeep = require('lodash.clonedeep');

Expand All @@ -27,12 +27,8 @@ function run(str, data) {
return str;
}

if (exclude && !Array.isArray(exclude)) exclude = [exclude];

if (path && exclude && exclude.length) {
for (let i = 0, len = exclude.length; i < len; i++) {
if (minimatch(path, exclude[i])) return str;
}
if (micromatch.isMatch(path, exclude, { basename: true })) return str;
}

return new Promise(function(resolve, reject) {
Expand Down
8 changes: 2 additions & 6 deletions lib/filters/html.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Htmlminifier = require('html-minifier').minify;
const minimatch = require('minimatch');
const micromatch = require('micromatch');
const cloneDeep = require('lodash.clonedeep');

function run(str, data) {
Expand All @@ -26,12 +26,8 @@ function run(str, data) {
return str;
}

if (exclude && !Array.isArray(exclude)) exclude = [exclude];

if (path && exclude && exclude.length) {
for (let i = 0, len = exclude.length; i < len; i++) {
if (minimatch(path, exclude[i])) return str;
}
if (micromatch.isMatch(path, exclude, { basename: true })) return str;
}

let result = str;
Expand Down
4 changes: 2 additions & 2 deletions lib/filters/image.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const minimatch = require('minimatch');
const micromatch = require('micromatch');
const Promise = require('bluebird');
const Imagemin = require('imagemin');
const mozjpeg = require('imagemin-mozjpeg');
Expand Down Expand Up @@ -52,7 +52,7 @@ function run(str, data) {

// exclude image
const routes = route.list().filter(function(path) {
return minimatch(path, '**/*.{' + targetfile.join(',') + '}', {
return micromatch.isMatch(path, '**/*.{' + targetfile.join(',') + '}', {
nocase: true
});
});
Expand Down
8 changes: 2 additions & 6 deletions lib/filters/js.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const minimatch = require('minimatch');
const micromatch = require('micromatch');
const UglifyJS = require('uglify-js');
const cloneDeep = require('lodash.clonedeep');

Expand Down Expand Up @@ -28,12 +28,8 @@ function run(str, data) {
return str;
}

if (exclude && !Array.isArray(exclude)) exclude = [exclude];

if (path && exclude && exclude.length) {
for (let i = 0, len = exclude.length; i < len; i++) {
if (minimatch(path, exclude[i])) return str;
}
if (micromatch.isMatch(path, exclude, { basename: true })) return str;
}

const result = UglifyJS.minify(str, options);
Expand Down
12 changes: 4 additions & 8 deletions lib/revision.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const path = require('path');
const minimatch = require('minimatch');
const micromatch = require('micromatch');
const Promise = require('bluebird');
const hasha = require('hasha');
const revPath = require('rev-path');
Expand Down Expand Up @@ -66,14 +66,10 @@ function run() {
/**
* Skip excluded files.
* */
if (exclude && !Array.isArray(exclude)) exclude = [exclude];

if (path && exclude && exclude.length) {
for (let i = 0, len = exclude.length; i < len; i++) {
if (minimatch(path, exclude[i])){
// console.log('[revision]Ignoring '+ path)
return false;
}
if (micromatch.isMatch(path, exclude, { basename: true })) {
// console.log('[revision]Ignoring '+ path)
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"imagemin-pngquant": "^8.0.0",
"imagemin-svgo": "^7.0.0",
"lodash.clonedeep": "^4.5.0",
"minimatch": "^3.0.4",
"micromatch": "^4.0.2",
"rev-path": "^2.0.0",
"soup": "^0.1.5",
"stream-to-array": "^2.3.0",
Expand Down