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

chore(deps): update vite #5311

Merged
merged 19 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"simple-git-hooks": "^2.9.0",
"tsx": "^4.6.1",
"typescript": "^5.2.2",
"vite": "^5.0.12",
"vite": "^5.1.4",
"vitest": "workspace:*",
"zx": "^7.2.3"
},
Expand Down
25 changes: 25 additions & 0 deletions packages/vite-node/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,31 @@ async function run(files: string[], options: CliOptions = {}) {
process.on('uncaughtException', (err) => {
console.error(c.red('[vite-node] Failed to execute file: \n'), err)
})

if (process.env.VITE_TEST_WATCHER_DEBUG) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add process.env.VITE_TEST_WATCHER_DEBUG: false in rollup config (under a condition like "production" build) so this is removed when bundling?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like I can use process.env.ROLLUP_WATCH to remove this only on build 17aa695

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this obviously breaks CI since it uses build... Let me think about a different way.

// manually check `watcher.getWatched()` to make sure entry files are ready
// since watcher.on('ready', ...) event is not reliable since 5.1.
// https://github.com/vitejs/vite/blob/63a39c244b08cf1f2299bc2c3cfddcb82070d05b/playground/hmr-ssr/__tests__/hmr.spec.ts#L1065

const nodePath = await import('node:path')

async function waitForWatched(files: string[]): Promise<void> {
while (!files.every(file => isWatched(file)))
await new Promise(resolve => setTimeout(resolve, 20))
}

function isWatched(file: string): boolean {
const watched = server.watcher.getWatched()
const resolved = nodePath.resolve(file)
const dir = nodePath.dirname(resolved)
const base = nodePath.basename(resolved)
return watched[dir]?.includes(base)
}

await waitForWatched(files)
// eslint-disable-next-line no-console
console.log('[debug] watcher is ready')
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions packages/vite-node/src/hmr/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ export function viteNodeHmrPlugin(): Plugin {
_send(payload)
emitter.emit('message', payload)
}
if (process.env.VITE_TEST_WATCHER_DEBUG) {
server.watcher.on('ready', () => {
// eslint-disable-next-line no-console
console.log('[debug] watcher is ready')
})
}
},
}
}
Loading
Loading