Np: Add a real prepublish hook?

Created on 3 May 2017  路  3Comments  路  Source: sindresorhus/np

So for many many years there have been countless issues opened by people who want to run some sort of compile step before publishing their module (coffeescript -> js, babel compile, typescript compile, etc), and the npm team has consistently been unable to deliver.

They have made two attempts, prepublish, which also runs on npm install and therefore makes it useless, and prepublishOnly, which only runs after the tar has been packed and therefore has no effect on the actual published code. I am baffled as to how it could be so difficult to implement a hook that runs and is able to transform code before publishing, but alas such is life.

I guess my question is, would you be down for a PR that adds an actual build hook? We could take a task named like np-before-publish and actually execute it before publishing, and I would be more than happy to pull request this in 馃懍

Most helpful comment

Use the version hook

{
  "scripts": {
    "version": "npm run build"
  }
}

All 3 comments

You can solve that with in-publish.

Here is how I am using it in trae:

{
  "scripts": {
    "prepublish": "in-publish && npm run build || echo 'just installing'"
  }
}

Use the version hook

{
  "scripts": {
    "version": "npm run build"
  }
}

prepublishOnly, which only runs after the tar has been packed and therefore has no effect on the actual published code

Is that supposed to be the case? I thought that was the whole purpose of prepublishOnly. On my environment scripts that run on prepublishOnly make it into the released code.

I'm on windows 10 using npm 5.6.0 and node 8.9.4.

I think this issue can be closed if some other people can confirm that prepublishOnly works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sindresorhus picture sindresorhus  路  7Comments

sindresorhus picture sindresorhus  路  4Comments

kapooostin picture kapooostin  路  5Comments

bennycode picture bennycode  路  4Comments

ProfessorManhattan picture ProfessorManhattan  路  4Comments