src/PackageEnvironment.js
/**
 * Ejects a path for the sake of printing to a shell script/Makefile to be
 * executed on a different host. We therefore print it relative to an abstract
 * and not-yet-assigned $ESY__SANDBOX.
 *
 * This is the use case:
 *
 * 0. Run npm install.
 * 1. Don't build.
 * 3. Generate shell script/makefile.
 * 4. tar the entire directory with the --dereference flag.
 * 5. scp it to a host where node isn't even installed.
 * 6. untar it with the -h flag.
 *
 * All internal symlinks will be preserved. I *believe* --dereference will copy
 * contents if symlink points out of the root location (I hope).
 *
 * So our goal is to ensure that the locations we record point to the realpath
 * if a location is actually a symlink to somewhere in the sandbox, but encode
 * the path (including symlinks) if it points outside the sandbox.  I believe
 * that will work with tar --dereference.
 */
Ejects a path for the sake of printing to a shell script/Makefile to be
executed on a different host. We therefore print it relative to an abstract
and not-yet-assigned $ESY__SANDBOX.

This is the use case.

0. Run npm install.
1. Don't build.
3. Generate shell script/makefile.
4. tar the entire directory with the --dereference flag.
5. scp it to a host where node isn't even installed.
6. untar it with the -h flag.

All internal symlinks will be preserved. I *believe* --dereference will copy
contents if symlink points out of the root location (I hope).

So our goal is to ensure that the locations we record point to the realpath
if a location is actually a symlink to somewhere in the sandbox, but encode
the path (including symlinks) if it points outside the sandbox.  I believe
that will work with tar --dereference.
Ejects a path for the sake of printing to a shell script / Makefile to be executed on a different host . We therefore print it relative to an abstract and not - yet - assigned $ESY__SANDBOX . This is the use case . 0 . Run npm install . 1 . Don ' t build . 3 . Generate shell script / makefile . 4 . tar the entire directory with the -- dereference flag . 5 . scp it to a host where node isn ' t even installed . 6 . untar it with the - h flag . All internal symlinks will be preserved . I * believe * -- dereference will copy contents if symlink points out of the root location ( I hope ) . So our goal is to ensure that the locations we record point to the realpath if a location is actually a symlink to somewhere in the sandbox but encode the path ( including symlinks ) if it points outside the sandbox . I believe that will work with tar -- dereference .
function relativeToSandbox(realFromPath, toPath) {
  let realToPath = fs.realpathSync(toPath);
  let toPathToUse = pathIsInside(realFromPath, realToPath)
    ? realToPath
    : toPath;
  let ret = path.relative(realFromPath, toPathToUse);
  return (ret == '0') ? "$esy__sandbox" : `$esy__sandbox/${ret}`;
}
function relativeToSandbox ( realFromPath , toPath ) { let realToPath = fs . realpathSync ( toPath ) ; let toPathToUse = pathIsInside ( realFromPath , realToPath ) ? realToPath : toPath ; let ret = path . relative ( realFromPath , toPathToUse ) ; return ( ret == '0' ) ? "$esy__sandbox" : ` ${ ret } ` ; }
Ejects a path for the sake of printing to a shell script/Makefile to be
 executed on a different host.
Ejects a path for the sake of printing to a shell script / Makefile to be executed on a different host .
/**
   * This sucks. If there's a symlink pointing outside of the sandbox, the
   * script can't include those, so it gives it from perspective of symlink.
   * This will work with tar, but there could be issues if multiple symlink
   * links all point to the same location, but appear to be different.  We
   * should execute a warning here instead. This problem is far from solved.
   * What would tar even do in that situation if it's following symlinks
   * outside of the tar directory? Would it copy it multiple times or copy it
   * once somehow?
   */