@percy/sdk-utils 1.10.1 → 1.10.2

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.
package/dist/bundle.js CHANGED
@@ -139,26 +139,36 @@
139
139
  }; // Create a new WebSocket and resolve with it once connected
140
140
 
141
141
 
142
- async function createWebSocket(address) {
142
+ function createWebSocket(address) {
143
143
  let timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
144
- // attempt to import `ws` in node environments
145
- let WebSocket = process.env.__PERCY_BROWSERIFIED__
146
- /* eslint-disable-next-line import/no-extraneous-dependencies */
147
- ? window.WebSocket : (await ({})).default;
148
- let ws = new WebSocket(address.replace(/^http/, 'ws'));
149
144
  return new Promise((resolve, reject) => {
150
- let done = ws.onopen = ws.onerror = e => {
151
- var _ws$_socket;
145
+ let ws;
152
146
 
153
- (_ws$_socket = ws._socket) === null || _ws$_socket === void 0 ? void 0 : _ws$_socket.unref();
147
+ let done = e => {
148
+ var _ws, _ws$_socket;
149
+
150
+ (_ws = ws) === null || _ws === void 0 ? void 0 : (_ws$_socket = _ws._socket) === null || _ws$_socket === void 0 ? void 0 : _ws$_socket.unref();
154
151
  clearTimeout(timeoutid);
155
- ws.onopen = ws.onerror = null;
152
+ /* istanbul ignore else: edge case */
153
+
154
+ if (ws) ws.onopen = ws.onerror = null;
156
155
  if (!e.error && e.type !== 'error') return resolve(ws);else reject(e.error || 'Error: Socket connection failed');
157
156
  };
158
157
 
159
158
  let timeoutid = setTimeout(done, timeout, {
160
159
  error: 'Error: Socket connection timed out'
161
160
  });
161
+ Promise.resolve(process.env.__PERCY_BROWSERIFIED__
162
+ /* eslint-disable-next-line import/no-extraneous-dependencies */
163
+ ? {
164
+ default: window.WebSocket
165
+ } : ({})).then(_ref => {
166
+ let {
167
+ default: WS
168
+ } = _ref;
169
+ ws = new WS(address.replace(/^http/, 'ws'));
170
+ ws.onopen = ws.onerror = done;
171
+ }, reject);
162
172
  });
163
173
  } // Connect to a remote logger at the specified address within the timeout
164
174
 
package/dist/logger.js CHANGED
@@ -84,25 +84,34 @@ const log = logger.log = (ns, lvl, msg, meta) => {
84
84
  }; // Create a new WebSocket and resolve with it once connected
85
85
 
86
86
 
87
- async function createWebSocket(address, timeout = 1000) {
88
- // attempt to import `ws` in node environments
89
- let WebSocket = process.env.__PERCY_BROWSERIFIED__
90
- /* eslint-disable-next-line import/no-extraneous-dependencies */
91
- ? window.WebSocket : (await Promise.resolve().then(() => _interopRequireWildcard(require('ws')))).default;
92
- let ws = new WebSocket(address.replace(/^http/, 'ws'));
87
+ function createWebSocket(address, timeout = 1000) {
93
88
  return new Promise((resolve, reject) => {
94
- let done = ws.onopen = ws.onerror = e => {
95
- var _ws$_socket;
89
+ let ws;
96
90
 
97
- (_ws$_socket = ws._socket) === null || _ws$_socket === void 0 ? void 0 : _ws$_socket.unref();
91
+ let done = e => {
92
+ var _ws, _ws$_socket;
93
+
94
+ (_ws = ws) === null || _ws === void 0 ? void 0 : (_ws$_socket = _ws._socket) === null || _ws$_socket === void 0 ? void 0 : _ws$_socket.unref();
98
95
  clearTimeout(timeoutid);
99
- ws.onopen = ws.onerror = null;
96
+ /* istanbul ignore else: edge case */
97
+
98
+ if (ws) ws.onopen = ws.onerror = null;
100
99
  if (!e.error && e.type !== 'error') return resolve(ws);else reject(e.error || 'Error: Socket connection failed');
101
100
  };
102
101
 
103
102
  let timeoutid = setTimeout(done, timeout, {
104
103
  error: 'Error: Socket connection timed out'
105
104
  });
105
+ Promise.resolve(process.env.__PERCY_BROWSERIFIED__
106
+ /* eslint-disable-next-line import/no-extraneous-dependencies */
107
+ ? {
108
+ default: window.WebSocket
109
+ } : Promise.resolve().then(() => _interopRequireWildcard(require('ws')))).then(({
110
+ default: WS
111
+ }) => {
112
+ ws = new WS(address.replace(/^http/, 'ws'));
113
+ ws.onopen = ws.onerror = done;
114
+ }, reject);
106
115
  });
107
116
  } // Connect to a remote logger at the specified address within the timeout
108
117
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/sdk-utils",
3
- "version": "1.10.1",
3
+ "version": "1.10.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -50,5 +50,5 @@
50
50
  ]
51
51
  }
52
52
  },
53
- "gitHead": "3e16144300e8b49aab638ceb699630f4be71bb9f"
53
+ "gitHead": "66527175cdac3848157be7dd8368f5845d98e77e"
54
54
  }