Skip to content

Commit 6df696b

Browse files
Copiloticlanton
andcommitted
Address code review nitpicks: extract regex constant and simplify boolean expression
Co-authored-by: iclanton <5010588+iclanton@users.noreply.github.com>
1 parent 81f63c2 commit 6df696b

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

libraries/rush-lib/src/utilities/npmrcUtilities.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function _trimNpmrcFile(
6363
npmrcFileLines,
6464
process.env,
6565
supportEnvVarFallbackSyntax,
66-
filterNpmIncompatibleProperties || false
66+
filterNpmIncompatibleProperties
6767
);
6868

6969
const combinedNpmrc: string = resultLines.join('\n');
@@ -90,6 +90,15 @@ const NPM_INCOMPATIBLE_PROPERTIES: Set<string> = new Set([
9090
'publish-branch'
9191
]);
9292

93+
/**
94+
* Regular expression to extract property names from .npmrc lines.
95+
* Matches everything before '=', '[', or whitespace to capture the property name.
96+
* Examples:
97+
* "registry=https://..." -> matches "registry"
98+
* "hoist-pattern[]=..." -> matches "hoist-pattern"
99+
*/
100+
const PROPERTY_NAME_REGEX: RegExp = /^([^=\[\s]+)/;
101+
93102
/**
94103
*
95104
* @param npmrcFileLines The npmrc file's lines
@@ -127,7 +136,7 @@ export function trimNpmrcFileLines(
127136
// Check if this is a property that npm doesn't understand
128137
if (filterNpmIncompatibleProperties) {
129138
// Extract the property name (everything before the '=' or '[')
130-
const match: RegExpMatchArray | null = line.match(/^([^=\[\s]+)/);
139+
const match: RegExpMatchArray | null = line.match(PROPERTY_NAME_REGEX);
131140
if (match) {
132141
const propertyName: string = match[1];
133142

0 commit comments

Comments
 (0)