MCPcopy
hub / github.com/vitejs/vite / readModifiedFile

Function readModifiedFile

packages/vite/src/node/server/hmr.ts:1136–1153  ·  view source on GitHub ↗
(file: string)

Source from the content-addressed store, hash-verified

1134// change event and sometimes this can be too early and get an empty buffer.
1135// Poll until the file's modified time has changed before reading again.
1136async function readModifiedFile(file: string): Promise<string> {
1137 const content = await fsp.readFile(file, 'utf-8')
1138 if (!content) {
1139 const mtime = (await fsp.stat(file)).mtimeMs
1140
1141 for (let n = 0; n < 10; n++) {
1142 await new Promise((r) => setTimeout(r, 10))
1143 const newMtime = (await fsp.stat(file)).mtimeMs
1144 if (newMtime !== mtime) {
1145 break
1146 }
1147 }
1148
1149 return await fsp.readFile(file, 'utf-8')
1150 } else {
1151 return content
1152 }
1153}
1154
1155export type ServerHotChannelApi = {
1156 innerEmitter: EventEmitter

Callers 1

handleHMRUpdateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected