mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
[v5] breaking: require TypeScript 4.5 and update tests (#2257)
* breaking(types): TS requirement * wip: latest only * wip: latest only 2 * drop ts <4.4 * wip: do not skip lib checkes * use latest node types * drop ts 4.4
This commit is contained in:
parent
020f27b0a2
commit
4ffdb19936
9
.github/workflows/test-old-typescript.yml
vendored
9
.github/workflows/test-old-typescript.yml
vendored
@ -22,10 +22,6 @@ jobs:
|
||||
- 4.7.4
|
||||
- 4.6.4
|
||||
- 4.5.5
|
||||
- 4.4.4
|
||||
- 4.3.5
|
||||
- 4.2.3
|
||||
- 4.1.5
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
@ -37,16 +33,11 @@ jobs:
|
||||
- run: yarn build
|
||||
- name: Patch for Old TS
|
||||
run: |
|
||||
sed -i~ 's/\/\/ @ts-expect-error.*\[LATEST-TS-ONLY\]//' tests/*.tsx
|
||||
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/"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
|
||||
yarn json -I -f package.json -e "this.resolutions={}; this.resolutions['@types/node']='18.13.0';"
|
||||
yarn add -D @types/node@18.13.0
|
||||
- name: Test ${{ matrix.typescript }}
|
||||
run: |
|
||||
yarn add -D typescript@${{ matrix.typescript }}
|
||||
|
||||
26
package.json
26
package.json
@ -9,18 +9,23 @@
|
||||
"main": "./index.js",
|
||||
"types": "./index.d.ts",
|
||||
"typesVersions": {
|
||||
"<4.0": {
|
||||
">=4.5": {
|
||||
"esm/*": [
|
||||
"ts3.4/*"
|
||||
"esm/*"
|
||||
],
|
||||
"*": [
|
||||
"ts3.4/*"
|
||||
"*"
|
||||
]
|
||||
},
|
||||
"*": {
|
||||
"esm/*": [
|
||||
"ts_version_4.5_and_above_is_required.d.ts"
|
||||
],
|
||||
"*": [
|
||||
"ts_version_4.5_and_above_is_required.d.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"**"
|
||||
],
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
@ -136,6 +141,9 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"**"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"prebuild": "shx rm -rf dist",
|
||||
@ -148,7 +156,7 @@
|
||||
"build:vanilla:shallow": "rollup -c --config-vanilla_shallow",
|
||||
"build:react:shallow": "rollup -c --config-react_shallow",
|
||||
"build:traditional": "rollup -c --config-traditional",
|
||||
"postbuild": "yarn patch-d-ts && yarn copy && yarn patch-esm-ts",
|
||||
"postbuild": "yarn patch-d-ts && yarn copy && yarn patch-old-ts && yarn patch-esm-ts",
|
||||
"prettier": "prettier \"*.{js,json,md}\" \"{examples,src,tests,docs}/**/*.{js,jsx,ts,tsx,md,mdx}\" --write",
|
||||
"prettier:ci": "prettier '*.{js,json,md}' '{examples,src,tests,docs}/**/*.{js,jsx,ts,tsx,md,mdx}' --list-different",
|
||||
"eslint": "eslint --no-eslintrc --c .eslintrc.json --fix '*.{js,json,ts}' '{src,tests}/**/*.{ts,tsx}'",
|
||||
@ -157,7 +165,8 @@
|
||||
"test": "vitest --ui --coverage",
|
||||
"test:ci": "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.4 && 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;\"",
|
||||
"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} && 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-old-ts": "shx touch dist/ts_version_4.5_and_above_is_required.d.ts",
|
||||
"patch-esm-ts": "node -e \"require('shelljs').find('dist/esm/**/*.d.ts').forEach(f=>{var f2=f.replace(/\\.ts$/,'.mts');require('fs').copyFileSync(f,f2);require('shelljs').sed('-i',/ from '(\\.[^']+)';$/,' from \\'\\$1.mjs\\';',f2);require('shelljs').sed('-i',/^declare module '(\\.[^']+)'/,'declare module \\'\\$1.mjs\\'',f2)})\""
|
||||
},
|
||||
"engines": {
|
||||
@ -212,7 +221,6 @@
|
||||
"@vitest/coverage-v8": "^0.34.6",
|
||||
"@vitest/ui": "^0.34.6",
|
||||
"concurrently": "^8.2.2",
|
||||
"downlevel-dts": "^0.11.0",
|
||||
"esbuild": "^0.19.8",
|
||||
"eslint": "^8.54.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
|
||||
@ -112,9 +112,9 @@ it('should have correct (partial) types for setState', () => {
|
||||
|
||||
const store = create<Count>((set) => ({
|
||||
count: 0,
|
||||
// @ts-expect-error we shouldn't be able to set count to undefined [LATEST-TS-ONLY]
|
||||
// @ts-expect-error we shouldn't be able to set count to undefined
|
||||
a: () => set(() => ({ count: undefined })),
|
||||
// @ts-expect-error we shouldn't be able to set count to undefined [LATEST-TS-ONLY]
|
||||
// @ts-expect-error we shouldn't be able to set count to undefined
|
||||
b: () => set({ count: undefined }),
|
||||
c: () => set({ count: 1 }),
|
||||
}))
|
||||
@ -130,9 +130,9 @@ it('should have correct (partial) types for setState', () => {
|
||||
store.setState({})
|
||||
store.setState((previous) => previous)
|
||||
|
||||
// @ts-expect-error type undefined is not assignable to type number [LATEST-TS-ONLY]
|
||||
// @ts-expect-error type undefined is not assignable to type number
|
||||
store.setState({ count: undefined })
|
||||
// @ts-expect-error type undefined is not assignable to type number [LATEST-TS-ONLY]
|
||||
// @ts-expect-error type undefined is not assignable to type number
|
||||
store.setState((state) => ({ ...state, count: undefined }))
|
||||
})
|
||||
|
||||
|
||||
18
yarn.lock
18
yarn.lock
@ -2350,15 +2350,6 @@ dom-accessibility-api@^0.5.9:
|
||||
resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz#5a7429e6066eb3664d911e33fb0e45de8eb08453"
|
||||
integrity sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==
|
||||
|
||||
downlevel-dts@^0.11.0:
|
||||
version "0.11.0"
|
||||
resolved "https://registry.yarnpkg.com/downlevel-dts/-/downlevel-dts-0.11.0.tgz#514a2d723009c5845730c1db6c994484c596ed9c"
|
||||
integrity sha512-vo835pntK7kzYStk7xUHDifiYJvXxVhUapt85uk2AI94gUUAQX9HNRtrcMHNSc3YHJUEHGbYIGsM99uIbgAtxw==
|
||||
dependencies:
|
||||
semver "^7.3.2"
|
||||
shelljs "^0.8.3"
|
||||
typescript next
|
||||
|
||||
electron-to-chromium@^1.4.601:
|
||||
version "1.4.614"
|
||||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.614.tgz#2fe789d61fa09cb875569f37c309d0c2701f91c0"
|
||||
@ -4294,7 +4285,7 @@ semver@^6.3.1:
|
||||
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
|
||||
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==
|
||||
|
||||
semver@^7.3.2, semver@^7.5.3, semver@^7.5.4:
|
||||
semver@^7.5.3, semver@^7.5.4:
|
||||
version "7.5.4"
|
||||
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
|
||||
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
|
||||
@ -4344,7 +4335,7 @@ shell-quote@^1.8.1:
|
||||
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.8.1.tgz#6dbf4db75515ad5bac63b4f1894c3a154c766680"
|
||||
integrity sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==
|
||||
|
||||
shelljs@^0.8.3, shelljs@^0.8.5:
|
||||
shelljs@^0.8.5:
|
||||
version "0.8.5"
|
||||
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.5.tgz#de055408d8361bed66c669d2f000538ced8ee20c"
|
||||
integrity sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==
|
||||
@ -4732,11 +4723,6 @@ typescript@^5.3.2:
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
|
||||
integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==
|
||||
|
||||
typescript@next:
|
||||
version "5.4.0-dev.20231217"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.0-dev.20231217.tgz#7b774444c14ae6ede3149753ca9f9301f91200e6"
|
||||
integrity sha512-LfTSjpGkhz5vojqrbHPD0UyPplTewag9lJpWP0U4hfeOXi62DN1CBp/us35zPVmD49iznxiIgTW9rNMbEiJYtw==
|
||||
|
||||
ufo@^1.3.0:
|
||||
version "1.3.2"
|
||||
resolved "https://registry.yarnpkg.com/ufo/-/ufo-1.3.2.tgz#c7d719d0628a1c80c006d2240e0d169f6e3c0496"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user