Skip to content

Commit

Permalink
feat(watch): deprecate ignore flag in favor or exclude flag
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Aug 24, 2024
1 parent 474ea71 commit 157c3ec
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 69 deletions.
14 changes: 11 additions & 3 deletions src/watch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ const flags = {
description: 'Clearing the screen on rerun',
default: true,
},
// Deprecated
ignore: {
type: [String],
description: 'Paths & globs to exclude from being watched',
description: 'Paths & globs to exclude from being watched (Deprecated: use --exclude)',
},
include: {
type: [String],
description: 'Additional paths & globs to watch',
},
exclude: {
type: [String],
description: 'Paths & globs to exclude from being watched',
},
} as const;

export const watchCommand = command({
Expand All @@ -63,8 +68,11 @@ export const watchCommand = command({
noCache: argv.flags.noCache,
tsconfigPath: argv.flags.tsconfig,
clearScreen: argv.flags.clearScreen,
ignore: argv.flags.ignore,
include: argv.flags.include,
exclude: [
...argv.flags.ignore,
...argv.flags.exclude,
],
ipc: true,
};

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

...options.ignore,
...options.exclude,
],
ignorePermissionErrors: true,
},
Expand Down
129 changes: 63 additions & 66 deletions tests/specs/watch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import path from 'node:path';
import { setTimeout } from 'node:timers/promises';
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
Expand Down Expand Up @@ -222,14 +221,73 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
}, 10_000);
});

describe('ignore', ({ test }) => {
test('file path & glob', async ({ onTestFinish, onTestFail }) => {
describe('include', ({ test }) => {
test('file path & glob', async () => {
const entryFile = 'index.js';
const fileA = 'file-a';
const fileB = 'directory/file-b';
await using fixture = await createFixture({
[entryFile]: `
import fs from 'fs/promises';
Promise.all([
fs.readFile('./${fileA}', 'utf8'),
fs.readFile('./${fileB}', 'utf8')
]).then(console.log, console.error);
`.trim(),
[fileA]: 'content-a',
[fileB]: 'content-b',
});

const tsxProcess = tsx(
[
'watch',
'--clear-screen=false',
`--include=${fileA}`,
'--include=directory/*',
entryFile,
],
fixture.path,
);

await processInteract(
tsxProcess.stdout!,
[
(data) => {
if (data.includes("'content-a', 'content-b'")) {
fixture.writeFile(fileA, 'update-a');
return true;
}
},
(data) => {
if (data.includes("'update-a', 'content-b'")) {
fixture.writeFile(fileB, 'update-b');
return true;
}
},
(data) => {
if (data.includes("'update-a', 'update-b'")) {
return true;
}
},
],
9000,
);

tsxProcess.kill();

const tsxProcessResolved = await tsxProcess;
expect(tsxProcessResolved.stderr).toBe('');
}, 10_000);
});

describe('exclude (ignore)', ({ test }) => {
test('file path & glob', async ({ onTestFail }) => {
const entryFile = 'index.js';
const fileA = 'file-a.js';
const fileB = 'directory/file-b.js';
const depA = 'node_modules/a/index.js';

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

onTestFinish(async () => await fixtureGlob.rm());

const tsxProcess = tsx(
[
'watch',
'--clear-screen=false',
`--ignore=${fileA}`,
`--ignore=${path.join(fixtureGlob.path, 'directory/*')}`,
'--exclude=directory/*',
entryFile,
],
fixtureGlob.path,
Expand Down Expand Up @@ -300,64 +356,5 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
expect(p.stderr).toBe('');
}, 10_000);
});

describe('watch additional files', ({ test }) => {
test('file path & glob', async () => {
const entryFile = 'index.js';
const fileA = 'file-a';
const fileB = 'directory/file-b';
await using fixture = await createFixture({
[entryFile]: `
import fs from 'fs/promises';
Promise.all([
fs.readFile('./${fileA}', 'utf8'),
fs.readFile('./${fileB}', 'utf8')
]).then(console.log, console.error);
`.trim(),
[fileA]: 'content-a',
[fileB]: 'content-b',
});

const tsxProcess = tsx(
[
'watch',
'--clear-screen=false',
`--include=${fileA}`,
'--include=directory/*',
entryFile,
],
fixture.path,
);

await processInteract(
tsxProcess.stdout!,
[
(data) => {
if (data.includes("'content-a', 'content-b'")) {
fixture.writeFile(fileA, 'update-a');
return true;
}
},
(data) => {
if (data.includes("'update-a', 'content-b'")) {
fixture.writeFile(fileB, 'update-b');
return true;
}
},
(data) => {
if (data.includes("'update-a', 'update-b'")) {
return true;
}
},
],
9000,
);

tsxProcess.kill();

const tsxProcessResolved = await tsxProcess;
expect(tsxProcessResolved.stderr).toBe('');
}, 10_000);
});
});
});

0 comments on commit 157c3ec

Please sign in to comment.