nx
nx copied to clipboard
Allow assets to be copied from ignored directories
- [ ] I'd be willing to implement this feature (contributing guide)
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
}
]
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.
@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.
This is the patch file I'm using. Also solves a second issue (see in-code comments).
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... 😉
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.
https://github.com/nrwl/nx/issues/30320#issuecomment-2726051050
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.
Hey @ndcunningham! Thanks for the update. See this comment for the separate executor and why it might not always work.
It can work, we just need to support --includeDependentProjects as well.
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.