-
-
Notifications
You must be signed in to change notification settings - Fork 27k
WebpackDevServer: (Only) Ignore node_modules if polling is required #3982
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5ddcfe2
Only ignore node_modules if polling is enabled
petetnt b32b4a0
Unify the USEPOLLING check to Chokidar rules
petetnt 058472f
Add OSX fsevents check, move the checks to react-dev-utils
petetnt 3a1e251
Currently no tests in react-dev-utils
petetnt 0394d01
Add shouldIgnoreNodeModules to files in package.json
petetnt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright (c) 2018-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// While Create React App does not use polling for watching files by default, | ||
// polling can occur if CHOKIDAR_USEPOLLING environment variable is | ||
// set to a truthy value. Excessive polling can cause CPU overloads | ||
// on some systems (see https://github.com/facebookincubator/create-react-app/issues/293), | ||
// which is why we ignore node_modules if polling is enforced. | ||
let shouldIgnoreNodeModules = false; | ||
|
||
const envForceUsePolling = process.env.CHOKIDAR_USEPOLLING; | ||
|
||
if (envForceUsePolling) { | ||
const usePollingLower = envForceUsePolling.toLowerCase(); | ||
|
||
// Chokidar rules https://github.com/paulmillr/chokidar/blob/master/index.js#L99 | ||
if ( | ||
usePollingLower === 'true' || | ||
usePollingLower === '1' || | ||
!!usePollingLower | ||
) { | ||
shouldIgnoreNodeModules = true; | ||
} | ||
} | ||
|
||
if (process.platform === 'darwin') { | ||
// On OSX polling can also occur if chokidar fails to load the | ||
// `fsevents` module. Check if the module is loaded: | ||
const cacheKeys = Object.keys(require.cache); | ||
const cachedFsEvents = | ||
require.cache[cacheKeys.find(i => i.includes('/fsevents/fsevents.js'))]; | ||
|
||
if (cachedFsEvents && cachedFsEvents.loaded) { | ||
// fsEvents is loaded, check if its WebpackDevServers | ||
let parentIsWebpackDevServer = false; | ||
let parent = cachedFsEvents.parent; | ||
|
||
while (parent && !parentIsWebpackDevServer) { | ||
if (parent.id.includes('webpack-dev-server')) { | ||
parentIsWebpackDevServer = true; | ||
} | ||
|
||
parent = parent.parent; | ||
} | ||
|
||
if (!parentIsWebpackDevServer) { | ||
shouldIgnoreNodeModules = true; | ||
} | ||
} else { | ||
shouldIgnoreNodeModules = true; | ||
} | ||
} | ||
|
||
module.exports = shouldIgnoreNodeModules; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm not super happy about this in particular. In the future we'll migrate off WDS. Do we need to hardcode this at all?
Can you explain more about why this check is necessary?
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.
Like mentioned somewhere about, the check is most likely not necessary, but anyway: consider case where ModuleX and WebpackDevServer both load Chokidar, and due to something ModuleX properly loads
fsevents
but WDS fails to do so -> WDS polls eventhough it didn't successfully load the module.That said,
I am totally okay with removing it if you are 🆗
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.
Is it WDS require-ing fsevents, or webpack? I would assume that webpack should be somewhere on the stack because WDS doesn't (afaik) do any watching manually, it just tells webpack to watch.
I'd be fine to change this line if it referenced just webpack.
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.
Sadly its WDS that requires
chokidar
to which thewatchOptions
are passed in WDS's own implementation of something similar towatchpack
which eventually requiresfsevents
.