2

I am testing on npm scripts to build my project dependency.

My idea comes from https://github.com/ParsePlatform/parse-server which impressed me by code in repository doesn't mean code in node_modules after npm install.

Below is my testmodule structure

src/index.js
package.json

and this is my package.json content

{
  "name": "testmodule",
  "version": "1.0.0",
  "description": "",
  "main": "lib/index.js",
  "scripts": {
    "build": "babel src/ -d lib/",
    "prepublish": "npm run build"
  },
  "devDependencies": {
    "babel-cli": "^6.18.0",
    "babel-core": "^6.18.2"
  }
}

and this is structure I expect after run npm install testmodule

node_modules/testmodule/lib/index.js
node_modules/testmodule/package.json

which is src folder should not be here.

But after I run npm install, it is exactly the same as when I push to my git repository.

Please take note that I am using GitLab in my own server.

So my questions are:

  1. Is there anything that i'm missing to make prepublish run?

  2. Which part of parse-server code makes the src folder and other files not there after install?

tehp
  • 5,018
  • 1
  • 24
  • 31
Simon
  • 1,426
  • 3
  • 16
  • 24

2 Answers2

1

How are you running npm install?

According to the documentation on npm scripts, the prepublish script is run "BEFORE the package is published. (Also run on local npm install without any arguments.)". It seems clear that the prepublish script is only run on npm publish or npm install <local directory>.

If you are trying to install directly from your local gitlab server via a URL, this will not work - the script will not be run. The solution would be to install locally unless you're willing to open source your package & push it to the npm repository or pay for a private npm repository. This is what I have done during development of packages before they're ready to be made public.

Kryten
  • 15,230
  • 6
  • 45
  • 68
  • Got it for prepublish. Thank you. But mind explain how parse-server remove src, resources folder and other file during publish? – Simon Nov 30 '16 at 06:29
  • 1
    FWIW, I know nothing about parse-server, but it looks like the package is installed from the npm repository. Therefore, at some point the developer did an `npm publish` and pushed the code to the npm repository. And that's when the parse-server prepublish script is run. – Kryten Nov 30 '16 at 14:31
1

prepublish is deprecated. Use prepublishOnly or prepare.

prepublish (DEPRECATED)

  • Does not run during npm publish, but does run during npm ci and npm install...

prepublishOnly

  • Runs BEFORE the package is prepared and packed, ONLY on npm publish.

https://docs.npmjs.com/cli/v9/using-npm/scripts

Mir-Ismaili
  • 13,974
  • 8
  • 82
  • 100