Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions bin/rclnodejs-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
//
// For frontend developers who don't want to write a Node.js server.
// Run `rclnodejs-web --help` or `npx rclnodejs-web web.json` to start
// the runtime. See demo/web/javascript/README.md for the full demo.
// demo. See demo/web/javascript/README.md for the full demo.

'use strict';
import path from 'node:path';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';

const path = require('node:path');
const fs = require('node:fs');

const {
import {
parseArgv,
loadConfigFile,
mergeConfig,
CliError,
HELP,
} = require('../lib/runtime/cli-config.js');
} from '../lib/runtime/cli-config.js';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const argv = process.argv.slice(2);

Expand Down Expand Up @@ -55,14 +55,11 @@ const argv = process.argv.slice(2);
fail(e);
}

// Defer the rclnodejs require until after argv parsing so --help / --version
// Defer the rclnodejs import until after argv parsing so --help / --version
// never pay the (slow, native) load cost.
const rclnodejs = require('../index.js');
const {
createRuntime,
WebSocketTransport,
HttpTransport,
} = require('../lib/runtime');
const rclnodejs = (await import('../index.js')).default;
const { createRuntime, WebSocketTransport, HttpTransport } =
await import('../lib/runtime/index.js');

// Track partial init so the catch block can clean up native handles before
// process.exit() — without this, a startup failure (e.g. EADDRINUSE on the
Expand Down
24 changes: 22 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default [
"**/benchmark/",
"**/docs/",
"**/demo/electron/",
"**/coverage/",
"**/dist/",
"**/prebuilds/",
"**/build/",
],
},
{
Expand Down Expand Up @@ -46,6 +50,22 @@ export default [
"@typescript-eslint/triple-slash-reference": "off",
},
},
{
plugins: {
prettier,
},
languageOptions: {
globals: {
...globals.node,
},
ecmaVersion: "latest",
sourceType: "module",
},
files: ["lib/**/*.js", "test/**/*.js", "bin/**/*.js", "rosocket/**/*.js", "index.js"],
rules: {
...eslintPluginPrettierRecommended.rules,
},
},
{
plugins: {
prettier,
Expand All @@ -57,8 +77,8 @@ export default [
ecmaVersion: "latest",
sourceType: "commonjs",
},
files: ["lib/**/*.js", "rosidl_parser/**/*.{js,cjs}", "rosidl_gen/**/*.{js,cjs}",
"rostsd_gen/**/*.{js,cjs}", "test/**/*.js", "example/**/*.js", "index.js"],
files: ["rosidl_parser/**/*.{js,cjs}", "rosidl_gen/**/*.{js,cjs}",
"rostsd_gen/**/*.{js,cjs}", "example/**/*.js"],
rules: {
...eslintPluginPrettierRecommended.rules,
},
Expand Down
120 changes: 57 additions & 63 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,76 +12,79 @@
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const DistroUtils = require('./lib/distro.js');
const RMWUtils = require('./lib/rmw.js');
const { Clock, ROSClock } = require('./lib/clock.js');
const ClockEvent = require('./lib/clock_event.js');
const ClockType = require('./lib/clock_type.js');
const ClockChange = require('./lib/clock_change.js');
const { compareVersions } = require('./lib/utils.js');
const Context = require('./lib/context.js');
const debug = require('debug')('rclnodejs');
const Duration = require('./lib/duration.js');
const fs = require('fs');
const generator = require('./rosidl_gen/index.cjs');
const loader = require('./lib/interface_loader.js');
const logging = require('./lib/logging.js');
const NodeOptions = require('./lib/node_options.js');
const {
import fs from 'fs';
import path from 'path';
import { spawn } from 'child_process';
import createDebug from 'debug';
import DistroUtils from './lib/distro.js';
import RMWUtils from './lib/rmw.js';
import { Clock, ROSClock } from './lib/clock.js';
import ClockEvent from './lib/clock_event.js';
import ClockType from './lib/clock_type.js';
import ClockChange from './lib/clock_change.js';
import { compareVersions } from './lib/utils.js';
import Context from './lib/context.js';
import Duration from './lib/duration.js';
import generator from './rosidl_gen/index.cjs';
import loader from './lib/interface_loader.js';
import logging from './lib/logging.js';
import NodeOptions from './lib/node_options.js';
import {
FloatingPointRange,
IntegerRange,
Parameter,
ParameterDescriptor,
ParameterType,
DEFAULT_NUMERIC_RANGE_TOLERANCE,
} = require('./lib/parameter.js');
const path = require('path');
const QoS = require('./lib/qos.js');
const {
} from './lib/parameter.js';
import QoS from './lib/qos.js';
import {
QoSPolicyKind,
QoSOverridingOptions,
} = require('./lib/qos_overriding_options.js');
const rclnodejs = require('./lib/native_loader.js');
const tsdGenerator = require('./rostsd_gen/index.cjs');
const validator = require('./lib/validator.js');
const Time = require('./lib/time.js');
const ActionClient = require('./lib/action/client.js');
const ActionServer = require('./lib/action/server.js');
const ActionUuid = require('./lib/action/uuid.js');
const ClientGoalHandle = require('./lib/action/client_goal_handle.js');
const { CancelResponse, GoalResponse } = require('./lib/action/response.js');
const ServerGoalHandle = require('./lib/action/server_goal_handle.js');
const { toJSONSafe, toJSONString } = require('./lib/message_serialization.js');
const {
} from './lib/qos_overriding_options.js';
import rclnodejs from './lib/native_loader.js';
import tsdGenerator from './rostsd_gen/index.cjs';
import validator from './lib/validator.js';
import Time from './lib/time.js';
import ActionClient from './lib/action/client.js';
import ActionServer from './lib/action/server.js';
import ActionUuid from './lib/action/uuid.js';
import ClientGoalHandle from './lib/action/client_goal_handle.js';
import { CancelResponse, GoalResponse } from './lib/action/response.js';
import ServerGoalHandle from './lib/action/server_goal_handle.js';
import { toJSONSafe, toJSONString } from './lib/message_serialization.js';
import {
getActionClientNamesAndTypesByNode,
getActionServerNamesAndTypesByNode,
getActionNamesAndTypes,
} = require('./lib/action/graph.js');
const ServiceIntrospectionStates = require('./lib/service_introspection.js');
const {
serializeMessage,
deserializeMessage,
} = require('./lib/serialization.js');
const ParameterClient = require('./lib/parameter_client.js');
const errors = require('./lib/errors.js');
const ParameterWatcher = require('./lib/parameter_watcher.js');
const ParameterEventHandler = require('./lib/parameter_event_handler.js');
const waitForMessage = require('./lib/wait_for_message.js');
const MessageIntrospector = require('./lib/message_introspector.js');
const MessageInfo = require('./lib/message_info.js');
const ObservableSubscription = require('./lib/observable_subscription.js');
const { spawn } = require('child_process');
const {
} from './lib/action/graph.js';
import ServiceIntrospectionStates from './lib/service_introspection.js';
import { serializeMessage, deserializeMessage } from './lib/serialization.js';
import ParameterClient from './lib/parameter_client.js';
import * as errors from './lib/errors.js';
import ParameterWatcher from './lib/parameter_watcher.js';
import ParameterEventHandler from './lib/parameter_event_handler.js';
import waitForMessage from './lib/wait_for_message.js';
import MessageIntrospector from './lib/message_introspector.js';
import MessageInfo from './lib/message_info.js';
import ObservableSubscription from './lib/observable_subscription.js';
import {
ValidationProblem,
getMessageSchema,
getFieldNames,
getFieldType,
validateMessage,
assertValidMessage,
createMessageValidator,
} = require('./lib/message_validation.js');
} from './lib/message_validation.js';
// The following three modules participate in a circular dependency with this
// file (via rate.js). In ESM the circular references are resolved by live
// bindings, so they are imported here at the top like everything else.
import Node from './lib/node.js';
import TimeSource from './lib/time_source.js';
import Lifecycle from './lib/lifecycle.js';

const debug = createDebug('rclnodejs');

/**
* Get the version of the generator that was used for the currently present interfaces.
Expand Down Expand Up @@ -764,25 +767,16 @@ const _sigHandler = () => {
};
process.on('SIGINT', _sigHandler);

module.exports = rcl;

// The following statements are located here to work around a
// circular dependency issue occurring in rate.js.
// Do not change the order of the following imports.
const Node = require('./lib/node.js');

/** {@link Node} class */
rcl.Node = Node;

const TimeSource = require('./lib/time_source.js');

/** {@link TimeSource} class */
rcl.TimeSource = TimeSource;

const Lifecycle = require('./lib/lifecycle.js');

/** Lifecycle namespace */
rcl.lifecycle = Lifecycle;

/** {@link MessageIntrospector} class */
rcl.MessageIntrospector = MessageIntrospector;

export default rcl;
30 changes: 12 additions & 18 deletions lib/action/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const rclnodejs = require('../native_loader.js');
const ActionInterfaces = require('./interfaces.js');
const ActionUuid = require('./uuid.js');
const ClientGoalHandle = require('./client_goal_handle.js');
const Deferred = require('./deferred.js');
const DistroUtils = require('../distro.js');
const Entity = require('../entity.js');
const loader = require('../interface_loader.js');
const QoS = require('../qos.js');
const {
TypeValidationError,
ActionError,
OperationError,
} = require('../errors.js');
const { assertValidMessage } = require('../message_validation.js');
import rclnodejs from '../native_loader.js';
import ActionInterfaces from './interfaces.js';
import ActionUuid from './uuid.js';
import ClientGoalHandle from './client_goal_handle.js';
import Deferred from './deferred.js';
import DistroUtils from '../distro.js';
import Entity from '../entity.js';
import loader from '../interface_loader.js';
import QoS from '../qos.js';
import { TypeValidationError, ActionError, OperationError } from '../errors.js';
import { assertValidMessage } from '../message_validation.js';

/**
* @class - ROS Action client.
Expand Down Expand Up @@ -577,4 +571,4 @@ class ActionClient extends Entity {
}
}

module.exports = ActionClient;
export default ActionClient;
6 changes: 2 additions & 4 deletions lib/action/client_goal_handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const ActionInterfaces = require('./interfaces.js');
import ActionInterfaces from './interfaces.js';

/**
* @class - Goal handle for working with Action Clients.
Expand Down Expand Up @@ -140,4 +138,4 @@ class ClientGoalHandle {
}
}

module.exports = ClientGoalHandle;
export default ClientGoalHandle;
6 changes: 2 additions & 4 deletions lib/action/deferred.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const { TypeValidationError } = require('../errors.js');
import { TypeValidationError } from '../errors.js';

/**
* @class - Wraps a promise allowing it to be resolved elsewhere.
Expand Down Expand Up @@ -83,4 +81,4 @@ class Deferred {
}
}

module.exports = Deferred;
export default Deferred;
6 changes: 2 additions & 4 deletions lib/action/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const rclnodejs = require('../native_loader.js');
import rclnodejs from '../native_loader.js';

/**
* Get a list of action names and types for action clients associated with a node.
Expand Down Expand Up @@ -55,7 +53,7 @@ function getActionNamesAndTypes(node) {
return rclnodejs.actionGetNamesAndTypes(node.handle);
}

module.exports = {
export {
getActionClientNamesAndTypesByNode,
getActionServerNamesAndTypesByNode,
getActionNamesAndTypes,
Expand Down
6 changes: 2 additions & 4 deletions lib/action/interfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const loader = require('../interface_loader.js');
import loader from '../interface_loader.js';

const CANCEL_GOAL_SERVICE = 'action_msgs/srv/CancelGoal';
const GOAL_INFO_MESSAGE = 'action_msgs/msg/GoalInfo';
Expand Down Expand Up @@ -75,4 +73,4 @@ class ActionInterfaces {
}
}

module.exports = ActionInterfaces;
export default ActionInterfaces;
8 changes: 1 addition & 7 deletions lib/action/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

/**
* Goal events that cause state transitions.
* @ignore
Expand Down Expand Up @@ -57,8 +55,4 @@ const CancelResponse = {
ACCEPT: 2,
};

module.exports = {
GoalEvent,
GoalResponse,
CancelResponse,
};
export { GoalEvent, GoalResponse, CancelResponse };
Loading
Loading