index.js should get the real folder in which it is working #1393

Closed
spieglio opened this Issue Jan 22, 2014 · 6 comments

Comments

Projects
None yet
3 participants

The index.js file in the module route should force the requires to use the __dirname for the require statements:

Instead of this

module.exports = process.env.JADE_COV
  ? require('./lib-cov/jade')
  : require('./lib/jade');

do this:

module.exports = process.env.JADE_COV
  ? require(__dirname + '/lib-cov/jade')
  : require(__dirname + '/lib/jade');

This would help with browserify / coffeeify including jade form of a node_module.

Owner

ForbesLindesay commented Jan 22, 2014

This would not help browserify, it would break browserify. That's not how require is built to work. coffeeify I don't know about, but if it can't cope with CommonJS then I don't really care about it.

Sorry to bother again, but this is what I get when using the following line in my js which is then browserified:

var jade = jade || require('jade').runtime;
Warning: Command failed: Error: module "./lib-cov/jade" not found from "/Users/<PATH_REPLACED>/node_modules/jade/index.js"
Owner

ForbesLindesay commented Jan 23, 2014

Yes, but that's a different issue. Jade used to use lib-cov. What that index.js file should say is:

module.exports = require('./lib/jade');

Or if we still want to use lib-cov (which I don't think we do) it should say:

//declare r variable to hide from browserify's static analysis
var r = require;
module.exports = process.env.JADE_COV
  ? r('./lib-cov/jade')
  : require('./lib/jade');
Owner

ForbesLindesay commented Jan 23, 2014

Also, if all you need is the runtime, you shouldn't use require('jade') you should use require('jade/lib/runtime') as that gives you a much smaller module that just contains the code needed at runtime.

spieglio referenced this issue in gruntjs/grunt-contrib-pug Jan 23, 2014

Closed

jade runtime direct not via require('jade') #84

Member

rlidwka commented Jan 23, 2014

Or put a comment there:

module.exports = process.env.JADE_COV
  ? require(/*don't bundle this pleeease*/'./lib-cov/jade')
  : require('./lib/jade');

It's not only browserify, same issue with nexe here: crcn/nexe#37 .

Owner

ForbesLindesay commented Jan 23, 2014

We should just remove the lib-cov stuff. It's not needed anymore.

@silver83 silver83 added a commit to silver83/jade that referenced this issue Feb 17, 2014

@silver83 silver83 followup on #1393 - remove lib-cov stuff 726bb43

@ForbesLindesay ForbesLindesay added a commit that referenced this issue Feb 17, 2014

@ForbesLindesay ForbesLindesay Merge pull request #1419 from silver83/master
followup on #1393 - remove lib-cov stuff
62e7a3f

@sleistner sleistner added a commit to sleistner/grunt-contrib-jade that referenced this issue Aug 18, 2014

@sleistner sleistner Jade runtime direct not via require('jade')
From
pugjs/pug#1393 (comment)

“If all you need is the runtime, you shouldn't use require('jade') you
should use require('jade/lib/runtime') as that gives you a much smaller
module that just contains the code needed at runtime.”
16bd92e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment