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

Commit

Permalink
Support preserveSymlinks: false (fixes #400) (#401)
Browse files Browse the repository at this point in the history
* Support preserveSymlinks: false (fixes #400)

* remove only

* Promise.prototype.finally is too new

* Only realpath existing paths

* Update appveyor to ensure symlinks are enabled
  • Loading branch information
bterlson authored and lukastaegert committed Aug 3, 2019
1 parent 1bc5896 commit 8f91234
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions appveyor.yml
Expand Up @@ -6,6 +6,7 @@ clone_depth: 10

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

environment:
matrix:
Expand Down
10 changes: 9 additions & 1 deletion src/index.js
@@ -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
@@ -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
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

0 comments on commit 8f91234

Please sign in to comment.