Skip to content

Commit

Permalink
fix(node-resolve): resolve symlinked entry point properly (#291)
Browse files Browse the repository at this point in the history
The regression appeared here uuidjs/uuid#402 (comment)
after upgrading from `rollup-plugin-node-resolve` to `@rollup/plugin-node-solve`

Dependencies entry points are resolved into symlinked path when browser
field map contains paths resolved into real paths.
  • Loading branch information
TrySound authored Apr 12, 2020
1 parent 5a71385 commit 37db2a2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/node-resolve/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'not random string';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "second",
"main": "./index.js",
"browser": {
"./index.js": "./index.browser.js"
}
}
10 changes: 10 additions & 0 deletions packages/node-resolve/test/symlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 37db2a2

Please sign in to comment.