Fixes #3047 -- Fixes module.paths when running directly with no explicit passed-in files.
This commit is contained in:
parent
c820e0241e
commit
a5513c45d0
|
@ -103,14 +103,15 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
exports.run = function(code, options) {
|
exports.run = function(code, options) {
|
||||||
var answer, mainModule, _ref;
|
var answer, dir, mainModule, _ref;
|
||||||
if (options == null) {
|
if (options == null) {
|
||||||
options = {};
|
options = {};
|
||||||
}
|
}
|
||||||
mainModule = require.main;
|
mainModule = require.main;
|
||||||
mainModule.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '.';
|
mainModule.filename = process.argv[1] = options.filename ? fs.realpathSync(options.filename) : '.';
|
||||||
mainModule.moduleCache && (mainModule.moduleCache = {});
|
mainModule.moduleCache && (mainModule.moduleCache = {});
|
||||||
mainModule.paths = require('module')._nodeModulePaths(path.dirname(fs.realpathSync(options.filename || '.')));
|
dir = options.fileName ? path.dirname(fs.realpathSync(options.filename)) : fs.realpathSync('.');
|
||||||
|
mainModule.paths = require('module')._nodeModulePaths(dir);
|
||||||
if (!helpers.isCoffee(mainModule.filename) || require.extensions) {
|
if (!helpers.isCoffee(mainModule.filename) || require.extensions) {
|
||||||
answer = compile(code, options);
|
answer = compile(code, options);
|
||||||
code = (_ref = answer.js) != null ? _ref : answer;
|
code = (_ref = answer.js) != null ? _ref : answer;
|
||||||
|
|
|
@ -107,7 +107,11 @@ exports.run = (code, options = {}) ->
|
||||||
mainModule.moduleCache and= {}
|
mainModule.moduleCache and= {}
|
||||||
|
|
||||||
# Assign paths for node_modules loading
|
# Assign paths for node_modules loading
|
||||||
mainModule.paths = require('module')._nodeModulePaths path.dirname fs.realpathSync options.filename or '.'
|
dir = if options.fileName
|
||||||
|
path.dirname fs.realpathSync options.filename
|
||||||
|
else
|
||||||
|
fs.realpathSync '.'
|
||||||
|
mainModule.paths = require('module')._nodeModulePaths dir
|
||||||
|
|
||||||
# Compile.
|
# Compile.
|
||||||
if not helpers.isCoffee(mainModule.filename) or require.extensions
|
if not helpers.isCoffee(mainModule.filename) or require.extensions
|
||||||
|
|
Loading…
Reference in New Issue