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

Watchman and symlinks #19

Closed
vjpr opened this issue Mar 15, 2023 · 8 comments
Closed

Watchman and symlinks #19

vjpr opened this issue Mar 15, 2023 · 8 comments
Labels
question Further information is requested

Comments

@vjpr
Copy link

vjpr commented Mar 15, 2023

I saw your post on watchman and symlinks here: facebook/watchman#105 (comment)

when the goal is to detected when symlinked dependencies change. The lack of symlink support makes Watchman unusable for our use case (monorepo with linked dependencies).

What exactly was the issue you ran into? I am using watchman for a pnpm monorepo just fine.

The symlinks issue is only an issue if you are symlinking outside the monorepo root. And this can be resolved by just manually resolving the symlinks.

If you want to only watch a few packages, and they are "workspace packages" (not third party and source code is in the monorepo, e.g. root/packages/a/node_modules/b -> root/packages/b), you can:

a. traverse the dependency graph to include all workspace packages abs paths
b. ...or read the node_modules dir for symlinks and resolve them

I can't remember if watchman will detect the creation of new symlinks if that is what you are looking for.

@vjpr vjpr added the enhancement New feature or request label Mar 15, 2023
@gajus gajus added question Further information is requested and removed enhancement New feature or request labels Mar 16, 2023
@gajus
Copy link
Owner

gajus commented Mar 16, 2023

The symlinks issue is only an issue if you are symlinking outside the monorepo root. And this can be resolved by just manually resolving the symlinks.

That does not align with my experience.

Project structure:

/node_modules/.pnpm/got@11.8.6/node_modules/got
/apps
  contra-api
    node_modules/got@ -> ../../../node_modules/.pnpm/got@11.8.6/node_modules/got
    src/bin/watch.ts

src/bin/watch.ts code:

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

void watch({
  project: path.resolve(__dirname, '../..'),
  triggers: [
    {
      expression: [
        'anyof',
        ['allof', ['dirname', 'node_modules'], ['match', '*', 'basename']],
        ['match', '*.ts', 'basename'],
        ['match', '*.graphql', 'basename'],
      ],
      interruptible: true,
      name: 'start-server',
      onChange: async ({ spawn }) => {
        await spawn`tsx ./src/bin/wait.ts`;
        await spawn`tsx ./src/bin/server.ts`;
      },
    },
  ],
});

I am doing:

touch apps/contra-api/node_modules/got/readme.md

and expect that watchman detects the change, but it does not.

The root of the project is /, i.e. all affected paths are within watchman's root.

@vjpr
Copy link
Author

vjpr commented Mar 16, 2023

facebook/watchman#647

Dot dirs need a special flag.

@gajus
Copy link
Owner

gajus commented Mar 16, 2023

Wish this would have been documented. Would have saved many hours of debugging.

As far as I can tell, there is no way to pass this as configuration using Node.js interface though?

@vjpr
Copy link
Author

vjpr commented Mar 16, 2023

They say make it a sibling to glob. Should just be part of the query. I'd have to check my code.

@gajus
Copy link
Owner

gajus commented Mar 16, 2023

Unfortunately, no luck.

{
  expression: [
    'anyof',
    [
      'allof',
      [ 'dirname', 'node_modules' ],
      [ 'match', '*', 'basename' ]
    ],
    [ 'match', '*.ts', 'basename' ]
  ],
  fields: [ 'name', 'size', 'mtime_ms', 'exists', 'type' ],
  glob: [ '**/*' ],
  glob_includedotfiles: true,
  relative_root: 'apps/contra-api'
}

Fails in the same setup as described above.

@gajus
Copy link
Owner

gajus commented Mar 20, 2023

Closing this as Watchman team confirmed that it isn't a feature that is currently supported.

@gajus gajus closed this as completed Mar 20, 2023
@vjpr
Copy link
Author

vjpr commented Mar 20, 2023

I found this in my code if it helps:

Screenshot 2023-03-20 at 3 38 09 pm

That nested includedotfiles might do the trick.

@gajus
Copy link
Owner

gajus commented Mar 20, 2023

Will give this a shot.

Now that #22 merged, this could be additional as a fallback backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants