diff --git a/packages/alias/src/index.js b/packages/alias/src/index.js index 5d696b86a..419dba708 100755 --- a/packages/alias/src/index.js +++ b/packages/alias/src/index.js @@ -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 ( diff --git a/packages/alias/test/test.js b/packages/alias/test/test.js index 4993dede7..c23296d50 100755 --- a/packages/alias/test/test.js +++ b/packages/alias/test/test.js @@ -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); +});