Skip to content

[Demo] Modernize TypeScript demos to NodeNext + ES2022#1534

Merged
minggangw merged 3 commits into
RobotWebTools:developfrom
minggangw:demos-nodenext
Jun 11, 2026
Merged

[Demo] Modernize TypeScript demos to NodeNext + ES2022#1534
minggangw merged 3 commits into
RobotWebTools:developfrom
minggangw:demos-nodenext

Conversation

@minggangw

@minggangw minggangw commented Jun 10, 2026

Copy link
Copy Markdown
Member

1. ESM migration of example/ (44 files)

Converted every CommonJS example to native ESM (.cjs.mjs):

  • Dropped 'use strict', replaced require('…/index.js').default with import rclnodejs from '…/index.js'.
  • Unwrapped main() / .then().catch() into top-level await + try/catch.
  • Preserved original copyright headers.
  • Updated all 10 example READMEs (.cjs.mjs, plus the "import rclnodejs from 'rclnodejs'" note).

2. ESM migration of demos (3 files)

  • demo/rosocket/server.cjsserver.mjs
  • demo/web/javascript/runtime.cjsruntime.mjs
  • demo/web/javascript/static.cjsstatic.mjs (adds __dirname shim via fileURLToPath)
  • Directory imports made explicit (../../rosocket/index.js, ../../../lib/runtime/index.js).
  • Updated demo/rosocket/README.md, demo/web/javascript/README.md, and demo/web/typescript/server.ts comments.

3. demo/typescript modernization (no .cjs→.mjs)

  • actions/, services/, topics/ tsconfig.json: module/moduleResolutionNodeNext, target/lib → ES2022, removed stale ./types typeRoots.
  • Updated README.md + per-folder READMEs (ES2022 wording, removed false "local type definitions" claims).

4. ESM fix for benchmarks (4 files)

benchmark/rclnodejs/**/*.js used bare require() under the root "type": "module" and threw ReferenceError: require is not defined. Converted to ESM (import { program } from 'commander', import rclnodejs from '../../../index.js'). Verified against ROS 2 Jazzy: topic + service pairs run with no exceptions.

5. CommonJS island fix for jsdoc tooling (1 file)

Added tools/jsdoc/package.json = {"type":"commonjs"} so build-index.js, regenerate-published-docs.js, and the jsdoc template publish.js (which must keep that exact name and be CJS) load correctly. Without it, npm run docs aborts with "Unable to load template: require is not defined". Verified: npm run docs now exits 0.

6. Root README ESM conversion (README.md, 13/13 lines)

  • Top publisher snippet: require('rclnodejs') + .init().then()import rclnodejs from 'rclnodejs' + top-level await.
  • Observable snippet: require('rxjs')import { throttleTime, map } from 'rxjs'.
  • Message-generation snippet: require('rclnodejs')import rclnodejs from 'rclnodejs'.
  • Quick Start: stale publisher-example.cjspublisher-example.mjs.
  • TypeScript tsconfig snippet → module: NodeNext, moduleResolution: NodeNext, target: es2022.

Fix: #1358

Copilot AI review requested due to automatic review settings June 10, 2026 09:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the TypeScript demo documentation and build configs to align with the package’s modern Node.js ESM/exports setup by switching demos to NodeNext module resolution and ES2022 targets.

Changes:

  • Update TypeScript config examples (root README + demo tsconfigs) to module/moduleResolution: NodeNext and target/lib: ES2022.
  • Remove references to local stub types/ definitions in demo docs (demos now use in-tree rclnodejs typings).
  • Refresh demo READMEs to reflect the new setup and ES2022+ positioning.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
README.md Modernizes the recommended TS compiler options snippet to NodeNext + ES2022.
demo/typescript/topics/tsconfig.json Switches topics demo TS compilation to NodeNext + ES2022 and removes local typeRoots usage.
demo/typescript/topics/README.md Updates documentation to reflect using in-tree rclnodejs typings (no local stubs).
demo/typescript/services/tsconfig.json Switches services demo TS compilation to NodeNext + ES2022 and removes local typeRoots usage.
demo/typescript/services/README.md Updates docs to reflect using in-tree rclnodejs typings rather than local stub types.
demo/typescript/README.md Updates overview wording from ES2020+ to ES2022+.
demo/typescript/actions/tsconfig.json Switches actions demo TS compilation to NodeNext + ES2022 and removes local typeRoots usage.
demo/typescript/actions/README.md Removes the (now-obsolete) types/ stub types from the folder tree.
Comments suppressed due to low confidence (1)

demo/typescript/services/tsconfig.json:24

  • include still references types/**/*, but there is no types/ directory in this demo. With rootDir: "./src", including files outside src/ would also fail compilation if a types/ folder is added back later. Remove the unused glob so rootDir/include are consistent.
    "typeRoots": ["./node_modules/@types"]
  },
  "include": [
    "src/**/*",
    "types/**/*"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 16 to 19
"typeRoots": [
"./types",
"./node_modules/@types"
]
},
@coveralls

coveralls commented Jun 10, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 91.22%. remained the same — minggangw:demos-nodenext into RobotWebTools:develop

@minggangw minggangw merged commit 10a5ef4 into RobotWebTools:develop Jun 11, 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