-
-
Notifications
You must be signed in to change notification settings - Fork 252
Fix lint:teams package script #6941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,17 @@ | ||
| import { readJsonFile } from '@metamask/utils/node'; | ||
| import { getPluginConfiguration } from '@yarnpkg/cli'; | ||
| import { Configuration, Project, structUtils } from '@yarnpkg/core'; | ||
| import { ppath } from '@yarnpkg/fslib'; | ||
| import execa from 'execa'; | ||
| import path from 'path'; | ||
|
|
||
| main().catch(console.error); | ||
| type Workspace = { | ||
| location: string; | ||
| name: string; | ||
| }; | ||
|
|
||
| // Run the script immediately. | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| main().catch((error) => { | ||
| console.error(error); | ||
| process.exitCode = 1; | ||
| }); | ||
|
|
||
| /** | ||
| * The entrypoint to this script. | ||
|
|
@@ -16,17 +23,9 @@ main().catch(console.error); | |
| async function main() { | ||
| const releaseableWorkspaces = await getPublicWorkspaces(); | ||
| const releaseablePackageNames = releaseableWorkspaces.map((workspace) => { | ||
| const packageName = workspace.manifest.name; | ||
| if (packageName === null) { | ||
| throw new Error( | ||
| `${structUtils.stringifyIdent( | ||
| workspace.anchoredDescriptor, | ||
| )} has no name in its manifest`, | ||
| ); | ||
| } | ||
| // The package names in teams.json omit the leading "@", so we do that here | ||
| // too in order to be consistent | ||
| return structUtils.stringifyIdent(packageName).slice(1); | ||
| return workspace.name.slice(1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Unchecked Assumptions: Silent Data CorruptionThe code assumes all package names start with "@" and blindly calls |
||
| }); | ||
|
|
||
| const teams = await readJsonFile<Record<string, string>>( | ||
|
|
@@ -52,18 +51,19 @@ async function main() { | |
| } | ||
|
|
||
| /** | ||
| * Uses the Yarn API to gather the Yarn workspaces inside of this project (the | ||
| * packages that are matched by the `workspaces` field inside of | ||
| * Uses the `yarn` executable to gather the Yarn workspaces inside of this | ||
| * project (the packages that are matched by the `workspaces` field inside of | ||
| * `package.json`). | ||
| * | ||
| * @returns The list of workspaces. | ||
| */ | ||
| async function getPublicWorkspaces() { | ||
| const cwd = ppath.resolve('..', ppath.cwd()); | ||
| const configuration = await Configuration.find(cwd, getPluginConfiguration()); | ||
| const { project } = await Project.find(configuration, cwd); | ||
| async function getPublicWorkspaces(): Promise<Workspace[]> { | ||
| const { stdout } = await execa('yarn', [ | ||
| 'workspaces', | ||
| 'list', | ||
| '--json', | ||
| '--no-private', | ||
| ]); | ||
|
|
||
| return project.workspaces.filter((workspace) => { | ||
| return !workspace.manifest.private; | ||
| }); | ||
| return stdout.split('\n').map((line) => JSON.parse(line)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Trailing Newlines Break JSON ParsingThe
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose so. We use this in other scripts though and it hasn't been a problem there, so I'm okay with this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Robust JSON Parsing for Command OutputThe |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove these dependencies? This was the only place they were used