Skip to content

Commit

Permalink
Ensure preview build versions are semver-parseable (#4034)
Browse files Browse the repository at this point in the history
Preview build versions are based on a commit ID. If the commit ID starts
with "0" — for instance, "0340690" — then the resulting version — for
instance, "2.3.4-preview.0340690" — will not be semver-parseable, and
therefore NPM will not allow such a version to be published.

This commit replaces the "." in the version string with a "-", which
resolves the issue.

The preview build instructions in the contributing doc has also been
updated.
  • Loading branch information
mcmire authored Mar 12, 2024
1 parent 816c8b2 commit 14f625a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ If you're a member of the MetaMask organization, you can create preview builds b
Note two things about each package:

- The name is scoped to `@metamask-previews` instead of `@metamask`.
- The ID of the last commit in the branch is appended to the version, e.g. `1.2.3-e2df9b4` instead of `1.2.3`.
- The ID of the last commit in the branch is appended to the version, e.g. `1.2.3-preview-e2df9b4` instead of `1.2.3`.

Now you can [use these preview builds in your project](#using-preview-builds).

Expand All @@ -125,7 +125,7 @@ If you've forked this repository, you can create preview builds based on a branc
You should be able to see the published version of each package in the output. Note two things:

- The name is scoped to the NPM organization you entered instead of `@metamask`.
- The ID of the last commit in the branch is appended to the version, e.g. `1.2.3-e2df9b4` instead of `1.2.3`.
- The ID of the last commit in the branch is appended to the version, e.g. `1.2.3-preview-e2df9b4` instead of `1.2.3`.

Now you can [use these preview builds in your project](#using-preview-builds).

Expand All @@ -145,16 +145,16 @@ To use a preview build for a package within a project, you need to override the

> **Example:**
>
> - If you're a member of MetaMask, your project uses Yarn, `@metamask/controller-utils` is listed in dependencies at `^1.1.4`, and you want to use the preview version `1.2.3-e2df9b4`, add the following to `resolutions`:
> - If you're a member of MetaMask, your project uses Yarn, `@metamask/controller-utils` is listed in dependencies at `^1.1.4`, and you want to use the preview version `1.2.3-preview-e2df9b4`, add the following to `resolutions`:
>
> ```
> "@metamask/controller-utils@^1.1.4": "npm:@metamask-previews/[email protected]"
> "@metamask/controller-utils@^1.1.4": "npm:@metamask-previews/[email protected]preview-e2df9b4"
> ```
>
> - If you are an individual contributor, your project uses NPM, `@metamask/assets-controllers` is listed in dependencies at `^3.4.7`, and you want to use the preview version `4.5.6-bc2a997` published under `@foo`, add the following to `overrides`:
> - If you are an individual contributor, your project uses NPM, `@metamask/assets-controllers` is listed in dependencies at `^3.4.7`, and you want to use the preview version `4.5.6-preview-bc2a997` published under `@foo`, add the following to `overrides`:
>
> ```
> "@metamask/assets-controllers@^3.4.7": "npm:@foo/[email protected]"
> "@metamask/assets-controllers@^3.4.7": "npm:@foo/[email protected]preview-bc2a997"
> ```
4. Run `yarn install`.
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepare-preview-builds.jq
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# of the version. Technically we'd want to bump the non-prerelease portion as
# well if we wanted this to be SemVer-compliant, but it was simpler not to.
# This is just for testing, it doesn't need to strictly follow SemVer.
.version |= split("-")[0] + "-preview.\($hash)" |
.version |= split("-")[0] + "-preview-\($hash)" |

# The workspace dependencies are updated to point to the exact preview build
# version, so that Yarn does not try to resolve a different version from the
Expand Down

0 comments on commit 14f625a

Please sign in to comment.