Skip to content

Working on NMP modules

Scott Nath edited this page Dec 15, 2016 · 1 revision

How to get live changes to a local npm module in a separate project

You can have instant, live changes to an npm module imported into your project's node_modules directory. This can be done using npm link

Making your local module available in another local project

Example usage: making changes to a local input plugin (input-plugin-foo), while seeing those changes live in your CMS (punchcard-instance-bar)

  1. In the root of your module's directory (input-plugin-foo), type:

    npm link

  2. In the project (punchcard-instance-bar) that wants to use the local module (input-plugin-foo), delete node_modules

    rm -rf ./node_modules

  3. In the project package.json (punchcard-instance-bar) remove references to the local module (input-plugin-foo)

  4. In the root of your project (punchcard-instance-bar) that wants to use the local module (input-plugin-foo), type:

    npm link {{name-of-module}} as in: npm link input-plugin-foo

  5. Once that is complete, re-install all other npm modules

    npm install

  6. Add the local module back to the project's package.json file - making sure to use the version number of your local module

    "input-plugin-foo": "^0.0.2",

Things to note

  1. If you need to reinstall all node modules, or you're doing a fresh install, then your npm link may be lost

  2. Make sure to read the npm page on how to use npm link - it is very helpful

  3. Make sure that module-a is still in package.json. You may need to change the url location, to the version number. So you would go from something like this:

      "devDependencies": {
        "ava": "^0.12.0",
        "eslint": "2.2.0",
        "eslint-config-yourcompany": "git+ssh://git@github.yourcompany.com:user/javascript-style-guides.git#v1.1.0",
        "nyc": "^6.0.0",
        "tap-diff": "^0.1.1"
      },
    

to this:

```
  "devDependencies": {
    "ava": "^0.12.0",
    "eslint": "2.2.0",
    "eslint-config-company": "^1.1.0",
    "nyc": "^6.0.0",
    "tap-diff": "^0.1.1"
  },
```

How to import NPM modules from GitHub instead of npmjs.com

IBM has implemented a private npm repository for deploying out npm modules. However, there are a lot of issues with that system, not least of which is the inability for our CI tool, Travis, to use our private repository. SO, we're forced to reference non-npmjs-based node modules in our package.json files directly from our GitHub Enterprise repositories.

See the npm install information for an expanded version on how to install from various sources other than npmjs.

Installing a module from GitHub Enterprise

  1. Get the ssh url for the module you want to use

  2. In package.json, add module name and the full url, preceded by git+ssh://. Example:

    "input-plugin-text": "git+ssh://git@github.yourcompany.com:snath/input-plugin-text.git",

  3. Modules gets installed when you run:

    npm install