mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
[v5] breaking: drop default exports (#2238)
* fix: drop default exports for v5 * chore: remove default from cjs build * refactor: export shallow in v5 * fix: remove `addModuleExport` option for cjs.
This commit is contained in:
parent
105bc570d2
commit
8030aeeb91
@ -78,22 +78,13 @@ function createESMConfig(input, output) {
|
||||
}
|
||||
}
|
||||
|
||||
function createCommonJSConfig(input, output, options) {
|
||||
function createCommonJSConfig(input, output) {
|
||||
return {
|
||||
input,
|
||||
output: {
|
||||
file: `${output}.js`,
|
||||
format: 'cjs',
|
||||
esModule: false,
|
||||
outro: options.addModuleExport
|
||||
? [
|
||||
`module.exports = ${options.addModuleExport.default};`,
|
||||
...Object.entries(options.addModuleExport)
|
||||
.filter(([key]) => key !== 'default')
|
||||
.map(([key, value]) => `module.exports.${key} = ${value};`),
|
||||
`exports.default = module.exports;`,
|
||||
].join('\n')
|
||||
: '',
|
||||
},
|
||||
external,
|
||||
plugins: [
|
||||
@ -176,18 +167,7 @@ module.exports = function (args) {
|
||||
}
|
||||
return [
|
||||
...(c === 'index' ? [createDeclarationConfig(`src/${c}.ts`, 'dist')] : []),
|
||||
createCommonJSConfig(`src/${c}.ts`, `dist/${c}`, {
|
||||
addModuleExport: {
|
||||
index: {
|
||||
default: 'react',
|
||||
create: 'create',
|
||||
useStore: 'useStore',
|
||||
createStore: 'vanilla.createStore',
|
||||
},
|
||||
vanilla: { default: 'vanilla', createStore: 'createStore' },
|
||||
shallow: { default: 'shallow', shallow: 'shallow$1' },
|
||||
}[c],
|
||||
}),
|
||||
createCommonJSConfig(`src/${c}.ts`, `dist/${c}`),
|
||||
createESMConfig(`src/${c}.ts`, `dist/esm/${c}.js`),
|
||||
createESMConfig(`src/${c}.ts`, `dist/esm/${c}.mjs`),
|
||||
createUMDConfig(`src/${c}.ts`, `dist/umd/${c}`, 'development'),
|
||||
|
||||
@ -37,7 +37,7 @@ type WithoutCallSignature<T> = { [K in keyof T]: T[K] }
|
||||
/**
|
||||
* @deprecated Use `createStore` and `useStore` for context usage
|
||||
*/
|
||||
function createContext<S extends StoreApi<unknown>>() {
|
||||
export function createContext<S extends StoreApi<unknown>>() {
|
||||
if (import.meta.env?.MODE !== 'production') {
|
||||
console.warn(
|
||||
"[DEPRECATED] `context` will be removed in a future version. Instead use `import { createStore, useStore } from 'zustand'`. See: https://github.com/pmndrs/zustand/discussions/1180.",
|
||||
@ -98,5 +98,3 @@ function createContext<S extends StoreApi<unknown>>() {
|
||||
useStoreApi,
|
||||
}
|
||||
}
|
||||
|
||||
export default createContext
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
export * from './vanilla.ts'
|
||||
export * from './react.ts'
|
||||
export { default } from './react.ts'
|
||||
|
||||
12
src/react.ts
12
src/react.ts
@ -120,15 +120,3 @@ const createImpl = <T>(createState: StateCreator<T, [], []>) => {
|
||||
|
||||
export const create = (<T>(createState: StateCreator<T, [], []> | undefined) =>
|
||||
createState ? createImpl(createState) : createImpl) as Create
|
||||
|
||||
/**
|
||||
* @deprecated Use `import { create } from 'zustand'`
|
||||
*/
|
||||
export default ((createState: any) => {
|
||||
if (import.meta.env?.MODE !== 'production') {
|
||||
console.warn(
|
||||
"[DEPRECATED] Default export is deprecated. Instead use `import { create } from 'zustand'`.",
|
||||
)
|
||||
}
|
||||
return create(createState)
|
||||
}) as Create
|
||||
|
||||
@ -1,19 +1,2 @@
|
||||
import { shallow } from './vanilla/shallow.ts'
|
||||
|
||||
// We will export this in v5 and remove default export
|
||||
// export { shallow } from './vanilla/shallow.ts'
|
||||
// export { useShallow } from './react/shallow.ts'
|
||||
|
||||
/**
|
||||
* @deprecated Use `import { shallow } from 'zustand/shallow'`
|
||||
*/
|
||||
export default ((objA, objB) => {
|
||||
if (import.meta.env?.MODE !== 'production') {
|
||||
console.warn(
|
||||
"[DEPRECATED] Default export is deprecated. Instead use `import { shallow } from 'zustand/shallow'`.",
|
||||
)
|
||||
}
|
||||
return shallow(objA, objB)
|
||||
}) as typeof shallow
|
||||
|
||||
export { shallow }
|
||||
export { shallow } from './vanilla/shallow.ts'
|
||||
export { useShallow } from './react/shallow.ts'
|
||||
|
||||
@ -105,18 +105,6 @@ const createStoreImpl: CreateStoreImpl = (createState) => {
|
||||
export const createStore = ((createState) =>
|
||||
createState ? createStoreImpl(createState) : createStoreImpl) as CreateStore
|
||||
|
||||
/**
|
||||
* @deprecated Use `import { createStore } from 'zustand/vanilla'`
|
||||
*/
|
||||
export default ((createState) => {
|
||||
if (import.meta.env?.MODE !== 'production') {
|
||||
console.warn(
|
||||
"[DEPRECATED] Default export is deprecated. Instead use import { createStore } from 'zustand/vanilla'.",
|
||||
)
|
||||
}
|
||||
return createStore(createState)
|
||||
}) as CreateStore
|
||||
|
||||
// ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@ -10,7 +10,7 @@ import { render } from '@testing-library/react'
|
||||
import { afterEach, it, vi } from 'vitest'
|
||||
import { create } from 'zustand'
|
||||
import type { StoreApi } from 'zustand'
|
||||
import createContext from 'zustand/context'
|
||||
import { createContext } from 'zustand/context'
|
||||
import { subscribeWithSelector } from 'zustand/middleware'
|
||||
|
||||
const consoleError = console.error
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user