Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: privatenumber/tsx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.18.0
Choose a base ref
...
head repository: privatenumber/tsx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 157c3ec6bcf0b0a5e387080576404c00f7fd662f
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Aug 24, 2024

  1. feat(watch): deprecate ignore flag in favor or exclude flag

    privatenumber committed Aug 24, 2024
    Copy the full SHA
    157c3ec View commit details
Showing with 74 additions and 69 deletions.
  1. +11 −3 src/watch/index.ts
  2. +63 −66 tests/specs/watch.ts
14 changes: 11 additions & 3 deletions src/watch/index.ts
Original file line number Diff line number Diff line change
@@ -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({
@@ -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,
};

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

...options.ignore,
...options.exclude,
],
ignorePermissionErrors: true,
},
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';
@@ -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"',
@@ -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,
@@ -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);
});
});
});