gajus / turbowatch

Extremely fast file change detector and task orchestrator for Node.js.
Other
938 stars 23 forks source link

warn when multiple projects use the same project path #15

Closed gajus closed 1 year ago

gajus commented 1 year ago

Imagine two services:

/apps/foo
/apps/bar

Both have the same bin/watch script:

import path from 'node:path';
import { watch } from 'turbowatch';

void watch({
  project: path.resolve('..'),
  triggers: [
    {
      expression: ['match', '*.ts', 'basename'],
      interruptible: false,
      name: 'start-server',
      onChange: async ({ spawn }) => {
        return spawn`tsx src/bin/server.ts`;
      },
    },
  ],
});

at first, this may seem correct, and it will even work. However, notice that the project resolves a relative path .. to CWD, rather than the directory, i.e. for both scripts it will be /apps. Whereas the intention was:

import path from 'node:path';
import { watch } from 'turbowatch';

void watch({
-  project: path.resolve('..'),
+ project: path.resolve(__dirname, '..'),
  triggers: [
    {
      expression: ['match', '*.ts', 'basename'],
      interruptible: false,
      name: 'start-server',
      onChange: async ({ spawn }) => {
        return spawn`tsx src/bin/server.ts`;
      },
    },
  ],
});

There are definitely valid use cases for overlapping project directories. However, in most cases this is not intentional and logging a warning would help the end user troubleshoot.

gajus commented 1 year ago

In retrospect, this feels like an overkill. We are now providing enough logs to make it clear what is being watched.