Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add coffeescript support #8

Merged
merged 2 commits into from almost 3 years ago

2 participants

Ricardo Tomasi Felix Gnass
Ricardo Tomasi

Hi Felix,

This change require()'s the coffee-script module in case the watched file has a .coffee extension, and changes the require hook extension in wrapper.js accordingly. It also tweaks the error capturing regex a little to allow for differences in coffee output. Is this viable?

Ricardo Tomasi

warning: dirty history. I suck at git.

Felix Gnass fgnass commented on the diff April 28, 2011
@@ -118,7 +119,9 @@ function start(title, msg) {
118 119
       /** Extract all file paths from the stack-trace */
119 120
       files = [];
120 121
       (error.match(/\(\/.*?:\d+:\d+\)/mg) || []).forEach(function(line) {
121  
-        files.push(line.match(/(\/.*?):/)[1]);
  122
+        // only watch files in current dir
2
Felix Gnass Owner
fgnass added a note April 28, 2011

Why this? The idea was to allow hacking on external modules installed via npm link.

in case of a syntax error in coffeescript the output includes lots of it's own package files which we don't want to be watching. maybe we should detect a parseError or syntaxError and handle them differently.

this could also be ignored, I'm not sure about the overhead of watching the extra 4-5 files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Felix Gnass fgnass commented on the diff April 28, 2011
@@ -70,6 +70,7 @@ function start(title, msg) {
70 70
       start('Restarting', 'Restarting');
71 71
     }
72 72
     else if (files) {
  73
+			console.log(util.inspect(files));
2
Felix Gnass Owner
fgnass added a note April 28, 2011

Is this intentional or a debugging leftover?

ugly leftover.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Felix Gnass fgnass merged commit 5204012 into from April 28, 2011
Felix Gnass fgnass closed this April 28, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Apr 27, 2011
Ricardo Tomasi added basic coffeescript support 0cd795d
Ricardo Tomasi pulling upstream 5204012
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 12 additions and 5 deletions. Show diff stats Hide diff stats

  1. 7  node-dev
  2. 10  wrapper.js
7  node-dev
@@ -70,6 +70,7 @@ function start(title, msg) {
70 70
       start('Restarting', 'Restarting');
71 71
     }
72 72
     else if (files) {
  73
+			console.log(util.inspect(files));
73 74
       /** Worker exited due to an error */
74 75
       files.forEach(function(file) {
75 76
         fs.watchFile(file, function(cur, prev) {
@@ -93,7 +94,7 @@ function start(title, msg) {
93 94
 
94 95
     error += s;
95 96
 
96  
-    stack = s.match(/^(.+): (.*)\n\s+at.+\((.*?):(\d+):(\d+)/m);
  97
+    stack = s.match(/^(.+): (.*)\n\s+at\s?.+?\s\(?(.*?):(\d+):(\d+)/m);
97 98
     if (stack) {
98 99
 
99 100
       // file:line
@@ -118,7 +119,9 @@ function start(title, msg) {
118 119
       /** Extract all file paths from the stack-trace */
119 120
       files = [];
120 121
       (error.match(/\(\/.*?:\d+:\d+\)/mg) || []).forEach(function(line) {
121  
-        files.push(line.match(/(\/.*?):/)[1]);
  122
+        // only watch files in current dir
  123
+        if (line.indexOf(process.cwd()) >= 0)
  124
+          files.push(line.match(/(\/.*?):/)[1]);
122 125
       });
123 126
       error = '';
124 127
     }
10  wrapper.js
@@ -42,15 +42,19 @@ for (var i=1; i < process.argv.length; i++) {
42 42
 /** Resolve the location of the main script relative to cwd */
43 43
 var main = Path.resolve(process.cwd(), arg);
44 44
 
  45
+var fileExt = main.match(/\.\w+$/)[0];
  46
+if (fileExt == '.coffee')
  47
+  require('coffee-script');
  48
+
45 49
 /** Hook into `require()` */
46  
-var requireJs = require.extensions['.js'];
47  
-require.extensions['.js'] = function(module, filename) {
  50
+var _require = require.extensions[fileExt];
  51
+require.extensions[fileExt] = function(module, filename) {
48 52
   if (module.id == main) {
49 53
     module.id = '.';
50 54
     module.parent = null;
51 55
   }
52 56
   watch(module);
53  
-  requireJs(module, filename);
  57
+  _require(module, filename);
54 58
 };
55 59
 
56 60
 /** Load the wrapped script */
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.