Permalink
Browse files

added node.js compiler

  • Loading branch information...
weepy@github.com weepy@github.com
weepy@github.com authored and weepy@github.com committed Nov 30, 2010
1 parent c0ca349 commit d025aa51eef7057076b4121b0d95971fde88c153
Showing with 56 additions and 5 deletions.
  1. +22 −0 LICENSE
  2. +2 −1 README.md
  3. +9 −1 lib/brequire.js
  4. +12 −3 package.json
  5. +11 −0 test/node/node.js
View
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2010 Jonah Fox
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
View
@@ -32,4 +32,5 @@ brequire test/src test/lib
then:
-open test/index.html
+open test/index.html
+
View
@@ -29,4 +29,12 @@ require.bind = function(path) {
require.module = function(path, fn) {
require.modules[path] = fn;
-};
+};
+
+require.compile = function(file, text) {
+ return "require.module('./" + file + "', function(module, exports, require) {\n// start module: " + file + "\n\n" + text + "\n\n// end module: "+ file +"\n});\n"
+}
+
+if(typeof exports != "undefined") {
+ exports.compile = require.compile
+}
View
@@ -1,10 +1,19 @@
{
"name": "brequire",
- "version": "0.0.2",
- "description": "Brings exact CommonJS (require, exports) functionality to the Browser.",
+ "version": "0.0.3",
+ "description": "Use CommonJS (require, exports) functionality in the browser",
"author": "weepy",
"bin": "./bin/brequire",
+ "author": "weepy",
+ "licenses": [{
+ "type": "MIT",
+ "url": "http://github.com/weepy/brequire/raw/master/LICENSE"
+ }],
+ "directories" : {
+ "lib" : "./lib"
+ },
"repository": "http://github.com/weepy/brequire",
"dependencies": {},
- "engines" : { "node": ">= 0.2.0" }
+ "engines" : { "node": ">= 0.2.0" },
+ "main": "./lib/brequire"
}
View
@@ -0,0 +1,11 @@
+var text = "var x = 1;"
+var file = "test"
+var js = require("brequire").compile(file, text)
+var expected = "require.module('./" + file + "', function(module, exports, require) {\n// start module: " + file + "\n\n" + text + "\n\n// end module: "+ file +"\n});\n"
+
+if(js != expected) {
+ console.log("FAILED:", js, "!=", expected)
+}
+else {
+ console.log("OK")
+}

0 comments on commit d025aa5

Please sign in to comment.