-
Couldn't load subscription status.
- Fork 4
Fix expansion of options in --build and --out
#278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "cmake-rn": patch | ||
| --- | ||
|
|
||
| Fix expansion of options in --build and --out |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -74,7 +74,7 @@ const tripletOption = new Option( | |||||||||||||||||||
| const buildPathOption = new Option( | ||||||||||||||||||||
| "--build <path>", | ||||||||||||||||||||
| "Specify the build directory to store the configured CMake project", | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| ).default("{source}/build"); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const cleanOption = new Option( | ||||||||||||||||||||
| "--clean", | ||||||||||||||||||||
|
|
@@ -84,7 +84,7 @@ const cleanOption = new Option( | |||||||||||||||||||
| const outPathOption = new Option( | ||||||||||||||||||||
| "--out <path>", | ||||||||||||||||||||
| "Specify the output directory to store the final build artifacts", | ||||||||||||||||||||
| ).default(false, "./{build}/{configuration}"); | ||||||||||||||||||||
| ).default("{build}/{configuration}"); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const defineOption = new Option( | ||||||||||||||||||||
| "-D,--define <entry...>", | ||||||||||||||||||||
|
|
@@ -151,8 +151,27 @@ for (const platform of platforms) { | |||||||||||||||||||
| program = platform.amendCommand(program); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| function expandTemplate( | ||||||||||||||||||||
| input: string, | ||||||||||||||||||||
| values: Record<string, unknown>, | ||||||||||||||||||||
| ): string { | ||||||||||||||||||||
| return input.replaceAll(/{([^}]+)}/g, (_, key: string) => | ||||||||||||||||||||
| typeof values[key] === "string" ? values[key] : "", | ||||||||||||||||||||
|
||||||||||||||||||||
| typeof values[key] === "string" ? values[key] : "", | |
| String(values[key]), |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The template expansion returns an empty string for non-string values, which could silently produce incorrect paths. For example, if {configuration} is undefined or non-string, the resulting path would be malformed (e.g., build//artifacts). Consider throwing an error for missing or non-string values, or at minimum documenting this behavior.
| return input.replaceAll(/{([^}]+)}/g, (_, key: string) => | |
| typeof values[key] === "string" ? values[key] : "", | |
| ); | |
| return input.replaceAll(/{([^}]+)}/g, (_, key: string) => { | |
| if (typeof values[key] !== "string") { | |
| throw new Error(`Template variable '{${key}}' is missing or not a string (got: ${typeof values[key]})`); | |
| } | |
| return values[key] as string; | |
| }); |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The out option expansion on line 171 references {build} in its default value ({build}/{configuration}), but the template is expanded using the original baseOptions.build string (e.g., {source}/build) rather than the already-resolved build path. This creates a circular dependency issue where out will contain the literal string {source}/build/{configuration} instead of the resolved path. The expansion of out should use the already-resolved build value.
| expandTemplate(baseOptions.out, baseOptions), | |
| expandTemplate( | |
| baseOptions.out, | |
| { ...baseOptions, build: baseOptions.build } | |
| ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
expandTemplatefunction lacks documentation explaining the template syntax, expected placeholders (e.g.,{source},{build},{configuration}), and behavior when values are missing or non-string. Add a JSDoc comment describing the template format and edge case handling.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤟