hypery2k
hypery2k

Reputation: 1691

NPM package output message at the very end

Did anyone know if it's possible to print a log message at the very end after the npm install?

  To enable CLI tab autocompletion run:
   mypackage completion >> ~/.profile


  [email protected] node_modules/progress

  [email protected] node_modules/kew

  [email protected] node_modules/adm-zip

  [email protected] node_modules/request-progress
  └── [email protected]
  ....

But I want to give a message after the dependency download, e.g:

  [email protected] node_modules/progress

  [email protected] node_modules/kew

  [email protected] node_modules/adm-zip

  [email protected] node_modules/request-progress
  └── [email protected]
  To enable CLI tab autocompletion run:
   mypackage completion >> ~/.profile

I tried it via a post installation script, but doesn't work

Upvotes: 8

Views: 4771

Answers (2)

splintor
splintor

Reputation: 10154

I also run into this problem. My workaround was to use custom script:

"scripts": {
  "presetup": "npm install -g",
  "setup": "node postinstall.js"
},

(I need my tool to be installed globally, hance -g. This, of course, can be omitted.)

And then I asked my users to run this line, instead of the usual npm install:

npm run-script setup my-package.tgz

Note that npm install still works. It just won't show the final message.

Upvotes: 3

user3117575
user3117575

Reputation:

From the npm documentation on "scripts" it states you can use the "postinstall" (or just "install") linked up with a command to run after the package has installed...

Since you say you already attempted this, but gave no context in your question on how, let me just walk you through the process...

For example, say this were in your package.json:

{
  ...
  "scripts": {
    "postinstall": "node postinstall.js"
  }
  ...
}

Then, in your project directory, you can create a postintall.js script, and put this in it:

console.log(
  "To enable CLI tab autocompletion run:\n" + 
  "mypackage completion >> ~/.profile"
);

Upvotes: 8

Related Questions