Skip to content

Commit 46b62d7

Browse files
balazsorban440ubbendom91
authored
feat(ts): expose types from main package (#1773)
* chore: add beta to release flow/GH actions * feat(ts): expose types from the package (#1665) * chore(types): move existing types to the repo * feat(ts): expose types from the main package * chore(deps): bring back `react-dom` version range * chore(ts): cleanup deps and comments * chore(ci): run types tests on a separate workflow * chore(ci): fix typo on types workflow * fix(ts): correctly export sub-module types (#1677) * chore(types): build types script Adds a script that moves the declaration files we have in `./types` to `./dist` relative to the files they intend to type. This is the first step, we still need to change what we declare in `package.json`, add the script to the CI pipeline if we're happy with it and figure out how to type `next-auth/jwt`. * refactor(lint): fix build-types script * fix(ts): add .d.ts sub-module files to package.json #1677 seemed to miss this * fix(built): typo in package.json * fix(build): fix release * feat(ts): support module augmentation (#1681) * chore(ts): remove unused imports * refactor(ts): clean up CallbackOptions * docs(ts): explain Module Augmentation * docs(ts): don't use @ in folder name "types" * test(ts): make jwt params optional * docs(ts): fix typo (TypeScript -> NextAuth.js) * style: replace ts-standard with eslint/prettier (#1724) * style: move from ts-standard to eslint/prettier * fix: install remaining eslint-config-standard peer deps * fix: add remaining missing dependencies/config Co-authored-by: Balázs Orbán <[email protected]> * docs(lint): update contributing.md (#1760) Regarding ESLint / Prettier use and link to their VSCode extensions * refactor(ts): de-duplicate types (#1690) * refactor(ts): deduplicate internal types * refactor(ts): ease up providers typings * test(ts): fix failing TS tests * test(ts): rename TS property to fix test * docs(ts): mention TS docs in README.md * feat(ts): move/update client types * refactor(TS): rename some types * test(ts): fix client tests * docs(ts): move function descriptions to .d.ts * chore: fix lint error * refactor(ts): separate internal types * chore: simplify build-types script * chore: update type import paths in src * chore(build): create root files at build * chore: remove unnecessary .npmignore * chore: run prettier on types * fix(ts): clean up jwt types * fix(ts): make getToken return type depend on raw param * docs(page): explain page errors, add theming note * docs(ts): add JSDoc to NextAuthOptions props * chore(ts): remove unused import * docs(ts): change JSDOC docs notation * refactor(build): extract module entries into enum * chore(ts): move ClientSafeProvider * chore(ts): simplify GetTokenParams generic * style(lint): fix linting errors * chore: re-add generic extension to GetTokenParams * fix(ts): extract EmailConfigServerOptions to interface * fix(ts): use relative imports * Merge branch 'main' into beta * Merge main into beta * fix(ts): fix typos, add more links to documentation * test(ts): update JWT getToken test * fix(build): fix tsconfig.json formatting * test(ts): use absolute imports in test files * fix(ts): add missing callbacks JSDoc * docs: mention TS in FAQ, fix typos * docs: fix some typos in the docs Co-authored-by: Lluis Agusti <[email protected]> Co-authored-by: Nico Domino <[email protected]>
1 parent 457952b commit 46b62d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3171
-2107
lines changed

.github/workflows/build.yml

+2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ on:
66
push:
77
branches:
88
- main
9+
- beta
910
- next
1011
pull_request:
1112
branches:
1213
- main
14+
- beta
1315
- next
1416

1517
jobs:

.github/workflows/codeql-analysis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ name: "CodeQL"
1313

1414
on:
1515
push:
16-
branches: [ main, next ]
16+
branches: [ main, beta, next ]
1717
pull_request:
1818
# The branches below must be a subset of the branches above
1919
branches: [ main ]

.github/workflows/integration.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ name: Integration Test
22

33
on:
44
push:
5-
branches:
6-
- main
7-
- next
5+
branches:
6+
- main
7+
- beta
8+
- next
89
pull_request:
910

1011
jobs:
@@ -17,7 +18,7 @@ jobs:
1718
if: github.event.pull_request.head.repo.full_name == github.repository
1819

1920
# We use self-hosted runners as cloud based runnners (e.g. AWS, GPC)
20-
# fail due to IP Address checks done by providers, which enforce
21+
# fail due to IP Address checks done by providers, which enforce
2122
# CAPTCHA checks on login request from cloud compute IP addresses to
2223
# prevent abuse.
2324
runs-on: self-hosted
@@ -45,7 +46,7 @@ jobs:
4546
- run: npm test
4647
# TODO Tests should exit out if env vars not set (currently hangs)
4748
env:
48-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
49+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
4950
NEXTAUTH_TWITTER_ID: ${{secrets.NEXTAUTH_TWITTER_ID}}
5051
NEXTAUTH_TWITTER_SECRET: ${{secrets.NEXTAUTH_TWITTER_SECRET}}
5152
NEXTAUTH_TWITTER_USERNAME: ${{secrets.NEXTAUTH_TWITTER_USERNAME}}

.github/workflows/release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
push:
44
branches:
55
- 'main'
6+
- 'beta'
67
- 'next'
78
- '3.x'
89
pull_request:

.github/workflows/types.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Types
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- beta
8+
- next
9+
pull_request:
10+
branches:
11+
- main
12+
- beta
13+
- next
14+
15+
jobs:
16+
lint-and-build:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Use Node.js
21+
uses: actions/setup-node@v1
22+
- name: Install dependencies
23+
uses: bahmutov/npm-install@v1
24+
- name: Check types
25+
run: npm run test:types

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Anyone can be a contributor. Either you found a typo, or you have an awesome fea
1616
* The latest changes are always in `main`, so please make your Pull Request against that branch.
1717
* Pull Requests should be raised for any change
1818
* Pull Requests need approval of a [core contributor](https://next-auth.js.org/contributors#core-team) before merging
19-
* Run `npm run lint:fix` before committing to make resolving conflicts easier (VSCode users, check out [this extension](https://marketplace.visualstudio.com/items?itemName=chenxsan.vscode-standardjs) to fix lint issues in development)
19+
* We use ESLint/Prettier for linting/formatting, so please run `npm run lint:fix` before committing to make resolving conflicts easier (VSCode users, check out [this ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and [this Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) to fix lint and formatting issues in development)
2020
* We encourage you to test your changes, and if you have the opportunity, please make those tests part of the Pull Request
2121
* If you add new functionality, please provide the corresponding documentation as well and make it part of the Pull Request
2222

README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,9 @@ Advanced options allow you to define your own routines to handle controlling wha
8484

8585
### TypeScript
8686

87-
You can install the appropriate types via the following command:
87+
NextAuth.js comes with built-in types. For more information and usage, check out the [TypeScript section](https://next-auth.js.org/getting-started/typescript) in the documentaion.
8888

89-
```
90-
npm install --save-dev @types/next-auth
91-
```
92-
93-
As of now, TypeScript is a community effort. If you encounter any problems with the types package, please create an issue at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/next-auth). Alternatively, you can open a pull request directly with your fixes there. We welcome anyone to start a discussion on migrating this package to TypeScript, or how to improve the TypeScript experience in general.
89+
The package at `@types/next-auth` is now deprecated.
9490

9591
## Example
9692

adapters.js

-1
This file was deleted.

client.js

-1
This file was deleted.

config/build.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const fs = require("fs-extra")
2+
const path = require("path")
3+
4+
const MODULE_ENTRIES = {
5+
SERVER: "index",
6+
CLIENT: "client",
7+
PROVIDERS: "providers",
8+
ADAPTERS: "adapters",
9+
JWT: "jwt",
10+
}
11+
12+
const BUILD_TARGETS = {
13+
[`${MODULE_ENTRIES.SERVER}.js`]: "module.exports = require('./dist/server').default\n",
14+
[`${MODULE_ENTRIES.CLIENT}.js`]: "module.exports = require('./dist/client').default\n",
15+
[`${MODULE_ENTRIES.ADAPTERS}.js`]: "module.exports = require('./dist/adapters').default\n",
16+
[`${MODULE_ENTRIES.PROVIDERS}.js`]: "module.exports = require('./dist/providers').default\n",
17+
[`${MODULE_ENTRIES.JWT}.js`]: "module.exports = require('./dist/lib/jwt').default\n",
18+
}
19+
20+
Object.entries(BUILD_TARGETS).forEach(([target, content]) => {
21+
fs.writeFile(path.join(process.cwd(), target), content, (err) => {
22+
if (err) throw err
23+
console.log(`[build] created "${target}" in root folder`)
24+
})
25+
})
26+
27+
const TYPES_TARGETS = [
28+
`${MODULE_ENTRIES.SERVER}.d.ts`,
29+
`${MODULE_ENTRIES.CLIENT}.d.ts`,
30+
`${MODULE_ENTRIES.ADAPTERS}.d.ts`,
31+
`${MODULE_ENTRIES.PROVIDERS}.d.ts`,
32+
`${MODULE_ENTRIES.JWT}.d.ts`,
33+
"internals",
34+
]
35+
36+
TYPES_TARGETS.forEach((target) => {
37+
fs.copy(
38+
path.resolve("types", target),
39+
path.join(process.cwd(), target),
40+
(err) => {
41+
if (err) throw err
42+
console.log(`[build-types] copying "${target}" to root folder`)
43+
}
44+
)
45+
})

index.js

-1
This file was deleted.

jwt.js

-1
This file was deleted.

0 commit comments

Comments
 (0)