@automattic/eslint-plugin-wpvip 0.5.6 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/eslint-plugin-wpvip",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "ESLint plugin for internal WordPress VIP projects",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,7 +1,23 @@
1
1
  const debugLog = require( './debug-log' );
2
2
  const findPackageJson = require( 'find-package-json' );
3
3
 
4
- const parent = findPackageJson( __dirname ).next()?.value || {};
4
+ // Get a list of all package.json files in the current directory tree, ascending
5
+ // up the tree from the current directory. Note that this code behaves differently
6
+ // when it is installed as a package vs. when we are linting the code in this repo.
7
+ //
8
+ // When installed as a package, the current directory is inside node_modules and is
9
+ // not the "package root" as we are thinking about it. In this case, we need to ignore
10
+ // all package.json files that are inside node_modules directories.
11
+ //
12
+ // When we are linting the code in this repo, the current directory is not inside
13
+ // node_modules and the first found "package.json" is the "package root."
14
+ //
15
+ // This problem is basically impossible to solve for all edge cases (like someone who
16
+ // runs `npm run lint` from inside "node_modules") but this code should work for
17
+ // most cases.
18
+ const packages = [ ...findPackageJson( __dirname ) ];
19
+ const parent =
20
+ packages.find( pkg => ! pkg.__path.includes( '/node_modules/' ) ) || packages.pop() || {};
5
21
 
6
22
  debugLog( `Found package.json: ${ parent.__path || 'none' }` );
7
23