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

feat(web): expose Web API compatible version of next-auth #5536

Merged
merged 113 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 103 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
e428b17
WIP use `Request` and `Response` for core
balazsorban44 Jun 26, 2022
1268301
Merge branch 'main' into chore/core-request-response
balazsorban44 Aug 11, 2022
8c21589
bump Next.js
balazsorban44 Aug 11, 2022
504f384
rename ts types
balazsorban44 Aug 11, 2022
c736948
refactor
balazsorban44 Aug 11, 2022
b274e98
simplify
balazsorban44 Aug 11, 2022
b933003
upgrade Next.js
balazsorban44 Aug 12, 2022
db6b1c9
implement body reader
balazsorban44 Aug 12, 2022
fe9c6a5
use `Request`/`Response` in `next-auth/next`
balazsorban44 Aug 12, 2022
bc9ddae
make linter happy
balazsorban44 Aug 12, 2022
a5cd972
revert
balazsorban44 Aug 12, 2022
2cf11bb
fix tests
balazsorban44 Aug 12, 2022
63cdea4
remove workaround for middleware return type
balazsorban44 Aug 12, 2022
eb77e23
Merge branch 'main' into chore/core-request-response
balazsorban44 Oct 5, 2022
1903e3c
return session in protected api route example
balazsorban44 Oct 5, 2022
b63e843
don't export internal handler
balazsorban44 Oct 5, 2022
07ab4f8
fall back host to localhost
balazsorban44 Oct 5, 2022
415d299
refactor `getBody`
balazsorban44 Oct 5, 2022
b41bdeb
refactor `next-auth/next`
balazsorban44 Oct 5, 2022
8f7288a
Merge branch 'main' into chore/core-request-response
balazsorban44 Oct 6, 2022
bd4d78b
chore: add `@edge-runtime/jest-environment`
balazsorban44 Oct 6, 2022
1a2e752
fix tests, using Node 18 as runtime
balazsorban44 Oct 6, 2022
195822c
fix test
balazsorban44 Oct 6, 2022
57a7d3f
remove patch
balazsorban44 Oct 7, 2022
3d14536
upgrade/add dependencies
balazsorban44 Oct 8, 2022
bc314ef
type and default import on one line
balazsorban44 Oct 8, 2022
0723747
don't import all adapters by default in dev
balazsorban44 Oct 8, 2022
b8ed735
simplify internal endpoint config
balazsorban44 Oct 8, 2022
9bea473
assert if both endpoint and issuer config is missing
balazsorban44 Oct 8, 2022
cbd7f18
allow internal redirect to be `URL`
balazsorban44 Oct 8, 2022
9466f65
mark clientId as always internally, fix comments
balazsorban44 Oct 9, 2022
dbf4293
add web-compatible authorization URL handling
balazsorban44 Oct 9, 2022
0c71f26
fix type
balazsorban44 Oct 9, 2022
5d6643b
Merge branch 'main' into chore/core-request-response
balazsorban44 Oct 9, 2022
0e635bd
Merge remote-tracking branch 'origin/chore/core-request-response' int…
balazsorban44 Oct 9, 2022
1bed118
fix neo4j build
balazsorban44 Oct 10, 2022
4a2c89d
Merge remote-tracking branch 'origin/chore/core-request-response' int…
balazsorban44 Oct 10, 2022
6843007
Merge branch 'main' into chore/core-request-response
balazsorban44 Oct 10, 2022
6d3e4af
Merge remote-tracking branch 'origin/chore/core-request-response' int…
balazsorban44 Oct 10, 2022
b2de56c
remove new-line
balazsorban44 Oct 10, 2022
8041a59
reduce file changes in the PR
balazsorban44 Oct 10, 2022
49cfcf1
Merge remote-tracking branch 'origin/chore/core-request-response' int…
balazsorban44 Oct 10, 2022
7b46d1a
simplify types
balazsorban44 Oct 10, 2022
79d6299
refactor `crypto` usage
balazsorban44 Oct 10, 2022
68d5387
add `next-auth/web`
balazsorban44 Oct 10, 2022
a063349
refactor
balazsorban44 Oct 10, 2022
697443d
send header instead of body to indicate redirect response
balazsorban44 Oct 10, 2022
119de7e
fix eslint
balazsorban44 Oct 10, 2022
7a47d68
fix tests
balazsorban44 Oct 10, 2022
9aaa058
Merge branch 'main' into feat/oauth4webapi-balazs
balazsorban44 Dec 3, 2022
b0b9939
Merge branch 'main' into feat/oauth4webapi-balazs
balazsorban44 Dec 3, 2022
6b46f37
chore: upgrade dep
balazsorban44 Dec 3, 2022
b0fb174
Merge branch 'main' into feat/oauth4webapi-balazs
balazsorban44 Dec 3, 2022
1ee62b6
Merge branch 'main' into feat/oauth4webapi-balazs
balazsorban44 Dec 3, 2022
5a22790
fix import
balazsorban44 Dec 3, 2022
9f3e33e
refactor: more renames
balazsorban44 Dec 5, 2022
40f11ed
Merge branch 'main' into feat/oauth4webapi-balazs
balazsorban44 Dec 5, 2022
7d8f468
Merge branch 'main' into feat/oauth4webapi-balazs
balazsorban44 Dec 5, 2022
9d079a5
wip core
balazsorban44 Dec 6, 2022
166d4a8
support OIDC
balazsorban44 Dec 6, 2022
cc098bd
remove `openid-client`
balazsorban44 Dec 6, 2022
808d9a2
temprarily remove duplicate logos
balazsorban44 Dec 7, 2022
99abfbe
revert
balazsorban44 Dec 7, 2022
8299b97
move redirect logic to core
balazsorban44 Dec 7, 2022
2730249
wip fix css
balazsorban44 Dec 7, 2022
598b3ef
revert Logo component
balazsorban44 Dec 7, 2022
c3932f1
Merge branch 'main' into feat/oauth4webapi-balazs
balazsorban44 Dec 7, 2022
df61660
output ESM
balazsorban44 Dec 8, 2022
104f944
fix logout
balazsorban44 Dec 8, 2022
5c96c8f
deprecate OAuth 1, simplify internals, improve defaults
balazsorban44 Dec 8, 2022
5945d9b
refactor providers, test facebook
balazsorban44 Dec 8, 2022
5633959
fix providers
balazsorban44 Dec 8, 2022
860c8b5
target es2020
balazsorban44 Dec 8, 2022
187d38b
fix CSS
balazsorban44 Dec 8, 2022
7444ab3
Merge branch 'main' into feat/oauth4webapi-balazs
balazsorban44 Dec 8, 2022
7f3a6ca
Merge branch 'main' into feat/oauth4webapi-balazs
balazsorban44 Dec 11, 2022
0b8d3fd
update lock file
balazsorban44 Dec 11, 2022
67c525b
Merge branch 'main' into feat/oauth4webapi-balazs
balazsorban44 Dec 12, 2022
fa864e1
make logos optional
balazsorban44 Dec 12, 2022
92cfb91
sync with `next-auth`
balazsorban44 Dec 12, 2022
0469fc6
clean up `next-auth/edge`
balazsorban44 Dec 12, 2022
73026a4
sync
balazsorban44 Dec 12, 2022
5d15ac5
remove uuid
balazsorban44 Dec 13, 2022
e651df5
make secret required in dev
balazsorban44 Dec 13, 2022
9d0c138
remove todo comments
balazsorban44 Dec 13, 2022
e9f0828
pass through OAuth client options
balazsorban44 Dec 13, 2022
f231016
generate declaration map
balazsorban44 Dec 13, 2022
b2e66cc
default env secret to AUTH_SECRET
balazsorban44 Dec 13, 2022
f2d193b
temporary Headers fix
balazsorban44 Dec 13, 2022
90df63e
move pages to lib
balazsorban44 Dec 13, 2022
c229183
move errors to lib
balazsorban44 Dec 13, 2022
ffee34d
move pages/index to lib
balazsorban44 Dec 13, 2022
d96947c
move routes to lib
balazsorban44 Dec 13, 2022
1d9e591
move init to lib
balazsorban44 Dec 13, 2022
cb5a2ad
move styles to lib
balazsorban44 Dec 13, 2022
3e3f9a9
move types to lib
balazsorban44 Dec 13, 2022
0939b13
move utils to lib
balazsorban44 Dec 13, 2022
9fcf854
fix imports
balazsorban44 Dec 13, 2022
cea5969
update ignore/clean patterns
balazsorban44 Dec 13, 2022
24f329a
fix imports
balazsorban44 Dec 13, 2022
249ebf4
update styles ts
balazsorban44 Dec 13, 2022
2c209d7
update gitignore
balazsorban44 Dec 13, 2022
4582348
update exports field
balazsorban44 Dec 13, 2022
fef8457
revert `next-auth`
balazsorban44 Dec 13, 2022
ced1ca4
remove extra tsconfig files
balazsorban44 Dec 13, 2022
369a27b
remove `private` from package.json
balazsorban44 Dec 13, 2022
df061b9
remove unused file, expose type
balazsorban44 Dec 13, 2022
18b8247
move gitignore, reduce exposed types
balazsorban44 Dec 13, 2022
6c098d7
add back tsconfig files
balazsorban44 Dec 13, 2022
1d1dfb7
remove leftover
balazsorban44 Dec 13, 2022
c2e40f0
Merge branch 'main' into feat/oauth4webapi-balazs
balazsorban44 Dec 13, 2022
34e4471
revert gitignore
balazsorban44 Dec 13, 2022
ef3dbfb
remove test script
balazsorban44 Dec 13, 2022
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ packages/next-auth/utils
packages/next-auth/core
packages/next-auth/jwt
packages/next-auth/react
packages/next-auth/web
packages/next-auth/adapters.d.ts
packages/next-auth/adapters.js
packages/next-auth/index.d.ts
Expand Down
1 change: 1 addition & 0 deletions apps/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"faunadb": "^4",
"next": "13.0.6",
"next-auth": "workspace:*",
"next-auth-core": "workspace:*",
"nodemailer": "^6",
"react": "^18",
"react-dom": "^18"
Expand Down
127 changes: 77 additions & 50 deletions apps/dev/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import NextAuth, { type NextAuthOptions } from "next-auth"
import { AuthHandler, AuthOptions } from "next-auth-core"

