Skip to content

Commit 1ec2aec

Browse files
committed
Use node resolve to avoid @stomp/stompjs dependency in .cjs output.
1 parent 09f0f58 commit 1ec2aec

File tree

5 files changed

+156
-14
lines changed

5 files changed

+156
-14
lines changed

bundles/tcp-wrapper.cjs

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
'use strict';
22

33
var net = require('net');
4-
var stompjs = require('@stomp/stompjs');
4+
5+
/**
6+
* Possible states for the IStompSocket
7+
*/
8+
var StompSocketState;
9+
(function (StompSocketState) {
10+
StompSocketState[StompSocketState["CONNECTING"] = 0] = "CONNECTING";
11+
StompSocketState[StompSocketState["OPEN"] = 1] = "OPEN";
12+
StompSocketState[StompSocketState["CLOSING"] = 2] = "CLOSING";
13+
StompSocketState[StompSocketState["CLOSED"] = 3] = "CLOSED";
14+
})(StompSocketState = StompSocketState || (StompSocketState = {}));
15+
/**
16+
* Possible activation state
17+
*/
18+
var ActivationState;
19+
(function (ActivationState) {
20+
ActivationState[ActivationState["ACTIVE"] = 0] = "ACTIVE";
21+
ActivationState[ActivationState["DEACTIVATING"] = 1] = "DEACTIVATING";
22+
ActivationState[ActivationState["INACTIVE"] = 2] = "INACTIVE";
23+
})(ActivationState = ActivationState || (ActivationState = {}));
524

625
/**
726
* Wrapper for a TCP socket to make it behave similar to the WebSocket interface
@@ -21,17 +40,17 @@ class TCPWrapper {
2140
this.onmessage = noOp;
2241
this.onopen = noOp;
2342
this.url = `tcp://${host}/${port}/`;
24-
this.readyState = stompjs.StompSocketState.CONNECTING;
43+
this.readyState = StompSocketState.CONNECTING;
2544
this.socket = this.getSocket(port, host);
2645
this.socket.on('connect', () => {
27-
this.readyState = stompjs.StompSocketState.OPEN;
46+
this.readyState = StompSocketState.OPEN;
2847
this.onopen();
2948
});
3049
this.socket.on('data', ev => {
3150
this.onmessage({ data: ev });
3251
});
3352
this.socket.on('close', hadError => {
34-
this.readyState = stompjs.StompSocketState.CLOSED;
53+
this.readyState = StompSocketState.CLOSED;
3554
if (this._closeEvtOnTermination) {
3655
this.onclose(this._closeEvtOnTermination);
3756
}
@@ -72,14 +91,14 @@ class TCPWrapper {
7291
* @param reason
7392
*/
7493
close(code, reason) {
75-
this.readyState = stompjs.StompSocketState.CLOSING;
94+
this.readyState = StompSocketState.CLOSING;
7695
this.socket.end();
7796
}
7897
/**
7998
* @internal
8099
*/
81100
terminate() {
82-
this.readyState = stompjs.StompSocketState.CLOSING;
101+
this.readyState = StompSocketState.CLOSING;
83102
this._closeEvtOnTermination = {
84103
wasClean: false,
85104
type: 'CloseEvent',

bundles/tcp-wrapper.cjs.map

+1-1
Original file line numberDiff line numberDiff line change

package-lock.json

+126-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"author": "[email protected]",
2020
"license": "Apache-2.0",
2121
"devDependencies": {
22+
"@rollup/plugin-node-resolve": "^15.0.1",
2223
"@rollup/plugin-typescript": "^11.0.0",
2324
"@stomp/stompjs": "^7.0.0-beta3",
2425
"@types/node": "^18.11.18",

rollup.config.mjs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import typescript from '@rollup/plugin-typescript';
2+
import nodeResolve from '@rollup/plugin-node-resolve';
23

34
export default [
45
{
56
input: 'src/index.ts',
6-
plugins: [typescript()],
7-
external: ['net', '@stomp/stompjs'],
7+
plugins: [typescript(), nodeResolve()],
8+
external: ['net'],
89
output: {
910
file: 'bundles/tcp-wrapper.cjs',
1011
format: 'cjs',

0 commit comments

Comments
 (0)