Skip to content
Open
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
1 change: 1 addition & 0 deletions lib/watch/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('node:path')

const arrayToRegExp = (arr) => {
const reg = arr.map((file) => {
if (file === 'build') { return '(?:^|[/\\\\])build(?:[/\\\\]|$)' }
if (/^\./.test(file)) { return `\\${file}` }
return file
}).join('|')
Expand Down
14 changes: 13 additions & 1 deletion test/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,20 @@ test('followWatch parameter should set watchDir correctly', async (t) => {
test('should equal expect RegExp', t => {
t.plan(1)

const expectRegExp = /(node_modules|build|dist|\.git|bower_components|logs)/
const expectRegExp = /(node_modules|(?:^|[/\\])build(?:[/\\]|$)|dist|\.git|bower_components|logs)/
const regExp = arrayToRegExp(['node_modules', 'build', 'dist', '.git', 'bower_components', 'logs'])

t.assert.deepStrictEqual(regExp, expectRegExp)
})

test('build ignore should only match build path segments', t => {
const regExp = arrayToRegExp(['build'])

t.assert.strictEqual(regExp.test('/tmp/any-builder/app.js'), false)
t.assert.strictEqual(regExp.test('/tmp/builders/app.js'), false)
t.assert.strictEqual(regExp.test('C:\\work\\any-builder\\app.js'), false)

t.assert.strictEqual(regExp.test('build/app.js'), true)
t.assert.strictEqual(regExp.test('/tmp/any-builder/build/app.js'), true)
t.assert.strictEqual(regExp.test('C:\\work\\any-builder\\build\\app.js'), true)
})