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

fix(vite-node): mjs files watch not work #3982

Merged
merged 7 commits into from
Oct 3, 2023
Merged
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions packages/vite-node/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isAbsolute, join } from 'node:path'
import cac from 'cac'
import c from 'picocolors'
import { createServer } from 'vite'
Expand Down Expand Up @@ -74,11 +75,21 @@ async function run(files: string[], options: CliOptions = {}) {
cli.version(version).outputHelp()
process.exit(1)
}
const root = options.root || process.cwd()

const serverOptions = options.options
? parseServerOptions(options.options)
: {}

serverOptions.deps ??= {}
Copy link
Member

Choose a reason for hiding this comment

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

This will only work for an entry file. Here is how it's done in Vitest when using vite-node:

/^(?!.*(?:node_modules)).*\.mjs$/,

Copy link
Member Author

Choose a reason for hiding this comment

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

So I should handle this in the vite node server? I'm not sure if my solution is correct

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you should handle it in vite node server

if (serverOptions.deps.inline !== true) {
const entries = files.map((file) => {
return new RegExp(`[^${isAbsolute(file) ? file : join(root, file)}]`)
})
serverOptions.deps.inline ??= []
serverOptions.deps.inline.push(...entries)
}

const server = await createServer({
logLevel: 'error',
configFile: options.config,
Expand Down
Loading