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

chore(auth): Convert @redwoodjs/auth to ESM+CJS dual build #10417

Merged
merged 16 commits into from
Apr 7, 2024

Conversation

Tobbe
Copy link
Member

@Tobbe Tobbe commented Apr 4, 2024

With this PR we now dual-build the @redwoodjs/auth package to output both CJS and ESM.

@redwoodjs/auth is used by @redwoodjs/web, all the auth providers, @redwoodjs/testing and a few more. It could also be used directly by users' apps if, for example, they implement a custom auth provider. So for now we need to provide both ESM and CJS builds of the package.

The most tricky thing here was to get the .js/.cjs/.mjs stuff right. I tried explaining it in comments in build.ts
arethetypeswrong is super helpful
Also see this issue for more info evanw/esbuild#2600

Another valuable discovery here was that isolateModules is required for esbuild. https://esbuild.github.io/content-types/#isolated-modules

@Tobbe Tobbe changed the title chore(auth): Convert to ESM+CJS dual build chore(auth): Convert @redwoodjs/auth to ESM+CJS dual build Apr 4, 2024
@Tobbe Tobbe added release:chore This PR is a chore (means nothing for users) changesets-ok Override the changesets check labels Apr 4, 2024
@Tobbe Tobbe added this to the next-release milestone Apr 4, 2024
Copy link
Contributor

@jtoar jtoar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far, caught two small things. Types are looking good as well:

$ yarn dlx @arethetypeswrong/cli ./redwoodjs-auth.tgz

@redwoodjs/auth v7.0.0

Build tools:
- typescript@5.4.3

👺 Import resolved to an ESM type declaration file, but a CommonJS JavaScript file. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseESM.md


┌───────────────────┬────────────────────────┐
│                   │ "@redwoodjs/auth"      │
├───────────────────┼────────────────────────┤
│ node10            │ 🟢                     │
├───────────────────┼────────────────────────┤
│ node16 (from CJS) │ 👺 Masquerading as ESM │
├───────────────────┼────────────────────────┤
│ node16 (from ESM) │ 🟢 (ESM)               │
├───────────────────┼────────────────────────┤
│ bundler           │ 🟢                     │
└───────────────────┴────────────────────────┘

Some others I'm noticing as I'm reviewing

  • still some files with an .mts extension that could just be a .ts extension (the vite config files namely)

packages/auth/package.json Outdated Show resolved Hide resolved
packages/auth/package.json Outdated Show resolved Hide resolved
packages/auth/package.json Outdated Show resolved Hide resolved
@Tobbe Tobbe merged commit a148f51 into redwoodjs:main Apr 7, 2024
46 checks passed
@Tobbe Tobbe deleted the tobbe-esm-auth branch April 7, 2024 13:42
dac09 added a commit to dac09/redwood that referenced this pull request Apr 9, 2024
…auth-provider-p1

* 'main' of github.com:redwoodjs/redwood:
  fix(middleware): Handle POST requests in middleware router too (redwoodjs#10418)
  chore(ci): get ci running on next (redwoodjs#10432)
  RSC: Explain noExternal vite config option (redwoodjs#10429)
  chore(web): Fix .d.ts overwrite build issue (redwoodjs#10431)
  chore(web): .js imports to prep for ESM (redwoodjs#10430)
  chore(refactor): Split rwjs/forms up into several smaller logical units (redwoodjs#10428)
  chore(rsc): simplify `noExternals` config (redwoodjs#10220)
  chore(deps): Update vite to 5.2.8 (redwoodjs#10427)
  chore(auth): Convert `@redwoodjs/auth` to ESM+CJS dual build (redwoodjs#10417)
  chore(framework-tools): Warn about missing metafile (redwoodjs#10426)
  chore(test): Switch rwjs/auth over to vitest (redwoodjs#10423)
  chore(whatwg-fetch): Switch to importing instead of requiring (redwoodjs#10424)
  chore(deps): bump undici from 5.28.3 to 5.28.4 in /.github/actions/check_changesets (redwoodjs#10421)
  chore(route-manifest): Add relativeFilePath to route manifest (redwoodjs#10416)
dac09 added a commit that referenced this pull request Apr 11, 2024
…th-mw-auth

* 'main' of github.com:redwoodjs/redwood: (21 commits)
  fix(auth): Handle when authorization header is lowercased (#10442)
  Update rbac.md - code match (#10405)
  chore: make crwa e2e test work across branches (#10437)
  feat: [Auth] Common AuthProvider & use* changes for middleware auth (#10420)
  fix(cli): only show webpack options for dev if `bundler = "webpack"` (#10359)
  fix(vercel): specify build env vars as a string (#10436)
  fix(vercel): write `vercel.json` as a part of setup (#10355)
  fix(middleware): Handle POST requests in middleware router too (#10418)
  chore(ci): get ci running on next (#10432)
  RSC: Explain noExternal vite config option (#10429)
  chore(web): Fix .d.ts overwrite build issue (#10431)
  chore(web): .js imports to prep for ESM (#10430)
  chore(refactor): Split rwjs/forms up into several smaller logical units (#10428)
  chore(rsc): simplify `noExternals` config (#10220)
  chore(deps): Update vite to 5.2.8 (#10427)
  chore(auth): Convert `@redwoodjs/auth` to ESM+CJS dual build (#10417)
  chore(framework-tools): Warn about missing metafile (#10426)
  chore(test): Switch rwjs/auth over to vitest (#10423)
  chore(whatwg-fetch): Switch to importing instead of requiring (#10424)
  chore(deps): bump undici from 5.28.3 to 5.28.4 in /.github/actions/check_changesets (#10421)
  ...
Josh-Walker-GM added a commit that referenced this pull request Apr 11, 2024
Co-authored-by: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com>
@Josh-Walker-GM Josh-Walker-GM modified the milestones: next-release, v7.4.0 Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changesets-ok Override the changesets check release:chore This PR is a chore (means nothing for users)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants