Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add extension in imports #1678

Merged
merged 58 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8734de4
chore: add extentsion in imports
dai-shi Mar 6, 2023
10ae7f0
fix github workflow
dai-shi Mar 6, 2023
4402f79
revert for zustand/context
dai-shi Mar 6, 2023
bda1a39
do not patch :)
dai-shi Mar 6, 2023
a74d5e8
fix workflow file
dai-shi Mar 6, 2023
0577fbf
update ts 5
dai-shi Mar 17, 2023
c3f200c
patch tsconfig
dai-shi Mar 17, 2023
0ea174a
use old typescript for react 16
dai-shi Mar 17, 2023
d03e526
downlevel-dts to 3.8
dai-shi Mar 17, 2023
7faa140
Revert "downlevel-dts to 3.8"
dai-shi Mar 17, 2023
40daaac
patch workflow file
dai-shi Mar 17, 2023
8bda65c
patch for react 16
dai-shi Mar 17, 2023
e3725ec
remove ts3.4 in workflow
dai-shi Mar 17, 2023
26b78c1
skipLibChecks
dai-shi Mar 17, 2023
e2c88f1
revert changes in test-multiple-versions.yml
dai-shi Mar 17, 2023
3f8304c
fix sed
dai-shi Mar 17, 2023
fca34d7
wip: add allowJs
dai-shi Mar 17, 2023
9f7bde5
Revert "wip: add allowJs"
dai-shi Mar 17, 2023
27703b8
use ts 495
dai-shi Mar 17, 2023
07a91d8
useESM false
dai-shi Mar 17, 2023
411d74f
Revert "useESM false"
dai-shi Mar 17, 2023
50d716d
no coverage
dai-shi Mar 17, 2023
016e872
no coverage 2
dai-shi Mar 17, 2023
f7fbae5
no coverage 3
dai-shi Mar 17, 2023
874e70f
wip
dai-shi Mar 17, 2023
c4ee682
disable transform
dai-shi Mar 17, 2023
54cc5af
revert a change
dai-shi Mar 17, 2023
72498f2
revert changes
dai-shi Mar 17, 2023
a0806da
Merge branch 'main' into chore/use-extension-in-imports
dai-shi Mar 31, 2023
a16caa4
test: try ignoring tests with dynamic imports
arjunvegda Apr 1, 2023
b82387b
test: skip tests that require/tests modules in isolation
arjunvegda Apr 2, 2023
277a401
test: remove dynamic import
arjunvegda Apr 2, 2023
46cbf74
run skipped tests on CI
dai-shi Apr 3, 2023
100c81b
test: add new devtools imports to ci-only tests
arjunvegda Apr 3, 2023
a854dab
revert CI-ONLY-* hack
dai-shi Apr 3, 2023
265720f
wip: workaround for react 16
dai-shi Apr 3, 2023
246051a
wip: workaround for react 16
dai-shi Apr 3, 2023
6d65d38
wip: workaround for react 16
dai-shi Apr 3, 2023
243fc13
wip: workaround for react 16
dai-shi Apr 3, 2023
abd4825
wip: workaround for react 16
dai-shi Apr 4, 2023
837d9ea
wip: workaround for react 16
dai-shi Apr 4, 2023
c1edd26
wip: workaround for react 16
dai-shi Apr 4, 2023
2be42ff
wip: workaround for react 16
dai-shi Apr 4, 2023
fb4b31e
wip: workaround for react 16
dai-shi Apr 4, 2023
6fd4b03
wip: workaround for react 16
dai-shi Apr 4, 2023
c73cf3a
wip: workaround for react 16
dai-shi Apr 4, 2023
dd727f4
CI-MATRIX- for devtools CI hacks
dai-shi Apr 4, 2023
0b1b91e
test: add env variable to test multiple builds workflow
arjunvegda Apr 4, 2023
6797efb
hack await import
dai-shi Apr 4, 2023
279426a
hack await import for another one
dai-shi Apr 4, 2023
d4e00a1
wip: experimenting workflow file
dai-shi Apr 4, 2023
c416f91
wip: experimenting workflow file
dai-shi Apr 4, 2023
7e9b8df
wip: experimenting workflow file
dai-shi Apr 4, 2023
3052f90
use different env name
dai-shi Apr 4, 2023
f6e1eab
wip: experimenting workflow file
dai-shi Apr 4, 2023
78bb2c9
do not use two envs
dai-shi Apr 4, 2023
d4d6813
revert to NODE_ENV
dai-shi Apr 4, 2023
006f33e
Merge branch 'main' into chore/use-extension-in-imports
dai-shi May 1, 2023
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
13 changes: 5 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"prefer-const": "error",
"curly": ["warn", "multi-line", "consistent"],
"no-console": "off",
"import/extensions": ["error", "always"],
"import/no-unresolved": ["error", { "commonjs": true, "amd": true }],
"import/export": "error",
"@typescript-eslint/no-duplicate-imports": ["error"],
Expand Down Expand Up @@ -93,12 +94,8 @@
"@typescript-eslint/parser": [".js", ".jsx", ".ts", ".tsx"]
},
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx", ".json"],
"paths": ["src"]
},
"alias": {
"extensions": [".js", ".jsx", ".ts", ".tsx", ".json"],
"extensions": [".js", ".jsx", ".ts", ".tsx"],
"map": [
["^zustand$", "./src/index.ts"],
["zustand", "./src"]
Expand All @@ -108,9 +105,9 @@
},
"overrides": [
{
"files": ["src"],
"parserOptions": {
"project": "./tsconfig.json"
"files": ["tests/**/*.ts", "tests/**/*.tsx"],
"rules": {
"import/extensions": ["error", "never"]
}
},
{
Expand Down
34 changes: 30 additions & 4 deletions .github/workflows/test-multiple-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ jobs:
matrix:
build: [cjs, umd] # [cjs, esm, umd, system]
env: [development, production]
devtools-skip:
- CI-MATRIX-NOSKIP
include:
- devtools-skip: CI-MATRIX-[2345]
build: umd
- devtools-skip: CI-MATRIX-[1345]
build: umd
- devtools-skip: CI-MATRIX-[1245]
build: umd
- devtools-skip: CI-MATRIX-[1235]
build: umd
- devtools-skip: CI-MATRIX-[1234]
build: umd
exclude:
- devtools-skip: CI-MATRIX-NOSKIP
build: umd
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand Down Expand Up @@ -48,13 +64,23 @@ jobs:
sed -i~ "1s/^/import.meta.env=import.meta.env||{};import.meta.env.MODE='${NODE_ENV}';/" tests/*.tsx
env:
NODE_ENV: ${{ matrix.env }}
- name: Patch for UMD/SystemJS
if: ${{ matrix.build == 'umd' || matrix.build == 'system' }}
- name: Patch for UMD
if: ${{ matrix.build == 'umd' }}
run: |
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/${BUILD}\1.${NODE_ENV}.js/" package.json
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/umd\1.${NODE_ENV}.js/" package.json
sed -i~ 's/"test:ci":.*,$/"test:ci": "jest",/' package.json
sed -i~ 's/= await import(/= require(/' tests/devtools.test.tsx
env:
NODE_ENV: ${{ matrix.env }}
run: |
sed -i~ "s/it('\[${DEVTOOLS_SKIP}\]/it.skip('/" tests/devtools.test.tsx
env:
DEVTOOLS_SKIP: ${{ matrix.devtools-skip }}
Comment on lines +73 to +78
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooooops, it wasn't the right fix...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following up #1786

- name: Patch for SystemJS
if: ${{ matrix.build == 'system' }}
run: |
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/system\1.${NODE_ENV}.js/" package.json
env:
BUILD: ${{ matrix.build }}
NODE_ENV: ${{ matrix.env }}
- name: Test ${{ matrix.build }} ${{ matrix.env }}
run: |
Expand Down
22 changes: 21 additions & 1 deletion .github/workflows/test-multiple-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ jobs:
- 18.2.0
- 18.3.0-next-1308e49a6-20230330
- 0.0.0-experimental-1308e49a6-20230330
devtools-skip:
- CI-MATRIX-NOSKIP
include:
- devtools-skip: CI-MATRIX-[2345]
react: 16.8.0
- devtools-skip: CI-MATRIX-[1345]
react: 16.8.0
- devtools-skip: CI-MATRIX-[1245]
react: 16.8.0
- devtools-skip: CI-MATRIX-[1235]
react: 16.8.0
- devtools-skip: CI-MATRIX-[1234]
react: 16.8.0
exclude:
- devtools-skip: CI-MATRIX-NOSKIP
react: 16.8.0
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand All @@ -53,7 +69,11 @@ jobs:
sed -i~ 's/"jsx": "react-jsx"/"jsx": "react"/' tsconfig.json
sed -i~ 's/import\.meta\.env[?]\.MODE/"DEVELOPMENT".toLowerCase()/' src/*.ts src/*/*.ts
sed -i~ 's/"test:ci":.*,$/"test:ci": "jest",/' package.json
- name: Test ${{ matrix.react }}
sed -i~ 's/= await import(/= require(/' tests/devtools.test.tsx
sed -i~ "s/it('\[${DEVTOOLS_SKIP}\]/it.skip('/" tests/devtools.test.tsx
env:
DEVTOOLS_SKIP: ${{ matrix.devtools-skip }}
- name: Test ${{ matrix.react }} ${{ matrix.devtools-skip }}
run: |
yarn add -D react@${{ matrix.react }} react-dom@${{ matrix.react }}
yarn test:ci
3 changes: 3 additions & 0 deletions .github/workflows/test-old-typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
fail-fast: false
matrix:
typescript:
- 4.9.5
- 4.8.4
- 4.7.4
- 4.6.4
Expand All @@ -35,6 +36,8 @@ jobs:
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": "nodenext",/"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
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"build:middleware:immer": "rollup -c --config-middleware_immer",
"build:shallow": "rollup -c --config-shallow",
"build:context": "rollup -c --config-context",
"postbuild": "yarn copy && yarn patch-esm-ts",
"postbuild": "yarn patch-d-ts && yarn copy && 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}' '{src,tests}/**/*.{ts,tsx}'",
Expand All @@ -95,6 +95,7 @@
"test:ci": "yarn node --experimental-vm-modules $(yarn bin jest)",
"test:dev": "yarn node --experimental-vm-modules $(yarn bin jest) --watch --no-coverage",
"test:coverage:watch": "yarn node --experimental-vm-modules $(yarn bin jest) --watch",
"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; this.jest=undefined;\"",
"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)})\""
},
Expand Down
29 changes: 8 additions & 21 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ const replace = require('@rollup/plugin-replace')
const terser = require('@rollup/plugin-terser')
const typescript = require('@rollup/plugin-typescript')
const { default: esbuild } = require('rollup-plugin-esbuild')
const createBabelConfig = require('./babel.config')
const createBabelConfig = require('./babel.config.js')

const extensions = ['.js', '.ts', '.tsx']
const { root } = path.parse(process.cwd())
const entries = [{ find: /.*\/vanilla\.ts$/, replacement: 'zustand/vanilla' }]

function external(id) {
return !id.startsWith('.') && !id.startsWith(root)
Expand Down Expand Up @@ -55,11 +56,7 @@ function createESMConfig(input, output) {
output: { file: output, format: 'esm' },
external,
plugins: [
alias({
entries: {
'./vanilla': 'zustand/vanilla',
},
}),
alias({ entries }),
resolve({ extensions }),
replace({
...(output.endsWith('.js')
Expand Down Expand Up @@ -100,11 +97,7 @@ function createCommonJSConfig(input, output, options) {
},
external,
plugins: [
alias({
entries: {
'./vanilla': 'zustand/vanilla',
},
}),
alias({ entries }),
resolve({ extensions }),
replace({
'import.meta.env?.MODE': 'process.env.NODE_ENV',
Expand Down Expand Up @@ -140,11 +133,7 @@ function createUMDConfig(input, output, env) {
},
external,
plugins: [
alias({
entries: {
'./vanilla': 'zustand/vanilla',
},
}),
alias({ entries }),
resolve({ extensions }),
replace({
'import.meta.env?.MODE': JSON.stringify(env),
Expand All @@ -166,11 +155,7 @@ function createSystemConfig(input, output, env) {
},
external,
plugins: [
alias({
entries: {
'./vanilla': 'zustand/vanilla',
},
}),
alias({ entries }),
resolve({ extensions }),
replace({
'import.meta.env?.MODE': JSON.stringify(env),
Expand Down Expand Up @@ -211,3 +196,5 @@ module.exports = function (args) {
createSystemConfig(`src/${c}.ts`, `dist/system/${c}`, 'production'),
]
}

module.exports.entries = []
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './vanilla'
export * from './react'
export { default } from './react'
export * from './vanilla.ts'
export * from './react.ts'
export { default } from './react.ts'
10 changes: 5 additions & 5 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './middleware/redux'
export * from './middleware/devtools'
export * from './middleware/subscribeWithSelector'
export * from './middleware/combine'
export * from './middleware/persist'
export * from './middleware/redux.ts'
export * from './middleware/devtools.ts'
export * from './middleware/subscribeWithSelector.ts'
export * from './middleware/combine.ts'
export * from './middleware/persist.ts'
2 changes: 1 addition & 1 deletion src/middleware/combine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StateCreator, StoreMutatorIdentifier } from '../vanilla'
import type { StateCreator, StoreMutatorIdentifier } from '../vanilla.ts'

type Write<T, U> = Omit<T, keyof U> & U

Expand Down
6 changes: 5 additions & 1 deletion src/middleware/devtools.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type {} from '@redux-devtools/extension'
import type { StateCreator, StoreApi, StoreMutatorIdentifier } from '../vanilla'
import type {
StateCreator,
StoreApi,
StoreMutatorIdentifier,
} from '../vanilla.ts'

// Copy types to avoid import type { Config } from '@redux-devtools/extension'
// https://github.com/pmndrs/zustand/issues/1205
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/immer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { produce } from 'immer'
import type { Draft } from 'immer'
import type { StateCreator, StoreMutatorIdentifier } from '../vanilla'
import type { StateCreator, StoreMutatorIdentifier } from '../vanilla.ts'

type Immer = <
T,
Expand Down
6 changes: 5 additions & 1 deletion src/middleware/persist.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { StateCreator, StoreApi, StoreMutatorIdentifier } from '../vanilla'
import type {
StateCreator,
StoreApi,
StoreMutatorIdentifier,
} from '../vanilla.ts'

export interface StateStorage {
getItem: (name: string) => string | null | Promise<string | null>
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/redux.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { StateCreator, StoreMutatorIdentifier } from '../vanilla'
import type { NamedSet } from './devtools'
import type { StateCreator, StoreMutatorIdentifier } from '../vanilla.ts'
import type { NamedSet } from './devtools.ts'

type Write<T, U> = Omit<T, keyof U> & U

Expand Down
2 changes: 1 addition & 1 deletion src/middleware/subscribeWithSelector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StateCreator, StoreMutatorIdentifier } from '../vanilla'
import type { StateCreator, StoreMutatorIdentifier } from '../vanilla.ts'

type SubscribeWithSelector = <
T,
Expand Down
5 changes: 3 additions & 2 deletions src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { useDebugValue } from 'react'
// This doesn't work in ESM, because use-sync-external-store only exposes CJS.
// See: https://github.com/pmndrs/valtio/issues/452
// The following is a workaround until ESM is supported.
// eslint-disable-next-line import/extensions
import useSyncExternalStoreExports from 'use-sync-external-store/shim/with-selector'
import { createStore } from './vanilla'
import { createStore } from './vanilla.ts'
import type {
Mutate,
StateCreator,
StoreApi,
StoreMutatorIdentifier,
} from './vanilla'
} from './vanilla.ts'

const { useSyncExternalStoreWithSelector } = useSyncExternalStoreExports

Expand Down
Loading