cspotcode / npm-pwsh

Install PowerShell via npm for use in npm scripts or elsewhere.
12 stars 5 forks source link

Cannot install PWSH on Heroku Node.js dyno #22

Open markb-trustifi opened 4 years ago

markb-trustifi commented 4 years ago

The installation script works well in local installation but fails to install powershell on Heroku dyno. First of all, it installs it on Heroku out of the box, but probably deletes it immediately after the installation:

> pwsh@0.2.0 postinstall /tmp/build_2d8a9620_/node_modules/pwsh
> node ./npm_lifecycle_postinstall.js

Downloading Powershell archive from https://github.com/PowerShell/PowerShell/releases/download/v6.1.0/powershell-6.1.0-linux-x64.tar.gz to /app/.npm-pwsh/powershell-6.1.0-linux-x64.tar.gz...
Download finished.
Extracting archive to /app/.npm-pwsh/powershell-6.1.0-linux-x64...
Extracted to /app/.npm-pwsh/powershell-6.1.0-linux-x64
Symlinking from /tmp/build_2d8a9620_/node_modules/pwsh/bin/pwsh to /app/.npm-pwsh/powershell-6.1.0-linux-x64/pwsh (via /tmp/build_2d8a9620_/node_modules/pwsh/bin/pwsh)...
Done!

It says that "/app/.npm-pwsh" doesn't exist: cannot access '/app/.npm-pwsh': No such file or directory

When I run the installation manually:

spawnSync('chmod 777 ' + __dirname + '/../../node_modules/pwsh/dist/npm_lifecycle_postinstall.js', [], {shell: true});
spawnSync('node', [__dirname + '/../../node_modules/pwsh/dist/npm_lifecycle_postinstall.js']);

It creates the ".npm-pwsh" folder with correct permissions and prints the line: Downloading Powershell archive from https://github.com/PowerShell/PowerShell/releases/download/v6.1.0/powershell-6.1.0-linux-x64.tar.gz to /app/.npm-pwsh/powershell-6.1.0-linux-x64.tar.gz....

After that it stops executing.

cspotcode commented 4 years ago

Interesting, what do you think needs to be changed on our end for this to start working?

markb-trustifi commented 4 years ago

Can you have cache folder inside the node_modules/pwsh/dist instead of the $HOME/.npm-pwsh?

cspotcode commented 4 years ago

We keep the cache in a shared location since pwsh is pretty big when extracted, so we don't want to be making multiple copies. I think that'll need to remain as the default behavior, but theoretically other behaviors are possible. Someone would need to send us a pull request which somehow allows the installation location to be customized.

Perhaps it can be exposed as a JS API or bin script which can be called in your own postinstall script to extract pwsh to a custom directory. get-pwsh ./.cache/pwsh. This won't put the binaries on your PATH but should be good enough. If we expose an API, it also allows other modules to consume the API, and those modules can put binaries on the PATH.

markb-trustifi commented 4 years ago

@cspotcode I found a solution/workaround, I just run bash script with all commands in a main project's postinstall event and it is not deleted by Heroku.