Skip to content

Commit

Permalink
gatsby-watcher.js: explicitly start watching delete page in develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Moocar committed Apr 3, 2019
1 parent 8c50073 commit 9abfd41
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
3 changes: 3 additions & 0 deletions packages/gatsby/src/commands/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const apiRunnerNode = require(`../utils/api-runner-node`)
const telemetry = require(`gatsby-telemetry`)
const detectPortInUseAndPrompt = require(`../utils/detect-port-in-use-and-prompt`)
const onExit = require(`signal-exit`)
const queryWatcher = require(`../query/query-watcher`)

// const isInteractive = process.stdout.isTTY

Expand Down Expand Up @@ -87,6 +88,8 @@ async function startServer(program) {
// Start bootstrap process.
await bootstrap(program)

queryWatcher.startWatchDeletePage()

await createIndexHtml()

const devConfig = await webpackConfig(
Expand Down
40 changes: 16 additions & 24 deletions packages/gatsby/src/query/query-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,32 +267,24 @@ const watch = rootDir => {
filesToWatch.forEach(filePath => watcher.add(filePath))
}

if (process.env.gatsby_executing_command === `develop`) {
let bootstrapFinished = false

emitter.on(`BOOTSTRAP_FINISHED`, () => {
bootstrapFinished = true
})

exports.startWatchDeletePage = () => {
emitter.on(`DELETE_PAGE`, action => {
if (bootstrapFinished) {
const componentPath = slash(action.payload.component)
const { pages } = store.getState()
let otherPageWithTemplateExists = false
for (let page of pages.values()) {
if (slash(page.component) === componentPath) {
otherPageWithTemplateExists = true
break
}
}
if (!otherPageWithTemplateExists) {
store.dispatch({
type: `REMOVE_TEMPLATE_COMPONENT`,
payload: {
componentPath,
},
})
const componentPath = slash(action.payload.component)
const { pages } = store.getState()
let otherPageWithTemplateExists = false
for (let page of pages.values()) {
if (slash(page.component) === componentPath) {
otherPageWithTemplateExists = true
break
}
}
if (!otherPageWithTemplateExists) {
store.dispatch({
type: `REMOVE_TEMPLATE_COMPONENT`,
payload: {
componentPath,
},
})
}
})
}

0 comments on commit 9abfd41

Please sign in to comment.