├── .gitignore ├── README.md ├── index.js ├── node-jsx.spec.js ├── package.json └── test-module.js /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | node_modules -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # deprecated -- use babel 2 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var jstransform = require('jstransform/simple'); 3 | 4 | var installed = false; 5 | 6 | function install(options) { 7 | if (installed) { 8 | return; 9 | } 10 | 11 | options = options || {}; 12 | 13 | // Import everything in the transformer codepath before we add the import hook 14 | jstransform.transform('', options); 15 | 16 | require.extensions[options.extension || '.js'] = function(module, filename) { 17 | if (!options.hasOwnProperty("react")) 18 | options.react = true; 19 | 20 | var src = fs.readFileSync(filename, {encoding: 'utf8'}); 21 | if (typeof options.additionalTransform == 'function') { 22 | src = options.additionalTransform(src); 23 | } 24 | try { 25 | src = jstransform.transform(src, options).code; 26 | } catch (e) { 27 | throw new Error('Error transforming ' + filename + ' to JS: ' + e.toString()); 28 | } 29 | module._compile(src, filename); 30 | }; 31 | 32 | installed = true; 33 | } 34 | 35 | module.exports = { 36 | install: install 37 | }; 38 | -------------------------------------------------------------------------------- /node-jsx.spec.js: -------------------------------------------------------------------------------- 1 | describe('node-jsx', function() { 2 | it('should work', function() { 3 | require('./index').install(); 4 | expect(require('./test-module').indexOf('data-reactid')).toBeGreaterThan(-1); 5 | }); 6 | }); 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-jsx", 3 | "version": "0.13.3", 4 | "description": "transparently require() jsx from node", 5 | "main": "index.js", 6 | "dependencies": { 7 | "jstransform": "11" 8 | }, 9 | "devDependencies": { 10 | "jasmine-node": "1.12.0", 11 | "react": "^0.13.2" 12 | }, 13 | "scripts": { 14 | "test": "jasmine-node node-jsx.spec.js" 15 | }, 16 | "repository": "petehunt/node-jsx", 17 | "author": "Pete Hunt", 18 | "license": "Apache 2" 19 | } 20 | -------------------------------------------------------------------------------- /test-module.js: -------------------------------------------------------------------------------- 1 | /** @jsx React.DOM */ 2 | 3 | var React = require('react'); 4 | 5 | module.exports = React.renderToString(
); 6 | --------------------------------------------------------------------------------