yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.44k stars 2.73k forks source link

yarn clean removes files/folders required for packages to work #3517

Closed ksmithut closed 7 years ago

ksmithut commented 7 years ago

Do you want to request a feature or report a bug?

Bug

What is the current behavior? When installing a package, if there is a subfolder called docs, it is removed.

If the current behavior is a bug, please provide the steps to reproduce.

npm install skyway@1.0.0
# Note that in node_modules/skyway/swagger2, there is a docs folder. There is a function in the module called `.docs()` that this refers to.
rm -r node_modules/skyway
yarn add skyway@1.0.0
# Note that in node_modules/skyway/swagger2, there is no docs folder, because yarn ran a clean step that removes a number of directories, including ones called `docs`

What is the expected behavior?

I expect that folders don't just get removed. I understand the need, but maybe it should be less aggressive, perhaps only cleaning out those types of folders from the top level, or allowing some way for package maintainers to mark targeted folders as "required for package" or something. I thought that's what .npmignore, although I understand that not all package maintainers clean up our output artifacts.

Please mention your node.js, yarn and operating system version.

Since I'm the maintainer of the skyway package, I've decided to rename that folder so that it can work with yarn, but I can't imagine that I'm the only one with a package with similar problems (however rare).

ksmithut commented 7 years ago

I do see that there is a new .yarnclean file in there, which yarn seems to respect. All I'm saying is, there could be users of yarn who will get Cannot find module './docs' with a stack trace that will lead them to a library they're using, and not understand that yarn cleaned it out.

I think it's something that will probably blow over quickly, or people will learn just to tweak their .yarnclean file (another dotfile in my projects?), so feel free to close this with links to the documentation that explains how this works/reasoning/requests behind this feature.

rally25rs commented 7 years ago

It looks like by default yarn clean removes:

# test directories
__tests__
test
tests
powered-test

# asset directories
docs
doc
website
images
assets

# examples
example
examples

# code coverage directories
coverage
.nyc_output

# build scripts
Makefile
Gulpfile.js
Gruntfile.js

# configs
.tern-project
.gitattributes
.editorconfig
.*ignore
.eslintrc
.jshintrc
.flowconfig
.documentup.json
.yarn-metadata.json
.*.yml
*.yml

# misc
*.gz
*.md

with the assumption that these are files that don't have an affect on the package, and are dev-time tools or reference material.

The docs for the clean command state:

This command is considered for advanced use cases only. Unless you are experiencing issues with the amount of files that are installed as part of node_modules it is not recommended to use this command.


It looks like skyway@1.0.0 is not a published version, but if I yarn add skyway@1.0.1 then I do get a swagger2/docs folder. Yarn doesn't automatically run a clean unless there is a .yarnclean file. Perhaps some other package put a .yarnclean file into your project?

ksmithut commented 7 years ago

So I went through my bash history and found that I was attempting to clear my yarn cache after I was getting some warnings about hashes mismatching, and I did run yarn clean.

Also, good catch on the version.

Apologies for any undue time you spent on this, I appreciate the help that lead me to the conclusion that the problem was between keyboard and chair 😄