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

feat(gatsby): Switch over to watchpack #15854

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ describe(`Hot Reloading`, () => {
cy.visit(`/hot-reloading`).waitForRouteChange()
})

it.skip(`works for changes in queries in themes`, () => {
it(`works for changes in queries in themes`, () => {
cy.exec(
`npm run update -- --file ../gatsby-theme-about/src/pages/hot-reloading.js --new-file scripts/new-file.js`
)
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"react": "^16.4.2",
"react-dom": "^16.4.2",
"rimraf": "^2.6.1",
"watchpack": "^1.6.0",
"xhr-mock": "^2.4.1"
},
"engines": {
Expand Down
31 changes: 17 additions & 14 deletions packages/gatsby/src/query/query-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
***/

const _ = require(`lodash`)
const chokidar = require(`chokidar`)
const Watchpack = require(`watchpack`)

const path = require(`path`)
const slash = require(`slash`)
Expand Down Expand Up @@ -227,22 +227,25 @@ const watch = async rootDir => {

const modulesThatUseGatsby = await getGatsbyDependents()

const packagePaths = modulesThatUseGatsby.map(module => {
const filesRegex = `*.+(t|j)s?(x)`
const pathRegex = `/{${filesRegex},!(node_modules)/**/${filesRegex}}`
return slash(path.join(module.path, pathRegex))
const packagePaths = modulesThatUseGatsby.map(module => slash(module.path))

var wp = new Watchpack({
aggregateTimeout: 1000,

poll: true,

followSymlinks: true,
})

watcher = chokidar
.watch([
slash(path.join(rootDir, `/src/**/*.{js,jsx,ts,tsx}`)),
...packagePaths,
])
.on(`change`, path => {
debounceCompile()
})
wp.watch(
[...filesToWatch],
[slash(path.join(rootDir, `src`)), ...packagePaths],
Date.now() - 10000
)

filesToWatch.forEach(filePath => watcher.add(filePath))
wp.on(`change`, function(filePath, mtime) {
debounceCompile()
})
}

exports.startWatchDeletePage = () => {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21041,7 +21041,7 @@ watch@~0.18.0:
exec-sh "^0.2.0"
minimist "^1.2.0"

watchpack@^1.5.0:
watchpack@^1.5.0, watchpack@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.6.0.tgz#4bc12c2ebe8aa277a71f1d3f14d685c7b446cd00"
dependencies:
Expand Down