mirror of
				https://github.com/actions/setup-node.git
				synced 2025-11-04 13:43:35 +00:00 
			
		
		
		
	Allow using .tool-versions for node-version-file
This enables developers which use `asdf` to use their version file Signed-off-by: Timo Sand <timo.sand@iki.fi>
This commit is contained in:
		
							parent
							
								
									ed960c9656
								
							
						
					
					
						commit
						bd33d2e93f
					
				
							
								
								
									
										2
									
								
								__tests__/data/.tool-versions
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								__tests__/data/.tool-versions
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					yarn 1.22.4
 | 
				
			||||||
 | 
					nodejs 17.6.0
 | 
				
			||||||
@ -601,6 +601,32 @@ describe('setup-node', () => {
 | 
				
			|||||||
      );
 | 
					      );
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it('reads node-version-file of `asdf` if provided', async () => {
 | 
				
			||||||
 | 
					      // Arrange
 | 
				
			||||||
 | 
					      const versionSpec = `yarn 1.22.4
 | 
				
			||||||
 | 
					nodejs 17.6.0
 | 
				
			||||||
 | 
					`;
 | 
				
			||||||
 | 
					      const versionFile = '.tool-versions';
 | 
				
			||||||
 | 
					      const expectedVersionSpec = '17.6.0';
 | 
				
			||||||
 | 
					      process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
 | 
				
			||||||
 | 
					      inputs['node-version-file'] = versionFile;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec);
 | 
				
			||||||
 | 
					      existsSpy.mockImplementationOnce(
 | 
				
			||||||
 | 
					        input => input === path.join(__dirname, 'data', versionFile)
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					      // Act
 | 
				
			||||||
 | 
					      await main.run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Assert
 | 
				
			||||||
 | 
					      expect(existsSpy).toHaveBeenCalledTimes(1);
 | 
				
			||||||
 | 
					      expect(existsSpy).toHaveReturnedWith(true);
 | 
				
			||||||
 | 
					      expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec);
 | 
				
			||||||
 | 
					      expect(logSpy).toHaveBeenCalledWith(
 | 
				
			||||||
 | 
					        `Resolved ${versionFile} as ${expectedVersionSpec}`
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it('both node-version-file and node-version are provided', async () => {
 | 
					    it('both node-version-file and node-version are provided', async () => {
 | 
				
			||||||
      inputs['node-version'] = '12';
 | 
					      inputs['node-version'] = '12';
 | 
				
			||||||
      const versionSpec = 'v14';
 | 
					      const versionSpec = 'v14';
 | 
				
			||||||
 | 
				
			|||||||
@ -468,6 +468,14 @@ function translateArchToDistUrl(arch: string): string {
 | 
				
			|||||||
export function parseNodeVersionFile(contents: string): string {
 | 
					export function parseNodeVersionFile(contents: string): string {
 | 
				
			||||||
  let nodeVersion = contents.trim();
 | 
					  let nodeVersion = contents.trim();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (contents.indexOf('nodejs') !== -1) {
 | 
				
			||||||
 | 
					    const lineWithNodeJsVersions = contents.match(/^nodejs.*$/gm);
 | 
				
			||||||
 | 
					    const firstLineWithNodeJsVersion =
 | 
				
			||||||
 | 
					      lineWithNodeJsVersions && lineWithNodeJsVersions[0];
 | 
				
			||||||
 | 
					    nodeVersion =
 | 
				
			||||||
 | 
					      firstLineWithNodeJsVersion?.replace('nodejs', '').trim() || nodeVersion;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (/^v\d/.test(nodeVersion)) {
 | 
					  if (/^v\d/.test(nodeVersion)) {
 | 
				
			||||||
    nodeVersion = nodeVersion.substring(1);
 | 
					    nodeVersion = nodeVersion.substring(1);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user