mirror of
				https://github.com/actions/setup-node.git
				synced 2025-11-04 01:03:33 +00:00 
			
		
		
		
	Fix node version file parsing
This commit is contained in:
		
							parent
							
								
									2a814b57e1
								
							
						
					
					
						commit
						389036835e
					
				@ -497,14 +497,14 @@ function translateArchToDistUrl(arch: string): string {
 | 
				
			|||||||
export function parseNodeVersionFile(contents: string): string {
 | 
					export function parseNodeVersionFile(contents: string): string {
 | 
				
			||||||
  let nodeVersion: string | undefined;
 | 
					  let nodeVersion: string | undefined;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
 | 
					  // Try parsing the file as an NPM `package.json`
 | 
				
			||||||
  nodeVersion = found?.groups?.version;
 | 
					  // file.
 | 
				
			||||||
 | 
					  nodeVersion = JSON.parse(contents).engines?.node;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!nodeVersion) {
 | 
					  if (!nodeVersion) {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      // Try parsing the file as an NPM `package.json`
 | 
					      const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
 | 
				
			||||||
      // file.
 | 
					      nodeVersion = found?.groups?.version;
 | 
				
			||||||
      nodeVersion = JSON.parse(contents).engines?.node;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (!nodeVersion) throw new Error();
 | 
					      if (!nodeVersion) throw new Error();
 | 
				
			||||||
    } catch (err) {
 | 
					    } catch (err) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user