New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
npm copy copy module files and dependencies into a deployable folder
#4082
base: latest
Are you sure you want to change the base?
Conversation
|
What is |
I used fs-extra because I couldn't find whatever fs lib npm preferred I wasn't aware of @npmcli/fs.
|
It's a polyfill. Good examples of how we are using it are in cacache
It's already a subdependency of cacache so adding it to the top shouldn't change much.
Ah ok this would be the gap we'd need to fill in |
Is that something you'll work on or should I start a PR? |
Please start a PR. It's not something we'd be able to get to internally for some time. |
|
Will you be happy with the experimental fs.cp interface? |
|
Yes matching what is likely to land in node itself would be the best option if you went down that path. There's no current implementation of this functionality in npm itself. Arborist effects this by duplicating the tree itself and then reifying it to another destination. This obviously won't work for module files. I believe that if you paired the recursive |
|
I want to wait for more feedback on general implementation before I start working on replacing fs-extra. I think we need a recursive copy. packlist can be replaced with mkdir -p and copy, but copying node_modules dependencies requires recursive copy. Maybe we could use arborist to reify a modified tree, but I would need help. I couldn't tell how to change the root of a tree. |
I need `fs.cp` in `npm copy` to copy node_modules files. I'm adapting node's [lib/internal/fs/cp/cp.js][0]. I'm checking in the original so I can record changes in git. ref npm/cli#4082 [0]: https://github.com/nodejs/node/blob/1fa507f098ca7a89012f76f0c849fa698e73a1a1/lib/internal/fs/cp/cp.js
I need `fs.cp` in `npm copy` to copy node_modules files. I'm adapting node's [lib/internal/fs/cp/cp.js][0]. I'm checking in the original so I can record changes in git. ref npm/cli#4082 [0]: https://github.com/nodejs/node/blob/1fa507f098ca7a89012f76f0c849fa698e73a1a1/lib/internal/fs/cp/cp.js
928384a
to
06e0234
Compare
651dbbd
to
7fc9416
Compare
|
fwiw, |
which i'm just now remembering was you that implemented! |
| } | ||
|
|
||
| async function relativeSymlink (target, path) { | ||
| await fs.mkdir(dirname(path), { recursive: true }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mkdir fails on Windows when the directory already exists, even with recursive: true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've spent more time on this EEXIST issue, and it seems that pushing fs.cp calls inside tasks isn't safe. mkdir operations happen concurrently under the hood multiple times for a same folder, which results in an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can drop parallel tasks and just run sequentially
3fd4909
to
4933c68
Compare
This idea was discussed in npm/rfcs#493 and the 2021-11-17 RFC meeting. The gist is there's a requirement to create a production copy of a package or workspace for deployment (zip archives for lambda,
COPYinto docker image) and existing npm commands have shortcomings, specifically regarding workspaces.This draft CR will give a foundation for discussions.
--omitand--productionflags?pack,installor another command support this usecase instead of adding a new command?I'll work on tests and documentation after more of the command is finalized
Goals (still up for discussion):