-
-
Notifications
You must be signed in to change notification settings - Fork 140
feat: ES modules (ESM) support with conditional esm or commonjs consumption #1836
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
base: main
Are you sure you want to change the base?
Conversation
…l-esm-consumption
Cases where the same java classname would result causing a name collision.
…pha testing largely
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 adds ES module (ESM) support to the NativeScript Android runtime, enabling the use of .mjs files alongside traditional CommonJS .js files. The implementation includes conditional detection of ES modules, dynamic import support, import.meta functionality, and enhanced Worker constructor capabilities.
Key Changes:
- Native C++ implementation for ES module loading, resolution, and callbacks (import.meta, dynamic imports)
- Java-side module resolution updated to handle
.mjsfile extensions - Test infrastructure modernized to verify results via console output instead of XML files
- Build tools updated to recognize and process
.mjsfiles
Reviewed Changes
Copilot reviewed 27 out of 29 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test-app/runtime/src/main/cpp/ModuleInternalCallbacks.cpp | Implements ES module resolution callback, import.meta initialization, dynamic import support, and Node.js built-in polyfills |
| test-app/runtime/src/main/cpp/ModuleInternal.cpp | Adds LoadESModule function to compile and evaluate .mjs files with proper registry management |
| test-app/runtime/src/main/java/com/tns/Module.java | Updates file resolution to check for .mjs extensions alongside .js files |
| test-app/runtime/src/main/cpp/Runtime.cpp | Registers V8 callbacks for import.meta and dynamic import() |
| test-app/tools/check_console_test_results.js | New script to verify test results from console output instead of XML files |
| test-app/runtime/src/main/java/com/tns/AppConfig.java | Adds logScriptLoading configuration option |
| test-app/build-tools/static-binding-generator/src/main/java/org/nativescript/staticbindinggenerator/Generator.java | Updates binding generator to create unique identifiers for .mjs files |
| test-app/app/src/main/assets/app/tests/testESModules.js | Test suite validating ES module loading, import.meta, and Worker enhancements |
Comments suppressed due to low confidence (2)
test-app/runtime/src/main/cpp/ModuleInternalCallbacks.cpp:1
- The regex pattern
/\/+/guses JavaScript literal syntax but this is C++ code generating a JavaScript polyfill string. The backslashes need to be escaped for the C++ string literal to produce the correct JavaScript regex. Should be\\/+to properly escape the forward slash.
#include "ModuleInternal.h"
test-app/runtime/src/main/cpp/ModuleInternalCallbacks.cpp:1
- Incorrect comment: usleep(100) provides a 100 microsecond (0.1ms) delay, but the comment says '0.1ms delay' which is correct. However, note that usleep() is deprecated in POSIX.1-2008 and removed in POSIX.1-2001; consider using nanosleep() instead.
#include "ModuleInternal.h"
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // capture static configuration to allow native lookups when currentRuntime is unavailable | ||
| Runtime.staticConfiguration = config; |
Copilot
AI
Oct 23, 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.
Missing declaration of the static staticConfiguration field. The comment indicates it's used for native lookups, but the field declaration is not visible in this diff.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Backwards compatible.