Explorar el Código

Merge pull request #6750 from vidartf/lerna

Fix resolution of lerna packages in buildutils
Steven Silvester hace 5 años
padre
commit
0af11c628a
Se han modificado 1 ficheros con 17 adiciones y 5 borrados
  1. 17 5
      buildutils/src/utils.ts

+ 17 - 5
buildutils/src/utils.ts

@@ -15,12 +15,24 @@ const backSlash = /\\/g;
  */
 export function getLernaPaths(basePath = '.'): string[] {
   basePath = path.resolve(basePath);
-  let baseConfig = require(path.join(basePath, 'package.json'));
+  let packages;
+  try {
+    let baseConfig = require(path.join(basePath, 'package.json'));
+    if (baseConfig.workspaces) {
+      packages = baseConfig.workspaces.packages || baseConfig.workspaces;
+    } else {
+      baseConfig = require(path.join(basePath, 'lerna.json'));
+      packages = baseConfig.packages;
+    }
+  } catch (e) {
+    if (e.code === 'MODULE_NOT_FOUND') {
+      throw new Error(
+        `No yarn workspace / lerna package list found in ${basePath}`
+      );
+    }
+    throw e;
+  }
   let paths: string[] = [];
-  let packages =
-    baseConfig.workspaces.packages ||
-    baseConfig.workspaces ||
-    baseConfig.packages;
   for (let config of packages) {
     paths = paths.concat(glob.sync(path.join(basePath, config)));
   }