Skip to content
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
16 changes: 10 additions & 6 deletions src/dev/dev-server2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import http from "node:http"
import path from "node:path"
import fs from "node:fs/promises"
import { isGitIgnored } from "globby"
import { Mutex } from "async-mutex"
import { getTempPathInApp } from "src/bundle/get-temp-path-in-app.js"
import { constructManifest } from "src/bundle/construct-manifest.js"
import { formatMessages } from "esbuild"
Expand Down Expand Up @@ -52,6 +53,8 @@ export const startDevServer2 = async (options: StartDevServerOptions) => {
await fs.writeFile(manifestPath, manifestContent, "utf-8")
}

const buildMutex = new Mutex()

const build = async () => {
options.onBuildStart?.()
const buildStartedAt = performance.now()
Expand Down Expand Up @@ -209,10 +212,12 @@ export const startDevServer2 = async (options: StartDevServerOptions) => {
})

const handleFileChange = async (isManifestChange: boolean = false) => {
if (isManifestChange) {
await updateManifest()
}
await build()
await buildMutex.runExclusive(async () => {
if (isManifestChange) {
await updateManifest()
}
await build()
})
}

watcher.on("change", async (file) => {
Expand All @@ -231,8 +236,7 @@ export const startDevServer2 = async (options: StartDevServerOptions) => {

// Initial build is triggered by watcher's ignoreInitial: false
// If ignoreInitial were true, you'd call:
await updateManifest()
await build()
await handleFileChange(true)

const stop = async () => {
watcher.close()
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"strict": true /* Enable all strict type-checking options. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
"paths": {
"src/*": ["./src/*"]
"src/*": ["./src/*"],
"winterspec": ["./src/index.ts"],
"winterspec/*": ["./src/*"]
},
"resolveJsonModule": true,
"rootDir": "./"
Expand Down
Loading