Skip to content

Commit e144cc5

Browse files
authored
Fix lint:teams package script (#6941)
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.
1 parent f35ae4c commit e144cc5

File tree

3 files changed

+43
-1543
lines changed

3 files changed

+43
-1543
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@
7272
"@types/semver": "^7",
7373
"@typescript-eslint/eslint-plugin": "^8.7.0",
7474
"@typescript-eslint/parser": "^8.7.0",
75-
"@yarnpkg/cli": "^4.5.3",
76-
"@yarnpkg/core": "^4.1.6",
77-
"@yarnpkg/fslib": "^3.1.1",
7875
"@yarnpkg/types": "^4.0.0",
7976
"babel-jest": "^29.7.0",
8077
"chalk": "^4.1.2",

scripts/lint-teams-json.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import { readJsonFile } from '@metamask/utils/node';
2-
import { getPluginConfiguration } from '@yarnpkg/cli';
3-
import { Configuration, Project, structUtils } from '@yarnpkg/core';
4-
import { ppath } from '@yarnpkg/fslib';
2+
import execa from 'execa';
53
import path from 'path';
64

7-
main().catch(console.error);
5+
type Workspace = {
6+
location: string;
7+
name: string;
8+
};
9+
10+
// Run the script immediately.
11+
main().catch((error) => {
12+
console.error(error);
13+
process.exitCode = 1;
14+
});
815

916
/**
1017
* The entrypoint to this script.
@@ -16,17 +23,9 @@ main().catch(console.error);
1623
async function main() {
1724
const releaseableWorkspaces = await getPublicWorkspaces();
1825
const releaseablePackageNames = releaseableWorkspaces.map((workspace) => {
19-
const packageName = workspace.manifest.name;
20-
if (packageName === null) {
21-
throw new Error(
22-
`${structUtils.stringifyIdent(
23-
workspace.anchoredDescriptor,
24-
)} has no name in its manifest`,
25-
);
26-
}
2726
// The package names in teams.json omit the leading "@", so we do that here
2827
// too in order to be consistent
29-
return structUtils.stringifyIdent(packageName).slice(1);
28+
return workspace.name.slice(1);
3029
});
3130

3231
const teams = await readJsonFile<Record<string, string>>(
@@ -52,18 +51,19 @@ async function main() {
5251
}
5352

5453
/**
55-
* Uses the Yarn API to gather the Yarn workspaces inside of this project (the
56-
* packages that are matched by the `workspaces` field inside of
54+
* Uses the `yarn` executable to gather the Yarn workspaces inside of this
55+
* project (the packages that are matched by the `workspaces` field inside of
5756
* `package.json`).
5857
*
5958
* @returns The list of workspaces.
6059
*/
61-
async function getPublicWorkspaces() {
62-
const cwd = ppath.resolve('..', ppath.cwd());
63-
const configuration = await Configuration.find(cwd, getPluginConfiguration());
64-
const { project } = await Project.find(configuration, cwd);
60+
async function getPublicWorkspaces(): Promise<Workspace[]> {
61+
const { stdout } = await execa('yarn', [
62+
'workspaces',
63+
'list',
64+
'--json',
65+
'--no-private',
66+
]);
6567

66-
return project.workspaces.filter((workspace) => {
67-
return !workspace.manifest.private;
68-
});
68+
return stdout.split('\n').map((line) => JSON.parse(line));
6969
}

0 commit comments

Comments
 (0)