-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add setup-module-windows command for automated Windows module scaffolding with comprehensive TurboModule stub generation #15118
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
Conversation
@copilot add a flag to support cpp-app too .. default should be cpp-lib |
Co-authored-by: anupriya13 <[email protected]>
Added
Example usage: yarn react-native setup-module-windows --template cpp-app Changes implemented in commit c9e1eea. |
Co-authored-by: anupriya13 <[email protected]>
@copilot add setupModuleWindows in packages/@react-native-windows/cli/src/index.ts |
Co-authored-by: anupriya13 <[email protected]>
@copilot fix "yarn" nd "yarn build" issues |
Co-authored-by: anupriya13 <[email protected]>
├── windows/ | ||
│ ├── App.xaml |
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.
Removed .xaml files from the cpp-app template documentation as they are new arch only. Changes committed in 7e8b4c7.
#15118 (comment) @copilot is cpp-app expected to have xaml files? if yes then add it back |
packages/@react-native-windows/cli/src/commands/setupModuleWindows/setupModuleWindows.ts
Show resolved
Hide resolved
packages/@react-native-windows/cli/src/commands/setupModuleWindows/setupModuleWindows.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: anupriya13 <[email protected]>
Fixed yarn and yarn build issues in commit fda336c. The problems were:
Both Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Fixed linting issues with prettier formatting and removed unused skipDeps and skipBuild parameters as they were not being used in the implementation. Changes committed in 473a6d5. |
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
@copilot update pr description as per react-native-windows PR template |
Updated the PR description to follow the react-native-windows PR template format with proper sections for Description (Type of Change, Why, What), Testing, and Changelog. The description now clearly explains this is a new feature that automates Windows module setup and includes comprehensive details about functionality and testing. |
# Verbose logging | ||
yarn react-native setup-module-windows --logging | ||
|
||
# Skip dependency upgrades |
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.
Update the doc with latest changes and remove skipdeps etc
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.
Updated EXAMPLE.md with latest changes - removed references to skip-deps, skip-build options and dependency installation step from command output. Changes committed in fb908eb.
|
||
- `--logging`: Enable verbose output logging | ||
- `--no-telemetry`: Disable telemetry tracking | ||
- `--skip-deps`: Skip dependency upgrades (use current versions) |
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.
@copilot update all .md docs with latest code changes and remove skipdeps etc
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.
Updated all .md documentation files with latest code changes - removed skip-deps and skip-build options from README.md and EXAMPLE.md to reflect the current implementation. Changes committed in fb908eb.
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.
Pull Request Overview
This PR introduces a new setup-module-windows
command that automates the entire Windows module setup workflow for React Native community modules. The command streamlines the process by running init-windows, codegen-windows, and generating comprehensive C++ stub files with proper method signatures parsed from TurboModule specifications.
- Adds automated Windows project setup with smart TurboModule parsing and validation
- Generates complete C++ stub files with accurate parameter types and implementation examples
- Supports both cpp-lib (default) and cpp-app templates with robust directory detection
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.
File | Description |
---|---|
packages/@react-native-windows/telemetry/src/utils/errorUtils.ts | Adds new error code for missing TurboModule spec validation |
packages/@react-native-windows/cli/src/index.ts | Registers the new setup-module-windows command and exports internal function |
packages/@react-native-windows/cli/src/commands/setupModuleWindows/ | Complete implementation of the new command with utilities, options, tests, and documentation |
change files | Beaker change files for telemetry and CLI packages |
const methodDeclarations = methods | ||
.map(method => { | ||
const cppParams = method.parameters | ||
.map(p => { | ||
if (p.type === 'function') { | ||
// Use the full type if available, otherwise fallback to simplified version | ||
if (p.fullType) { | ||
return p.fullType; | ||
} | ||
// Handle callback functions from codegen | ||
if (p.name.includes('onSuccess') || p.name === 'callback') { | ||
return `std::function<void()> const & ${p.name}`; | ||
} else if (p.name.includes('onError')) { | ||
return `std::function<void(::React::JSValue const &)> const & ${p.name}`; | ||
} else { | ||
return `std::function<void()> const & ${p.name}`; | ||
} | ||
} else { | ||
let cppType = mapTSToCppType(p.type); | ||
// Use winrt::hstring for string parameters to match Windows conventions | ||
if (p.type === 'string') { | ||
cppType = 'winrt::hstring const&'; | ||
} | ||
return `${cppType} ${p.name}`; | ||
} | ||
}) | ||
.join(', '); |
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.
This method signature generation logic is duplicated in the C++ implementation generation section (lines 628-655). Consider extracting this parameter mapping logic into a reusable helper function to eliminate code duplication and improve maintainability.
Copilot uses AI. Check for mistakes.
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.
const helloWorldImplementation = `void ${moduleName}::helloWorld() noexcept { | ||
// Log a welcome message using Windows console | ||
OutputDebugStringA("Hello, world! Welcome to the ${moduleName} module!\\n"); | ||
}`; |
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 OutputDebugStringA function call uses a hardcoded string literal with embedded escape sequences. Consider using a raw string literal or proper string formatting to improve readability and avoid potential escaping issues.
Copilot uses AI. Check for mistakes.
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.
const registryMatch = content.match( | ||
/TurboModuleRegistry\.get(?:Enforcing)?<[^>]+>\(\s*['"`]([^'"`]+)['"`]\s*\)/, |
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 regular expression pattern uses character classes that could match unintended characters. The pattern [^'\"\\
]` should use proper escaping for the backtick character or consider using a more specific pattern to avoid potential false matches.
const registryMatch = content.match( | |
/TurboModuleRegistry\.get(?:Enforcing)?<[^>]+>\(\s*['"`]([^'"`]+)['"`]\s*\)/, | |
/TurboModuleRegistry\.get(?:Enforcing)?<[^>]+>\(\s*['"\`]([^'"\`]+)['"\`]\s*\)/, |
Copilot uses AI. Check for mistakes.
const errorSectionPattern = | ||
/REACT_SHOW_METHOD_SPEC_ERRORS\s*\(\s*\d+,\s*"([^"]+)",\s*"([^"]*)"/g; |
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 regex pattern doesn't handle escaped quotes within strings, which could lead to incorrect parsing. Consider using a more robust pattern that handles escaped characters or implement a proper string parsing mechanism for better reliability.
const errorSectionPattern = | |
/REACT_SHOW_METHOD_SPEC_ERRORS\s*\(\s*\d+,\s*"([^"]+)",\s*"([^"]*)"/g; | |
/REACT_SHOW_METHOD_SPEC_ERRORS\s*\(\s*\d+,\s*"((?:[^"\\]|\\.)*)",\s*"((?:[^"\\]|\\.)*)"/g; |
Copilot uses AI. Check for mistakes.
it('should convert package names to PascalCase', () => { | ||
const setup = new SetupModuleWindows('/test', mockOptions); | ||
// Access private method for testing | ||
const getModuleName = (setup as any).getModuleName.bind(setup); |
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.
Using any
type casting to access private methods is not a best practice for testing. Consider either making the method protected/public for testing or testing through the public interface to avoid breaking encapsulation.
Copilot uses AI. Check for mistakes.
…eflect latest changes Co-authored-by: anupriya13 <[email protected]>
@copilot update pr description as per react-native-windows PR template |
The multiple "Running init-windows..." messages occur because:
The issue is caused by conflicting spinners and the cpp-lib template trying to process an example directory. I'll fix this by preventing the second spinner creation and improving the example directory handling.
Fixed the multiple init-windows logging issue in commit d321494. The problem was:
The solution:
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
… suppressing template logging Co-authored-by: anupriya13 <[email protected]>
Updated the PR description to follow the react-native-windows PR template format. The description now includes proper sections for Description (Type of Change, Why, What), Screenshots, Testing, and Changelog with detailed information about the setup-module-windows command functionality. |
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
717bc19
into
user/anuverma/setupwindows_cli
Description
Type of Change
Why
React Native Windows developers need an automated way to set up Windows support for community modules. The current manual process involves multiple steps (running init-windows, codegen-windows, creating stub files) and is error-prone. This automation reduces setup time from hours to minutes and prevents common configuration mistakes.
What
This PR introduces the
setup-module-windows
command that automates the entire Windows module setup process:Automated Setup Pipeline:
Smart TurboModule Integration:
Key Features:
Screenshots
N/A - CLI command functionality
Testing
Changelog
Should this change be included in the release notes: yes
[General] [Added] - New
setup-module-windows
CLI command for automated Windows module scaffolding with comprehensive TurboModule stub generation✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Microsoft Reviewers: Open in CodeFlow