Skip to content

Commit 65c7759

Browse files
committed
Drop now-unnecessary uuid dep for modern randomUUID global
1 parent 13ed127 commit 65c7759

File tree

7 files changed

+12
-20
lines changed

7 files changed

+12
-20
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
"@types/semver": "7.5.0",
111111
"@types/shelljs": "0.8.9",
112112
"@types/source-map-support": "0.4.2",
113-
"@types/uuid": "8.3.4",
114113
"@types/ws": " 8.5.3",
115114
"assert": "^2.0.0",
116115
"brotli-wasm": "^1.0.0",
@@ -200,7 +199,6 @@
200199
"socks-proxy-agent": "^7.0.0",
201200
"typed-error": "^3.0.2",
202201
"urlpattern-polyfill": "^8.0.0",
203-
"uuid": "^8.3.2",
204202
"ws": "^8.8.0"
205203
}
206204
}

src/admin/admin-server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as cors from 'cors';
88
import corsGate = require('cors-gate');
99
import * as bodyParser from 'body-parser';
1010
import * as Ws from 'ws';
11-
import { v4 as uuid } from "uuid";
1211

1312
import { createHandler as createGraphQLHandler } from 'graphql-http/lib/use/express';
1413
import { execute, GraphQLScalarType, subscribe } from 'graphql';
@@ -210,7 +209,7 @@ export class AdminServer<Plugins extends { [key: string]: AdminPlugin<any, any>
210209
)
211210
);
212211

213-
const sessionId = uuid();
212+
const sessionId = crypto.randomUUID();
214213
await this.startSessionManagementAPI(sessionId, sessionPlugins);
215214

216215
res.json({

src/rules/requests/request-rule.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Buffer } from 'buffer';
22

33
import * as _ from 'lodash';
4-
import { v4 as uuid } from "uuid";
54

65
import { OngoingRequest, CompletedRequest, OngoingResponse, Explainable, RulePriority } from "../../types";
76
import { buildBodyReader, buildInitiatedRequest, waitForCompletedRequest } from '../../util/request-utils';
@@ -48,7 +47,7 @@ export class RequestRule implements RequestRule {
4847
constructor(data: RequestRuleData) {
4948
validateMockRuleData(data);
5049

51-
this.id = data.id || uuid();
50+
this.id = data.id || crypto.randomUUID();
5251
this.priority = data.priority ?? RulePriority.DEFAULT;
5352
this.matchers = data.matchers;
5453
this.completionChecker = data.completionChecker;

src/rules/websockets/websocket-rule.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import * as _ from 'lodash';
2-
import { v4 as uuid } from "uuid";
31
import * as net from 'net';
42
import * as http from 'http';
53

4+
import * as _ from 'lodash';
65
import {
76
OngoingRequest,
87
CompletedRequest,
@@ -59,7 +58,7 @@ export class WebSocketRule implements WebSocketRule {
5958
constructor(data: WebSocketRuleData) {
6059
validateMockRuleData(data);
6160

62-
this.id = data.id || uuid();
61+
this.id = data.id || crypto.randomUUID();
6362
this.priority = data.priority ?? RulePriority.DEFAULT;
6463
this.matchers = data.matchers;
6564
this.completionChecker = data.completionChecker;

src/serialization/serialization.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Buffer } from 'buffer';
22
import { Duplex } from 'stream';
33

44
import * as _ from 'lodash';
5-
import { v4 as uuid } from "uuid";
65

76
import { MaybePromise } from '@httptoolkit/util';
87
import {
@@ -125,7 +124,7 @@ export class ClientServerChannel extends Duplex {
125124
) {
126125
super({ objectMode: true });
127126

128-
this.topicId = topicId || uuid();
127+
this.topicId = topicId || crypto.randomUUID();
129128
this.rawStream.on('error', this._onRawStreamError);
130129
this.rawStream.on('finish', this._onRawStreamFinish);
131130
}
@@ -192,7 +191,7 @@ export class ClientServerChannel extends Duplex {
192191
data = actionOrData;
193192
}
194193

195-
const requestId = uuid();
194+
const requestId = crypto.randomUUID();
196195

197196
return new Promise<R>((resolve, reject) => {
198197
const responseListener = (response: RequestMessage<R>) => {
@@ -324,7 +323,7 @@ export function serializeProxyConfig(
324323
channel: ClientServerChannel
325324
): SerializedProxyConfig {
326325
if (_.isFunction(proxyConfig)) {
327-
const callbackId = `proxyConfig-callback-${uuid()}`;
326+
const callbackId = `proxyConfig-callback-${crypto.randomUUID()}`;
328327

329328
channel.onRequest<
330329
ProxySettingCallbackParams,

src/server/mockttp-server.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as _ from "lodash";
99
import { EventEmitter } from 'events';
1010
import portfinder = require("portfinder");
1111
import connect = require("connect");
12-
import { v4 as uuid } from "uuid";
1312
import cors = require("cors");
1413
import now = require("performance-now");
1514
import WebSocket = require("ws");
@@ -687,7 +686,7 @@ export class MockttpServer extends AbstractMockttp implements Mockttp {
687686
});
688687
}
689688

690-
const id = uuid();
689+
const id = crypto.randomUUID();
691690

692691
const tags: string[] = getSocketMetadataTags(socketMetadata);
693692

@@ -1050,7 +1049,7 @@ ${await this.suggestRule(request)}`
10501049
const isHeaderOverflow = errorCode === "HPE_HEADER_OVERFLOW";
10511050

10521051
const commonParams = {
1053-
id: uuid(),
1052+
id: crypto.randomUUID(),
10541053
tags: [
10551054
`client-error:${error.code || 'UNKNOWN'}`,
10561055
...getSocketMetadataTags(socket[SocketMetadata])
@@ -1142,7 +1141,7 @@ ${await this.suggestRule(request)}`
11421141
this.announceClientErrorAsync(session.initialSocket, {
11431142
errorCode: error.code,
11441143
request: {
1145-
id: uuid(),
1144+
id: crypto.randomUUID(),
11461145
tags: [
11471146
`client-error:${error.code || 'UNKNOWN'}`,
11481147
...(isBadPreface ? ['client-error:bad-preface'] : []),
@@ -1192,7 +1191,7 @@ ${await this.suggestRule(request)}`
11921191
? buildRawSocketEventData(socket)
11931192
: buildTlsSocketEventData(socket as tls.TLSSocket),
11941193
{
1195-
id: uuid(),
1194+
id: crypto.randomUUID(),
11961195
hostname: hostname, // Deprecated, but kept here for backward compat
11971196
destination: { hostname, port: targetPort }
11981197
}

src/util/tls.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Buffer } from 'buffer';
22
import * as fs from 'fs/promises';
33

44
import * as _ from 'lodash';
5-
import { v4 as uuid } from "uuid";
65

76
import * as x509 from '@peculiar/x509';
87
import * as asn1X509 from '@peculiar/asn1-x509';
@@ -220,7 +219,7 @@ export async function generateSPKIFingerprint(certPem: string): Promise<string>
220219

221220
// Generates a unique serial number for a certificate as a hex string:
222221
function generateSerialNumber() {
223-
return 'A' + uuid().replace(/-/g, '');
222+
return 'A' + crypto.randomUUID().replace(/-/g, '');
224223
// We add a leading 'A' to ensure it's always positive (not 'F') and always
225224
// valid (e.g. leading 000 is bad padding, and would be unparseable).
226225
}

0 commit comments

Comments
 (0)