mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
build: secondary entry-points resolving for windows (#6652)
Currently the secondary entry-points are resolved by running `grep` as a child process. This works fine on MacOS, Linux and on Windows if Git Bash is installed. With this change, the secondary entry-points will be resolved on Windows using the `findstr` command. The `findstr` command is always available on Windows and therefore Git Bash is no longer a requirement. Closes #6211
This commit is contained in:
committed by
Jeremy Elbourn
parent
9644840e4c
commit
deca032d2d
@@ -2,6 +2,7 @@ import {join} from 'path';
|
||||
import {readdirSync, lstatSync, existsSync} from 'fs';
|
||||
import {spawnSync} from 'child_process';
|
||||
import {BuildPackage} from './build-package';
|
||||
import {platform} from 'os';
|
||||
|
||||
|
||||
/**
|
||||
@@ -36,14 +37,12 @@ export function getSecondaryEntryPointsForPackage(pkg: BuildPackage) {
|
||||
|
||||
// Update the deps for each node to point to the appropriate BuildNodes.
|
||||
buildNodes.forEach(node => {
|
||||
const importStatementFindCommand = buildPackageImportStatementFindCommand(
|
||||
join(packageDir, node.name), packageName);
|
||||
|
||||
// Look for any imports that reference this same umbrella package and get the corresponding
|
||||
// BuildNode for each by looking at the import statements with grep.
|
||||
node.deps = spawnSync('grep', [
|
||||
'-Eroh',
|
||||
'--include', '*.ts',
|
||||
`from '@angular/${packageName}/.+';`,
|
||||
`${packageDir}/${node.name}/`
|
||||
])
|
||||
node.deps = spawnSync(importStatementFindCommand.binary, importStatementFindCommand.args)
|
||||
.stdout
|
||||
.toString()
|
||||
.split('\n')
|
||||
@@ -86,3 +85,19 @@ interface BuildNode {
|
||||
deps: BuildNode[];
|
||||
visited?: boolean;
|
||||
}
|
||||
|
||||
|
||||
/** Builds the command that will be executed to find all import statements for a package. */
|
||||
function buildPackageImportStatementFindCommand(searchDirectory: string, packageName: string) {
|
||||
if (platform() === 'win32') {
|
||||
return {
|
||||
binary: 'findstr',
|
||||
args: ['/r', `from.'@angular/${packageName}/.*'`, `${searchDirectory}\\*`]
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
binary: 'grep',
|
||||
args: ['-Eroh', '--include', '*.ts', `from '@angular/${packageName}/.+';`, searchDirectory]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user