diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json index efbd8787270..15bc44f15e3 100644 --- a/oxlint-suppressions.json +++ b/oxlint-suppressions.json @@ -5579,20 +5579,6 @@ "count": 2 } }, - "packages/seedless-onboarding-controller/src/utils.ts": { - "typescript/no-unsafe-argument": { - "count": 2 - }, - "typescript/no-unsafe-assignment": { - "count": 2 - }, - "typescript/no-unsafe-member-access": { - "count": 2 - }, - "typescript/no-unsafe-return": { - "count": 1 - } - }, "packages/seedless-onboarding-controller/tests/mocks/vaultEncryptor.ts": { "typescript/no-unsafe-argument": { "count": 6 @@ -7255,16 +7241,13 @@ "count": 20 }, "typescript/no-unsafe-argument": { - "count": 12 + "count": 11 }, "typescript/no-unsafe-assignment": { - "count": 23 + "count": 22 }, "typescript/no-unsafe-member-access": { - "count": 9 - }, - "typescript/no-unsafe-return": { - "count": 1 + "count": 8 } }, "packages/utils/src/fs.ts": { diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md index d815b83db95..914ec591aab 100644 --- a/packages/utils/CHANGELOG.md +++ b/packages/utils/CHANGELOG.md @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump `lodash` from `^4.17.21` to `^4.18.1` ([#10447](https://github.com/MetaMask/core/pull/10447)) - Bump `debug` from `^4.3.4` to `^4.4.3` ([#10523](https://github.com/MetaMask/core/pull/10523)) +### Removed + +- Remove `uuid` dependency in favor of Node's built-in `crypto.randomUUID()` ([#10210](https://github.com/MetaMask/core/issues/10210)) + ### Fixed - Narrow byte helper return types to `Uint8Array` ([#10617](https://github.com/MetaMask/core/pull/10617)) diff --git a/packages/utils/package.json b/packages/utils/package.json index 9ce3bc20135..5cbf8832147 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -67,8 +67,7 @@ "debug": "^4.4.3", "lodash": "^4.18.1", "pony-cause": "^2.1.11", - "semver": "^7.8.5", - "uuid": "^11.1.1" + "semver": "^7.8.5" }, "devDependencies": { "@metamask/auto-changelog": "^6.2.1", diff --git a/packages/utils/src/fs.test.ts b/packages/utils/src/fs.test.ts index 46d76292bd9..38dd66ba81d 100644 --- a/packages/utils/src/fs.test.ts +++ b/packages/utils/src/fs.test.ts @@ -1,9 +1,10 @@ +// eslint-disable-next-line no-shadow +import crypto from 'crypto'; import fs from 'fs'; import { when } from 'jest-when'; import os from 'os'; import path from 'path'; import util from 'util'; -import { v4 } from 'uuid'; import { createSandbox, @@ -19,19 +20,12 @@ import { const { withinSandbox } = createSandbox('utils'); -// Wrap the real `v4` so it behaves normally until a test overrides it. -jest.mock('uuid', () => { - const actual = jest.requireActual('uuid'); - // This is how to mock an ES-compatible module in Jest. - return { __esModule: true, ...actual, v4: jest.fn(actual.v4) }; -}); - -// `v4` is overloaded; naming the signature used here avoids resolving to the -// last overload, which returns a `Uint8Array`. -const v4Mock = jest.mocked<() => string>(v4); - -const mockUuidV4 = (value: string): void => { - v4Mock.mockReturnValue(value); +const mockRandomUUID = (value: string): void => { + jest + .spyOn(crypto, 'randomUUID') + .mockReturnValue( + value as `${string}-${string}-${string}-${string}-${string}`, + ); }; describe('fs', () => { @@ -690,7 +684,7 @@ describe('fs', () => { }); it('does not create the sandbox directory immediately', async () => { - mockUuidV4('AAAA-AAAA-AAAA-AAAA'); + mockRandomUUID('AAAA-AAAA-AAAA-AAAA'); createSandbox('utils-fs'); const sandboxDirectoryPath = path.join( @@ -707,7 +701,7 @@ describe('fs', () => { describe('withinSandbox', () => { it('creates the sandbox directory and keeps it around before its given function ends', async () => { expect.assertions(1); - mockUuidV4('AAAA-AAAA-AAAA-AAAA'); + mockRandomUUID('AAAA-AAAA-AAAA-AAAA'); const { withinSandbox: withinTestSandbox } = createSandbox('utils-fs'); await withinTestSandbox(async () => { @@ -723,7 +717,7 @@ describe('fs', () => { }); it('removes the sandbox directory after its given function ends', async () => { - mockUuidV4('AAAA-AAAA-AAAA-AAAA'); + mockRandomUUID('AAAA-AAAA-AAAA-AAAA'); const { withinSandbox: withinTestSandbox } = createSandbox('utils-fs'); await withinTestSandbox(async () => { @@ -741,7 +735,7 @@ describe('fs', () => { }); it('throws if the sandbox directory already exists', async () => { - mockUuidV4('AAAA-AAAA-AAAA-AAAA'); + mockRandomUUID('AAAA-AAAA-AAAA-AAAA'); const { withinSandbox: withinTestSandbox } = createSandbox('utils-fs'); const sandboxDirectoryPath = path.join( diff --git a/packages/utils/src/fs.ts b/packages/utils/src/fs.ts index 17fdbed8388..7f5c351e8ca 100644 --- a/packages/utils/src/fs.ts +++ b/packages/utils/src/fs.ts @@ -1,10 +1,11 @@ // This file is intended to be used only in a Node.js context. /* eslint-disable import-x/no-nodejs-modules */ +// eslint-disable-next-line no-shadow +import crypto from 'crypto'; import fs from 'fs'; import os from 'os'; import path from 'path'; -import { v4 as uuidV4 } from 'uuid'; import { isErrorWithCode, wrapError } from './errors.js'; import type { Json } from './json.js'; @@ -241,7 +242,11 @@ export async function forceRemove(entryPath: string): Promise { * ``` */ export function createSandbox(projectName: string): FileSandbox { - const directoryPath = path.join(os.tmpdir(), projectName, uuidV4()); + const directoryPath = path.join( + os.tmpdir(), + projectName, + crypto.randomUUID(), + ); return { directoryPath, diff --git a/yarn.lock b/yarn.lock index db00c8a2db0..33e284e87dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9218,7 +9218,6 @@ __metadata: typedoc: "npm:^0.28.20" typedoc-plugin-missing-exports: "npm:^2.0.0" typescript: "npm:@typescript/typescript6@^6.0.2" - uuid: "npm:^11.1.1" web3: "npm:^4.16.0" languageName: unknown linkType: soft