Skip to content

Commit 1f978df

Browse files
jeff-hykinsea-bassEzraBrooks
authored
Support for Deno & Bun (#874)
* deno detection check * use fully-qualified import path * add deno lock * allow .ts file extensions * Update Ros.js * make websocket check more general * fix linting * remove contents * Delete deno.lock * Move to new tsconfig --------- Co-authored-by: Sebastian Castro <[email protected]> Co-authored-by: Ezra Brooks <[email protected]>
1 parent f594bc2 commit 1f978df

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/core/Action.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { EventEmitter } from 'eventemitter3';
77
import Ros from '../core/Ros.js';
8-
import { GoalStatus } from '../core/GoalStatus';
8+
import { GoalStatus } from '../core/GoalStatus.ts';
99

1010
/**
1111
* A ROS 2 action client.

src/core/Ros.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ export default class Ros extends EventEmitter {
6161
socketAdapter(this)
6262
);
6363
} else if (this.transportLibrary === 'websocket') {
64-
// Detect if in browser vs in NodeJS
65-
if (typeof window !== 'undefined') {
64+
// browsers, Deno, and Bun support WebSockets natively
65+
if (typeof WebSocket === 'function') {
6666
if (!this.socket || this.socket.readyState === WebSocket.CLOSED) {
6767
const sock = new WebSocket(url);
6868
sock.binaryType = 'arraybuffer';
6969
this.socket = Object.assign(sock, socketAdapter(this));
7070
}
7171
} else {
72-
// if in Node.js, import ws to replace browser WebSocket API
72+
// if in Node.js, import ws to replace WebSocket API
7373
import('ws').then((ws) => {
7474
if (!this.socket || this.socket.readyState === ws.WebSocket.CLOSED) {
7575
const sock = new ws.WebSocket(url);

tsconfig.build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"tsBuildInfoFile": "./node_modules/.cache/typescript/tsbuildinfo" /* Specify the folder for .tsbuildinfo incremental compilation files. */,
1818
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
1919
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
20+
"allowImportingTsExtensions": true,
2021

2122
/* Module Options */
2223
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,

0 commit comments

Comments
 (0)