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): Prevent crash when passing single module as options #1406
Conversation
Right now, when passing a single module with the new `--options` CLI flag, `cac` returns a string instead of an array. This causes a crash, trying to call `map` on it. ``` ❯ ./packages/vite-node/vite-node.mjs --options.deps.inline="module" hello.js file:///Users/antoine/Code/vitest/packages/vite-node/dist/cli.js:697 inline: (_b = (_a = serverOptions.deps) == null ? void 0 : _a.inline) == null ? void 0 : _b.map((dep) => { ^ TypeError: _b.map is not a function at parseServerOptions (file:///Users/antoine/Code/vitest/packages/vite-node/dist/cli.js:697:99) at CAC.run (file:///Users/antoine/Code/vitest/packages/vite-node/dist/cli.js:660:49) at CAC.runMatchedCommand (file:///Users/antoine/Code/vitest/packages/vite-node/dist/cli.js:622:34) at CAC.parse (file:///Users/antoine/Code/vitest/packages/vite-node/dist/cli.js:549:12) at file:///Users/antoine/Code/vitest/packages/vite-node/dist/cli.js:652:5 at ModuleJob.run (node:internal/modules/esm/module_job:185:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:281:24) ``` This PR updates the typings to reflect that, and makes sure that both `string` and `string[]` are properly handled.
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
@@ -108,18 +124,18 @@ function parseServerOptions(serverOptions: ViteNodeServerOptionsCLI): ViteNodeSe | |||
transformMode: { | |||
...serverOptions.transformMode, | |||
|
|||
ssr: serverOptions.transformMode?.ssr?.map(dep => new RegExp(dep)), | |||
web: serverOptions.transformMode?.ssr?.map(dep => new RegExp(dep)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a mistake here. It should have been web
instead. It's now fixed.
packages/vite-node/src/cli.ts
Outdated
return { | ||
...serverOptions, | ||
deps: { | ||
...serverOptions.deps, | ||
inline: serverOptions.deps?.inline?.map((dep) => { | ||
inline: serverOptionsDepsInline?.map((dep) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may just use toArray
(you can move it from vitest to vite-node)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in d218ee2. Much simpler indeed!
CI failed, but I believe it has nothing to do with the changes. Should I do something? |
Right now, when passing a single module with the new
--options
CLI flag,cac
returns a string instead of an array. This causes a crash, trying to callmap
on it.This PR updates the typings to reflect that, and makes sure that both
string
andstring[]
are properly handled.