Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions oxlint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions packages/utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrayBuffer>` ([#10617](https://github.com/MetaMask/core/pull/10617))
Expand Down
3 changes: 1 addition & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 12 additions & 18 deletions packages/utils/src/fs.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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(
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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(
Expand Down
9 changes: 7 additions & 2 deletions packages/utils/src/fs.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -241,7 +242,11 @@ export async function forceRemove(entryPath: string): Promise<void> {
* ```
*/
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,
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading