Skip to content

Commit

Permalink
add --dedupe
Browse files Browse the repository at this point in the history
  • Loading branch information
fgnass committed Sep 9, 2014
1 parent 37fd76d commit b627f13
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
node_modules
node_modules
npm-debug.log
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,23 @@ options you can set to tweak its behaviour:
* `timestamp` – The timestamp format to use for logging restarts. _Default:_ `"HH:MM:ss"`
* `vm` – Whether to watch files loaded via Node's [VM](http://nodejs.org/docs/latest/api/vm.html) module. _Default:_ `true`
* `fork` – Whether to hook into [child_process.fork](http://nodejs.org/docs/latest/api/child_process.html#child_process_child_process_fork_modulepath_args_options) (required for [clustered](http://nodejs.org/docs/latest/api/cluster.html) programs). _Default:_ `true`
* `deps` - How many levels of dependencies should be watched. _Default:_ `1`
* `deps` – How many levels of dependencies should be watched. _Default:_ `1`
* `dedupe` – Whether modules should by [dynamically deduped](https://www.npmjs.org/package/dynamic-dedupe). _Default:_ `false`

Upon startup node-dev looks for a `.node-dev.json` file in the user's HOME
directory. It will also look for a `.node-dev.json` file in the current
directory which (if present) overwrites the per-user settings.

### Dedupe linked modules

Sometimes you need to make sure that multiple modules get
_exactly the same instance_ of a common (peer-) dependency. This can usually be
achieved by running `npm dedupe` – however this doesn't work when you try to
`npm link` a dependency (which is quite common during development). Therefore
node-dev provides a `--dedupe` switch that will inject the
[dynamic-dedupe](https://www.npmjs.org/package/dynamic-dedupe) module into your
app.

### Transpilers

You can also use node-dev to run transpiled languages. You can either use a
Expand Down
1 change: 1 addition & 0 deletions lib/cfg.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
deps : c.deps,
timestamp : c.timestamp || (c.timestamp !== false && 'HH:MM:ss'),
clear : !!c.clear,
dedupe : !!c.dedupe,
extensions : c.extensions || {
coffee: "coffee-script/register",
ls: "LiveScript"
Expand Down
3 changes: 2 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ exports.parseOpts = function(args, defaults) {
else if (option(args, '--no-deps')) deps = 0

return {
deps: deps
deps: deps,
dedupe: option(args, '--dedupe', defaults.dedupe)
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/dedupe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('dynamic-dedupe').activate()
11 changes: 7 additions & 4 deletions lib/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ module.exports = function(wrapper, callback) {
var handlers = require.extensions
for (var ext in handlers) {

// Get or create the hook for the extension
var hook = hooks[ext] || (hooks[ext] = createHook(ext))
// Get or create the hook for the extension ...
var hook = hooks[ext]

// first encounter, create a new hook
if (!hook) hook = hooks[ext] = createHook(ext)

if (handlers[ext] !== hook) {
origs[ext] = handlers[ext]
if (!origs[ext]) origs[ext] = handlers[ext]
handlers[ext] = hook
}
}
Expand All @@ -52,7 +55,7 @@ module.exports = function(wrapper, callback) {
origs[ext](module, filename)

// Make sure the module did not hijack the handler
updateHooks()
//updateHooks()
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module.exports = function(args) {
// Parse command line options
var opts = cli.parseOpts(args, cfg)

// Run ./dedupe.js as prelaod script
if (opts.dedupe) process.env.NODE_DEV_PRELOAD = __dirname + '/dedupe'

// Inject wrap.js into the args array
cli.injectScript(args, __dirname + '/wrap.js')

Expand Down
4 changes: 4 additions & 0 deletions lib/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ process.argv.splice(1, 1)
// Set NODE_ENV to 'development' unless already set
if (!process.env.NODE_ENV) process.env.NODE_ENV = 'development'

if (process.env.NODE_DEV_PRELOAD) {
require(process.env.NODE_DEV_PRELOAD)
}

// Listen SIGTERM and exit unless there is another listener
process.on('SIGTERM', function() {
if (process.listeners('SIGTERM').length == 1) process.exit(0)
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
"test": "mocha"
},
"dependencies": {
"growl": "~1.7.0",
"dateformat": "~1.0.4-1.2.3",
"filewatcher": "~1.1.1"
"dynamic-dedupe": "^0.2.0",
"filewatcher": "~1.1.1",
"growl": "~1.7.0"
},
"devDependencies": {
"mocha": "~1.4.1",
Expand Down

0 comments on commit b627f13

Please sign in to comment.