coreutils.js icon indicating copy to clipboard operation
coreutils.js copied to clipboard

What node version is this designed for?

Open alspore opened this issue 11 years ago • 9 comments

I've been having some problems with version v0.12.1 distributed in the upstream Arch Linux repos, though v0.10.38 has had no problems.

alspore avatar Apr 01 '15 18:04 alspore

I started this 6 months ago and then only v0.10 was available, but I don't think it should be difficult to adapt to v0.12 if there are any issue.

piranna avatar Apr 01 '15 18:04 piranna

Cool. I'm going to try to update everything. For now, here are the outputs of the incompatible scripts.

date.js

util.js:0
(function (exports, require, module, __filename, __dirname) { // Copyright Joy

RangeError: Maximum call stack size exceeded
    at isFunction (util.js)
    at formatValue (util.js:217:7)
    at formatValue (util.js:224:13)
    at formatValue (util.js:224:13)
    at formatValue (util.js:224:13)
    at formatValue (util.js:224:13)
    at formatValue (util.js:224:13)
    at formatValue (util.js:224:13)
    at formatValue (util.js:224:13)
    at formatValue (util.js:224:13)

ls.js

_common.js  cat.js  cd.js  date.js  echo.js  grep.js  index.js  ls.js  sort.js  /home/aaron/coreutils.js/lib/_common.js:122
    else if(chunk.inspect)
                 ^
TypeError: Cannot read property 'inspect' of undefined
    at InspectStream._transform (/home/aaron/coreutils.js/lib/_common.js:122:18)
    at InspectStream.Transform._read (_stream_transform.js:179:10)
    at InspectStream.Transform._write (_stream_transform.js:167:12)
    at doWrite (_stream_writable.js:301:12)
    at writeOrBuffer (_stream_writable.js:288:5)
    at InspectStream.Writable.write (_stream_writable.js:217:11)
    at ls.ondata (_stream_readable.js:540:20)
    at ls.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at ls.Readable.push (_stream_readable.js:126:10)

alspore avatar Apr 01 '15 18:04 alspore

:+1: inspect() is done so it can be output its content on the REPL as a result, but I'm thinking to remove it since it couldn't work for streams, that probably is a better API for Node.js, so instead the commands craft stream pipeline objects and to output content just use .pipe() to stdout. It could be more dificult to use, but more versalite and coherent with Node.js style. What do you think?

piranna avatar Apr 01 '15 19:04 piranna

date.js seems to work if I remove the following lines. I'm not too familiar with prototypes in javascript. What's the purpose of this bit?

function inspect()
{
  return result
}

Object.defineProperty(result, 'inspect', {value: inspect})

alspore avatar Apr 01 '15 19:04 alspore

https://nodejs.org/api/util.html#util_custom_inspect_function_on_objects ;-)

piranna avatar Apr 01 '15 19:04 piranna

Thanks!

alspore avatar Apr 01 '15 19:04 alspore

You are welcome :-)

piranna avatar Apr 01 '15 19:04 piranna

Ooh, the pipes would be nice. So I gather the commands would send the pipes as return values of the exposed api.

alspore avatar Apr 01 '15 19:04 alspore

Yes, that's the idea, instead of exec commands, you would build pipeline objects that can be moved around without consume data, and when you are ready, pipe the output to a file or stdout or whatever :-) Later it could be build a more "classic" bash-like shell on top of this.

piranna avatar Apr 01 '15 19:04 piranna