Skip to content

Conversation

@NathanWalker
Copy link
Contributor

  • Conditionally detects .mjs (esm) or .js bundled code
  • Loads and executes ES modules

Backwards compatible.

@NathanWalker NathanWalker marked this pull request as draft September 7, 2025 18:11
@NathanWalker NathanWalker marked this pull request as ready for review October 23, 2025 17:08
@NathanWalker NathanWalker requested a review from Copilot October 23, 2025 17:09
Copy link

Copilot AI left a 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 .mjs file extensions
  • Test infrastructure modernized to verify results via console output instead of XML files
  • Build tools updated to recognize and process .mjs files

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 /\/+/g uses 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.

@NathanWalker NathanWalker requested a review from triniwiz November 5, 2025 03:44
@NathanWalker NathanWalker merged commit 052cb21 into main Nov 5, 2025
5 checks passed
@NathanWalker NathanWalker deleted the feat/allow-conditional-esm-consumption branch November 5, 2025 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants