viewstools / yarn-workspaces-cra-crna

How to use yarn workspaces with Create React App and Create React Native App (Expo) to share common code across
151 stars 23 forks source link

Ignore non-directories when getting workspaces #32

Open dancrumb opened 1 year ago

dancrumb commented 1 year ago

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch get-yarn-workspaces@1.0.2 for the project I'm working on.

I use this pattern in my root package file:

{
 ...
"workspaces": [
    "apps/*",
    "packages/*"
  ]
}

I have some files in my packages directory and get-yarn-workspaces is picking those up as workspaces which breaks some downstream code.

Since workspaces are inherently directories, it makes sense to filter out non-directories.

Here is the diff that solved my problem:

diff --git a/node_modules/get-yarn-workspaces/index.js b/node_modules/get-yarn-workspaces/index.js
index bbacbcb..2803a6e 100644
--- a/node_modules/get-yarn-workspaces/index.js
+++ b/node_modules/get-yarn-workspaces/index.js
@@ -24,5 +24,5 @@ module.exports = function getWorkspaces(from) {
   });

   const packages = getPackages(require(path.join(root, 'package.json')));
-  return flatten(packages.map(name => glob.sync(path.join(root, name))));
+  return flatten(packages.map(name => glob.sync(path.join(root, name)))).filter(w => fs.statSync(w).isDirectory());
 };

This issue body was partially generated by patch-package.