This morning I stumbled to my desk into a TypeScript codebase that was riddled with sym-linked dependencies from a debugging session the night before (created using yarn link
). Now was the time to undo the tangle, and to put things back as they were.
And that’s when I faced the first challenge of the day - how can I see a list of all my sym-linked dependencies? yarn link
provides no such option. Then I remembered a stack overflow article that I copied and pasted from the other day for this exact problem.
Too lazy to open a browser, I hit Ctrl + R and started typing a search query from what I vaguely remembered of the command. It had an ls
in there … And also a ^l
I remember, and lo and behold, I found it:
$ ( ls -l node_modules ; ls -l node_modules/@* ) | grep ^l
Great - and it worked as expected. But what is it doing?
Nothing special, but worth remembering:
ls
) all files inside node_modules
. Additionally, it accounts for scoped packages (prepended with @
). -l
flag is provided to produce a longer output format, effectively showing file permissions, owners, groups, size, etc.grep
to filter results with regex. It’s a simple expression: ^l
. Basically, only return lines that start with l
. And why is that? Because the first character of a file’s permissions denote what type of file it is:
-
is a regular filed
is a directoryl
is a linkBy listing all directories inside node_modules
and node_modules/@
and filtering those that start with l
, we effectively get a list of all sym-linked packages!