nexe: fs.readdir not working properly on any directory in application's path

What happened:

fs.readdir() and fs.readdirSync() don’t seem to work properly on any directory in the application’s path.

For example, if the application is in ~/GitHub/javascript-experiments/nexe-test, attempting to read any parent directory returns only the directory names which are part of the application’s path.

What you expected to happen:

When running the test code via node, the complete contents of my home directory are shown correctly:

[ Dirent { name: '.ICEauthority', [Symbol(type)]: 1 },
  Dirent { name: '.bash_history', [Symbol(type)]: 1 },
  Dirent { name: '.bash_logout', [Symbol(type)]: 1 },
  Dirent { name: '.bashrc', [Symbol(type)]: 1 },
  Dirent { name: '.cache', [Symbol(type)]: 2 },
  Dirent { name: '.config', [Symbol(type)]: 2 },
  Dirent { name: '.dbus', [Symbol(type)]: 2 },
  Dirent { name: '.gnupg', [Symbol(type)]: 2 },
  Dirent { name: '.local', [Symbol(type)]: 2 },
  Dirent { name: '.mozilla', [Symbol(type)]: 2 },
  Dirent { name: '.nexe', [Symbol(type)]: 2 },
  Dirent { name: '.node_repl_history', [Symbol(type)]: 1 },
  Dirent { name: '.npm', [Symbol(type)]: 2 },
  Dirent { name: '.pkg-cache', [Symbol(type)]: 2 },
  Dirent { name: '.pki', [Symbol(type)]: 2 },
  Dirent { name: '.profile', [Symbol(type)]: 1 },
  Dirent { name: '.ssh', [Symbol(type)]: 2 },
  Dirent { name: 'Desktop', [Symbol(type)]: 2 },
  Dirent { name: 'Documents', [Symbol(type)]: 2 },
  Dirent { name: 'Downloads', [Symbol(type)]: 2 },
  Dirent { name: 'GitHub', [Symbol(type)]: 2 },
  Dirent { name: 'Music', [Symbol(type)]: 2 },
  Dirent { name: 'Pictures', [Symbol(type)]: 2 },
  Dirent { name: 'Public', [Symbol(type)]: 2 },
  Dirent { name: 'Templates', [Symbol(type)]: 2 },
  Dirent { name: 'Videos', [Symbol(type)]: 2 } ]

Output of compiled application shows only the next directory in the application’s path and returns an array of strings, instead of Dirent objects.

[ 'GitHub' ]

If I move the application’s executable file outside my home directory, or if I change the code to read another directory (like /var), the output is correct.

See also a simpler example in my other comment

How to reproduce it (as minimally and precisely as possible):

const fs = require('fs'),
      homedir = require('os').homedir(),
      entries = fs.readdirSync( homedir, { withFileTypes: true } );

console.log( entries );

Environment:

  • Platform(OS/Version): Debian 10 / Windows 10 (both Pro and Home)
  • Host Node Version: 12.14.0, 12.14.1
  • Target Node Version: 12.14.0, 12.14.1
  • Nexe version: 3.3.2 / 4.0.0-beta.3
  • Python Version: 2.7.16, 2.7.17

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 5
  • Comments: 16 (1 by maintainers)

Most upvoted comments

But the main problem, at least for me, is that fs.readdir simply won’t list all the files/directories, even without the withFileTypes option.

Suppose I have this directory structure:

  • c:\
    • stuff\
      • apps\
      • games\
      • music\

Now, I compile the code below (no withFileTypes option) with nexe and name it test.exe:

const fs = require('fs'),
      entries = fs.readdirSync( process.argv[2] );

console.log( entries );

Supposing test.exe is in c:\Users\hvianna\Documents\ (not in the path of the directory I’m trying to read), if I run:

test c:\stuff

I’ll get:

[ 'apps', 'games', 'music' ]

Now, I move test.exe to c:\stuff\apps and run it from there:

cd \stuff\apps
test c:\stuff

And that’s what I get:

[ 'apps' ]

It only sees the path to the executable application itself, and completely ignores the other directories.

This becomes a real problem when both the application and the data directories are located, for example, under the user’s home directory, even in different subdirectories, which is very much likely to happen.

Maybe the solution would be using a virtual entrypoint for the application files inside the package, like pkg does?