Skip to content

Commit 474ea71

Browse files
mdmower-csnwprivatenumberboxizen
authored
feat(watch): --include CLI flag to watch additional files (#625)
Co-authored-by: hiroki osame <[email protected]> Co-authored-by: boxizeng <[email protected]> Co-authored-by: Box Tsang <[email protected]>
1 parent af370e7 commit 474ea71

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/watch/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ const flags = {
3636
type: [String],
3737
description: 'Paths & globs to exclude from being watched',
3838
},
39+
include: {
40+
type: [String],
41+
description: 'Additional paths & globs to watch',
42+
},
3943
} as const;
4044

4145
export const watchCommand = command({
@@ -60,6 +64,7 @@ export const watchCommand = command({
6064
tsconfigPath: argv.flags.tsconfig,
6165
clearScreen: argv.flags.clearScreen,
6266
ignore: argv.flags.ignore,
67+
include: argv.flags.include,
6368
ipc: true,
6469
};
6570

@@ -195,7 +200,10 @@ export const watchCommand = command({
195200
* As an alternative, we watch cwd and all run-time dependencies
196201
*/
197202
const watcher = watch(
198-
argv._,
203+
[
204+
...argv._,
205+
...options.include,
206+
],
199207
{
200208
cwd: process.cwd(),
201209
ignoreInitial: true,

tests/specs/watch.ts

+59
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,64 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
300300
expect(p.stderr).toBe('');
301301
}, 10_000);
302302
});
303+
304+
describe('watch additional files', ({ test }) => {
305+
test('file path & glob', async () => {
306+
const entryFile = 'index.js';
307+
const fileA = 'file-a';
308+
const fileB = 'directory/file-b';
309+
await using fixture = await createFixture({
310+
[entryFile]: `
311+
import fs from 'fs/promises';
312+
Promise.all([
313+
fs.readFile('./${fileA}', 'utf8'),
314+
fs.readFile('./${fileB}', 'utf8')
315+
]).then(console.log, console.error);
316+
`.trim(),
317+
[fileA]: 'content-a',
318+
[fileB]: 'content-b',
319+
});
320+
321+
const tsxProcess = tsx(
322+
[
323+
'watch',
324+
'--clear-screen=false',
325+
`--include=${fileA}`,
326+
'--include=directory/*',
327+
entryFile,
328+
],
329+
fixture.path,
330+
);
331+
332+
await processInteract(
333+
tsxProcess.stdout!,
334+
[
335+
(data) => {
336+
if (data.includes("'content-a', 'content-b'")) {
337+
fixture.writeFile(fileA, 'update-a');
338+
return true;
339+
}
340+
},
341+
(data) => {
342+
if (data.includes("'update-a', 'content-b'")) {
343+
fixture.writeFile(fileB, 'update-b');
344+
return true;
345+
}
346+
},
347+
(data) => {
348+
if (data.includes("'update-a', 'update-b'")) {
349+
return true;
350+
}
351+
},
352+
],
353+
9000,
354+
);
355+
356+
tsxProcess.kill();
357+
358+
const tsxProcessResolved = await tsxProcess;
359+
expect(tsxProcessResolved.stderr).toBe('');
360+
}, 10_000);
361+
});
303362
});
304363
});

0 commit comments

Comments
 (0)