Skip to content

Commit 1efb56f

Browse files
authored
Use yarn workspaces foreach for lint command (#479)
1 parent efde1de commit 1efb56f

File tree

30 files changed

+1001
-860
lines changed

30 files changed

+1001
-860
lines changed

.yarn/releases/code-chronicles.patch

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
From: Miorel-Lucian Palii <[email protected]>
2-
Date: Mon, 21 Oct 2024 19:50:25 -0700
2+
Date: Fri, 25 Oct 2024 21:06:12 -0700
33
Subject: Code Chronicles Yarn patch!
44

55
---
66
.../sources/commands/set/version/sources.ts | 16 ++++--
7-
.../sources/commands/foreach.ts | 17 ++++--
7+
.../sources/commands/foreach.ts | 49 ++++++++++++-----
88
.../sources/commands/build/bundle.ts | 9 +++-
99
packages/yarnpkg-core/sources/Manifest.ts | 3 +-
1010
packages/yarnpkg-core/sources/Report.ts | 53 ++++++++++++++-----
11-
5 files changed, 72 insertions(+), 26 deletions(-)
11+
5 files changed, 95 insertions(+), 35 deletions(-)
1212

1313
diff --git a/packages/plugin-essentials/sources/commands/set/version/sources.ts b/packages/plugin-essentials/sources/commands/set/version/sources.ts
1414
index dc38915c1d06f9f41638c55b973fb08f2f695358..0ab5eec31a8109f165a146d4822369a3f31bb8f5 100644
@@ -52,10 +52,35 @@ index dc38915c1d06f9f41638c55b973fb08f2f695358..0ab5eec31a8109f165a146d4822369a3
5252
const bundleBuffer = await xfs.readFilePromise(bundlePath);
5353

5454
diff --git a/packages/plugin-workspace-tools/sources/commands/foreach.ts b/packages/plugin-workspace-tools/sources/commands/foreach.ts
55-
index 47668fc447c882119b4efb7b75453e2dac30a99e..fefe4d75e5bfd45c081171b5e1f242bceb777c01 100644
55+
index 47668fc447c882119b4efb7b75453e2dac30a99e..8487c94a62f158fd1c26c64984d8413c9492c38d 100644
5656
--- a/packages/plugin-workspace-tools/sources/commands/foreach.ts
5757
+++ b/packages/plugin-workspace-tools/sources/commands/foreach.ts
58-
@@ -260,7 +260,7 @@ export default class WorkspacesForeachCommand extends BaseCommand {
58+
@@ -240,11 +240,23 @@ export default class WorkspacesForeachCommand extends BaseCommand {
59+
}
60+
}
61+
62+
+ // Default to maximum verbosity in terminal environments.
63+
+ const verbosity = this.verbose ?? ((this.context.stdout as WriteStream).isTTY ? Infinity : 0);
64+
+ const label = verbosity > 0;
65+
+ const timing = verbosity > 1;
66+
+ let commandCount = 0;
67+
+
68+
for (const workspace of selection) {
69+
if (scriptName && !workspace.manifest.scripts.has(scriptName) && !isGlobalScript) {
70+
const accessibleBinaries = await scriptUtils.getWorkspaceAccessibleBinaries(workspace);
71+
if (!accessibleBinaries.has(scriptName)) {
72+
- log(`Excluding ${workspace.relativeCwd} because it doesn't have a "${scriptName}" script`);
73+
+ // [Code Chronicles] Report what we skipped for explicitness.
74+
+ if (label && !this.dryRun) {
75+
+ const prefix = getPrefix(workspace, {configuration, label, commandIndex: commandCount++});
76+
+ this.context.stdout.write(`${prefix} Skipping because there's no "${scriptName}" script\n`);
77+
+ } else {
78+
+ log(`Excluding ${workspace.relativeCwd} because it doesn't have a "${scriptName}" script\n`);
79+
+ }
80+
continue;
81+
}
82+
}
83+
@@ -260,7 +272,7 @@ export default class WorkspacesForeachCommand extends BaseCommand {
5984
}
6085

6186
if (this.exclude.length > 0 && (micromatch.isMatch(structUtils.stringifyIdent(workspace.anchoredLocator), this.exclude) || micromatch.isMatch(workspace.relativeCwd, this.exclude))) {
@@ -64,7 +89,54 @@ index 47668fc447c882119b4efb7b75453e2dac30a99e..fefe4d75e5bfd45c081171b5e1f242bc
6489
continue;
6590
}
6691

67-
@@ -448,7 +448,7 @@ export default class WorkspacesForeachCommand extends BaseCommand {
92+
@@ -275,11 +287,6 @@ export default class WorkspacesForeachCommand extends BaseCommand {
93+
if (this.dryRun)
94+
return 0;
95+
96+
- // Default to maximum verbosity in terminal environments.
97+
- const verbosity = this.verbose ?? ((this.context.stdout as WriteStream).isTTY ? Infinity : 0);
98+
- const label = verbosity > 0;
99+
- const timing = verbosity > 1;
100+
-
101+
const concurrency = this.parallel ?
102+
(this.jobs === `unlimited`
103+
? Infinity
104+
@@ -296,7 +303,6 @@ export default class WorkspacesForeachCommand extends BaseCommand {
105+
const needsProcessing = new Map<LocatorHash, Workspace>();
106+
const processing = new Set<DescriptorHash>();
107+
108+
- let commandCount = 0;
109+
let finalExitCode: number | null = null;
110+
111+
let abortNextCommands = false;
112+
@@ -324,11 +330,16 @@ export default class WorkspacesForeachCommand extends BaseCommand {
113+
114+
const start = Date.now();
115+
116+
+ // [Code Chronicles] Update the environment to indicate that it's a
117+
+ // `yarn workspaces foreach`.
118+
+ const oldEnv = process.env;
119+
+ process.env = {...oldEnv, CODE_CHRONICLES_RUNNING_VIA_YARN_WORKSPACES_FOREACH: `1`};
120+
const exitCode = (await this.cli.run([this.commandName, ...this.args], {
121+
cwd: workspace.cwd,
122+
stdout,
123+
stderr,
124+
})) || 0;
125+
+ process.env = oldEnv;
126+
127+
stdout.end();
128+
stderr.end();
129+
@@ -399,7 +410,8 @@ export default class WorkspacesForeachCommand extends BaseCommand {
130+
131+
commandPromises.push(limit(async () => {
132+
const exitCode = await runCommand(workspace, {
133+
- commandIndex: ++commandCount,
134+
+ // [Code Chronicles] Start the `commandIndex` at 0.
135+
+ commandIndex: commandCount++,
136+
});
137+
138+
needsProcessing.delete(identHash);
139+
@@ -448,7 +460,7 @@ export default class WorkspacesForeachCommand extends BaseCommand {
68140

69141

70142
function createStream(report: Report, {prefix, interlaced}: {prefix: string | null, interlaced: boolean}): [Writable, Promise<boolean>] {
@@ -73,7 +145,15 @@ index 47668fc447c882119b4efb7b75453e2dac30a99e..fefe4d75e5bfd45c081171b5e1f242bc
73145

74146
const defaultStream = new miscUtils.DefaultStream();
75147
defaultStream.pipe(streamReporter, {end: false});
76-
@@ -484,12 +484,19 @@ function getPrefix(workspace: Workspace, {configuration, commandIndex, label}: G
148+
@@ -480,16 +492,25 @@ type GetPrefixOptions = {
149+
label: boolean;
150+
};
151+
152+
+
153+
+// [Code Chronicles] Add a few more colors.
154+
+const WORKSPACE_COLORS = [`#00A6ED`, `#2E86AB`, `#A23B72`, `#F18F01`, `#C73E1D`, `#CCE2A3`, `#FF69B4`, `#3D9970`];
155+
+
156+
function getPrefix(workspace: Workspace, {configuration, commandIndex, label}: GetPrefixOptions) {
77157
if (!label)
78158
return null;
79159

@@ -85,9 +165,8 @@ index 47668fc447c882119b4efb7b75453e2dac30a99e..fefe4d75e5bfd45c081171b5e1f242bc
85165
+ const prefix = `[${name}]`;
86166

87167
- const colors = [`#2E86AB`, `#A23B72`, `#F18F01`, `#C73E1D`, `#CCE2A3`];
88-
+ // [Code Chronicles] Add a few more colors.
89-
+ const colors = [`#00A6ED`, `#2E86AB`, `#A23B72`, `#F18F01`, `#C73E1D`, `#CCE2A3`, `#FF69B4`, `#3D9970`];
90-
const colorName = colors[commandIndex % colors.length];
168+
- const colorName = colors[commandIndex % colors.length];
169+
+ const colorName = WORKSPACE_COLORS[commandIndex % WORKSPACE_COLORS.length];
91170

92171
return formatUtils.pretty(configuration, prefix, colorName);
93172
}

.yarn/releases/yarn-4.5.1-git.20241018.hash-031b5da-code-chronicles-patch.cjs renamed to .yarn/releases/yarn-4.5.1-git.20241025.hash-f59bbf9-code-chronicles-patch.cjs

Lines changed: 176 additions & 174 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ enableInlineBuilds: true
55
enableTelemetry: false
66
nodeLinker: node-modules
77
tsEnableAutoTypes: true
8-
yarnPath: .yarn/releases/yarn-4.5.1-git.20241018.hash-031b5da-code-chronicles-patch.cjs
8+
yarnPath: .yarn/releases/yarn-4.5.1-git.20241025.hash-f59bbf9-code-chronicles-patch.cjs
9+
# TODO: patch Yarn to not add extra newlines to this file

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
"type": "module",
1111
"scripts": {
1212
"format": "yarn workspace @code-chronicles/repository-scripts start format",
13-
"lint": "yarn workspace @code-chronicles/repository-scripts start lint",
13+
"lint": "code-chronicles-lint",
1414
"prepare": "husky",
1515
"test": "yarn workspace @code-chronicles/repository-scripts start test",
16-
"typecheck": "tsx -e 'require(\"@code-chronicles/repository-scripts/typecheck\").run()'"
16+
"typecheck": "code-chronicles-typecheck"
1717
},
1818
"devDependencies": {
1919
"@code-chronicles/eslint-config": "workspace:*",
2020
"@code-chronicles/repository-scripts": "workspace:*",
2121
"@yarnpkg/types": "4.0.0",
22-
"eslint": "9.12.0",
22+
"eslint": "9.13.0",
2323
"husky": "9.1.6",
2424
"lint-staged": "15.2.10",
2525
"prettier": "3.3.3",

workspaces/adventure-pack/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,34 @@
5252
"build-chrome-extension": "tsx src/scripts/build/buildChromeExtension.ts",
5353
"package-goodies:test": "tsx ./jest.config.ts --testPathIgnorePatterns=\"<rootDir>/goodies/\"",
5454
"format": "yarn goodies:java:format && yarn goodies:kotlin:format && yarn goodies:python3:format && yarn goodies:typescript:format && prettier --color --write .",
55-
"lint": "eslint --color --max-warnings=0 .",
55+
"lint": "code-chronicles-lint",
5656
"postinstall": "yarn goodies:java:install && yarn goodies:kotlin:install && yarn goodies:python3:install",
5757
"test": "yarn goodies:java:test && yarn goodies:kotlin:test && yarn goodies:python3:test && yarn goodies:typescript:test && yarn package-goodies:test",
58-
"typecheck": "tsx -e 'require(\"@code-chronicles/repository-scripts/typecheck\").run()'"
58+
"typecheck": "code-chronicles-typecheck"
5959
},
6060
"dependencies": {
6161
"immutability-helper": "patch:immutability-helper@npm%3A3.1.1#~/.yarn/patches/immutability-helper-npm-3.1.1-482f1f8f58.patch",
6262
"invariant": "2.2.4",
6363
"nullthrows": "patch:nullthrows@npm%3A1.1.1#~/.yarn/patches/nullthrows-npm-1.1.1-3d1f817134.patch",
6464
"react": "18.3.1",
6565
"react-dom": "18.3.1",
66-
"react-syntax-highlighter": "15.5.0"
66+
"react-syntax-highlighter": "15.6.1"
6767
},
6868
"devDependencies": {
6969
"@code-chronicles/eslint-config": "workspace:*",
7070
"@code-chronicles/repository-scripts": "workspace:*",
7171
"@code-chronicles/util": "workspace:*",
7272
"@jest/globals": "29.7.0",
73-
"@types/node": "22.7.6",
74-
"@types/react": "18.3.11",
73+
"@types/node": "22.8.1",
74+
"@types/react": "18.3.12",
7575
"@types/react-dom": "18.3.1",
7676
"@types/react-syntax-highlighter": "15.5.13",
7777
"cross-env": "7.0.3",
78-
"eslint": "9.12.0",
78+
"eslint": "9.13.0",
7979
"fork-ts-checker-webpack-plugin": "9.0.2",
8080
"jest": "29.7.0",
8181
"prettier": "3.3.3",
82-
"prettier-plugin-java": "2.6.4",
82+
"prettier-plugin-java": "2.6.5",
8383
"ts-jest": "29.2.5",
8484
"ts-loader": "9.5.1",
8585
"ts-morph": "24.0.0",

workspaces/download-leetcode-submissions/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"scripts": {
1818
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack",
1919
"format": "prettier --color --write .",
20-
"lint": "eslint --color --max-warnings=0 .",
20+
"lint": "code-chronicles-lint",
2121
"start": "tsx src/main.ts",
22-
"typecheck": "tsx -e 'require(\"@code-chronicles/repository-scripts/typecheck\").run()'"
22+
"typecheck": "code-chronicles-typecheck"
2323
},
2424
"dependencies": {
2525
"@code-chronicles/leetcode-api": "workspace:*",
@@ -31,9 +31,9 @@
3131
"@code-chronicles/eslint-config": "workspace:*",
3232
"@code-chronicles/repository-scripts": "workspace:*",
3333
"@code-chronicles/webpack-make-output-executable-plugin": "workspace:*",
34-
"@types/node": "22.7.6",
34+
"@types/node": "22.8.1",
3535
"cross-env": "7.0.3",
36-
"eslint": "9.12.0",
36+
"eslint": "9.13.0",
3737
"fork-ts-checker-webpack-plugin": "9.0.2",
3838
"prettier": "3.3.3",
3939
"ts-loader": "9.5.1",

workspaces/eslint-config/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
},
1919
"scripts": {
2020
"format": "prettier --color --write .",
21-
"lint": "eslint --color --max-warnings=0 ."
21+
"lint": "code-chronicles-lint"
2222
},
2323
"dependencies": {
2424
"@stylistic/eslint-plugin-js": "2.9.0",
2525
"@stylistic/eslint-plugin-ts": "2.9.0",
26-
"@typescript-eslint/eslint-plugin": "8.10.0",
27-
"@typescript-eslint/parser": "8.10.0",
26+
"@typescript-eslint/eslint-plugin": "8.11.0",
27+
"@typescript-eslint/parser": "8.11.0",
2828
"eslint-import-resolver-typescript": "3.6.3",
2929
"eslint-plugin-import": "2.31.0",
3030
"eslint-plugin-import-x": "4.3.1",
@@ -34,7 +34,7 @@
3434
},
3535
"devDependencies": {
3636
"@code-chronicles/repository-scripts": "workspace:*",
37-
"eslint": "9.12.0",
37+
"eslint": "9.13.0",
3838
"prettier": "3.3.3",
3939
"tsx": "4.19.1"
4040
}

workspaces/fetch-leetcode-problem-list/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"scripts": {
1818
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack",
1919
"format": "prettier --color --write .",
20-
"lint": "eslint --color --max-warnings=0 .",
20+
"lint": "code-chronicles-lint",
2121
"start": "tsx src/main.ts",
22-
"typecheck": "tsx -e 'require(\"@code-chronicles/repository-scripts/typecheck\").run()'"
22+
"typecheck": "code-chronicles-typecheck"
2323
},
2424
"dependencies": {
2525
"@code-chronicles/leetcode-api": "workspace:*",
@@ -29,9 +29,9 @@
2929
"@code-chronicles/eslint-config": "workspace:*",
3030
"@code-chronicles/repository-scripts": "workspace:*",
3131
"@code-chronicles/webpack-make-output-executable-plugin": "workspace:*",
32-
"@types/node": "22.7.6",
32+
"@types/node": "22.8.1",
3333
"cross-env": "7.0.3",
34-
"eslint": "9.12.0",
34+
"eslint": "9.13.0",
3535
"fork-ts-checker-webpack-plugin": "9.0.2",
3636
"prettier": "3.3.3",
3737
"ts-loader": "9.5.1",

workspaces/fetch-recent-accepted-leetcode-submissions/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"scripts": {
1818
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack",
1919
"format": "prettier --color --write .",
20-
"lint": "eslint --color --max-warnings=0 .",
20+
"lint": "code-chronicles-lint",
2121
"start": "tsx src/main.ts",
22-
"typecheck": "tsx -e 'require(\"@code-chronicles/repository-scripts/typecheck\").run()'"
22+
"typecheck": "code-chronicles-typecheck"
2323
},
2424
"dependencies": {
2525
"@code-chronicles/leetcode-api": "workspace:*",
@@ -29,9 +29,9 @@
2929
"@code-chronicles/eslint-config": "workspace:*",
3030
"@code-chronicles/repository-scripts": "workspace:*",
3131
"@code-chronicles/webpack-make-output-executable-plugin": "workspace:*",
32-
"@types/node": "22.7.6",
32+
"@types/node": "22.8.1",
3333
"cross-env": "7.0.3",
34-
"eslint": "9.12.0",
34+
"eslint": "9.13.0",
3535
"fork-ts-checker-webpack-plugin": "9.0.2",
3636
"prettier": "3.3.3",
3737
"ts-loader": "9.5.1",

workspaces/generate-health-report/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
"type": "module",
1616
"scripts": {
1717
"format": "prettier --color --write .",
18-
"lint": "eslint --color --max-warnings=0 .",
18+
"lint": "code-chronicles-lint",
1919
"start": "tsx src/main.ts",
20-
"typecheck": "tsc --pretty --project ."
20+
"typecheck": "code-chronicles-typecheck"
2121
},
2222
"dependencies": {
2323
"@code-chronicles/util": "workspace:*",
@@ -26,8 +26,8 @@
2626
},
2727
"devDependencies": {
2828
"@code-chronicles/eslint-config": "workspace:*",
29-
"@types/node": "22.7.6",
30-
"eslint": "9.12.0",
29+
"@types/node": "22.8.1",
30+
"eslint": "9.13.0",
3131
"prettier": "3.3.3",
3232
"typescript": "5.6.3"
3333
}

0 commit comments

Comments
 (0)