Skip to content

Commit 2f84148

Browse files
committed
Replace the use of generated regular expressions with Path.isUnder
1 parent ecda861 commit 2f84148

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

apps/rush-lib/src/cli/actions/ChangeAction.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ import * as os from 'os';
55
import * as path from 'path';
66
import * as child_process from 'child_process';
77
import * as colors from 'colors';
8-
import * as lodash from 'lodash';
98

109
import inquirer = require('inquirer');
1110

1211
import {
1312
CommandLineFlagParameter,
1413
CommandLineStringParameter
1514
} from '@microsoft/ts-command-line';
16-
import { FileSystem } from '@microsoft/node-core-library';
15+
import {
16+
FileSystem,
17+
Path
18+
} from '@microsoft/node-core-library';
1719

1820
import { RushConfigurationProject } from '../../api/RushConfigurationProject';
1921
import {
@@ -211,9 +213,8 @@ export class ChangeAction extends BaseRushAction {
211213
normalizedFolder = normalizedFolder + '/';
212214
}
213215

214-
const pathRegex: RegExp = new RegExp(`^${lodash.escapeRegExp(normalizedFolder)}`, 'i');
215216
for (const folder of changedFolders) {
216-
if (folder && folder.match(pathRegex)) {
217+
if (folder && Path.isUnderOrEqual(folder, normalizedFolder)) {
217218
return true;
218219
}
219220
}

apps/rush-lib/src/utilities/VersionControl.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
import * as child_process from 'child_process';
55
import * as colors from 'colors';
6-
import * as lodash from 'lodash';
7-
import { Executable } from '@microsoft/node-core-library';
6+
import {
7+
Executable,
8+
Path
9+
} from '@microsoft/node-core-library';
810

911
const DEFAULT_BRANCH: string = 'master';
1012
const DEFAULT_REMOTE: string = 'origin';
@@ -60,16 +62,15 @@ export class VersionControl {
6062
const output: string = child_process.execSync(
6163
`git diff ${targetBranch}... --name-only --no-renames --diff-filter=A`
6264
).toString();
63-
const regex: RegExp | undefined = pathPrefix ? new RegExp(`^${lodash.escapeRegExp(pathPrefix)}`, 'i') : undefined;
6465
return output.split('\n').map((line) => {
6566
if (line) {
6667
const trimmedLine: string = line.trim();
67-
if (regex && trimmedLine.match(regex)) {
68+
if (!pathPrefix || Path.isUnderOrEqual(trimmedLine, pathPrefix)) {
6869
return trimmedLine;
6970
}
71+
} else {
72+
return undefined;
7073
}
71-
72-
return undefined;
7374
}).filter((line) => {
7475
return line && line.length > 0;
7576
}) as string[];

0 commit comments

Comments
 (0)