Skip to content

Commit

Permalink
fix: support nohoist in yarn workspaces (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
egilsster committed Sep 15, 2020
1 parent e695551 commit cc1f5c5
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion packages/utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,41 @@ const minimatch = require("minimatch");

const isCI = !!process.env.CI;

// Supports workspaces using nohoist
// https://classic.yarnpkg.com/blog/2018/02/15/nohoist/
const getYarnPackages = (workspaces) => {
// No workspaces
if (!workspaces) {
return [];
}

try {
// "workspaces": ["packages/*"],
if (Array.isArray(workspaces)) {
return workspaces;
}

// "workspaces": {
// "packages": ["packages/*"],
// },
if (Array.isArray(workspaces.packages)) {
return workspaces.packages;
}
} catch (e) {
// Ignore, returns empty array below
}

// Invalid format
return [];
};

const pkg = importCwd("./package.json");
const findPkgs = (g) => globby.sync(`${g}/package.json`);
const reducePkgs = (acc, curr) => acc.concat(curr.map((c) => c.slice(0, -13)));
const lerna = importCwd.silent("./lerna.json");
const workspaces = (pkg.workspaces || []).map(findPkgs).reduce(reducePkgs, []);
const workspaces = getYarnPackages(pkg.workspaces)
.map(findPkgs)
.reduce(reducePkgs, []);
const lernaPackages = ((lerna && lerna.packages) || [])
.map(findPkgs)
.reduce(reducePkgs, []);
Expand Down

0 comments on commit cc1f5c5

Please sign in to comment.