Skip to content

Commit 9bb05ae

Browse files
authored
fix(node-resolve): Respect if other plugins resolve the resolution to a different id (#1181)
* fix(node-resolve): Respect if other plugins resolve the resolution to a different id * chore(node-resolve): Install pnpm 6 instead of 7
1 parent ae59ceb commit 9bb05ae

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

.github/workflows/node-windows.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
node-version: ${{ matrix.node }}
3737

3838
- name: install pnpm
39-
run: npm install pnpm -g
39+
run: npm install pnpm@6 -g
4040

4141
- name: pnpm install
4242
run: pnpm install --ignore-scripts

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
4444
- name: Install pnpm
4545
run: |
46-
npm install pnpm -g;
46+
npm install pnpm@6 -g;
4747
echo node `pnpm -v`;
4848
4949
- name: Set Git Config

.github/workflows/validate.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
run: git branch -f master origin/master
3535

3636
- name: Install pnpm
37-
run: npm install pnpm -g
37+
run: npm install pnpm@6 -g
3838

3939
- name: Sanity Check
4040
run: |

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)