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

Commit befca76

Browse files
authored
Fix ordering of jsnext:main when using the jsnext option (#209)
* Update dependencies * Test and fix wrong ordering of jsnext:main when using jsnext: true
1 parent 9736d86 commit befca76

File tree

9 files changed

+155
-165
lines changed

9 files changed

+155
-165
lines changed

package-lock.json

+120-144
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
"buble": "^0.19.7",
77
"es5-ext": "^0.10.49",
88
"eslint": "^5.16.0",
9-
"mocha": "^6.0.2",
10-
"rollup": "^1.8.0",
9+
"mocha": "^6.1.2",
10+
"rollup": "^1.9.3",
1111
"rollup-plugin-buble": "^0.19.6",
1212
"rollup-plugin-commonjs": "^9.3.4",
1313
"string-capitalize": "^1.0.1",
14-
"typescript": "^3.4.1",
15-
"vlq": "^1.0.0"
14+
"typescript": "^3.4.3"
1615
},
1716
"main": "dist/rollup-plugin-node-resolve.cjs.js",
1817
"module": "dist/rollup-plugin-node-resolve.es.js",
@@ -33,7 +32,7 @@
3332
],
3433
"dependencies": {
3534
"@types/resolve": "0.0.8",
36-
"builtin-modules": "^3.0.0",
35+
"builtin-modules": "^3.1.0",
3736
"is-module": "^1.0.0",
3837
"resolve": "^1.10.0"
3938
},

src/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {dirname, extname, normalize, resolve, sep, join} from 'path';
1+
import {dirname, extname, join, normalize, resolve, sep} from 'path';
22
import builtins from 'builtin-modules';
33
import resolveId from 'resolve';
44
import isModule from 'is-module';
@@ -45,16 +45,16 @@ function getMainFields (options) {
4545
}
4646
mainFields = options.mainFields;
4747
} else {
48-
mainFields = ['module', 'main'];
49-
[['module', 'module'], ['jsnext', 'jsnext:main'], ['main', 'main']].forEach(([option, field]) => {
48+
mainFields = [];
49+
[['module', 'module', true], ['jsnext', 'jsnext:main', false], ['main', 'main', true]].forEach(([option, field, defaultIncluded]) => {
5050
if (option in options) {
5151
// eslint-disable-next-line no-console
5252
console.warn(`node-resolve: setting options.${option} is deprecated, please override options.mainFields instead`);
53-
if (options[option] === false) {
54-
mainFields = mainFields.filter(mainField => mainField !== field);
55-
} else if (options[option] === true && mainFields.indexOf(field) === -1) {
53+
if (options[option]) {
5654
mainFields.push(field);
5755
}
56+
} else if (defaultIncluded) {
57+
mainFields.push(field);
5858
}
5959
});
6060
}

test/node_modules/jsnext/entry-main.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/jsnext/package.json

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/module/entry-main.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/module/package.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/samples/jsnext/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { encode } from 'vlq';
1+
import value from 'jsnext';
22

3-
export default encode( 123 ); // 2H
3+
export default value;

test/test.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,29 @@ describe( 'rollup-plugin-node-resolve', function () {
5858
nodeResolve({ mainFields: ['jsnext:main', 'module', 'main'] })
5959
]
6060
}).then( executeBundle ).then( module => {
61-
assert.equal( module.exports, '2H' );
61+
assert.equal( module.exports, 'JSNEXT' );
6262
});
6363
});
6464

65-
it( 'DEPRECATED: options.jsnext still works', function () {
65+
it( 'DEPRECATED: options.jsnext still works with correct priority', function () {
6666
return rollup.rollup({
6767
input: 'samples/jsnext/main.js',
6868
plugins: [
69-
nodeResolve({ jsnext: true })
69+
nodeResolve({ jsnext: true, main: true })
7070
]
7171
}).then( executeBundle ).then( module => {
72-
assert.equal( module.exports, '2H' );
72+
assert.equal( module.exports, 'JSNEXT' );
73+
});
74+
});
75+
76+
it( 'DEPRECATED: options.module still works with correct priority', function () {
77+
return rollup.rollup({
78+
input: 'samples/module/main.js',
79+
plugins: [
80+
nodeResolve({ module: true, main: true, preferBuiltins: false })
81+
]
82+
}).then( executeBundle ).then( module => {
83+
assert.equal( module.exports, 'MODULE' );
7384
});
7485
});
7586

@@ -660,7 +671,7 @@ describe( 'rollup-plugin-node-resolve', function () {
660671
nodeResolve({})
661672
]
662673
}).then( executeBundle ).then( module => {
663-
assert.equal( module.exports, '2H' );
674+
assert.equal( module.exports, 'MAIN' );
664675
});
665676
});
666677

@@ -819,7 +830,7 @@ describe( 'rollup-plugin-node-resolve', function () {
819830
})
820831
]
821832
}).then( executeBundle ).then( module => {
822-
assert.deepEqual(module.exports, {
833+
assert.deepEqual(module.exports, {
823834
React: 'react:root',
824835
ReactConsumer: 'react-consumer:react:root'
825836
});
@@ -833,7 +844,7 @@ describe( 'rollup-plugin-node-resolve', function () {
833844
nodeResolve()
834845
]
835846
}).then( executeBundle ).then( module => {
836-
assert.deepEqual(module.exports, {
847+
assert.deepEqual(module.exports, {
837848
React: 'react:root',
838849
ReactConsumer: 'react-consumer:react:child'
839850
});

0 commit comments

Comments
 (0)