Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var fs = require('fs');
var React = require('react-tools');
var watch = require('node-watch');

var installed = false;

Expand All @@ -23,12 +24,39 @@ function install(options) {
} catch (e) {
throw new Error('Error transforming ' + filename + ' to JSX: ' + e.toString());
}

// Watch the fie we just transformed and expire it
if (options.watch) {
watch(filename, watchFn);
}

module._compile(src, filename);
};

installed = true;
}

function watchFn(filename) {
expire(filename, true);
}

function expire(id, recursive) {
var modules = [id];
var module = require.cache[id];

// Go through all the module's parents. Seems to be necessary to clear the cache
while (recursive && module && module.parent) {
module = module.parent;

modules.unshift(module.id);
hasParents = module.parent;
}

for (var i = 0; i < modules.length; i++) {
delete require.cache[modules[i]];
}
}

module.exports = {
install: install
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "transparently require() jsx from node",
"main": "index.js",
"dependencies": {
"node-watch": "~0.3.4",
"react-tools": "^0.12.1"
},
"devDependencies": {
Expand Down