michaelficarra / commonjs-everywhere

:rainbow: minimal CommonJS browser bundler with aliasing, extensibility, and source maps
BSD 3-Clause "New" or "Revised" License
158 stars 21 forks source link

support for 'events' core module #35

Closed ghempton closed 11 years ago

ghempton commented 11 years ago

fixes michaelficarra/CoffeeScriptRedux#183

michaelficarra commented 11 years ago

Why was node's events library not working for you?

ghempton commented 11 years ago

The test included here fails (a simple require 'events'). Gives the same issue as I was having in CSR.

michaelficarra commented 11 years ago

Ah, I see now. As of 0.10, events now depends upon child_process, which hasn't been ported or made available for obvious reasons. When I add the test and run the tests, I get this output, which is much clearer:

$ git diff
diff --git i/test/core.coffee w/test/core.coffee
index d37b4951..cfef23c7 100644
--- i/test/core.coffee
+++ w/test/core.coffee
@@ -14,3 +14,7 @@ suite 'Node Core Libraries', ->
   test 'querystring', ->
     fixtures '/a.js': 'module.exports = require("querystring").parse("a=b").a'
     eq 'b', bundleEvalSync '/a.js'
+
+  test 'events', ->
+    fixtures '/a.js': 'module.exports = require("events")'
+    ok bundleEvalSync '/a.js'
$ make test
node_modules/.bin/mocha --compilers coffee:coffee-script-redux -u tdd -R dot test/*.coffee

  ․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․

  ✖ 1 of 44 tests failed:

  1) Node Core Libraries events:
     Error: Core module "[redacted]/commonjs-everywhere/core/child_process.js" has not yet been ported to the browser
ghempton commented 11 years ago

Sorry for the lack of clarity. The error in CSR is actually different than this one I realize. For some reason require 'events' simply returns null in that case. Well regardless, this fix does fix the CSR issue.

ghempton commented 11 years ago

@michaelficarra done

michaelficarra commented 11 years ago

Thanks, @ghempton.