-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(watcher): move baseDirFromPattern into PatternUtils.getBaseD…
…ir (#3241)
- Loading branch information
1 parent
02f071d
commit 51007b1
Showing
4 changed files
with
49 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
|
||
const PatternUtils = { | ||
getBaseDir (pattern) { | ||
return pattern | ||
.replace(/[/\\][^/\\]*\*.*$/, '') // remove parts with * | ||
.replace(/[/\\][^/\\]*[!+]\(.*$/, '') // remove parts with !(...) and +(...) | ||
.replace(/[/\\][^/\\]*\)\?.*$/, '') || path.sep // remove parts with (...)? | ||
} | ||
} | ||
|
||
module.exports = PatternUtils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict' | ||
const PatternUtils = require('../../../lib/utils/pattern-utils') | ||
|
||
describe('PatternUtils.getBaseDir', () => { | ||
it('return parent directory without start', () => { | ||
expect(PatternUtils.getBaseDir('/some/path/**/more.js')).to.equal('/some/path') | ||
expect(PatternUtils.getBaseDir('/some/p*/file.js')).to.equal('/some') | ||
}) | ||
|
||
it('remove part with !(x)', () => { | ||
expect(PatternUtils.getBaseDir('/some/p/!(a|b).js')).to.equal('/some/p') | ||
expect(PatternUtils.getBaseDir('/some/p!(c|b)*.js')).to.equal('/some') | ||
}) | ||
|
||
it('remove part with +(x)', () => { | ||
expect(PatternUtils.getBaseDir('/some/p/+(a|b).js')).to.equal('/some/p') | ||
expect(PatternUtils.getBaseDir('/some/p+(c|bb).js')).to.equal('/some') | ||
}) | ||
|
||
it('remove part with (x)?', () => { | ||
expect(PatternUtils.getBaseDir('/some/p/(a|b)?.js')).to.equal('/some/p') | ||
expect(PatternUtils.getBaseDir('/some/p(c|b)?.js')).to.equal('/some') | ||
}) | ||
|
||
it('allow paths with parentheses', () => { | ||
expect(PatternUtils.getBaseDir('/some/x (a|b)/a.js')).to.equal('/some/x (a|b)/a.js') | ||
expect(PatternUtils.getBaseDir('/some/p(c|b)/*.js')).to.equal('/some/p(c|b)') | ||
}) | ||
|
||
it('ignore exact files', () => { | ||
expect(PatternUtils.getBaseDir('/usr/local/bin.js')).to.equal('/usr/local/bin.js') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters