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

Option --config of vite-node not working #3714

Open
6 tasks done
jagu-sayan opened this issue Jul 1, 2023 · 4 comments
Open
6 tasks done

Option --config of vite-node not working #3714

jagu-sayan opened this issue Jul 1, 2023 · 4 comments
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) vite-node

Comments

@jagu-sayan
Copy link

Describe the bug

The --config option is not taken into account and vite-node continues to use the vite.config.js configuration file.

Reproduction

https://stackblitz.com/edit/vitejs-vite-yn6aom?file=package.json

npx vite-node --script ./scripts/test.ts
# return `REAL_KEY`
npx vite-node --config vite-node.config.js --script ./scripts/test.ts
# BUG: return `REAL_KEY`, but should return DUMMY_KEY

System Info

System:
    OS: Linux 5.15 Arch Linux
    CPU: (32) x64 AMD Ryzen 9 7950X 16-Core Processor
    Memory: 9.92 GB / 15.19 GB
    Container: Yes
    Shell: 5.9 - /usr/sbin/zsh
  Binaries:
    Node: 18.16.1 - /mnt/wslg/runtime-dir/fnm_multishells/20564_1688209265198/bin/node
    npm: 9.7.2 - /mnt/wslg/runtime-dir/fnm_multishells/20564_1688209265198/bin/npm
    pnpm: 8.6.5 - /mnt/wslg/runtime-dir/fnm_multishells/20564_1688209265198/bin/pnpm
  npmPackages:
    @vitest/coverage-c8: ^0.32.2 => 0.32.2
    vitest: ^0.32.2 => 0.32.2

Used Package Manager

npm

Validations

@stackblitz
Copy link

stackblitz bot commented Jul 1, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@hi-ogawa
Copy link
Contributor

--script option is for "hashbang" usage https://github.com/vitest-dev/vitest/tree/main/packages/vite-node#hashbang. As explained there, when this is used, all other options are considered to be the process.argv of the script itself.

I suppose you can just remove --script in your case:

https://stackblitz.com/edit/vitejs-vite-29jczg?file=package.json

❯ npm run test:vite-node-config

> vite-starter@0.0.0 test:vite-node-config
> vite-node --config vite-node.config.js ./scripts/test.ts

DUMMY_KEY

❯ npm run test:vite-config

> vite-starter@0.0.0 test:vite-config
> vite-node ./scripts/test.ts

REAL_KEY

@sheremet-va
Copy link
Member

sheremet-va commented Jan 16, 2024

If I remember correctly, it should still process arguments that come before the file name. Only arguments after the file name are passed down as process.argv to the script. This is how Node.js CLI is supposed to work if I am not mistaken.

@hi-ogawa
Copy link
Contributor

Only arguments after the file name are passed down as process.argv to the script.

Probably it was difficult to implement this on top of cac argument handling #2793. Currently options are completely emptied when --script is given:

if (options.script) {
files = [files[0]]
options = {}
process.argv = [process.argv[0], resolve(files[0]), ...process.argv.slice(2).filter(arg => arg !== '--script' && arg !== files[0])]
}

But now looking at the other PR #3574 which changed options to be passed to the script itself, maybe it might be now easier to achieve this.


Btw, I realized #!/usr/bin/env vite-node --script doesn't work on Linux (tested on my PC) and it must be #!/usr/bin/env -S .... This caveat is explained in ts-node doc https://typestrong.org/ts-node/docs/usage/#shebang but probably missed out when adding this feature on vite-node.

@sheremet-va sheremet-va added p3-minor-bug An edge case that only affects very specific usage (priority) and removed bug labels Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) vite-node
Projects
None yet
Development

No branches or pull requests

3 participants