-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 prune
equivalent behavior
#696
Comments
Thanks for the report! |
|
@kittens running
|
@torifat Yea that looks to be working, even when you cut out devDependencies by using |
When I run |
My expectation that |
On our CI platform, we currently do this:
i.e. after testing, but before deploying, we remove devDependencies. They get added back again at the start of the next build/test. Is there an equivalent way with |
I agree with @rarkins. Do y'all have an example of how you produce an app suitable for deployment that removes all of the devDependencies? But still allows for the lock file to make sure that all the deps are solid? This is the biggest issue that we face with npm's shrinkwrap. We want production deps to be locked but devDependencies to be free floating so that they are updated more easily as they tend to change more rapidly. |
So, |
@erulabs what order would you run those things in?
I'm having trouble getting the equivalent to |
@chetanddesai You don't need to wipe out the
Remember that if you're trying to do this stuff in a container - yarn keeps its cache outside the |
It is not very intuitive. I do not want to (re)install production packages, I want to remove dev packages. Is it hard to implement an alias |
Does Yarn not remove files when using |
As @abhiaiyer91 says |
Running this script gets me close to const exec = require('child_process').exec;
const devDependencies = Object.keys(require('./package.json').devDependencies).join(' ');
const command = 'yarn remove ' + devDependencies;
const child = exec(command, (err, stdout, stderr) => {
if (err) throw err;
console.log(`stdout: \n${stdout}`);
console.log(`stderr: \n${stderr}`);
}); |
For me |
@tech4him1 I found the same, try adding |
I can't reproduce this bug. If you still experience it on the latest Yarn release, please update the script below to make it a viable reproduction, and reopen the issue (or ping me if you're not the OP).
|
Another issue here: some packages are private, so docker cannot install them. I want to copy all the stuff to docker context, then just remove devDeps. No reinstall – it fails. |
@Diokuz Docker can install private packages if you provide |
@vladgolubev in my case it was not possible because our private npm server (not an npm.org) was physically unreachable from docker. |
No news here ? |
Of course this becomes more complicated when you use yarn workspaces. Here's a helper for that. It does have a dependency on https://gist.github.com/loopmode/318e881454dc0498874a4e764d3dce55 |
My $ yarn remove $(cat package.json | jq -r '.devDependencies | keys | join(" ")') |
This should help reduce the size of the slug. From https://dashboard.heroku.com/apps/reported-web/activity/builds/c343e368-6f2d-454f-97b1-de7c67723b88: ! Warning: Your slug size (307 MB) exceeds our soft limit (300 MB) which may affect boot time. See https://devcenter.heroku.com/changelog-items/1145 and yarnpkg/yarn#696 (comment)
This should help reduce the size of the slug. From https://dashboard.heroku.com/apps/reported-web/activity/builds/c343e368-6f2d-454f-97b1-de7c67723b88: ! Warning: Your slug size (307 MB) exceeds our soft limit (300 MB) which may affect boot time. See https://devcenter.heroku.com/changelog-items/1145 and yarnpkg/yarn#696 (comment)
For anyone still desiring this feature, all of the current workarounds require the yarn command to work online. In my case I have private packages from GitHub, and don't want the access credentials to be accessible in the final image. With None of the current solutions work with the |
My solution, using COPY package.json yarn.lock ./
RUN echo $(cat package.json | jq 'del(.devDependencies)') > package.json
RUN yarn --frozen-lockfile |
@patarapolw isn't that equivalent to |
I can't speak for @patarapolw but when I run (This is for a workspaces enabled project if that makes a difference) |
@gaggle running into the same issue now in a workspaces-enabled project. I've resorted to using this fix from @b6pzeusbc54tvhw5jgpyw8pwz2x6gs, which works. Note, however, that I'm installing all the dependencies in a Docker image after using package-json-merge to create one concatenated So first, I have a script in my top-level package.json that uses package-json-merge and runs before the Docker container gets any build context: Then in the Dockerfile, I:
I hope this helps anyone using Docker & workspaces together. It works but it's a little messy. I'm interested to know if you have found a cleaner setup since posting your comment? |
The easiest way to have a setup like that would be Yarn 2 /w |
I think a separate script to
It would be ideal if we can do:
So that the files to be uploaded will be fewer taking less time to upload.
|
I aggre with @aprilmintacpineda for typescript project we can't use |
Running my Dockerfile like this seems to achieve the result I want. My node_modules drops from 190MB to 150MB and all Yarn has to do is prune rather than re-install everything.
|
I haven't been able to get yarn2 to respect the cache during my docker build, it reliably fetches if I don't manually specify cache preservation. And because the cache is in a separate folder, it's being included in the final build. Currently migrating away from yarn (much to my chagrin! I prefer it over npm!) because I can't argue with 15% smaller bundles, see reactiflux/reactibot#224 I spent about 8 hours trying to replicate |
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
Currently yarn doesn't seem to be removing any packages that aren't needed. With npm you can run
npm prune
, but yarn doesn't have that and doesn't do the same operation in other cases.What is the expected behavior?
Please mention your node.js, yarn and operating system version.
Node v5.7.0
Yarn v0.15.1
macOS 10.12
The text was updated successfully, but these errors were encountered: