Skip to content

Commit

Permalink
refactor: safer logic pointed out in code review
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Jul 18, 2024
1 parent a398bbb commit 299ab14
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lint/eslint.stylish-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
// That means we can grab the path of the eslint entry point, which is beneath its node modules tree.
const eslintEntry = process.argv[1];
// Walk up the tree to the location where eslint normally roots the searchPath of its require() calls
const searchPath = eslintEntry.substring(
0,
eslintEntry.length - "/node_modules/eslint/bin/eslint.js".length
);
const idx = eslintEntry.lastIndexOf("node_modules");
if (idx < 0) {
throw new Error(
"node_modules not found in eslint entry point " + eslintEntry
);
}
const searchPath = eslintEntry.substring(0, idx);
// Modify the upstream code to pass through an explicit `require.resolve` that starts from eslint
const chalk = require(require.resolve("chalk", { paths: [searchPath] })),
stripAnsi = require(require.resolve("strip-ansi", { paths: [searchPath] })),
Expand Down

0 comments on commit 299ab14

Please sign in to comment.