-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Feat(source-filesystem): No file watchers on build #6207
Conversation
Deploy preview for using-drupal ready! Built with commit 3699cfe |
Deploy preview for gatsbygram failed. Built with commit 3699cfe https://app.netlify.com/sites/gatsbygram/deploys/5b6b821bfdd72a65db274fdc |
}) | ||
|
||
const fsMachine = createFSMachine() | ||
let currentState = fsMachine.initialState |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
above 2 lines ashould be insidefileWatcher
function - otherwise there would be single instance of state machine even if multiple instances of plugin are running which would cause problems
Others thing that comes to my mind - ignored files/directories currently isn't exactly 1:1 - it would be good to create more complex fixture and compare if both fileWatcher and fileFinder creates same nodes |
Also worth noting - this also results in build speedup - |
I'm a bit wary that having two separate implementations for finding files will be the source of subtle bugs. As an example it looks like the Windows / AppVeyor tests for this are failing at the moment. I actually don't know how chokidar works behind the scenes, but I wonder if there's a way to use it without watchers, or to tell it to output a list of files that it will watch? A quick look at the docs seems like there's a polling method and a |
@pieh The idea would be that only one would run, determined by the @m-allanson my understanding of I thought I had pushed a fix for appveyor, I will try again. |
I echo @m-allanson's concern about having two separate implementations. But this would solve but the watchers exhaustion problem & speed up things as there's no reason to add watchers in production builds so that's wasting time. Interesting discussion paulmillr/chokidar#410 You might want to try using one of the libraries mentioned there e.g. https://github.com/kmalakoff/readdirp-walk instead of rolling your own algorithm. |
@Bouncey it'd be great to get this merged if you have a chance to try out using |
Wondering how we can push this across the finish line? This is also a blocker for internal gatsby inc stuff |
Hey @m-allanson & @thebigredgeek, I have been slammed at work recently. I plan to get the changes made as soon as possible though. |
fb12f83
to
3699cfe
Compare
Sorry for the force push, but it was a grizzly rebase. I just had a feeling I was about to add 300 commits to this bad boy. |
Deploy preview for using-postcss-sass failed. Built with commit 3699cfe https://app.netlify.com/sites/using-postcss-sass/deploys/5b6b821cfdd72a65db274fe2 |
Deploy preview for image-processing failed. Built with commit 3699cfe https://app.netlify.com/sites/image-processing/deploys/5b6b821cfdd72a65db274fe6 |
Deploy preview for using-remark failed. Built with commit 3699cfe https://app.netlify.com/sites/using-remark/deploys/5b6b821efdd72a65db274fee |
So FWIW, you can set the environment variable |
fc4ca3e
to
2116fff
Compare
I've opened issue in |
Got response from |
For reference, this PR covers a similar issue #5807 |
* master: (1595 commits) chore: update link for react-gatsby-firebase-authentication (gatsbyjs#10314) fix(www): Awesome Gatsby sidebar link (gatsbyjs#10313) Add thijs koerselman to creators list (gatsbyjs#10303) chore(release): Publish fix(gatsby-plugin-emotion): allow for React.Fragment shorthand syntax (gatsbyjs#10291) feat(www): Update starter cards (gatsbyjs#10258) Update index.md (gatsbyjs#10307) Update index.md (gatsbyjs#10306) Add thijs koerselman portfolio to sites list (gatsbyjs#10304) chore(release): Publish fix(gatsby): don't remount matchPath pages (gatsbyjs#10261) chore(release): Publish feat(gatsby-source-contentful): enable RichText for all users (gatsbyjs#10301) docs(tutorial): update 404 screenshot (gatsbyjs#10295) feat(gatsby-plugin-typescript): allow specifying babel preset options (gatsbyjs#10248) docs(gatsby-plugin-sass): fix typo in docs (gatsbyjs#10292) fix(ci): actually only run tests on non-docs changes (gatsbyjs#10287) fix(blog): rename for correct date in link (gatsbyjs#10290) Adds a more descriptive link purpose (gatsbyjs#9266) fix(www): comment out down showcase site ...
Mostly this involved including the changes from gatsbyjs#8859 into file-watcher.js
I've updated this branch with the latest changes from master. There's a Windows issue that needs clearing up, I'll look into that now. |
* master: (35 commits) feat(gatsby-source-filesystem): keep original name of remote files (gatsbyjs#9777) docs(gatsby-source-contentful): Rewrite of gatsby-source-contentful query section (gatsbyjs#7533) Update "Deploying with Now" Guide (gatsbyjs#10390) Add Matomo to list of analytics plugins (gatsbyjs#10372) Add satispay.com to showcase (gatsbyjs#10380) Adds @goblindegook/gatsby-starter-typescript (gatsbyjs#10377) Fix typo in gatsby-remark-code-repls sample `gatsby-config.json` in README (gatsbyjs#10361) fix(gatsby): fix false type conflict warning on plugin fields (gatsbyjs#10355) fix(docs): Just a small typo fix in the docs (gatsbyjs#10359) feat(gatsby-image): add onStartLoad prop (gatsbyjs#6702) fix(docs): add Ecosystem to docs sidebar, consistency with tutorial sidebar (gatsbyjs#10350) fix(www): Starters.yaml housekeeping (gatsbyjs#10354) docs: add ttag starter (gatsbyjs#10352) docs: document branching (gatsbyjs#9983) plugin checker initial commit (gatsbyjs#7062) docs: new starter features is required (gatsbyjs#10353) docs: migrated line highlighting to highlight-line, highlight-start, highlight-end (gatsbyjs#10202) Add Birra Napoli to site showcase (gatsbyjs#10344) Add BetterDocs to site showcase (gatsbyjs#10349) chore(release): Publish ...
I've swapped @gatsbyjs/core I think this is good for another review now. |
Idea here: That way we could do -const watcher = chokidar.watch(pluginOptions.path, {
+const watcher = findFiles(pluginOptions.path, {
+ watch: process.env.GATSBY_EXECUTING_COMMAND === `develop`,
ignored: [
`**/*.un~`,
`**/.DS_Store`,
`**/.gitignore`,
`**/.npmignore`,
`**/.babelrc`,
`**/yarn.lock`,
`**/bower_components`,
`**/node_modules`,
`../**/dist/**`,
...(pluginOptions.ignore || []),
],
}) here as first step, and later on we could move it to its own package and do the same in gatsby core without much effort. What are your thoughts? |
* master: (33 commits) fix(blog): youfit case study typofix Doc improvements to Visual testing with Storybook guide (gatsbyjs#10436) fix(gatsby-plugin-offline): prevent incorrect revisioning of static file by workbox (gatsbyjs#10416) fix(starters): ttag repo link fix typo in pull request template (gatsbyjs#10454) fix(www) Fix query for plugin links always ?=undefined (gatsbyjs#10453) chore(release): Publish fix(gatsby): fix extracting StaticQuery nested in shorthand fragment (gatsbyjs#10443) fix(www): avoid querying for no-cache=1 (gatsbyjs#10389) fix(gatsby-image): update typescript definitions - properly mark fields as optional (gatsbyjs#10419) refactor(gatsby): improve EnsureResources (gatsbyjs#10224) Fixed minor Typos and grammatical errors (gatsbyjs#9353) docs: add ClinciJS website into showcase (gatsbyjs#10437) docs(babel-preset-gatsby): document --save-dev flag in README (gatsbyjs#10434) fix(docs): Environment Variables Examples (gatsbyjs#10406) chore(release): Publish [gatsby-image] re: fade out base64 on full image load (gatsbyjs#7539) docs(starter-library): add example to starter library (gatsbyjs#10425) docs(gatsby-plugin-offline): specify to not HTTP-cache sw.js (gatsbyjs#10430) fix(docs): prompt => confirm (gatsbyjs#10431) ...
Thanks @pieh, that was a good idea as it turned up some issues that I'd previously overlooked. It looks like chokidar does some additional processing on paths before deciding which ones to ignore. This means that for our list of default ignores to be handled correctly, we'd need to emulate chokidar functionality in Gatsby code. This seems like a great way to introduce subtle bugs into Gatsby :) Example differenceAs an example - in the default ignores we have a couple of globs like In our new anymatch(`**/node_modules`, `some/dir/node_modules/packagename/subdir/foo/blah.js`) and so won’t ignore the file, whereas chokidar will ignore the file. We could handle this case in our own code, but there may be other differences too. ConclusionI'm going to close this PR for now, as:
Thanks @Bouncey for the original PR! |
Additional researchI spent a bit of time looking at other projects and how they handle file watching. This isn't particularly relevant, but I collected the info so might as well post it. Other watchersThere's watchman from facebook, this requires an external service to be installed. There's NSFW from Axosoft, this is a native node module and requires node-gyp to be functional before you can install it. Other projects that watch filesVSCode seems to have a different watcher for each platform (one is chokidar). Brunch uses chokidar’s |
When a site has many many files coming through
gatsby-source-filesystem
, an issue can arise where the system running gatsby runs out of watchers. This gist has a workaround for increasing the number of watchers available.The above fix does not work reliably in a
netlify
build container however. So this PR makes changes where, if theNODE_ENV
is'production'
, we use the built-infs
to traverse the directory tree looking for file paths. This will not attach any listeners.If we are in
'development'
, we still usechokidar
to monitor for file changes as per the current functionality.