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

build: generate d.mts for for .mjs, so typescript could resolve types correctly #2695

Merged
merged 7 commits into from
Jul 21, 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
1 change: 1 addition & 0 deletions .github/workflows/test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
pnpm run-all-checks
pnpm clean
pnpm build
pnpm attw
pnpm test:build
e2e:
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion _internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"module": "./dist/index.esm.js",
"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",
Expand Down
4 changes: 1 addition & 3 deletions _internal/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type * as revalidateEvents from './constants'
import type { defaultConfig } from './utils/config'

export type GlobalState = [
Record<string, RevalidateCallback[]>, // EVENT_REVALIDATORS
Expand Down Expand Up @@ -293,8 +292,7 @@ export type Middleware = (
) => <Data = any, Error = any>(
key: Key,
fetcher: BareFetcher<Data> | null,
config: typeof defaultConfig &
SWRConfiguration<Data, Error, BareFetcher<Data>>
config: SWRConfiguration<Data, Error, BareFetcher<Data>>
) => SWRResponse<Data, Error>

type ArgumentsTuple = [any, ...unknown[]] | readonly [any, ...unknown[]]
Expand Down
1 change: 0 additions & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"module": "./dist/index.esm.js",
"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",
Expand Down
3 changes: 2 additions & 1 deletion core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import 'client-only'
import useSWR from './use-swr'
export default useSWR
// Core APIs
export { SWRConfig, unstable_serialize } from './use-swr'
export { SWRConfig } from './use-swr'
export { unstable_serialize } from './serialize'
export { useSWRConfig } from 'swr/_internal'
export { mutate } from 'swr/_internal'
export { preload } from 'swr/_internal'
Expand Down
2 changes: 1 addition & 1 deletion core/src/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Key } from 'swr'
import type { Key } from 'swr/_internal'
import { serialize } from 'swr/_internal'

export const unstable_serialize = (key: Key) => serialize(key)[0]
1 change: 0 additions & 1 deletion immutable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"module": "./dist/index.esm.js",
"require": "./dist/index.js"
Expand Down
1 change: 0 additions & 1 deletion infinite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"module": "./dist/index.esm.js",
"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",
Expand Down
1 change: 0 additions & 1 deletion mutation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"module": "./dist/index.esm.js",
promer94 marked this conversation as resolved.
Show resolved Hide resolved
"require": "./dist/index.js"
Expand Down
42 changes: 27 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,65 @@
"main": "./core/dist/index.js",
"module": "./core/dist/index.esm.js",
"types": "./core/dist/index.d.ts",
"typesVersions": {
"*": {
"infinite": [
"./infinite/dist/index.d.ts"
],
"immutable": [
"./immutable/dist/index.d.ts"
],
"mutation": [
"./mutation/dist/index.d.ts"
],
"subscription": [
"./subscription/dist/index.d.ts"
]
}
},
"exports": {
"./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/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"
},
"./immutable": {
"types": "./immutable/dist/index.d.ts",
"import": "./immutable/dist/index.mjs",
"module": "./immutable/dist/index.esm.js",
"require": "./immutable/dist/index.js"
},
"./subscription": {
"types": "./subscription/dist/index.d.ts",
"import": "./subscription/dist/index.mjs",
"module": "./subscription/dist/index.esm.js",
"require": "./subscription/dist/index.js"
},
"./mutation": {
"types": "./mutation/dist/index.d.ts",
"import": "./mutation/dist/index.mjs",
"module": "./mutation/dist/index.esm.js",
"require": "./mutation/dist/index.js"
},
"./_internal": {
"types": "./_internal/dist/index.d.ts",
"react-server": "./_internal/dist/react-server.mjs",
"import": "./_internal/dist/index.mjs",
"module": "./_internal/dist/index.esm.js",
"require": "./_internal/dist/index.js"
}
},
"files": [
"core/dist/**/*.{js,d.ts,mjs}",
"infinite/dist/**/*.{js,d.ts,mjs}",
"immutable/dist/**/*.{js,d.ts,mjs}",
"mutation/dist/**/*.{js,d.ts,mjs}",
"_internal/dist/**/*.{js,d.ts,mjs}",
"subscription/dist/*.{js,d.ts,mjs}",
"core/dist/**/*.{js,d.ts,mjs,d.mts}",
"infinite/dist/**/*.{js,d.ts,mjs,d.mts}",
"immutable/dist/**/*.{js,d.ts,mjs,d.mts}",
"mutation/dist/**/*.{js,d.ts,mjs,d.mts}",
"_internal/dist/**/*.{js,d.ts,mjs,d.mts}",
"subscription/dist/*.{js,d.ts,mjs,d.mts}",
"core/package.json",
"infinite/package.json",
"immutable/package.json",
Expand All @@ -82,6 +92,7 @@
"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 --cwd",
"attw": "attw --pack",
promer94 marked this conversation as resolved.
Show resolved Hide resolved
"types:check": "pnpm -r run types:check",
"prepublishOnly": "pnpm clean && pnpm build",
"publish-beta": "pnpm publish --tag beta",
Expand All @@ -93,7 +104,7 @@
"test": "jest",
"test:build": "jest --config jest.config.build.js",
"test:e2e": "playwright test",
"run-all-checks": "pnpm types:check && pnpm lint && pnpm test && pnpm test-typing"
"run-all-checks": "pnpm types:check && pnpm lint && pnpm test-typing"
},
"lint-staged": {
"*.{ts,tsx}": [
Expand All @@ -102,6 +113,7 @@
]
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.7.0",
"@playwright/test": "^1.34.3",
"@swc/core": "^1.3.62",
"@swc/jest": "0.2.26",
Expand All @@ -114,7 +126,7 @@
"@types/use-sync-external-store": "^0.0.3",
"@typescript-eslint/eslint-plugin": "5.59.8",
"@typescript-eslint/parser": "5.59.8",
"bunchee": "3.5.0",
"bunchee": "3.6.0",
"eslint": "8.42.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-jest-dom": "5.0.1",
Expand Down Expand Up @@ -150,4 +162,4 @@
"client-only": "^0.0.1",
"use-sync-external-store": "^1.2.0"
}
}
}
Loading