Skip to content

Commit

Permalink
Use @metamask/superstruct, set moduleResolution to NodeNext (#185)
Browse files Browse the repository at this point in the history
## Explanation

As part of our OKR for upgrading TypeScript to v5.0+ (Q2 2024 O3KR4), we
are updating our core dependencies to generate builds and type
declarations for both CJS and ESM.

- Replaces all references to `superstruct` with ESM-compatible
`@metamask/superstruct` fork.
- Set TypeScript `module`, `moduleResolution` options to `NodeNext`.

## References

- Closes: #186
- Blocks: MetaMask/core#3651
- Blocked by: MetaMask/superstruct#20

## Changelog

```md
### Changed

- **BREAKING:** Replace dependency `superstruct` `^1.0.3` with ESM-compatible `@metamask/superstruct` `^3.0.0` ([#185](#185)).
- Bump devDependency `typescript` from `~4.8.4` to `~5.0.4` ([#185](#185)).
```

---------

Co-authored-by: Elliot Winkler <[email protected]>
  • Loading branch information
MajorLift and mcmire authored Jun 4, 2024
1 parent 7eac3c8 commit 631d1eb
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@
},
"dependencies": {
"@ethereumjs/tx": "^4.2.0",
"@metamask/superstruct": "^3.0.0",
"@noble/hashes": "^1.3.1",
"@scure/base": "^1.1.3",
"@types/debug": "^4.1.7",
"debug": "^4.3.4",
"pony-cause": "^2.1.10",
"semver": "^7.5.4",
"superstruct": "^1.0.3",
"uuid": "^9.0.1"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions src/assert.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { string, assert as superstructAssert } from 'superstruct';
import { string, assert as superstructAssert } from '@metamask/superstruct';

import {
assert,
Expand All @@ -7,8 +7,8 @@ import {
assertStruct,
} from './assert';

jest.mock('superstruct', () => ({
...jest.requireActual('superstruct'),
jest.mock('@metamask/superstruct', () => ({
...jest.requireActual('@metamask/superstruct'),
assert: jest.fn(),
}));

Expand Down Expand Up @@ -50,7 +50,7 @@ describe('assertExhaustive', () => {

describe('assertStruct', () => {
beforeEach(() => {
const actual = jest.requireActual('superstruct');
const actual = jest.requireActual('@metamask/superstruct');
(
superstructAssert as jest.MockedFunction<typeof superstructAssert>
).mockImplementation(actual.assert);
Expand Down
4 changes: 2 additions & 2 deletions src/assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Struct } from 'superstruct';
import { assert as assertSuperstruct } from 'superstruct';
import type { Struct } from '@metamask/superstruct';
import { assert as assertSuperstruct } from '@metamask/superstruct';

import { getErrorMessage } from './errors';

Expand Down
2 changes: 1 addition & 1 deletion src/base64.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { is, size, string } from 'superstruct';
import { is, size, string } from '@metamask/superstruct';

import type { Base64Options } from './base64';
import { base64 } from './base64';
Expand Down
4 changes: 2 additions & 2 deletions src/base64.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Struct } from 'superstruct';
import { pattern } from 'superstruct';
import type { Struct } from '@metamask/superstruct';
import { pattern } from '@metamask/superstruct';

import { assert } from './assert';

Expand Down
4 changes: 2 additions & 2 deletions src/caip-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Infer } from 'superstruct';
import { is, pattern, string } from 'superstruct';
import type { Infer } from '@metamask/superstruct';
import { is, pattern, string } from '@metamask/superstruct';

export const CAIP_CHAIN_ID_REGEX =
/^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;
Expand Down
2 changes: 1 addition & 1 deletion src/checksum.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { is } from 'superstruct';
import { is } from '@metamask/superstruct';

import { ChecksumStruct } from './checksum';

Expand Down
2 changes: 1 addition & 1 deletion src/checksum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { size, string } from 'superstruct';
import { size, string } from '@metamask/superstruct';

import { base64 } from './base64';

Expand Down
4 changes: 2 additions & 2 deletions src/coercers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Infer } from 'superstruct';
import type { Infer } from '@metamask/superstruct';
import {
bigint,
coerce,
Expand All @@ -8,7 +8,7 @@ import {
string,
StructError,
union,
} from 'superstruct';
} from '@metamask/superstruct';

import { assert } from './assert';
import { bytesToHex, hexToBytes } from './bytes';
Expand Down
4 changes: 2 additions & 2 deletions src/hex.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Struct } from '@metamask/superstruct';
import { is, pattern, string } from '@metamask/superstruct';
import { keccak_256 as keccak256 } from '@noble/hashes/sha3';
import type { Struct } from 'superstruct';
import { is, pattern, string } from 'superstruct';

import { assert } from './assert';
import { bytesToHex } from './bytes';
Expand Down
4 changes: 2 additions & 2 deletions src/json.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import type { Infer } from 'superstruct';
import { boolean, number, optional, string } from 'superstruct';
import type { Infer } from '@metamask/superstruct';
import { boolean, number, optional, string } from '@metamask/superstruct';
import { expectAssignable, expectNotAssignable } from 'tsd';

import type { Json } from '.';
Expand Down
8 changes: 4 additions & 4 deletions src/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
max,
number,
optional,
} from 'superstruct';
} from '@metamask/superstruct';

import {
assert,
Expand Down Expand Up @@ -46,8 +46,8 @@ import {
JSON_VALIDATION_FIXTURES,
} from './__fixtures__';

jest.mock('superstruct', () => ({
...jest.requireActual('superstruct'),
jest.mock('@metamask/superstruct', () => ({
...jest.requireActual('@metamask/superstruct'),
assert: jest.fn(),
}));

Expand Down Expand Up @@ -225,7 +225,7 @@ describe('exactOptional', () => {

describe('json', () => {
beforeEach(() => {
const actual = jest.requireActual('superstruct');
const actual = jest.requireActual('@metamask/superstruct');
(
superstructAssert as jest.MockedFunction<typeof superstructAssert>
).mockImplementation(actual.assert);
Expand Down
9 changes: 5 additions & 4 deletions src/json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Context, Infer } from 'superstruct';
import {
any,
array,
Expand All @@ -19,12 +18,14 @@ import {
union,
unknown,
Struct,
} from 'superstruct';
} from '@metamask/superstruct';
import type {
Context,
Infer,
ObjectSchema,
Optionalize,
Simplify,
} from 'superstruct/dist/utils';
Optionalize,
} from '@metamask/superstruct';

import type { AssertionErrorConstructor } from './assert';
import { assertStruct } from './assert';
Expand Down
4 changes: 2 additions & 2 deletions src/versions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Struct } from '@metamask/superstruct';
import { is, refine, string } from '@metamask/superstruct';
import {
gt as gtSemver,
gtr as gtrSemver,
satisfies as satisfiesSemver,
valid as validSemVerVersion,
validRange as validSemVerRange,
} from 'semver';
import type { Struct } from 'superstruct';
import { is, refine, string } from 'superstruct';

import { assertStruct } from './assert';
import type { Opaque } from './opaque';
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"lib": ["ES2020", "dom"],
"module": "CommonJS",
"moduleResolution": "node",
"module": "nodenext",
"moduleResolution": "nodenext",
"noEmit": true,
"noErrorTruncation": true,
"noUncheckedIndexedAccess": true,
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,13 @@ __metadata:
languageName: node
linkType: hard

"@metamask/superstruct@npm:^3.0.0":
version: 3.0.0
resolution: "@metamask/superstruct@npm:3.0.0"
checksum: 667f8f2947186972516bb72b4ba215eaeede257c8beb0450583dd4c8b00c28729ff938267ca8804a3a351277fd627b8607cafeb71eb7045a2b6930639bb6a341
languageName: node
linkType: hard

"@metamask/utils@workspace:.":
version: 0.0.0-use.local
resolution: "@metamask/utils@workspace:."
Expand All @@ -1066,6 +1073,7 @@ __metadata:
"@metamask/eslint-config-jest": ^12.0.0
"@metamask/eslint-config-nodejs": ^12.0.0
"@metamask/eslint-config-typescript": ^12.0.0
"@metamask/superstruct": ^3.0.0
"@noble/hashes": ^1.3.1
"@scure/base": ^1.1.3
"@ts-bridge/cli": ^0.1.2
Expand Down Expand Up @@ -1095,7 +1103,6 @@ __metadata:
prettier-plugin-packagejson: ^2.3.0
semver: ^7.5.4
stdio-mock: ^1.2.0
superstruct: ^1.0.3
ts-jest: ^29.0.3
ts-node: ^10.7.0
tsd: ^0.29.0
Expand Down Expand Up @@ -6753,13 +6760,6 @@ __metadata:
languageName: node
linkType: hard

"superstruct@npm:^1.0.3":
version: 1.0.3
resolution: "superstruct@npm:1.0.3"
checksum: 761790bb111e6e21ddd608299c252f3be35df543263a7ebbc004e840d01fcf8046794c274bcb351bdf3eae4600f79d317d085cdbb19ca05803a4361840cc9bb1
languageName: node
linkType: hard

"supports-color@npm:^5.3.0":
version: 5.5.0
resolution: "supports-color@npm:5.5.0"
Expand Down

0 comments on commit 631d1eb

Please sign in to comment.