Phase 1: Rename CJS-only build/generator files to .cjs#1529
Merged
minggangw merged 2 commits intoJun 6, 2026
Conversation
Rename scripts/, rosidl_gen/, rosidl_gen/templates/, rosidl_parser/, and rostsd_gen/ modules from .js to .cjs ahead of the ESM migration (issue RobotWebTools#1358). These files run synchronously under Node (gyp, postinstall, message generation) and stay CommonJS, so they must be explicitly .cjs once "type": "module" is introduced in Phase 3. Update all references: package.json scripts/bin, binding.gyp, .npmignore, eslint globs, internal requires, the worker spawn path, the extensionless py_utils require, message-template emitted require paths, and external requires in lib/, index.js, tests, and examples. Verified with a native rebuild, full message regeneration (35 packages), and a runtime load smoke test under ROS jazzy.
There was a problem hiding this comment.
Pull request overview
This PR is Phase 1 of the ESM migration plan: it renames build-time / generator-time CommonJS modules from .js to .cjs and updates all in-repo references so these modules remain pinned to CJS ahead of adding "type": "module" later.
Changes:
- Renamed build, install, test-runner, parser, and generator modules to
.cjs(including rosidl templates) to explicitly preserve CommonJS behavior. - Updated runtime and test
require()callsites, worker spawn paths, eslint globs, binding.gyp generator/config invocations, and package.json scripts/bin entries to point at.cjs. - Updated documentation snippets that instruct running generator scripts from
node_modules.
Reviewed changes
Copilot reviewed 28 out of 43 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/test-security-related.js | Update translator require to .cjs. |
| test/test-rosidl-message-generator.js | Update packages require to .cjs. |
| test/test-primitive-types.js | Update primitive_types require to .cjs. |
| test/test-messsage-generation-overlay.js | Update generator require to .cjs. |
| test/test-message-object.js | Update packages require to .cjs. |
| test/test-lifecycle.js | Update ros_distro script invocation to .cjs. |
| test/test-init-shutdown.js | Update generator require to .cjs. |
| test/test-array-data.js | Update translator require to .cjs. |
| scripts/tag_prebuilds.cjs | CJS-pinned prebuild tagging script renamed to .cjs. |
| scripts/run_test.cjs | CJS-pinned mocha runner renamed to .cjs and referenced by npm scripts. |
| scripts/ros_distro.cjs | CJS-pinned ROS distro detector renamed to .cjs and referenced by binding.gyp/tests. |
| scripts/install.cjs | CJS-pinned install/build logic renamed to .cjs and referenced by npm scripts. |
| scripts/generate_tsd.cjs | Update rostsd_gen entrypoint require to .cjs. |
| scripts/generate_messages.cjs | Update generator + tsd generator requires to .cjs. |
| scripts/cpplint.cjs | CJS-pinned cpplint helper renamed to .cjs and referenced by npm scripts. |
| scripts/config.cjs | CJS-pinned build config helper renamed to .cjs and referenced by binding.gyp. |
| rostsd_gen/readme.md | Update example command to use generate_tsd.cjs. |
| rostsd_gen/index.cjs | Update rosidl_gen filter require to .cjs. |
| rosidl_parser/rosidl_parser.cjs | Fix py_utils require to explicitly use .cjs. |
| rosidl_parser/py_utils.cjs | CJS-pinned py utils renamed to .cjs. |
| rosidl_gen/templates/service-template.cjs | Template file renamed to .cjs for generator-time CJS. |
| rosidl_gen/templates/service-event-template.cjs | Template file renamed to .cjs for generator-time CJS. |
| rosidl_gen/templates/message-template.cjs | Update emitted require strings to point at .cjs generator helpers. |
| rosidl_gen/templates/action-template.cjs | Template file renamed to .cjs for generator-time CJS. |
| rosidl_gen/primitive_types.cjs | Generator helper renamed to .cjs. |
| rosidl_gen/packages.cjs | Update filter require to .cjs. |
| rosidl_gen/message_translator.cjs | Generator helper renamed to .cjs. |
| rosidl_gen/index.cjs | Update internal requires and worker spawn path to .cjs. |
| rosidl_gen/idl_generator.cjs | Update parser/templates/action_msgs requires to .cjs. |
| rosidl_gen/generate_worker.cjs | Update internal requires to .cjs. |
| rosidl_gen/filter.cjs | Generator helper renamed to .cjs. |
| rosidl_gen/deallocator.cjs | Generator helper renamed to .cjs. |
| rosidl_gen/action_msgs.cjs | Generator helper renamed to .cjs. |
| package.json | Update scripts/bin/format globs/prebuild hook to .cjs. |
| lib/message_introspector.js | Update translator import to .cjs. |
| lib/interface_loader.js | Update generator import to .cjs. |
| index.js | Update generator + tsd generator imports to .cjs. |
| example/rosidl/rosidl-parse-srv-example.js | Update parser import to .cjs. |
| example/rosidl/rosidl-parse-msg-example.js | Update parser import to .cjs. |
| example/rosidl/rosidl-parse-action-example.js | Update parser import to .cjs. |
| eslint.config.mjs | Update file globs to lint both .js and .cjs in generator/parser trees. |
| binding.gyp | Update generator/config and ros_version commands to .cjs. |
| .npmignore | Update ignored script filenames to .cjs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+9
to
+12
| You can update the interfaces.d.ts types manually by running the generate_tsd.js script. | ||
|
|
||
| ``` | ||
| node node_modules/rclnodejs/scripts/generate_tsd.js | ||
| node node_modules/rclnodejs/scripts/generate_tsd.cjs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First phase of the ESM migration. Renames the build- and generator-time modules that must remain CommonJS — they run synchronously under Node (node-gyp,
postinstall, message generation) — from.jsto.cjs. The explicit.cjsextension pins them to CommonJS ahead of introducing"type": "module"in Phase 3.Renamed to
.cjs(24 files)scripts/—config,cpplint,generate_messages,generate_tsd,install,ros_distro,run_test,tag_prebuildsrosidl_gen/—action_msgs,deallocator,filter,generate_worker,idl_generator,index,message_translator,packages,primitive_typesrosidl_gen/templates/—action-template,message-template,service-event-template,service-templaterosidl_parser/—py_utils,rosidl_parserrostsd_gen/—indexReference updates (19 files)
package.json—scripts+binentries point at the.cjspathsbinding.gyp— generator/config paths.npmignore/ eslint globs — include.cjsgenerate_worker.cjspy_utils→./py_utils.cjs(extensionlessrequiredoes not resolve.cjs)message-template.cjsoutput stringsindex.js,lib/interface_loader.js,lib/message_introspector.js,example/rosidl/*, and 8test/*filesFix: #1358