cspotcode / npm-pwsh

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

the pwsh dependency cannot be used in Azure Pipeline on Windows hosts #19

Closed Josverl closed 4 years ago

Josverl commented 5 years ago

I really like this module, but I run into an issue where I least expected it

a package that :

package.zip

the package installs and the script has been developped / tested on windows , linux and mac if the package is installed (for testing) by an azure pipeline then :

I only can repro the failure in this setup on the windows build hosts. (all build host already have pwsh preloaded ,depedency is to cater for other machines)

##[section]Starting: npm install
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.151.2
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
npm install
========================== Starting Command Output ===========================
##[command]"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\_work\_temp\e8cb465d-f34e-4b1e-a0a8-fdaf38a93382.cmd""

> @serialport/bindings@2.0.8 install D:\_work\1\s\node_modules\@serialport\bindings
> prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild

> pwsh@0.2.0 postinstall D:\_work\1\s\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-win-x64.zip to C:\Users\VssAdministrator\.npm-pwsh\powershell-6.1.0-win32-x64.zip...
Download finished.
Extracting archive to C:\Users\VssAdministrator\.npm-pwsh\powershell-6.1.0-win32-x64...
Extracted to C:\Users\VssAdministrator\.npm-pwsh\powershell-6.1.0-win32-x64
Creating .cmd shim from D:\_work\1\s\node_modules\.bin\pwsh.cmd to C:\Users\VssAdministrator\.npm-pwsh\powershell-6.1.0-win32-x64\pwsh.exe (via D:\_work\1\s\node_modules\pwsh\bin\pwsh)...
Done!

> justatest@1.0.0 postinstall D:\_work\1\s
> pwsh hello2.ps1

The filename, directory name, or volume label syntax is incorrect.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! justatest@1.0.0 postinstall: `pwsh hello2.ps1`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the justatest@1.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\npm\cache\_logs\2019-08-12T20_29_03_242Z-debug.log
##[error]Cmd.exe exited with code '1'.
##[section]Finishing: npm install

I assume that something fails when trying to create the symlink for node_modules/.bin/pwsh but can't really tell.

build steps : do the same on 3 platforms :


trigger:
- master

strategy:
  matrix:
    linux:
      imageName: 'ubuntu-16.04'
      Windows-core:
       imagename: 'win1803'
    mac:
      imageName: 'macos-10.14'

pool:
  vmImage: $(imageName)

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
    npm run hello1
  displayName: 'run script - 1'

- script: |
    npm install
  displayName: 'npm install'

- script: |
    npm run hello1
  displayName: 'run script - 2'

the build logs ( win and linux) are attached Windows core - failing log_28_61.zip

and for comparison : linux : not failing log_22_61.zip

workaround the only known workaround i have found is not to include pwsh as a dependency

cspotcode commented 5 years ago

@Josverl It looks like you're hitting the same bug as #18.

Creating .cmd shim from D:\_work\1\s\node_modules\.bin\pwsh.cmd to C:\Users\VssAdministrator\.npm-pwsh\powershell-6.1.0-win32-x64\pwsh.exe (via D:\_work\1\s\node_modules\pwsh\bin\pwsh)...

The .cmd shims are created by a third-party library. The library has a bug where it can't create shims that delegate to a different drive letter. There's an alternative library we can use which may fix the issue. I posted complete details in the thread for #18.

I believe the fix is pretty simple. I don't have time to write it, but if someone else submits a pull-request, I'll make sure to merge and publish it.

cspotcode commented 4 years ago

Replaced by #24, which is meant to more precisely describe the necessary fix. We will wait for a pull request.