Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Oct 16, 2024
1 parent 7e2e2c3 commit 2470fca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
17 changes: 12 additions & 5 deletions src/watch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,25 @@ export const watchCommand = command({
).on('all', reRun);

if (resolvedIncludes.length > 0) {
const globParents = resolvedIncludes.map(pattern => (isGlob(pattern)
? globParent(pattern)
: pattern));
const globParents = resolvedIncludes.map(pattern => (
isGlob(pattern)
? globParent(pattern)
: pattern
));

watch(globParents, {
cwd: process.cwd(),
ignoreInitial: true,
ignorePermissionErrors: true,
// ignore all files not in includes or explicitly excluded
// we need to make sure not to ignore directories otherwise chokidar won't check for it
ignored: file => !globParents.includes(file)
&& (!isOptionsInclude(file) || isOptionsExclude(file)),
ignored: file => (
!globParents.includes(file)
&& (
!isOptionsInclude(file)
|| isOptionsExclude(file)
)
),
}).on('all', reRun);
}

Expand Down
17 changes: 9 additions & 8 deletions tests/specs/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
describe('include', ({ test }) => {
test('file path & glob', async () => {
const entryFile = 'index.js';
const fileA = 'file-a';
// Watches hidden file
const fileA = '.file-a';
const fileB = 'directory/file-b';
await using fixture = await createFixture({
[entryFile]: `
Expand Down Expand Up @@ -363,7 +364,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
const fileB = 'directory/file-b.js';
const depA = 'node_modules/a/index.js';

await using fixtureGlob = await createFixture({
await using fixture = await createFixture({
[fileA]: 'export default "logA"',
[fileB]: 'export default "logB"',
[depA]: 'export default "logC"',
Expand All @@ -380,11 +381,11 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
'watch',
'--clear-screen=false',
`--ignore=../${fileA}`,
'--ignore=abra.js',
'--ignore=doesnt-exist.js',
'--exclude=../directory/*',
'index.js',
],
path.join(fixtureGlob.path, 'process-directory'),
fixture.getPath('process-directory'),
);

onTestFail(async () => {
Expand All @@ -411,13 +412,13 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
if (data === 'logA logB logC\n') {
// These changes should not trigger a re-run
await Promise.all([
fixtureGlob.writeFile(fileA, `export default "${negativeSignal}"`),
fixtureGlob.writeFile(fileB, `export default "${negativeSignal}"`),
fixtureGlob.writeFile(depA, `export default "${negativeSignal}"`),
fixture.writeFile(fileA, `export default "${negativeSignal}"`),
fixture.writeFile(fileB, `export default "${negativeSignal}"`),
fixture.writeFile(depA, `export default "${negativeSignal}"`),
]);

await setTimeout(1000);
fixtureGlob.writeFile(entryFile, 'console.log("TERMINATE")');
fixture.writeFile(entryFile, 'console.log("TERMINATE")');
return true;
}
},
Expand Down

0 comments on commit 2470fca

Please sign in to comment.