nx icon indicating copy to clipboard operation
nx copied to clipboard

Allow assets to be copied from ignored directories

Open lppedd opened this issue 2 years ago • 2 comments
trafficstars

Description

There are cases where assets to be copied are produced by a built dependency.
An example is a VS Code extension that relies on Angular webviews.

"assets": [
  {
    "input": "dist/my-webviews/",
    "glob": "**/*",
    "output": "dist-webviews"
  }
]

However, looking at the CopyAssetsHandler code, it seems directories listed in .gitignore and .nxignore are blacklisted.

https://github.com/nrwl/nx/blob/13f33eada3cfd183b1fa033878aec8b57ae8294e/packages/js/src/utils/assets/copy-assets-handler.ts#L65-L71

So the copy operation is not performed at all.
In my opinion, assets should not depend on ignored directories, as they are just resources I want to throw around.

Motivation

Avoids creating additional targets (e.g., copy-webviews) that rely on custom code.

Suggested Implementation

An additional option to unrestrict the copying operation.

"assets": [
  {
    "input": "dist/my-webviews/",
    "glob": "**/*",
    "output": "dist-webviews",
    "considerIgnores": false
  }
]

lppedd avatar Nov 17 '23 09:11 lppedd

This is becoming a problem. When using watch configurations (e.g., with tsc), dependent targets are not executed.
This means our custom assets copying tasks don't work.

Consider a custom executor

"build": {
  "executor": "@hcl/nx-assets:assets",
  "options": {
    "copy": [
      {
        "input": "dist/ui/.../webviews",
        "output": "dist/tsc/.../dist-webviews"
      }
    ]
  },
  "cache": false,
  "dependsOn": ["build-extension"] // <--- @nx/js:tsc
}

Once build-extension is executed, if it specifies watch: true, the @hcl/nx-assets:assets executor is never run.

lppedd avatar Aug 28 '24 12:08 lppedd

@FrozenPandaz sorry for pinging you directly.

Just need a clarification: I've found out that in more recent versions of Nx putting a !dist/ in .nxignore to de-ignore the folder seem to solve the issue, however I don't know what the impact of that change would be globally. Any idea?

Edit: in the meantime I've decided to use patch-package.

lppedd avatar Aug 28 '24 12:08 lppedd

This is the patch file I'm using. Also solves a second issue (see in-code comments).

@nx+js+19.6.6.patch

lppedd avatar Sep 13 '24 08:09 lppedd

This should be the default IMHO. I'm not sure I even see the use-case for the existing behaviour. You already need to explicitly define your assets, you should handle exclusions/inclusions right there. I could maybe see the case for adhering to .nxignore, but not .gitignore. Please update so I no longer have to patch every single app/lib install... 😉

danielmahon avatar Mar 06 '25 19:03 danielmahon

This one should be an easy fix, and it looks like the demand exists.
Every now and then a new assets-related issue comes up with this exact problem.

lppedd avatar Mar 12 '25 13:03 lppedd

https://github.com/nrwl/nx/issues/30320#issuecomment-2726051050

messerbill avatar Mar 15 '25 00:03 messerbill

Hey, sorry for the lack of updates here. I understand the motivation and we did in-fact know this ahead of time that some inclusion option would be useful as you see the comment stated it: https://github.com/nrwl/nx/blob/13f33eada3cfd183b1fa033878aec8b57ae8294e/packages/js/src/utils/assets/copy-assets-handler.ts#L64

However, I think the approach we might take would be different than listed here. The copy assets functionality is used by a lot of executors, so it maybe more accurate to separate it into a standalone utility executor moving forward.

I will bring it up and discuss it with the team.

ndcunningham avatar Jul 16 '25 16:07 ndcunningham

Hey @ndcunningham! Thanks for the update. See this comment for the separate executor and why it might not always work.

lppedd avatar Jul 17 '25 10:07 lppedd

It can work, we just need to support --includeDependentProjects as well.

ndcunningham avatar Jul 18 '25 15:07 ndcunningham

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

github-actions[bot] avatar Sep 21 '25 00:09 github-actions[bot]