rclnodejs 1.5.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +25 -2
  2. package/binding.gyp +2 -0
  3. package/index.js +21 -4
  4. package/lib/action/client.js +1 -1
  5. package/lib/action/graph.js +1 -1
  6. package/lib/action/server.js +1 -1
  7. package/lib/action/server_goal_handle.js +1 -1
  8. package/lib/client.js +1 -1
  9. package/lib/clock.js +1 -1
  10. package/lib/context.js +1 -1
  11. package/lib/duration.js +1 -1
  12. package/lib/event_handler.js +1 -1
  13. package/lib/guard_condition.js +1 -1
  14. package/lib/lifecycle.js +1 -1
  15. package/lib/lifecycle_publisher.js +1 -1
  16. package/lib/logging.js +1 -1
  17. package/lib/message_serialization.js +171 -0
  18. package/lib/native_loader.js +173 -0
  19. package/lib/node.js +16 -1
  20. package/lib/parameter.js +4 -10
  21. package/lib/publisher.js +1 -1
  22. package/lib/serialization.js +1 -1
  23. package/lib/service.js +1 -1
  24. package/lib/subscription.js +17 -2
  25. package/lib/time.js +1 -1
  26. package/lib/time_source.js +1 -1
  27. package/lib/timer.js +1 -1
  28. package/lib/type_description_service.js +1 -1
  29. package/lib/utils.js +324 -0
  30. package/lib/validator.js +1 -1
  31. package/package.json +14 -18
  32. package/prebuilds/linux-arm64/humble-jammy-arm64-rclnodejs.node +0 -0
  33. package/prebuilds/linux-arm64/jazzy-noble-arm64-rclnodejs.node +0 -0
  34. package/prebuilds/linux-arm64/kilted-noble-arm64-rclnodejs.node +0 -0
  35. package/prebuilds/linux-x64/humble-jammy-x64-rclnodejs.node +0 -0
  36. package/prebuilds/linux-x64/jazzy-noble-x64-rclnodejs.node +0 -0
  37. package/prebuilds/linux-x64/kilted-noble-x64-rclnodejs.node +0 -0
  38. package/rosidl_convertor/idl_convertor.js +3 -2
  39. package/rosidl_gen/deallocator.js +1 -1
  40. package/rosidl_gen/generate_worker.js +1 -1
  41. package/rosidl_gen/generator.json +1 -1
  42. package/rosidl_gen/idl_generator.js +11 -24
  43. package/rosidl_gen/index.js +1 -1
  44. package/rosidl_gen/primitive_types.js +2 -2
  45. package/rosidl_gen/templates/action-template.js +68 -0
  46. package/rosidl_gen/templates/message-template.js +1113 -0
  47. package/rosidl_gen/templates/service-event-template.js +31 -0
  48. package/rosidl_gen/templates/service-template.js +44 -0
  49. package/rosidl_parser/rosidl_parser.js +2 -2
  50. package/scripts/install.js +113 -0
  51. package/scripts/tag_prebuilds.js +70 -0
  52. package/src/addon.cpp +3 -0
  53. package/third_party/ref-napi/index.js +15 -0
  54. package/third_party/ref-napi/lib/ref.js +1696 -0
  55. package/third_party/ref-napi/src/ref_napi_bindings.cpp +736 -0
  56. package/third_party/ref-napi/src/ref_napi_bindings.h +26 -0
  57. package/types/index.d.ts +17 -0
  58. package/types/node.d.ts +16 -1
  59. package/rosidl_gen/templates/CMakeLists.dot +0 -40
  60. package/rosidl_gen/templates/action.dot +0 -50
  61. package/rosidl_gen/templates/message.dot +0 -851
  62. package/rosidl_gen/templates/package.dot +0 -16
  63. package/rosidl_gen/templates/service.dot +0 -26
  64. package/rosidl_gen/templates/service_event.dot +0 -10
