From 146a8404c43d2a35a253bab9ee2200086b821d83 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 12 Jun 2023 11:41:24 +0200 Subject: [PATCH 01/12] Add react-server bundle for core and infinite --- core/package.json | 8 +++++++- core/{ => src}/index.ts | 4 ++-- core/src/react-server.ts | 1 + infinite/package.json | 8 +++++++- infinite/{ => src}/index.ts | 17 ++++++++++------- infinite/src/react-server.ts | 1 + infinite/src/serialize.ts | 12 ++++++++++++ infinite/{ => src}/types.ts | 0 infinite/tsconfig.json | 2 +- package.json | 4 +++- pnpm-lock.yaml | 8 ++++---- 11 files changed, 48 insertions(+), 17 deletions(-) rename core/{ => src}/index.ts (82%) create mode 100644 core/src/react-server.ts rename infinite/{ => src}/index.ts (96%) create mode 100644 infinite/src/react-server.ts create mode 100644 infinite/src/serialize.ts rename infinite/{ => src}/types.ts (100%) diff --git a/core/package.json b/core/package.json index 09b191850..cbab74037 100644 --- a/core/package.json +++ b/core/package.json @@ -2,7 +2,13 @@ "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", diff --git a/core/index.ts b/core/src/index.ts similarity index 82% rename from core/index.ts rename to core/src/index.ts index 83fa55141..2eb19c186 100644 --- a/core/index.ts +++ b/core/src/index.ts @@ -1,8 +1,8 @@ // useSWR -import useSWR from './use-swr' +import useSWR from '../use-swr' export default useSWR // Core APIs -export { SWRConfig, unstable_serialize } from './use-swr' +export { SWRConfig, unstable_serialize } from '../use-swr' export { useSWRConfig } from 'swr/_internal' export { mutate } from 'swr/_internal' export { preload } from 'swr/_internal' diff --git a/core/src/react-server.ts b/core/src/react-server.ts new file mode 100644 index 000000000..510dd9bb6 --- /dev/null +++ b/core/src/react-server.ts @@ -0,0 +1 @@ +export { unstable_serialize } from '../use-swr' diff --git a/infinite/package.json b/infinite/package.json index b18074d12..c854da9e7 100644 --- a/infinite/package.json +++ b/infinite/package.json @@ -2,7 +2,13 @@ "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", 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/package.json b/package.json index 1f8b14f27..9f5b5015a 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" @@ -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.1", "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..34919e6d2 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.1 + version: 3.3.1(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.1(typescript@5.1.3): + resolution: {integrity: sha512-jsL58K398sOn8RQP5VvSbtnIvFRsM6SIC9v3zLTey92vLPdietEkOh7AxqY14hzYA/ng8gLXdSLmBzZu+4Y5pw==} engines: {node: '>= 16'} hasBin: true peerDependencies: From 44aba8af27ceccc4ee0dab20fcd91bff7e6ebd95 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 12 Jun 2023 13:16:01 +0200 Subject: [PATCH 02/12] Upgrade bunchee and change convention --- _internal/package.json | 11 ++++++++--- _internal/{ => src}/constants.ts | 0 _internal/{ => src}/index.ts | 0 _internal/{ => src}/types.ts | 0 _internal/{ => src}/utils/cache.ts | 0 _internal/{ => src}/utils/config-context.ts | 0 _internal/{ => src}/utils/config.ts | 0 _internal/{ => src}/utils/devtools.ts | 0 _internal/{ => src}/utils/env.ts | 0 _internal/{ => src}/utils/global-state.ts | 0 _internal/{ => src}/utils/hash.ts | 0 _internal/{ => src}/utils/helper.ts | 0 _internal/{ => src}/utils/merge-config.ts | 0 _internal/{ => src}/utils/middleware-preset.ts | 0 _internal/{ => src}/utils/mutate.ts | 0 _internal/{ => src}/utils/normalize-args.ts | 0 _internal/{ => src}/utils/preload.ts | 0 _internal/{ => src}/utils/resolve-args.ts | 0 _internal/{ => src}/utils/serialize.ts | 0 _internal/{ => src}/utils/state.ts | 0 _internal/{ => src}/utils/subscribe-key.ts | 0 _internal/{ => src}/utils/timestamp.ts | 0 _internal/{ => src}/utils/use-swr-config.ts | 0 _internal/{ => src}/utils/web-preset.ts | 0 _internal/{ => src}/utils/with-middleware.ts | 0 _internal/tsconfig.json | 2 +- core/src/index.ts | 4 ++-- core/src/react-server.ts | 2 +- core/{ => src}/use-swr.ts | 0 immutable/{ => src}/index.ts | 0 immutable/tsconfig.json | 2 +- package.json | 4 ++-- pnpm-lock.yaml | 10 +++++----- subscription/package.json | 7 ++++++- subscription/{ => src}/index.ts | 0 subscription/{ => src}/types.ts | 0 subscription/tsconfig.json | 2 +- 37 files changed, 27 insertions(+), 17 deletions(-) rename _internal/{ => src}/constants.ts (100%) rename _internal/{ => src}/index.ts (100%) rename _internal/{ => src}/types.ts (100%) rename _internal/{ => src}/utils/cache.ts (100%) rename _internal/{ => src}/utils/config-context.ts (100%) rename _internal/{ => src}/utils/config.ts (100%) rename _internal/{ => src}/utils/devtools.ts (100%) rename _internal/{ => src}/utils/env.ts (100%) rename _internal/{ => src}/utils/global-state.ts (100%) rename _internal/{ => src}/utils/hash.ts (100%) rename _internal/{ => src}/utils/helper.ts (100%) rename _internal/{ => src}/utils/merge-config.ts (100%) rename _internal/{ => src}/utils/middleware-preset.ts (100%) rename _internal/{ => src}/utils/mutate.ts (100%) rename _internal/{ => src}/utils/normalize-args.ts (100%) rename _internal/{ => src}/utils/preload.ts (100%) rename _internal/{ => src}/utils/resolve-args.ts (100%) rename _internal/{ => src}/utils/serialize.ts (100%) rename _internal/{ => src}/utils/state.ts (100%) rename _internal/{ => src}/utils/subscribe-key.ts (100%) rename _internal/{ => src}/utils/timestamp.ts (100%) rename _internal/{ => src}/utils/use-swr-config.ts (100%) rename _internal/{ => src}/utils/web-preset.ts (100%) rename _internal/{ => src}/utils/with-middleware.ts (100%) rename core/{ => src}/use-swr.ts (100%) rename immutable/{ => src}/index.ts (100%) rename subscription/{ => src}/index.ts (100%) rename subscription/{ => src}/types.ts (100%) diff --git a/_internal/package.json b/_internal/package.json index ac9494000..290a09388 100644 --- a/_internal/package.json +++ b/_internal/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/_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/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/src/index.ts b/core/src/index.ts index 2eb19c186..83fa55141 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -1,8 +1,8 @@ // useSWR -import useSWR from '../use-swr' +import useSWR from './use-swr' export default useSWR // Core APIs -export { SWRConfig, unstable_serialize } from '../use-swr' +export { SWRConfig, unstable_serialize } from './use-swr' export { useSWRConfig } from 'swr/_internal' export { mutate } from 'swr/_internal' export { preload } from 'swr/_internal' diff --git a/core/src/react-server.ts b/core/src/react-server.ts index 510dd9bb6..67a6ef4cd 100644 --- a/core/src/react-server.ts +++ b/core/src/react-server.ts @@ -1 +1 @@ -export { unstable_serialize } from '../use-swr' +export { unstable_serialize } from './use-swr' diff --git a/core/use-swr.ts b/core/src/use-swr.ts similarity index 100% rename from core/use-swr.ts rename to core/src/use-swr.ts 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/package.json b/package.json index 9f5b5015a..8db430b13 100644 --- a/package.json +++ b/package.json @@ -80,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", @@ -113,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.3.1", + "bunchee": "3.3.3", "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 34919e6d2..4b225fcc9 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.3.1 - version: 3.3.1(typescript@5.1.3) + specifier: 3.3.3 + version: 3.3.3(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.3.1(typescript@5.1.3): - resolution: {integrity: sha512-jsL58K398sOn8RQP5VvSbtnIvFRsM6SIC9v3zLTey92vLPdietEkOh7AxqY14hzYA/ng8gLXdSLmBzZu+4Y5pw==} + /bunchee@3.3.3(typescript@5.1.3): + resolution: {integrity: sha512-CE78sGjh+G0pqj3M+G6ZuI6JhN4d2cUExSvZSl2b4Wuh/7IVtV4JT77yGbHpYGTFGqB8gdmqoPVpV75yT/f8pQ==} 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..7cb2f41d8 100644 --- a/subscription/package.json +++ b/subscription/package.json @@ -2,7 +2,12 @@ "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", 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 From b17f7491bc0306ec791e5b4bd591b5b03234bfeb Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 12 Jun 2023 13:18:52 +0200 Subject: [PATCH 03/12] Update mutation exports and fix alias --- jest.config.js | 12 ++++++------ mutation/package.json | 7 ++++++- mutation/{ => src}/index.ts | 0 mutation/{ => src}/types.ts | 0 mutation/tsconfig.json | 2 +- package.json | 2 +- tsconfig.json | 12 ++++++------ 7 files changed, 20 insertions(+), 15 deletions(-) rename mutation/{ => src}/index.ts (100%) rename mutation/{ => src}/types.ts (100%) 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..151e366f1 100644 --- a/mutation/package.json +++ b/mutation/package.json @@ -2,7 +2,12 @@ "main": "./dist/index.js", "module": "./dist/index.esm.js", "types": "./dist/mutation/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", 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 8db430b13..a9507c922 100644 --- a/package.json +++ b/package.json @@ -43,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" 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 }, From d0b9482c53214068e00248f38200c0f141454c2b Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 12 Jun 2023 13:21:06 +0200 Subject: [PATCH 04/12] fix mutation typing --- mutation/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mutation/package.json b/mutation/package.json index 151e366f1..7cb2f41d8 100644 --- a/mutation/package.json +++ b/mutation/package.json @@ -1,7 +1,7 @@ { "main": "./dist/index.js", "module": "./dist/index.esm.js", - "types": "./dist/mutation/index.d.ts", + "types": "./dist/index.d.ts", "exports": { "types": "./dist/index.d.ts", "import": "./dist/index.mjs", From de28f5a21fd92593a706f3a35fe0d19dbb130d10 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 12 Jun 2023 13:23:25 +0200 Subject: [PATCH 05/12] update script --- _internal/package.json | 2 +- core/package.json | 4 ++-- immutable/package.json | 4 ++-- infinite/package.json | 4 ++-- mutation/package.json | 4 ++-- package.json | 2 +- pnpm-lock.yaml | 4 ++-- subscription/package.json | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/_internal/package.json b/_internal/package.json index 290a09388..18ca8dc42 100644 --- a/_internal/package.json +++ b/_internal/package.json @@ -11,7 +11,7 @@ "private": true, "scripts": { "watch": "bunchee -w", - "build": "bunchee", + "build": "", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, diff --git a/core/package.json b/core/package.json index cbab74037..6b3407c7a 100644 --- a/core/package.json +++ b/core/package.json @@ -11,8 +11,8 @@ }, "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/package.json b/immutable/package.json index f1f40976b..b2742b991 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/infinite/package.json b/infinite/package.json index c854da9e7..c54adf66d 100644 --- a/infinite/package.json +++ b/infinite/package.json @@ -11,8 +11,8 @@ }, "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/package.json b/mutation/package.json index 7cb2f41d8..5a9a6d3d6 100644 --- a/mutation/package.json +++ b/mutation/package.json @@ -10,8 +10,8 @@ }, "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/package.json b/package.json index a9507c922..da8075a4c 100644 --- a/package.json +++ b/package.json @@ -113,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.3.3", + "": "3.3.3", "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 4b225fcc9..eb8dc0e62 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,7 +44,7 @@ importers: '@typescript-eslint/parser': specifier: 5.59.8 version: 5.59.8(eslint@8.42.0)(typescript@5.1.3) - bunchee: + : specifier: 3.3.3 version: 3.3.3(typescript@5.1.3) eslint: @@ -1995,7 +1995,7 @@ packages: engines: {node: '>=6'} dev: true - /bunchee@3.3.3(typescript@5.1.3): + /@3.3.3(typescript@5.1.3): resolution: {integrity: sha512-CE78sGjh+G0pqj3M+G6ZuI6JhN4d2cUExSvZSl2b4Wuh/7IVtV4JT77yGbHpYGTFGqB8gdmqoPVpV75yT/f8pQ==} engines: {node: '>= 16'} hasBin: true diff --git a/subscription/package.json b/subscription/package.json index 7cb2f41d8..5a9a6d3d6 100644 --- a/subscription/package.json +++ b/subscription/package.json @@ -10,8 +10,8 @@ }, "private": true, "scripts": { - "watch": "bunchee index.ts -w", - "build": "bunchee index.ts", + "watch": "bunchee -w", + "build": " bunchee", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, From 5e116c1e6883f3b6e30872552ca045b9b9b9f8c1 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 12 Jun 2023 13:27:52 +0200 Subject: [PATCH 06/12] fix lock file --- pnpm-lock.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eb8dc0e62..4b225fcc9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,7 +44,7 @@ importers: '@typescript-eslint/parser': specifier: 5.59.8 version: 5.59.8(eslint@8.42.0)(typescript@5.1.3) - : + bunchee: specifier: 3.3.3 version: 3.3.3(typescript@5.1.3) eslint: @@ -1995,7 +1995,7 @@ packages: engines: {node: '>=6'} dev: true - /@3.3.3(typescript@5.1.3): + /bunchee@3.3.3(typescript@5.1.3): resolution: {integrity: sha512-CE78sGjh+G0pqj3M+G6ZuI6JhN4d2cUExSvZSl2b4Wuh/7IVtV4JT77yGbHpYGTFGqB8gdmqoPVpV75yT/f8pQ==} engines: {node: '>= 16'} hasBin: true From 58c91f28959011763730ae930119b7eada6a6f1a Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 12 Jun 2023 13:28:49 +0200 Subject: [PATCH 07/12] fix pkg.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index da8075a4c..a9507c922 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,7 @@ "@types/use-sync-external-store": "^0.0.3", "@typescript-eslint/eslint-plugin": "5.59.8", "@typescript-eslint/parser": "5.59.8", - "": "3.3.3", + "bunchee": "3.3.3", "eslint": "8.42.0", "eslint-config-prettier": "8.8.0", "eslint-plugin-jest-dom": "5.0.1", From 099828b1c8a6462a7fe68b76ab63b28090172abb Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 12 Jun 2023 13:30:52 +0200 Subject: [PATCH 08/12] fix pnpm version --- .github/workflows/trigger-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 }} From cb29a22c419fc18252eea43fe3f1e18631a92949 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 12 Jun 2023 13:41:12 +0200 Subject: [PATCH 09/12] fix typing --- test/type/helper-types.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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() { From f1f8bb4b15002a7bd416f2bd2226178054133eae Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 12 Jun 2023 14:48:28 +0200 Subject: [PATCH 10/12] revert --- _internal/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_internal/package.json b/_internal/package.json index 18ca8dc42..290a09388 100644 --- a/_internal/package.json +++ b/_internal/package.json @@ -11,7 +11,7 @@ "private": true, "scripts": { "watch": "bunchee -w", - "build": "", + "build": "bunchee", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, From 87cc1c9491c26a8b78cfaa6645b49ac501f9ce3a Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 13 Jun 2023 22:33:03 +0200 Subject: [PATCH 11/12] separate serialize --- _internal/package.json | 1 + _internal/src/react-server.ts | 1 + core/package.json | 2 +- core/src/react-server.ts | 2 +- core/src/serialize.ts | 4 ++++ core/src/use-swr.ts | 2 +- immutable/package.json | 2 +- infinite/package.json | 2 +- mutation/package.json | 2 +- subscription/package.json | 2 +- 10 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 _internal/src/react-server.ts create mode 100644 core/src/serialize.ts diff --git a/_internal/package.json b/_internal/package.json index 290a09388..76da6864a 100644 --- a/_internal/package.json +++ b/_internal/package.json @@ -4,6 +4,7 @@ "types": "./dist/index.d.ts", "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" 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/core/package.json b/core/package.json index 6b3407c7a..2c8982424 100644 --- a/core/package.json +++ b/core/package.json @@ -12,7 +12,7 @@ "private": true, "scripts": { "watch": "bunchee -w", - "build": " bunchee", + "build": "bunchee", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, diff --git a/core/src/react-server.ts b/core/src/react-server.ts index 67a6ef4cd..0945e0af8 100644 --- a/core/src/react-server.ts +++ b/core/src/react-server.ts @@ -1 +1 @@ -export { unstable_serialize } from './use-swr' +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/src/use-swr.ts b/core/src/use-swr.ts index f04b27259..72054298f 100644 --- a/core/src/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 b2742b991..6eddb8ebc 100644 --- a/immutable/package.json +++ b/immutable/package.json @@ -6,7 +6,7 @@ "private": true, "scripts": { "watch": "bunchee -w", - "build": " bunchee", + "build": "bunchee", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, diff --git a/infinite/package.json b/infinite/package.json index c54adf66d..43d676a66 100644 --- a/infinite/package.json +++ b/infinite/package.json @@ -12,7 +12,7 @@ "private": true, "scripts": { "watch": "bunchee -w", - "build": " bunchee", + "build": "bunchee", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, diff --git a/mutation/package.json b/mutation/package.json index 5a9a6d3d6..1f30b94f3 100644 --- a/mutation/package.json +++ b/mutation/package.json @@ -11,7 +11,7 @@ "private": true, "scripts": { "watch": "bunchee -w", - "build": " bunchee", + "build": "bunchee", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, diff --git a/subscription/package.json b/subscription/package.json index 5a9a6d3d6..1f30b94f3 100644 --- a/subscription/package.json +++ b/subscription/package.json @@ -11,7 +11,7 @@ "private": true, "scripts": { "watch": "bunchee -w", - "build": " bunchee", + "build": "bunchee", "types:check": "tsc --noEmit", "clean": "rimraf dist" }, From d3815ea4668695c7d788a3ed38c94fc2f5b27ade Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 13 Jun 2023 22:39:22 +0200 Subject: [PATCH 12/12] bunchee 3.3.4 --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a9507c922..467979ecc 100644 --- a/package.json +++ b/package.json @@ -113,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.3.3", + "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 4b225fcc9..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.3.3 - version: 3.3.3(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.3.3(typescript@5.1.3): - resolution: {integrity: sha512-CE78sGjh+G0pqj3M+G6ZuI6JhN4d2cUExSvZSl2b4Wuh/7IVtV4JT77yGbHpYGTFGqB8gdmqoPVpV75yT/f8pQ==} + /bunchee@3.3.4(typescript@5.1.3): + resolution: {integrity: sha512-p6LsM6Itw6nianQEp3zUsYvaX/rXyF5ky+VJHiLvVvhYD1Q5p0AD4xNm5+tJjetwuOk5yI00DLRZut//uTetyQ==} engines: {node: '>= 16'} hasBin: true peerDependencies: