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

fix: respect setting the deprecated fields "module", "main", and "jsn… #204

Merged
merged 1 commit into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import entry from 'entries';

export default entry;
33 changes: 33 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
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