From 56d2be9a4143f0c7e66e623588379eab1d82fc6c Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Mon, 3 Aug 2020 08:54:55 -0700 Subject: [PATCH] fix #310: support symlinks with absolute paths --- CHANGELOG.md | 6 ++++++ internal/fs/fs.go | 5 ++++- scripts/end-to-end-tests.js | 14 +++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3afe9edc14..f8b1335acd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/internal/fs/fs.go b/internal/fs/fs.go index 4b5bb9ebe33..69c2bb071b6 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -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) diff --git a/scripts/end-to-end-tests.js b/scripts/end-to-end-tests.js index fa4743e7c83..1857f50ca5e 100644 --- a/scripts/end-to-end-tests.js +++ b/scripts/end-to-end-tests.js @@ -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` }, + }), ) } @@ -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) }