mirror of
				https://github.com/actions/setup-node.git
				synced 2025-10-31 23:43:33 +00:00 
			
		
		
		
	Parse use-node-version key from .npmrc
This commit is contained in:
		
							parent
							
								
									626bea34d5
								
							
						
					
					
						commit
						b0f1a15a39
					
				
							
								
								
									
										3381
									
								
								dist/cache-save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3381
									
								
								dist/cache-save/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										3428
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3428
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										20
									
								
								src/util.ts
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/util.ts
									
									
									
									
									
								
							| @ -3,6 +3,7 @@ import * as exec from '@actions/exec'; | ||||
| import * as io from '@actions/io'; | ||||
| 
 | ||||
| import fs from 'fs'; | ||||
| import * as INI from 'ini'; | ||||
| import path from 'path'; | ||||
| 
 | ||||
| export function getNodeVersionFromFile(versionFilePath: string): string | null { | ||||
| @ -56,6 +57,25 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null { | ||||
|     core.info('Node version file is not JSON file'); | ||||
|   } | ||||
| 
 | ||||
|   // Try parsing the file as an NPM `.npmrc` file.
 | ||||
|   //
 | ||||
|   // If the file contents contain the use-node-version key, we conclude it's an
 | ||||
|   // `.npmrc` file.
 | ||||
|   if (contents.match(/use-node-version *=/)) { | ||||
|     const manifest = INI.parse(contents); | ||||
|     const key = 'use-node-version'; | ||||
| 
 | ||||
|     if (key in manifest && typeof manifest[key] === 'string') { | ||||
|       const version = manifest[key]; | ||||
|       core.info(`Using node version ${version} from global INI ${key}`); | ||||
|       return version; | ||||
|     } | ||||
| 
 | ||||
|     // We didn't find the key `use-node-version` in the global scope of the
 | ||||
|     // `.npmrc` file, so we return.
 | ||||
|     return null; | ||||
|   } | ||||
| 
 | ||||
|   const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m); | ||||
|   return found?.groups?.version ?? contents.trim(); | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user