Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ module.exports = {

extends: ['@metamask/eslint-config'],

rules: {
// Handled by Oxfmt.
'prettier/prettier': 'off',
'import/order': 'off',
},

overrides: [
{
files: ['*.ts'],
Expand Down
20 changes: 20 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",
"printWidth": 80,
"quoteProps": "as-needed",
"singleQuote": true,
"sortImports": {
"newlinesBetween": false,
"groups": [
["builtin", "external"],
{ "newlinesBetween": true },
["internal", "parent", "sibling", "index", "unknown"]
]
},
"sortPackageJson": {
"sortScripts": true
},
"tabWidth": 2,
"trailingComma": "all",
"ignorePatterns": [".yarnrc.yml", "CHANGELOG.md"]
}
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,28 @@ The API documentation can be generated with the command `yarn docs`, which saves
The project follows the same release process as the other libraries in the MetaMask organization. The GitHub Actions [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) and [`action-publish-release`](https://github.com/MetaMask/action-publish-release) are used to automate the release process; see those repositories for more information about how they work.

1. Choose a release version.

- The release version should be chosen according to SemVer. Analyze the changes to see whether they include any breaking changes, new features, or deprecations, then choose the appropriate SemVer version. See [the SemVer specification](https://semver.org/) for more information.

2. If this release is backporting changes onto a previous release, then ensure there is a major version branch for that version (e.g. `1.x` for a `v1` backport release).

- The major version branch should be set to the most recent release with that major version. For example, when backporting a `v1.0.2` release, you'd want to ensure there was a `1.x` branch that was set to the `v1.0.1` tag.

3. Trigger the [`workflow_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) event [manually](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow) for the `Create Release Pull Request` action to create the release PR.

- For a backport release, the base branch should be the major version branch that you ensured existed in step 2. For a normal release, the base branch should be the main branch for that repository (which should be the default value).
- This should trigger the [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) workflow to create the release PR.

4. Update the changelog to move each change entry into the appropriate change category ([See here](https://keepachangelog.com/en/1.0.0/#types) for the full list of change categories, and the correct ordering), and edit them to be more easily understood by users of the package.

- Generally any changes that don't affect consumers of the package (e.g. lockfile changes or development environment changes) are omitted. Exceptions may be made for changes that might be of interest despite not having an effect upon the published package (e.g. major test improvements, security improvements, improved documentation, etc.).
- Try to explain each change in terms that users of the package would understand (e.g. avoid referencing internal variables/concepts).
- Consolidate related changes into one change entry if it makes it easier to explain.
- Run `yarn auto-changelog validate --rc` to check that the changelog is correctly formatted.

5. Review and QA the release.

- If changes are made to the base branch, the release branch will need to be updated with these changes and review/QA will need to restart again. As such, it's probably best to avoid merging other PRs into the base branch while review is underway.

6. Squash & Merge the release.

- This should trigger the [`action-publish-release`](https://github.com/MetaMask/action-publish-release) workflow to tag the final release commit and publish the release on GitHub.

7. Publish the release on npm.

- Be very careful to use a clean local environment to publish the release, and follow exactly the same steps used during CI.
- Use `npm publish --dry-run` to examine the release contents to ensure the correct files are included. Compare to previous releases if necessary (e.g. using `https://unpkg.com/browse/[package name]@[package version]/`).
- Once you are confident the release contents are correct, publish the release using `npm publish`.
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
"bugs": {
"url": "https://github.com/MetaMask/utils/issues"
},
"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/utils.git"
},
"license": "ISC",
"files": [
"dist"
],
"sideEffects": false,
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.cts",
"exports": {
".": {
"import": {
Expand All @@ -35,12 +41,10 @@
},
"./package.json": "./package.json"
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.cts",
"files": [
"dist"
],
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"scripts": {
"build": "ts-bridge --project tsconfig.build.json --clean",
"build:docs": "typedoc",
Expand All @@ -50,16 +54,13 @@
"lint:dependencies": "depcheck && yarn dedupe",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
"lint:misc": "oxfmt --ignore-path .gitignore",
"prepack": "./scripts/prepack.sh",
"test": "yarn test:source && yarn test:types",
"test:source": "jest && jest-it-up",
"test:types": "tsd",
"test:watch": "jest --watch"
},
"resolutions": {
"jest-worker@^28.1.3": "patch:jest-worker@npm%3A28.1.3#./.yarn/patches/jest-worker-npm-28.1.3-5d0ff9006c.patch"
},
"dependencies": {
"@ethereumjs/tx": "^4.2.0",
"@metamask/scure-bip39": "^2.1.1",
Expand Down Expand Up @@ -92,18 +93,18 @@
"@typescript-eslint/parser": "^5.43.0",
"depcheck": "^1.4.7",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.2",
"eslint-plugin-jsdoc": "^39.9.1",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^6.1.1",
"jest": "^29.2.2",
"jest-it-up": "^2.0.2",
"jest-when": "^3.6.0",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.3.0",
"oxfmt": "^0.44.0",
"prettier": "^3.3.3",
"stdio-mock": "^1.2.0",
"ts-jest": "^29.0.3",
"ts-node": "^10.7.0",
Expand All @@ -112,20 +113,19 @@
"typescript": "~5.3.3",
"web3": "^4.16.0"
},
"packageManager": "yarn@4.16.0",
"resolutions": {
"jest-worker@^28.1.3": "patch:jest-worker@npm%3A28.1.3#./.yarn/patches/jest-worker-npm-28.1.3-5d0ff9006c.patch"
},
"tsd": {
"directory": "src"
},
"engines": {
"node": "^18.18 || ^20.14 || >=22"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"packageManager": "yarn@4.16.0",
"lavamoat": {
"allowScripts": {
"@lavamoat/preinstall-always-fail": false
}
},
"tsd": {
"directory": "src"
}
}
13 changes: 9 additions & 4 deletions src/__fixtures__/bytes.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export type Json =
export type ObjectOptional<Schema extends Record<string, unknown>> = {
[Key in keyof Schema as Schema[Key] extends ExactOptionalGuard
? Key
: never]?: Schema[Key] extends ExactOptionalGuard & infer Original
: never]?: Schema[Key] extends ExactOptionalGuard & (infer Original)
? Original
: never;
} & {
Expand Down Expand Up @@ -699,8 +699,8 @@ export function getJsonRpcIdValidator(options?: JsonRpcValidatorOptions) {
const isValidJsonRpcId = (id: unknown): id is JsonRpcId => {
return Boolean(
(typeof id === 'number' && (permitFractions || Number.isInteger(id))) ||
(typeof id === 'string' && (permitEmptyString || id.length > 0)) ||
(permitNull && id === null),
(typeof id === 'string' && (permitEmptyString || id.length > 0)) ||
(permitNull && id === null),
);
};

Expand Down
Loading
Loading