Skip to content

Commit

Permalink
Fix parsing of empty build props in run-windows (#13665)
Browse files Browse the repository at this point in the history
## Description

This PR fixes the two issues with `run-windows --msbuildprops`

1. When passing nothing, the command should not error and exit
2. When the string is parsed into key/value pairs, do not add empty keys to the msbuild command (which will cause msbuild to fail)

### Type of Change
- Bug fix (non-breaking change which fixes an issue)

### Why
Ran into these issues while working on PR #13634, extracted them as general bug fixes here.

### What
See above.

## Screenshots
N/A

## Testing
Verified running `run-windows` with malformed `--msbuildprops` no longer errors.

## Changelog
Should this change be included in the release notes: _yes_

Fix parsing of empty build props in run-windows
  • Loading branch information
jonthysell authored Sep 6, 2024
1 parent 409bf6e commit 6bddf6a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fix parsing of empty build props in run-windows",
"packageName": "@react-native-windows/cli",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function optionSanitizer(key: keyof RunWindowsOptions, value: any): any {
case 'buildLogDirectory':
return value === undefined ? false : true; // Strip PII
case 'msbuildprops':
return value === undefined ? 0 : value.split(',').length; // Convert to count
return typeof value === 'string' ? value.split(',').length : 0; // Convert to count
case 'release':
case 'arch':
case 'singleproc':
Expand Down
10 changes: 7 additions & 3 deletions packages/@react-native-windows/cli/src/utils/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import path from 'path';

import MSBuildTools from './msbuildtools';
import Version from './version';
import {newError} from './commandWithProgress';
import {newError, newWarn} from './commandWithProgress';
import {
RunWindowsOptions,
BuildConfig,
Expand Down Expand Up @@ -122,11 +122,15 @@ export function parseMsBuildProps(
options: RunWindowsOptions,
): Record<string, string> {
const result: Record<string, string> = {};
if (options.msbuildprops) {
if (typeof options.msbuildprops === 'string') {
const props = options.msbuildprops.split(',');
for (const prop of props) {
const propAssignment = prop.split('=');
result[propAssignment[0]] = propAssignment[1];
if (propAssignment.length === 2 && propAssignment[0].trim().length > 0) {
result[propAssignment[0].trim()] = propAssignment[1].trim();
} else if (options.logging === true) {
newWarn(`Unable to parse msbuildprop: '${prop}'`);
}
}
}
return result;
Expand Down

0 comments on commit 6bddf6a

Please sign in to comment.