1.0.1 • Published 5 years ago

@vibhus/locale_modules_poc v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

local_modules usage Proof of Concept

Just a proof of concept of using local_modules to solve the "Better local require() paths" problem.

It also helps you write true re-usable sub-modules.

Running the app

Just like any node app:

npm install
npm start

_Note: if you run npm 3+, you need to remove the preinstall script in package.json

Note: This apps does nothing useful, it'll just print a useless array.

Writing new sub modules

  • Create a new folder for your module, such as local_modules/my-module (can be anything else)
  • Create a package.json file for it, along with the usual README.md
  • Adds its dependencies in its own package.json
  • Write the module (duh)
  • Install this local package in your top level module using: npm install --save ./local_modules/my-new-module.
  • ????
  • Profit!

Updating a local module

  • Update whatever you want in your module (including dependencies)
  • Bump your sub-module version in its package.json (important)
  • Simply run npm update or npm update my-module

Or

Use rm-local-modules as preinstall script and simply run npm install:

// package.json
{
  "devDependencies": {
    "rm-local-modules": "0.0.0"
  },
  "scripts": {
    "preinstall": "rm-local-modules"
  }
}

Pros

  • No dirty hack, require() wrapper, ../../../ paths, but pure npm
  • Proper nested 3rd party dependency declaration
  • Super easy to externalize your local module and make it a 3rd party library if you feel like it: it already is an independent node module.

Cons

  • The npm update of local module is broken at the moment. Fingers crossed we can have it soon. Fixed! And available since npm 2.9.0 / iojs 2.0.0.
  • A bug in npm 3+ broke the preinstall lifecyle and the rm-local-modules in prescript trick doesn't work.
1.0.1

5 years ago

1.0.0

5 years ago