Skip to content

Commit

Permalink
fix(alias): customResolver, matchedEntry bugfix (#29)
Browse files Browse the repository at this point in the history
* ignore Intellij IDEA dir

* updated pnpm-lock.yaml

According to pnpm actual version and included packages

* @rollup/plugin-alias: customResolver option

Allow to use customResolver instead of built-in resolving algorithm in

* @rollup/plugin-alias: updated readme

customResolver option

* (alias) updated README

customResolver description

* docs: rework custom resolver options and section

* (alias) customResolver bugfix
  • Loading branch information
Acionyx authored and shellscape committed Nov 6, 2019
1 parent 338b32c commit 50b96b0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/alias/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function alias(options = {}) {
typeof matchedEntry.customResolver === 'object' &&
typeof matchedEntry.customResolver.resolveId === 'function'
) {
customResolver = options.customResolver.resolveId;
customResolver = matchedEntry.customResolver.resolveId;
} else if (typeof options.customResolver === 'function') {
customResolver = options.customResolver;
} else if (
Expand Down
38 changes: 38 additions & 0 deletions packages/alias/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,41 @@ test('Local customResolver function', (t) => {

t.is(resolved, localCustomResult);
});

test('Global customResolver plugin-like object', (t) => {
const customResult = 'customResult';
const result = alias({
entries: [
{
find: 'test',
replacement: path.resolve('./test/files/folder/hipster.jsx')
}
],
resolve: ['.js', '.jsx'],
customResolver: {resolveId: () => customResult}
});

const resolved = result.resolveId('test', posix.resolve(DIRNAME, './files/index.js'));

t.is(resolved, customResult);
});

test('Local customResolver plugin-like object', (t) => {
const customResult = 'customResult';
const localCustomResult = 'localCustomResult';
const result = alias({
entries: [
{
find: 'test',
replacement: path.resolve('./test/files/folder/hipster.jsx'),
customResolver: {resolveId: () => localCustomResult}
}
],
resolve: ['.js', '.jsx'],
customResolver: {resolveId: () => customResult}
});

const resolved = result.resolveId('test', posix.resolve(DIRNAME, './files/index.js'));

t.is(resolved, localCustomResult);
});

0 comments on commit 50b96b0

Please sign in to comment.