In order to support running "compiler-cli" tests that use the "test_support.ts" utilities on Windows with Bazel, we need to imporve the logic that resolves NPM packages and symlinks them into a temporary directory. A more Bazel idiomatic and windows compatible way of resolving Bazel runfiles is to use the "RUNFILES_MANIFEST" if present. This ensures that the NPM packages can be also symlinked on Windows, and tests can execute properly on Windows. Read more about why this is needed here: * https://github.com/bazelbuild/bazel/issues/3726#issue-257062364 PR Close #28352
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| /**
 | |
|  * @license
 | |
|  * Copyright Google Inc. All Rights Reserved.
 | |
|  *
 | |
|  * Use of this source code is governed by an MIT-style license that can be
 | |
|  * found in the LICENSE file at https://angular.io/license
 | |
|  */
 | |
| 
 | |
| import * as fs from 'fs';
 | |
| import * as path from 'path';
 | |
| 
 | |
| /**
 | |
|  * Gets all built Angular NPM package artifacts by querying the Bazel runfiles.
 | |
|  * In case there is a runfiles manifest (e.g. on Windows), the packages are resolved
 | |
|  * through the manifest because the runfiles are not symlinked and cannot be searched
 | |
|  * within the real filesystem.
 | |
|  */
 | |
| export function getAngularPackagesFromRunfiles() {
 | |
|   // Path to the Bazel runfiles manifest if present. This file is present if runfiles are
 | |
|   // not symlinked into the runfiles directory.
 | |
|   const runfilesManifestPath = process.env.RUNFILES_MANIFEST_FILE;
 | |
| 
 | |
|   if (!runfilesManifestPath) {
 | |
|     const packageRunfilesDir = path.join(process.env.RUNFILES !, 'angular/packages');
 | |
| 
 | |
|     return fs.readdirSync(packageRunfilesDir)
 | |
|         .map(name => ({name, pkgPath: path.join(packageRunfilesDir, name, 'npm_package/')}))
 | |
|         .filter(({pkgPath}) => fs.existsSync(pkgPath));
 | |
|   }
 | |
| 
 | |
|   return fs.readFileSync(runfilesManifestPath, 'utf8')
 | |
|       .split('\n')
 | |
|       .map(mapping => mapping.split(' '))
 | |
|       .filter(([runfilePath]) => runfilePath.match(/^angular\/packages\/[\w-]+\/npm_package$/))
 | |
|       .map(([runfilePath, realPath]) => ({
 | |
|              name: path.relative('angular/packages', runfilePath).split(path.sep)[0],
 | |
|              pkgPath: realPath,
 | |
|            }));
 | |
| }
 | |
| 
 | |
| /**
 | |
|  * Resolves a NPM package from the Bazel runfiles. We need to resolve the Bazel tree
 | |
|  * artifacts using a "resolve file" because the NodeJS module resolution does not allow
 | |
|  * resolving to directory paths.
 | |
|  */
 | |
| export function resolveNpmTreeArtifact(manifestPath: string, resolveFile = 'package.json') {
 | |
|   return path.dirname(require.resolve(path.posix.join(manifestPath, resolveFile)));
 | |
| }
 |