Skip to content

Commit f20f6d2

Browse files
authoredApr 8, 2020
Allow nodeVersion in XO config to override engines.node (#457)
1 parent ec87ef3 commit f20f6d2

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed
 

‎lib/options-manager.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ Merge option passed via CLI/API via options founf in config files.
240240
const mergeOptions = (options, xoOptions = {}, enginesOptions = {}) => {
241241
const mergedOptions = normalizeOptions({
242242
...xoOptions,
243-
nodeVersion: enginesOptions && enginesOptions.node && semver.validRange(enginesOptions.node),
243+
...(enginesOptions && enginesOptions.node && semver.validRange(enginesOptions.node) ? {nodeVersion: enginesOptions.node} : {}),
244244
...options
245245
});
246246

‎test/options-manager.js

+4-13
Original file line numberDiff line numberDiff line change
@@ -476,29 +476,29 @@ test('findApplicableOverrides', t => {
476476
test('mergeWithFileConfig: use child if closest', t => {
477477
const cwd = path.resolve('fixtures', 'nested', 'child');
478478
const {options} = manager.mergeWithFileConfig({cwd});
479-
const expected = {...childConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, nodeVersion: undefined};
479+
const expected = {...childConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd};
480480
t.deepEqual(options, expected);
481481
});
482482

483483
test('mergeWithFileConfig: use parent if closest', t => {
484484
const cwd = path.resolve('fixtures', 'nested');
485485
const {options} = manager.mergeWithFileConfig({cwd});
486-
const expected = {...parentConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, nodeVersion: undefined};
486+
const expected = {...parentConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd};
487487
t.deepEqual(options, expected);
488488
});
489489

490490
test('mergeWithFileConfig: use parent if child is ignored', t => {
491491
const cwd = path.resolve('fixtures', 'nested');
492492
const filename = path.resolve(cwd, 'child-ignore', 'file.js');
493493
const {options} = manager.mergeWithFileConfig({cwd, filename});
494-
const expected = {...parentConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, filename, nodeVersion: undefined};
494+
const expected = {...parentConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, filename};
495495
t.deepEqual(options, expected);
496496
});
497497

498498
test('mergeWithFileConfig: use child if child is empty', t => {
499499
const cwd = path.resolve('fixtures', 'nested', 'child-empty');
500500
const {options} = manager.mergeWithFileConfig({cwd});
501-
t.deepEqual(options, {nodeVersion: undefined, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd});
501+
t.deepEqual(options, {extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd});
502502
});
503503

504504
test('mergeWithFileConfig: read engines from package.json', t => {
@@ -531,7 +531,6 @@ test('mergeWithFileConfig: typescript files', async t => {
531531
extensions: DEFAULT_EXTENSION,
532532
ignores: DEFAULT_IGNORES,
533533
cwd,
534-
nodeVersion: undefined,
535534
semicolon: false,
536535
ts: true
537536
};
@@ -552,7 +551,6 @@ test('mergeWithFileConfig: tsx files', async t => {
552551
extensions: DEFAULT_EXTENSION,
553552
ignores: DEFAULT_IGNORES,
554553
cwd,
555-
nodeVersion: undefined,
556554
semicolon: false,
557555
ts: true
558556
};
@@ -590,7 +588,6 @@ test('mergeWithFileConfigs: nested configs with prettier', async t => {
590588
files: [path.resolve(cwd, 'no-semicolon.js')],
591589
options: {
592590
semicolon: true,
593-
nodeVersion: undefined,
594591
cwd,
595592
extensions: DEFAULT_EXTENSION,
596593
ignores: DEFAULT_IGNORES
@@ -601,7 +598,6 @@ test('mergeWithFileConfigs: nested configs with prettier', async t => {
601598
files: [path.resolve(cwd, 'child/semicolon.js')],
602599
options: {
603600
semicolon: false,
604-
nodeVersion: undefined,
605601
cwd: path.resolve(cwd, 'child'),
606602
extensions: DEFAULT_EXTENSION,
607603
ignores: DEFAULT_IGNORES
@@ -618,7 +614,6 @@ test('mergeWithFileConfigs: nested configs with prettier', async t => {
618614
envs: [],
619615
plugins: [],
620616
extends: [],
621-
nodeVersion: undefined,
622617
cwd: path.resolve(cwd, 'child-override'),
623618
extensions: DEFAULT_EXTENSION,
624619
ignores: DEFAULT_IGNORES
@@ -635,7 +630,6 @@ test('mergeWithFileConfigs: nested configs with prettier', async t => {
635630
envs: [],
636631
plugins: [],
637632
extends: [],
638-
nodeVersion: undefined,
639633
cwd: path.resolve(cwd, 'child-override', 'child-prettier-override'),
640634
extensions: DEFAULT_EXTENSION,
641635
ignores: DEFAULT_IGNORES
@@ -659,7 +653,6 @@ test('mergeWithFileConfigs: typescript files', async t => {
659653
files: [path.resolve(cwd, 'two-spaces.tsx')],
660654
options: {
661655
space: 4,
662-
nodeVersion: undefined,
663656
cwd,
664657
extensions: DEFAULT_EXTENSION,
665658
ignores: DEFAULT_IGNORES,
@@ -684,7 +677,6 @@ test('mergeWithFileConfigs: typescript files', async t => {
684677
files: [path.resolve(cwd, 'child/extra-semicolon.ts')],
685678
options: {
686679
semicolon: false,
687-
nodeVersion: undefined,
688680
cwd: path.resolve(cwd, 'child'),
689681
extensions: DEFAULT_EXTENSION,
690682
ignores: DEFAULT_IGNORES,
@@ -697,7 +689,6 @@ test('mergeWithFileConfigs: typescript files', async t => {
697689
files: [path.resolve(cwd, 'child/sub-child/four-spaces.ts')],
698690
options: {
699691
space: 2,
700-
nodeVersion: undefined,
701692
cwd: path.resolve(cwd, 'child/sub-child'),
702693
extensions: DEFAULT_EXTENSION,
703694
ignores: DEFAULT_IGNORES,

0 commit comments

Comments
 (0)
Please sign in to comment.