Skip to content

Commit

Permalink
Upgrade to Yarn v4 (#289)
Browse files Browse the repository at this point in the history
This commit aligns this repo more closely with our module template.

- Add `packageManager` to `package.json`
- Add `allow-scripts` Yarn plugin
- Add Yarn constraints (but modified to suit this package, whose build
pipeline is not fully standardized with the module template)
- Remove `setup` script (since `allow-scripts` gets called automatically
now)
- Replace `prepublishOnly` script with `prepack`
- Update GitHub workflow to install Yarn via Corepack
- Update Yarn-specific section of `.gitignore`
- Update installation instructions in README
- Upgrade `eslint-plugin-jsdoc` as the version we were using was
previously not compatible with the version of Node we are using, but
Yarn v1 did not pick this up. Fix lint violations to match.
  • Loading branch information
mcmire authored Dec 5, 2024
1 parent 784421b commit 95f269e
Show file tree
Hide file tree
Showing 12 changed files with 6,666 additions and 4,396 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ jobs:
node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
- name: Install Corepack via Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install Yarn
run: corepack enable
- name: Install Node.js ${{ matrix.node-version }} and restore Yarn cache
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- run: yarn --frozen-lockfile
- run: yarn allow-scripts
cache: 'yarn'
- name: Install dependencies via Yarn
run: yarn --immutable
- run: yarn build
- run: yarn lint
- run: yarn test
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
# We check out the release pull request's base branch, which will be
# used as the base branch for all git operations.
ref: ${{ github.event.pull_request.base.ref }}
- uses: actions/setup-node@v4
ref: ${{ github.sha }}
- name: Install Corepack via Node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: yarn
node-version-file: '.nvmrc'
- name: Install Yarn
run: corepack enable
- name: Restore Yarn cache
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- uses: MetaMask/action-publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13 changes: 8 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ node_modules/
# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
# yarn v3 (w/o zero-install)
# See: https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
9 changes: 9 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable */
//prettier-ignore
module.exports = {
name: "@yarnpkg/plugin-allow-scripts",
factory: function (require) {
var plugin=(()=>{var l=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var p=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(o,e)=>(typeof require<"u"?require:o)[e]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var u=(t,o)=>{for(var e in o)l(t,e,{get:o[e],enumerable:!0})},f=(t,o,e,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of a(o))!c.call(t,i)&&i!==e&&l(t,i,{get:()=>o[i],enumerable:!(r=s(o,i))||r.enumerable});return t};var m=t=>f(l({},"__esModule",{value:!0}),t);var g={};u(g,{default:()=>d});var n=p("@yarnpkg/shell"),x={hooks:{afterAllInstalled:async()=>{let t=await(0,n.execute)("yarn run allow-scripts");t!==0&&process.exit(t)}}},d=x;return m(g);})();
return plugin;
}
};
2 changes: 0 additions & 2 deletions .yarnrc

This file was deleted.

17 changes: 17 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
compressionLevel: mixed

enableGlobalCache: false

enableScripts: false

enableTelemetry: 0

logFilters:
- code: YN0004
level: discard

nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs
spec: 'https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js'
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ blockTracker.on('error', (err) => console.error(err));
### Setup

- Install the current LTS version of [Node.js](https://nodejs.org)
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm use` will automatically choose the right node version for you.
- Install [Yarn v1](https://yarnpkg.com/en/docs/install)
- Run `yarn setup` to install dependencies and run any requried post-install scripts
- **Warning:** Do not use the `yarn` / `yarn install` command directly. Use `yarn setup` instead. The normal install command will skip required post-install scripts, leaving your development environment in an invalid state.
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm install` will install the latest version and running `nvm use` will automatically choose the right node version for you.
- Install [Yarn](https://yarnpkg.com) v4 via [Corepack](https://github.com/nodejs/corepack?tab=readme-ov-file#how-to-install)
- Run `yarn install` to install dependencies and run any required post-install scripts

### Testing and Linting

Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@metamask/eth-block-tracker",
"version": "11.0.3",
"description": "A block tracker for the Ethereum blockchain. Keeps track of the latest block.",
"description": "A block tracker for the Ethereum blockchain. Keeps track of the latest block",
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/eth-block-tracker.git"
Expand All @@ -15,12 +15,12 @@
"scripts": {
"build": "tsc --project tsconfig.build.json",
"build:clean": "rimraf dist && yarn build",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint": "yarn lint:eslint && yarn lint:constraints && yarn lint:misc --check",
"lint:constraints": "yarn constraints",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
"prepublishOnly": "yarn build:clean && yarn lint && yarn test",
"setup": "yarn install && yarn allow-scripts",
"prepack": "./scripts/prepack.sh",
"test": "jest",
"test:watch": "jest --watch"
},
Expand All @@ -45,12 +45,13 @@
"@types/pify": "^5.0.1",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"@yarnpkg/types": "^4.0.0",
"eslint": "^8.21.0",
"eslint-config-prettier": "^8.1.0",
"eslint-import-resolver-typescript": "^2.7.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.9.1",
"eslint-plugin-jsdoc": "^41.0.0",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
Expand All @@ -62,6 +63,7 @@
"ts-node": "^10.7.0",
"typescript": "~4.8.4"
},
"packageManager": "[email protected]",
"engines": {
"node": "^18.16 || ^20 || >=22"
},
Expand Down
11 changes: 11 additions & 0 deletions scripts/prepack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e
set -o pipefail

if [[ -n $SKIP_PREPACK ]]; then
echo "Notice: skipping prepack."
exit 0
fi

yarn build
4 changes: 4 additions & 0 deletions tests/withBlockTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function getFakeProvider({
* provider.
* @param callback - A callback which will be called with the built block
* tracker.
* @returns The provider and block tracker.
*/
async function withPollingBlockTracker(
options: WithPollingBlockTrackerOptions,
Expand All @@ -161,6 +162,7 @@ async function withPollingBlockTracker(
*
* @param callback - A callback which will be called with the built block
* tracker.
* @returns The provider and block tracker.
*/
async function withPollingBlockTracker(
callback: WithPollingBlockTrackerCallback,
Expand Down Expand Up @@ -197,6 +199,7 @@ async function withPollingBlockTracker(
* provider.
* @param callback - A callback which will be called with the built block
* tracker.
* @returns The provider and block tracker.
*/
async function withSubscribeBlockTracker(
options: WithSubscribeBlockTrackerOptions,
Expand All @@ -209,6 +212,7 @@ async function withSubscribeBlockTracker(
*
* @param callback - A callback which will be called with the built block
* tracker.
* @returns The provider and block tracker.
*/
async function withSubscribeBlockTracker(
callback: WithSubscribeBlockTrackerCallback,
Expand Down
Loading

0 comments on commit 95f269e

Please sign in to comment.