Skip to content

Commit

Permalink
coffee#1715: node: .run now follows symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
satyr committed Sep 21, 2011
1 parent 375ac0c commit afdc975
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ module.exports = function(Coco){
main.moduleCache && (main.moduleCache = {});
filename = '.';
if (that = options.filename) {
try {
that = fs.readlinkSync(that);
} catch (_e) {}
main.paths = main.constructor._nodeModulePaths(path.dirname(that));
filename = process.argv[1] = path.resolve(that);
}
main.filename = filename;
options.js || (code = Coco.compile(code, options));
options.js || (code = Coco.compile(code, {
filename: filename,
bare: true
}));
try {
return main._compile(code, filename);
} catch (e) {
Expand Down Expand Up @@ -46,9 +52,7 @@ function hackTrace(error, js, filename){
if (0 > (index = trace.indexOf(filename))) {
continue;
}
if ((_ref = /:(\d+):/.exec(trace.slice(index + filename.length))) != null) {
lno = _ref[1];
}
lno = (/:(\d+):/.exec(trace.slice(index + filename.length)) || '')[1];
if (!(lno = +lno)) {
continue;
}
Expand Down
5 changes: 3 additions & 2 deletions src/node.co
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ module.exports = (Coco) ->
# Hack for relative `require`.
filename = \.
if options.filename
try that = fs.readlinkSync that
main.paths = main.._nodeModulePaths path.dirname that
filename = process.argv.1 = path.resolve that
main <<< {filename}
options.js or code = Coco.compile code, options
options.js or code = Coco.compile code, {filename, +bare}
try main._compile code, filename catch throw hackTrace e, code, filename

Coco import all require(\events)EventEmitter::
Expand All @@ -31,7 +32,7 @@ function hackTrace error, js, filename
return error unless traces.length > 1
for trace, i of traces
continue if 0 > index = trace.indexOf filename
[, lno]? = /:(\d+):/exec trace.slice index + filename.length
{1: lno} = /:(\d+):/exec trace.slice index + filename.length or ''
continue unless +=lno
{length} = '' + end = lno+4; lines ||= js / \\n
for n from 1 >? lno-4 to end
Expand Down

0 comments on commit afdc975

Please sign in to comment.