Skip to content

Commit 8db0978

Browse files
authored
chore: Check for package.json in examples (#200)
Previously, OS-created hidden files like `.DS_Store` in `examples/` would cause the prepare and test scripts to throw `ENOTDIR`. They now filter for directories that contain a `package.json` before installing dependencies or running tests.
1 parent b695396 commit 8db0978

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

npm-prepare.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ const fs = require("fs");
1111
const path = require("path");
1212

1313
const examplesDir = path.resolve(__dirname, "examples");
14-
const examples = fs.readdirSync(examplesDir);
14+
const examples = fs.readdirSync(examplesDir)
15+
.filter(exampleDir => fs.statSync(path.join(examplesDir, exampleDir)).isDirectory())
16+
.filter(exampleDir => fs.existsSync(path.join(examplesDir, exampleDir, "package.json")));
1517

1618
for (const example of examples) {
1719
childProcess.execSync("npm install", {

tests/examples/all.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ const fs = require("fs");
55
const path = require("path");
66
const semver = require("semver");
77

8-
const examples = path.resolve(__dirname, "../../examples/");
9-
for (const example of fs.readdirSync(examples)) {
10-
const cwd = path.join(examples, example);
8+
const examplesDir = path.resolve(__dirname, "../../examples/");
9+
const examples = fs.readdirSync(examplesDir)
10+
.filter(exampleDir => fs.statSync(path.join(examplesDir, exampleDir)).isDirectory())
11+
.filter(exampleDir => fs.existsSync(path.join(examplesDir, exampleDir, "package.json")));
12+
13+
for (const example of examples) {
14+
const cwd = path.join(examplesDir, example);
1115

1216
// The plugin officially supports ESLint as early as v6, but the examples
1317
// use ESLint v7, which has a higher minimum Node.js version than does v6.

0 commit comments

Comments
 (0)