Skip to content

Commit f8d4c44

Browse files
committedMay 1, 2022
fix(node-resolve): Respect if other plugins resolve the resolution to a different id
1 parent b8cf7b8 commit f8d4c44

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
 

‎packages/node-resolve/src/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ export function nodeResolve(opts = {}) {
281281
if (resolvedResolved.external) {
282282
return false;
283283
}
284+
// Allow other plugins to take over resolution. Rollup core will not
285+
// change the id if it corresponds to an existing file
286+
if (resolvedResolved.id !== resolved.id) {
287+
return resolvedResolved;
288+
}
284289
// Pass on meta information added by other plugins
285290
return { ...resolved, meta: resolvedResolved.meta };
286291
}

‎packages/node-resolve/test/test.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join, resolve } from 'path';
1+
import { join, resolve, dirname } from 'path';
22

33
import test from 'ava';
44
import { rollup } from 'rollup';
@@ -581,3 +581,31 @@ test('passes on meta information from other plugins', async (t) => {
581581
]
582582
});
583583
});
584+
585+
test('allow other plugins to take over resolution', async (t) => {
586+
await rollup({
587+
input: 'entry/main.js',
588+
onwarn: failOnWarn(t),
589+
plugins: [
590+
nodeResolve(),
591+
{
592+
name: 'change-resolution',
593+
resolveId(importee) {
594+
if (importee.endsWith('main.js')) {
595+
return {
596+
id: join(dirname(importee), 'other.js'),
597+
meta: { 'change-resolution': 'changed' }
598+
};
599+
}
600+
return null;
601+
},
602+
603+
load(id) {
604+
const info = this.getModuleInfo(id);
605+
t.is(info.id, join(__dirname, 'fixtures', 'entry', 'other.js'));
606+
t.deepEqual(info.meta, { 'change-resolution': 'changed' });
607+
}
608+
}
609+
]
610+
});
611+
});

0 commit comments

Comments
 (0)
Please sign in to comment.