Skip to content

Commit

Permalink
Replace 'superstruct' imports with '@metamask/superstruct' (#613)
Browse files Browse the repository at this point in the history
## 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.
```
  • Loading branch information
MajorLift authored Jun 12, 2024
1 parent 8209318 commit d43fa26
Show file tree
Hide file tree
Showing 7 changed files with 1,801 additions and 1,490 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"verify-snaps": "ts-node scripts/verify-snaps.ts"
},
"dependencies": {
"@metamask/utils": "^8.3.0",
"@metamask/superstruct": "^3.0.0",
"@metamask/utils": "^8.5.0",
"@noble/curves": "^1.2.0",
"@noble/hashes": "^1.3.2",
"superstruct": "^1.0.3"
"@noble/hashes": "^1.3.2"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^2.3.1",
Expand Down
2 changes: 1 addition & 1 deletion scripts/verify-snaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
getLocalizedSnapManifest,
getSnapChecksum,
} from '@metamask/snaps-utils';
import type { Infer } from '@metamask/superstruct';
import { assertIsSemVerVersion, getErrorMessage } from '@metamask/utils';
import deepEqual from 'fast-deep-equal';
import { imageSize as imageSizeSync } from 'image-size';
import { resolve } from 'path';
import semver from 'semver/preload';
import type { Infer } from 'superstruct';
import { promisify } from 'util';

import type { VerifiedSnapStruct } from '../src';
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
VersionStruct,
VersionRangeStruct,
ChecksumStruct,
} from '@metamask/utils';
import type { Infer } from 'superstruct';
import type { Infer } from '@metamask/superstruct';
import {
pattern,
size,
Expand All @@ -16,7 +11,12 @@ import {
enums,
refine,
boolean,
} from 'superstruct';
} from '@metamask/superstruct';
import {
VersionStruct,
VersionRangeStruct,
ChecksumStruct,
} from '@metamask/utils';

// For now, validate that each snap is using an NPM id.
const NpmIdStruct = refine(string(), 'Npm ID', (value) =>
Expand Down
2 changes: 1 addition & 1 deletion src/registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert } from '@metamask/superstruct';
import type { SemVerRange, SemVerVersion } from '@metamask/utils';
import { assert } from 'superstruct';

import type { SnapsRegistryDatabase } from '.';
import { SnapsRegistryDatabaseStruct } from '.';
Expand Down
4 changes: 2 additions & 2 deletions src/verify.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Infer } from '@metamask/superstruct';
import { literal, object } from '@metamask/superstruct';
import type { Hex } from '@metamask/utils';
import {
StrictHexStruct,
Expand All @@ -8,8 +10,6 @@ import {
} from '@metamask/utils';
import { secp256k1 } from '@noble/curves/secp256k1';
import { sha256 } from '@noble/hashes/sha256';
import type { Infer } from 'superstruct';
import { literal, object } from 'superstruct';

export const SignatureStruct = object({
signature: StrictHexStruct,
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
Loading

0 comments on commit d43fa26

Please sign in to comment.