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

OAuth: Reset password & Sign-up #2945

Merged
merged 92 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
87fba04
Add support for reset password
matthieusieben Feb 20, 2025
4a99f11
fix handle validation
matthieusieben Feb 28, 2025
4ce22ba
Update .changeset/tiny-goats-sing.md
matthieusieben Mar 3, 2025
d4b5c08
Merge remote-tracking branch 'origin/main' into msi/oauth-reset-pwd
matthieusieben Mar 3, 2025
8a6c7b1
cleanup
matthieusieben Mar 3, 2025
3e0430e
fix tests
matthieusieben Mar 3, 2025
1d3ceb1
Stringer validation of OauthPRovider config
matthieusieben Mar 3, 2025
05ccd31
fix oauth tests
matthieusieben Mar 3, 2025
770d274
Sign up test
matthieusieben Mar 3, 2025
ab0126d
prettier ignore
matthieusieben Mar 3, 2025
ed954e0
extract strings
matthieusieben Mar 3, 2025
0776ac0
update po files
matthieusieben Mar 3, 2025
ab7c215
add french
matthieusieben Mar 3, 2025
bbe7e93
i18n & a11y improvements
matthieusieben Mar 3, 2025
9fb5636
change sing in btn label
matthieusieben Mar 3, 2025
8a8dd5f
fix build script
matthieusieben Mar 3, 2025
e1cf63d
update pnpm-lock
matthieusieben Mar 3, 2025
e0e5e6f
changeset
matthieusieben Mar 3, 2025
850018c
commens
matthieusieben Mar 3, 2025
288554b
streamline build of frontend
matthieusieben Mar 3, 2025
fd13075
vite based dev server
matthieusieben Mar 3, 2025
569198f
fix lint
matthieusieben Mar 3, 2025
6b44142
move postcss config to universal place
matthieusieben Mar 3, 2025
80357de
improve output of "pnpm dev" by running all dev commands from a singl…
matthieusieben Mar 3, 2025
311faa2
Use smaller logo image
matthieusieben Mar 3, 2025
c9d49b0
Locale selector
matthieusieben Mar 4, 2025
845f9ea
layout fix
matthieusieben Mar 4, 2025
c68c811
docs
matthieusieben Mar 4, 2025
2f17b58
Merge remote-tracking branch 'origin/main' into msi/oauth-reset-pwd
matthieusieben Mar 4, 2025
bc5892e
copy built locales to verify task
matthieusieben Mar 4, 2025
c61d0cd
Force locale during tests
matthieusieben Mar 4, 2025
214c408
typo
matthieusieben Mar 4, 2025
c5153d9
remove debugging params
matthieusieben Mar 4, 2025
588c2a9
fix oauth test flakiness
matthieusieben Mar 4, 2025
3e2f058
close browser after each test
matthieusieben Mar 4, 2025
eefb342
remove birthday input
matthieusieben Mar 4, 2025
e9c12a1
Use SVG for bee-icon + add image source & license
matthieusieben Mar 4, 2025
c48bcda
tidy
matthieusieben Mar 4, 2025
50c6f76
tidy
matthieusieben Mar 4, 2025
43e8e3c
Preload assets
matthieusieben Mar 4, 2025
e152818
tidy
matthieusieben Mar 4, 2025
0ac268a
tidy
matthieusieben Mar 5, 2025
fe7be2a
tidy
matthieusieben Mar 5, 2025
37ecbb3
minor ui improvements
matthieusieben Mar 5, 2025
8c05d2e
Allow translation of links
matthieusieben Mar 5, 2025
4f2dfbd
improve a11y
matthieusieben Mar 5, 2025
d47e2f9
tidy
matthieusieben Mar 5, 2025
895f7eb
Negotiate locale from backend
matthieusieben Mar 5, 2025
178fdac
Improve caching of assets
matthieusieben Mar 5, 2025
a7f67bf
fix a11y issue
matthieusieben Mar 5, 2025
151da97
add reset pwd & remember tests
matthieusieben Mar 5, 2025
bea4e31
properly reflect "email already taken" errors
matthieusieben Mar 5, 2025
283504a
minor margin adaptations
matthieusieben Mar 5, 2025
9435319
typo in strings
matthieusieben Mar 6, 2025
2f28769
Small improvements. Thank you @surfdude29
matthieusieben Mar 6, 2025
2d5e7db
review changes
matthieusieben Mar 6, 2025
595d649
tidy
matthieusieben Mar 6, 2025
51a05eb
tidy
matthieusieben Mar 6, 2025
bed660d
tidy
matthieusieben Mar 6, 2025
3c94e7f
typo
matthieusieben Mar 6, 2025
c6300cc
Send user locale to the backend during oauth operations.
matthieusieben Mar 6, 2025
6bb24a9
typo
matthieusieben Mar 6, 2025
02056d5
docs
matthieusieben Mar 6, 2025
821bb55
import
matthieusieben Mar 6, 2025
2e90348
tidy
matthieusieben Mar 6, 2025
8bdfca6
Do not bundle HCaptcha with main bundle
matthieusieben Mar 6, 2025
f21d604
Admonition component, replace on sign in
estrattonbailey Mar 6, 2025
41a213e
Adjust handle step styles
estrattonbailey Mar 6, 2025
7c763d7
Tweak reset flows
estrattonbailey Mar 6, 2025
a5b5997
Format
estrattonbailey Mar 6, 2025
7e8a901
fix loading
matthieusieben Mar 6, 2025
64c3043
Update strings
matthieusieben Mar 6, 2025
ea9cd83
format
matthieusieben Mar 6, 2025
736a3c7
format
matthieusieben Mar 6, 2025
1e78fa0
minor refactor
matthieusieben Mar 6, 2025
d9fdc5f
fix vite dev
matthieusieben Mar 6, 2025
2909d6c
drop ExpandTransition
matthieusieben Mar 6, 2025
1454cc8
password strength meter fix
matthieusieben Mar 6, 2025
5a90599
Split locale-provider to allow proper HMR
matthieusieben Mar 6, 2025
682f82a
make pwd strength more preogressive
matthieusieben Mar 6, 2025
c5182c0
fix div descendent of p
matthieusieben Mar 6, 2025
0e366ed
Properly support 3 letters locales
matthieusieben Mar 6, 2025
3e6009a
tidy
matthieusieben Mar 6, 2025
c8681f7
wording
matthieusieben Mar 6, 2025
9484f7c
a11y
matthieusieben Mar 6, 2025
0043548
tidy
matthieusieben Mar 6, 2025
f1d184b
missing a11y attr
matthieusieben Mar 6, 2025
c568d4d
tidy
matthieusieben Mar 6, 2025
4c8be13
refactor: remove icon-card (used only once)
matthieusieben Mar 6, 2025
72c5e89
add "below" slot to input container
matthieusieben Mar 6, 2025
2827226
tidy
matthieusieben Mar 6, 2025
6223cdd
changeset
matthieusieben Mar 7, 2025
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
5 changes: 5 additions & 0 deletions .changeset/brave-countries-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Add support for password reset
5 changes: 5 additions & 0 deletions .changeset/eleven-ducks-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto-labs/fetch": patch
---

