Merge branch 'main' into v5

This commit is contained in:
daishi 2024-04-06 20:53:23 +09:00
commit 4c4e4d1ec4
10 changed files with 391 additions and 328 deletions

View File

@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
build: [cjs, esm]
env: [development] # [development, production]
env: [development, production]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
@ -36,11 +36,12 @@ jobs:
- name: Patch for CJS
if: ${{ matrix.build == 'cjs' }}
run: |
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\1.js/" package.json
sed -i~ "s/resolve('\.\/src\(.*\)\.ts')/resolve('\.\/dist\1.js')/" vitest.config.ts
sed -i~ "s/module.exports.createStore = vanilla.createStore;//" dist/index.js
- name: Patch for ESM
if: ${{ matrix.build == 'esm' }}
run: |
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/esm\1.js/" package.json
sed -i~ "s/resolve('\.\/src\(.*\)\.ts')/resolve('\.\/dist\/esm\1.mjs')/" vitest.config.ts
sed -i~ "1s/^/import.meta.env=import.meta.env||{};import.meta.env.MODE='${NODE_ENV}';/" tests/*.tsx
env:
NODE_ENV: ${{ matrix.env }}

View File

@ -38,7 +38,7 @@ jobs:
sed -i~ 's/"zustand": \["\.\/src\/index\.ts"\],/"zustand": [".\/dist\/index.d.ts"],/' tsconfig.json
sed -i~ 's/"zustand\/\*": \["\.\/src\/\*\.ts"\]/"zustand\/*": [".\/dist\/*.d.ts"]/' tsconfig.json
sed -i~ 's/"include": .*/"include": ["src\/types.d.ts", "dist\/**\/*", "tests\/**\/*"],/' tsconfig.json
- name: Install old TypeScript
run: yarn add -D typescript@${{ matrix.typescript }}
- name: Test ${{ matrix.typescript }}
run: |
yarn add -D typescript@${{ matrix.typescript }}
yarn tsc --noEmit
run: yarn tsc --noEmit

View File

@ -131,3 +131,4 @@ For a working example of this, see the [Code Sandbox](https://codesandbox.io/s/z
- [auto-zustand-selectors-hook](https://github.com/Albert-Gao/auto-zustand-selectors-hook)
- [react-hooks-global-state](https://github.com/dai-shi/react-hooks-global-state)
- [zustood](https://github.com/udecode/zustood)
- [@davstack/store](https://www.npmjs.com/package/@davstack/store)

View File

@ -15,6 +15,8 @@ This can be done using third-party libraries created by the community.
> for someone looking to extend Zustand's feature set.
- [@colorfy-software/zfy](https://colorfy-software.gitbook.io/zfy/) — 🧸 Useful helpers for state management in React with Zustand.
- [@davstack/store](https://www.npmjs.com/package/@davstack/store) — A zustand store factory that auto generates selectors with get/set/use methods, supports inferred types, and makes global / local state management easy.
- [@dhmk/zustand-lens](https://github.com/dhmk083/dhmk-zustand-lens) — Lens support for Zustand.
- [@liveblocks/zustand](https://github.com/liveblocks/liveblocks/tree/main/packages/liveblocks-zustand) — Liveblocks middleware to make your application multiplayer.
- [auto-zustand-selectors-hook](https://github.com/Albert-Gao/auto-zustand-selectors-hook) — Automatic generation of Zustand hooks with Typescript support.

View File

@ -120,8 +120,8 @@
"@types/use-sync-external-store": "^0.0.6",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"@vitest/coverage-v8": "0.33.0",
"@vitest/ui": "0.33.0",
"@vitest/coverage-v8": "^1.4.0",
"@vitest/ui": "^1.4.0",
"concurrently": "^8.2.2",
"esbuild": "^0.20.1",
"eslint": "^8.57.0",
@ -144,7 +144,7 @@
"shx": "^0.3.4",
"typescript": "^5.3.3",
"use-sync-external-store": "^1.2.0",
"vitest": "0.33.0"
"vitest": "^1.4.0"
},
"peerDependencies": {
"@types/react": ">=18.0",

View File

@ -1,4 +1,4 @@
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { devtools, redux } from 'zustand/middleware'
import { StoreApi, createStore } from 'zustand/vanilla'
@ -16,12 +16,12 @@ type TupleOfEqualLength<Arr extends unknown[], T> = number extends Arr['length']
type Connection = {
subscribers: ((message: unknown) => void)[]
api: {
subscribe: Mock<[f: (m: unknown) => void], () => void>
unsubscribe: Mock<any>
send: Mock<any>
init: Mock<any>
error: Mock<any>
dispatch?: Mock<any>
subscribe: any
unsubscribe: any
send: any
init: any
error: any
dispatch?: any
}
}
const namedConnections = new Map<string | undefined, Connection>()

View File

@ -34,8 +34,7 @@ describe('types', () => {
})
describe('useShallow', () => {
const testUseShallowSimpleCallback =
vi.fn<[{ selectorOutput: string[]; useShallowOutput: string[] }]>()
const testUseShallowSimpleCallback = vi.fn()
const TestUseShallowSimple = ({
selector,
state,

View File

@ -35,10 +35,7 @@ describe.skipIf(!React.version.startsWith('18'))(
'ssr behavior with react 18',
() => {
it('should handle different states between server and client correctly', async () => {
const { hydrateRoot } =
await vi.importActual<typeof import('react-dom/client')>(
'react-dom/client',
)
const { hydrateRoot }: any = await vi.importActual('react-dom/client')
const markup = renderToString(
<React.Suspense fallback={<div>Loading...</div>}>
@ -70,10 +67,7 @@ describe.skipIf(!React.version.startsWith('18'))(
bears: 0,
}))
const { hydrateRoot } =
await vi.importActual<typeof import('react-dom/client')>(
'react-dom/client',
)
const { hydrateRoot }: any = await vi.importActual('react-dom/client')
const Component = () => {
const bears = useStore((state) => state.bears)

View File

@ -1,11 +1,12 @@
import { resolve } from 'path'
// eslint-disable-next-line import/extensions
import { defineConfig } from 'vitest/config'
export default defineConfig({
resolve: {
alias: [
{ find: /^zustand$/, replacement: './src/index.ts' },
{ find: /^zustand(.*)$/, replacement: './src/$1.ts' },
{ find: /^zustand$/, replacement: resolve('./src/index.ts') },
{ find: /^zustand(.*)$/, replacement: resolve('./src/$1.ts') },
],
},
test: {

665
yarn.lock

File diff suppressed because it is too large Load Diff