Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
fix: respect setting the deprecated fields "module", "main", and "jsn…
Browse files Browse the repository at this point in the history
…ext" (#204)
  • Loading branch information
Nick Woodward authored and lukastaegert committed Apr 6, 2019
1 parent 2344757 commit b6f6eb5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -51,7 +51,7 @@ function getMainFields (options) {
// eslint-disable-next-line no-console
console.warn(`node-resolve: setting options.${option} is deprecated, please override options.mainFields instead`);
if (options[option] === false) {
mainFields = mainFields.filter(mainField => mainField === field);
mainFields = mainFields.filter(mainField => mainField !== field);
} else if (options[option] === true && mainFields.indexOf(field) === -1) {
mainFields.push(field);
}
Expand Down
3 changes: 3 additions & 0 deletions test/samples/prefer-main/main.js
@@ -0,0 +1,3 @@
import entry from 'entries';

export default entry;
33 changes: 33 additions & 0 deletions test/test.js
Expand Up @@ -547,6 +547,39 @@ describe( 'rollup-plugin-node-resolve', function () {
});
});

it( 'should support disabling "module" field resolution', function () {
return rollup.rollup({
input: 'samples/prefer-main/main.js',
plugins: [
nodeResolve({ module: false })
]
}).then( executeBundle ).then( module => {
assert.equal( module.exports, 'MAIN-ENTRY' );
});
});

it( 'should support disabling "main" field resolution', function () {
return rollup.rollup({
input: 'samples/prefer-module/main.js',
plugins: [
nodeResolve({ main: false })
]
}).then( executeBundle ).then( module => {
assert.equal( module.exports, 'MODULE-ENTRY' );
});
});

it( 'should support enabling "jsnext" field resolution', function () {
return rollup.rollup({
input: 'samples/prefer-module/main.js',
plugins: [
nodeResolve({ main: false, module: false, jsnext: true })
]
}).then( executeBundle ).then( module => {
assert.equal( module.exports, 'JSNEXT-ENTRY' );
});
});

describe( 'symlinks', () => {
function createMissingDirectories () {
createDirectory( './samples/symlinked/first/node_modules' );
Expand Down

0 comments on commit b6f6eb5

Please sign in to comment.