@mantiq/vite 0.5.16 → 0.5.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Vite.ts +30 -3
package/package.json
CHANGED
package/src/Vite.ts
CHANGED
|
@@ -41,9 +41,14 @@ export class Vite {
|
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Check for the hot file to determine dev/prod mode.
|
|
44
|
-
* Called during ViteServiceProvider.boot()
|
|
44
|
+
* Called during ViteServiceProvider.boot() and re-checked lazily
|
|
45
|
+
* if the initial check found no hot file (backend may start before Vite).
|
|
45
46
|
*/
|
|
46
47
|
async initialize(): Promise<void> {
|
|
48
|
+
await this.refreshHotFile()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private async refreshHotFile(): Promise<void> {
|
|
47
52
|
const hotPath = this.hotFilePath()
|
|
48
53
|
const file = Bun.file(hotPath)
|
|
49
54
|
if (await file.exists()) {
|
|
@@ -59,6 +64,12 @@ export class Vite {
|
|
|
59
64
|
return typeof this.hotFileCache === 'string'
|
|
60
65
|
}
|
|
61
66
|
|
|
67
|
+
/** Re-check hot file — called when manifest not found (might be dev mode). */
|
|
68
|
+
async recheckDev(): Promise<boolean> {
|
|
69
|
+
await this.refreshHotFile()
|
|
70
|
+
return this.isDev()
|
|
71
|
+
}
|
|
72
|
+
|
|
62
73
|
/** The dev server URL (from hot file or config fallback). */
|
|
63
74
|
devServerUrl(): string {
|
|
64
75
|
return typeof this.hotFileCache === 'string'
|
|
@@ -80,6 +91,9 @@ export class Vite {
|
|
|
80
91
|
async assets(entrypoints: string | string[]): Promise<string> {
|
|
81
92
|
const entries = Array.isArray(entrypoints) ? entrypoints : [entrypoints]
|
|
82
93
|
|
|
94
|
+
// Re-check hot file if not yet in dev mode (backend may have started before Vite)
|
|
95
|
+
if (!this.isDev()) await this.recheckDev()
|
|
96
|
+
|
|
83
97
|
if (this.isDev()) {
|
|
84
98
|
return this.devAssets(entries)
|
|
85
99
|
}
|
|
@@ -212,6 +226,13 @@ export class Vite {
|
|
|
212
226
|
const file = Bun.file(path)
|
|
213
227
|
|
|
214
228
|
if (!(await file.exists())) {
|
|
229
|
+
// Manifest not found — maybe Vite started after us (dev mode).
|
|
230
|
+
// Re-check the hot file before throwing a production error.
|
|
231
|
+
if (await this.recheckDev()) {
|
|
232
|
+
// We're now in dev mode — no manifest needed, caller should
|
|
233
|
+
// use devAssets() instead. Return empty manifest to avoid throw.
|
|
234
|
+
return {}
|
|
235
|
+
}
|
|
215
236
|
throw new ViteManifestNotFoundError(path)
|
|
216
237
|
}
|
|
217
238
|
|
|
@@ -224,12 +245,18 @@ export class Vite {
|
|
|
224
245
|
this.manifestCache = null
|
|
225
246
|
}
|
|
226
247
|
|
|
248
|
+
private resolvePublicDir(): string {
|
|
249
|
+
const pub = this.config.publicDir
|
|
250
|
+
if (pub.startsWith('/')) return pub
|
|
251
|
+
return this.basePath ? `${this.basePath}/${pub}` : pub
|
|
252
|
+
}
|
|
253
|
+
|
|
227
254
|
private manifestPath(): string {
|
|
228
|
-
return `${this.
|
|
255
|
+
return `${this.resolvePublicDir()}/${this.config.buildDir}/${this.config.manifest}`
|
|
229
256
|
}
|
|
230
257
|
|
|
231
258
|
private hotFilePath(): string {
|
|
232
|
-
return `${this.
|
|
259
|
+
return `${this.resolvePublicDir()}/${this.config.hotFile}`
|
|
233
260
|
}
|
|
234
261
|
|
|
235
262
|
// ── SSR ─────────────────────────────────────────────────────────────────
|