Requiring Yadda

66 views
Skip to first unread message

Stephen Cresswell

unread,
May 21, 2013, 7:07:40 AM5/21/13
to casp...@googlegroups.com
I've been making some changes in the Yadda 0.3.0 branch so that it can be bundled as a node module, but having difficulty requiring the module from Casper. 

var Yadda = require('./lib/yadda') results in 

CasperError: CasperJS couldn't find module ./Interpreter

Interpreter is required by Yadda.js and the problem appears to have something to do with relative paths. If I hack the code to require('./lib/yadda/lib/Interpreter'), Casper complains about the next requirement.

Any ideas how to work around this? I've tried using Browserify to create web compatible and umd compatible modules without any luck.

Thanks,

Steve

Stephen Cresswell

unread,
May 21, 2013, 8:38:41 AM5/21/13
to casp...@googlegroups.com
Update...

I managed to get thing working with the following, but it's ugly. Suggestions for improvements gratefully received.

function initYadda() {
    // Using browserify overwrites Casper's require method
    var oldRequire = require;
    phantom.injectJs('../../dist/yadda-0.3.0.js');
    window.Yadda = require('Yadda');
    window.CasperPlugin = require('plugins').CasperPlugin;
    window.Library = require('localisation').English;
    window.TextParser = require('parsers').TextParser;
    window.Dictionary = require('Dictionary');
    window.library = require('./google-library').init();
    window.yadda = new Yadda(library);
    window.require = oldRequire;
};
Reply all
Reply to author
Forward
0 new messages