Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit cc1f5c5

Browse files
authored
fix: support nohoist in yarn workspaces (#537)
1 parent e695551 commit cc1f5c5

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

packages/utils/src/index.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,41 @@ const minimatch = require("minimatch");
99

1010
const isCI = !!process.env.CI;
1111

12+
// Supports workspaces using nohoist
13+
// https://classic.yarnpkg.com/blog/2018/02/15/nohoist/
14+
const getYarnPackages = (workspaces) => {
15+
// No workspaces
16+
if (!workspaces) {
17+
return [];
18+
}
19+
20+
try {
21+
// "workspaces": ["packages/*"],
22+
if (Array.isArray(workspaces)) {
23+
return workspaces;
24+
}
25+
26+
// "workspaces": {
27+
// "packages": ["packages/*"],
28+
// },
29+
if (Array.isArray(workspaces.packages)) {
30+
return workspaces.packages;
31+
}
32+
} catch (e) {
33+
// Ignore, returns empty array below
34+
}
35+
36+
// Invalid format
37+
return [];
38+
};
39+
1240
const pkg = importCwd("./package.json");
1341
const findPkgs = (g) => globby.sync(`${g}/package.json`);
1442
const reducePkgs = (acc, curr) => acc.concat(curr.map((c) => c.slice(0, -13)));
1543
const lerna = importCwd.silent("./lerna.json");
16-
const workspaces = (pkg.workspaces || []).map(findPkgs).reduce(reducePkgs, []);
44+
const workspaces = getYarnPackages(pkg.workspaces)
45+
.map(findPkgs)
46+
.reduce(reducePkgs, []);
1747
const lernaPackages = ((lerna && lerna.packages) || [])
1848
.map(findPkgs)
1949
.reduce(reducePkgs, []);

0 commit comments

Comments
 (0)