Improved error response parsing
5 changes: 5 additions & 0 deletions .changeset/hip-feet-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": minor
---

Add support for account sign-up
5 changes: 5 additions & 0 deletions .changeset/hungry-buttons-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-client-browser-example": patch
---

Update react to version 19
7 changes: 7 additions & 0 deletions .changeset/long-bats-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@atproto/oauth-provider": patch
"@atproto/oauth-types": patch
"@atproto/jwk": patch
---

Properly support locales with 3 chars (Asturian)
5 changes: 5 additions & 0 deletions .changeset/rotten-hornets-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Add support for multiple locales
5 changes: 5 additions & 0 deletions .changeset/short-masks-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/syntax": patch
---

Deprecate unused classes
5 changes: 5 additions & 0 deletions .changeset/sour-guests-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto-labs/rollup-plugin-bundle-manifest": patch
---

Improve typing of plugin
5 changes: 5 additions & 0 deletions .changeset/tall-rules-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-client": patch
---

Minor code optimizations
5 changes: 5 additions & 0 deletions .changeset/tiny-goats-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto-labs/fetch": patch
---

Remove explicit dependency on "zod". Improved typing of `fetchJsonZodProcessor` function.
5 changes: 5 additions & 0 deletions .changeset/weak-elephants-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-client-browser-example": patch
---

