Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nodeVersion in XO config to override engines.node #457

Merged
merged 1 commit into from Apr 8, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/options-manager.js
Expand Up @@ -240,7 +240,7 @@ Merge option passed via CLI/API via options founf in config files.
const mergeOptions = (options, xoOptions = {}, enginesOptions = {}) => {
const mergedOptions = normalizeOptions({
...xoOptions,
nodeVersion: enginesOptions && enginesOptions.node && semver.validRange(enginesOptions.node),
...(enginesOptions && enginesOptions.node && semver.validRange(enginesOptions.node) ? {nodeVersion: enginesOptions.node} : {}),
...options
});

Expand Down
17 changes: 4 additions & 13 deletions test/options-manager.js
Expand Up @@ -476,29 +476,29 @@ test('findApplicableOverrides', t => {
test('mergeWithFileConfig: use child if closest', t => {
const cwd = path.resolve('fixtures', 'nested', 'child');
const {options} = manager.mergeWithFileConfig({cwd});
const expected = {...childConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd, nodeVersion: undefined};
const expected = {...childConfig.xo, extensions: DEFAULT_EXTENSION, ignores: DEFAULT_IGNORES, cwd};
t.deepEqual(options, expected);
});

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

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

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

test('mergeWithFileConfig: read engines from package.json', t => {
Expand Down Expand Up @@ -531,7 +531,6 @@ test('mergeWithFileConfig: typescript files', async t => {
extensions: DEFAULT_EXTENSION,
ignores: DEFAULT_IGNORES,
cwd,
nodeVersion: undefined,
semicolon: false,
ts: true
};
Expand All @@ -552,7 +551,6 @@ test('mergeWithFileConfig: tsx files', async t => {
extensions: DEFAULT_EXTENSION,
ignores: DEFAULT_IGNORES,
cwd,
nodeVersion: undefined,
semicolon: false,
ts: true
};
Expand Down Expand Up @@ -590,7 +588,6 @@ test('mergeWithFileConfigs: nested configs with prettier', async t => {
files: [path.resolve(cwd, 'no-semicolon.js')],
options: {
semicolon: true,
nodeVersion: undefined,
cwd,
extensions: DEFAULT_EXTENSION,
ignores: DEFAULT_IGNORES
Expand All @@ -601,7 +598,6 @@ test('mergeWithFileConfigs: nested configs with prettier', async t => {
files: [path.resolve(cwd, 'child/semicolon.js')],
options: {
semicolon: false,
nodeVersion: undefined,
cwd: path.resolve(cwd, 'child'),
extensions: DEFAULT_EXTENSION,
ignores: DEFAULT_IGNORES
Expand All @@ -618,7 +614,6 @@ test('mergeWithFileConfigs: nested configs with prettier', async t => {
envs: [],
plugins: [],
extends: [],
nodeVersion: undefined,
cwd: path.resolve(cwd, 'child-override'),
extensions: DEFAULT_EXTENSION,
ignores: DEFAULT_IGNORES
Expand All @@ -635,7 +630,6 @@ test('mergeWithFileConfigs: nested configs with prettier', async t => {
envs: [],
plugins: [],
extends: [],
nodeVersion: undefined,
cwd: path.resolve(cwd, 'child-override', 'child-prettier-override'),
extensions: DEFAULT_EXTENSION,
ignores: DEFAULT_IGNORES
Expand All @@ -659,7 +653,6 @@ test('mergeWithFileConfigs: typescript files', async t => {
files: [path.resolve(cwd, 'two-spaces.tsx')],
options: {
space: 4,
nodeVersion: undefined,
cwd,
extensions: DEFAULT_EXTENSION,
ignores: DEFAULT_IGNORES,
Expand All @@ -684,7 +677,6 @@ test('mergeWithFileConfigs: typescript files', async t => {
files: [path.resolve(cwd, 'child/extra-semicolon.ts')],
options: {
semicolon: false,
nodeVersion: undefined,
cwd: path.resolve(cwd, 'child'),
extensions: DEFAULT_EXTENSION,
ignores: DEFAULT_IGNORES,
Expand All @@ -697,7 +689,6 @@ test('mergeWithFileConfigs: typescript files', async t => {
files: [path.resolve(cwd, 'child/sub-child/four-spaces.ts')],
options: {
space: 2,
nodeVersion: undefined,
cwd: path.resolve(cwd, 'child/sub-child'),
extensions: DEFAULT_EXTENSION,
ignores: DEFAULT_IGNORES,
Expand Down