Skip to content

Commit

Permalink
fix: 🐛 Adhere to lerna settings for workspaces directory
Browse files Browse the repository at this point in the history
Closes: #85
  • Loading branch information
JeroenKnoops committed Oct 6, 2019
1 parent e640730 commit 4151235
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions lib/util/lerna.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,32 @@ const isDir = (root) => (name) => {
}
};

const removeLastDirectoryPartOf = (url) => {
return url.substring(0, url.lastIndexOf('/'));
}

const getPackageDirectory = (state) => {
const pkgFilename = path.join(state.root, 'package.json');

if (fs.existsSync(pkgFilename)) {
try {
const packagesDirectory = require(pkgFilename).workspaces.packages;

if (packagesDirectory) {
// Remove the /* on the tail
return removeLastDirectoryPartOf("" + packagesDirectory);
}
// eslint-disable-next-line no-empty
} catch (error) {
}
}

return "packages";
}

const getAllPackages = (state) => {
try {
const dir = path.join(state.root, 'packages');
const dir = path.join(state.root, getPackageDirectory(state));

return fs.readdirSync(dir).filter(isDir(dir));
} catch (error) {
Expand All @@ -35,10 +58,10 @@ const getChangedFiles = () => {
.split('\n');
}

const getChangedPackages = () => {
const getChangedPackages = (state) => {
const unique = {};
const changedFiles = getChangedFiles();
const regex = /^packages\/([^/]+)\//;
const regex = new RegExp("^"+ getPackageDirectory(state) +"\/([^/]+)\/", "is");

for (const filename of changedFiles) {
const matches = filename.match(regex);
Expand Down

0 comments on commit 4151235

Please sign in to comment.