microsoft / ado-npm-auth

This package can automatically use the azureauth CLI to fetch tokens and update a user's .npmrc file for authenticating to Azure DevOps npm feeds.
MIT License
11 stars 9 forks source link

azureauth postinstall script - scripts/install.js is not working correctly in wsl #13

Open sivakumarmedidi opened 7 months ago

sivakumarmedidi commented 7 months ago

🔑 Authenticating to package feed... Encountered error while performing auth Error: AzureAuth is not installed. at adoPat (.nvm/versions/node/v20.12.2/lib/node_modules/ado-npm-auth/dist/ado-npm-auth.cjs:38644:19) at async generateNpmrcPat (.nvm/versions/node/v20.12.2/lib/node_modules/ado-npm-auth/dist/ado-npm-auth.cjs:38659:17) at async setNpmrcPat (.nvm/versions/node/v20.12.2/lib/node_modules/ado-npm-auth/dist/ado-npm-auth.cjs:38783:51) at async run (.nvm/versions/node/v20.12.2/lib/node_modules/ado-npm-auth/dist/ado-npm-auth.cjs:38122:9) at async.nvm/versions/node/v20.12.2/lib/node_modules/ado-npm-auth/dist/ado-npm-auth.cjs:38145:16 ❌ Authentication to package feed failed.

The azureauth executable which is supposed to be downloaded and installed via postinstall script for azureauth package is not installed correctly in wsl. So, seeing this error. Can this be fixed please?

MatanBobi commented 7 months ago

This might be related to the bug I've fixed here: https://github.com/microsoft/ado-npm-auth/pull/15 which was causing the error thrown to be irrelevant. Can we get some more details regarding the OS you're using? Is that MacOS? Linux? Windows?

sivakumarmedidi commented 7 months ago

This is happening in Windows Subsystem for Linux.

process.platform is being resolved as linux and the respective flows are commented out in scripts/install.js

  const DOWNLOAD_MAP = {
    win32: {
      x64: `azureauth-${AZUREAUTH_INFO.version}-win10-x64.zip`,
    },
    darwin: {
      x64: `azureauth-${AZUREAUTH_INFO.version}-osx-x64.tar.gz`,
      arm64: `azureauth-${AZUREAUTH_INFO.version}-osx-arm64.tar.gz`,
    },
    // TODO: support linux when the binaries are available
    // linux: {
    //   def: "azureauth.exe",
    //   x64: "azureauth-${AZUREAUTH_INFO.version}-win10-x64.zip",
    // },
  };
sivakumarmedidi commented 7 months ago

@jcreamer898, it would be great if you could help me with this. Thanks!

Stuart-Wilcox commented 7 months ago

Hey @sivakumarmedidi the issue is that the underlying library doesn't have a release for linux yet. On WSL, you can get away with using the Windows .exe, and I noticed this behaviour too.

Also confusingly there's two places that do basically the same thing of running underlying azureauth, so I'm going to try and consolidate this. Stay tuned for the fix for WSL

marcopelegrini commented 4 months ago

This is also happening when using pnpm exec ado-npm-auth instead of npm

It would be great if npm wasn't hard-coded in the npxAzureAuthCommand so I can have only one package manager being used for my project

thsparks commented 3 months ago

I'm also seeing the "AzureAuth is not installed" error when running on WSL:

🔑 Authenticating to package feed...
Encountered error while performing auth Error: AzureAuth is not installed.
    at adoPat (/home/<user>/.npm/_npx/db64d855fa186e0a/node_modules/ado-npm-auth/dist/ado-npm-auth.cjs:38678:19)
    at async generateNpmrcPat (/home/<user>/.npm/_npx/db64d855fa186e0a/node_modules/ado-npm-auth/dist/ado-npm-auth.cjs:38693:17)
    at async setNpmrcPat (/home/<user>/.npm/_npx/db64d855fa186e0a/node_modules/ado-npm-auth/dist/ado-npm-auth.cjs:38817:51)
    at async run (/home/<user>/.npm/_npx/db64d855fa186e0a/node_modules/ado-npm-auth/dist/ado-npm-auth.cjs:38130:9)
    at async /home/<user>/.npm/_npx/db64d855fa186e0a/node_modules/ado-npm-auth/dist/ado-npm-auth.cjs:38153:16
❌ Authentication to package feed failed.

@Stuart-Wilcox , you mentioned "On WSL, you can get away with using the Windows .exe". Can you elaborate on how you got that working? I see a check that looks like it would handle this automatically in the line below, but I'm still seeing the error. Not sure if there's a step I need to run beforehand to ensure it's available here. I tried just installing azureauth in Windows but it didn't seem to have an effect.

https://github.com/microsoft/ado-npm-auth/blob/988cb615c121293caa76bb3cb08d75539ad400d6/packages/ado-npm-auth/src/azureauth/azureauth-command.ts#L33

System Settings

Node version - v18.20.4 Npm version - 10.7.0 WSL - 5.15.153.1-microsoft-standard-wsl2

thsparks commented 3 months ago

Ah, I was able to get the windows.exe workaround working by following the azureauth windows install instructions found here: https://github.com/AzureAD/microsoft-authentication-cli?tab=readme-ov-file#windows. Previously, I had just been using npm to install it in windows.