gajus/turbowatch

Ensure that expressions are evaluated using paths relative to the project root

gajus opened this issue · 0 comments

gajus commented

User reported that they are seeing these logs repeat over and over:

[18:21:34.779]   1ms debug @turbowatch #subscribe: build (3f923bd4): 21 files changed; showing first 10
files:
  - /Users/juls/src/contra/gaia/packages/money/.dist
  - /Users/juls/src/contra/gaia/packages/money/.dist/currencies.js.map
  - /Users/juls/src/contra/gaia/packages/money/.dist/currencies.js
  - /Users/juls/src/contra/gaia/packages/money/.dist/currencies.d.ts.map

Their Turbowatch script was:

import { defineConfig } from 'turbowatch';

export default defineConfig({
  project: __dirname,
  triggers: [
    {
      expression: [
        'anyof',
        [
          'allof',
          ['dirname', 'node_modules'],
          ['dirname', 'dist'],
          ['match', '*'],
        ],
        [
          'allof',
          ['not', ['dirname', 'node_modules']],
          ['dirname', 'src'],
          ['match', '*'],
        ],
      ],
      interruptible: true,
      name: 'build',
      onChange: async ({ spawn }) => {
        await spawn`pnpm run build`;
      },
    },
  ],
});

The non-obvious catch is that /Users/juls/src/contra/gaia/packages/money/.dist path includes src outside of the project root. This was obviously not intended.

The fix to match expressions against a path relative to project root.