Skip to content

Commit

Permalink
chore: Check for package.json in examples (#200)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
btmills authored Nov 30, 2021
1 parent b695396 commit 8db0978
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion npm-prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const fs = require("fs");
const path = require("path");

const examplesDir = path.resolve(__dirname, "examples");
const examples = fs.readdirSync(examplesDir);
const examples = fs.readdirSync(examplesDir)
.filter(exampleDir => fs.statSync(path.join(examplesDir, exampleDir)).isDirectory())
.filter(exampleDir => fs.existsSync(path.join(examplesDir, exampleDir, "package.json")));

for (const example of examples) {
childProcess.execSync("npm install", {
Expand Down
10 changes: 7 additions & 3 deletions tests/examples/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ const fs = require("fs");
const path = require("path");
const semver = require("semver");

const examples = path.resolve(__dirname, "../../examples/");
for (const example of fs.readdirSync(examples)) {
const cwd = path.join(examples, example);
const examplesDir = path.resolve(__dirname, "../../examples/");
const examples = fs.readdirSync(examplesDir)
.filter(exampleDir => fs.statSync(path.join(examplesDir, exampleDir)).isDirectory())
.filter(exampleDir => fs.existsSync(path.join(examplesDir, exampleDir, "package.json")));

for (const example of examples) {
const cwd = path.join(examplesDir, example);

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

0 comments on commit 8db0978

Please sign in to comment.