Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Support preserveSymlinks: false (fixes #400) #401

Merged
merged 5 commits into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ clone_depth: 10

init:
- git config --global core.autocrlf false
- git config --global core.symlinks true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice you found this! This could be useful for Rollup core as well.


environment:
matrix:
Expand Down
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { realpathSync, existsSync } from 'fs';
import { extname, resolve } from 'path';
import { sync as nodeResolveSync, isCore } from 'resolve';
import { createFilter } from 'rollup-pluginutils';
Expand Down Expand Up @@ -39,8 +40,15 @@ export default function commonjs(options = {}) {
} catch (err) {
resolvedId = resolve(id);
}

customNamedExports[resolvedId] = options.namedExports[id];

if (existsSync(resolvedId)) {
const realpath = realpathSync(resolvedId);
if (realpath !== resolvedId) {
customNamedExports[realpath] = options.namedExports[id];
}
}

});
}

Expand Down
1 change: 1 addition & 0 deletions test/samples/symlinked-node-modules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { foo } from 'events';
1 change: 1 addition & 0 deletions test/samples/symlinked-node-modules/node_modules/events

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,42 @@ describe('rollup-plugin-commonjs', () => {
});
});

it('handles symlinked node_modules with preserveSymlinks: false', () => {
const cwd = process.cwd();

// ensure we resolve starting from a directory with
// symlinks in node_modules.

process.chdir('samples/symlinked-node-modules');

return rollup({
input: './index.js',
onwarn(warning) {
// should not get a warning about unknown export 'foo'
throw new Error(`Unexpected warning: ${warning.message}`);
},
plugins: [
resolve({
preserveSymlinks: false,
preferBuiltins: false
}),
commonjs({
namedExports: {
events: ['foo']
}
})
]
})
.then(v => {
process.chdir(cwd);
return v;
})
.catch(err => {
process.chdir(cwd);
throw err;
});
});

it('handles named exports for built-in shims', async () => {
const bundle = await rollup({
input: 'samples/custom-named-exports-browser-shims/main.js',
Expand Down