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

Add react-server bundle for core and infinite #2664

Merged
merged 12 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/trigger-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
12 changes: 9 additions & 3 deletions _internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions _internal/src/react-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { serialize } from './utils/serialize'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion _internal/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"compilerOptions": {
"outDir": "./dist"
},
"include": ["./*.ts"]
"include": ["./src"]
}
12 changes: 9 additions & 3 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions core/src/react-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { unstable_serialize } from './serialize'
4 changes: 4 additions & 0 deletions core/src/serialize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { Key } from 'swr'
import { serialize } from 'swr/_internal'

export const unstable_serialize = (key: Key) => serialize(key)[0]
2 changes: 1 addition & 1 deletion core/use-swr.ts → core/src/use-swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions immutable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion immutable/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"compilerOptions": {
"outDir": "./dist"
},
"include": ["./*.ts"]
"include": ["./src"]
}
12 changes: 9 additions & 3 deletions infinite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
17 changes: 10 additions & 7 deletions infinite/index.ts → infinite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<undefined>

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 = (<Data, Error>(useSWRNext: SWRHook) =>
(
Expand Down
1 change: 1 addition & 0 deletions infinite/src/react-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { unstable_serialize } from './serialize'
12 changes: 12 additions & 0 deletions infinite/src/serialize.ts
Original file line number Diff line number Diff line change
@@ -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)
}
File renamed without changes.
2 changes: 1 addition & 1 deletion infinite/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"compilerOptions": {
"outDir": "./dist"
},
"include": ["./*.ts"]
"include": ["./src"]
}
12 changes: 6 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module.exports = {
modulePathIgnorePatterns: ['<rootDir>/examples/'],
setupFilesAfterEnv: ['<rootDir>/test/jest-setup.ts'],
moduleNameMapper: {
'^swr$': '<rootDir>/core/index.ts',
'^swr/infinite$': '<rootDir>/infinite/index.ts',
'^swr/immutable$': '<rootDir>/immutable/index.ts',
'^swr/subscription$': '<rootDir>/subscription/index.ts',
'^swr/mutation$': '<rootDir>/mutation/index.ts',
'^swr/_internal$': '<rootDir>/_internal/index.ts'
'^swr$': '<rootDir>/core/src/index.ts',
'^swr/infinite$': '<rootDir>/infinite/src/index.ts',
'^swr/immutable$': '<rootDir>/immutable/src/index.ts',
'^swr/subscription$': '<rootDir>/subscription/src/index.ts',
'^swr/mutation$': '<rootDir>/mutation/src/index.ts',
'^swr/_internal$': '<rootDir>/_internal/src/index.ts'
},
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest']
Expand Down
13 changes: 9 additions & 4 deletions mutation/package.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion mutation/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"compilerOptions": {
"outDir": "./dist"
},
"include": ["./*.ts"]
"include": ["./src"]
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions subscription/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion subscription/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"outDir": "./dist",
"rootDir": "..",
},
"include": [".", "../src"],
"include": ["./src"],
"exclude": ["./dist"]
}
2 changes: 1 addition & 1 deletion test/type/helper-types.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BlockingData } from '../../_internal/types'
import type { BlockingData } from 'swr/_internal'
import { expectType } from './utils'

export function testDataCached() {
Expand Down
12 changes: 6 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down