@@ -0,0 +1,31 @@
1
+ // Copyright (c) 2025, The Robot Web Tools Contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ function generateServiceEvent(data) {
16
+ const serviceInfo = data.serviceInfo;
17
+
18
+ return `# This file is automatically generated by rosidl_gen
19
+ #
20
+ # *** DO NOT EDIT directly
21
+ #
22
+
23
+ service_msgs/ServiceEventInfo info
24
+
25
+ ${serviceInfo.pkgName}/${serviceInfo.interfaceName}_Request[<=1] request
26
+
27
+ ${serviceInfo.pkgName}/${serviceInfo.interfaceName}_Response[<=1] response
28
+ `;
29
+ }
30
+
31
+ module.exports = generateServiceEvent;
@@ -0,0 +1,44 @@
1
+ // Copyright (c) 2025, The Robot Web Tools Contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ function generateService(data) {
16
+ const serviceInfo = data.serviceInfo;
17
+ const className = `${serviceInfo.pkgName}__${serviceInfo.subFolder}__${serviceInfo.interfaceName}`;
18
+
19
+ return `// This file is automatically generated by rclnodejs
20
+ //
21
+ // *** DO NOT EDIT directly
22
+ //
23
+
24
+ 'use strict';
25
+
26
+ class ${className} {
27
+ static get Request() {
28
+ return require('./${className}_Request.js');
29
+ }
30
+
31
+ static get Response() {
32
+ return require('./${className}_Response.js');
33
+ }
34
+
35
+ static type() {
36
+ return {pkgName: '${serviceInfo.pkgName}', subFolder: '${serviceInfo.subFolder}', interfaceName: '${serviceInfo.interfaceName}'};
37
+ }
38
+ }
39
+
40
+ module.exports = ${className};
41
+ `;
42
+ }
43
+
44
+ module.exports = generateService;
@@ -14,7 +14,7 @@
14
14
 
15
15
  'use strict';
16
16
 
17
- const compareVersions = require('compare-versions');
17
+ const { compareVersions } = require('../lib/utils.js');
18
18
  const path = require('path');
19
19
  const execFile = require('child_process').execFile;
20
20
 
@@ -22,7 +22,7 @@ const pythonExecutable = require('./py_utils').getPythonExecutable('python3');
22
22
 
23
23
  const contextSupportedVersion = '21.0.0.0';
24
24
  const currentVersion = process.version;
