diff --git a/.github/workflows/trigger-release.yml b/.github/workflows/trigger-release.yml index 79bafa0ff..daa982ec8 100644 --- a/.github/workflows/trigger-release.yml +++ b/.github/workflows/trigger-release.yml @@ -24,7 +24,7 @@ on: name: Trigger Release env: - PNPM_VERSION: 7.26.1 + PNPM_VERSION: 8.4.0 SEMVER_TYPE: ${{ github.event.inputs.semverType }} RELEASE_TYPE: ${{ github.event.inputs.releaseType }} diff --git a/_internal/package.json b/_internal/package.json index ac9494000..76da6864a 100644 --- a/_internal/package.json +++ b/_internal/package.json @@ -2,11 +2,17 @@ "main": "./dist/index.js", "module": "./dist/index.esm.js", "types": "./dist/index.d.ts", - "exports": "./dist/index.mjs", + "exports": { + "types": "./dist/index.d.ts", + "react-server": "./dist/react-server.mjs", + "import": "./dist/index.mjs", + "module": "./dist/index.esm.js", + "require": "./dist/index.js" + }, "private": true, "scripts": { - "watch": "bunchee index.ts -w", - "build": "bunchee index.ts", + "watch": "bunchee -w", + "build": "bunchee", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, diff --git a/_internal/constants.ts b/_internal/src/constants.ts similarity index 100% rename from _internal/constants.ts rename to _internal/src/constants.ts diff --git a/_internal/index.ts b/_internal/src/index.ts similarity index 100% rename from _internal/index.ts rename to _internal/src/index.ts diff --git a/_internal/src/react-server.ts b/_internal/src/react-server.ts new file mode 100644 index 000000000..52fd9e5cc --- /dev/null +++ b/_internal/src/react-server.ts @@ -0,0 +1 @@ +export { serialize } from './utils/serialize' diff --git a/_internal/types.ts b/_internal/src/types.ts similarity index 100% rename from _internal/types.ts rename to _internal/src/types.ts diff --git a/_internal/utils/cache.ts b/_internal/src/utils/cache.ts similarity index 100% rename from _internal/utils/cache.ts rename to _internal/src/utils/cache.ts diff --git a/_internal/utils/config-context.ts b/_internal/src/utils/config-context.ts similarity index 100% rename from _internal/utils/config-context.ts rename to _internal/src/utils/config-context.ts diff --git a/_internal/utils/config.ts b/_internal/src/utils/config.ts similarity index 100% rename from _internal/utils/config.ts rename to _internal/src/utils/config.ts diff --git a/_internal/utils/devtools.ts b/_internal/src/utils/devtools.ts similarity index 100% rename from _internal/utils/devtools.ts rename to _internal/src/utils/devtools.ts diff --git a/_internal/utils/env.ts b/_internal/src/utils/env.ts similarity index 100% rename from _internal/utils/env.ts rename to _internal/src/utils/env.ts diff --git a/_internal/utils/global-state.ts b/_internal/src/utils/global-state.ts similarity index 100% rename from _internal/utils/global-state.ts rename to _internal/src/utils/global-state.ts diff --git a/_internal/utils/hash.ts b/_internal/src/utils/hash.ts similarity index 100% rename from _internal/utils/hash.ts rename to _internal/src/utils/hash.ts diff --git a/_internal/utils/helper.ts b/_internal/src/utils/helper.ts similarity index 100% rename from _internal/utils/helper.ts rename to _internal/src/utils/helper.ts diff --git a/_internal/utils/merge-config.ts b/_internal/src/utils/merge-config.ts similarity index 100% rename from _internal/utils/merge-config.ts rename to _internal/src/utils/merge-config.ts diff --git a/_internal/utils/middleware-preset.ts b/_internal/src/utils/middleware-preset.ts similarity index 100% rename from _internal/utils/middleware-preset.ts rename to _internal/src/utils/middleware-preset.ts diff --git a/_internal/utils/mutate.ts b/_internal/src/utils/mutate.ts similarity index 100% rename from _internal/utils/mutate.ts rename to _internal/src/utils/mutate.ts diff --git a/_internal/utils/normalize-args.ts b/_internal/src/utils/normalize-args.ts similarity index 100% rename from _internal/utils/normalize-args.ts rename to _internal/src/utils/normalize-args.ts diff --git a/_internal/utils/preload.ts b/_internal/src/utils/preload.ts similarity index 100% rename from _internal/utils/preload.ts rename to _internal/src/utils/preload.ts diff --git a/_internal/utils/resolve-args.ts b/_internal/src/utils/resolve-args.ts similarity index 100% rename from _internal/utils/resolve-args.ts rename to _internal/src/utils/resolve-args.ts diff --git a/_internal/utils/serialize.ts b/_internal/src/utils/serialize.ts similarity index 100% rename from _internal/utils/serialize.ts rename to _internal/src/utils/serialize.ts diff --git a/_internal/utils/state.ts b/_internal/src/utils/state.ts similarity index 100% rename from _internal/utils/state.ts rename to _internal/src/utils/state.ts diff --git a/_internal/utils/subscribe-key.ts b/_internal/src/utils/subscribe-key.ts similarity index 100% rename from _internal/utils/subscribe-key.ts rename to _internal/src/utils/subscribe-key.ts diff --git a/_internal/utils/timestamp.ts b/_internal/src/utils/timestamp.ts similarity index 100% rename from _internal/utils/timestamp.ts rename to _internal/src/utils/timestamp.ts diff --git a/_internal/utils/use-swr-config.ts b/_internal/src/utils/use-swr-config.ts similarity index 100% rename from _internal/utils/use-swr-config.ts rename to _internal/src/utils/use-swr-config.ts diff --git a/_internal/utils/web-preset.ts b/_internal/src/utils/web-preset.ts similarity index 100% rename from _internal/utils/web-preset.ts rename to _internal/src/utils/web-preset.ts diff --git a/_internal/utils/with-middleware.ts b/_internal/src/utils/with-middleware.ts similarity index 100% rename from _internal/utils/with-middleware.ts rename to _internal/src/utils/with-middleware.ts diff --git a/_internal/tsconfig.json b/_internal/tsconfig.json index 1996f8b51..51ed51cbe 100644 --- a/_internal/tsconfig.json +++ b/_internal/tsconfig.json @@ -3,5 +3,5 @@ "compilerOptions": { "outDir": "./dist" }, - "include": ["./*.ts"] + "include": ["./src"] } \ No newline at end of file diff --git a/core/package.json b/core/package.json index 09b191850..2c8982424 100644 --- a/core/package.json +++ b/core/package.json @@ -2,11 +2,17 @@ "main": "./dist/index.js", "module": "./dist/index.esm.js", "types": "./dist/index.d.ts", - "exports": "./dist/index.mjs", + "exports": { + "types": "./dist/index.d.ts", + "react-server": "./dist/react-server.mjs", + "import": "./dist/index.mjs", + "module": "./dist/index.esm.js", + "require": "./dist/index.js" + }, "private": true, "scripts": { - "watch": "bunchee index.ts -w", - "build": "bunchee index.ts", + "watch": "bunchee -w", + "build": "bunchee", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, diff --git a/core/index.ts b/core/src/index.ts similarity index 100% rename from core/index.ts rename to core/src/index.ts diff --git a/core/src/react-server.ts b/core/src/react-server.ts new file mode 100644 index 000000000..0945e0af8 --- /dev/null +++ b/core/src/react-server.ts @@ -0,0 +1 @@ +export { unstable_serialize } from './serialize' diff --git a/core/src/serialize.ts b/core/src/serialize.ts new file mode 100644 index 000000000..aabf8ec0e --- /dev/null +++ b/core/src/serialize.ts @@ -0,0 +1,4 @@ +import type { Key } from 'swr' +import { serialize } from 'swr/_internal' + +export const unstable_serialize = (key: Key) => serialize(key)[0] diff --git a/core/use-swr.ts b/core/src/use-swr.ts similarity index 99% rename from core/use-swr.ts rename to core/src/use-swr.ts index f04b27259..72054298f 100644 --- a/core/use-swr.ts +++ b/core/src/use-swr.ts @@ -744,7 +744,7 @@ export const SWRConfig = OBJECT.defineProperty(ConfigProvider, 'defaultValue', { defaultValue: FullConfiguration } -export const unstable_serialize = (key: Key) => serialize(key)[0] +export { unstable_serialize } from './serialize' /** * A hook to fetch data. diff --git a/immutable/package.json b/immutable/package.json index f1f40976b..6eddb8ebc 100644 --- a/immutable/package.json +++ b/immutable/package.json @@ -5,8 +5,8 @@ "exports": "./dist/index.mjs", "private": true, "scripts": { - "watch": "bunchee index.ts -w", - "build": "bunchee index.ts", + "watch": "bunchee -w", + "build": "bunchee", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, diff --git a/immutable/index.ts b/immutable/src/index.ts similarity index 100% rename from immutable/index.ts rename to immutable/src/index.ts diff --git a/immutable/tsconfig.json b/immutable/tsconfig.json index 1996f8b51..51ed51cbe 100644 --- a/immutable/tsconfig.json +++ b/immutable/tsconfig.json @@ -3,5 +3,5 @@ "compilerOptions": { "outDir": "./dist" }, - "include": ["./*.ts"] + "include": ["./src"] } \ No newline at end of file diff --git a/infinite/package.json b/infinite/package.json index b18074d12..43d676a66 100644 --- a/infinite/package.json +++ b/infinite/package.json @@ -2,11 +2,17 @@ "main": "./dist/index.js", "module": "./dist/index.esm.js", "types": "./dist/infinite/index.d.ts", - "exports": "./dist/index.mjs", + "exports": { + "types": "./dist/index.d.ts", + "react-server": "./dist/react-server.mjs", + "import": "./dist/index.mjs", + "module": "./dist/index.esm.js", + "require": "./dist/index.js" + }, "private": true, "scripts": { - "watch": "bunchee index.ts -w", - "build": "bunchee index.ts", + "watch": "bunchee -w", + "build": "bunchee", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, diff --git a/infinite/index.ts b/infinite/src/index.ts similarity index 96% rename from infinite/index.ts rename to infinite/src/index.ts index cfedb5a7d..dfc76df81 100644 --- a/infinite/index.ts +++ b/infinite/src/index.ts @@ -30,17 +30,20 @@ import type { SWRInfiniteCompareFn } from './types' import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js' +import { INFINITE_PREFIX, getFirstPageKey } from './serialize' -const INFINITE_PREFIX = '$inf$' +// const INFINITE_PREFIX = '$inf$' const EMPTY_PROMISE = Promise.resolve() as Promise -const getFirstPageKey = (getKey: SWRInfiniteKeyLoader) => { - return serialize(getKey ? getKey(0, null) : null)[0] -} +// const getFirstPageKey = (getKey: SWRInfiniteKeyLoader) => { +// return serialize(getKey ? getKey(0, null) : null)[0] +// } -export const unstable_serialize = (getKey: SWRInfiniteKeyLoader) => { - return INFINITE_PREFIX + getFirstPageKey(getKey) -} +export { unstable_serialize } from './serialize' + +// export const unstable_serialize = (getKey: SWRInfiniteKeyLoader) => { +// return INFINITE_PREFIX + getFirstPageKey(getKey) +// } export const infinite = ((useSWRNext: SWRHook) => ( diff --git a/infinite/src/react-server.ts b/infinite/src/react-server.ts new file mode 100644 index 000000000..0945e0af8 --- /dev/null +++ b/infinite/src/react-server.ts @@ -0,0 +1 @@ +export { unstable_serialize } from './serialize' diff --git a/infinite/src/serialize.ts b/infinite/src/serialize.ts new file mode 100644 index 000000000..53f6af0e0 --- /dev/null +++ b/infinite/src/serialize.ts @@ -0,0 +1,12 @@ +import type { SWRInfiniteKeyLoader } from './types' +import { serialize } from 'swr/_internal' + +export const INFINITE_PREFIX = '$inf$' + +export const getFirstPageKey = (getKey: SWRInfiniteKeyLoader) => { + return serialize(getKey ? getKey(0, null) : null)[0] +} + +export const unstable_serialize = (getKey: SWRInfiniteKeyLoader) => { + return INFINITE_PREFIX + getFirstPageKey(getKey) +} diff --git a/infinite/types.ts b/infinite/src/types.ts similarity index 100% rename from infinite/types.ts rename to infinite/src/types.ts diff --git a/infinite/tsconfig.json b/infinite/tsconfig.json index 1996f8b51..51ed51cbe 100644 --- a/infinite/tsconfig.json +++ b/infinite/tsconfig.json @@ -3,5 +3,5 @@ "compilerOptions": { "outDir": "./dist" }, - "include": ["./*.ts"] + "include": ["./src"] } \ No newline at end of file diff --git a/jest.config.js b/jest.config.js index c1eb562c5..b543a605d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -5,12 +5,12 @@ module.exports = { modulePathIgnorePatterns: ['/examples/'], setupFilesAfterEnv: ['/test/jest-setup.ts'], moduleNameMapper: { - '^swr$': '/core/index.ts', - '^swr/infinite$': '/infinite/index.ts', - '^swr/immutable$': '/immutable/index.ts', - '^swr/subscription$': '/subscription/index.ts', - '^swr/mutation$': '/mutation/index.ts', - '^swr/_internal$': '/_internal/index.ts' + '^swr$': '/core/src/index.ts', + '^swr/infinite$': '/infinite/src/index.ts', + '^swr/immutable$': '/immutable/src/index.ts', + '^swr/subscription$': '/subscription/src/index.ts', + '^swr/mutation$': '/mutation/src/index.ts', + '^swr/_internal$': '/_internal/src/index.ts' }, transform: { '^.+\\.(t|j)sx?$': ['@swc/jest'] diff --git a/mutation/package.json b/mutation/package.json index 74043d917..1f30b94f3 100644 --- a/mutation/package.json +++ b/mutation/package.json @@ -1,12 +1,17 @@ { "main": "./dist/index.js", "module": "./dist/index.esm.js", - "types": "./dist/mutation/index.d.ts", - "exports": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "exports": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "module": "./dist/index.esm.js", + "require": "./dist/index.js" + }, "private": true, "scripts": { - "watch": "bunchee index.ts -w", - "build": "bunchee index.ts", + "watch": "bunchee -w", + "build": "bunchee", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, diff --git a/mutation/index.ts b/mutation/src/index.ts similarity index 100% rename from mutation/index.ts rename to mutation/src/index.ts diff --git a/mutation/types.ts b/mutation/src/types.ts similarity index 100% rename from mutation/types.ts rename to mutation/src/types.ts diff --git a/mutation/tsconfig.json b/mutation/tsconfig.json index 69caa135e..1f5b2f697 100644 --- a/mutation/tsconfig.json +++ b/mutation/tsconfig.json @@ -3,5 +3,5 @@ "compilerOptions": { "outDir": "./dist" }, - "include": ["./*.ts"] + "include": ["./src"] } diff --git a/package.json b/package.json index 1f8b14f27..467979ecc 100644 --- a/package.json +++ b/package.json @@ -18,12 +18,14 @@ "./package.json": "./package.json", ".": { "types": "./core/dist/index.d.ts", + "react-server": "./core/dist/react-server.mjs", "import": "./core/dist/index.mjs", "module": "./core/dist/index.esm.js", "require": "./core/dist/index.js" }, "./infinite": { "types": "./infinite/dist/infinite/index.d.ts", + "react-server": "./infinite/dist/react-server.mjs", "import": "./infinite/dist/index.mjs", "module": "./infinite/dist/index.esm.js", "require": "./infinite/dist/index.js" @@ -41,7 +43,7 @@ "require": "./subscription/dist/index.js" }, "./mutation": { - "types": "./mutation/dist/mutation/index.d.ts", + "types": "./mutation/dist/index.d.ts", "import": "./mutation/dist/index.mjs", "module": "./mutation/dist/index.esm.js", "require": "./mutation/dist/index.js" @@ -78,7 +80,7 @@ "watch": "pnpm -r run watch", "build": "pnpm build-package _internal && pnpm build-package core && pnpm build-package infinite && pnpm build-package immutable && pnpm build-package mutation && pnpm build-package subscription", "build:e2e": "pnpm next build e2e/site", - "build-package": "bunchee index.ts --cwd", + "build-package": "bunchee --cwd", "types:check": "pnpm -r run types:check", "prepublishOnly": "pnpm clean && pnpm build", "publish-beta": "pnpm publish --tag beta", @@ -111,7 +113,7 @@ "@types/use-sync-external-store": "^0.0.3", "@typescript-eslint/eslint-plugin": "5.59.8", "@typescript-eslint/parser": "5.59.8", - "bunchee": "3.2.0", + "bunchee": "3.3.4", "eslint": "8.42.0", "eslint-config-prettier": "8.8.0", "eslint-plugin-jest-dom": "5.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 73c6ba502..ef8d1cf9a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -45,8 +45,8 @@ importers: specifier: 5.59.8 version: 5.59.8(eslint@8.42.0)(typescript@5.1.3) bunchee: - specifier: 3.2.0 - version: 3.2.0(typescript@5.1.3) + specifier: 3.3.4 + version: 3.3.4(typescript@5.1.3) eslint: specifier: 8.42.0 version: 8.42.0 @@ -1995,8 +1995,8 @@ packages: engines: {node: '>=6'} dev: true - /bunchee@3.2.0(typescript@5.1.3): - resolution: {integrity: sha512-gFg9T/oTDSlzBmjpxKAMUgTHFBx05bCw9jCM0O+moEjGyt8TMIwaG8RbiBCXxE43lEhUwU1RrtCRlSYniU+w7w==} + /bunchee@3.3.4(typescript@5.1.3): + resolution: {integrity: sha512-p6LsM6Itw6nianQEp3zUsYvaX/rXyF5ky+VJHiLvVvhYD1Q5p0AD4xNm5+tJjetwuOk5yI00DLRZut//uTetyQ==} engines: {node: '>= 16'} hasBin: true peerDependencies: @@ -3499,7 +3499,7 @@ packages: resolution: {integrity: sha512-Kijeg9Dag6CKtIDA7O21zNTACqD5MD/8HfIV8pdD94vFyFuer52SigdC3IQMhab3vACxXMiFk+yMHNdbqtyTGA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: - '@babel/code-frame': 7.18.6 + '@babel/code-frame': 7.21.4 '@jest/types': 29.5.0 '@types/stack-utils': 2.0.1 chalk: 4.1.2 diff --git a/subscription/package.json b/subscription/package.json index 06a1e4022..1f30b94f3 100644 --- a/subscription/package.json +++ b/subscription/package.json @@ -2,11 +2,16 @@ "main": "./dist/index.js", "module": "./dist/index.esm.js", "types": "./dist/index.d.ts", - "exports": "./dist/index.mjs", + "exports": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "module": "./dist/index.esm.js", + "require": "./dist/index.js" + }, "private": true, "scripts": { - "watch": "bunchee index.ts -w", - "build": "bunchee index.ts", + "watch": "bunchee -w", + "build": "bunchee", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, diff --git a/subscription/index.ts b/subscription/src/index.ts similarity index 100% rename from subscription/index.ts rename to subscription/src/index.ts diff --git a/subscription/types.ts b/subscription/src/types.ts similarity index 100% rename from subscription/types.ts rename to subscription/src/types.ts diff --git a/subscription/tsconfig.json b/subscription/tsconfig.json index 683b85e52..bd4e55bac 100644 --- a/subscription/tsconfig.json +++ b/subscription/tsconfig.json @@ -4,6 +4,6 @@ "outDir": "./dist", "rootDir": "..", }, - "include": [".", "../src"], + "include": ["./src"], "exclude": ["./dist"] } \ No newline at end of file diff --git a/test/type/helper-types.tsx b/test/type/helper-types.tsx index 3a06bfbd1..abea1e30d 100644 --- a/test/type/helper-types.tsx +++ b/test/type/helper-types.tsx @@ -1,4 +1,4 @@ -import type { BlockingData } from '../../_internal/types' +import type { BlockingData } from 'swr/_internal' import { expectType } from './utils' export function testDataCached() { diff --git a/tsconfig.json b/tsconfig.json index 30c150f1c..08c535630 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,12 +19,12 @@ "noEmitOnError": true, "downlevelIteration": true, "paths": { - "swr": ["./core/index.ts"], - "swr/infinite": ["./infinite/index.ts"], - "swr/immutable": ["./immutable/index.ts"], - "swr/mutation": ["./mutation/index.ts"], - "swr/_internal": ["./_internal/index.ts"], - "swr/subscription": ["subscription/index.ts"], + "swr": ["./core/src/index.ts"], + "swr/infinite": ["./infinite/src/index.ts"], + "swr/immutable": ["./immutable/src/index.ts"], + "swr/mutation": ["./mutation/src/index.ts"], + "swr/_internal": ["./_internal/src/index.ts"], + "swr/subscription": ["subscription/src/index.ts"], }, "incremental": true },