6 Commits

Author SHA1 Message Date
Jonathan Gelin
fd31fa633d
fix(js): resolve asset paths relative to workspace root instead of cwd (#31664)
## Description

This PR fixes an issue where asset files copied during a build using the
`@nx/js:tsc` executor are placed in the wrong directory depending on the
current working directory from which the `nx` command is executed.

This behavior becomes particularly problematic in scenarios like release
workflows that rely on `preVersionCommand` to run E2E tests. For
instance, when using tools like Jest from the root of an E2E project,
scripts like `start-local-registry` may trigger a build and run the
`preVersionCommand`. However, instead of placing assets in the expected
`dist` folder of the project, they are incorrectly copied relative to
the E2E folder’s location.


## Reproduction Steps

1. Create a new Nx workspace:

   ```bash
npx --yes create-nx-workspace assets-issue --preset=ts --no-interactive
   cd assets-issue
   ```

2. Add the Nx Plugin package:

   ```bash
   nx add @nx/plugin
   ```

3. Generate a new plugin:

   ```bash
nx g @nx/plugin:plugin packages/my-plugin --linter eslint
--unitTestRunner jest
   ```

4. Add a generator to the plugin:

   ```bash
nx g @nx/plugin:generator packages/my-plugin/src/generators/my-generator
   ```

5. Build the plugin from the workspace root:

   ```bash
   nx build my-plugin
   ```

    Assets are copied correctly:

   ```
   dist/packages/my-plugin/generators/files/src/index.ts.template
   dist/packages/my-plugin/generators/schema.json
   dist/packages/my-plugin/generators/schema.d.ts
   ```

6. Now build the same project from a nested folder:

   ```bash
   mkdir e2e && cd e2e
   nx build my-plugin --skip-nx-cache
   ```

    Assets are copied relative to the current folder:

   ```
   e2e/packages/my-plugin/dist/generators/files/src/index.ts.template
   e2e/packages/my-plugin/dist/generators/schema.json
   e2e/packages/my-plugin/dist/generators/schema.d.ts
   ```

## Expected Behavior

The build output—especially copied assets—should always respect the
project’s `outputPath` configuration regardless of where the `nx`
command is invoked from. The behavior should be consistent and **not
influenced by `process.cwd()`**.
2025-06-23 08:42:59 +02:00
pralkarz
d38bb78f27
cleanup(js): replace fs-extra with node:fs (#27932) 2024-09-17 15:48:42 +04:00
Colum Ferry
61255ce540
fix(js): copy assets handler should correctly handle assets on windows (#23351)
<!-- 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 -->
CopyAssetsHandler was not outputting the assets in the correct location
due to issues with `path/posix`.
`path/posix` is required for some areas of this code, like `minimatch`.


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
`minimatch` ignores should continue to work as expected
assets should be output to the correct location

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

Fixes #
2024-05-13 19:44:53 +01:00
Jason Jean
8fe80a5ea8
chore(js): fix flaky assets test (#19966) 2023-11-01 10:12:52 -04:00
Jonathan Cammisuli
8bfc0b5527
feat(js): use the daemon watcher instead of parcel/watcher (#13413) 2022-11-30 11:09:44 -05:00
Jack Hsu
ed7db7c114
feat(bundling): add esbuild plugin (#12053) 2022-09-20 12:05:58 -04:00