Skip to content

Commit

Permalink
refactor(ts): rewrite core to TypeScript (nextauthjs#2552)
Browse files Browse the repository at this point in the history
* chore(deps): upgrade TS packages

* build(ts): use tsc to compile

* refactor(ts): move some files to TS

* chore: implement SkyPack check suggestions

* chore(ci): temprarily disable tests

* chore: add PR comment action

* chore: add determine version github action

* chore: prefix with env.

* chore: add runs to action

* chore: change runs.using to node12

* chore: fix typo

* chore: install @actions/core as dev dependency

* chore: move env var, remove old script

* chore: change version comment message

* refactor(ts): convert server/index.js to TS

* chore: fix `types` path

* chore: fix paths

* refactor(ts): convert `next-auth/react`

* refactor(ts): convert `next-auth/jwt` to TS

* chore: fix import

* refactor: move `types` into `src`

* refactor(ts): fix types imports

* chore: add cleanup script

* chore: exclude all `tests` folder from compilation

* refactor: rename types/index.d.ts to types/index.ts

* refactor(ts): move `next-auth/jwt`

* refactor(ts): move `next-auth/providers`

* chore(ts): fix `next-auth` types

* refactor(ts): change internal import paths

* test(ts): remove type tests

* chore: remove test:types script

* refactor(ts): move more code to TypeScript

* refactor: fix some imports

* refactor(ts): move error module into server

* fix(ts): add type to .js providers

* chore: rename adapters.ts to adapters.d.ts

* fix: update exports field

* chore: add files that should end up on npm

* chore: add stricter lib checking

* refactor(ts): remove unnecessary files, fix imports

* chore: autocomplete env variables

* fix: add css folder to npm files

* fix: fix CSS import/generation

* feat: log provider when authorization url error happens

* refactor(ts): turn pages into .tsx

* chore: compile differently for client/server

* refactor(ts): move server file to TS

* chore: add back node target

* chore: add back comment removal

* chore: re-enable tests

* chore: ignore test files when building

* chore(ts): refactor files to TS

* chore(ts): fix imports

* chore(ts): more ts

* fix(ts): correctly type _NEXTAUTH_DEBUG env var

* chore: don't generate internals module iwth babel

* fix(ts): better `clientId`, `clientSecret` constraints

* refactor(ts): move facebook provider to TS

* refactor(ts): apply suggested changes

* chore(ts): strip internal types from compilation

* refactor(ts): move server types to server folder

* refactor(ts): rename internals to types
  • Loading branch information
mnphpexpert committed Aug 31, 2021
1 parent 4b77043 commit 8191956
Show file tree
Hide file tree
Showing 136 changed files with 2,109 additions and 5,451 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Build
run: npm run build
- name: Run tests
run: npm test -- --coverage --verbose && npm run test:types
run: npm test -- --coverage --verbose
- name: Coverage
uses: codecov/codecov-action@v1
with:
Expand Down Expand Up @@ -66,11 +66,21 @@ jobs:
node-version: 16
- name: Dependencies
uses: bahmutov/npm-install@v1
- name: Determine version
uses: ./config/version-pr
id: determine-version
env:
PR_NUMBER: ${{ github.event.number }}
- name: Publish to npm
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc
npm run version:pr
npm publish --access public --tag experimental
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
- name: Comment version on PR
uses: NejcZdovc/comment-pr@v1
with:
message: "🎉 Experimental release [published on npm](https://www.npmjs.com/package/next-auth/v/${{ env.VERSION }})!\n\n```sh\nnpm i next-auth@${{ env.VERSION }}\n```\n```sh\nyarn add next-auth@${{ env.VERSION }}\n```"
env:
VERSION: ${{ steps.determine-version.outputs.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 6 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,16 @@ node_modules
# Generated files
.docusaurus
.cache-loader
/internals
/providers
/types/providers/*
!types/providers/index.d.ts
!types/providers/email.d.ts
!types/providers/credentials.d.ts
!types/providers/oauth.d.ts
/client
/css
/lib
/server
/jwt
/react
/adapters.d.ts
/adapters.js
/client.d.ts
/client.js
/index.d.ts
/index.js
/jwt.d.ts
/jwt.js
/errors.js
/errors.d.ts
/react.js
/react.d.ts

# Development app
app/next-auth
Expand Down
68 changes: 47 additions & 21 deletions config/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,54 @@
// https://nextjs.org/docs/getting-started#system-requirements
// https://nextjs.org/docs/basic-features/supported-browsers-features

module.exports = {
presets: [["@babel/preset-env", { targets: { node: "12" } }]],
plugins: [
"@babel/plugin-proposal-optional-catch-binding",
"@babel/plugin-transform-runtime",
],
comments: false,
overrides: [
{
test: ["../src/client/**"],
module.exports = (api) => {
const isTest = api.env("test")
if (isTest) {
return {
presets: [
["@babel/preset-env", { targets: { ie: "11" } }],
"@babel/preset-env",
["@babel/preset-react", { runtime: "automatic" }],
["@babel/preset-typescript", { isTSX: true, allExtensions: true }],
],
},
{
test: ["../src/server/pages/**"],
presets: ["preact"],
},
{
test: ["../src/**/*.test.js"],
presets: [["@babel/preset-react", { runtime: "automatic" }]],
},
],
}
}
return {
presets: [
["@babel/preset-env", { targets: { node: 12 } }],
"@babel/preset-typescript",
],
plugins: [
"@babel/plugin-proposal-optional-catch-binding",
"@babel/plugin-transform-runtime",
],
ignore: [
"../src/**/__tests__/**",
"../src/adapters.ts",
"../src/lib/types.ts",
],
comments: false,
overrides: [
{
test: ["../src/react/index.tsx"],
presets: [
["@babel/preset-env", { targets: { ie: 11 } }],
["@babel/preset-react", { runtime: "automatic" }],
],
},
{
test: ["../src/server/pages/*.tsx"],
presets: ["preact"],
plugins: [
[
"jsx-pragmatic",
{
module: "preact",
export: "h",
import: "h",
},
],
],
},
],
}
}
108 changes: 0 additions & 108 deletions config/build.js

