Skip to content

Commit

Permalink
Migrate to pnpm (#2548)
Browse files Browse the repository at this point in the history
* wip: migrate to pnpm

* no concurrently

* fix build

* chore remove yarn scripts

* fix type package

* wip: fix workflow files

* wip: fix workflow files

* revert install-script

* add babel-loader

* Revert "add babel-loader"

This reverts commit b79e279.

* install gatsby-plugin-pnpm

* wip: gatsby

* try simpler compressed-size-action.yml

* Revert "try simpler compressed-size-action.yml"

This reverts commit 822baae.

* use the latest version?

* remove setup-node?

* revert

* use pnpm

* some more adjustments

* add type field

* tiny improvement
  • Loading branch information
dai-shi committed May 12, 2024
1 parent feb5ae3 commit 1dbe400
Show file tree
Hide file tree
Showing 15 changed files with 18,994 additions and 17,064 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Fixes #

## Check List

- [ ] `yarn run prettier` for formatting code and docs
- [ ] `pnpm run prettier` for formatting code and docs
12 changes: 9 additions & 3 deletions .github/workflows/compressed-size-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: preactjs/compressed-size-action@v2
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8.2.0
- uses: actions/setup-node@v3
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
node-version: 18
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- uses: preactjs/compressed-size-action@v2
24 changes: 12 additions & 12 deletions .github/workflows/lint-and-type.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
node-version: '18'
cache: yarn
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- run: yarn install --frozen-lockfile --check-files
- name: Prettier
run: yarn prettier:ci
- name: Lint
run: yarn eslint:ci
- name: Type
run: yarn pretest
version: 8.2.0
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- run: pnpm install --frozen-lockfile
- run: pnpm test:format
- run: pnpm test:types
- run: pnpm test:lint
12 changes: 10 additions & 2 deletions .github/workflows/livecodes-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8.2.0
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- uses: live-codes/preview-in-livecodes@v1
with:
install-command: "yarn install --frozen-lockfile --check-files"
build-command: "yarn build"
install-command: "pnpm install --frozen-lockfile"
build-command: "pnpm build"
base-url: "https://{{LC::REF}}.preview-in-livecodes-demo.pages.dev"
21 changes: 12 additions & 9 deletions .github/workflows/test-multiple-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ jobs:
build: [cjs, esm, umd]
env: [development, production]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
node-version: '18'
cache: yarn
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- run: yarn install --frozen-lockfile --check-files
- run: yarn build
version: 8.2.0
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- run: pnpm install --frozen-lockfile
- run: pnpm build
- name: Use React 17 for production test
if: ${{ matrix.env == 'production' }}
run: |
yarn add -D react@17.0.2 react-dom@17.0.2 @testing-library/react@12.1.4
pnpm add -D react@17.0.2 react-dom@17.0.2 @testing-library/react@12.1.4
- name: Patch for DEV-ONLY
if: ${{ matrix.env == 'development' }}
run: |
Expand Down Expand Up @@ -65,6 +68,6 @@ jobs:
NODE_ENV: ${{ matrix.env }}
- name: Test ${{ matrix.build }} ${{ matrix.env }}
run: |
yarn test:ci:build # test:ci
pnpm test-build:spec # test:spec
env:
NODE_ENV: ${{ matrix.env }}
44 changes: 24 additions & 20 deletions .github/workflows/test-multiple-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
node-version: '18'
cache: yarn
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- run: yarn install --frozen-lockfile --check-files
- name: Test Build # we don't have any other workflows to test build
run: yarn build
- name: Test Default
run: yarn test:ci
version: 8.2.0
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- run: pnpm install --frozen-lockfile
- run: pnpm build # we don't have any other workflows to test build
- run: pnpm test:spec

test_matrix:
runs-on: ubuntu-latest
Expand All @@ -36,25 +37,28 @@ jobs:
- 18.3.0-canary-4b84f1161-20240318
- 0.0.0-experimental-4b84f1161-20240318
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8.2.0
- uses: actions/setup-node@v3
with:
node-version: '18'
cache: yarn
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- run: yarn install --frozen-lockfile --check-files
node-version: 18
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- run: pnpm install --frozen-lockfile
- name: Install legacy testing-library
if: ${{ startsWith(matrix.react, '16.') || startsWith(matrix.react, '17.') }}
run: yarn add -D @testing-library/react@12.1.4
run: pnpm add -D @testing-library/react@12.1.4
- name: Patch for React 16
if: ${{ startsWith(matrix.react, '16.') }}
run: |
sed -i~ '1s/^/import React from "react";/' tests/*/*.tsx tests/*/*/*.tsx
sed -i~ 's/"jsx": "react-jsx"/"jsx": "react"/' tsconfig.json
sed -i~ 's/import\.meta\.env[?]\.MODE/"DEVELOPMENT".toLowerCase()/' src/*.ts src/*/*.ts src/*/*/*.ts
- name: Test Build # we need to build for babel tests
run: yarn build
run: pnpm build
- name: Test ${{ matrix.react }}
run: |
yarn add -D react@${{ matrix.react }} react-dom@${{ matrix.react }}
yarn test:ci
pnpm add -D react@${{ matrix.react }} react-dom@${{ matrix.react }}
pnpm test:spec
40 changes: 16 additions & 24 deletions .github/workflows/test-old-typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ jobs:
- 3.9.7
- 3.8.3
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
node-version: '18'
cache: yarn
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- run: yarn install --frozen-lockfile --check-files
- run: yarn build
version: 8.2.0
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- run: pnpm install --frozen-lockfile
- run: pnpm build
- name: Patch for Newer TS
if: ${{ matrix.typescript == '4.9.5' || matrix.typescript == '4.8.4' }}
run: |
Expand Down Expand Up @@ -66,34 +69,23 @@ jobs:
sed -i~ 's/"jsx": "react-jsx",/"jsx": "react",/' tsconfig.json
sed -i~ 's/"noUncheckedIndexedAccess": true,//' tsconfig.json
sed -i~ 's/^import type /import /' tests/*/*.tsx tests/*/*/*.tsx
yarn json -I -f package.json -e "this.resolutions={}; this.resolutions['@types/prettier']='2.4.2'; this.resolutions['@types/node']='18.11.18';"
yarn add -D @types/prettier@2.4.2 @types/node@18.11.18 @types/yargs@17.0.13 @types/babel__traverse@7.18.2
pnpm json -I -f package.json -e "this.resolutions={}; this.resolutions['@types/prettier']='2.4.2'; this.resolutions['@types/node']='18.11.18';"
pnpm add -D @types/prettier@2.4.2 @types/node@18.11.18 @types/yargs@17.0.13 @types/babel__traverse@7.18.2
rm -r tests/react/vanilla-utils/atomWithObservable.*
- name: Install old TypeScript
run: yarn add -D typescript@${{ matrix.typescript }}
run: pnpm add -D typescript@${{ matrix.typescript }}
- name: Patch testing setup for Old TS
if: ${{ matrix.typescript == '4.4.4' || matrix.typescript == '4.3.5' || matrix.typescript == '4.2.3' || matrix.typescript == '4.1.5' || matrix.typescript == '4.0.5' || startsWith(matrix.typescript, '3.') }}
run: |
rm node_modules/@vitest/expect/dist/*.d.ts
echo "declare module '@vitest/expect'" >> ./src/types.d.ts
rm node_modules/@vitest/runner/dist/*.d.ts
echo "declare module '@vitest/runner'" >> ./src/types.d.ts
rm node_modules/@vitest/spy/dist/*.d.ts
echo "declare module '@vitest/spy'" >> ./src/types.d.ts
rm node_modules/@vitest/utils/dist/*.d.ts
echo "declare module '@vitest/utils'" >> ./src/types.d.ts
rm node_modules/vite-node/dist/*.d.ts
echo "declare module 'vite-node'" >> ./src/types.d.ts
rm node_modules/vitest/dist/*.d.ts
echo "declare module 'vitest'" >> ./src/types.d.ts
pnpm add -D vitest@0.33.0 @vitest/coverage-v8@0.33.0 @vitest/ui@0.33.0
- name: Patch testing setup for older TS
if: ${{ matrix.typescript == '4.0.5' || startsWith(matrix.typescript, '3.') }}
run: |
yarn add -D @testing-library/user-event@12.1.7 @testing-library/react@11.0.4
pnpm add -D @testing-library/user-event@12.1.7 @testing-library/react@11.0.4
rm node_modules/vitest/dist/*.d.ts
echo "declare module 'vitest'" >> ./src/types.d.ts
- name: Test ${{ matrix.typescript }}
run: |
rm -r node_modules/@types/babel__core/node_modules
sed -i~ 's/">=4.2": {/">=4.1": {/' node_modules/rxjs/package.json
yarn tsc --noEmit
pnpm test:types
16 changes: 8 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ If you would like to contribute by fixing an open issue or developing a new feat
1. Fork this repository
2. Create a new feature branch based off the `main` branch
3. Follow the [Core lib](#core-lib) and/or the [docs](#docs) guide below and come back to this once done
4. Run `yarn run prettier` to format the code
4. Run `pnpm run prettier` to format the code
5. Git stage your required changes and commit (review the commit guidelines below)
6. Submit the PR for review

### Core lib

1. Install dependencies by running `yarn`. We use [version 1](https://classic.yarnpkg.com/lang/en/docs/install) of yarn
1. Install dependencies by running `pnpm`.
2. Create failing tests for your fix or new feature in the `tests` folder
3. Implement your changes
4. Build the library `yarn run build` _(Pro-tip: `yarn run build-watch` runs the build in watch mode)_
5. Run the tests and ensure that they pass. _(Pro-tip: `yarn test:dev` runs the test in watch mode)_
6. You can use `yarn link` or `yalc` to sym-link this package and test it locally on your own project. Alternatively, you may use CodeSandbox CI's canary releases to test the changes in your own project (requires a PR to be created first)
4. Build the library `pnpm run build` _(Pro-tip: `pnpm run build-watch` runs the build in watch mode)_
5. Run the tests and ensure that they pass.
6. You can use `pnpm link` or `yalc` to sym-link this package and test it locally on your own project. Alternatively, you may use CodeSandbox CI's canary releases to test the changes in your own project (requires a PR to be created first)
7. Follow step 4 and onwards from the [general](#general) guide above to bring it to the finish line

### Docs

1. Navigate to the `website` folder. Eg. `cd website`
2. Install dependencies by running `yarn` in the `website` folder We use [version 1](https://classic.yarnpkg.com/lang/en/docs/install) of yarn
3. Run `yarn dev` to start the dev server
2. Install dependencies by running `pnpm` in the `website` folder
3. Run `pnpm dev` to start the dev server
4. Navigate to [`http://localhost:9000`](http://localhost:9000) to view the docs
5. Navigate to the `docs` folder and make necessary changes to the docs
6. Add your changes to the docs and see them live reloaded in the browser
Expand All @@ -49,7 +49,7 @@ We follow the [conventional commit spec](https://www.conventionalcommits.org/en/

Your commit type must be one of the following:

- **build**: Changes that affect the build system or external dependencies (example scopes: yarn, npm, rollup, etc.)
- **build**: Changes that affect the build system or external dependencies (example scopes: pnpm, npm, rollup, etc.)
- **ci**: Changes to our CI configuration files and scripts (example scopes: GitHub Actions)
- **docs**: Documentation only changes
- **feat**: A new feature
Expand Down
28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "jotai",
"description": "👻 Primitive and flexible state management for React",
"private": true,
"type": "commonjs",
"version": "2.8.0",
"description": "👻 Primitive and flexible state management for React",
"main": "./index.js",
"types": "./index.d.ts",
"typesVersions": {
Expand Down Expand Up @@ -60,8 +61,8 @@
"sideEffects": false,
"scripts": {
"prebuild": "shx rm -rf dist",
"build": "concurrently -m 8 'yarn:build:*'",
"build-watch": "concurrently -n watch: 'yarn:build:* --watch'",
"build": "pnpm run prebuild && pnpm run '/^build:.*/' && pnpm run postbuild",
"build-watch": "pnpm run '/^build:.*/' --watch",
"build:base": "rollup -c",
"build:utils": "rollup -c --config-utils",
"build:babel:plugin-debug-label": "rollup -c --config-babel_plugin-debug-label",
Expand All @@ -72,15 +73,15 @@
"build:react": "rollup -c --config-react --client-only",
"build:react:utils": "rollup -c --config-react_utils --client-only",
"build:experimental": "rollup -c --config-experimental",
"postbuild": "yarn patch-d-ts && yarn copy && yarn patch-ts3.8 && yarn patch-old-ts && yarn patch-esm-ts && yarn patch-readme",
"postbuild": "pnpm patch-d-ts && pnpm copy && pnpm patch-ts3.8 && pnpm patch-old-ts && pnpm patch-esm-ts && pnpm patch-readme",
"prettier": "prettier '*.{js,json,md}' '{src,tests,benchmarks,docs}/**/*.{ts,tsx,md,mdx}' --write",
"prettier:ci": "prettier '*.{js,json,md}' '{src,tests,benchmarks,docs}/**/*.{ts,tsx,md,mdx}' --list-different",
"eslint": "eslint --fix --no-eslintrc --c .eslintrc.json '*.{js,json,ts}' '{src,tests,benchmarks}/**/*.{ts,tsx}'",
"eslint:ci": "eslint --no-eslintrc --c .eslintrc.json '*.{js,json,ts}' '{src,tests,benchmarks}/**/*.{ts,tsx}'",
"pretest": "tsc",
"test": "vitest --ui --coverage",
"test:ci": "vitest && USE_STORE2=true vitest",
"test:ci:build": "vitest",
"test": "pnpm run '/^test:.*/'",
"test:format": "prettier '*.{js,json,md}' '{src,tests,benchmarks,docs}/**/*.{ts,tsx,md,mdx}' --list-different",
"test:types": "tsc --noEmit",
"test:lint": "eslint --no-eslintrc --c .eslintrc.json '*.{js,json,ts}' '{src,tests,benchmarks}/**/*.{ts,tsx}'",
"test:spec": "vitest && USE_STORE2=true vitest",
"test-build:spec": "vitest",
"patch-d-ts": "node -e \"var {entries}=require('./rollup.config.js');require('shelljs').find('dist/**/*.d.ts').forEach(f=>{entries.forEach(({find,replacement})=>require('shelljs').sed('-i',new RegExp(' from \\''+find.source.slice(0,-1)+'\\';$'),' from \\''+replacement+'\\';',f));require('shelljs').sed('-i',/ from '(\\.[^']+)\\.ts';$/,' from \\'\\$1\\';',f)})\"",
"copy": "shx cp -r dist/src/* dist/esm && shx cp -r dist/src/* dist && shx rm -rf dist/src && shx rm -rf dist/{src,tests} && downlevel-dts dist dist/ts3.8 --to=3.8 && shx cp package.json readme.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.prettier=undefined;\"",
"patch-ts3.8": "node -e \"require('shelljs').find('dist/ts3.8/**/*.d.ts').forEach(f=>require('fs').appendFileSync(f,'declare type Awaited<T> = T extends Promise<infer V> ? V : T;'))\"",
Expand Down Expand Up @@ -114,6 +115,7 @@
"url": "https://github.com/pmndrs/jotai/issues"
},
"homepage": "https://github.com/pmndrs/jotai",
"packageManager": "pnpm@8.15.0",
"devDependencies": {
"@babel/core": "^7.24.4",
"@babel/plugin-transform-react-jsx": "^7.23.4",
Expand All @@ -132,6 +134,7 @@
"@testing-library/react": "^14.2.2",
"@testing-library/user-event": "14.4.3",
"@types/babel__core": "^7.20.5",
"@types/babel__template": "^7.4.4",
"@types/node": "^20.12.4",
"@types/react": "18.2.56",
"@types/react-dom": "^18.2.24",
Expand All @@ -140,7 +143,6 @@
"@vitest/coverage-v8": "^1.4.0",
"@vitest/ui": "^1.4.0",
"benny": "^3.7.1",
"concurrently": "^8.2.2",
"downlevel-dts": "^0.11.0",
"esbuild": "^0.20.2",
"eslint": "^8.57.0",
Expand All @@ -162,6 +164,7 @@
"rollup-plugin-banner2": "^1.2.3",
"rollup-plugin-esbuild": "^6.1.1",
"rxjs": "^7.8.1",
"shelljs": "^0.8.5",
"shx": "^0.3.4",
"ts-expect": "^1.3.0",
"ts-node": "^10.9.2",
Expand All @@ -185,6 +188,5 @@
"react": {
"optional": true
}
},
"packageManager": "yarn@1.22.1"
}
}
Loading

0 comments on commit 1dbe400

Please sign in to comment.