Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: relative link error #308

Merged
merged 12 commits into from
May 2, 2024
11 changes: 6 additions & 5 deletions lib/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ class Filesystem {
}

insertLink (p) {
const symlink = fs.readlinkSync(p)
const parentPath = path.dirname(p)
const link = path.relative(fs.realpathSync(this.src), path.join(parentPath, symlink))
if (link.substr(0, 2) === '..') {
throw new Error(`${p}: file "${link}" links out of the package`)
const realSrcPath = fs.realpathSync(this.src)
const target = path.join(path.dirname(p), fs.readlinkSync(p))
const relativePath = path.relative(realSrcPath, fs.realpathSync(target))
if (relativePath.startsWith('..')) {
throw new Error(`${p}: file "${relativePath}" links out of the package`)
}
const link = path.relative(realSrcPath, target)
const node = this.searchNodeFromPath(p)
node.link = link
return link
Expand Down