25
- const isContextSupported = compareVersions.compare(
25
+ const isContextSupported = compareVersions(
26
26
  currentVersion.substring(1, currentVersion.length),
27
27
  contextSupportedVersion,
28
28
  '>='
@@ -0,0 +1,113 @@
1
+ // Copyright (c) 2025, The Robot Web Tools Contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ const fs = require('fs');
16
+ const path = require('path');
17
+ const { execSync } = require('child_process');
18
+ const { detectUbuntuCodename } = require('../lib/utils');
19
+
20
+ function getRosDistro() {
21
+ return process.env.ROS_DISTRO || null;
22
+ }
23
+
24
+ function checkPrebuiltBinary() {
25
+ const platform = process.platform;
26
+ const arch = process.arch;
27
+
28
+ // Only Linux has prebuilt binaries
29
+ if (platform !== 'linux') {
30
+ console.log(
31
+ `Platform ${platform} does not have prebuilt binaries, will build from source`
32
+ );
33
+ return false;
34
+ }
35
+
36
+ const ubuntuCodename = detectUbuntuCodename();
37
+ const rosDistro = getRosDistro();
38
+
39
+ if (!ubuntuCodename || !rosDistro) {
40
+ console.log(
41
+ 'Cannot detect Ubuntu codename or ROS distribution, will build from source'
42
+ );
43
+ return false;
44
+ }
45
+
46
+ // Check for the specific prebuilt binary
47
+ const prebuildDir = path.join(
48
+ __dirname,
49
+ '..',
50
+ 'prebuilds',
51
+ `${platform}-${arch}`
52
+ );
53
+ const expectedBinary = `${rosDistro}-${ubuntuCodename}-${arch}-rclnodejs.node`;
54
+ const binaryPath = path.join(prebuildDir, expectedBinary);
55
+
56
+ if (fs.existsSync(binaryPath)) {
57
+ console.log(`✓ Found prebuilt binary: ${expectedBinary}`);
58
+ console.log(` Platform: ${platform}, Arch: ${arch}`);
59
+ console.log(` Ubuntu: ${ubuntuCodename}, ROS: ${rosDistro}`);
60
+ return true;
61
+ }
62
+
63
+ console.log(
64
+ `✗ No prebuilt binary found for ${rosDistro}-${ubuntuCodename}-${arch}`
65
+ );
66
+
67
+ // List available binaries for debugging
68
+ if (fs.existsSync(prebuildDir)) {
69
+ const availableBinaries = fs
70
+ .readdirSync(prebuildDir)
71
+ .filter((f) => f.endsWith('.node'));
72
+ if (availableBinaries.length > 0) {
73
+ console.log(
74
+ ' Available prebuilt binaries:',
75
+ availableBinaries.join(', ')
76
+ );
77
+ }
78
+ }
79
+
80
+ return false;
81
+ }
82
+
83
+ function buildFromSource() {
84
+ console.log('\n=== Building rclnodejs from source ===');
85
+ try {
86
+ execSync('npm run rebuild', {
87
+ stdio: 'inherit',
88
+ cwd: path.join(__dirname, '..'),
89
+ timeout: 600000, // 10 minute timeout
90
+ });
91
+ console.log('✓ Successfully built from source\n');
92
+ } catch (error) {
93
+ console.error('✗ Failed to build from source:', error.message);
94
+ process.exit(1);
95
+ }
96
+ }
97
+
98
+ function main() {
99
+ console.log('\n=== Installing rclnodejs ===\n');
100
+
101
+ if (checkPrebuiltBinary()) {
102
+ console.log('✓ Installation complete - using prebuilt binary\n');
103
+ } else {
104
+ console.log('→ Building from source...\n');
105
+ buildFromSource();
106
+ }
107
+ }
108
+
109
+ if (require.main === module) {
110
+ main();
111
+ }
112
+
113
+ module.exports = { checkPrebuiltBinary, buildFromSource };
@@ -0,0 +1,70 @@
1
+ // Copyright (c) 2025, The Robot Web Tools Contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ const fs = require('fs');
16
+ const path = require('path');
17
+ const { detectUbuntuCodename } = require('../lib/utils');
18
+
19
+ function tagPrebuilds() {
20
+ const rosDistro = process.env.ROS_DISTRO;
21
+ const ubuntuCodename = detectUbuntuCodename();
22
+ const platform = process.platform;
23
+ const arch = process.arch;
24
+
25
+ console.log(
26
+ `Tagging prebuilds with Ubuntu: ${ubuntuCodename || 'unknown'}, ROS2: ${rosDistro || 'unknown'}, Platform: ${platform}, Arch: ${arch}`
27
+ );
28
+
29
+ const prebuildDir = path.join(
30
+ __dirname,
31
+ '..',
32
+ 'prebuilds',
33
+ `${platform}-${arch}`
34
+ );
35
+
36
+ if (!fs.existsSync(prebuildDir)) {
37
+ console.log('No prebuilds directory found, skipping tagging');
38
+ return;
39
+ }
40
+
41
+ const files = fs.readdirSync(prebuildDir).filter((f) => f.endsWith('.node'));
42
+
43
+ for (const file of files) {
44
+ const filePath = path.join(prebuildDir, file);
45
+
46
+ // Create tagged version with format: {ros_distro}-{linux-codename}-{cpu-arch}-rclnodejs.node
47
+ if (rosDistro && ubuntuCodename) {
48
+ const taggedName = `${rosDistro}-${ubuntuCodename}-${arch}-rclnodejs.node`;
49
+ const taggedPath = path.join(prebuildDir, taggedName);
50
+ fs.copyFileSync(filePath, taggedPath);
51
+ console.log(`Created tagged binary: ${taggedName}`);
52
+
53
+ // Remove the original generic binary file if it's the basic rclnodejs.node
54
+ if (file === 'rclnodejs.node') {
55
+ fs.unlinkSync(filePath);
56
+ console.log(`Removed generic binary: ${file}`);
57
+ }
58
+ } else {
59
+ console.log(
60
+ `Skipping tagging for ${file} - missing ROS_DISTRO or Ubuntu codename`
61
+ );
62
+ }
63
+ }
64
+ }
65
+
66
+ if (require.main === module) {
67
+ tagPrebuilds();
68
+ }
69
+
70
+ module.exports = { tagPrebuilds };
package/src/addon.cpp CHANGED
@@ -40,6 +40,7 @@
40
40
  #include "rcl_type_description_service_bindings.h"
41
41
  #endif
42
42
  #include "rcl_utilities.h"
43
+ #include "ref_napi_bindings.h"
43
44
  #include "shadow_node.h"
44
45
 
45
46
  bool IsRunningInElectronRenderer(const Napi::Env& env) {
@@ -93,6 +94,8 @@ Napi::Object InitModule(Napi::Env env, Napi::Object exports) {
93
94
  rclnodejs::ShadowNode::Init(env, exports);
94
95
  rclnodejs::RclHandle::Init(env, exports);
95
96
 
97
+ exports.Set("ref", rclnodejs::InitRefNapi(env));
98
+
96
99
  #ifdef DEBUG_ON
97
100
  int result = rcutils_logging_set_logger_level(PACKAGE_NAME,
98
101
  RCUTILS_LOG_SEVERITY_DEBUG);
@@ -0,0 +1,15 @@
1
+ // Copyright (c) 2025, The Robot Web Tools Contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ module.exports = require('./lib/ref');