-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Hi, I was wondering if there were any news on this issue. @jeanbmar is there anything @everett1992 or I could help with to expedite this review? Thanks, |
Hi 😀, what's the status of this issue? thanks |
Hi @jeanbmar, Sorry for the direct ping, do you have any updates on how we can make sure this PR moves forward? Thanks again, |
Hi @pose, I don’t work with the npm team :). I need this too! |
Hi @nlf, Sorry for the direct ping, we are trying to find the right owner for this review. Do you think you could help us out? Thanks, |
}, | ||
}) | ||
process.chdir(npm.prefix) | ||
npm.config.set('omit', ['optional']) |
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.
Is the name of the test correct? We omit not bundled, but optional dependencies here.
npm.config.set('workspace', ['a']) | ||
await npm.exec('copy', ['build']) | ||
|
||
assertExists(path.join('build', 'node_modules', 'a')) |
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.
Maybe we should test for package.json
and README.md
copied, not just for the folder?
I can see that https://github.com/everett1992/rfcs/blob/npm-copy/accepted/0000-npm-copy.md mentions |
@amazlite I haven't updated the RFC as npm has evolved. This PR uses the --omit flag rather than --production to match npm 7+.
|
@everett1992 I've created a repo to show people reading this PR how to use your work on I've noticed a problem though. |
3037d35
to
f3b0c43
Compare
@everett1992 I've noticed an issue with symlinks.
Symlinks point to Symlinks are fine when doing |
@everett1992 Have you lost interest in this PR? |
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,
COPY
into docker image) and existing npm commands have shortcomings, specifically regarding workspaces.This draft CR will give a foundation for discussions.
--omit
and--production
flags?pack
,install
or 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):