Skip to content

Commit d43fa26

Browse files
authored
Replace 'superstruct' imports with '@metamask/superstruct' (#613)
## Explanation As part of the Wallet Framework Team's OKR (Q2 2024 O3KR4) for upgrading TypeScript to v5.0+ in the core monorepo, we are updating dependencies of the core repo so that they generate builds and type declarations for both CJS and ESM. This requirement applies to nested dependencies as well, so we are also replacing `superstruct` with the ESM-compatible fork `@metamask/superstruct` in all core dependency packages. ## Description - [x] Replace `superstruct` dependency with `@metamask/superstruct` `^3.0.0`. - [x] Replace all `superstruct` import statements with `@metamask/superstruct` - [x] Bump `@metamask/utils` to `^8.5.0`. - [x] If feasible without too much additional work: - [ ] ~Bump `typescript` to `~5.0.4`~ - [x] Set tsconfig options `module` and `moduleResolution` to `NodeNext`. - [ ] Using the `create-release-pr` github action, publish a new release containing these changes. ## References - Closes #611 ## Changelog ```md ## [3.1.1] ### Changed - Bump `@metamask/utils` from `^8.3.0` to `^8.5.0` ([#613](#613)) ### Fixed - Replace `superstruct` with ESM-compatible `@metamask/superstruct` `^3.0.0` ([#613](#613)) - This fixes the issue of this package being unusable by any TypeScript project that uses `Node16` or `NodeNext` as its `moduleResolution` option. ```
1 parent 8209318 commit d43fa26

File tree

7 files changed

+1801
-1490
lines changed

7 files changed

+1801
-1490
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
"verify-snaps": "ts-node scripts/verify-snaps.ts"
3131
},
3232
"dependencies": {
33-
"@metamask/utils": "^8.3.0",
33+
"@metamask/superstruct": "^3.0.0",
34+
"@metamask/utils": "^8.5.0",
3435
"@noble/curves": "^1.2.0",
35-
"@noble/hashes": "^1.3.2",
36-
"superstruct": "^1.0.3"
36+
"@noble/hashes": "^1.3.2"
3737
},
3838
"devDependencies": {
3939
"@lavamoat/allow-scripts": "^2.3.1",

scripts/verify-snaps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import {
55
getLocalizedSnapManifest,
66
getSnapChecksum,
77
} from '@metamask/snaps-utils';
8+
import type { Infer } from '@metamask/superstruct';
89
import { assertIsSemVerVersion, getErrorMessage } from '@metamask/utils';
910
import deepEqual from 'fast-deep-equal';
1011
import { imageSize as imageSizeSync } from 'image-size';
1112
import { resolve } from 'path';
1213
import semver from 'semver/preload';
13-
import type { Infer } from 'superstruct';
1414
import { promisify } from 'util';
1515

1616
import type { VerifiedSnapStruct } from '../src';

src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
VersionStruct,
3-
VersionRangeStruct,
4-
ChecksumStruct,
5-
} from '@metamask/utils';
6-
import type { Infer } from 'superstruct';
1+
import type { Infer } from '@metamask/superstruct';
72
import {
83
pattern,
94
size,
@@ -16,7 +11,12 @@ import {
1611
enums,
1712
refine,
1813
boolean,
19-
} from 'superstruct';
14+
} from '@metamask/superstruct';
15+
import {
16+
VersionStruct,
17+
VersionRangeStruct,
18+
ChecksumStruct,
19+
} from '@metamask/utils';
2020

2121
// For now, validate that each snap is using an NPM id.
2222
const NpmIdStruct = refine(string(), 'Npm ID', (value) =>

src/registry.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { assert } from '@metamask/superstruct';
12
import type { SemVerRange, SemVerVersion } from '@metamask/utils';
2-
import { assert } from 'superstruct';
33

44
import type { SnapsRegistryDatabase } from '.';
55
import { SnapsRegistryDatabaseStruct } from '.';

src/verify.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Infer } from '@metamask/superstruct';
2+
import { literal, object } from '@metamask/superstruct';
13
import type { Hex } from '@metamask/utils';
24
import {
35
StrictHexStruct,
@@ -8,8 +10,6 @@ import {
810
} from '@metamask/utils';
911
import { secp256k1 } from '@noble/curves/secp256k1';
1012
import { sha256 } from '@noble/hashes/sha256';
11-
import type { Infer } from 'superstruct';
12-
import { literal, object } from 'superstruct';
1313

1414
export const SignatureStruct = object({
1515
signature: StrictHexStruct,

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"exactOptionalPropertyTypes": true,
55
"forceConsistentCasingInFileNames": true,
66
"lib": ["ES2020", "DOM"],
7-
"module": "CommonJS",
8-
"moduleResolution": "node",
7+
"module": "NodeNext",
8+
"moduleResolution": "NodeNext",
99
"noEmit": true,
1010
"noErrorTruncation": true,
1111
"noUncheckedIndexedAccess": true,

0 commit comments

Comments
 (0)