rsnext/test
Shu Ding 555ff3bcdb
Improved modularizeImports rules (#53051)
This PR adds some improved `modularizeImports` rules to ensure that some
of the popular UI libraries (mostly icons) can be correctly optimized
instead of creating thousands of modules. Here's an example of applying
this to `lucide-react`:

![CleanShot 2023-07-22 at 19 34
15@2x](https://github.com/vercel/next.js/assets/3676859/cf9ef13f-1d5d-4df6-9097-364983ea7b8b)

With https://github.com/swc-project/plugins/pull/196 being landed, we
can add different transform rules for specific names in the import. For
example, for `lucide-react` there're now 3 transforms:
- `'Lucide(.*)': ...`
- `'(.*)Icon': ...`
- `'*': ...`

On top of that, another critical change made in this PR is the
introducing of `modularize-import-loader`. With this new loader, we can
delegate the task of re-exporting the value to Webpack, where we can
adjust the type of the export and the target path. This is very
necessary and can't be done in SWC alone because libs like
`lucide-react` is using `.mjs` and don't have `exports` values for the
individual icons in the package.json files.

Because of that, if we simply transform the expression to `import Icon
from 'lucide-react/esm/icons/foo` it will fail because:
1. It's missing a `.mjs` extension
2. It doesn't have `/esm/icons/foo.mjs` in package.json `exports`

For 1), in fact that they moved to `.mjs` only in a recent upgrade so we
can't even hard code it to be `.mjs` in the transform (breaks old
versions).

Because of all the above, I decided to go with Webpack's own resolution
logic with the loader as a _temporary_ solution. It's temporary because
it's still assuming that the file structure of these libs doesn't
change.
2023-07-27 16:08:25 +02:00
..
.stats-app chore: remove experimental appDir: true from tests (#52291) 2023-07-05 19:17:29 -07:00
__mocks__ [edge] bump @edge-runtime/* package suite (#49092) 2023-05-31 08:03:20 +00:00
development Improved modularizeImports rules (#53051) 2023-07-27 16:08:25 +02:00
e2e Respect fetching logging config and Polish logs format (#52973) 2023-07-27 09:02:42 +00:00
examples feat(cli): introduce --tailwind flag (#46927) 2023-03-16 16:06:27 +01:00
integration Reimplement stream cancellation (#52281) 2023-07-26 12:57:34 -07:00
lib Fix not found hangs the build with overridden node env (#53106) 2023-07-24 21:00:53 +00:00
production Revert "Revert "Separate routing code from render servers (#52492)"" (#53029) 2023-07-21 14:02:52 -07:00
unit fix(edge): allow Request cloning via NextRequest (#53157) 2023-07-25 11:36:39 +00:00
.gitignore ci(workflow): enable test trace upload (#51107) 2023-06-12 17:14:13 +00:00
jest-setup-after-env.ts type check tests (and convert next-test-utils.js to ts) (#51071) 2023-06-23 17:42:50 +00:00
jest.d.ts type check tests (and convert next-test-utils.js to ts) (#51071) 2023-06-23 17:42:50 +00:00
readme.md refactor: split up CONTRIBUTING.md (#40515) 2022-09-16 14:54:58 -07:00
test-file.txt

See Testing for more information on how you can run/write/debug tests for Next.js.