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 Feb 6, 2024
1 parent 71857a0 commit 3b9d372
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 114 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Expand Up @@ -12,10 +12,9 @@ jobs:
node-version:
- 20
- 18
- 16
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install --force
Expand Down
115 changes: 61 additions & 54 deletions config/plugins.cjs
Expand Up @@ -41,7 +41,7 @@ module.exports = {
checkFilenames: false,
checkDefaultAndNamespaceImports: false,
checkShorthandImports: false,
extendDefaultReplacements: false,
extendDefaultReplacements: true,
replacements: {
// https://thenextweb.com/dd/2020/07/13/linux-kernel-will-no-longer-use-terms-blacklist-and-slave/
whitelist: {
Expand All @@ -57,76 +57,83 @@ module.exports = {
secondary: true,
},

// Not part of `eslint-plugin-unicorn`
// Reverse.
application: {
app: true,
},
applications: {
apps: true,
},

// Part of `eslint-plugin-unicorn`
arr: {
array: true,
// Disable some that may be too annoying.
env: false,
i: false, // Do it at some point, but not ready for it yet. Maybe 2025.

// Not part of `eslint-plugin-unicorn`. Upstream them at some point.
bin: {
binary: true,
},
e: {
error: true,
event: true,
eof: {
endOfFile: true,
},
el: {
element: true,
impl: {
implement: true,
implementation: true,
},
elem: {
element: true,
anim: {
animation: true,
},
len: {
length: true,
calc: {
calculate: true,
},
msg: {
message: true,
dict: {
dictionary: true,
},
num: {
number: true,
dup: {
duplicate: true,
},
obj: {
object: true,
enc: {
encode: true,
encryption: true,
},
opts: {
options: true,
gen: {
generate: true,
general: true,
},
param: {
parameter: true,
gfx: {
graphics: true,
},
params: {
parameters: true,
inc: {
increment: true,
},
prev: {
previous: true,
iter: {
iterate: true,
iterator: true,
},
req: {
request: true,
nav: {
navigate: true,
navigation: true,
},
res: {
response: true,
result: true,
norm: {
normalize: true,
},
ret: {
returnValue: true,
notif: {
notification: true,
},
str: {
string: true,
perf: {
performance: true,
},
temp: {
temporary: true,
proc: {
process: true,
},
tmp: {
temporary: true,
rand: {
random: true,
},
val: {
value: true,
sys: {
system: true,
},
err: {
error: true,
temp: {
temporary: true,
},
},
},
Expand All @@ -153,13 +160,10 @@ module.exports = {
},
],

// Temporarily disabled because it's buggy with TypeScript: https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2175
// Temporarily disabled because of https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2218
'unicorn/no-empty-file': 'off',

// TODO: Disabled for now until it becomes more stable: https://github.com/sindresorhus/eslint-plugin-unicorn/search?q=consistent-destructuring+is:issue&state=open&type=issues
'unicorn/consistent-destructuring': 'off',

// TODO: Disabled for now as I don't have time to deal with the backslash that might come from this. Try to enable this rule in 2021.
// TODO: Disabled for now as I don't have time to deal with the backslash that might come from this. Try to enable this rule in 2025.
'unicorn/no-null': 'off',

// We only enforce it for single-line statements to not be too opinionated.
Expand Down Expand Up @@ -355,10 +359,13 @@ module.exports = {
// 'n/shebang': 'error',

'n/no-deprecated-api': 'error',
'n/prefer-global/buffer': [
'error',
'never',
],

// We no longer enforce this as we don't want to use Buffer at all, but sometimes we need to conditionally use the `Buffer` global, but we then don't want the import so the module works cross-platform.
// 'n/prefer-global/buffer': [
// 'error',
// 'never',
// ],

'n/prefer-global/console': [
'error',
'always',
Expand Down
4 changes: 3 additions & 1 deletion index.js
Expand Up @@ -28,7 +28,9 @@ const globFiles = async (patterns, options) => {

const files = await globby(
patterns,
{ignore: ignores, gitignore: true, absolute: true, cwd},
{
ignore: ignores, gitignore: true, absolute: true, cwd,
},
);

return files.filter(file => extensions.includes(path.extname(file).slice(1)));
Expand Down
1 change: 1 addition & 0 deletions lib/constants.js
Expand Up @@ -7,6 +7,7 @@ const DEFAULT_IGNORES = [
'**/*.min.js',
'vendor/**',
'dist/**',
'distribution/**',
'tap-snapshots/*.{cjs,js}',
];

Expand Down
18 changes: 8 additions & 10 deletions lib/options-manager.js
Expand Up @@ -4,7 +4,7 @@ import os from 'node:os';
import path from 'node:path';
import arrify from 'arrify';
import {mergeWith, flow, pick} from 'lodash-es';
import {findUpSync} from 'find-up';
import {findUpSync} from 'find-up-simple';
import findCacheDir from 'find-cache-dir';
import prettier from 'prettier';
import semver from 'semver';
Expand Down Expand Up @@ -83,7 +83,7 @@ const getEmptyXOConfig = () => ({
extends: [],
});

const mergeFn = (previousValue, value, key) => {
const mergeFunction = (previousValue, value, key) => {
if (Array.isArray(previousValue)) {
if (MERGE_OPTIONS_CONCAT.includes(key)) {
return [...previousValue, ...value];
Expand All @@ -102,14 +102,12 @@ The config files are searched starting from `options.filePath` if defined or `op
const mergeWithFileConfig = async options => {
options.cwd = path.resolve(options.cwd || process.cwd());
const configExplorer = cosmiconfig(MODULE_NAME, {searchPlaces: CONFIG_FILES, loaders: {noExt: defaultLoaders['.json']}, stopDir: options.cwd});
const pkgConfigExplorer = cosmiconfig('engines', {searchPlaces: ['package.json'], stopDir: options.cwd});
if (options.filePath) {
options.filePath = path.resolve(options.cwd, options.filePath);
}
const packageConfigExplorer = cosmiconfig('engines', {searchPlaces: ['package.json'], stopDir: options.cwd});
options.filePath &&= path.resolve(options.cwd, options.filePath);

const searchPath = options.filePath || options.cwd;
const {config: xoOptions, filepath: xoConfigPath} = (await configExplorer.search(searchPath)) || {};
const {config: enginesOptions} = (await pkgConfigExplorer.search(searchPath)) || {};
const {config: enginesOptions} = (await packageConfigExplorer.search(searchPath)) || {};

options = normalizeOptions({
...xoOptions,
Expand Down Expand Up @@ -274,7 +272,7 @@ const buildConfig = (options, prettierOptions) => {
buildTSConfig(options),
buildExtendsConfig(options),
buildPrettierConfig(options, prettierOptions),
)(mergeWith(getEmptyConfig(), DEFAULT_CONFIG, mergeFn));
)(mergeWith(getEmptyConfig(), DEFAULT_CONFIG, mergeFunction));
};

const toValueMap = (array, value = true) => Object.fromEntries(array.map(item => [item, value]));
Expand Down Expand Up @@ -473,7 +471,7 @@ const mergeWithPrettierConfig = (options, prettierOptions) => {
semi: options.semicolon !== false,
},
prettierOptions,
mergeFn,
mergeFunction,
);
};

Expand Down Expand Up @@ -503,7 +501,7 @@ const applyOverrides = (file, options) => {

const {applicable, hash} = findApplicableOverrides(path.relative(options.cwd, file), overrides);

options = mergeWith(getEmptyXOConfig(), options, ...applicable.map(override => normalizeOptions(override)), mergeFn);
options = mergeWith(getEmptyXOConfig(), options, ...applicable.map(override => normalizeOptions(override)), mergeFunction);
delete options.files;
return {options, hash};
}
Expand Down
59 changes: 30 additions & 29 deletions package.json
Expand Up @@ -12,8 +12,9 @@
},
"type": "module",
"bin": "./cli.js",
"sideEffects": false,
"engines": {
"node": ">=16"
"node": ">=18"
},
"scripts": {
"test:clean": "find ./test -type d -name 'node_modules' -prune -not -path ./test/fixtures/project/node_modules -exec rm -rf '{}' +",
Expand Down Expand Up @@ -53,53 +54,53 @@
"typescript"
],
"dependencies": {
"@eslint/eslintrc": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@eslint/eslintrc": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"arrify": "^3.0.0",
"cosmiconfig": "^8.2.0",
"cosmiconfig": "^8.3.6",
"define-lazy-prop": "^3.0.0",
"eslint": "^8.45.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-xo": "^0.43.1",
"eslint-config-xo-typescript": "^1.0.0",
"eslint-formatter-pretty": "^5.0.0",
"eslint-import-resolver-webpack": "^0.13.2",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-xo": "^0.44.0",
"eslint-config-xo-typescript": "^2.0.0",
"eslint-formatter-pretty": "^6.0.1",
"eslint-import-resolver-webpack": "^0.13.8",
"eslint-plugin-ava": "^14.0.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "~2.27.5",
"eslint-plugin-n": "^16.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-no-use-extend-native": "^0.5.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-unicorn": "^48.0.0",
"esm-utils": "^4.1.2",
"find-cache-dir": "^4.0.0",
"find-up": "^6.3.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^51.0.0",
"esm-utils": "^4.2.1",
"find-cache-dir": "^5.0.0",
"find-up-simple": "^1.0.0",
"get-stdin": "^9.0.0",
"get-tsconfig": "^4.6.2",
"globby": "^13.2.2",
"get-tsconfig": "^4.7.2",
"globby": "^14.0.0",
"imurmurhash": "^0.1.4",
"json-stable-stringify-without-jsonify": "^1.0.1",
"lodash-es": "^4.17.21",
"meow": "^12.0.1",
"meow": "^13.1.0",
"micromatch": "^4.0.5",
"open-editor": "^4.0.0",
"prettier": "^3.0.0",
"semver": "^7.5.4",
"open-editor": "^4.1.1",
"prettier": "^3.2.5",
"semver": "^7.6.0",
"slash": "^5.1.0",
"to-absolute-glob": "^3.0.0",
"typescript": "^5.1.6"
"typescript": "^5.3.3"
},
"devDependencies": {
"ava": "^5.3.1",
"ava": "^6.1.1",
"eslint-config-xo-react": "^0.27.0",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"execa": "^7.1.1",
"execa": "^8.0.1",
"nyc": "^15.1.0",
"proxyquire": "^2.1.3",
"temp-write": "^5.0.0",
"webpack": "^5.88.1"
"webpack": "^5.90.1"
},
"xo": {
"ignores": [
Expand Down
12 changes: 7 additions & 5 deletions readme.md
Expand Up @@ -384,7 +384,7 @@ If some files in your project are transpiled in order to support an older Node.j

For example, if your project targets Node.js 8 but you want to use the latest JavaScript syntax as supported in Node.js 12:
1. Set the `engines.node` property of your `package.json` to `>=8`
2. Configure [Babel](https://babeljs.io) to transpile your source files (in `src` directory in this example)
2. Configure [Babel](https://babeljs.io) to transpile your source files (in `source` directory in this example)
3. Make sure to include the transpiled files in your published package with the [`files`](https://docs.npmjs.com/files/package.json#files) and [`main`](https://docs.npmjs.com/files/package.json#main) properties of your `package.json`
4. Configure the XO `overrides` option to set `nodeVersion` to `>=12` for your source files directory

Expand All @@ -394,14 +394,16 @@ For example, if your project targets Node.js 8 but you want to use the latest Ja
"node": ">=12"
},
"scripts": {
"build": "babel src --out-dir dist"
"build": "babel source --out-dir distribution"
},
"main": "dist/index.js",
"files": ["dist/**/*.js"],
"main": "distribution/index.js",
"files": [
"distribution/**/*.js"
],
"xo": {
"overrides": [
{
"files": "{src}/**/*.js",
"files": "source/**/*.js",
"nodeVersion": ">=16"
}
]
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/webpack/no-config/file1.js
@@ -1,2 +1,2 @@
import __ from 'inexistent'; // eslint-disable-line no-unused-vars
import _ from 'file2alias'; // eslint-disable-line no-unused-vars
import __ from 'inexistent';
import _ from 'file2alias';
1 change: 1 addition & 0 deletions test/fixtures/webpack/no-config/file2.js
@@ -1,2 +1,3 @@
const foo = 1;

export default foo;

0 comments on commit 3b9d372

Please sign in to comment.