120 Commits

Author SHA1 Message Date
Jack Hsu
147d0e1345
chore(js): bump some v21 removal to v22 (#30911)
This PR bumps two v21 removals to v22:
1. SWC inline feature -- some people still use it even though it's
experimental. We should rethink how to remove this.
2. Cypress component testing not relying on `@nx/webpack:webpack`
executor -- we need a separate `webpack.cy.config.js` that only
configures the plugins needed Cypress CT.

This PR also keeps the Webpack plugin exports of `@nx/react` and
`@nx/webpack` packages. The `convert-to-inferred` and app generators
have been using the `@nx/react/webpack-plugin` and
`@nx/webpack/app-plugin` already for a while, there's no harm to keep
the exports in the index for older projects if they haven't been
updated.
2025-04-29 09:58:06 -04:00
Jack Hsu
9234fb30a6
feat(react): undeprecate svgr option for Next.js apps since --turbo supports it (#30909)
This PR delays deprecation of `svgr` for `@nx/next`, as Turbopack
supports it now.

This PR also deprecates all SVGR support for v22. It is not a well-used
feature, and the webpack plugin is not maintained. We'll ensure in v22
to add the SVGR webpack plugin to userland configs, but we'll not
maintain it ourselves moving forward.

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2025-04-29 08:44:21 -04:00
Colum Ferry
27b78cd7ae
fix(webpack): migrate to latest version to prevent security vulnerabilities #29755 (#30590)
## Current Behavior
The `@nx/webpack` depends on `webpack` at version `^5.80.0`. Despite the
`^` allowing it to resolve to a higher minor, there has been no
migration to force users onto a higher version.
There is a security vulnerability with version `5.88.0`.

## Expected Behavior
Ensure users are migrated to a version where the security vulnerability
has been fixed.

## Related Issue(s)

Fixes #29755
2025-04-02 12:32:24 -04:00
Jack Hsu
90c0c8ebf6
fix(react): transpile SVGR into React 19 compatible component (#29543)
This PR fixes an issue with React 19 and our `@nx/react/plugins/jest`
transform. The current transform uses an unsupported `$$typeof` symbol,
and also uses the deprecated `forwardRef` API.

The updated transform will use new API for React 19 and older, while
maintaining the previous API for React 18 and earlier. The backwards
compatibility may be needed if the test is using `ref`, which requires
`forwardRef` older versions.

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
SVGR fails in Jest tests with React 19

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
SVGR works

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2025-01-07 18:26:02 -05:00
Nigel Sirisomphone
e4939fa3ee
fix(react): assert test property is defined on webpack rule in nx-react-webpack-plugin (#27525)
The `removeSvgLoaderIfPresent` method in `apply-react-config.ts`
iterates through each Webpack rule, calls `toString` on each `test`
property, and checks for the presence of the string `"svg"` to see if
any existing SVG plugins need to be removed.

Some of the Webpack rules in the config don't have the test property,
and calling `toString` without asserting the test property is defined
first throws type errors.

This commit introduces a very small change that simply asserts that
`rule.test` is not `undefined` before calling `.toString()`.

## Current Behavior
Running a React Webpack library with `svgr` enabled causes compilation
errors.

<img width="1171" alt="Screenshot 2024-08-20 at 10 36 09 AM"
src="https://github.com/user-attachments/assets/cb28d1ca-10d2-4d20-aa78-e69339a8273b">

<img width="487" alt="Screenshot 2024-08-20 at 10 39 28 AM"
src="https://github.com/user-attachments/assets/c170e0d8-8674-43b0-97a3-a5dffd398c17">

## Expected Behavior
Enabling SVGR in the `NxReactWebpackPlugin` config should compile as
normal.

---------

Co-authored-by: Colum Ferry <cferry09@gmail.com>
2024-12-11 10:40:21 +00:00
Jack Hsu
6c5916a79f
feat(rollup): use .cjs file extension for config files (#29196)
The `rollup.config.js` file will be resolved as ESM if the closest
`package.json` has `type: 'module`. This causes an error when computing
the project graph and when reading the file for builds.

```
  Original error: require is not defined in ES module scope, you can use import instead
```

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

This PR also updates the output directory to `{projectRoot}/dist` for
the new TS setup.

## Current Behavior
`nx g @nx/react:lib --bundler=rollup` has an error due to Node
resolution

## Expected Behavior
`nx g @nx/react:lib --bundler=rollup` works out of the box

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #29193, #[29195](https://github.com/nrwl/nx/issues/29195)

---------

Co-authored-by: Leosvel Pérez Espinosa <leosvel.perez.espinosa@gmail.com>
2024-12-04 12:53:42 -05:00
Jack Hsu
81892b51fd
feat(misc)!: handle v20 deprecations in plugins (#28222)
This PR removes these from v20 since they were deprecated and slated for
removal:

- `executeWebpackDevServerBuilder` export from `@nx/angular/executors`,
users should use `executeDevServerBuilder`
- `withStylus` util from `@nx/next/plugins/with-stylus` since it was
deprecated in v17 and has just throw an error that users need to use
SASS with Next.js

The `getRollupOptions` function from `@nx/react/plugins/bundle-rollup`
has been deprecated as mention previously and slated for removal in v22.
New users are using inferred targets from Rollup, and existing projects
using this module should run `nx g @nx/rollup:convert-to-inferred` or
manually update rollup config to use `withNx` function.

Also, bumped some deprecation for later in v21:

- Remove inline builds from tsc/swc 
- Changes to SVGR to align with Webpack v5 (e.g. `import ReactComponent
from './img.svg?svgr'`)
- Remove `isolatedConfig` from Webpack executor -- requires a migration
that extracts to a standard webpack config just in case (different from
the original one that extracts to `withNx`)

The ESLint TODOs were rescoped to `TODO(eslint)` and we'll look at it in
further flat config work rather than tying it to an Nx release.

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-10-02 15:29:31 -04:00
Jack Hsu
f221a41dbd
feat(misc): remove @nrwl/ scoped packages (#27858)
This PR removes the `@nrwl/*` packages. Also cleans up references to the
legacy packages.

NOTE: The rescope page is now under `/deprecated/rescope`. There is
still >1000K monthly traffic to it, which might be due to older Nx
users.

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-09-27 17:19:01 -04:00
Jack Hsu
8804f12450
feat(bundling): add convert-to-inferred generator for @nx/rollup (#26280)
This PR adds `@nx/rollup:convert-to-inferred` generator.


## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-06-13 13:52:55 -04:00
Zoran Kokeza
14eb8de800
fix(react): disable react refresh overlay (#22013)
## Current Behavior
Currently when a user runs into a compile/runtime error in react
application 2 error overlays will show. One from react-refresh-plugin
and the second one from webpack-dev-server (which is enabled by default)

![image](https://github.com/nrwl/nx/assets/19208948/c6be47bc-3ffd-4148-bdc6-18b59affae7f)

![image](https://github.com/nrwl/nx/assets/19208948/65ebe2a4-ed47-4feb-b289-645f3e2303cc)

### Steps to reproduce

This is reproducible using both webpack config types when the react
refresh plugin is applied to the configuration.
1. create fresh nx react app with webpack
2. add `hot: true`in webpack dev server configuration, so
react-refresh-plugin gets applied
3. anywhere in the app code throw an error i.e.
```
useEffect(() => {
  setTimeout(() => {
    throw new Error('test');
  }, 1000);
}, []);
```
4. observe 2 error overlays shown
Or clone the repo https://github.com/zoran995/nx-react-error-overlay,
branch main is using nx enhanced config, branch default-config is using
plain webpack config. Here is also a codesandbox showcasing an issue
https://codesandbox.io/p/github/zoran995/nx-react-error-overlay/main?file=%2Fapps%2Forg%2Fsrc%2Fapp%2Fapp.tsx&import=true

## Expected Behavior
Only one error should be shown to the user, and this is the actual
configuration of the plugin that is used by react scripts. I went with
not exposing another config option for nx react webpack plugin as there
is already an option to configure webpack dev server error overlay and
most of the react community is used to have the react-refresh one
disabled.
2024-05-29 09:20:37 -06:00
Nicholas Cunningham
9cd0b420d1
feat(react): Add SvgOptions for NxReactWebpackPlugin and WithNx (#23283)
This PR adds the ability to now override our svg options by providing
them either using `NxReactWebpackPlugin` for react apps or `withNx` for
Next.js apps

```
new NxReactWebpackPlugin({
  svgr: {
    svgo: true,
    titleProp: true,
    ref: true,
  }
}),
  ```

This now gives you control on customizing how the svg is handled. Should you need to enable svgo you can provide the config using `svgr.config.js`

https://react-svgr.com/docs/options/#svgo

closes: #9487
2024-05-13 08:15:44 -06:00
Jack Hsu
2e621f324c
feat(misc): v19 cleanup for Nx plugins (#23104)
This PR removes deprecated code that's been slated for removal in Nx 19
- mentioned as `TODO(v19)` comments.

## Breaking Changes

- **CNW:** `create-nx-workspace` no longer support `--preset=empty` and
`--preset=core`, use `--preset=apps` and `--preset=npm` respectively.
Deprecated in Nx 15.9.
- **Next.js:** `NX_` environment variables are no longer bundled into
Next.js apps, use `NEXT_PUBLIC` instead. Deprecated in Nx 16.8.
- **Webpack, Storybook, Esbuild:** `NX_` environment variables are no
longer bundled into browser bundles, use `NX_PUBLIC` instead. This
removes the possibility of intentional bundling of `NX_` variables.
Deprecated in Nx 18.
- **Cypress:** `cypressComponentConfiguration` generator removed from
`@nx/cypress`, use `configurationGenerator`instead. Deprecated in Nx
16.8.
- **Cypress:** `cypressProjectGenerator` generator removed from
`@nx/cypress`, use `configurationGenerator` instead. Deprecated in Nx
15.9.
- **Expo:** `withNxWebpack` removed from `@nx/expo`, use [metro
bundler](https://docs.expo.dev/guides/customizing-metro/)
(https://docs.expo.dev/guides/customizing-metro/) in app.json instead.
There is a migration to handle this in Nx 19. Deprecated in Nx 15.8.

## Deferred to v20

- **JS:** `classProperties.loose` option removed from `@nx/js/babel`
preset, use `loose` instead. Deprecated in Nx 17.0.
- **ESLint:** Low priority task to "deviations from
@typescript-eslint/recommended" for our lint rules. @JamesHenry will
look at this later before Nx 20, but it is unimportant.
- **React:** component testing does not work with Project Crystal, and
we need the executor + built-in webpack configs to run CT. Will do a
follow-up on this after Nx 19 release. Related issue:
https://github.com/nrwl/nx/issues/21546
- **Next.js:** `withStylus` removal from `@nx/next`, use SASS instead.
It hasn't worked, but we kept the file to throw an error when used.
Deprecated in Nx 17.0.
- **Next.js**: `@nx/next:component` and `@nx/next:page` generators to
not derive the `components` and `app`/`pages` directory. Use `nx g
@nx/next:component apps/myapp/components/button` instead. Deprecated in
Nx 17.0.
- **Webpack:** `isolatedConfig` option removal from
`@nx/webpack:webpack` executor. There is a migration to handle this in
Nx 19. Deprecated in in Nx 17.2.
- **Angular:** `executeWebpackDevServerBuilder` removal from
`@nx/angular/executors`, use `executeDevServerBuilder` instead.
Deprecated in Nx 17.0.
2024-05-02 13:37:12 -04:00
Jack Hsu
5e08b153c9
feat(bundling): upgrade rollup to v4 (#22656) 2024-04-18 22:08:07 -04:00
Jason Jean
bf206e578e
feat(misc): non conflicting init/add flow (#22791) 2024-04-15 16:45:08 -04:00
Jack Hsu
270788e47b
fix(webpack): bring back previous SVG and SVGR behavior for React projects (#22628) 2024-04-02 20:46:41 -04:00
Jack Hsu
b7ffb257a2
fix(bundling): prevent sensitive keys from being bundled (#22413) 2024-03-20 13:01:43 -04:00
Jason Jean
396ffc4636
feat(core): enable project crystal by default (#21403)
Co-authored-by: Katerina Skroumpelou <sk.katherine@gmail.com>
Co-authored-by: Jack Hsu <jack.hsu@gmail.com>
Co-authored-by: Colum Ferry <cferry09@gmail.com>
Co-authored-by: Leosvel Pérez Espinosa <leosvel.perez.espinosa@gmail.com>
Co-authored-by: Emily Xiong <xiongemi@gmail.com>
Co-authored-by: Nicholas Cunningham <ndcunningham@gmail.com>
2024-02-02 03:40:59 -05:00
Craigory Coppola
deb0f1a492
chore(repo): bump deprecation messages to v19 (#21430) 2024-01-30 16:29:05 -05:00
Jack Hsu
f4569efe0a
fix(react): update default webpack config for component testing (#20749) 2023-12-13 15:02:45 -05:00
Jack Hsu
1cd8b05486
fix(react): webpack backwards compat for @nx/react/plugin/webpack (#20697) 2023-12-11 14:39:59 -05:00
Jack Hsu
507fe42e4f
feat(webpack): add plugin to automatically configure build and serve targets (#20243) 2023-11-28 13:01:03 -05:00
Jack Hsu
395eb70336
feat(webpack): add NxWebpackPlugin that works with normal Webpack configuration (#19984) 2023-11-08 11:03:34 -05:00
Eric Renken
e8b6034b6c
feat(nextjs): can set compiler when setting up nxComponentTestingPreset (#19171) 2023-11-03 17:11:42 +02:00
Katerina Skroumpelou
01847b15c4
fix(react): storybook plugin tsconfig resolution (#19631) 2023-10-16 11:12:32 -04:00
Jack Hsu
8826a7737d
feat(react): remove stylus option from generators (#19441) 2023-10-12 12:49:45 -04:00
Colum Ferry
14643b68b5
feat(react): use TS config files for module federation (#19455) 2023-10-12 11:42:41 -04:00
Craigory Coppola
a18dd48510
chore(react): pass full context to parseTargetString (#19156) 2023-09-20 09:07:21 -04:00
Caleb Ukle
193206ac86
feat(testing): support cypress v13 (#18899) 2023-09-01 11:55:13 -04:00
Ben McCann
38fec9ca77
feat(testing): Vite 5 compatibility for Cypress (#18535) 2023-08-08 14:24:05 -05:00
Caleb Ukle
7d15e0c350
chore(repo): bump webpack version (#17836) 2023-06-28 19:54:38 +00:00
Katerina Skroumpelou
e58cc798a5
feat(storybook): move tsconfig one level up (#17749) 2023-06-26 16:25:52 +03:00
Caleb Ukle
f3f74068ea
fix(testing): update default webpack config for react CT (#17562) 2023-06-21 11:41:33 -04:00
Colum Ferry
99739179c7
chore(react): remove unnecessary type cast (#17689) 2023-06-20 08:50:42 -05:00
Jack Hsu
08339ee49f
feat(js): do not generate root babel.config.json for babel projects (#17289) 2023-06-06 15:45:33 -04:00
Chris McLeod
be267a7cd9
fix(react): do not require webpackConfig for cypress component testing (#16966)
Co-authored-by: Loïc BERTRAND <loic.bert.marcel@gmail.com>
2023-05-16 21:53:09 +00:00
Caleb Ukle
dfd51634f3
fix(testing): prevent ct and e2e generators overwriting configs (#16651) 2023-05-11 12:19:16 -04:00
Caleb Ukle
ebcc4363d0
fix(testing): fix react CT w/ vite and dependant projects (#16475) 2023-04-28 16:40:04 -04:00
Jason Jean
76dfc62412
feat(web): replace usages of @nrwl with @nx (#16376) 2023-04-19 10:59:41 -04:00
Jack Hsu
ced3ab9c59
feat(nextjs): add migration for Next.js 13.3.0 (#16370) 2023-04-18 10:26:23 -04:00
Jason Jean
2d195007b0
feat(core): switch packages to use the @nx scope (#16069) 2023-04-14 19:56:37 -04:00
Jack Hsu
d8f9f32e7a
fix(react): update types for "@nrwl/react/plugins/webpack" for projec… (#15235) 2023-02-24 18:43:29 +02:00
Katerina Skroumpelou
b7fe0a2311
docs(storybook): add titles and descriptions to all docs (#14749) 2023-02-01 17:03:51 +00:00
Jack Hsu
ec28689a80
docs(webpack): add guide for webpack plugins (e.g. withNx, withWeb, etc.) (#14720) 2023-01-31 17:06:32 +00:00
Dan Roujinsky
e92097c5d0
fix(webpack): use webpack-merge for plugins to preserve values, fix React SVG loader (#14695) 2023-01-31 10:09:58 -05:00
Jack Hsu
795e4d6985
fix(webpack): fix support for module federation plugin (#14653) 2023-01-27 14:14:31 +02:00
Jack Hsu
d5332b4e23
feat(webpack): move web-specific options into withWeb plugin (#14590) 2023-01-26 14:17:13 -05:00
Jack Hsu
cd92d102d3
feat(webpack): add isolatedConfig option to skip automatically applying Nx plugins (#14618) 2023-01-26 10:32:34 -05:00
Katerina Skroumpelou
c3de9fdd76
fix(storybook): react plugin sourcemap type (#14600)
Co-authored-by: Bashkim Isai <me@bashkim.com>
2023-01-25 17:43:25 +02:00
Katerina Skroumpelou
61f7a9a85a
fix(react): storybook plugin fixes (#14493) 2023-01-20 08:18:43 -05:00
Jack Hsu
01b42896a2
fix(react): add migration to install @nrwl/webpack if needed by Story… (#14480) 2023-01-19 18:27:36 +00:00