Skip to content

Commit

Permalink
fix(node-resolve): Respect if other plugins resolve the resolution to…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
lukastaegert committed May 2, 2022
1 parent ae59ceb commit 9bb05ae
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node-windows.yml
Expand Up @@ -36,7 +36,7 @@ jobs:
node-version: ${{ matrix.node }}

- name: install pnpm
run: npm install pnpm -g
run: npm install pnpm@6 -g

- name: pnpm install
run: pnpm install --ignore-scripts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Install pnpm
run: |
npm install pnpm -g;
npm install pnpm@6 -g;
echo node `pnpm -v`;
- name: Set Git Config
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Expand Up @@ -34,7 +34,7 @@ jobs:
run: git branch -f master origin/master

- name: Install pnpm
run: npm install pnpm -g
run: npm install pnpm@6 -g

- name: Sanity Check
run: |
Expand Down
5 changes: 5 additions & 0 deletions packages/node-resolve/src/index.js
Expand Up @@ -281,6 +281,11 @@ export function nodeResolve(opts = {}) {
if (resolvedResolved.external) {
return false;
}
// Allow other plugins to take over resolution. Rollup core will not
// change the id if it corresponds to an existing file
if (resolvedResolved.id !== resolved.id) {
return resolvedResolved;
}
// Pass on meta information added by other plugins
return { ...resolved, meta: resolvedResolved.meta };
}
Expand Down
30 changes: 29 additions & 1 deletion packages/node-resolve/test/test.js
@@ -1,4 +1,4 @@
import { join, resolve } from 'path';
import { join, resolve, dirname } from 'path';

import test from 'ava';
import { rollup } from 'rollup';
Expand Down Expand Up @@ -581,3 +581,31 @@ test('passes on meta information from other plugins', async (t) => {
]
});
});

test('allow other plugins to take over resolution', async (t) => {
await rollup({
input: 'entry/main.js',
onwarn: failOnWarn(t),
plugins: [
nodeResolve(),
{
name: 'change-resolution',
resolveId(importee) {
if (importee.endsWith('main.js')) {
return {
id: join(dirname(importee), 'other.js'),
meta: { 'change-resolution': 'changed' }
};
}
return null;
},

load(id) {
const info = this.getModuleInfo(id);
t.is(info.id, join(__dirname, 'fixtures', 'entry', 'other.js'));
t.deepEqual(info.meta, { 'change-resolution': 'changed' });
}
}
]
});
});

0 comments on commit 9bb05ae

Please sign in to comment.