Skip to content

Commit

Permalink
Require Node.js 18
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 4, 2023
1 parent 5536c24 commit e917c7b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 49 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 20
- 18
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import process from 'node:process';
import path from 'node:path';
import fs from 'node:fs';
import minimist from 'minimist';
import {readPackageUpSync} from 'read-pkg-up';
import {writePackageSync} from 'write-pkg';
import execa from 'execa';
import {readPackageUpSync} from 'read-package-up';
import {writePackageSync} from 'write-package';
import {execa} from 'execa';
import hasYarn from 'has-yarn';

const DEFAULT_TEST_SCRIPT = 'echo "Error: no test specified" && exit 1';
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"bin": "./cli.js",
"exports": "./index.js",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
"node": ">=18"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -35,16 +35,19 @@
"xo"
],
"dependencies": {
"execa": "^5.1.1",
"execa": "^8.0.1",
"has-yarn": "^3.0.0",
"minimist": "^1.2.5",
"read-pkg-up": "^9.0.0",
"write-pkg": "^5.0.0"
"minimist": "^1.2.8",
"read-package-up": "^11.0.0",
"write-package": "^7.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
"dot-prop": "^6.0.1",
"ava": "^5.3.1",
"dot-prop": "^8.0.2",
"temp-write": "^5.0.0",
"xo": "^0.45.0"
"xo": "^0.56.0"
},
"ava": {
"timeout": "10m"
}
}
71 changes: 36 additions & 35 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import path from 'node:path';
import fs from 'node:fs';
import process from 'node:process';
import tempWrite from 'temp-write';
import dotProp from 'dot-prop';
import {getProperty} from 'dot-prop';
import test from 'ava';
import createXo from './index.js';

const originalArgv = [...process.argv];
const {get} = dotProp;

async function run(pkg) {
const filepath = tempWrite.sync(JSON.stringify(pkg), 'package.json');
Expand All @@ -22,8 +21,8 @@ async function run(pkg) {

test('empty package.json', async t => {
const pkg = await run({});
t.is(get(pkg, 'scripts.test'), 'xo');
t.is(get(pkg, 'xo'), undefined);
t.is(getProperty(pkg, 'scripts.test'), 'xo');
t.is(getProperty(pkg, 'xo'), undefined);
});

test('has scripts', async t => {
Expand All @@ -33,8 +32,8 @@ test('has scripts', async t => {
},
});

t.is(get(pkg, 'scripts.test'), 'xo');
t.is(get(pkg, 'xo'), undefined);
t.is(getProperty(pkg, 'scripts.test'), 'xo');
t.is(getProperty(pkg, 'xo'), undefined);
});

test('has default test', async t => {
Expand All @@ -44,8 +43,8 @@ test('has default test', async t => {
},
});

t.is(get(pkg, 'scripts.test'), 'xo');
t.is(get(pkg, 'xo'), undefined);
t.is(getProperty(pkg, 'scripts.test'), 'xo');
t.is(getProperty(pkg, 'xo'), undefined);
});

test('has only xo', async t => {
Expand All @@ -55,8 +54,8 @@ test('has only xo', async t => {
},
});

t.is(get(pkg, 'scripts.test'), 'xo');
t.is(get(pkg, 'xo'), undefined);
t.is(getProperty(pkg, 'scripts.test'), 'xo');
t.is(getProperty(pkg, 'xo'), undefined);
});

test('has test', async t => {
Expand All @@ -66,8 +65,8 @@ test('has test', async t => {
},
});

t.is(get(pkg, 'scripts.test'), 'xo && ava');
t.is(get(pkg, 'xo'), undefined);
t.is(getProperty(pkg, 'scripts.test'), 'xo && ava');
t.is(getProperty(pkg, 'xo'), undefined);
});

test('has cli args', async t => {
Expand All @@ -80,8 +79,8 @@ test('has cli args', async t => {
});

process.argv = originalArgv;
t.is(get(pkg, 'scripts.test'), 'xo');
t.is(get(pkg, 'xo.space'), true);
t.is(getProperty(pkg, 'scripts.test'), 'xo');
t.is(getProperty(pkg, 'xo.space'), true);
});

