Skip to content

Commit

Permalink
feat: close server on sigint/sigterm
Browse files Browse the repository at this point in the history
close #1525
  • Loading branch information
yyx990803 committed Jan 14, 2021
1 parent 25e9c44 commit 4338d7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ export async function createServer(
}
}

process.once('SIGINT', server.close)
process.once('SIGTERM', server.close)

watcher.on('change', async (file) => {
file = normalizePath(file)
// invalidate module graph cache on file change
Expand Down
3 changes: 3 additions & 0 deletions packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export async function createPluginContainer(
}

let nestedResolveCall = 0
let closed = false

const container: PluginContainer = {
options: await (async () => {
Expand Down Expand Up @@ -573,13 +574,15 @@ export async function createPluginContainer(
},

async close() {
if (closed) return
const ctx = new Context()
await Promise.all(
plugins.map((p) => p.buildEnd && p.buildEnd.call(ctx as any))
)
await Promise.all(
plugins.map((p) => p.closeBundle && p.closeBundle.call(ctx as any))
)
closed = true
}
}

Expand Down

0 comments on commit 4338d7d

Please sign in to comment.