Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Run prepublish script from package.json on apm publish #372

Open
Glavin001 opened this issue Jun 8, 2015 · 5 comments
Open

Run prepublish script from package.json on apm publish #372

Glavin001 opened this issue Jun 8, 2015 · 5 comments

Comments

@Glavin001
Copy link

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

@kevinsawicki
Copy link
Contributor

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?

👍

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.

@Glavin001
Copy link
Author

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.

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

      apm/src/publish.coffee

      Lines 56 to 57 in b47423d

      versionArgs = ['version', version, '-m', 'Prepare %s release']
      @fork @atomNpmPath, versionArgs, (code, stderr='', stdout='') =>
    • 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

versionArgs = ['version', version, '-m', 'Prepare %s release']
and https://github.com/npm/npm/blob/cc41475f0e237e07cf436487126b96a893dfcc85/lib/version.js#L152

So let's consider what should happen when running apm publish:

  • run prepublish script
  • check if it exitted successfully
    • show error message if applicable
    • continue if successful
  • check if changes to staging area and commit if available?
    • What would the commit message be? Preparing to prepare # release? 😜
  • continue to run publish as normal, which includes incrementing version and publishing to apm API
  • 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 added a commit to Glavin001/apm that referenced this issue Jun 15, 2015
See atom#372. Prepublish and Postpublish scripts in package.json file
@danielbayley
Copy link

+1 for this!

cbargren added a commit to Axosoft/atom-github-notifications that referenced this issue Mar 9, 2017
So this really sucks but there really isn't a great way to publish an apm-specific version of the app (pre-babeled) in the same way that you can do such a thing for npm. Basically, apm wants your package to exactly match your git repository. This means there isn't really much room for transpiling in a clean way (babeling, then publishing the babeled code, excluding the unbabeled code)

See the following:
https://discuss.atom.io/t/how-to-use-the-npmignore/9208/5
atom/apm#372
@ghost
Copy link

ghost commented Jul 14, 2017

Huge 👍

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.

@aminya
Copy link
Contributor

aminya commented Apr 1, 2020

Is there any update or workaround for this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants