Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arnaudrinquin/local_modules_poc
`local_modules` usage Proof of Concept
https://github.com/arnaudrinquin/local_modules_poc
Last synced: 2 months ago
JSON representation
`local_modules` usage Proof of Concept
- Host: GitHub
- URL: https://github.com/arnaudrinquin/local_modules_poc
- Owner: ArnaudRinquin
- Created: 2015-04-10T17:04:00.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-17T22:57:36.000Z (almost 8 years ago)
- Last Synced: 2024-10-23T08:54:25.439Z (2 months ago)
- Language: JavaScript
- Size: 37.1 KB
- Stars: 95
- Watchers: 4
- Forks: 15
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# local_modules usage Proof of Concept
Just a proof of concept of using `local_modules` to solve the ["Better local require() paths"](https://gist.github.com/branneman/8048520) 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`:
```js
// 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](https://github.com/npm/npm/issues/7426). Fingers crossed we can have it soon.~~ Fixed! And available since `npm 2.9.0` / `iojs 2.0.0`.
* [A bug in `npm 3+`](https://github.com/npm/npm/issues/10379) broke the `preinstall` lifecyle and the `rm-local-modules` in `prescript` trick doesn't work.