Skip to content

Commit deca032

Browse files
devversionjelbourn
authored andcommitted
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
1 parent 9644840 commit deca032

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

tools/package-tools/secondary-entry-points.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {join} from 'path';
22
import {readdirSync, lstatSync, existsSync} from 'fs';
33
import {spawnSync} from 'child_process';
44
import {BuildPackage} from './build-package';
5+
import {platform} from 'os';
56

67

78
/**
@@ -36,14 +37,12 @@ export function getSecondaryEntryPointsForPackage(pkg: BuildPackage) {
3637

3738
// Update the deps for each node to point to the appropriate BuildNodes.
3839
buildNodes.forEach(node => {
40+
const importStatementFindCommand = buildPackageImportStatementFindCommand(
41+
join(packageDir, node.name), packageName);
42+
3943
// Look for any imports that reference this same umbrella package and get the corresponding
4044
// BuildNode for each by looking at the import statements with grep.
41-
node.deps = spawnSync('grep', [
42-
'-Eroh',
43-
'--include', '*.ts',
44-
`from '@angular/${packageName}/.+';`,
45-
`${packageDir}/${node.name}/`
46-
])
45+
node.deps = spawnSync(importStatementFindCommand.binary, importStatementFindCommand.args)
4746
.stdout
4847
.toString()
4948
.split('\n')
@@ -86,3 +85,19 @@ interface BuildNode {
8685
deps: BuildNode[];
8786
visited?: boolean;
8887
}
88+
89+
90+
/** Builds the command that will be executed to find all import statements for a package. */
91+
function buildPackageImportStatementFindCommand(searchDirectory: string, packageName: string) {
92+
if (platform() === 'win32') {
93+
return {
94+
binary: 'findstr',
95+
args: ['/r', `from.'@angular/${packageName}/.*'`, `${searchDirectory}\\*`]
96+
};
97+
} else {
98+
return {
99+
binary: 'grep',
100+
args: ['-Eroh', '--include', '*.ts', `from '@angular/${packageName}/.+';`, searchDirectory]
101+
};
102+
}
103+
}

0 commit comments

Comments
 (0)