From 415123502b5f00e3988fc49b4643c945f91185e3 Mon Sep 17 00:00:00 2001 From: Jeroen Knoops Date: Sun, 6 Oct 2019 23:14:56 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Adhere=20to=20lerna=20set?= =?UTF-8?q?tings=20for=20workspaces=20directory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes: #85 --- lib/util/lerna.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/util/lerna.js b/lib/util/lerna.js index b5fdf1dd..51f8f1e7 100755 --- a/lib/util/lerna.js +++ b/lib/util/lerna.js @@ -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) { @@ -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);