// Providers
import Apple from "next-auth/providers/apple"
import Auth0 from "next-auth/providers/auth0"
import AzureAD from "next-auth/providers/azure-ad"
import AzureB2C from "next-auth/providers/azure-ad-b2c"
import BoxyHQSAML from "next-auth/providers/boxyhq-saml"
import Cognito from "next-auth/providers/cognito"
import Credentials from "next-auth/providers/credentials"
import Discord from "next-auth/providers/discord"
import DuendeIDS6 from "next-auth/providers/duende-identity-server6"
import Email from "next-auth/providers/email"
import Facebook from "next-auth/providers/facebook"
import Foursquare from "next-auth/providers/foursquare"
import Freshbooks from "next-auth/providers/freshbooks"
import GitHub from "next-auth/providers/github"
import Gitlab from "next-auth/providers/gitlab"
import Google from "next-auth/providers/google"
import IDS4 from "next-auth/providers/identity-server4"
import Instagram from "next-auth/providers/instagram"
import Keycloak from "next-auth/providers/keycloak"
import Line from "next-auth/providers/line"
import LinkedIn from "next-auth/providers/linkedin"
import Mailchimp from "next-auth/providers/mailchimp"
import Okta from "next-auth/providers/okta"
import Osu from "next-auth/providers/osu"
import Patreon from "next-auth/providers/patreon"
import Slack from "next-auth/providers/slack"
import Spotify from "next-auth/providers/spotify"
import Trakt from "next-auth/providers/trakt"
import Twitch from "next-auth/providers/twitch"
import Twitter, { TwitterLegacy } from "next-auth/providers/twitter"
import Vk from "next-auth/providers/vk"
import Wikimedia from "next-auth/providers/wikimedia"
import WorkOS from "next-auth/providers/workos"
import Apple from "next-auth-core/providers/apple"
import Auth0 from "next-auth-core/providers/auth0"
import AzureAD from "next-auth-core/providers/azure-ad"
import AzureB2C from "next-auth-core/providers/azure-ad-b2c"
import BoxyHQSAML from "next-auth-core/providers/boxyhq-saml"
// import Cognito from "next-auth-core/providers/cognito"
import Credentials from "next-auth-core/providers/credentials"
import Discord from "next-auth-core/providers/discord"
import DuendeIDS6 from "next-auth-core/providers/duende-identity-server6"
// import Email from "next-auth-core/providers/email"
import Facebook from "next-auth-core/providers/facebook"
import Foursquare from "next-auth-core/providers/foursquare"
import Freshbooks from "next-auth-core/providers/freshbooks"
import GitHub from "next-auth-core/providers/github"
import Gitlab from "next-auth-core/providers/gitlab"
import Google from "next-auth-core/providers/google"
// import IDS4 from "next-auth-core/providers/identity-server4"
import Instagram from "next-auth-core/providers/instagram"
// import Keycloak from "next-auth-core/providers/keycloak"
import Line from "next-auth-core/providers/line"
import LinkedIn from "next-auth-core/providers/linkedin"
import Mailchimp from "next-auth-core/providers/mailchimp"
// import Okta from "next-auth-core/providers/okta"
import Osu from "next-auth-core/providers/osu"
import Patreon from "next-auth-core/providers/patreon"
import Slack from "next-auth-core/providers/slack"
import Spotify from "next-auth-core/providers/spotify"
import Trakt from "next-auth-core/providers/trakt"
import Twitch from "next-auth-core/providers/twitch"
import Twitter from "next-auth-core/providers/twitter"
import Vk from "next-auth-core/providers/vk"
import Wikimedia from "next-auth-core/providers/wikimedia"
import WorkOS from "next-auth-core/providers/workos"

