Skip to content

Phase 1: Rename CJS-only build/generator files to .cjs#1529

Merged
minggangw merged 2 commits into
RobotWebTools:developfrom
minggangw:esm-migration-phase1-3
Jun 6, 2026
Merged

Phase 1: Rename CJS-only build/generator files to .cjs#1529
minggangw merged 2 commits into
RobotWebTools:developfrom
minggangw:esm-migration-phase1-3

Conversation

@minggangw
Copy link
Copy Markdown
Member

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 .js to .cjs. The explicit .cjs extension 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_prebuilds
  • rosidl_gen/action_msgs, deallocator, filter, generate_worker, idl_generator, index, message_translator, packages, primitive_types
  • rosidl_gen/templates/action-template, message-template, service-event-template, service-template
  • rosidl_parser/py_utils, rosidl_parser
  • rostsd_gen/index

Reference updates (19 files)

  • package.jsonscripts + bin entries point at the .cjs paths
  • binding.gyp — generator/config paths
  • .npmignore / eslint globs — include .cjs
  • Internal requires — cross-references within the renamed trees
  • Worker spawn pathgenerate_worker.cjs
  • Extensionless require fixpy_utils./py_utils.cjs (extensionless require does not resolve .cjs)
  • Emitted require pathsmessage-template.cjs output strings
  • External requiresindex.js, lib/interface_loader.js, lib/message_introspector.js, example/rosidl/*, and 8 test/* files

Fix: #1358

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.
Copilot AI review requested due to automatic review settings June 5, 2026 11:18
@minggangw minggangw changed the title Phase 1: rename CJS-only build/generator files to .cjs Phase 1: Rename CJS-only build/generator files to .cjs Jun 5, 2026
Copy link
Copy Markdown

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 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 thread rostsd_gen/readme.md Outdated
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
@coveralls
Copy link
Copy Markdown

coveralls commented Jun 5, 2026

Coverage Status

coverage: 85.523%. remained the same — minggangw:esm-migration-phase1-3 into RobotWebTools:develop

@minggangw minggangw merged commit 9488c15 into RobotWebTools:develop Jun 6, 2026
20 checks passed
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.

ES Module Migration Plan for rclnodejs

3 participants