npm install inexplicably runs npm run prepublish in npm 1.2.0
#3059
Comments
|
Running |
|
I refuse to believe that. How am I supposed to do things like auto-test, generate documentation, and create git tags before publishing to NPM if Travis-CI and every single user of the library would end up running that same code!?
|
|
Okay, so I found the commit that's causing the issue, and I think there's a better way to solve the problem rather than cause inexplicable behavior to help some people out (and completely wreck all of my NPM modules). What you wanted was to be able to run the A better solution would be to expose an For this particular use-case, #!/usr/bin/env bash
if ["$npm_invocation" == "npm install"]; then
./prepublish.sh
fiThis, I think, is much more useful because This is all necessary because the I'm willing to make a PR to add the |
|
This change was by design, and was carefully considered. I would say you're doing way too much in your prepublish script. I suggest adding a Makefile with a Or, if that's not to your liking, you can set a config var on your local machine like Or yet another workaround, you can have a script with a different name entirely like Far and away, the most common use case for prepublish is to compile coffeescript into javascript (or minify javascript into ugly javascript, which is essentially the same sort of task). Since this is deterministic, and not platform-dependent, it makes no sense to do it multiple times, on each install target in the preinstall event. It should be done, instead, right before publishing the package, so that it can be bundled in the arball. However, the objection to moving it there is that it no longer compiles CoffeeScript to JavaScript in Eventually, arbitrary pre/post/install scripts will be removed, and It looks like these packages are going to be affected by this. On the other hand, these packages will benefit from the change. |
|
Your two links aren't working for me, though I can see what you're going for (it won't catch scripts that actually delegate to a sh file and do their magic in there because it was too long to keep as a JSON string). Why wouldn't it make more sense to keep the semantic meaning of This new behavior breaks the contract of the scripts interface, and if they're deprecated for I just don't see this as doing "too much" in my prepublish script -- it's simply doing the housekeeping on the repo and making sure that I don't publish a release without minified code, or generated docs, or a missing git tag -- little details that such a script is perfect for. |
|
Ah, yes, markdown mangled the links. Fixed.
Because most modules with a prepublish script want to have it do the exact same thing in both cases. So that's the default. I understand that it's not what you'd prefer. I'm sorry. You are the edge case in this scenario. There are already several ways that you can work around this (listed in my previous message), and we're talking about fewer than a dozen packages. I'd even be happy to send you pull requests to change them. |
|
I've started migrating my code as suggested to a custom npm script. I still think this behavior is unexpected because You don't need to work on any PRs for me, but the other two authors in that list probably deserve a warning that the next time they bootstrap their dev environment for their libraries it will fail. I guess I'm mostly upset because I've touted NPM as an example of a well-done source package manager that does exactly what you expect of it, and this just doesn't make much sense, even if it is more convenient for the majority of lib authors. |
|
I'm with @dfellis And for the record I have been using the same hook exactly as @dfellis has, to make sure my unit tests pass before publishing, to to git housekeeping, to publish to the gazillion frontend module package managers etc. I have no problem writing Makefiles, but really I prefer pre- and post-hooks to be intuitive. |
|
Having the same issue, I guess I'm always the edge case... Should add a new hook, don't break consistency. |
This all makes sense, and worked well before (and after) this change.
This argument seems pretty weak to me, but maybe I don't understand it fully. Is there further discussion somewhere else that I missed? My understanding is that the main (and probably only) reason for running
FWIW, I found this issue after the change broke my travis-ci builds. I don't mind modifying my Makefile to work around it, but I really don't understand who the user group is that needs EDIT: found this https://github.com/isaacs/npm/pull/3053 in which a use case for having scripts automatically run on plain npm install is outlined. |
|
The eventual goal for package.json scripts will be to run pre/post install ONLY on |
This might be related to the behaviour change introduced in isaacs/npm#3059
|
Does anyone have a pointer of where was this carefully considered ? A mailing list thread, another ticket or something ? |
None that I was able to find, (and I did a lot of searching when this issue first broke my CI setup). The justifications given in this issue are terrible as well. In particular...
... and ...
... are both well reasoned arguments against preinstall/postinstall, but have nothing to do with prepublish. The comments in this discussion (again, the only recorded discussion of the issue afaik) are:
This change was a clearly confusing and undesirable to many of the users of the "prepublish" hook, and it concerns me that @isaacs (who has absolute authority over a lot of critical infrastructure for node) would defend it. |
|
I'm upgrading to npm 1.2, and this just bit me too. I was pretty baffled as well. The install-through-git use case in #3053 is interesting food for thought, though I'm pretty surprised that that's not being called an "edge case", and wanting to do things purely pre-publish is. |
prepublish gets run during `npm install`, which can screw stuff up see issue: https://github.com/isaacs/npm/issues/3059
prepublish gets run during `npm install`, which can screw stuff up see issue: https://github.com/isaacs/npm/issues/3059
closes #336 prepublish gets run during `npm install`, which can screw stuff up so do it in a Makefile see issue: https://github.com/isaacs/npm/issues/3059
|
+1 @dfellis Prepublish is a nice way for me to sanity check my modules before sending them off to npm. To say that install should trigger publish is counter-intuitive. I will resort to @isaacs hack for now, I.E. exporting a variable within my prepublish script, but it sure feels like bad design. npm publish # runs prepublish script |
|
@JamesMGreene, perhaps that attunement is reflected in her
|
|
Indeed, it's a cow path that we can pave, if that pattern is effective for people. As far as breaking If we were to pave this cow path then yes, I'd want a more explicit env var. The whole |
|
+1 this is totally unexpected behaviour. Got bitten by this this evening. |
|
+1 prepublish is really surprising in a bad way - altho i can't complain about the docs: https://docs.npmjs.com/misc/scripts Wanted to refer back to @isaacs comment above about deprecating this behaviour, a long time has passed |
|
This also causes |
|
Just another vote for the priority to be raised on this. I keep forgetting that "prepublish" doesn't actually mean "prepublish". |
|
Is this not getting prioritized because it's closed? |
|
@mtscout6 Good question. I'm hoping this is being tracked in another issue. If an issue's been logged and it's agreed that something should happen at some point to fix it, it should be tracked somewhere. Otherwise, these types of things tend to fall off the radar. |
|
@david0178418 I just created a new issue here: #8402 , let's hope this one doesn't get closed. |
Defying common sense. And English. npm/npm#3059
|
+1. cause problems for me |
travis runs a `npm install` for the package. npm-install runs `npm prepublish` (what is an unexpected behaviour if you ask me or (*1)). npm-test would run the karma test with chrome as browser which would fail on travis. (*1) npm/npm#3059
travis runs a `npm install` for the package. npm-install runs `npm prepublish` (what is an unexpected behaviour if you ask me or (*1)). npm-test would run the karma test with chrome as browser which would fail on travis. (*1) npm/npm#3059
Package must be published AFTER 'make clean' is run to prevent any dirty cache file from being packed into tar. Ideally, we could run 'make clean' prior to publishing (prepublish), but it doesn't currently work like that: npm/npm#3059 😒
Steps: 1. On a clean tree on `master`, add a new entry to `CHANGELOG.md` in the same format as the other entries, then run `script/prep-release.sh` to do everything that can be done locally: bump version, build, package as tarball + zipfile, commit, tag. 2. After double-checking the build/package/commit/tag, run `script/push-release.sh` (with a GitHub access token env variable) to automatically publish to NPM, push to GitHub, create a new GitHub Release, and cleanup the tarballs etc. Notes: - `CHANGELOG.md`: I changed the format to resemble [the GitHub Releases page] more. In particular, each entry has a one-line summary on the GitHub Releases page that was the commit message for the version bump/ changelog addition, but didn't show up in the changelog at all. - `Makefile`: since these scripts create and cleanup the tarballs and zipfiles, there's no need for `make dist` anymore, and `make clean` is now, well, cleaner. - Creating GitHub Releases: this was loosely inspired by the [gh-release Bash script], but was mostly based on the [GitHub Releases API docs]. [the GitHub Releases page] https://github.com/mathquill/mathquill/releases [gh-release Bash script]: https://github.com/progrium/gh-release/blob/master/bash/gh-release.bash [itHub Releases API docs]: https://developer.github.com/v3/repos/releases/#create-a-release -- I designed this release process to have 2 steps: 1. Do everything that can be done locally: build, changelogs, bump version, commit, tag, create tarballs and zipfiles 2. Only after getting a chance to double-check the stuff done locally do we publish on public servers like NPM and GitHub Not coincidentally, `npm` has two relevant commands, [`npm version`] and [`npm publish`]. They seem like they'd correspond nicely with my 2 steps, so I tried implementing the release process as hooks into those commands, but it was too annoying: - [`npm version`] ensures that the working tree is clean even before calling the `preversion` hook, and then automatically commits, so the releaser would have to edit `CHANGELOG.md` during one of those hook calls (like it opens a shell or editor or something). - [`npm publish`] is not as well-documented as `npm version`, but I [stumbled on] a sub-step: [`npm pack`], which figures out the files to be included and packs them into a tarball to be uploaded to the NPM registry. However, we actually want that to happen during the Step 1, so we can double-check it before uploading, not this step. So using NPM hook scripts, the workflow would have to be: 1. On a clean tree, run `npm version patch`, which opens an editor on `CHANGELOG.md`, then builds, commits, tags, and in particular packages a tarball like `mathquill-0.10.2.tgz`. 2. After double-checking the build/package/commit/tag, run `npm publish mathquill-0.10.2.tgz`. Note that plain `npm publish` would re-run `npm pack` instead of using the tarball from Step 1. (I guess that would be fine, just inefficient?) Rather than work within these inconveniences, I figured it'd be simpler to just use "lower-level" tools, or at least, the same tools but in a lower-level capacity. Specifically, `prep-release.sh` calls `npm version --no-git-tag-version`, which just bumps the version in package.json and doesn't do anything with Git, and then calls `npm pack` to package the tarball; and `push-release.sh` calls `npm publish <tarball>`, skipping the internal call to `npm pack` simply using `npm publish` to upload to the NPM registry. [`npm version`]: https://docs.npmjs.com/cli/version [`npm publish`]: https://docs.npmjs.com/cli/publish [`npm pack`]: https://docs.npmjs.com/cli/pack [stumbled on]: npm/npm#13080
Hopefully this is something minor (accidentally replaced
preinstallwithprepublishsomewhere)The text was updated successfully, but these errors were encountered: