-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[DRAFT] Introduce a new cli command module-windows-setup #15093
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
…urate project directory detection and file path generation (#15080) * Initial plan * Implement module-windows-setup command for streamlined RNW community module integration Co-authored-by: anupriya13 <[email protected]> * Add comprehensive error handling, validation, and enhanced output to module-windows-setup Co-authored-by: anupriya13 <[email protected]> * Complete module-windows-setup implementation with tests and comprehensive documentation Co-authored-by: anupriya13 <[email protected]> * Enhance module-windows-setup with intelligent API discovery and spec mapping Co-authored-by: anupriya13 <[email protected]> * Add comprehensive testing guide for module-windows-setup command Co-authored-by: anupriya13 <[email protected]> * Run yarn lint:fix and yarn format equivalent commands Co-authored-by: anupriya13 <[email protected]> * Fix build errors: correct telemetry codes, Node.js compatibility, and API usage Co-authored-by: anupriya13 <[email protected]> * Change files * Fix spec file discovery to exclude node_modules and validate TurboModule files Co-authored-by: anupriya13 <[email protected]> * Improve module-windows-setup to extract actual module names from existing spec files Co-authored-by: anupriya13 <[email protected]> * Add change file for module naming consistency improvements Co-authored-by: anupriya13 <[email protected]> * Fix Windows permission error and simplify dependency management Co-authored-by: anupriya13 <[email protected]> * Fix build error: make ModuleWindowsSetup properties public for testing Co-authored-by: anupriya13 <[email protected]> * Fix API extraction to generate correct method signatures from spec files instead of generic multiply method Co-authored-by: anupriya13 <[email protected]> * Add old architecture Windows directory cleanup before new arch setup Co-authored-by: anupriya13 <[email protected]> * Fix module name display in success message to show actual module name instead of generic ModuleName Co-authored-by: anupriya13 <[email protected]> * Fix TypeScript build error: use actualModuleName variable in codegenNamespace Co-authored-by: anupriya13 <[email protected]> * Fix eslint warnings: remove unnecessary escape characters in regex Co-authored-by: anupriya13 <[email protected]> * Remove vnext/codegen changes and add to .gitignore to prevent future commits Co-authored-by: anupriya13 <[email protected]> * Fix module-windows-setup to use correct package root instead of example directory Co-authored-by: anupriya13 <[email protected]> * Change Windows directory handling to always rename existing windows directory to windows_old Co-authored-by: anupriya13 <[email protected]> * Remove .gitignore changes - revert vnext/codegen entry and comment Co-authored-by: anupriya13 <[email protected]> * Comment updating package for now * Fix Node.js compatibility and TypeScript compilation issues Co-authored-by: anupriya13 <[email protected]> * Fix TypeScript syntax error in moduleWindowsSetup.ts - uncomment catch block Co-authored-by: anupriya13 <[email protected]> * Fix deprecation warnings in module-windows-setup command by suppressing Node.js warnings Co-authored-by: anupriya13 <[email protected]> * Fix module-windows-setup to parse actual API methods from codegen C++ header files Co-authored-by: anupriya13 <[email protected]> * Fix module-windows-setup to parse actual API methods from codegen files and provide WebView-like default methods Co-authored-by: anupriya13 <[email protected]> * Expand default WebView methods to include comprehensive API coverage Co-authored-by: anupriya13 <[email protected]> * Remove hardcoded WebView default methods to make module-windows-setup generic Co-authored-by: anupriya13 <[email protected]> * Fix TypeScript compilation errors by removing unused helper methods Co-authored-by: anupriya13 <[email protected]> * Enhance module-windows-setup to strictly follow codegen-driven API generation and improve logging clarity Co-authored-by: anupriya13 <[email protected]> * Fix module-windows-setup to find codegen files in windows subdirectories Co-authored-by: anupriya13 <[email protected]> * Update moduleWindowsSetup.ts * Fix module-windows-setup to read codegen files after they are written with better logging and timing Co-authored-by: anupriya13 <[email protected]> * Fix file paths in module-windows-setup to use correct subdirectory structure Co-authored-by: anupriya13 <[email protected]> * Fix module-windows-setup to use actual Windows project directory structure instead of codegen spec names Co-authored-by: anupriya13 <[email protected]> * Fix module-windows-setup to use codegenConfig.windows.outputDirectory for correct project directory detection Co-authored-by: anupriya13 <[email protected]> * Fix TypeScript compilation issues in moduleWindowsSetup Co-authored-by: anupriya13 <[email protected]> * Update moduleWindowsSetup.ts * Update moduleWindowsSetup.ts --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: anupriya13 <[email protected]>
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 module-windows-setup
command to streamline the process of adding Windows support to React Native community modules. The command automates the entire workflow from API discovery to C++ stub generation, reducing manual setup effort and improving consistency across Windows module implementations.
Key changes include:
- Intelligent API discovery from multiple sources (TypeScript/JavaScript, Android Java, iOS Objective-C, README docs)
- Automated TurboModule spec file generation with discovered methods
- C++ header and implementation stub generation with proper type mapping
- Complete Windows project setup automation
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
packages/@react-native-windows/cli/src/index.ts | Exports the new moduleWindowsSetupCommand to make it available via CLI |
packages/@react-native-windows/cli/src/commands/moduleWindowsSetup/moduleWindowsSetup.ts | Main implementation with ModuleWindowsSetup class handling API discovery, codegen, and stub generation |
packages/@react-native-windows/cli/src/commands/moduleWindowsSetup/moduleWindowsSetupOptions.ts | Command line options interface and configuration for the new command |
packages/@react-native-windows/cli/src/commands/moduleWindowsSetup/index.ts | Module exports for the moduleWindowsSetup command |
packages/@react-native-windows/cli/src/commands/moduleWindowsSetup/tests/moduleWindowsSetup.test.ts | Unit tests covering core functionality like name conversion and method parsing |
packages/@react-native-windows/cli/src/commands/moduleWindowsSetup/TESTING.md | Comprehensive testing guide with real-world module examples |
packages/@react-native-windows/cli/src/commands/moduleWindowsSetup/README.md | Complete documentation explaining command usage, options, and generated files |
packages/@react-native-windows/cli/src/commands/moduleWindowsSetup/EXAMPLE.md | Step-by-step example showing full workflow with react-native-webview |
packages/@react-native-windows/cli/tsconfig.json | Adds ES2017.Object support for Object.entries usage |
packages/@react-native-windows/cli/package.json | Updates Node.js engine requirement from 22+ to 20+ |
packages/@rnw-scripts/beachball-config/package.json | Updates Node.js engine requirement from 22.14.0+ to 20+ |
change/ files | Beachball change files documenting the new feature |
// this.verboseMessage( | ||
// 'Upgrading React Native and React Native Windows to latest versions...', | ||
// ); |
Copilot
AI
Sep 5, 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.
Remove commented-out code. If this message is needed, uncomment it; otherwise, delete these lines to keep the code clean.
Copilot uses AI. Check for mistakes.
// const packageJsonPath = path.join(this.root, 'package.json'); | ||
// const pkgJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8')); | ||
|
||
// if (!pkgJson.peerDependencies) { | ||
// pkgJson.peerDependencies = {}; | ||
// } | ||
// if (!pkgJson.devDependencies) { | ||
// pkgJson.devDependencies = {}; | ||
// } | ||
|
||
// pkgJson.peerDependencies['react-native'] = `^${rnLatest}`; | ||
// pkgJson.devDependencies['react-native-windows'] = `^${rnwLatest}`; | ||
|
||
// await fs.writeFile(packageJsonPath, JSON.stringify(pkgJson, null, 2)); | ||
// this.verboseMessage('Updated dependency versions in package.json'); | ||
|
||
// // Install updated dependencies with timeout | ||
// execSync('yarn install', { | ||
// cwd: this.root, | ||
// stdio: 'inherit', | ||
// timeout: 120000, | ||
// }); |
Copilot
AI
Sep 5, 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.
Remove large block of commented-out code. This appears to be dependency upgrade functionality that was intentionally disabled, but the commented code should be removed to improve readability.
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.
@copilot remove commented code
await Promise.all( | ||
files.map(async file => { | ||
const filePath = path.join(dirPath, file); | ||
await this.removeDirectoryRecursively(filePath); | ||
}), | ||
); |
Copilot
AI
Sep 5, 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.
Consider using sequential deletion instead of parallel Promise.all for removing directory contents. Parallel deletion of many files can overwhelm the filesystem and cause errors. Use a for-loop or reduce to process files sequentially.
await Promise.all( | |
files.map(async file => { | |
const filePath = path.join(dirPath, file); | |
await this.removeDirectoryRecursively(filePath); | |
}), | |
); | |
for (const file of files) { | |
const filePath = path.join(dirPath, file); | |
await this.removeDirectoryRecursively(filePath); | |
} |
Copilot uses AI. Check for mistakes.
// Wait a bit for codegen files to be fully written to disk | ||
this.verboseMessage('Waiting for codegen files to be written...'); | ||
await new Promise<void>(resolve => setTimeout(resolve, 1000)); |
Copilot
AI
Sep 5, 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.
Replace arbitrary timeout with proper file system polling or alternative synchronization mechanism. Hard-coded timeouts are unreliable and may not work on slower systems or under high load.
Copilot uses AI. Check for mistakes.
patterns.forEach(pattern => { | ||
let match; | ||
while ((match = pattern.exec(content)) !== null) { | ||
methods.push({ | ||
name: match[1], | ||
returnType: this.parseReturnType(match[2] || 'void'), | ||
parameters: this.parseParameters(match[0]), | ||
}); | ||
} | ||
}); |
Copilot
AI
Sep 5, 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.
Reset regex lastIndex between patterns to avoid state pollution. When using regex.exec() in a loop with the global flag, the lastIndex property persists between iterations. Add pattern.lastIndex = 0;
before the while loop.
Copilot uses AI. Check for mistakes.
npx @react-native-windows/cli module-windows-setup | ||
``` | ||
|
||
### No APIs discovered |
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 don't check or parse any andorid of ios files
return `std::function<void()> const & ${p.name}`; | ||
} | ||
} else { | ||
let cppType = this.mapTSToCppType(p.type); |
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 this file is too long , keep some functions in separate files for better grouping
pkgJson.name || 'SampleModule', | ||
); | ||
|
||
pkgJson.codegenConfig = { |
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 i think init-windows internally runs codegen-windows, why do we need to redo here?
return; | ||
} | ||
|
||
// this.verboseMessage( |
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.
remove this comment block @copilot
Description
Type of Change
Why
What is the motivation for this change? Add a few sentences describing the context and overall goals of the pull request's commits.
Resolves #15078
What
What changes were made to the codebase to solve the bug, add the functionality, etc. that you specified above.
Section A. Current Steps to integrate new arch windows template into a native module:
Section B. What are the issues?
Section C. How to make it easier?
Automate steps 2 to 5 in section A using a single command from cli i.e. “yarn react-native module-windows-setup –logging"
Step 6 is out of scope and can be done by developers
Introduce a new flag --no-example in yarn react-native init-windows cli command that ignores the creation of example file directory. There can be cases where we don't want the example directory to be created on every init windows having a flag to ignore this would be very useful. Add --no-example flag to init-windows CLI command #15092
Screenshots
Add any relevant screen captures here from before or after your changes.
CLI.module-windows-setup.mp4
CLI with other APIs after generating spec file from prompt:
CLI.module-windows-setup.mp4
Testing
If you added tests that prove your changes are effective or that your feature works, add a few sentences here detailing the added test scenarios.
Optional: Describe the tests that you ran locally to verify your changes.
Changelog
Should this change be included in the release notes: yes
Add a brief summary of the change to use in the release notes for the next release.
Introduce a new cli command module-windows-setup