-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
193 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const fg = require('fast-glob'); | ||
|
||
const {loadManifest, getPackageSize} = require('.'); | ||
|
||
const loadWorkspace = async (startPath) => { | ||
const resolvedAppPath = path.resolve(startPath); | ||
const manifestPath = path.join(resolvedAppPath, 'package.json'); | ||
if (fs.existsSync(manifestPath)) { | ||
const manifest = await loadManifest(resolvedAppPath); | ||
|
||
if (Array.isArray(manifest.workspaces)) { | ||
const entries = await fg(manifest.workspaces, { | ||
onlyDirectories: true, | ||
unique: true, | ||
cwd: resolvedAppPath, | ||
}); | ||
|
||
const workspaceProjects = await entries.reduce(async (aggPromise, relativePath) => { | ||
const agg = await aggPromise; | ||
const projectPath = path.join(resolvedAppPath, relativePath); | ||
const projectManifest = await loadManifest(projectPath); | ||
agg.push({ | ||
...projectManifest, | ||
relativePath, | ||
size: await getPackageSize(projectPath), | ||
}); | ||
return agg; | ||
}, Promise.resolve([])); | ||
|
||
return { | ||
path: resolvedAppPath, | ||
workspaceProjects, | ||
}; | ||
} | ||
} | ||
|
||
if (resolvedAppPath !== '/') { | ||
return loadWorkspace(path.join(resolvedAppPath, '..')); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
module.exports = {loadWorkspace}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.