-
Notifications
You must be signed in to change notification settings - Fork 208
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
5 changed files
with
1,219 additions
and
43 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 |
---|---|---|
@@ -1,26 +1,40 @@ | ||
// @ts-check | ||
import { execFileSync } from 'child_process'; | ||
import process from 'node:process'; | ||
|
||
import { getPluginConfiguration } from '@yarnpkg/cli'; | ||
import { Configuration, Project } from '@yarnpkg/core'; | ||
|
||
const pluginConf = getPluginConfiguration(); | ||
|
||
/** | ||
* Omits the root | ||
* | ||
* @returns {Array<{ location: string, name: string }>} | ||
* @returns {Promise<Array<{ location: string, name: string }>>} e.g. {"location":"packages/zoe","name":"@agoric/zoe"} | ||
*/ | ||
export const listWorkspaces = () => { | ||
const ndjson = execFileSync('yarn', ['workspaces', 'list', '--json'], { | ||
stdio: ['ignore', 'pipe', 'inherit'], | ||
shell: true, | ||
encoding: 'utf-8', | ||
}); | ||
return ndjson | ||
.trim() | ||
.split('\n') | ||
.map(line => { | ||
try { | ||
return JSON.parse(line); | ||
} catch (e) { | ||
throw new Error(`Could not parse '${line}'`); | ||
} | ||
}) | ||
.filter(({ location }) => location !== '.'); | ||
export const listWorkspaces = async () => { | ||
const cwd = process.cwd(); | ||
const configuration = await Configuration.find( | ||
// @ts-expect-error not a PortablePath | ||
cwd, | ||
pluginConf, | ||
); | ||
const { project } = await Project.find( | ||
configuration, | ||
configuration.startingCwd, | ||
); | ||
const { workspacesByIdent } = project; | ||
const records = []; | ||
for (const entry of workspacesByIdent.entries()) { | ||
const [_, workspace] = entry; | ||
const { locator, relativeCwd } = workspace; | ||
// omit root | ||
if (relativeCwd === '.') { | ||
continue; | ||
} | ||
records.push({ | ||
location: relativeCwd, | ||
name: locator.scope ? `@${locator.scope}/${locator.name}` : locator.name, | ||
}); | ||
} | ||
return records; | ||
}; |
Oops, something went wrong.