Skip to content

Commit

Permalink
Breaking: drop Node.js 8 support (refs eslint/rfcs#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Dec 22, 2019
1 parent 827259e commit d6636f0
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 82 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/ci.yml
Expand Up @@ -26,20 +26,16 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node: [13.x, 12.x, 10.x, 8.x, "8.10.0"]
node: [13.x, 12.x, 10.x, "10.12.0"]
exclude:
- os: windows-latest
node: "8.10.0"
- os: windows-latest
node: 8.x
node: "10.12.0"
- os: windows-latest
node: 10.x
- os: windows-latest
node: 13.x
- os: macOS-latest
node: "8.10.0"
- os: macOS-latest
node: 8.x
node: "10.12.0"
- os: macOS-latest
node: 10.x
- os: macOS-latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -39,7 +39,7 @@ ESLint is a tool for identifying and reporting on patterns found in ECMAScript/J

## <a name="installation-and-usage"></a>Installation and Usage

Prerequisites: [Node.js](https://nodejs.org/) (`^8.10.0`, `^10.13.0`, or `>=11.10.1`) built with SSL support. (If you are using an official Node.js distribution, SSL is always built in.)
Prerequisites: [Node.js](https://nodejs.org/) (`^10.12.0`, or `>=12.0.0`) built with SSL support. (If you are using an official Node.js distribution, SSL is always built in.)

You can install ESLint using npm:

Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/getting-started.md
Expand Up @@ -8,7 +8,7 @@ ESLint is a tool for identifying and reporting on patterns found in ECMAScript/J

## Installation and Usage

Prerequisites: [Node.js](https://nodejs.org/en/) (`^8.10.0`, `^10.13.0`, or `>=11.10.1`) built with SSL support. (If you are using an official Node.js distribution, SSL is always built in.)
Prerequisites: [Node.js](https://nodejs.org/en/) (`^10.12.0`, or `>=12.0.0`) built with SSL support. (If you are using an official Node.js distribution, SSL is always built in.)

You can install ESLint using npm or yarn:

Expand Down
17 changes: 8 additions & 9 deletions lib/cli-engine/file-enumerator.js
Expand Up @@ -127,12 +127,12 @@ function statSafeSync(filePath) {
/**
* Get filenames in a given path to a directory.
* @param {string} directoryPath The path to target directory.
* @returns {string[]} The filenames.
* @returns {import("fs").Dirent[]} The filenames.
* @private
*/
function readdirSafeSync(directoryPath) {
try {
return fs.readdirSync(directoryPath);
return fs.readdirSync(directoryPath, { withFileTypes: true });
} catch (error) {
/* istanbul ignore next */
if (error.code !== "ENOENT") {
Expand Down Expand Up @@ -386,12 +386,11 @@ class FileEnumerator {
let config = null;

// Enumerate the files of this directory.
for (const filename of readdirSafeSync(directoryPath)) {
const filePath = path.join(directoryPath, filename);
const stat = statSafeSync(filePath); // TODO: Use `withFileTypes` in the future.
for (const entry of readdirSafeSync(directoryPath)) {
const filePath = path.join(directoryPath, entry.name);

// Check if the file is matched.
if (stat && stat.isFile()) {
if (entry.isFile()) {
if (!config) {
config = configArrayFactory.getConfigArrayForFile(
filePath,
Expand All @@ -415,18 +414,18 @@ class FileEnumerator {
: extensionRegExp.test(filePath);

if (matched) {
debug(`Yield: ${filename}${ignored ? " but ignored" : ""}`);
debug(`Yield: ${entry.name}${ignored ? " but ignored" : ""}`);
yield {
config: configArrayFactory.getConfigArrayForFile(filePath),
filePath,
flag
};
} else {
debug(`Didn't match: ${filename}`);
debug(`Didn't match: ${entry.name}`);
}

// Dive into the sub directory.
} else if (options.recursive && stat && stat.isDirectory()) {
} else if (options.recursive && entry.isDirectory()) {
if (!config) {
config = configArrayFactory.getConfigArrayForFile(
filePath,
Expand Down
29 changes: 7 additions & 22 deletions lib/shared/relative-module-resolver.js
Expand Up @@ -6,35 +6,18 @@
"use strict";

const Module = require("module");
const path = require("path");

// Polyfill Node's `Module.createRequire` if not present. We only support the case where the argument is a filepath, not a URL.
const createRequire = (

// Added in v12.2.0
Module.createRequire ||

// Added in v10.12.0, but deprecated in v12.2.0.
Module.createRequireFromPath ||

// Polyfill - This is not executed on the tests on node@>=10.
/* istanbul ignore next */
(filename => {
const mod = new Module(filename, null);

mod.filename = filename;
mod.paths = Module._nodeModulePaths(path.dirname(filename)); // eslint-disable-line no-underscore-dangle
mod._compile("module.exports = require;", filename); // eslint-disable-line no-underscore-dangle
return mod.exports;
})
);
/*
* `Module.createRequire` is added in v12.2.0. It supports URL as well.
* We only support the case where the argument is a filepath, not a URL.
*/
const createRequire = Module.createRequire || Module.createRequireFromPath;

module.exports = {

/**
* Resolves a Node module relative to another module
* @param {string} moduleName The name of a Node module, or a path to a Node module.
*
* @param {string} relativeToPath An absolute path indicating the module that `moduleName` should be resolved relative to. This must be
* a file rather than a directory, but the file need not actually exist.
* @returns {string} The absolute path that would result from calling `require.resolve(moduleName)` in a file located at `relativeToPath`
Expand All @@ -43,6 +26,8 @@ module.exports = {
try {
return createRequire(relativeToPath).resolve(moduleName);
} catch (error) {

// This `if` block is for older Node.js than 12.0.0. We can remove this block in the future.
if (
typeof error === "object" &&
error !== null &&
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -116,7 +116,7 @@
"load-perf": "^0.2.0",
"markdownlint": "^0.15.0",
"markdownlint-cli": "^0.17.0",
"metro-memory-fs": "^0.54.1",
"memfs": "^3.0.1",
"mocha": "^6.1.2",
"mocha-junit-reporter": "^1.23.0",
"npm-license": "^0.3.3",
Expand Down
43 changes: 2 additions & 41 deletions tests/lib/_utils.js
Expand Up @@ -6,7 +6,7 @@
"use strict";

const path = require("path");
const MemoryFs = require("metro-memory-fs");
const { Volume, createFsFromVolume } = require("memfs");

/**
* Prevents leading spaces in a multiline template literal from appearing in the resulting string
Expand All @@ -25,36 +25,6 @@ function unIndent(strings, ...values) {
return lines.map(line => line.slice(minLineIndent)).join("\n");
}

/**
* Add support of `recursive` option.
* @param {import("fs")} fs The in-memory file system.
* @param {() => string} cwd The current working directory.
* @returns {void}
*/
function supportMkdirRecursiveOption(fs, cwd) {
const { mkdirSync } = fs;

fs.mkdirSync = (filePath, options) => {
if (typeof options === "object" && options !== null) {
if (options.recursive) {
const absolutePath = path.resolve(cwd(), filePath);
const parentPath = path.dirname(absolutePath);

if (
parentPath &&
parentPath !== absolutePath &&
!fs.existsSync(parentPath)
) {
fs.mkdirSync(parentPath, options);
}
}
mkdirSync(filePath, options.mode);
} else {
mkdirSync(filePath, options);
}
};
}

/**
* Define in-memory file system.
* @param {Object} options The options.
Expand All @@ -71,17 +41,8 @@ function defineInMemoryFs({
* The in-memory file system for this mock.
* @type {import("fs")}
*/
const fs = new MemoryFs({
cwd,
platform: process.platform === "win32" ? "win32" : "posix"
});

// Support D: drive.
if (process.platform === "win32") {
fs._roots.set("D:", fs._makeDir(0o777)); // eslint-disable-line no-underscore-dangle
}
const fs = createFsFromVolume(new Volume());

supportMkdirRecursiveOption(fs, cwd);
fs.mkdirSync(cwd(), { recursive: true });

/*
Expand Down

0 comments on commit d6636f0

Please sign in to comment.