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

[Bug?]: (Windows) Yarn run/exec puts literal quotes around parameters #6232

Open
1 task
rChaoz opened this issue Apr 16, 2024 · 0 comments
Open
1 task

[Bug?]: (Windows) Yarn run/exec puts literal quotes around parameters #6232

rChaoz opened this issue Apr 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@rChaoz
Copy link

rChaoz commented Apr 16, 2024

Self-service

  • I'd be willing to implement a fix

Describe the bug

Since I upgraded to berry from v1 some of my scripts are failing. To be exact, I have a script that invokes the Windows copy command like so (in "scripts" in package.json):

"other command && copy /Y src_files dest"

This used to work until the update and is now failing with "The system cannot find the file specified".
I investigated a bit and here's what I found.

Yarn exec/run v1 vs. v2

Create a file test.bat with the following content:

@echo %*

This just prints all arguments it receives. Let's try to execute it using cmd directly, then using yarn exec and yarn run for v1 and berry.

The following table contains the command used and the generated output for each method.

Command cmd (v1) yarn exec (v2) yarn exec (v1) yarn run (v2) yarn run
test.bat arg arg arg "arg" arg "arg"
test.bat "a b c" "a b c" "a b c" "a b c" "a b c" "a b c"
test.bat o="a b c" o="a b c" "o=a b c" "o=a b c" o="a b c" "o=a b c"
echo test test (error) test test test
echo "test" "test" (error) test "test" test
cmd /c echo "arg" "arg" arg arg "arg" arg
cmd /c test.bat arg arg arg arg arg arg

Notes:

For the cmd column, the command is executed directly from within cmd.exe (e.g. typing test.bat directly in shell)

For the yarn exec column, the command is executed like so: yarn exec <command> (e.g. typing yarn exec test.bat in shell).

The (error) in the yarn v1 column stands for error Couldn't find the binary echo.

For the yarn run column, I just used a new package.json with "scripts": { "thing": "<command>" } and ran it with yarn run thing.

The problem

I'm guessing that the copy command is called with "/Y" as an argument, instead of just /Y, as running copy "/Y" src dest produces the same error. The most important is the first row in the table above - that shows exactly what the problem is.

Workaround

See the last row in the table - you can append cmd /c in front of commands where the extra quotes cause problems. This works for simple commands, but I've yet to make it work with my copy command due to other issues (#6233). The actual workaround I used was using shx instead of run-script-os.
My previous setup used run-script-os with 2 scripts - one for Windows with copy and another for the rest with cp. I have switched to a single script using shx (which implements all Unix utilities in JS so they work cross-platform), so now I use shx cp and no longer have to have a separate Windows script.

Environment

System:
  OS: Windows 10 10.0.19045
  CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700KF
Binaries:
  Node: 20.8.0 - ~\AppData\Local\Temp\xfs-2e9c83c0\node.CMD
  Yarn: 4.1.1 - ~\AppData\Local\Temp\xfs-2e9c83c0\yarn.CMD
  npm: 10.2.1 - C:\Program Files\nodejs\npm.CMD

(installed with nvm)

Additional context

No response

@rChaoz rChaoz added the bug Something isn't working label Apr 16, 2024
@rChaoz rChaoz changed the title [Bug?]: (Windows) Yarn exec puts literal quotes around parameters [Bug?]: (Windows) Yarn run/exec puts literal quotes around parameters Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant