Skip to content
New issue

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

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

Already on GitHub? # to your account

Make Watchman a non-hard dependency #1644

Closed
kassens opened this issue Apr 19, 2017 · 21 comments
Closed

Make Watchman a non-hard dependency #1644

kassens opened this issue Apr 19, 2017 · 21 comments

Comments

@kassens
Copy link
Member

kassens commented Apr 19, 2017

Not sure where a good place for this would be in the docs – probably the compiler section.

See #1626 for @unirey hitting this issue.

@kassens kassens added the docs label Apr 19, 2017
@ivome
Copy link

ivome commented Apr 19, 2017

It does not seem to be limited to windows, I get the same message on OS X 10.10.5

@kassens kassens changed the title Mention requirement to install Watchman on Windows Mention requirement to install Watchman Apr 19, 2017
@kassens
Copy link
Member Author

kassens commented Apr 19, 2017

Updated the title to reflect that.

@igl
Copy link

igl commented May 3, 2017

Why is it required for a static build that does not --watch?
Jenkins is not happy.

@wincent
Copy link
Contributor

wincent commented May 3, 2017

Why is it required for a static build that does not --watch?

Good question. At the moment, I think the answer may be "because nobody has taken the taken the time to isolate the parts of the code that depend on Watchman". It probably would be interesting to do so, as having a small dependency footprint is a desirable property.

@taion
Copy link
Contributor

taion commented Jun 2, 2017

I think that's the bigger/more surprising thing. It's odd to require watchman for e.g. CI environments where:

  • There's no watching going on, and
  • watchman is a bit annoying to install

@wincent
Copy link
Contributor

wincent commented Jun 2, 2017

Yep, I agree with you. Like I said over here:

I'd like to see us gracefully fallback to a non-watchman implementation when Watchman is not available (and especially when not running under --watch mode).

We'd definitely welcome a pull-request that addressed this.

@wincent wincent changed the title Mention requirement to install Watchman Make Watchman a non-hard dependency Jun 19, 2017
@wincent wincent added enhancement and removed docs labels Jun 19, 2017
@wincent
Copy link
Contributor

wincent commented Jun 19, 2017

Retitled this to reflect the desired solution, so removing the "docs" label, although we'd still welcome clearer docs in the meantime.

@ryancole
Copy link
Contributor

Would this be considered rather simple to do, or are there a some gotchas involved? I have some free time and could try my best to provide a pull request. If it's going to be a bit complicated though I would probably just let somebody else with more knowledge of the internals take a shot at it.

@wincent
Copy link
Contributor

wincent commented Jun 22, 2017

@ryancole: I don't think it is likely to be particularly difficult, but few things are ever as easy as you think they will...

If you wanted to look at the code to gauge the complexity of it I'd suggest starting here:

function buildWatchExpression(options: {extensions: Array<string>}) {
return [
'allof',
['type', 'f'],
['anyof', ...options.extensions.map(ext => ['suffix', ext])],
['not', ['match', '**/node_modules/**', 'wholename']],
['not', ['match', '**/__mocks__/**', 'wholename']],
['not', ['match', '**/__tests__/**', 'wholename']],
['not', ['match', '**/__generated__/**', 'wholename']],
];
}

That's the watch expression that the current system passes through to Watchman. To break the dependency, we need to implement simple code that knows how to identify all the files matched by that description. Doesn't look too bad, to be honest.

@henryqdineen
Copy link

👍 but I am wondering what is the suggested way around this now. Are people just installing watchman as part of the CI build?

@taion
Copy link
Contributor

taion commented Jun 26, 2017

Yeah. It requires using a sudo-enabled Travis setup. It's unfortunate.

@matthewoates
Copy link

I'm checking in the built graphql files. It's not pretty, but way prettier than adding watchman to CI.

@JCMais
Copy link

JCMais commented Jun 30, 2017

The main issue from what I can see is in this line:

const files = await RelayCodegenWatcher.queryFiles(

Code excerpt:

  async parseEverything(parserName: string): Promise<void> {
    if (this.parsers[parserName]) {
      // no need to parse
      return;
    }

    const parserConfig = this.parserConfigs[parserName];
    this.parsers[parserName] = parserConfig.getParser(parserConfig.baseDir);

    // here \/
    const files = await RelayCodegenWatcher.queryFiles(
      parserConfig.baseDir,
      parserConfig.watchmanExpression,
      parserConfig.getFileFilter
        ? parserConfig.getFileFilter(parserConfig.baseDir)
        : anyFileFilter,
    );
    this.parseFileChanges(parserName, files);
}

Watchman is being used to return all files that relay-compiler needs to parse. This makes it that, even if no --watch flag is passed, a watchman client is initialized. See source of RelayCodegenWatcher.queryFiles

@sibelius
Copy link
Contributor

image

anybody fixed this on circleci?

@robrichard
Copy link
Contributor

@sibelius I've seen it happen on our in-house Jenkins server. We add watchman watch-del-all to our job config as a workaround.

I have a PR open (#1966) to not use watchman unless you are using watch mode.

@eddies
Copy link
Contributor

eddies commented Jul 18, 2017

@sibelius I use the following in my circle.yml:

dependencies:
  cache_directories:
    - watchman
  pre:
    - if [[ ! -e watchman ]]; then git clone https://github.com/facebook/watchman.git && cd watchman/ && git checkout v4.7.0 && ./autogen.sh && ./configure && make; fi
    - cd watchman && sudo make install
    - sudo sysctl fs.inotify.max_user_watches=524288
    - sudo sysctl -p

@junosuarez
Copy link

junosuarez commented Jul 19, 2017

thanks to @eddies, we got this working on Travis by adding:

before_install:
  # dirty ugly watchman hack https://github.com/facebook/relay/issues/1644#issuecomment-315998313
  - if [[ ! -e watchman ]]; then git clone https://github.com/facebook/watchman.git && cd watchman/ && git checkout v4.7.0 && ./autogen.sh && ./configure && make  && sudo make install; fi
  - sudo sysctl fs.inotify.max_user_watches=524288
  - sudo sysctl -p
  - cd ~/build/$TRAVIS_REPO_SLUG
  # end dirty watchman hack

@Oxyaction
Copy link

Oxyaction commented Nov 20, 2017

Any suggestions? Why this issue is closed?

@taion
Copy link
Contributor

taion commented Nov 20, 2017

It was resolved. You don't need Watchman any more unless you're watching.

@steida
Copy link

steida commented Feb 24, 2018

@taion Unless we have src as current dir.

@ersinakinci
Copy link

ersinakinci commented Apr 20, 2019

I'm still hitting the watchman dependency when running

npx relay-compiler --src client --schema client/config/schema.graphql.

However, if I add the --watchman false flag, like so:

npx relay-compiler --src client --schema client/config/schema.graphql --watchman false,

everything works.

Why is watchman still enabled by default even when not using --watch?

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests