apm icon indicating copy to clipboard operation
apm copied to clipboard

Run `prepublish` script from package.json on apm publish

Open Glavin001 opened this issue 10 years ago • 5 comments

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

Glavin001 avatar Jun 08 '15 20:06 Glavin001

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.

kevinsawicki avatar Jun 08 '15 23:06 kevinsawicki

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 version requires 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 publish does not deal with git and just flows down the lifecycle: https://github.com/npm/npm/blob/180da67c9fa53103d625e2f031626c2453c7ebcd/lib/publish.js#L74-L77
    • npm stores its own copy of the code and does not use Git/GitHub as reference. Therefore it does not care about committing before prepublish and publish stages as it never makes a git commit anywhere and pushes whatever code is available when publish is executed.
  • apm publish uses npm version internally and not npm publish.
    • See https://github.com/atom/apm/blob/b47423db2dd093404cab80d752793cdf91986111/src/publish.coffee#L56-L57
    • Therefore we will need to run prepublish and then git commit (if applicable), then run npm version and the other lifecycle stages, including postpublish -- 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 prepublish script
  • [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:
  • [x] continue to run publish as normal, which includes incrementing version and publishing to apm API
  • [x] run postpublish if all successful

I'd like to design and implement a Pull Request in these next few days. Any feedback would be greatly appreciated. Thanks!

Glavin001 avatar Jun 11 '15 16:06 Glavin001

+1 for this!

danielbayley avatar May 20 '16 17:05 danielbayley

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.

ghost avatar Jul 14 '17 08:07 ghost

Is there any update or workaround for this?

aminya avatar Apr 01 '20 06:04 aminya