Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ls() not returning an Array #446

Open
jcbohin opened this issue May 26, 2016 · 16 comments
Open

ls() not returning an Array #446

jcbohin opened this issue May 26, 2016 · 16 comments

Comments

@jcbohin
Copy link

jcbohin commented May 26, 2016

Node version:

v6.2.0

ShellJS version (the most recent version/Github branch you see the bug on):

0.7.0

Operating system:

OSX 15.5.0

Description of the bug:

shelljs.ls() returns an object containing results (files and folders as elements of the array) and a bunch of methods and no longer an Array (as it used to do until 0.7 and as described in the docs :

Returns array of files in the given path, or in current directory if no path provided.

Example ShellJS command to reproduce the error:

require('shelljs').ls('/')
@nfischer
Copy link
Member

It returns an array with some extra attributes. Does this break your code?

@jcbohin
Copy link
Author

jcbohin commented May 26, 2016

Well, I have some issues with the attributes that don't act as expected (especially for an Array), like sort() for example:

with shelljs@0.6.0:

> shelljs.ls('/tmp/').sort()
[ 'KSOutOfProcessFetcher.501.ppfIhqX0vjaTSb8AJYobDV7Cu68=',
  'VSCode Crashes',
  'com.apple.launchd.QWh3jiFEDS',
  'com.apple.launchd.TUty48UNRv',
  'com.apple.launchd.TX6hPuCu3V',
  'ct.shutdown',
  'test',
  'test-shelljs',
  'test2' ]
>

with shelljs@0.7.0:

> shelljs.ls('/tmp/').sort()
{ [String: 'com.apple.launchd.QWh3jiFEDS\ncom.apple.launchd.TUty48UNRv\ncom.apple.launchd.TX6hPuCu3V\nct.shutdown\nKSOutOfProcessFetcher.501.ppfIhqX0vjaTSb8AJYobDV7Cu68=\ntest\ntest-shelljs\ntest2\nVSCode Crashes\n']
  stdout: 'com.apple.launchd.QWh3jiFEDS\ncom.apple.launchd.TUty48UNRv\ncom.apple.launchd.TX6hPuCu3V\nct.shutdown\nKSOutOfProcessFetcher.501.ppfIhqX0vjaTSb8AJYobDV7Cu68=\ntest\ntest-shelljs\ntest2\nVSCode Crashes\n',
  stderr: null,
  code: 0,
  to: [Function],
  toEnd: [Function],
  cat: [Function],
  head: [Function],
  sed: [Function],
  sort: [Function],
  tail: [Function],
  grep: [Function],
  exec: [Function] }
>

I get the idea of pipes, but since I'm waiting for an array, I'm expecting "standard" array prototype methods to work as anywhere else.

@jcbohin
Copy link
Author

jcbohin commented May 26, 2016

As a side note, ls() does not behave like it did before 0.6, I now need to add a trailing / to paths to get content of a folder if I don't use glob:

with shelljs@0.6.0:

> shelljs.ls('/tmp')
[ 'KSOutOfProcessFetcher.501.ppfIhqX0vjaTSb8AJYobDV7Cu68=',
  'VSCode Crashes',
  'com.apple.launchd.QWh3jiFEDS',
  'com.apple.launchd.TUty48UNRv',
  'com.apple.launchd.TX6hPuCu3V',
  'ct.shutdown',
  'test',
  'test-shelljs',
  'test2' ]
> shelljs.ls('/tmp/')
[ 'KSOutOfProcessFetcher.501.ppfIhqX0vjaTSb8AJYobDV7Cu68=',
  'VSCode Crashes',
  'com.apple.launchd.QWh3jiFEDS',
  'com.apple.launchd.TUty48UNRv',
  'com.apple.launchd.TX6hPuCu3V',
  'ct.shutdown',
  'test',
  'test-shelljs',
  'test2' ]
>

with shelljs@0.7.0:

> shelljs.ls('/tmp')
[ '/tmp',
  stdout: '/tmp\n',
  stderr: null,
  code: 0,
  to: [Function],
  toEnd: [Function],
  cat: [Function],
  head: [Function],
  sed: [Function],
  sort: [Function],
  tail: [Function],
  grep: [Function],
  exec: [Function] ]
> shelljs.ls('/tmp/')
[ 'KSOutOfProcessFetcher.501.ppfIhqX0vjaTSb8AJYobDV7Cu68=',
  'VSCode Crashes',
  'com.apple.launchd.QWh3jiFEDS',
  'com.apple.launchd.TUty48UNRv',
  'com.apple.launchd.TX6hPuCu3V',
  'ct.shutdown',
  'test',
  'test-shelljs',
  'test2',
  stdout: 'KSOutOfProcessFetcher.501.ppfIhqX0vjaTSb8AJYobDV7Cu68=\nVSCode Crashes\ncom.apple.launchd.QWh3jiFEDS\ncom.apple.launchd.TUty48UNRv\ncom.apple.launchd.TX6hPuCu3V\nct.shutdown\ntest\ntest-shelljs\ntest2\n',
  stderr: null,
  code: 0,
  to: [Function],
  toEnd: [Function],
  cat: [Function],
  head: [Function],
  sed: [Function],
  sort: [Function],
  tail: [Function],
  grep: [Function],
  exec: [Function] ]
>

This second problem is not a big deal, but it sure breaks code for some.

@jcbohin
Copy link
Author

jcbohin commented May 26, 2016

PS: I get it if it's by design, but in this case maybe it should be advertised in the docs.

@nfischer
Copy link
Member

I now need to add a trailing / to paths to get content of a folder if I don't use glob:

Thanks for pointing that out. I'll investigate.

@nfischer
Copy link
Member

@jcbohin I can't reproduce the issue with the absence of the trailing /

Node v6.0, shelljs v0.7, Ubuntu

@jcbohin
Copy link
Author

jcbohin commented May 27, 2016

@nfischer I'm positive on the repro with Node v6.2, shelljs v0.7, OS X v15.5:

 jc@worm  /t/t/0.7 
 ❯ npm ls shelljs                                                                                                                                                                                                                                           [10:08:44]
/private/tmp/test-shelljs/0.7
└── shelljs@0.7.0


 jc@worm  /t/t/0.7 
 ❯ uname -a                                                                                                                                                                                                                                                 [10:08:47]
Darwin worm 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64

 jc@worm  /t/t/0.7 
 ❯ node --version                                                                                                                                                                                                                                           [10:09:05]
v6.2.0

 jc@worm  /t/t/0.7 
 ❯ node                                                                                                                                                                                                                                                     [10:09:09]
> require('shelljs').ls('/tmp')
[ '/tmp',
  stdout: '/tmp\n',
  stderr: null,
  code: 0,
  to: [Function],
  toEnd: [Function],
  cat: [Function],
  head: [Function],
  sed: [Function],
  sort: [Function],
  tail: [Function],
  grep: [Function],
  exec: [Function] ]
> require('shelljs').ls('/tmp/')
[ 'KSOutOfProcessFetcher.501.ppfIhqX0vjaTSb8AJYobDV7Cu68=',
  'VSCode Crashes',
  'com.apple.launchd.QWh3jiFEDS',
  'com.apple.launchd.TUty48UNRv',
  'com.apple.launchd.TX6hPuCu3V',
  'ct.shutdown',
  'test',
  'test-shelljs',
  'test2',
  stdout: 'KSOutOfProcessFetcher.501.ppfIhqX0vjaTSb8AJYobDV7Cu68=\nVSCode Crashes\ncom.apple.launchd.QWh3jiFEDS\ncom.apple.launchd.TUty48UNRv\ncom.apple.launchd.TX6hPuCu3V\nct.shutdown\ntest\ntest-shelljs\ntest2\n',
  stderr: null,
  code: 0,
  to: [Function],
  toEnd: [Function],
  cat: [Function],
  head: [Function],
  sed: [Function],
  sort: [Function],
  tail: [Function],
  grep: [Function],
  exec: [Function] ]
>

@jcbohin
Copy link
Author

jcbohin commented May 27, 2016

@nfischer you are right about ubuntu, I was unable to repro on Ubuntu with Node v5.11.1

Could be an OSX issue. Would you like me to create a separate issue (since it's different from the Array methods overriding discussed in this one ?)

Also if you don't have access to an OSX install I can help you pinpoint the problem and/or test a branch locally.

Edit: works fine with windows, definitively an os-specific case

@nfischer
Copy link
Member

@jcbohin Yeah, see if you can take a look at this issue on OS X. I'm going to open a PR adding a specific test case for this. If that PR fails (as your comments suggest it should on our OS X CI), then I'll open the issue.

@madkrupt
Copy link

I'm on OSX as well, having the same issue except with all the functions, even pwd() gives me an array of output rather than a single line

@nfischer
Copy link
Member

@ariporad could you please look into this?

@ariporad
Copy link
Contributor

ariporad commented Jun 22, 2016

@nfischer: Confirmed on macOS, looking into it.

@ariporad
Copy link
Contributor

OK, so I've figured this out:

On macOS, /tmp is symlinked to /private/tmp.
On macOS, fs.lstatSync('symlink2dir') is a file, but fs.lstatSync('symlink2dir/') is a directory...

This is basically our problem. I'm looking into it more.

Also, @jcbohin: We don't support OS X 15.5.0. It's not really a thing that exists 😝.

@ariporad
Copy link
Contributor

This appears to be just how lstat works on macOS.

@ariporad
Copy link
Contributor

Travis is conveniently experiencing an outage for their macOS workers at the moment.

@jcbohin
Copy link
Author

jcbohin commented Jun 23, 2016

@ariporad good catch, it's OS X 10.11.5 (the kernel is 15.5.0, as stated by uname -a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants