nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
25.04k stars 3.54k forks source link

chore: optimize packages to reduce bundle size #12063

Closed halvaradop closed 1 month ago

halvaradop commented 1 month ago

☕️ Reasoning

This pull request aims to reduce the bundle size of the @auth/core package. I noticed that the package size is larger than necessary due to the inclusion of .ts files in the build process. These files are compiled into .d.ts, .js, and .d.ts.map files, which already contain the codebase, leading to duplication and increased package size.

While including .ts files can help users understand the code structure when navigating through files, it can also make contributing to the package more cumbersome due to the increased size and clutter in the IDE.

Here are the key points regarding the changes:

Current Bundle Size:

Dry Run Comparison

Now, the difference in size executing pnpm publish --dry-run --no-git-checks is shown in the images below:

Now

dry-run-unoptimized

After

dry-run-optimized

These changes not only improve the size of the package but also enhance the organization of compiled files. Although this pull request primarily focuses on the @auth/core package, the intent is to implement similar optimizations across all packages supported by Auth.js.

I would like to discuss this approach further, as I believe it will benefit contributors and users alike.

[!WARNING] I have noticed that these changes caused some errors, which are expected because the export files are now different from what is expected by other packages. I will be actively working on resolving these issues.

🧢 Checklist

🎫 Affected issues

📌 Resources

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2024 9:52pm
1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **next-auth-docs** | ⬜️ Ignored ([Inspect](https://vercel.com/authjs/next-auth-docs/3X9A2TfFsBhbbpDcvVXfUZfvHYms)) | [Visit Preview](https://next-auth-docs-git-fork-halvaradop-chore-reduce-bundle-authjs.vercel.app) | | Oct 18, 2024 9:52pm |
vercel[bot] commented 1 month ago

@halvaradop is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

socket-security[bot] commented 1 month ago

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@ariakit/react@0.4.13 None +5 4.13 MB ariakit-bot
npm/@aws-sdk/client-dynamodb@3.499.0 Transitive: environment, filesystem, network, shell +53 5.03 MB aws-sdk-bot
npm/@aws-sdk/lib-dynamodb@3.499.0 Transitive: environment, filesystem +10 922 kB aws-sdk-bot
npm/@azure/data-tables@13.2.2 Transitive: environment, network +9 3.17 MB azure-sdk
npm/@balazsorban/monorepo-release@0.5.1 Transitive: environment, filesystem +11 554 kB balazsorban
npm/@builder.io/qwik-city@1.5.5 eval, network +2 2.72 MB adamdbradley
npm/@builder.io/qwik@1.7.3 eval 0 45.6 MB shairez
npm/@cloudflare/workers-types@4.20240117.0 None 0 2.69 MB wrangler-publisher
npm/@eslint/compat@1.1.1 None 0 47.7 kB eslintbot
npm/@eslint/js@9.9.1 None 0 14.2 kB eslintbot
npm/@graphql-codegen/cli@5.0.0 environment, filesystem, network, shell, unsafe +52 10.1 MB dotansimha
npm/@graphql-codegen/client-preset@4.1.0 Transitive: environment, eval, filesystem, shell, unsafe +40 11.8 MB dotansimha
npm/@graphql-typed-document-node/core@3.2.0 None 0 2.96 kB dotansimha
npm/@inkeep/widgets@0.2.289 Transitive: environment, filesystem, network, shell, unsafe +28 22.2 MB sarah-inkeep
npm/@mikro-orm/core@5.9.7 environment, eval, filesystem, unsafe 0 888 kB b4nan
npm/@mikro-orm/sqlite@5.9.7 filesystem +1 354 kB b4nan
npm/@miniflare/d1@2.14.2 filesystem, unsafe Transitive: environment, eval, network, shell +5 460 kB wrangler-publisher
npm/@next/third-parties@14.2.15 None 0 14.2 kB vercel-release-bot
npm/@playwright/test@1.40.0 None 0 25.3 kB dgozman-ms
npm/@preact/preset-vite@2.8.1 Transitive: environment, filesystem, unsafe +35 7.99 MB rschristian
npm/@prettier/plugin-pug@3.0.0 environment 0 349 kB shinigami92
npm/@prisma/client@5.20.0 environment, filesystem, shell 0 9.16 MB prismabot
npm/@prisma/extension-accelerate@1.1.0 None 0 62.8 kB prismabot
npm/@radix-ui/react-accordion@1.2.1 None +13 321 kB chancestrickland
npm/@radix-ui/react-tabs@1.1.1 None +13 303 kB chancestrickland
npm/@simplewebauthn/browser@9.0.1 None 0 42 kB iamkale
npm/@simplewebauthn/server@9.0.3 network +7 1.58 MB iamkale
npm/@simplewebauthn/types@9.0.1 None 0 25.7 kB iamkale
npm/vite@5.3.1 environment, eval, filesystem, network, shell, unsafe 0 3.26 MB vitebot

🚮 Removed packages: npm/@actions/github@6.0.0, npm/@auth/solid-start@0.13.0, npm/@solidjs/meta@0.28.7, npm/@solidjs/router@0.6.0, npm/@types/node@20.11.15, npm/autoprefixer@10.4.20, npm/broken-link-checker@0.7.8, npm/postcss@8.4.44, npm/solid-js@1.8.22, npm/solid-start-node@0.2.32, npm/solid-start-vercel@0.2.32, npm/solid-start@0.2.32, npm/tailwindcss@3.4.10, npm/tsup@8.0.1, npm/tsx@4.7.0, npm/typescript@5.2.2, npm/typescript@5.3.3, npm/vite@3.2.10, npm/zod@3.23.8

View full report↗︎

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 69.07%. Comparing base (a7491dc) to head (3064c8f). Report is 5 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #12063 +/- ## =========================================== + Coverage 39.05% 69.07% +30.01% =========================================== Files 191 136 -55 Lines 29994 7560 -22434 Branches 1288 682 -606 =========================================== - Hits 11715 5222 -6493 + Misses 18279 2338 -15941 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

balazsorban44 commented 1 month ago

Thanks, but this is intentional! Together with the .d.ts.map files, this let's developers jump straight to the real source code from their editor.

See https://www.typescriptlang.org/tsconfig/#declarationMap