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

refactor(gatsby): explicitly watch delete page from gatsby develop #13099

Merged
Merged
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
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,
},
})
}
})
}