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

create .ps1 only when the user policy allows it #7953

Open
1 task done
nachoaldamav opened this issue Apr 17, 2024 · 3 comments
Open
1 task done

create .ps1 only when the user policy allows it #7953

nachoaldamav opened this issue Apr 17, 2024 · 3 comments

Comments

@nachoaldamav
Copy link
Contributor

Contribution

Describe the user story

Currently pnpm creates 3 different files for dependency binaries (bash, ps1 and CMD), in most cases the OS will select the correct binary to use, such as bash for UNIX, CMD for Windows CMD and ps1 when using Powershell.

In Powershell it is possible to limit the execution of scripts through a list of Execution Policies, normally, users will not modify that policy and will keep the default one (unrestricted for <6 powershell and RemoteSigned for >6 Powershell, also known as PWSH).

In some cases the policy may be changed to a stricter one that could block the execution of binaries and therefore break applications when using pnpm with Powershell.

Describe the solution you'd like

Automatically check if the user has a permissive policy that allows execution of .ps1 scripts by checking Get-executionPolicy. If the policy restricts it, generate only the bash and CMD files to force Powershell to use the CMD file.

Describe the drawbacks of your solution

  • Small performance degradation in Windows when installing dependencies in clean project (200ms aprox., response is memory cached)
  • Does not work with process-specific policies (Set-ExecutionPolicy -ExecutionPolicy Restricted -Scope Process) as the checker runs in a new process.
  • When using Powershell <6, it does not detect user profiles and uses the system one.

Describe alternatives you've considered

Keep it as it is. We don't have any issue opened about this problem, seems very specific but some users could find this issue at some point.

@nachoaldamav
Copy link
Contributor Author

For reference, this is what currently appears when trying to run a globally installed package if the Policy is Restricted.

PS E:\> set-ExecutionPolicy -ExecutionPolicy Restricted -Scope Process
PS E:\> rimraf -v
rimraf: File C:\Users\nacho\AppData\Local\pnpm\rimraf.ps1 cannot be loaded because running scripts is disabled 
on this system. For more information, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.

@zkochan
Copy link
Member

zkochan commented Apr 18, 2024

You should also mention that this would solve the "Y/n" prompt, when killing a process with "Ctrl+c". By the way, does npm CLI have the prompt?

@nachoaldamav
Copy link
Contributor Author

By default as pnpm creates the .ps1 file, so globally packages installed with pnpm don't have that prompt when running in Powershell.

And about npm, the CLI itself has the prompt (at least in my side), so when running npm run build it appears, even though npm also creates .ps1 files in the node_modules/.bin directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants