module.extensions #4384

Closed
alvarolm opened this Issue Dec 6, 2012 · 4 comments

2 participants

@alvarolm

module.extensions doesnt seems to be working properly, the example given on http://nodejs.org/api/globals.html#globals_require_extensions returns nothing.
node@0.8.12 | linux | ia32

node js file (run.js):

#!/usr/bin/env node
var sys=require("sys"), fs = require('fs');

    require.extensions['.jse'] = function(module, filename) {
      var content = fs.readFileSync(filename, 'utf8');
      module.exports = content;
    };

require('./0.jse'):

console.log(require('./0.msc'))

jse file (0.jse):

#! /usr/bin/env node
console.log('IT WORKS!')

$ ls -al *.jse *.js

-rwxr-xr-x 1 alvaro alvaro 46 dic 6 17:26 0.jse
-rwxr-xr-x 1 alvaro alvaro 314 dic 6 17:32 run.js

file --mime *.js *.jse

run.js: text/plain; charset=us-ascii
0.jse:  text/plain; charset=us-ascii

$ node run.js

it outputs

#! /usr/bin/env node
console.log('IT WORKS!')

instead of:

IT WORKS!

whats wrong?

@bnoordhuis bnoordhuis closed this in c79fd0e Dec 6, 2012
@bnoordhuis
Node.js Foundation member

Thanks, I've removed the broken example in c79fd0e. You can't implement that functionality without depending on private internals anyway.

@alvarolm

how!?, can you give me a guide ? (:

@bnoordhuis
Node.js Foundation member

You compile it with module._compile(contents, filename).

@alvarolm

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment