Skip to content

Commit 47780bd

Browse files
committed
chore: drop uuid dependency in favor of crypto.randomUUID
Replaces `uuid` (v8) with Node's built-in `crypto.randomUUID()`, available since Node 14.17 / 15.6. The codebase only used `v4()` (random UUIDs), which `crypto.randomUUID()` covers natively. Motivation: - npm audit flags `uuid <14.0.0` (GHSA-w5hq-g745-h8pq), blocking CI's `npm audit --production` step. - The CVE only affects `v3/v5/v6` with a `buf` parameter; this codebase was never affected at runtime, but the audit gate still failed. - `uuid >= 14` is pure ESM and breaks the existing ts-jest CommonJS setup. Dropping the dependency entirely sidesteps both issues. Bumps `engines.node` from `>=12.0` to `>=14.17`. Node 12 reached end of life in April 2022; this aligns the engines field with reality. Touched: - src/documentMinifier.ts: `uuidv4()` -> `randomUUID()` - tests/core.ts, tests/glossary.test.ts, tests/multilingualGlossary.test.ts, tests/documentMinification/helperMethods.test.ts: same swap - package.json: removes `uuid` and `@types/uuid`, bumps engines.node
1 parent e662939 commit 47780bd

7 files changed

Lines changed: 31 additions & 60 deletions

File tree

package-lock.json

Lines changed: 21 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"bugs": "https://github.com/DeepLcom/deepl-node/issues",
1212
"homepage": "https://www.deepl.com/",
1313
"engines": {
14-
"node": ">=12.0"
14+
"node": ">=14.17"
1515
},
1616
"keywords": [
1717
"deepl",
@@ -23,14 +23,12 @@
2323
"adm-zip": "^0.5.16",
2424
"axios": "^1.7.4",
2525
"form-data": "^3.0.4",
26-
"loglevel": ">=1.6.2",
27-
"uuid": "^8.3.2"
26+
"loglevel": ">=1.6.2"
2827
},
2928
"devDependencies": {
3029
"@types/adm-zip": "^0.5.7",
3130
"@types/jest": "^29.5.0",
3231
"@types/mock-fs": "^4.13.4",
33-
"@types/uuid": "^8.3.4",
3432
"@typescript-eslint/eslint-plugin": "^5.6.0",
3533
"@typescript-eslint/parser": "^5.6.0",
3634
"dotenv": "^16.4.7",

src/documentMinifier.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as path from 'path';
22
import * as fs from 'fs';
33
import * as os from 'os';
4-
import { v4 as uuidv4 } from 'uuid';
4+
import { randomUUID } from 'crypto';
55
import { DocumentDeminificationError, DocumentMinificationError } from './errors';
66
import AdmZip from 'adm-zip';
77
import { FsHelper } from './fsHelper';
@@ -283,7 +283,7 @@ export class DocumentMinifier implements IDocumentMinifier {
283283
* @throws {DocumentMinificationError} If the temporary directory could not be created
284284
*/
285285
private static createTemporaryDirectory(): string {
286-
const tempDir = path.join(os.tmpdir(), 'document_minification_' + uuidv4());
286+
const tempDir = path.join(os.tmpdir(), 'document_minification_' + randomUUID());
287287

288288
if (fs.existsSync(tempDir)) {
289289
throw new DocumentMinificationError(

tests/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as deepl from 'deepl-node';
77
import fs from 'fs';
88
import os from 'os';
99
import path from 'path';
10-
import { v4 as randomUUID } from 'uuid';
10+
import { randomUUID } from 'crypto';
1111

1212
// Note: this constant cannot be exported immediately, because exports are locally undefined
1313
const internalExampleText: Record<string, string> = {

tests/documentMinification/helperMethods.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DocumentMinifier } from '../../src/documentMinifier';
55
import AdmZip from 'adm-zip';
66
import { DocumentMinificationError } from '../../src';
77
import { FsHelper } from '../../src/fsHelper';
8-
import { v4 as uuidv4 } from 'uuid';
8+
import { randomUUID } from 'crypto';
99
import mock from 'mock-fs';
1010

1111
describe('DocumentMinifier helperMethods', () => {
@@ -32,7 +32,7 @@ describe('DocumentMinifier helperMethods', () => {
3232
});
3333

3434
it('should use provided temp directory when specified', () => {
35-
const customTempDir = path.join(os.tmpdir(), 'custom_temp_dir' + uuidv4());
35+
const customTempDir = path.join(os.tmpdir(), 'custom_temp_dir' + randomUUID());
3636
fs.mkdirSync(customTempDir);
3737

3838
const minifier = new DocumentMinifier(customTempDir);

tests/glossary.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as deepl from 'deepl-node';
66

77
import fs from 'fs';
88
import { makeTranslator, tempFiles, withRealServer, testTimeout } from './core';
9-
import { v4 as randomUUID } from 'uuid';
9+
import { randomUUID } from 'crypto';
1010

1111
const invalidGlossaryId = 'invalid_glossary_id';
1212
const nonExistentGlossaryId = '96ab91fd-e715-41a1-adeb-5d701f84a483';

tests/multilingualGlossary.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import * as deepl from 'deepl-node';
66

7-
import { v4 as uuidv4 } from 'uuid';
7+
import { randomUUID } from 'crypto';
88
import { makeDeeplClient, withRealServer } from './core';
99

1010
describe('Multilingual Glossary Tests', () => {
@@ -29,7 +29,7 @@ describe('Multilingual Glossary Tests', () => {
2929

3030
constructor(client: deepl.DeepLClient, testName: string) {
3131
this.client = client;
32-
const uuid = uuidv4();
32+
const uuid = randomUUID();
3333
this.glossaryName = `${GLOSSARY_NAME_PREFIX}: ${testName} ${uuid}`;
3434
}
3535

0 commit comments

Comments
 (0)