Run `prepublish` script from package.json on apm publish
Applicable apm code: https://github.com/atom/apm/blob/6c94d96f5d640a51d49a41e2e1d1aa47310516e8/src/publish.coffee
I would like to use the prepublish script in package.json file, as described by npm, to generate my documentation before publishing. See https://github.com/Glavin001/atom-beautify/blob/master/package.json#L150
This currently does not work / is not a feature. Is this something that is of interest to others? Would a pull request be accepted? What other considerations does the community have, before / if I were to develop a Pull Request?
Thanks!
Glavin
Is this something that is of interest to others?
Yeah, this issue has come up before as something that would be great to eventually have first-class support for.
Would a pull request be accepted?
:+1:
What other considerations does the community have, before / if I were to develop a Pull Request?
There is a publish-spec.coffee already so I'd say add new specs there, and add a simple package fixture that includes a prepublish script.
Also this will require doing a git commit after running the script right? Since the built assets will need to be part of the repository before the tag is pushed and the atom.io API is hit.
These notes are mostly for me and any others not familiar with npm and apm internals. I like to document my research in Issues before I start development. Please correct me on anything that I missed. Thanks!
Here is publish from npm: https://github.com/npm/npm/blob/180da67c9fa53103d625e2f031626c2453c7ebcd/lib/publish.js#L74
And publish specs: https://github.com/npm/npm/blob/180da67c9fa53103d625e2f031626c2453c7ebcd/test/tap/prepublish.js
Also this will require doing a git commit after running the script right? Since the built assets will need to be part of the repository before the tag is pushed and the atom.io API is hit.
I think you're right.
-
npm versionrequires that it be a clean Git working directory- See https://github.com/npm/npm/blob/cc41475f0e237e07cf436487126b96a893dfcc85/lib/version.js#L152
- From https://docs.npmjs.com/cli/version:
If run in a git repo, it will also create a version commit and tag, and fail if the repo is not clean.
-
npm publishdoes not deal withgitand just flows down the lifecycle: https://github.com/npm/npm/blob/180da67c9fa53103d625e2f031626c2453c7ebcd/lib/publish.js#L74-L77-
npmstores its own copy of the code and does not use Git/GitHub as reference. Therefore it does not care about committing beforeprepublishandpublishstages as it never makes agit commitanywhere and pushes whatever code is available whenpublishis executed.
-
-
apm publishusesnpm versioninternally and notnpm publish.- See https://github.com/atom/apm/blob/b47423db2dd093404cab80d752793cdf91986111/src/publish.coffee#L56-L57
- Therefore we will need to run
prepublishand thengit commit(if applicable), then runnpm versionand the other lifecycle stages, includingpostpublish-- might as well add that, too, as it should not be as complicated.
I would prefer that it be included under the Prepare # release commit, however this is handled mostly by npm version, which checks for the clean git working directory. See https://github.com/atom/apm/blob/b47423db2dd093404cab80d752793cdf91986111/src/publish.coffee#L56 and https://github.com/npm/npm/blob/cc41475f0e237e07cf436487126b96a893dfcc85/lib/version.js#L152
So let's consider what should happen when running apm publish:
- [x] run
prepublishscript - [x] check if it exitted successfully
- [x] show error message if applicable
- [x] continue if successful
- [x] check if changes to staging area and commit if available?
- [ ] What would the commit message be?
Preparing to prepare # release? :stuck_out_tongue_winking_eye:
- [ ] What would the commit message be?
- [x] continue to run
publishas normal, which includes incrementing version and publishing toapmAPI - [x] run
postpublishif all successful
I'd like to design and implement a Pull Request in these next few days. Any feedback would be greatly appreciated. Thanks!
+1 for this!
Huge :+1:
This is preventing me from packing static resources. It seems I have no choice but to download static resources on activation, which is unnecessary extra work and dirty too.
On a related note, the prepublish script is executed when I run apm install myuser/mypackage where myuser/mypackage is the GitHub repo reference of the package, but not when I run apm install mypackage, where mypackage is the name of the Atom package as published on atom.io. Unfortunately I need the latter to work, because obviously users will install from the package browser, and not by running apm install github-ref.
Is there any update or workaround for this?