1

I'm about to write a yeoman generator where the whole template is hosted on a git repository. So the package.json of my yeoman generator looks like

{
  "name": "generator-foo",
  "version": "0.1.0",
  "description": "",
  "files": [
    "generators"
  ],
  "keywords": [
    "yeoman-generator"
  ],
  "dependencies": {
    "foo-template": "git://somewhere-in-the-world/foo-template.git#0.1.0",
    "chalk": "^1.1.3",
    "yeoman-generator": "^1.1.1",
    "yosay": "^2.0.0"
  }
}

Is there any way to prevent npm install from installing the foo-template package, i.e. running any postinstall script just for this package? Instead, it should be just downloaded to node_modules.

Thomas W.
  • 2,134
  • 2
  • 24
  • 46
  • What do you mean with installing? Like calling post-install hooks? – jsalonen Jun 25 '17 at 18:56
  • Possible duplicate of [npm: disable postinstall script while install package](https://stackoverflow.com/questions/23505318/npm-disable-postinstall-script-while-install-package) – jsalonen Jun 25 '17 at 18:57
  • No, it's not a duplicate to these question. In both question it is asked to disable all postinstall scripts. What I want is to prevent running the postinstall scripts in foo-template, but in all other packages. – Thomas W. Jun 25 '17 at 19:15
  • Okay thanks for the more detailed explanation! – jsalonen Jun 25 '17 at 19:16
  • I'm curious: why do you want to skip the postinstall scripts for that specific package? – jsalonen Jun 25 '17 at 19:20
  • Because it just includes the template code for a yeoman generator. It is not required in this place to really install the whole package, which is then really large. – Thomas W. Jun 25 '17 at 19:23
  • Which parts of the package you need? And would `--ignore-scripts` be sufficient for that task? – jsalonen Jun 25 '17 at 19:24
  • I need the whole package. You can think about it to be something like an angular seed. I need the seed as data for the generator, but it does not need to be installed by itself. `--ignore-scripts` is not an option, as it disables all scripts for the yeoman generator. – Thomas W. Jun 25 '17 at 19:29

1 Answers1

1

As describe here, postinstall scripts can be disabled globally for npm using --ignore-scripts flag.

As a complete solution, I would move your explicit dependency to foo-template to your local postinstall section with ignore scripts enabled:

{
  "name": "generator-foo",
  ...
  "postinstall": "npm install --ignore-scripts git://somewhere-in-the-world/foo-template.git#0.1.0",
  "peerDependencies": {
    "foo-template": "git://somewhere-in-the-world/foo-template.git#0.1.0" 
  }
}

Note that to make sure the dependency is explicitly described, we should mark it as a peerDependency (e.g. prevents package removal on prune).

jsalonen
  • 29,593
  • 15
  • 91
  • 109