Skip to content

Commit

Permalink
fix #310: support symlinks with absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Aug 3, 2020
1 parent b3ff330 commit 56d2be9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

* Support symlinks with absolute paths in `node_modules` ([#310](https://github.com/evanw/esbuild/issues/310))

Previously esbuild only supported symlinks with relative paths, not absolute paths. Adding support for absolute paths in symlinks fixes issues with esbuild and [pnpm](https://github.com/pnpm/pnpm) on Windows.

## 0.6.14

* Add support for parsing top-level await ([#253](https://github.com/evanw/esbuild/issues/253))
Expand Down
5 changes: 4 additions & 1 deletion internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ func (fs *realFS) ReadDirectory(dir string) map[string]Entry {
if err != nil {
continue // Skip over this entry
}
symlink = filepath.Clean(filepath.Join(dir, link))
if !filepath.IsAbs(link) {
link = filepath.Join(dir, link)
}
symlink = filepath.Clean(link)

// Re-run "lstat" on the symlink target
stat2, err2 := os.Lstat(symlink)
Expand Down
14 changes: 13 additions & 1 deletion scripts/end-to-end-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@
'registry/node_modules/bar/index.js': `export const bar = 123`,
'node_modules/foo/index.js': { symlink: `../../registry/node_modules/foo/index.js` },
}),
test(['--bundle', 'in.js', '--outfile=node.js'], {
'in.js': `import {foo} from 'foo'; if (foo !== 123) throw 'fail'`,
'registry/node_modules/foo/index.js': `export {bar as foo} from 'bar'`,
'registry/node_modules/bar/index.js': `export const bar = 123`,
'node_modules/foo': { symlink: `TEST_DIR_ABS_PATH/registry/node_modules/foo` },
}),
test(['--bundle', 'in.js', '--outfile=node.js'], {
'in.js': `import {foo} from 'foo'; if (foo !== 123) throw 'fail'`,
'registry/node_modules/foo/index.js': `export {bar as foo} from 'bar'`,
'registry/node_modules/bar/index.js': `export const bar = 123`,
'node_modules/foo/index.js': { symlink: `TEST_DIR_ABS_PATH/registry/node_modules/foo/index.js` },
}),
)
}

Expand Down Expand Up @@ -793,7 +805,7 @@
mkdirp.sync(path.dirname(filePath))

// Optionally symlink the file if the test requests it
if (contents.symlink) await symlinkAsync(contents.symlink, filePath)
if (contents.symlink) await symlinkAsync(contents.symlink.replace('TEST_DIR_ABS_PATH', thisTestDir), filePath)
else await writeFileAsync(filePath, contents)
}

Expand Down

0 comments on commit 56d2be9

Please sign in to comment.