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

Commit 8f91234

Browse files
bterlsonlukastaegert
authored andcommitted
Support preserveSymlinks: false (fixes #400) (#401)
* Support preserveSymlinks: false (fixes #400) * remove only * Promise.prototype.finally is too new * Only realpath existing paths * Update appveyor to ensure symlinks are enabled
1 parent 1bc5896 commit 8f91234

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

appveyor.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ clone_depth: 10
66

77
init:
88
- git config --global core.autocrlf false
9+
- git config --global core.symlinks true
910

1011
environment:
1112
matrix:

src/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { realpathSync, existsSync } from 'fs';
12
import { extname, resolve } from 'path';
23
import { sync as nodeResolveSync, isCore } from 'resolve';
34
import { createFilter } from 'rollup-pluginutils';
@@ -39,8 +40,15 @@ export default function commonjs(options = {}) {
3940
} catch (err) {
4041
resolvedId = resolve(id);
4142
}
42-
4343
customNamedExports[resolvedId] = options.namedExports[id];
44+
45+
if (existsSync(resolvedId)) {
46+
const realpath = realpathSync(resolvedId);
47+
if (realpath !== resolvedId) {
48+
customNamedExports[realpath] = options.namedExports[id];
49+
}
50+
}
51+
4452
});
4553
}
4654

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import { foo } from 'events';

test/samples/symlinked-node-modules/node_modules/events

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test.js

+36
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,42 @@ describe('rollup-plugin-commonjs', () => {
342342
});
343343
});
344344

345+
it('handles symlinked node_modules with preserveSymlinks: false', () => {
346+
const cwd = process.cwd();
347+
348+
// ensure we resolve starting from a directory with
349+
// symlinks in node_modules.
350+
351+
process.chdir('samples/symlinked-node-modules');
352+
353+
return rollup({
354+
input: './index.js',
355+
onwarn(warning) {
356+
// should not get a warning about unknown export 'foo'
357+
throw new Error(`Unexpected warning: ${warning.message}`);
358+
},
359+
plugins: [
360+
resolve({
361+
preserveSymlinks: false,
362+
preferBuiltins: false
363+
}),
364+
commonjs({
365+
namedExports: {
366+
events: ['foo']
367+
}
368+
})
369+
]
370+
})
371+
.then(v => {
372+
process.chdir(cwd);
373+
return v;
374+
})
375+
.catch(err => {
376+
process.chdir(cwd);
377+
throw err;
378+
});
379+
});
380+
345381
it('handles named exports for built-in shims', async () => {
346382
const bundle = await rollup({
347383
input: 'samples/custom-named-exports-browser-shims/main.js',

0 commit comments

Comments
 (0)