Skip to content
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
2 changes: 1 addition & 1 deletion packages/node-resolve/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export function nodeResolve(opts = {}) {
// `moduleSideEffects` information.
const resolvedResolved = await this.resolve(resolved.id, importer, {
...resolveOptions,
custom: { ...custom, 'node-resolve': { resolved } }
custom: { ...custom, 'node-resolve': { ...custom['node-resolve'], resolved } }
});
if (resolvedResolved) {
// Handle plugins that manually make the result external
Expand Down
4 changes: 4 additions & 0 deletions packages/node-resolve/test/fixtures/cyclic-commonjs/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exports.main = 'main';
const other = require('./other.js');

t.is(other.main, 'main');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { main } = require('./main.js');

exports.main = main;
15 changes: 15 additions & 0 deletions packages/node-resolve/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ test('finds and converts a basic CommonJS module', async (t) => {
t.is(module.exports, 'It works!');
});

test('handles cyclic CommonJS modules', async (t) => {
const bundle = await rollup({
input: 'cyclic-commonjs/main.js',
onwarn(warning) {
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
t.fail(`Unexpected warning:\n${warning.code}\n${warning.message}`);
}
},
plugins: [nodeResolve(), commonjs()]
});
const { module } = await testBundle(t, bundle);

t.is(module.exports.main, 'main');
});

test('handles a trailing slash', async (t) => {
const bundle = await rollup({
input: 'trailing-slash.js',
Expand Down