This file was deleted.

1 change: 1 addition & 0 deletions config/jest-setup.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import "regenerator-runtime/runtime"
import "@testing-library/jest-dom"
import "whatwg-fetch"
5 changes: 4 additions & 1 deletion config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
transform: {
"\\.js$": ["babel-jest", { configFile: "./config/babel.config.js" }],
"\\.(js|jsx|ts|tsx)$": [
"babel-jest",
{ configFile: "./config/babel.config.js" },
],
},
rootDir: "../src",
setupFilesAfterEnv: ["../config/jest-setup.js"],
Expand Down
8 changes: 8 additions & 0 deletions config/version-pr/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: "Determine version"
description: "Determines npm package version based on PR number and commit SHA"
outputs:
version:
description: "npm package version"
runs:
using: "node12"
main: "index.js"
9 changes: 5 additions & 4 deletions config/version-pr.js → config/version-pr/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require("fs-extra")
const path = require("path")
const core = require("@actions/core")

try {
const packageJSONPath = path.join(process.cwd(), "package.json")
Expand All @@ -8,10 +9,10 @@ try {
const sha8 = process.env.GITHUB_SHA.substr(0, 8)
const prNumber = process.env.PR_NUMBER

packageJSON.version = `0.0.0-pr.${prNumber}.${sha8}`

const packageVersion = `0.0.0-pr.${prNumber}.${sha8}`
packageJSON.version = packageVersion
core.setOutput("version", packageVersion)
fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON))
} catch (error) {
console.error("Could not set PR version", error)
process.exit(1)
core.setFailed(error.message)
}
13 changes: 6 additions & 7 deletions config/wrap-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
// To work around this issue, this script is a manual step that wraps CSS in a
// JavaScript file that has the compiled CSS embedded in it, and exports only
// a function that returns the CSS as a string.
const fs = require('fs')
const path = require('path')
const fs = require("fs")
const path = require("path")

const pathToCssJs = path.join(__dirname, '../dist/css/index.js')
const pathToCss = path.join(__dirname, '../dist/css/index.css')

const css = fs.readFileSync(pathToCss, 'utf8')
const pathToCss = path.join(__dirname, "../css/index.css")
const css = fs.readFileSync(pathToCss, "utf8")
const cssWithEscapedQuotes = css.replace(/"/gm, '\\"')
const js = `module.exports = function() { return "${cssWithEscapedQuotes}" }`

const js = `module.exports = function() { return "${cssWithEscapedQuotes}" }`
const pathToCssJs = path.join(__dirname, "../css/index.js")
fs.writeFileSync(pathToCssJs, js)
Loading

0 comments on commit 8191956

Please sign in to comment.