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

[v5] breaking: drop default exports #2238

Merged
merged 5 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 5 additions & 8 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,9 @@ function createCommonJSConfig(input, output, options) {
esModule: false,
outro: options.addModuleExport
? [
`module.exports = ${options.addModuleExport.default};`,
charkour marked this conversation as resolved.
Show resolved Hide resolved
...Object.entries(options.addModuleExport)
.filter(([key]) => key !== 'default')
.map(([key, value]) => `module.exports.${key} = ${value};`),
`exports.default = module.exports;`,
...Object.entries(options.addModuleExport).map(
([key, value]) => `module.exports.${key} = ${value};`,
),
].join('\n')
: '',
},
Expand Down Expand Up @@ -179,13 +177,12 @@ module.exports = function (args) {
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' },
vanilla: { createStore: 'createStore' },
shallow: { shallow: 'shallow$1' },
}[c],
}),
createESMConfig(`src/${c}.ts`, `dist/esm/${c}.js`),
Expand Down
4 changes: 1 addition & 3 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>>() {
charkour marked this conversation as resolved.
Show resolved Hide resolved
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.",
Expand Down Expand Up @@ -98,5 +98,3 @@ function createContext<S extends StoreApi<unknown>>() {
useStoreApi,
}
}

export default createContext
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './vanilla.ts'
export * from './react.ts'
export { default } from './react.ts'
12 changes: 0 additions & 12 deletions src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 0 additions & 12 deletions src/shallow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,4 @@ import { shallow } from './vanilla/shallow.ts'
// export { shallow } from './vanilla/shallow.ts'
// export { useShallow } from './react/shallow.ts'
charkour marked this conversation as resolved.
Show resolved Hide resolved

/**
* @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 }
12 changes: 0 additions & 12 deletions src/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

// ---------------------------------------------------------

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/context.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading