Преглед изворни кода

scan multiple node_modules

Yuki Takei пре 1 година
родитељ
комит
50f8809e90
1 измењених фајлова са 38 додато и 31 уклоњено
  1. 38 31
      apps/app/src/utils/next.config.utils.js

+ 38 - 31
apps/app/src/utils/next.config.utils.js

@@ -3,7 +3,10 @@
 const fs = require('fs');
 const fs = require('fs');
 const path = require('path');
 const path = require('path');
 
 
-const nodeModulesPath = path.resolve(__dirname, '../../../../node_modules');
+const nodeModulesPaths = [
+  path.resolve(__dirname, '../../node_modules'),
+  path.resolve(__dirname, '../../../../node_modules'),
+];
 
 
 /**
 /**
  * @typedef { { ignorePackageNames: string[] } } Opts
  * @typedef { { ignorePackageNames: string[] } } Opts
@@ -19,23 +22,25 @@ exports.listScopedPackages = (scopes, opts = defaultOpts) => {
   /** @type {string[]} */
   /** @type {string[]} */
   const scopedPackages = [];
   const scopedPackages = [];
 
 
-  fs.readdirSync(nodeModulesPath)
-    .filter(name => scopes.includes(name))
-    .forEach((scope) => {
-      fs.readdirSync(path.resolve(nodeModulesPath, scope))
-        .filter(name => !name.startsWith('.'))
-        .forEach((folderName) => {
-          const { name } = require(path.resolve(
-            nodeModulesPath,
-            scope,
-            folderName,
-            'package.json',
-          ));
-          if (!opts.ignorePackageNames.includes(name)) {
-            scopedPackages.push(name);
-          }
-        });
-    });
+  nodeModulesPaths.forEach((nodeModulesPath) => {
+    fs.readdirSync(nodeModulesPath)
+      .filter(name => scopes.includes(name))
+      .forEach((scope) => {
+        fs.readdirSync(path.resolve(nodeModulesPath, scope))
+          .filter(name => !name.startsWith('.'))
+          .forEach((folderName) => {
+            const { name } = require(path.resolve(
+              nodeModulesPath,
+              scope,
+              folderName,
+              'package.json',
+            ));
+            if (!opts.ignorePackageNames.includes(name)) {
+              scopedPackages.push(name);
+            }
+          });
+      });
+  });
 
 
   return scopedPackages;
   return scopedPackages;
 };
 };
@@ -47,19 +52,21 @@ exports.listPrefixedPackages = (prefixes, opts = defaultOpts) => {
   /** @type {string[]} */
   /** @type {string[]} */
   const prefixedPackages = [];
   const prefixedPackages = [];
 
 
-  fs.readdirSync(nodeModulesPath)
-    .filter(name => prefixes.some(prefix => name.startsWith(prefix)))
-    .filter(name => !name.startsWith('.'))
-    .forEach((folderName) => {
-      const { name } = require(path.resolve(
-        nodeModulesPath,
-        folderName,
-        'package.json',
-      ));
-      if (!opts.ignorePackageNames.includes(name)) {
-        prefixedPackages.push(name);
-      }
-    });
+  nodeModulesPaths.forEach((nodeModulesPath) => {
+    fs.readdirSync(nodeModulesPath)
+      .filter(name => prefixes.some(prefix => name.startsWith(prefix)))
+      .filter(name => !name.startsWith('.'))
+      .forEach((folderName) => {
+        const { name } = require(path.resolve(
+          nodeModulesPath,
+          folderName,
+          'package.json',
+        ));
+        if (!opts.ignorePackageNames.includes(name)) {
+          prefixedPackages.push(name);
+        }
+      });
+  });
 
 
   return prefixedPackages;
   return prefixedPackages;
 };
 };