34 Commits

Author SHA1 Message Date
Colum Ferry
b97ee099c8
fix(vite): resolve project-specific tsconfig before workspace fallback (#31423)
## Current Behavior

The Nx Vite TsConfig paths plugin incorrectly resolves to workspace root
tsconfig files instead of project-specific ones, causing path aliases
like `@/contexts` to fail resolution.

## Expected Behavior

The plugin should check for project-specific tsconfig files
(`tsconfig.app.json`, `tsconfig.lib.json`, `tsconfig.json`) before
falling back to workspace root configurations.

## Related Issue(s)

Fixes #28945

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Coly010 <Coly010@users.noreply.github.com>
2025-06-03 10:27:44 +01:00
Colum Ferry
985107cac3
fix(vite): ensure nxCopyAssetsPlugin outputs assets to correct location #28786 (#30585)
## Current Behavior
The `nxCopyAssetsPlugin` from `@nx/vite` does not output the asset files
to the correct location.
It prepends the `rootDir` even when the `outDir` in the `vite.config`
resolves to contain the `rootDir`.

## Expected Behavior
Only prepend the `rootDir` when it does not already exist

## Related Issue(s)

Fixes #28786
2025-04-02 13:30:55 +01:00
Colum Ferry
a58b7aba8a
fix(vite): ensure paths with explicit extensions are resolved #29948 (#30202)
## Current Behavior
When TS Path Mappings are combined with an explicit extension of the
build outcome of a file, the `nxViteTsPaths` plugin cannot resolve the
file.

e.g.

```ts

import {something} from '@mylib/file.js';


// tsconfig paths

"@mylib/*": ["mylib/src/*"]
```

In this case, we fallback to the file system to try find the file, and
we do it by adding extensions to the end of the path.

e.g.

```ts
@mylib/file.js.js
@mylib/file.js.ts
@mylib/file.js.mts
etc
```

## Expected Behavior
Perform the usual logic first to try find the file in the file system.

If the file is still not resolved AND the path ends with an `extname`
that we support in `options.extensions`, strip the extension from the
path and try append the different extensions again and resolve against
the filesystem.

This allows for the case where someone has a file in their file system
that _is_ `file.js.js` to be resolve via `@mylib/file.js` as well as
when the explicit path is provided.


## Related Issues

Fixes #29948
2025-02-27 16:27:20 +00:00
Colum Ferry
4fe4fe95fa
fix(vite): allow force ignore of logs from nxViteTsPaths plugin #29320 (#30200)
## Current Behavior
When Vite build is run where:
- `nxViteTsPaths` plugin is enabled
- `--verbose` or `NX_VERBOSE_LOGGING=true` is set

The resulting logs can be quite noisy.

## Expected Behavior
When `debug` is explicitly set to false, ignore logs even when
`--verbose` is passed.

Usage:

```ts
nxViteTsPaths({ debug: false })
```

## Related Issue(s)

Fixes #29320

---------

Co-authored-by: Leosvel Pérez Espinosa <leosvel.perez.espinosa@gmail.com>
2025-02-27 14:53:57 +00:00
Jack Hsu
202b49bdbe
fix(core): re-enable CRA migration to Vite (#30082)
This PR brings back the CRA migration that was missing since Nx 18.

## Current Behavior
<!-- This is the behavior we have today -->
`nx init` does not migrate CRA apps 

## Expected Behavior
`nx init` migrates CRA apps to Vite since CRA is deprecated

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

Fixes #
2025-02-25 14:08:13 -05:00
Colum Ferry
46e5dcefb0
fix(js): use uuid when generating tmp tsconfig (#30118)
## Current Behavior
When multiple processes/tasks are running in parallel for a single
project that produce tmp tsconfig files for buildable libraries, they
can clobber each other.
 

## Expected Behavior
Ensure the config file is generated with a unique id to prevent
clobbering
2025-02-20 15:53:44 -05:00
Nicholas Cunningham
3c0820f707
fix(vite): prevent asset copying when NX_GRAPH_CREATION is enabled (#30037)
This PR includes updates to the `nxCopyAssetsPlugin` function in the
`packages/vite/plugins/nx-copy-assets.plugin.ts` file to improve asset
handling and daemon integration.

The most important changes include adding a check for
`NX_GRAPH_CREATION`.

Additionally, it also contains a check to ensure that before attempting
to watch for file changes the daemon should be available.
2025-02-13 22:01:57 -05:00
Esteban
e2e9e6cb36
fix(vite): fall back to file matching when resolved file does not exist in nx-vite-ts-paths plugin (#29472)
The fallback path resolution was only happening if the resolvedFile was
a falsy value, so it was returning inexistent filepaths.

This pull request includes a small but important change to the
`packages/vite/plugins/nx-tsconfig-paths.plugin.ts` file. The change
improves the reliability of resolving file paths by checking if the
resolved path exists before proceeding with fallback file matching.

*
[`packages/vite/plugins/nx-tsconfig-paths.plugin.ts`](diffhunk://#diff-ad026b24ed45d9df484cabc7e277fc9b4d7759560af36bf357cbc4186725ae0bL174-R176):
Added a check to verify if the resolved file path exists before using
fallback file matching.
* 
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- 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 -->
The resolver doesn't resolve the full file path, it ignores the file
extension. For example, for a path like this:
`import mergeClassNames from '@projects/global/utils/mergeClassNames'`

It resolves to 
`absolutePath.../projects/libs/global/src/utils/mergeClassNames`

When vite is building a project, it doesn't find the file and it errors.

This happens because the resolved file path is not a falsy value, thus,
it doesn't run the fallback file path matching.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
What is expected is that it resolves to (notice the file extension)
`absolutePath.../projects/libs/global/src/utils/mergeClassNames.ts`

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

---------

Co-authored-by: Leosvel Pérez Espinosa <leosvel.perez.espinosa@gmail.com>
2025-01-29 12:01:50 +01:00
Matt Lewis
6948249ac7
fix(vite): tsconfig paths plugin should not partially match paths (#29501)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- 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 -->

When there is a path mapping like:
```
"match-lib-deep/": ["libs/lib1/src/*"],
"match-lib-top-level": ["libs/lib2/src/*"],
"match-lib/*": ["libs/lib3/src/*"],
```

Imports to `match-lib-deep` or `match-lib-top-level` will try and use
the last `match-lib` path mapping as the trailing `/` is not accounted
for in the `startsWith` check.

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

The correct path mapping is matched.

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

N/A
2025-01-07 12:48:57 +01:00
Konstantin Kai
b6d41b617e
fix(vite): resolves files with dot suffixes correctly (#28518)
Use `basename` for retrieving the filename in `findFile` function from
`nx-tsconfig-paths.plugin` that previously led to an unresolved error
for files with dot suffixes e.g.`/dir/file.suffix.ext`

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- 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
For files that have the same name but one of them has a suffix, e.g.
```ts
- lib1
  - file.ts
  - file.i18n.ts
- apps
  - app1
    - main.ts
- tsconfig.base.json // with { "paths": { "@lib1/*": ["lib1/*"] }}
```
The resolving process is incorrect because the `import value from
'@lib1/file.i18n'` from `apps/app1/main.ts` every time resolves to
`file.ts,` and the `parse` method from the `node:path` splits away the
suffix from the name.

## Expected Behavior
`import value from '@lib1/file.i18n'` should work correctly if you
import them from another package

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

Fixes #27852

---------

Co-authored-by: Colum Ferry <cferry09@gmail.com>
2024-12-12 20:08:53 +00:00
Jack Hsu
972c01bd25
feat(storybook): add support for TS solutions file (#29194)
This PR adds support for the [new TS
setup](https://github.com/nrwl/nx/discussions/29099) with Storybook.
2024-12-04 17:44:07 +00:00
Egor Kuzin
7ba7f3e798
fix(vite): tsconfig paths plugin should resolve file with dot in the name (#28701)
closed #28615

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- 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 #28615
2024-11-04 10:00:02 -05:00
MaxKless
499300fd76
fix(core): repair SIGINT signals on windows (#28496)
using `windowsHide: true` is causing an issue on windows: Ctrl + C
handling isn't enabled and no `SIGINT` is sent to the child process when
users exit the process. See https://github.com/nodejs/node/issues/29837
and https://github.com/nodejs/node-v0.x-archive/issues/5054 for
reference. This will cause leftover processes throughout nx.

This PR sets `windowsHide: false` everywhere except for the plugin
workers and some short-lived utils. They `spawn` child processes but
have explicit handling to make sure they kill themselves when the parent
process dies, so the missing Ctrl + C handling doesn't cause issues.

We will follow up to make sure any other culprits that still cause
windows popups (especially when used through Nx Console) are handled.
Leaving no leftover processes running is more important for now, though.

Keep in mind the underlying tooling (like vite) might have some windows
popups themselves that Nx will inherit.
2024-10-17 15:03:37 -04:00
MaxKless
b73f1e0e00
fix(core): set windowsHide: true wherever possible (#28073)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- 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-24 11:31:22 -04:00
Jack Hsu
eb7ac2c57a
fix(vite): tsconfig paths plugin should resolve file extensions (#27774)
This PR updates the tsconfig paths plugin for Vite such that it resolves
paths with file extensions as well.

<!-- 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 #22868
2024-09-04 14:31:25 -04:00
Jack Hsu
ca9f3cce0b
feat(bundling): add nxCopyAssetsPlugin for Vite to use in JS libs (#27593)
This PR adds a `nxCopyAssetsPlugin` for Vite to brings it to parity with
the other compilers/bundlers (tsc, swc, esbuild, rollup, and webpack).

When generate a lib with Vite (e.g.`nx g @nx/js:lib --bundler=vite` or
`nx g @nx/react:lib --bundler=vite`), we expect it to at least copy
`README.md` as an asset.

Note: Vite has support for copying assets from `public/` but that is
less flexible and more intended for apps, not libs.

<!-- 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 #27351
2024-08-22 13:30:40 -04:00
Colum Ferry
795f8479d8
fix(vite): ensure nxViteTsPaths resolve before vite internal resolver (#27155)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- 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 -->
In Yarn and PNPM Workspaces, the `nxViteTsPaths`'s `resolveId` is not
called because Vite has already tried to resolve the module.


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Ensure the `nxViteTsPath`'s logic is run before vite's internal
resolver.

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

Fixes #20520
2024-07-26 16:59:20 +01:00
LongYinan
981eb30a0f
feat(core): support compile to wasi target (#22870)
This pull request is trying to add wasm32-wasi target support for the
nx/native

To test the build, you can run the following commands:

- `rustup target add wasm32-wasip1-threads`
- `pnpm exec napi build --release --platform --package-json-path
packages/nx/package.json --manifest-path packages/nx/Cargo.toml --js
./native-bindings.js -o packages/nx/src/native --target
wasm32-wasip1-threads`

And the wasm file will be built at
packages/nx/src/native/nx.wasm32-wasi.wasm

Blocked by:

- Support @napi-rs/cli 3.0  Cammisuli/monodon#48
- https://github.com/napi-rs/napi-rs/issues/2009

The pseudo_terminal mod is excluded on the wasm32 targets, which is as
expected.

The watch mod is excluded because of the upstream `watchexec` deps
introduced by ignore-files don't support the wasi target at this moment
(but we can improve it).

## Related Issues
Fixes https://github.com/nrwl/nx/issues/21860
Fixes https://github.com/nrwl/nx/issues/23821

---------

Co-authored-by: FrozenPandaz <jasonjean1993@gmail.com>
2024-07-05 15:55:35 -04:00
Colum Ferry
b42b6f7dbe
fix(vite): incremental builds tmp tsconfig should have baseUrl set to workspace root (#26680)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- 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 -->
When nxViteTsPaths resolves the tmp tsconfig we create for the buildable
libs, it uses the absoluteBaseUrl of the tsconfig to when creating the
ESM matcher for resolving files.
There is no baseUrl set, therefore the absoluteBaseUrl becomes the
directory of the tmp tsconfig
This means the paths to the built artifacts are incorrect


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Use the workspace root, which lines up with the output locations for
built artifacts, for the baseUrl for the tmp tsconfig


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

Fixes #
2024-06-25 18:15:23 +01:00
Colum Ferry
44565262a6
fix(vite): nxViteTsPaths plugin should not run-many for vitest (#26574)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- 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 -->
`nxViteTsPaths` does not check if the mode is test and only filters the
`run-many` command based on whether Vite's config.command === serve.

Vitest will set `config.command` to serve, even for `test` targets.
It does set `mode = test` however.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
When `mode === test`, we do not invoke `nx run-many`

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

Fixes #
2024-06-17 06:52:28 -07:00
Colum Ferry
64c6287b83
feat(vite): support incremental builds with nxViteTsPaths (#23908)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->
We do not support incremental builds with vite when using inference
plugin


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Support incremental builds with vite when using inference plugin

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

Fixes #
2024-05-22 16:30:53 +01:00
Matthias Stemmler
b4f6e425c4
fix(vite): get tsconfig from new path including target (#22775)
## Current Behavior
Since v18.2.3 (e4c4697f69cf29c50aced1997715a7da5f680e23) the
`tsconfig.generated.json` file generated if `"buildLibsFromSource":
false` is placed under a path containing the current build target. The
`nx-tsconfig-paths` plugin of `@nx/vite` was not updated accordingly, so
now it doesn't find `tsconfig.generated.json`, effectively causing
`@nx/vite` to ignore the `"buildLibsFromSource": false` setting.

## Expected Behavior
With this PR, `nx-tsconfig-paths` finds `tsconfig.generated.json` at the
correct path, so `"buildLibsFromSource": false` works as it did before
v18.2.3.
2024-05-08 12:30:07 +01:00
Ian Chadwick
9a9bd2abd3
fix(vite): deep file resolution in nx-tsconfig-paths.plugin.ts (#21513) 2024-02-02 18:33:50 +02:00
Jan Pretzel
82a0d613d2
fix(bundling): consider index/folder imports in manual file resolution (#19030) 2024-01-30 19:24:51 +02:00
Katerina Skroumpelou
7da53c026e
fix(vite): replaceFile and fileReplacement fixes (#21077) 2024-01-10 18:53:34 +02:00
Katerina Skroumpelou
2c88282e8a
fix(vite): adjust config generation (#20367) 2023-11-29 15:58:49 +02:00
Caleb Ukle
e3b513b6c0
fix(bundling): fallback to manual file resolution if tsconfig-paths fails (#18477) 2023-08-25 11:18:05 -05:00
Caleb Ukle
6529be96cf
feat(vite): add tsconfig paths resolution plugin (#17844) 2023-07-17 15:42:12 +00:00
Katerina Skroumpelou
ac3804983b
cleanup(vite): remove unnecessary import (#14544) 2023-01-23 16:55:31 +02:00
Katerina Skroumpelou
53cffacf6b
Revert "fix(vite): Support fileReplacements for devServer" (#14104) 2023-01-03 13:26:10 +02:00
nodegin
b3ff11f5d9
fix(vite): Support fileReplacements for devServer (#13761)
Co-authored-by: ⁢ <john@doe.gov>
2022-12-13 12:11:29 +02:00
Katerina Skroumpelou
6fcb9c4dba
chore(bundling): added tests for fileReplacement (#13292) 2022-11-22 09:36:07 +00:00
Katerina Skroumpelou
e4092aa47f
fix(bundling): file replacement for vite (#13255) 2022-11-18 15:24:33 +00:00
Katerina Skroumpelou
8d103f323c
feat(bundling): vite plugin executors (#13032) 2022-11-14 14:33:09 -05:00