@@ -42,20 +42,28 @@ async function executeTask() {
4242 } else {
4343
4444 // new task version with auth support
45- var npmrcPath : string = path . join ( cwd , '.npmrc' ) ;
46- var tempNpmrcPath : string = getTempNpmrcPath ( ) ;
47- var debugLog : boolean = tl . getVariable ( 'system.debug' ) && tl . getVariable ( 'system.debug' ) . toLowerCase ( ) === 'true' ;
48-
4945 try {
50- if ( tl . osType ( ) . toLowerCase ( ) === 'windows_nt' ) {
46+
47+ var npmrcPath : string = path . join ( cwd , '.npmrc' ) ;
48+ var tempNpmrcPath : string = getTempNpmrcPath ( ) ;
49+
50+ var debugLog : boolean = tl . getVariable ( 'system.debug' ) && tl . getVariable ( 'system.debug' ) . toLowerCase ( ) === 'true' ;
51+
52+ var shouldRunAuthHelper : boolean = tl . osType ( ) . toLowerCase ( ) === 'windows_nt' && tl . exist ( npmrcPath ) ;
53+ if ( shouldRunAuthHelper ) {
54+ copyUserNpmrc ( tempNpmrcPath ) ;
5155 await runNpmAuthHelperAsync ( getNpmAuthHelperRunner ( npmrcPath , tempNpmrcPath , debugLog ) ) ;
5256 }
5357
5458 // set required environment variables for npm execution
5559 var npmExecOptions = < trm . IExecOptions > {
5660 env : extend ( { } , process . env )
5761 } ;
58- npmExecOptions . env [ 'npm_config_userconfig' ] = tempNpmrcPath ;
62+
63+ if ( shouldRunAuthHelper ) {
64+ npmExecOptions . env [ 'npm_config_userconfig' ] = tempNpmrcPath ;
65+ }
66+
5967 if ( debugLog ) {
6068 npmExecOptions . env [ 'npm_config_loglevel' ] = 'verbose' ;
6169 }
@@ -87,6 +95,25 @@ async function runNpmAuthHelperAsync(npmAuthRunner: trm.ToolRunner) : Promise<nu
8795 }
8896}
8997
98+ function copyUserNpmrc ( tempNpmrcPath : string ) {
99+ // copy the user level npmrc contents, if it exists.
100+ var currentUserNpmrcPath : string = getUserNpmrcPath ( ) ;
101+ if ( tl . exist ( currentUserNpmrcPath ) ) {
102+ tl . debug ( `Copying ${ currentUserNpmrcPath } to ${ tempNpmrcPath } ...` ) ;
103+ tl . cp ( currentUserNpmrcPath , tempNpmrcPath , /* options */ null , /* continueOnError */ true ) ;
104+ }
105+ }
106+
107+ function getUserNpmrcPath ( ) {
108+ var userNpmRc = process . env [ 'npm_config_userconfig' ] ;
109+ if ( ! userNpmRc ) {
110+ // default npm rc is located at user's home folder.
111+ userNpmRc = path . join ( process . env [ 'HOMEDRIVE' ] , process . env [ 'HOMEPATH' ] , '.npmrc' ) ;
112+ }
113+ tl . debug ( `User npm rc: ${ userNpmRc } ` ) ;
114+ return userNpmRc ;
115+ }
116+
90117async function tryRunNpmConfigAsync ( npmConfigRunner : trm . ToolRunner , execOptions : trm . IExecOptions ) {
91118 try {
92119 var code = await npmConfigRunner . exec ( execOptions ) ;
@@ -178,6 +205,7 @@ function addBuildCredProviderEnv(env: EnvironmentDictionary) : EnvironmentDictio
178205 env [ 'VSS_NUGET_ACCESSTOKEN' ] = accessToken ;
179206 env [ 'VSS_NUGET_URI_PREFIXES' ] = urlPrefixes . join ( ';' ) ;
180207 env [ 'NPM_CREDENTIALPROVIDERS_PATH' ] = credProviderPath ;
208+ env [ 'VSS_DISABLE_DEFAULTCREDENTIALPROVIDER' ] = '1' ;
181209 return env ;
182210}
183211
0 commit comments