Build using SWC
5 changes: 5 additions & 0 deletions .changeset/young-parents-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/pds": patch
---

Add support for account sign-ups during OAuth flows
1 change: 1 addition & 0 deletions .github/workflows/repo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
path: |
packages/*/dist
packages/*/*/dist
packages/oauth/oauth-provider/src/assets/app/locales/*/messages.ts
retention-days: 1
test:
name: Test
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
enable-pre-post-scripts = true
include-workspace-root = true
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ packages/api/src/client
packages/bsky/src/lexicon
packages/pds/src/lexicon
packages/ozone/src/lexicon

# Automatically generated by lingui
packages/oauth/oauth-provider/src/assets/app/locales/*/messages.ts
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"consolas",
"dpop",
"googleusercontent",
"hcaptcha",
"hexeditor",
"ingester",
"insertable",
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
"packageManager": "pnpm@8.15.9",
"scripts": {
"lint:fix": "pnpm lint --fix",
"lint": "eslint . --ext .ts,.js",
"lint": "eslint . --ext .ts,.js,.tsx,.jsx",
"style:fix": "prettier --write .",
"style": "prettier --check .",
"verify": "pnpm --stream '/^verify:.+$/'",
"verify:style": "pnpm run style",
"verify:lint": "pnpm lint",
"verify:types": "tsc --build tsconfig.json",
"format": "pnpm lint:fix && pnpm style:fix",
"codegen": "pnpm run --recursive --stream --filter '@atproto/lex-cli...' build --force && pnpm run --recursive --stream --parallel codegen",
"build": "pnpm --recursive --stream build",
"dev": "NODE_ENV=development pnpm --stream '/^dev:.+$/'",
"dev:tsc": "tsc --build tsconfig.json --watch",
"dev:pkg": "pnpm --recursive --parallel --stream dev",
"test": "LOG_ENABLED=false ./packages/dev-infra/with-test-redis-and-db.sh pnpm --stream -r test",
"test:withFlags": "LOG_ENABLED=false ./packages/dev-infra/with-test-redis-and-db.sh pnpm --stream -r test --",
"precodegen": "pnpm run --recursive --stream --filter '@atproto/lex-cli...' build --force",
"codegen": "pnpm run --recursive --stream --parallel codegen",
"build": "pnpm run --recursive --stream '/^(build|build:.+)$/'",
"dev": "NODE_ENV=development pnpm run --recursive --parallel --stream '/^(dev|dev:.+)$/'",
"dev:tsc": "tsc --build tsconfig.json --preserveWatchOutput --watch",
"test": "LOG_ENABLED=false ./packages/dev-infra/with-test-redis-and-db.sh pnpm test --stream --recursive",
"test:withFlags": "pnpm run test --",
"changeset": "changeset",
"release": "pnpm build && changeset publish",
"version-packages": "changeset version && git add ."
Expand Down
15 changes: 11 additions & 4 deletions packages/dev-env/src/pds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export class TestPds {
recoveryDidKey: recoveryKey,
adminPassword: ADMIN_PASSWORD,
jwtSecret: JWT_SECRET,
serviceHandleDomains: ['.test'],
// @NOTE ".example" will not actually work and is only used to display
// multiple domains in the sing-up UI
serviceHandleDomains: ['.test', '.example'],
bskyAppViewUrl: 'https://appview.invalid',
bskyAppViewDid: 'did:example:invalid',
bskyAppViewCdnUrlPattern: 'http://cdn.appview.com/%s/%s/%s',
Expand All @@ -47,10 +49,15 @@ export class TestPds {
inviteRequired: false,
disableSsrfProtection: true,
serviceName: 'Development PDS',
brandColor: '#ffcb1e',
errorColor: undefined,
brandColor: '#8338ec',
errorColor: '#ff006e',
warningColor: '#fb5607',
successColor: '#02c39a',
logoUrl:
'https://uxwing.com/wp-content/themes/uxwing/download/animals-and-birds/bee-icon.png',
// Using a "data:" instead of a real URL to avoid making CORS requests in dev.
// License: https://uxwing.com/license/
// Source: https://uxwing.com/bee-icon/
`data:image/svg+xml;base64,${Buffer.from('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 117.47 122.88"><defs><style>.cls-1,.cls-2{fill-rule:evenodd;}.cls-2{fill:#ffcb1e;}</style></defs><title>bee</title><path class="cls-1" d="M72.69,49.18c5.93.81,12.68,1.76,19.09,3.3,41.08,9.87,25.49,44.79,4.33,40.78A23.57,23.57,0,0,1,83.48,86.2c0,1.23-.12,2.45-.24,3.65a1.47,1.47,0,0,1-.07.72,49.21,49.21,0,0,1-6.78,20.68c-4.49,7.15-10.75,11.63-17.72,11.63S45.4,118.52,40.9,111.46a41.91,41.91,0,0,1-4-8.23l-.06-.18a54.7,54.7,0,0,1-3-17.22,24.75,24.75,0,0,1-13,7.43C.68,97.49-15.49,62.44,25.22,52.48A184,184,0,0,1,44.4,49.16l-.09-.09a9.18,9.18,0,0,1-1.9-2.74,28,28,0,0,1-2.26-10.81,17.15,17.15,0,0,1,5.41-12.45,18.57,18.57,0,0,1,7.78-4.42,19.21,19.21,0,0,0-2.19-7.07A8.05,8.05,0,0,0,47.4,8.13a4.77,4.77,0,1,1,1.38-3.36c0,.22,0,.43,0,.64a11,11,0,0,1,5,4.64,21.82,21.82,0,0,1,2.56,8,20.17,20.17,0,0,1,2.21-.13c.56,0,1.11,0,1.65.07a21.65,21.65,0,0,1,2.66-8.14,10.84,10.84,0,0,1,5.45-4.68c0-.14,0-.28,0-.42A4.77,4.77,0,1,1,69.49,8a7.8,7.8,0,0,0-4.07,3.48,18.73,18.73,0,0,0-2.26,7.06,18.57,18.57,0,0,1,8.31,4.56,17.11,17.11,0,0,1,5.41,12.45,27.65,27.65,0,0,1-2.6,11.38,10,10,0,0,1-1.59,2.28Z"/><path class="cls-2" d="M40.15,103.25a37.55,37.55,0,0,0,3.3,6.59c3.94,6.18,9.33,10,15.22,10s11.22-3.94,15.16-10.21A38.55,38.55,0,0,0,77,103.28q-9.49-5.66-18.7-5.66a33.91,33.91,0,0,0-18.17,5.63Zm31-37.85c-.65-1.51-1.29-3-1.92-4.42-1.84-4.19-3.37-7.81-5.18-12a21.24,21.24,0,0,0-5.76-.9,22,22,0,0,0-5.23.54C51.2,53,49.64,56.67,47.74,61l-1.89,4.36a41.7,41.7,0,0,1,12.58-2.09A37.6,37.6,0,0,1,71.17,65.4ZM69.39,25.26A15.7,15.7,0,0,0,58.52,21a15.89,15.89,0,0,0-3,.28,1.21,1.21,0,0,1-.33.07h0a15.56,15.56,0,0,0-7.47,3.93,14.13,14.13,0,0,0-4.46,10.26,24.67,24.67,0,0,0,2,9.51,6.21,6.21,0,0,0,1.24,1.83,1.43,1.43,0,0,0,1,.47,1.51,1.51,0,0,0,.64-.16,24,24,0,0,1,20.6.37,1.55,1.55,0,0,0,.73.2,1.57,1.57,0,0,0,1-.46,6.41,6.41,0,0,0,1.3-1.78,24.28,24.28,0,0,0,2.25-10,14.17,14.17,0,0,0-4.46-10.26Zm9.38,55c-1.86-2.83-4.59-10.46-7.11-11.45a35.4,35.4,0,0,0-13.21-2.54A40,40,0,0,0,45,68.82c-1.8.66-5.3,9.18-6.78,11.44-1.65,2.51-1.33,1.13-1.36,3.52,0,.12,0,.45,0,1s0,1.32,0,2c.29-.28.59-.55.89-.81C43.56,81,51.53,79.15,59.3,79.48S74.62,82.3,79.69,86.1l.73.58c0-.82.06-3.55.06-4.38,0-.39-.85-.74-1.71-2ZM37.19,90.9a50.67,50.67,0,0,0,1.94,9.42A36.54,36.54,0,0,1,58.32,94.6q9.78,0,19.73,5.78a52,52,0,0,0,2.08-9.86,17.62,17.62,0,0,0-2.26-2c-4.6-3.45-11.55-5.72-18.69-6S44.9,83.86,39.76,88.26a19.46,19.46,0,0,0-2.57,2.64Z"/></svg>', 'utf8').toString('base64')}`,
homeUrl: 'https://bsky.social/',
termsOfServiceUrl: 'https://bsky.social/about/support/tos',
privacyPolicyUrl: 'https://bsky.social/about/support/privacy-policy',
Expand Down
3 changes: 0 additions & 3 deletions packages/internal/fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
"devDependencies": {
"typescript": "^5.6.3"
},
"optionalDependencies": {
"zod": "^3.23.8"
},
"scripts": {
"build": "tsc --build tsconfig.json"
}
Expand Down
50 changes: 35 additions & 15 deletions packages/internal/fetch/src/fetch-response.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { ParseParams, TypeOf, ZodTypeAny } from 'zod'
import { Transformer, pipe } from '@atproto-labs/pipe'
import { FetchError } from './fetch-error.js'
import { TransformedResponse } from './transformed-response.js'
import {
Json,
MaxBytesTransformStream,
cancelBody,
ifObject,
ifString,
logCancellationError,
} from './util.js'
Expand Down Expand Up @@ -69,15 +67,16 @@ const extractResponseMessage: ResponseMessageGetter = async (response) => {
const json: unknown = await response.json()

if (typeof json === 'string') return json
if (typeof json === 'object' && json != null) {
const errorDescription = ifString(json['error_description'])
if (errorDescription) return errorDescription

const errorDescription = ifString(ifObject(json)?.['error_description'])
if (errorDescription) return errorDescription
const error = ifString(json['error'])
if (error) return error

const error = ifString(ifObject(json)?.['error'])
if (error) return error

const message = ifString(ifObject(json)?.['message'])
if (message) return message
const message = ifString(json['message'])
if (message) return message
}
}
} catch {
// noop
Expand Down Expand Up @@ -283,10 +282,31 @@ export function fetchJsonProcessor<T = Json>(
)
}

export function fetchJsonZodProcessor<S extends ZodTypeAny>(
schema: S,
params?: Partial<ParseParams>,
): Transformer<ParsedJsonResponse, TypeOf<S>> {
return async (jsonResponse: ParsedJsonResponse): Promise<TypeOf<S>> =>
schema.parseAsync(jsonResponse.json, params)
export type SyncValidationSchema<S, P = unknown> = {
parse(value: unknown, params?: P): S
}

export type AsyncValidationSchema<S, P = unknown> = {
parseAsync(value: unknown, params?: P): Promise<S>
}

export function fetchJsonValidatorProcessor<S, P = unknown>(
schema: SyncValidationSchema<S, P> | AsyncValidationSchema<S, P>,
params?: P,
): Transformer<ParsedJsonResponse, S> {
if ('parseAsync' in schema && typeof schema.parseAsync === 'function') {
return async (jsonResponse: ParsedJsonResponse): Promise<S> =>
schema.parseAsync(jsonResponse.json, params)
}

if ('parse' in schema && typeof schema.parse === 'function') {
return async (jsonResponse: ParsedJsonResponse): Promise<S> =>
schema.parse(jsonResponse.json, params)
}

// Needed for type safety (and allows fool proofing the usage of this function)
throw new TypeError('Invalid schema')
}

/** @note Use {@link fetchJsonValidatorProcessor} instead */
export const fetchJsonZodProcessor = fetchJsonValidatorProcessor
18 changes: 0 additions & 18 deletions packages/internal/fetch/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@ export function isIp(hostname: string) {
return false
}

const plainObjectProto = Object.prototype
export const ifObject = <V>(v: V) => {
if (typeof v === 'object' && v != null && !Array.isArray(v)) {
const proto = Object.getPrototypeOf(v)
if (proto === null || proto === plainObjectProto) {
// eslint-disable-next-line @typescript-eslint/ban-types
return v as V extends JsonScalar | JsonArray | Function | symbol
? never
: V extends Json
? V
: // Plain object are (mostly) safe to access using a string index
Record<string, unknown>
}
}

return undefined
}

export const ifString = <V>(v: V) => (typeof v === 'string' ? v : undefined)

export class MaxBytesTransformStream extends TransformStream<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function bundleManifest({
}: {
name?: string
data?: boolean
} = {}): Plugin {
} = {}): Plugin<never> {
return {
name: 'bundle-manifest',
generateBundle(outputOptions, bundle) {
Expand Down
2 changes: 1 addition & 1 deletion packages/oauth/jwk/src/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const jwtPayloadSchema = z
.optional(),
locale: z
.string()
.regex(/^[a-z]{2}(-[A-Z]{2})?$/)
.regex(/^[a-z]{2,3}(-[A-Z]{2})?$/)
.optional(),
updated_at: z.number().int().optional(),

Expand Down
13 changes: 6 additions & 7 deletions packages/oauth/oauth-client-browser-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-html": "^1.0.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/react": "^18.2.50",
"@types/react-dom": "^18.2.18",
"@rollup/plugin-swc": "^0.4.0",
"@swc/helpers": "^0.5.15",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"autoprefixer": "^10.4.17",
"postcss": "^8.4.33",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"rollup": "^4.13.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-serve": "^1.1.1",
Expand Down
50 changes: 38 additions & 12 deletions packages/oauth/oauth-client-browser-example/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ const { default: commonjs } = require('@rollup/plugin-commonjs')
const { default: html, makeHtmlAttributes } = require('@rollup/plugin-html')
const { default: json } = require('@rollup/plugin-json')
const { default: nodeResolve } = require('@rollup/plugin-node-resolve')
const { default: replace } = require('@rollup/plugin-replace')
const { default: terser } = require('@rollup/plugin-terser')
const { default: typescript } = require('@rollup/plugin-typescript')
const { default: swc } = require('@rollup/plugin-swc')
const { defineConfig } = require('rollup')
const {
default: manifest,
Expand All @@ -19,7 +17,7 @@ module.exports = defineConfig((commandLineArguments) => {
process.env['NODE_ENV'] ??
(commandLineArguments.watch ? 'development' : 'production')

const minify = NODE_ENV !== 'development'
const devMode = NODE_ENV === 'development'

return {
input: 'src/main.tsx',
Expand All @@ -30,17 +28,46 @@ module.exports = defineConfig((commandLineArguments) => {
format: 'iife',
},
plugins: [
{
name: 'resolve-swc-helpers',
resolveId(src) {
// For some reason, "nodeResolve" doesn't resolve these:
if (src.startsWith('@swc/helpers/')) return require.resolve(src)
},
},
nodeResolve({ preferBuiltins: false, browser: true }),
commonjs(),
json(),
postcss({ config: true, extract: true, minimize: false }),
typescript({
tsconfig: './tsconfig.build.json',
outputToFilesystem: true,
}),
replace({
preventAssignment: true,
values: { 'process.env.NODE_ENV': JSON.stringify(NODE_ENV) },
swc({
swc: {
swcrc: false,
configFile: false,
sourceMaps: true,
minify: !devMode,
jsc: {
minify: {
compress: {
module: true,
unused: true,
},
mangle: true,
},
externalHelpers: true,
target: 'es2020',
parser: { syntax: 'typescript', tsx: true },
transform: {
useDefineForClassFields: true,
react: { runtime: 'automatic' },
optimizer: {
simplify: true,
globals: {
vars: { 'process.env.NODE_ENV': JSON.stringify(NODE_ENV) },
},
},
},
},
},
}),
html({
title: 'OAuth Client Example',
Expand Down Expand Up @@ -79,7 +106,6 @@ module.exports = defineConfig((commandLineArguments) => {
</html>
`,
}),
minify && terser({}),
manifest({ name: 'files.json', data: true }),

commandLineArguments.watch &&
Expand Down
Loading