Skip to content

Commit 157c3ec

Browse files
committed
feat(watch): deprecate ignore flag in favor or exclude flag
1 parent 474ea71 commit 157c3ec

File tree

2 files changed

+74
-69
lines changed

2 files changed

+74
-69
lines changed

src/watch/index.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,19 @@ const flags = {
3232
description: 'Clearing the screen on rerun',
3333
default: true,
3434
},
35+
// Deprecated
3536
ignore: {
3637
type: [String],
37-
description: 'Paths & globs to exclude from being watched',
38+
description: 'Paths & globs to exclude from being watched (Deprecated: use --exclude)',
3839
},
3940
include: {
4041
type: [String],
4142
description: 'Additional paths & globs to watch',
4243
},
44+
exclude: {
45+
type: [String],
46+
description: 'Paths & globs to exclude from being watched',
47+
},
4348
} as const;
4449

4550
export const watchCommand = command({
@@ -63,8 +68,11 @@ export const watchCommand = command({
6368
noCache: argv.flags.noCache,
6469
tsconfigPath: argv.flags.tsconfig,
6570
clearScreen: argv.flags.clearScreen,
66-
ignore: argv.flags.ignore,
6771
include: argv.flags.include,
72+
exclude: [
73+
...argv.flags.ignore,
74+
...argv.flags.exclude,
75+
],
6876
ipc: true,
6977
};
7078

@@ -217,7 +225,7 @@ export const watchCommand = command({
217225
// 3rd party packages
218226
'**/{node_modules,bower_components,vendor}/**',
219227

220-
...options.ignore,
228+
...options.exclude,
221229
],
222230
ignorePermissionErrors: true,
223231
},

tests/specs/watch.ts

+63-66
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import path from 'node:path';
21
import { setTimeout } from 'node:timers/promises';
32
import { testSuite, expect } from 'manten';
43
import { createFixture } from 'fs-fixture';
@@ -222,14 +221,73 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
222221
}, 10_000);
223222
});
224223

225-
describe('ignore', ({ test }) => {
226-
test('file path & glob', async ({ onTestFinish, onTestFail }) => {
224+
describe('include', ({ test }) => {
225+
test('file path & glob', async () => {
226+
const entryFile = 'index.js';
227+
const fileA = 'file-a';
228+
const fileB = 'directory/file-b';
229+
await using fixture = await createFixture({
230+
[entryFile]: `
231+
import fs from 'fs/promises';
232+
Promise.all([
233+
fs.readFile('./${fileA}', 'utf8'),
234+
fs.readFile('./${fileB}', 'utf8')
235+
]).then(console.log, console.error);
236+
`.trim(),
237+
[fileA]: 'content-a',
238+
[fileB]: 'content-b',
239+
});
240+
241+
const tsxProcess = tsx(
242+
[
243+
'watch',
244+
'--clear-screen=false',
245+
`--include=${fileA}`,
246+
'--include=directory/*',
247+
entryFile,
248+
],
249+
fixture.path,
250+
);
251+
252+
await processInteract(
253+
tsxProcess.stdout!,
254+
[
255+
(data) => {
256+
if (data.includes("'content-a', 'content-b'")) {
257+
fixture.writeFile(fileA, 'update-a');
258+
return true;
259+
}
260+
},
261+
(data) => {
262+
if (data.includes("'update-a', 'content-b'")) {
263+
fixture.writeFile(fileB, 'update-b');
264+
return true;
265+
}
266+
},
267+
(data) => {
268+
if (data.includes("'update-a', 'update-b'")) {
269+
return true;
270+
}
271+
},
272+
],
273+
9000,
274+
);
275+
276+
tsxProcess.kill();
277+
278+
const tsxProcessResolved = await tsxProcess;
279+
expect(tsxProcessResolved.stderr).toBe('');
280+
}, 10_000);
281+
});
282+
283+
describe('exclude (ignore)', ({ test }) => {
284+
test('file path & glob', async ({ onTestFail }) => {
227285
const entryFile = 'index.js';
228286
const fileA = 'file-a.js';
229287
const fileB = 'directory/file-b.js';
230288
const depA = 'node_modules/a/index.js';
231289

232-
const fixtureGlob = await createFixture({
290+
await using fixtureGlob = await createFixture({
233291
[fileA]: 'export default "logA"',
234292
[fileB]: 'export default "logB"',
235293
[depA]: 'export default "logC"',
@@ -241,14 +299,12 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
241299
`.trim(),
242300
});
243301

244-
onTestFinish(async () => await fixtureGlob.rm());
245-
246302
const tsxProcess = tsx(
247303
[
248304
'watch',
249305
'--clear-screen=false',
250306
`--ignore=${fileA}`,
251-
`--ignore=${path.join(fixtureGlob.path, 'directory/*')}`,
307+
'--exclude=directory/*',
252308
entryFile,
253309
],
254310
fixtureGlob.path,
@@ -300,64 +356,5 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
300356
expect(p.stderr).toBe('');
301357
}, 10_000);
302358
});
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-
});
362359
});
363360
});

0 commit comments

Comments
 (0)