isaacs / node-glob

glob functionality for node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add an option to return real paths for symlinks

bajtos opened this issue · comments

Node Inspector is using glob to find all javascript files that may be loaded later by node in order to allow developers to set breakpoints in files before they are loaded. This is useful e.g. when debugging unit-tests via node --debug-brk, as the test files are loaded later by the test runner.

At the moment, this mechanism does not work for symlinked files (typically via npm link {module}), because glob returns paths in project's node_modules folder, while node resolves all symlinks to real paths before passing the filename to V8.

I am proposing to add a glob option to tell it to convert symlinks to real paths. While this can be implemented by Node Inspector as a post-processing step calling fs.realpath on all items returned by glob, it seems to me that we can get better performance by implementing this feature in glob, as it is already fs API.

Example

File layout:

~/my-module
~/my-module/node_modules
~/my-module/node_modules/debug -> /usr/local/lib/node_modules/debug
~/my-module/index.js
/usr/local/lib/node_modules/debug
/usr/local/lib/node_modules/debug/debug.js
/usr/local/lib/node_modules/debug/node.js

Expected result for glob('**/*.js', { cwd: '~/my-module', realpaths: true }):

~/my-module/index.js
/usr/local/lib/node_modules/debug/debug.js
/usr/local/lib/node_modules/debug/node.js

Patch welcome. Make sure to add tests for both sync and async behavior. The option should be realpath:true (to better match stat:true behavior).

Make sure to take advantage of the cache option to fs.realpath, so that it can avoid statting the same paths multiple times.

Thanks. I don't have time to work on this right now, but perhaps one of Node Inspector users will be willing to contribute the patch.