Skip to content

Commit

Permalink
Switch to pnpm (#17)
Browse files Browse the repository at this point in the history
- Switch from npm to pnpm
- Import `package-lock.json` into `pnpm-lock.yaml` using `pnpm import`
- Pin pnpm via corepack into `package.json`
- Use pnpm on CI
- Change npm to pnpm in docs
- Fix a small TypeError in a test
  • Loading branch information
timomeh authored Apr 24, 2024
1 parent 73dacf4 commit edea8b2
Show file tree
Hide file tree
Showing 7 changed files with 11,190 additions and 16,849 deletions.
8 changes: 4 additions & 4 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ description: Setup Node.js and install dependencies
runs:
using: composite
steps:
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
cache-dependency-path: 'package-lock.json'
- run: npm ci
node-version: 20.x
cache: pnpm
- run: pnpm install
shell: bash
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- run: npm run lint
- run: npm run typecheck
- run: pnpm lint
- run: pnpm typecheck

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: npm test
- run: pnpm test

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: npm run build
- run: pnpm build
25 changes: 15 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This project is built with [Preact](https://preactjs.com/) and bundled with [Vite](https://vitejs.dev/).

## Prerequisites

- Node.js
- This project uses pnpm. Run `corepack enable` to use pnpm in this project.

## Development workflow

This project uses Vite's [Library Mode](https://vitejs.dev/guide/build.html#library-mode).
Expand All @@ -10,10 +15,10 @@ This project uses Vite's [Library Mode](https://vitejs.dev/guide/build.html#libr
- The example app in the `src/` directory.
- Tests and Stories are colocated to embeds inside the `lib/` directory.

To get started with the project, run `npm i` in the root directory.
To get started with the project, run `pnpm i` in the root directory.

```sh
npm i
pnpm i
```

### Example App
Expand All @@ -22,20 +27,20 @@ The [example app](/example/) demonstrates usage of the library and works as a de

It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild.

To start the development server, run `npm run dev`.
To start the development server, run `pnpm dev`.

```sh
npm run dev
pnpm dev
```

You can then open the example app in your browser.

### Storybook

To develop with Storybook, run `npm run storybook`.
To develop with Storybook, run `pnpm storybook`.

```sh
npm run storybook
pnpm storybook
```

The [storybook](/storybook/) is used to develop the UI of an embed without having to initialize it. Changes to the library's JavaScript code will be reflected in Storybook without a rebuild.
Expand All @@ -45,14 +50,14 @@ The [storybook](/storybook/) is used to develop the UI of an embed without havin
Make sure your code passes TypeScript and ESLint. Run the following to verify:

```sh
npm run typecheck
npm run lint
pnpm typecheck
pnpm lint
```

To fix formatting errors, run the following:

```sh
npm run lint --fix
pnpm lint --fix
```

## Testing
Expand All @@ -62,5 +67,5 @@ We use [Vitest](https://vitest.dev/) for testing, together with [Preact Testing
Run the unit tests by:

```sh
npm test
pnpm test
```
4 changes: 2 additions & 2 deletions lib/PortingEmbed/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('updating a porting', () => {
const sub = db.subscriptions.find(
(s) => s.id === csn.intent.completePorting.subscription,
)
const prt = db.portings.find((p) => p.id === sub!.porting!.id)
const prt = db.portings.find((p) => p.id === sub?.porting?.id)
return prt
}

Expand Down Expand Up @@ -368,7 +368,7 @@ describe('updating a porting', () => {
})
})

expect(submitStatusEvent.mock.lastCall[0].error).toMatch(
expect(submitStatusEvent.mock.lastCall[0].error.message).toMatch(
/FETCH_FAILED: Simulated error/i,
)
})
Expand Down
Loading

0 comments on commit edea8b2

Please sign in to comment.