Skip to content

Conversation

@mcmire
Copy link
Contributor

@mcmire mcmire commented Oct 24, 2025

Explanation

With the Yarn upgrade, the lint:teams package script now prints an error indicating that the npmMinimalAgeGate configuration option is unrecognized. This script uses the Yarn API to get the list of workspaces, so it's possible something changed internally to where we now need a different incantation to initialize Yarn.

This commit fixes the script so that it uses yarn workspaces to get information about the workspaces instead of the Yarn API. This has always been known to work in the past so hopefully it should avoid any future breakages.

References

(N/A)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

Note

Replace Yarn API usage with yarn workspaces list in scripts/lint-teams-json.ts, removing related @yarnpkg/* dev deps.

  • Scripts:
    • scripts/lint-teams-json.ts:
      • Switch from Yarn API to executing yarn workspaces list --json --no-private via execa.
      • Add Workspace type; parse JSON lines; adjust package name derivation.
      • Add immediate main() invocation with error handling and nonzero exit on failure.
  • Tooling/Dependencies:
    • Remove Yarn API dev deps (@yarnpkg/cli, @yarnpkg/core, @yarnpkg/fslib) from package.json.
    • Lockfile updated accordingly.

Written by Cursor Bugbot for commit d2f9cc0. This will update automatically on new commits. Configure here.

After the Yarn upgrade, the `lint:teams` package script prints an error
indicating that the `npmMinimalAgeGate` configuration option is
unrecognized. This script uses the Yarn API to get the list of
workspaces, so it's possible something changed internally.

This commit fixes the script so that it uses `yarn workspaces` to get
information about the workspaces, hopefully avoiding any future
breakages.
@mcmire mcmire marked this pull request as ready for review October 24, 2025 15:22
return project.workspaces.filter((workspace) => {
return !workspace.manifest.private;
});
return stdout.split('\n').map((line) => JSON.parse(line));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Trailing Newlines Break JSON Parsing

The getPublicWorkspaces function splits yarn workspaces list stdout by newlines and parses each line as JSON. Command-line tools often output trailing newlines or empty lines, which causes JSON.parse('') to throw a SyntaxError and crash the script. This is a regression in error handling.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -1,9 +1,13 @@
import { readJsonFile } from '@metamask/utils/node';
import { getPluginConfiguration } from '@yarnpkg/cli';
Copy link
Member

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

};

// Run the script immediately.
main().catch(console.error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should reconsider this .catch handler. It ended up silencing the error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... maybe we need to exit with a non-zero exit code here, would that work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, exactly. See the create-package script for example, where we do this:

cli(process.argv, commands).catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

// 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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unchecked Assumptions: Silent Data Corruption

The code assumes all package names start with "@" and blindly calls .slice(1) without validation. If a workspace has a package name that doesn't start with "@", the first character will be incorrectly removed, causing silent data corruption. The old code had explicit null checking and error handling that was removed.

Fix in Cursor Fix in Web

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mcmire mcmire enabled auto-merge (squash) November 7, 2025 19:02
return project.workspaces.filter((workspace) => {
return !workspace.manifest.private;
});
return stdout.split('\n').map((line) => JSON.parse(line));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Robust JSON Parsing for Command Output

The stdout.split('\n').map((line) => JSON.parse(line)) pattern will fail if the command output includes a trailing newline, which would create an empty string that causes JSON.parse to throw a SyntaxError. The code should filter out empty lines before parsing, such as using stdout.split('\n').filter(line => line.trim()).map((line) => JSON.parse(line)).

Fix in Cursor Fix in Web

@mcmire mcmire merged commit e144cc5 into main Nov 7, 2025
272 checks passed
@mcmire mcmire deleted the fix-lint-teams branch November 7, 2025 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants