Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow a dynamic interruptible setting #14

Open
gajus opened this issue Mar 14, 2023 · 0 comments
Open

allow a dynamic interruptible setting #14

gajus opened this issue Mar 14, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@gajus
Copy link
Owner

gajus commented Mar 14, 2023

There may be use cases where the desired behavior is that the service is restarted only when certain files change, e.g.

void watch({
  project: __dirname,
  triggers: [
    {
      expression: [
        'anyof',
        ['match', '*', 'basename'],
      ],
      // Marking this routine as non-interruptible will ensure that
      // next dev is not restarted when file changes are detected.
      interruptible: false,
      name: 'start-server',
      onChange: async ({ spawn }) => {
        await spawn`next dev`;
      },
    },
  ],
});

Setting { interruptible: false } is going to prevent next dev from being restarted. However, what if we want to restart the service when next.config.js changes? Then we could do something like this:

void watch({
  project: __dirname,
  triggers: [
    {
      expression: [
        'anyof',
        ['match', '*', 'basename'],
      ],
      interruptible: ({ files }) => {
        if (includes(files, 'next.config.ts')) {
          return true;
        }

        return false;
      },
      name: 'start-server',
      onChange: async ({ spawn }) => {
        await spawn`next dev`;
      },
    },
  ],
});
@gajus gajus added the enhancement New feature or request label Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant