shelljs / shx

Portable Shell Commands for Node
MIT License
1.73k stars 45 forks source link

Feature: Symbolic Links #119

Closed ilyaigpetrov closed 7 years ago

ilyaigpetrov commented 7 years ago

I need to create a symbolic to a relative folder. Here is how I do it with windows in mind:

const dirFileOrJunction = 'dir';
fs.symlink(targetPath, linkPath, dirFileOrJunction, (err) => {

  if(!err) {
    return;
  }

  if (!process.platform.startsWith('win')) {
    throw err;
  }

  // Error on Windows
  child_process.exec(`mklink /D ${linkPath} ${targetPath}`, (err, stdout, stderr) => {

    if (!err) {
        return;
    }
    // Try junction (will be absolute).
    child_process.execSync(`mklink /J ${linkPath} ${targetPath}`);

  });

})
nfischer commented 7 years ago

ln -s?

ilyaigpetrov commented 7 years ago

@nfischer, right, ln -s.

nfischer commented 7 years ago

No, I mean shx ln -s foo bar should work, does it not?

ilyaigpetrov commented 7 years ago

Yes, it works on Linux, Windows yet to test. Couldn't find any documentation about it. Thanks.

nfischer commented 7 years ago

Documentation is under the shelljs repo. If shell.ln('-s', 'foo', 'bar') doesn't work on Windows, please file a bug against that repo.