Skip to content
Draft

v3 #3337

Show file tree
Hide file tree
Changes from 20 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
2 changes: 1 addition & 1 deletion .github/workflows/preview-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build
- run: pnpm dlx pkg-pr-new publish './dist' --compact --template './examples/*'
- run: pnpm dlx pkg-pr-new publish --compact --template './examples/*'
3 changes: 1 addition & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ jobs:
package-manager-cache: false
- run: pnpm install
- run: pnpm run build
- run: pnpm publish --no-git-checks
working-directory: dist
- run: pnpm publish --no-git-checks --tag next
38 changes: 5 additions & 33 deletions .github/workflows/test-multiple-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
strategy:
fail-fast: false
matrix:
build: [cjs, esm, umd]
env: [development, production]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
Expand All @@ -28,10 +27,6 @@ jobs:
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build
- name: Use React 17 for production test
if: ${{ matrix.env == 'production' }}
run: |
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 All @@ -42,36 +37,13 @@ jobs:
run: |
sed -i~ "s/\(it\|describe\)[.a-zA-Z]*('\PRD-ONLY\]/\1('/" tests/*/*.ts* tests/*/*/*.ts*
sed -i~ "s/\(it\|describe\)[.a-zA-Z]*('\[DEV-ONLY\]/\1.skip('/" tests/*/*.ts* tests/*/*/*.ts*
- name: Patch for CJS
if: ${{ matrix.build == 'cjs' }}
- name: Patch dist for production # React itself must stay in development mode for act() to work
if: ${{ matrix.env == 'production' }}
run: |
sed -i~ "s/resolve('\.\/src\(.*\)\.ts')/resolve('\.\/dist\1.js')/" vitest.config.mts
sed -i~ "s/import { useResetAtom } from 'jotai\/react\/utils'/const { useResetAtom } = require('..\/..\/..\/dist\/react\/utils.js')/" tests/react/utils/useResetAtom.test.tsx
sed -i~ "s/import { RESET, atomWithReducer, atomWithReset } from 'jotai\/vanilla\/utils'/const { RESET, atomWithReducer, atomWithReset } = require('..\/..\/..\/dist\/vanilla\/utils.js')/" tests/react/utils/useResetAtom.test.tsx
perl -i~ -0777 -pe "s/import {[^}]+} from 'jotai\/vanilla\/internals'/const { INTERNAL_buildStoreRev3: INTERNAL_buildStore, INTERNAL_initializeStoreHooksRev3: INTERNAL_initializeStoreHooks, INTERNAL_getBuildingBlocksRev3: INTERNAL_getBuildingBlocks } = require('..\/..\/dist\/vanilla\/internals.js')/g" tests/vanilla/store.test.tsx tests/vanilla/internals.test.tsx tests/vanilla/derive.test.tsx tests/vanilla/effect.test.ts
sed -i~ 's/process\.env\.NODE_ENV/"production"/g' dist/*.js dist/*/*.js dist/*/*/*.js
- name: Patch for ESM
if: ${{ matrix.build == 'esm' }}
run: |
sed -i~ "s/resolve('\.\/src\(.*\)\.ts')/resolve('\.\/dist\/esm\1.mjs')/" vitest.config.mts
sed -i~ "1s/^/import.meta.env.MODE='${NODE_ENV}';/" tests/*/*.tsx tests/*/*/*.tsx
env:
NODE_ENV: ${{ matrix.env }}
- name: Patch for UMD
if: ${{ matrix.build == 'umd' }}
run: |
sed -i~ "s/resolve('\.\/src\(.*\)\.ts')/resolve('\.\/dist\/umd\1.${NODE_ENV}.js')/" vitest.config.mts
rm tests/react/utils/useResetAtom.test.tsx # FIXME we skip this for now. Actually I'm not sure if we really run tests with UMD build
rm tests/vanilla/store.test.tsx tests/vanilla/internals.test.tsx tests/vanilla/derive.test.tsx tests/vanilla/effect.test.ts # FIXME we skip this for now. Actually I'm not sure if we really run tests with UMD build
env:
NODE_ENV: ${{ matrix.env }}
- name: Patch for SystemJS
if: ${{ matrix.build == 'system' }}
run: |
sed -i~ "s/resolve('\.\/src\(.*\)\.ts')/resolve('\.\/dist\/system\1.${NODE_ENV}.js')/" vitest.config.mts
env:
NODE_ENV: ${{ matrix.env }}
- name: Test ${{ matrix.build }} ${{ matrix.env }}
sed -i~ "s/resolve('\.\/src\(.*\)\.ts')/resolve('\.\/dist\1.js')/" vitest.config.mts
- name: Test ESM ${{ matrix.env }}
run: |
pnpm run test:spec
env:
NODE_ENV: ${{ matrix.env }}
18 changes: 0 additions & 18 deletions .github/workflows/test-multiple-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ jobs:
fail-fast: false
matrix:
react:
- 16.14.0
- 17.0.0
- 18.0.0
- 18.1.0
- 18.2.0
Expand All @@ -37,22 +35,6 @@ jobs:
node-version: 'lts/*'
cache: 'pnpm'
- run: pnpm install
- name: Install legacy testing-library
if: ${{ startsWith(matrix.react, '16.') || startsWith(matrix.react, '17.') }}
run: |
pnpm add -D @testing-library/react@12.1.4
- name: Patch for React 17
if: ${{ startsWith(matrix.react, '17.') }}
run: |
pnpm add -D vitest@3.2.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: pnpm run build
- name: Test ${{ matrix.react }}
run: |
pnpm add -D react@$REACT_VER react-dom@$REACT_VER
Expand Down
85 changes: 3 additions & 82 deletions .github/workflows/test-old-typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,6 @@ jobs:
- 5.7.3
- 5.6.3
- 5.5.4
- 5.4.5
- 5.3.3
- 5.2.2
- 5.1.6
- 5.0.4
- 4.9.5
- 4.8.4
- 4.7.4
- 4.6.4
- 4.5.5
- 4.4.4
- 4.3.5
- 4.2.3
- 4.1.5
- 4.0.5
- 3.9.7
- 3.8.3
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
Expand All @@ -49,71 +32,9 @@ jobs:
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build
- name: Patch for all TS
run: |
sed -i~ 's/"isolatedDeclarations": true,//' tsconfig.json
- name: Patch for v4/v3 TS
if: ${{ startsWith(matrix.typescript, '4.') || startsWith(matrix.typescript, '3.') }}
run: |
sed -i~ 's/"verbatimModuleSyntax": true,//' tsconfig.json
- name: Patch for Newer TS
if: ${{ matrix.typescript == '4.9.5' || matrix.typescript == '4.8.4' }}
run: |
sed -i~ 's/"moduleResolution": "bundler",/"moduleResolution": "node",/' tsconfig.json
sed -i~ 's/"allowImportingTsExtensions": true,//' tsconfig.json
sed -i~ 's/"jotai": \["\.\/src\/index\.ts"\],/"jotai": [".\/dist\/index.d.ts"],/' tsconfig.json
sed -i~ 's/"jotai\/\*": \["\.\/src\/\*\.ts"\]/"jotai\/*": [".\/dist\/*.d.ts"]/' tsconfig.json
sed -i~ 's/"include": .*/"include": ["src\/types.d.ts", "dist\/**\/*", "tests\/**\/*"],/' tsconfig.json
- name: Patch for specific TS version
run: |
ts_ver_esc=${TS_VER//./\\.}
sed -i~ "s/\/\/ @ts-expect-error .*\[SKIP-TS-${ts_ver_esc}\].*//" tests/*/*.tsx tests/*/*/*.tsx
sed -i~ "s/\/\/ .*\[ONLY-TS-${ts_ver_esc}\].* @ts-ignore/\/\/ @ts-ignore/" tests/*/*.tsx tests/*/*/*.tsx
env:
TS_VER: ${{ matrix.typescript }}
- name: Patch for Old TS
if: ${{ matrix.typescript == '4.7.4' || matrix.typescript == '4.6.4' || matrix.typescript == '4.5.5' || 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: |
sed -i~ 's/"target":/"skipLibCheck":true,"target":/' tsconfig.json
sed -i~ 's/"exactOptionalPropertyTypes": true,//' tsconfig.json
sed -i~ 's/"moduleResolution": "bundler",/"moduleResolution": "node",/' tsconfig.json
sed -i~ 's/"allowImportingTsExtensions": true,//' tsconfig.json
sed -i~ 's/"jotai": \["\.\/src\/index\.ts"\],/"jotai": [".\/dist\/ts3.8\/index.d.ts"],/' tsconfig.json
sed -i~ 's/"jotai\/\*": \["\.\/src\/\*\.ts"\]/"jotai\/*": [".\/dist\/ts3.8\/*.d.ts"]/' tsconfig.json
sed -i~ 's/"include": .*/"include": ["src\/types.d.ts", "dist\/**\/*", "tests\/**\/*"],/' tsconfig.json
yq eval -i '.overrides |= (.["@types/babel__traverse"] = "7.18.2")' pnpm-workspace.yaml
pnpm add -D @testing-library/user-event@14.4.3 @types/node@22.2.0 @types/babel__traverse@7.18.2
- name: Patch for Older TS
if: ${{ matrix.typescript == '4.2.3' || matrix.typescript == '4.1.5' || matrix.typescript == '4.0.5' || startsWith(matrix.typescript, '3.') }}
run: |
sed -i~ 's/import\.meta\.env/(import.meta.env as any)/' tests/*/*.tsx tests/*/*/*.tsx
sed -i~ '1s/^/\/\/\/ <reference types="react\/experimental" \/>\nimport React from "react";/' tests/*/*.tsx tests/*/*/*.tsx
sed -i~ 's/"jsx": "react-jsx",/"jsx": "react",/' tsconfig.json
sed -i~ 's/"noUncheckedIndexedAccess": true,//' tsconfig.json
sed -i~ 's/"paths": {/"baseUrl":".","paths": {/' tsconfig.json
sed -i~ 's/^import type /import /' tests/*/*.tsx tests/*/*/*.tsx
pnpm json -I -f package.json -e "this.resolutions={}; this.resolutions['@types/prettier']='2.4.2'; this.resolutions['@types/node']='18.11.18'; this.resolutions['@types/react']='18.2.56';"
pnpm add -D @types/prettier@2.4.2 @types/node@18.11.18 @types/yargs@17.0.13 @types/react@18.2.56
rm -r tests/react/vanilla-utils/atomWithObservable.*
- name: Install old TypeScript
- name: Install TypeScript ${{ matrix.typescript }}
run: pnpm add -D typescript@$TS_VER
env:
TS_VER: ${{ matrix.typescript }}
- name: Patch testing setup for Old TS
if: ${{ matrix.typescript == '4.6.4' || matrix.typescript == '4.5.5' || 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: |
pnpm add -D vitest@0.33.0 @vitest/coverage-v8@0.33.0 @vitest/ui@0.33.0
pnpm add -D @testing-library/jest-dom@5 @types/testing-library__jest-dom@5
pnpm add -D @types/jest@27.4.1
sed -i~ 's/"@testing-library\/jest-dom"/"@types\/testing-library__jest-dom"/' tsconfig.json
- name: Patch testing setup for older TS
if: ${{ matrix.typescript == '4.0.5' || startsWith(matrix.typescript, '3.') }}
run: |
pnpm add -D @testing-library/user-event@12.1.7 @testing-library/react@11.0.4 @types/react-dom@18.3.1
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
pnpm run test:types
- name: Test TypeScript ${{ matrix.typescript }}
run: pnpm run test:types
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ permissions:
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 20.19.0
- 22.12.0
- 24.0.0
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8
with:
standalone: true
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 'lts/*'
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- run: pnpm install
- run: pnpm run test:format
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ yarn-error.log*
# misc
.DS_Store
.idea
.README.md.bak

# examples
examples/**/*/package-lock.json
Expand Down
28 changes: 0 additions & 28 deletions babel.config.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion benchmarks/atom-creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { add, complete, cycle, save, suite } from 'benny'
import { atom } from '../src/vanilla/atom.ts'
import { atom } from '../src/vanilla/atom.js'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

Expand Down
6 changes: 3 additions & 3 deletions benchmarks/computed-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { add, complete, cycle, save, suite } from 'benny'
import type { Atom } from '../src/vanilla/atom.ts'
import { atom } from '../src/vanilla/atom.ts'
import { createStore } from '../src/vanilla/store.ts'
import type { Atom } from '../src/vanilla/atom.js'
import { atom } from '../src/vanilla/atom.js'
import { createStore } from '../src/vanilla/store.js'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

Expand Down
6 changes: 3 additions & 3 deletions benchmarks/derived-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { add, complete, cycle, save, suite } from 'benny'
import type { Atom } from '../src/vanilla/atom.ts'
import { atom } from '../src/vanilla/atom.ts'
import { createStore } from '../src/vanilla/store.ts'
import type { Atom } from '../src/vanilla/atom.js'
import { atom } from '../src/vanilla/atom.js'
import { createStore } from '../src/vanilla/store.js'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

Expand Down
6 changes: 3 additions & 3 deletions benchmarks/diamond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { add, complete, cycle, save, suite } from 'benny'
import type { Atom } from '../src/vanilla/atom.ts'
import { atom } from '../src/vanilla/atom.ts'
import { createStore } from '../src/vanilla/store.ts'
import type { Atom } from '../src/vanilla/atom.js'
import { atom } from '../src/vanilla/atom.js'
import { createStore } from '../src/vanilla/store.js'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/read-write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { add, complete, cycle, save, suite } from 'benny'
import { atom } from '../src/vanilla/atom.ts'
import { createStore } from '../src/vanilla/store.ts'
import { atom } from '../src/vanilla/atom.js'
import { createStore } from '../src/vanilla/store.js'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

Expand Down
6 changes: 3 additions & 3 deletions benchmarks/select-atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { add, complete, cycle, save, suite } from 'benny'
import { atom } from '../src/vanilla/atom.ts'
import { createStore } from '../src/vanilla/store.ts'
import { selectAtom } from '../src/vanilla/utils/selectAtom.ts'
import { atom } from '../src/vanilla/atom.js'
import { createStore } from '../src/vanilla/store.js'
import { selectAtom } from '../src/vanilla/utils/selectAtom.js'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { add, complete, cycle, save, suite } from 'benny'
import { atom } from '../src/vanilla/atom.ts'
import { createStore } from '../src/vanilla/store.ts'
import { atom } from '../src/vanilla/atom.js'
import { createStore } from '../src/vanilla/store.js'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/wide-fan-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { add, complete, cycle, save, suite } from 'benny'
import { atom } from '../src/vanilla/atom.ts'
import { createStore } from '../src/vanilla/store.ts'
import { atom } from '../src/vanilla/atom.js'
import { createStore } from '../src/vanilla/store.js'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

Expand Down
4 changes: 1 addition & 3 deletions docs/core/atom.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ See the below example for `fetch` usage.

#### `options.setSelf`

It's a special function to invoke the write function of the self atom.

⚠️ It's provided primarily for internal usage and third-party library authors. Read the source code carefully to understand the behavior. Check release notes for any breaking/non-breaking changes.
⚠️ This internal feature was only available in Jotai v2 and has been removed in v3.

## Stackblitz

Expand Down
Loading
Loading