diff --git a/packages/node-resolve/src/util.js b/packages/node-resolve/src/util.js index 03065d20d..bfc0a16e2 100644 --- a/packages/node-resolve/src/util.js +++ b/packages/node-resolve/src/util.js @@ -171,7 +171,12 @@ export function resolveImportSpecifiers(importSpecifierList, resolveOptions) { return value; } - return resolveId(importSpecifierList[i], resolveOptions); + return resolveId(importSpecifierList[i], resolveOptions).then((result) => { + if (!resolveOptions.preserveSymlinks) { + result = realpathSync(result); + } + return result; + }); }); if (i < importSpecifierList.length - 1) { diff --git a/packages/node-resolve/test/fixtures/symlinked/second/index.browser.js b/packages/node-resolve/test/fixtures/symlinked/second/index.browser.js new file mode 100644 index 000000000..0a32e68ca --- /dev/null +++ b/packages/node-resolve/test/fixtures/symlinked/second/index.browser.js @@ -0,0 +1 @@ +export default 'not random string'; diff --git a/packages/node-resolve/test/fixtures/symlinked/second/package.json b/packages/node-resolve/test/fixtures/symlinked/second/package.json new file mode 100644 index 000000000..7c0753e37 --- /dev/null +++ b/packages/node-resolve/test/fixtures/symlinked/second/package.json @@ -0,0 +1,7 @@ +{ + "name": "second", + "main": "./index.js", + "browser": { + "./index.js": "./index.browser.js" + } +} diff --git a/packages/node-resolve/test/symlinks.js b/packages/node-resolve/test/symlinks.js index 600c6b7f6..e3732ab7d 100644 --- a/packages/node-resolve/test/symlinks.js +++ b/packages/node-resolve/test/symlinks.js @@ -53,6 +53,16 @@ test.serial('resolves symlinked packages', async (t) => { t.is(module.exports.number1, module.exports.number2); }); +test.serial('resolves symlinked packages with browser object', async (t) => { + const bundle = await rollup({ + input: 'symlinked/first/index.js', + onwarn: () => t.fail('No warnings were expected'), + plugins: [nodeResolve({ browser: true })] + }); + const { module } = await testBundle(t, bundle); + t.is(module.exports.number1, 'not random string'); +}); + test.serial('preserves symlinks if `preserveSymlinks` is true', async (t) => { const bundle = await rollup({ input: 'symlinked/first/index.js',