// // Prisma
// import { PrismaClient } from "@prisma/client"
Expand Down Expand Up @@ -66,9 +66,9 @@ import WorkOS from "next-auth/providers/workos"
// secret: process.env.SUPABASE_SERVICE_ROLE_KEY,
// })

export const authOptions: NextAuthOptions = {
export const authOptions: AuthOptions = {
// adapter,
debug: process.env.NODE_ENV !== "production",
// debug: process.env.NODE_ENV !== "production",
theme: {
logo: "https://next-auth.js.org/img/logo/logo-sm.png",
brandColor: "#1786fb",
Expand All @@ -78,15 +78,19 @@ export const authOptions: NextAuthOptions = {
credentials: { password: { label: "Password", type: "password" } },
async authorize(credentials) {
if (credentials.password !== "pw") return null
return { name: "Fill Murray", email: "bill@fillmurray.com", image: "https://www.fillmurray.com/64/64" }
return { name: "Fill Murray", email: "bill@fillmurray.com", image: "https://www.fillmurray.com/64/64", id: "1", foo: "" }
},
}),
Apple({ clientId: process.env.APPLE_ID, clientSecret: process.env.APPLE_SECRET }),
Auth0({ clientId: process.env.AUTH0_ID, clientSecret: process.env.AUTH0_SECRET, issuer: process.env.AUTH0_ISSUER }),
AzureAD({ clientId: process.env.AZURE_AD_CLIENT_ID, clientSecret: process.env.AZURE_AD_CLIENT_SECRET, tenantId: process.env.AZURE_AD_TENANT_ID }),
AzureAD({
clientId: process.env.AZURE_AD_CLIENT_ID,
clientSecret: process.env.AZURE_AD_CLIENT_SECRET,
tenantId: process.env.AZURE_AD_TENANT_ID,
}),
AzureB2C({ clientId: process.env.AZURE_B2C_ID, clientSecret: process.env.AZURE_B2C_SECRET, issuer: process.env.AZURE_B2C_ISSUER }),
BoxyHQSAML({ issuer: "https://jackson-demo.boxyhq.com", clientId: "tenant=boxyhq.com&product=saml-demo.boxyhq.com", clientSecret: "dummy" }),
Cognito({ clientId: process.env.COGNITO_ID, clientSecret: process.env.COGNITO_SECRET, issuer: process.env.COGNITO_ISSUER }),
// Cognito({ clientId: process.env.COGNITO_ID, clientSecret: process.env.COGNITO_SECRET, issuer: process.env.COGNITO_ISSUER }),
Discord({ clientId: process.env.DISCORD_ID, clientSecret: process.env.DISCORD_SECRET }),
DuendeIDS6({ clientId: "interactive.confidential", clientSecret: "secret", issuer: "https://demo.duendesoftware.com" }),
Facebook({ clientId: process.env.FACEBOOK_ID, clientSecret: process.env.FACEBOOK_SECRET }),
Expand All @@ -95,33 +99,56 @@ export const authOptions: NextAuthOptions = {
GitHub({ clientId: process.env.GITHUB_ID, clientSecret: process.env.GITHUB_SECRET }),
Gitlab({ clientId: process.env.GITLAB_ID, clientSecret: process.env.GITLAB_SECRET }),
Google({ clientId: process.env.GOOGLE_ID, clientSecret: process.env.GOOGLE_SECRET }),
IDS4({ clientId: process.env.IDS4_ID, clientSecret: process.env.IDS4_SECRET, issuer: process.env.IDS4_ISSUER }),
// IDS4({ clientId: process.env.IDS4_ID, clientSecret: process.env.IDS4_SECRET, issuer: process.env.IDS4_ISSUER }),
Instagram({ clientId: process.env.INSTAGRAM_ID, clientSecret: process.env.INSTAGRAM_SECRET }),
Keycloak({ clientId: process.env.KEYCLOAK_ID, clientSecret: process.env.KEYCLOAK_SECRET, issuer: process.env.KEYCLOAK_ISSUER }),
// Keycloak({ clientId: process.env.KEYCLOAK_ID, clientSecret: process.env.KEYCLOAK_SECRET, issuer: process.env.KEYCLOAK_ISSUER }),
Line({ clientId: process.env.LINE_ID, clientSecret: process.env.LINE_SECRET }),
LinkedIn({ clientId: process.env.LINKEDIN_ID, clientSecret: process.env.LINKEDIN_SECRET }),
Mailchimp({ clientId: process.env.MAILCHIMP_ID, clientSecret: process.env.MAILCHIMP_SECRET }),
Okta({ clientId: process.env.OKTA_ID, clientSecret: process.env.OKTA_SECRET, issuer: process.env.OKTA_ISSUER }),
// Okta({ clientId: process.env.OKTA_ID, clientSecret: process.env.OKTA_SECRET, issuer: process.env.OKTA_ISSUER }),
Osu({ clientId: process.env.OSU_CLIENT_ID, clientSecret: process.env.OSU_CLIENT_SECRET }),
Patreon({ clientId: process.env.PATREON_ID, clientSecret: process.env.PATREON_SECRET }),
Slack({ clientId: process.env.SLACK_ID, clientSecret: process.env.SLACK_SECRET }),
Spotify({ clientId: process.env.SPOTIFY_ID, clientSecret: process.env.SPOTIFY_SECRET }),
Trakt({ clientId: process.env.TRAKT_ID, clientSecret: process.env.TRAKT_SECRET }),
Twitch({ clientId: process.env.TWITCH_ID, clientSecret: process.env.TWITCH_SECRET }),
Twitter({ version: "2.0", clientId: process.env.TWITTER_ID, clientSecret: process.env.TWITTER_SECRET }),
TwitterLegacy({ clientId: process.env.TWITTER_LEGACY_ID, clientSecret: process.env.TWITTER_LEGACY_SECRET }),
Twitter({ clientId: process.env.TWITTER_ID, clientSecret: process.env.TWITTER_SECRET }),
// TwitterLegacy({ clientId: process.env.TWITTER_LEGACY_ID, clientSecret: process.env.TWITTER_LEGACY_SECRET }),
Vk({ clientId: process.env.VK_ID, clientSecret: process.env.VK_SECRET }),
Wikimedia({ clientId: process.env.WIKIMEDIA_ID, clientSecret: process.env.WIKIMEDIA_SECRET }),
WorkOS({ clientId: process.env.WORKOS_ID, clientSecret: process.env.WORKOS_SECRET }),
],
}

if (authOptions.adapter) {
authOptions.providers.unshift(
// NOTE: You can start a fake e-mail server with `pnpm email`
// and then go to `http://localhost:1080` in the browser
Email({ server: "smtp://127.0.0.1:1025?tls.rejectUnauthorized=false" })
)
// TODO:
// authOptions.providers.unshift(
// // NOTE: You can start a fake e-mail server with `pnpm email`
// // and then go to `http://localhost:1080` in the browser
// Email({ server: "smtp://127.0.0.1:1025?tls.rejectUnauthorized=false" })
// )
}

// TODO: move to next-auth/edge
function Auth(...args: any[]) {
const envSecret = process.env.AUTH_SECRET ?? process.env.NEXTAUTH_SECRET
const envTrustHost = !!(process.env.NEXTAUTH_URL ?? process.env.AUTH_TRUST_HOST ?? process.env.VERCEL ?? process.env.NODE_ENV !== "production")
if (args.length === 1) {
return async (req: Request) => {
args[0].secret ??= envSecret
args[0].trustHost ??= envTrustHost
return await AuthHandler(req, args[0])
}
}
args[1].secret ??= envSecret
args[1].trustHost ??= envTrustHost
return AuthHandler(args[0], args[1])
}

// export default Auth(authOptions)

export default function handle(request: Request) {
return Auth(request, authOptions)
}

export default NextAuth(authOptions)
export const config = { runtime: "experimental-edge" }
5 changes: 5 additions & 0 deletions packages/core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
adapters.*
index.*
jwt
lib
providers
77 changes: 77 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"name": "next-auth-core",
"private": true,
"version": "0.0.1",
"description": "Authentication for the web.",
"homepage": "https://next-auth.js.org",
"repository": "https://github.com/nextauthjs/next-auth.git",
"author": "Balázs Orbán <info@balazsorban.com>",
"contributors": [
"Balázs Orbán <info@balazsorban.com>",
"Nico Domino <yo@ndo.dev>",
"Lluis Agusti <hi@llu.lu>",
"Thang Huu Vu <thvu@hey.com>",
"Iain Collins <me@iaincollins.com"
],
"type": "module",
"types": "./index.d.ts",
"files": [
"adapters.*",
"index.*",
"jwt",
"lib",
"providers",
"src"
],
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js"
},
"./adapters": {
"types": "./adapters.d.ts"
},
"./jwt": {
"types": "./jwt/index.d.ts",
"import": "./jwt/index.js"
},
"./providers/*": {
"types": "./providers/*.d.ts",
"import": "./providers/*.js"
}
},
"license": "ISC",
"dependencies": {
"@panva/hkdf": "1.0.2",
"cookie": "0.5.0",
"jose": "4.11.1",
"oauth4webapi": "2.0.4",
"preact": "10.11.3",
"preact-render-to-string": "5.2.3"
},
"peerDependencies": {
"nodemailer": "6.8.0"
},
"peerDependenciesMeta": {
"nodemailer": {
"optional": true
}
},
"scripts": {
"build": "pnpm clean && tsc && pnpm css",
"clean": "rm -rf adapters.* index.* jwt lib providers",
"css": "node ./scripts/generate-css.js",
"dev": "pnpm css && tsc -w",
"test": "jest"
},
"devDependencies": {
"@next-auth/tsconfig": "workspace:*",
"@types/node": "18.11.10",
"@types/nodemailer": "6.4.6",
"@types/react": "18.0.26",
"autoprefixer": "10.4.13",
"cssnano": "5.1.14",
"postcss": "8.4.19",
"postcss-nested": "6.0.0"
}
}
22 changes: 22 additions & 0 deletions packages/core/scripts/generate-css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import fs from "fs"
import path from "path"
import postcss from "postcss"

import autoprefixer from "autoprefixer"
import postCssNested from "postcss-nested"
import cssNano from "cssnano"

const from = path.join(process.cwd(), "src/lib/styles/index.css")
const css = fs.readFileSync(from)

const processedCss = await postcss([
autoprefixer,
postCssNested,
cssNano({ preset: "default" }),
]).process(css, { from })

fs.writeFileSync(
path.join(process.cwd(), "src/lib/styles/index.ts"),
`export default \`${processedCss.css}\`
// Generated by \`pnpm css\``
)
Loading