From 47948e55483cceba5d7cb0888a561bcbc6df8fe5 Mon Sep 17 00:00:00 2001 From: Ayobami Haastrup <47716486+AyobamiH@users.noreply.github.com> Date: Mon, 5 Oct 2026 20:29:31 +0100 Subject: [PATCH] fix: match build watch ignore by path segment Signed-off-by: Ayobami Haastrup <47716486+AyobamiH@users.noreply.github.com> --- lib/watch/utils.js | 1 + test/watch.test.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/watch/utils.js b/lib/watch/utils.js index 6f49c3c6..0a5a1bda 100644 --- a/lib/watch/utils.js +++ b/lib/watch/utils.js @@ -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('|') diff --git a/test/watch.test.js b/test/watch.test.js index 135be9ec..c89fd037 100644 --- a/test/watch.test.js +++ b/test/watch.test.js @@ -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) +})