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

Fix ordering of jsnext:main when using the jsnext option #209

Merged
merged 2 commits into from
Apr 11, 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
264 changes: 120 additions & 144 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
"buble": "^0.19.7",
"es5-ext": "^0.10.49",
"eslint": "^5.16.0",
"mocha": "^6.0.2",
"rollup": "^1.8.0",
"mocha": "^6.1.2",
"rollup": "^1.9.3",
"rollup-plugin-buble": "^0.19.6",
"rollup-plugin-commonjs": "^9.3.4",
"string-capitalize": "^1.0.1",
"typescript": "^3.4.1",
"vlq": "^1.0.0"
"typescript": "^3.4.3"
},
"main": "dist/rollup-plugin-node-resolve.cjs.js",
"module": "dist/rollup-plugin-node-resolve.es.js",
Expand All @@ -33,7 +32,7 @@
],
"dependencies": {
"@types/resolve": "0.0.8",
"builtin-modules": "^3.0.0",
"builtin-modules": "^3.1.0",
"is-module": "^1.0.0",
"resolve": "^1.10.0"
},
Expand Down
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {dirname, extname, normalize, resolve, sep, join} from 'path';
import {dirname, extname, join, normalize, resolve, sep} from 'path';
import builtins from 'builtin-modules';
import resolveId from 'resolve';
import isModule from 'is-module';
Expand Down Expand Up @@ -45,16 +45,16 @@ function getMainFields (options) {
}
mainFields = options.mainFields;
} else {
mainFields = ['module', 'main'];
[['module', 'module'], ['jsnext', 'jsnext:main'], ['main', 'main']].forEach(([option, field]) => {
mainFields = [];
[['module', 'module', true], ['jsnext', 'jsnext:main', false], ['main', 'main', true]].forEach(([option, field, defaultIncluded]) => {
if (option in 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);
} else if (options[option] === true && mainFields.indexOf(field) === -1) {
if (options[option]) {
mainFields.push(field);
}
} else if (defaultIncluded) {
mainFields.push(field);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions test/node_modules/jsnext/entry-main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion test/node_modules/jsnext/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/node_modules/module/entry-main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/node_modules/module/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/samples/jsnext/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { encode } from 'vlq';
import value from 'jsnext';

export default encode( 123 ); // 2H
export default value;
25 changes: 18 additions & 7 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,29 @@ describe( 'rollup-plugin-node-resolve', function () {
nodeResolve({ mainFields: ['jsnext:main', 'module', 'main'] })
]
}).then( executeBundle ).then( module => {
assert.equal( module.exports, '2H' );
assert.equal( module.exports, 'JSNEXT' );
});
});

it( 'DEPRECATED: options.jsnext still works', function () {
it( 'DEPRECATED: options.jsnext still works with correct priority', function () {
return rollup.rollup({
input: 'samples/jsnext/main.js',
plugins: [
nodeResolve({ jsnext: true })
nodeResolve({ jsnext: true, main: true })
]
}).then( executeBundle ).then( module => {
assert.equal( module.exports, '2H' );
assert.equal( module.exports, 'JSNEXT' );
});
});

it( 'DEPRECATED: options.module still works with correct priority', function () {
return rollup.rollup({
input: 'samples/module/main.js',
plugins: [
nodeResolve({ module: true, main: true, preferBuiltins: false })
]
}).then( executeBundle ).then( module => {
assert.equal( module.exports, 'MODULE' );
});
});

Expand Down Expand Up @@ -660,7 +671,7 @@ describe( 'rollup-plugin-node-resolve', function () {
nodeResolve({})
]
}).then( executeBundle ).then( module => {
assert.equal( module.exports, '2H' );
assert.equal( module.exports, 'MAIN' );
});
});

Expand Down Expand Up @@ -819,7 +830,7 @@ describe( 'rollup-plugin-node-resolve', function () {
})
]
}).then( executeBundle ).then( module => {
assert.deepEqual(module.exports, {
assert.deepEqual(module.exports, {
React: 'react:root',
ReactConsumer: 'react-consumer:react:root'
});
Expand All @@ -833,7 +844,7 @@ describe( 'rollup-plugin-node-resolve', function () {
nodeResolve()
]
}).then( executeBundle ).then( module => {
assert.deepEqual(module.exports, {
assert.deepEqual(module.exports, {
React: 'react:root',
ReactConsumer: 'react-consumer:react:child'
});
Expand Down