test('has cli args and test', async t => {
Expand All @@ -94,9 +93,9 @@ test('has cli args and test', async t => {
});

process.argv = originalArgv;
t.is(get(pkg, 'scripts.test'), 'xo && ava');
t.is(get(pkg, 'xo.envs.0'), 'node');
t.is(get(pkg, 'xo.envs.1'), 'browser');
t.is(getProperty(pkg, 'scripts.test'), 'xo && ava');
t.is(getProperty(pkg, 'xo.envs[0]'), 'node');
t.is(getProperty(pkg, 'xo.envs[1]'), 'browser');
});

test('has cli args and existing config', async t => {
Expand All @@ -109,9 +108,9 @@ test('has cli args and existing config', async t => {
});

process.argv = originalArgv;
t.is(get(pkg, 'scripts.test'), 'xo');
t.is(get(pkg, 'xo.space'), true);
t.is(get(pkg, 'xo.esnext'), true);
t.is(getProperty(pkg, 'scripts.test'), 'xo');
t.is(getProperty(pkg, 'xo.space'), true);
t.is(getProperty(pkg, 'xo.esnext'), true);
});

test('has existing config without cli args', async t => {
Expand All @@ -124,12 +123,13 @@ test('has existing config without cli args', async t => {
});

process.argv = originalArgv;
t.is(get(pkg, 'scripts.test'), 'xo');
t.deepEqual(get(pkg, 'xo'), {esnext: true});
t.is(getProperty(pkg, 'scripts.test'), 'xo');
t.deepEqual(getProperty(pkg, 'xo'), {esnext: true});
});

test('has everything covered when it comes to config', async t => {
process.argv = [...originalArgv,
process.argv = [
...originalArgv,
'--space',
'--esnext',
'--no-semicolon',
Expand All @@ -138,27 +138,28 @@ test('has everything covered when it comes to config', async t => {
'--global=foo',
'--global=bar',
'--ignore=foo',
'--ignore=bar'];
'--ignore=bar',
];

const pkg = await run({});

process.argv = originalArgv;
t.is(get(pkg, 'scripts.test'), 'xo');
t.is(get(pkg, 'xo.space'), true);
t.is(get(pkg, 'xo.esnext'), true);
t.is(get(pkg, 'xo.semicolon'), false);
t.is(get(pkg, 'xo.envs.0'), 'foo');
t.is(get(pkg, 'xo.envs.1'), 'bar');
t.is(get(pkg, 'xo.globals.0'), 'foo');
t.is(get(pkg, 'xo.globals.1'), 'bar');
t.is(get(pkg, 'xo.ignores.0'), 'foo');
t.is(get(pkg, 'xo.ignores.1'), 'bar');
t.is(getProperty(pkg, 'scripts.test'), 'xo');
t.is(getProperty(pkg, 'xo.space'), true);
t.is(getProperty(pkg, 'xo.esnext'), true);
t.is(getProperty(pkg, 'xo.semicolon'), false);
t.is(getProperty(pkg, 'xo.envs[0]'), 'foo');
t.is(getProperty(pkg, 'xo.envs[1]'), 'bar');
t.is(getProperty(pkg, 'xo.globals[0]'), 'foo');
t.is(getProperty(pkg, 'xo.globals[1]'), 'bar');
t.is(getProperty(pkg, 'xo.ignores[0]'), 'foo');
t.is(getProperty(pkg, 'xo.ignores[1]'), 'bar');
});

test('installs the XO dependency', async t => {
const filepath = tempWrite.sync(JSON.stringify({}), 'package.json');
await createXo({cwd: path.dirname(filepath)});
t.truthy(get(JSON.parse(fs.readFileSync(filepath, 'utf8')), 'devDependencies.xo'));
t.truthy(getProperty(JSON.parse(fs.readFileSync(filepath, 'utf8')), 'devDependencies.xo'));
});

test('installs via yarn if there\'s a lockfile', async t => {
Expand Down

0 comments on commit e917c7b

Please sign in to comment.