To summarize the issue and solution:

When you `npm install` a local path, npm will create a link from the local path 
to your target `node_modules`. When `npm` creates links, it will always pass 
`"junction"` as the third argument. This argument is only relevant on Windows 
and the default value is `"file"`.

Windows distinguishes between different types of links, just like UNIX does, 
but differently. The most important distinctions are between *file* and 
*directory* **symlinks** and **junctions** (or reparse points). Instinctively, 
every developer would want to just use symlinks on Windows as well, but 
junctions are usually preferable. A symlink on Windows is much more versatile, 
but we usually don't care about the extra functionality and we also don't want 
to care about the file/directory distinction. For all intents and purposes, a 
junction is the way to go. As junctions can only be used to link directories 
and symbolic links are problematic, you are left with the limitation that you 
can really only easily and properly link *directories* on Windows.

So when you instruct NodeJS to create a symlink on Windows and you don't pass a 
third argument, NodeJS will create a *file* symlink. [This will usually fail, 
because the user is not allowed to create 
symlinks.](https://security.stackexchange.com/questions/10194/why-do-you-have-to-be-an-admin-to-create-a-symlink-in-windows)
 That is one of the main reasons to always use junctions on Windows.

Now when we're instructing `fs-extra` to copy the directory (which is an 
existing junction), it will detect it as being a symlink (in its own terms; 
it's still a junction) and instead of copying just create a link between source 
and destination [**without specifying "junction" as the third 
argument**](https://github.com/jprichardson/node-fs-extra/blob/402c1d05727f2f9414a4905ffa75f4fa1d99461c/lib/copy-sync/copy-sync.js#L129).
 This will instruct NodeJS to create a *file* symlink. That either fails 
instantly or creates the file symlink when the target is actually a directory.

So by passing `dereference`, we're letting `fs-extra` know that we care about 
the referenced directory and not the link itself. It will then properly copy 
the directory.

I'm not sure why `fs-extra` doesn't use `"junction"` or any other kind of 
detection for this when creating symlinks.

[ Full content available at: https://github.com/apache/cordova-lib/pull/705 ]
This message was relayed via gitbox.apache.org for [email protected]

Reply via email to