Skip to content

Commit 1b300ff

Browse files
JohnMcLearclaude
andauthored
fix(plugins): keep checkPlugin from undoing the ESLint 9 migration (#8585)
* fix(plugins): keep checkPlugin from undoing the ESLint 9 migration The 28 Nov sync put .eslintrc.cjs back into ep_hljs and ep_dynamic_default_content, dropped their TypeScript 7 Dependabot ignore, and wrote a lint.yml whose `version: 10` clashes with a plugin packageManager pin ("Multiple versions of pnpm specified"). - Replace lib/eslintrc.cjs with lib/eslint.config.mjs. A plugin with a flat config keeps it and loses any leftover .eslintrc.*; one with only the stock .eslintrc.cjs, or none, gets the flat config and ESLint 9. A customised .eslintrc.* is only warned about. - Default devDependencies are eslint ^9.39.5 and eslint-config-etherpad ^5.0.4. - lib/dependabot.yml keeps typescript below 7. - lint.yml takes pnpm from core's packageManager (sparse checkout of core's package.json), like the test workflows, so no template pins a pnpm version. checkPlugin drops a plugin's own pnpm packageManager pin. - ep_dynamic_default_content no longer needs its own lint.yml. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TcYAoDMav4BPPE9JrMtSvw * fix(plugins): only move plugins to ESLint 9 when they lint with a flat config Review follow-ups: - Decide the ESLint config before touching eslint devDependencies. A plugin with only a customised .eslintrc.* is no longer given ESLint 9, which would ignore its config. - A plugin that already has a flat config gets at least eslint ^9.39.5 and eslint-config-etherpad ^5.0.4, so removing its legacy config cannot leave it on ESLint 8. - Next to a flat config, only the stock .eslintrc.cjs is deleted; a customised one is kept with a warning. - autofix runs `pnpm install --no-frozen-lockfile`, so the lockfile follows the package.json changes even where CI makes frozen the default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TcYAoDMav4BPPE9JrMtSvw --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent bb38a97 commit 1b300ff

9 files changed

Lines changed: 320 additions & 33 deletions

File tree

‎bin/plugins/README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ listed in `SKIP_REPOS` in the workflow.
7070
checkPlugin does not bump the plugin version; the plugin's `npmpublish.yml`
7171
does that when the push lands.
7272

73+
Plugins lint with ESLint 9 and a flat config. checkPlugin keeps a plugin's own
74+
`eslint.config.*`, deletes a leftover stock `.eslintrc.cjs` next to it (ESLint 9
75+
ignores it), and moves a plugin that only has the stock `.eslintrc.cjs`, or no
76+
config at all, to `lib/eslint.config.mjs`. A plugin on a flat config gets at
77+
least eslint 9 and eslint-config-etherpad 5.0.4. A customised `.eslintrc.*` is
78+
never deleted: it gets a warning and has to be migrated by hand.
79+
80+
Every workflow template gets pnpm from core's `packageManager` field, so plugin
81+
CI runs the same pnpm as core and no template sets a pnpm `version:`. A
82+
plugin's own `packageManager: pnpm@...` pin is removed for the same reason.
83+
7384
```
7485
getCorePlugins.sh
7586
updateCorePlugins.sh

‎bin/plugins/checkPlugin.ts‎

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import childProcess from 'node:child_process';
2121
import log4js from 'log4js';
2222
import path from 'node:path';
2323
import semver from "semver";
24+
import {dropPnpmPin, flatConfigDevDepBumps, syncEslintConfig} from './pluginLint';
2425

2526
// Template files that some plugins deliberately customise. checkPlugin leaves
2627
// these alone instead of overwriting them with the copy in bin/plugins/lib/.
@@ -44,8 +45,8 @@ const KEEP_FILES: {[plugin: string]: string[]} = {
4445
ep_who_did_what: ['.github/workflows/frontend-tests.yml', '.github/workflows/backend-tests.yml'],
4546
// Installs ep_file_menu_toolbar, whose Edit menu this plugin extends.
4647
ep_copy_paste_select_all: ['.github/workflows/frontend-tests.yml'],
47-
// Runs core from the workspace root and pins pnpm via packageManager.
48-
ep_dynamic_default_content: ['.github/workflows/frontend-tests.yml', '.github/workflows/lint.yml'],
48+
// Runs core from the workspace root.
49+
ep_dynamic_default_content: ['.github/workflows/frontend-tests.yml'],
4950
// Builds the admin SPA for the /admin access specs.
5051
ep_openid_connect: ['.github/workflows/backend-tests.yml'],
5152
};
@@ -246,11 +247,9 @@ log4js.configure({
246247
const parsedPackageJSON = JSON.parse(packageJSON);
247248

248249
await updateDeps(parsedPackageJSON, 'devDependencies', {
249-
// Match the plugin fleet, but never rewrite an existing pin: some plugins
250-
// are already on newer majors (e.g. eslint 10), and changing the
251-
// TypeScript version can break plugin code.
252-
'eslint': {ver: '^8.57.1', overwrite: false},
253-
'eslint-config-etherpad': {ver: '^5.0.0', overwrite: false},
250+
// Never rewrite an existing pin: changing the TypeScript version can
251+
// break plugin code. eslint and eslint-config-etherpad are handled with
252+
// the ESLint config below.
254253
'typescript': {ver: '~6.0.3', overwrite: false},
255254
// These were moved to eslint-config-etherpad's dependencies so they can be removed:
256255
'@typescript-eslint/eslint-plugin': null,
@@ -292,19 +291,21 @@ log4js.configure({
292291
delete parsedPackageJSON.eslintConfig;
293292
await writePackageJson(parsedPackageJSON);
294293
}
295-
if (files.includes('.eslintrc.js')) {
296-
const [from, to] = [`${pluginPath}/.eslintrc.js`, `${pluginPath}/.eslintrc.cjs`];
297-
if (!files.includes('.eslintrc.cjs')) {
298-
if (autoFix) {
299-
await fsp.rename(from, to);
300-
} else {
301-
logger.warn(`please rename ${from} to ${to}`);
302-
}
303-
} else {
304-
logger.error(`both ${from} and ${to} exist; delete ${from}`);
305-
}
306-
} else {
307-
await checkFile('bin/plugins/lib/eslintrc.cjs', '.eslintrc.cjs', false);
294+
// ESLint 9 only reads flat configs (eslint.config.*). Never write a legacy
295+
// .eslintrc.cjs: ESLint 9 ignores it, and it confuses anyone reading the
296+
// plugin.
297+
const {usesFlatConfig} = syncEslintConfig(
298+
pluginPath, await fsp.readFile('bin/plugins/lib/eslint.config.mjs', 'utf8'), autoFix, logger);
299+
if (usesFlatConfig) {
300+
// A flat config needs ESLint 9 and eslint-config-etherpad 5.0.4. Newer
301+
// pins (e.g. eslint 10) are kept.
302+
await updateDeps(parsedPackageJSON, 'devDependencies',
303+
flatConfigDevDepBumps(parsedPackageJSON.devDependencies));
304+
}
305+
306+
// Plugin CI installs core's pnpm (see lib/*.yml), so drop a plugin's own pin.
307+
if (dropPnpmPin(parsedPackageJSON, autoFix, logger) && autoFix) {
308+
await writePackageJson(parsedPackageJSON);
308309
}
309310

310311
if (checkEntries(parsedPackageJSON, {
@@ -517,7 +518,9 @@ log4js.configure({
517518

518519
// Install dependencies so we can run ESLint. This should also create or update package-lock.json
519520
// if autoFix is enabled.
520-
const npmInstall = `pnpm install`;
521+
// pnpm defaults to --frozen-lockfile under CI, which would fail after the
522+
// autofixes above changed package.json, so let autofix update the lockfile.
523+
const npmInstall = autoFix ? 'pnpm install --no-frozen-lockfile' : 'pnpm install';
521524
execSync(npmInstall, {stdio: 'inherit'});
522525
// Create the ep_etherpad-lite symlink if necessary. This must be done after running `npm install`
523526
// because that command nukes the symlink.

‎bin/plugins/lib/dependabot.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ updates:
99
schedule:
1010
interval: "daily"
1111
versioning-strategy: "increase"
12+
ignore:
13+
# typescript-eslint has no release that supports TypeScript 7 yet.
14+
- dependency-name: "typescript"
15+
versions: [">=7"]

‎bin/plugins/lib/eslint.config.mjs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import etherpad from 'eslint-config-etherpad/flat/plugin.js';
2+
3+
export default etherpad;

‎bin/plugins/lib/eslintrc.cjs‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎bin/plugins/lib/lint.yml‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,34 @@ jobs:
77
lint:
88
name: ESLint
99
runs-on: ubuntu-latest
10-
# `eslint .` executes .eslintrc.cjs and every installed ESLint plugin, so
10+
# `eslint .` executes eslint.config.mjs and every installed ESLint plugin, so
1111
# don't hand it the caller's contents:write / id-token:write token.
1212
permissions:
1313
contents: read
1414
steps:
1515
- name: Check out plugin repository
1616
uses: actions/checkout@v7
17+
with:
18+
path: plugin
19+
# Only core's package.json is needed: its packageManager field sets the
20+
# pnpm version, the same one the backend and frontend test workflows use.
21+
- name: Check out Etherpad core's package.json
22+
uses: actions/checkout@v7
23+
with:
24+
repository: ether/etherpad
25+
path: core
26+
sparse-checkout: /package.json
27+
sparse-checkout-cone-mode: false
1728
- uses: actions/setup-node@v7
1829
name: Install Node.js
1930
with:
2031
node-version: 26
2132
- uses: pnpm/action-setup@v6.1.1
2233
name: Install pnpm
2334
with:
24-
version: 10
35+
# No `version:`: pnpm comes from core's packageManager, so it follows
36+
# core and never clashes with a version input.
37+
package_json_file: ./core/package.json
2538
run_install: false
2639
- name: Get pnpm store directory
2740
shell: bash
@@ -30,10 +43,12 @@ jobs:
3043
name: Setup pnpm cache
3144
with:
3245
path: ${{ env.STORE_PATH }}
33-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
46+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('plugin/pnpm-lock.yaml') }}
3447
restore-keys: |
3548
${{ runner.os }}-pnpm-store-
3649
- name: Install dependencies
50+
working-directory: plugin
3751
run: pnpm install --ignore-scripts
3852
- name: Run ESLint
53+
working-directory: plugin
3954
run: pnpm run lint

‎bin/plugins/lib/npmpublish.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ jobs:
3838
- uses: pnpm/action-setup@v6.1.1
3939
name: Install pnpm
4040
with:
41+
# No `version:`: the core checkout above puts core's package.json at
42+
# the workspace root, so pnpm comes from core's packageManager, like
43+
# every other plugin workflow.
4144
run_install: false
4245
- name: Get pnpm store directory
4346
shell: bash

‎bin/plugins/pluginLint.ts‎

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Helpers for the parts of checkPlugin.ts that decide a plugin's ESLint config
2+
// and pnpm pin. They only touch the files they are asked about, so the backend
3+
// tests can run them against a scratch directory without installing anything.
4+
5+
import fs from 'node:fs';
6+
import path from 'node:path';
7+
import semver from 'semver';
8+
9+
// File names ESLint 9 reads as a flat config.
10+
export const FLAT_CONFIG_NAMES = [
11+
'eslint.config.js', 'eslint.config.mjs', 'eslint.config.cjs',
12+
'eslint.config.ts', 'eslint.config.mts', 'eslint.config.cts',
13+
];
14+
15+
// Legacy (eslintrc) config file names. ESLint 9 ignores all of them.
16+
export const LEGACY_CONFIG_NAMES = [
17+
'.eslintrc', '.eslintrc.js', '.eslintrc.cjs', '.eslintrc.json', '.eslintrc.yml', '.eslintrc.yaml',
18+
];
19+
20+
// The .eslintrc.cjs that checkPlugin used to write into every plugin. A plugin
21+
// whose legacy config is exactly this can be moved to the flat config with no
22+
// loss; anything else was customised and has to be migrated by hand.
23+
export const STOCK_LEGACY_CONFIG = `'use strict';
24+
25+
// This is a workaround for https://github.com/eslint/eslint/issues/3458
26+
require('eslint-config-etherpad/patch/modern-module-resolution');
27+
28+
module.exports = {
29+
root: true,
30+
extends: 'etherpad/plugin',
31+
};
32+
`;
33+
34+
// devDependencies a plugin needs for the flat config in lib/eslint.config.mjs.
35+
export const FLAT_CONFIG_DEV_DEPS = {
36+
'eslint': '^9.39.5',
37+
'eslint-config-etherpad': '^5.0.4',
38+
};
39+
40+
type Logger = {info: (m: string) => void, warn: (m: string) => void};
41+
42+
export type EslintConfigResult = {
43+
// Files that were (or, without autofix, would be) removed.
44+
removed: string[],
45+
// True when eslint.config.mjs was (or would be) written from the template.
46+
wroteFlatConfig: boolean,
47+
// True when the plugin lints with a flat config afterwards, so it needs at
48+
// least FLAT_CONFIG_DEV_DEPS. False while a customised legacy config waits
49+
// to be migrated by hand: moving that plugin to ESLint 9 would stop it
50+
// reading its own config.
51+
usesFlatConfig: boolean,
52+
};
53+
54+
const normalize = (s: string) => s.replace(/\r\n/g, '\n').trim();
55+
56+
// Make sure the plugin uses an ESLint flat config:
57+
// - a plugin that already has one keeps it, and a leftover stock legacy config
58+
// is removed because ESLint 9 ignores it;
59+
// - a plugin with only the stock legacy config, or none at all, gets
60+
// lib/eslint.config.mjs;
61+
// - a customised legacy config is never removed, only warned about.
62+
// The caller raises the ESLint devDependencies when usesFlatConfig is true.
63+
export const syncEslintConfig = (
64+
pluginPath: string, flatTemplate: string, autoFix: boolean, logger: Logger,
65+
): EslintConfigResult => {
66+
const exists = (f: string) => fs.existsSync(path.join(pluginPath, f));
67+
const flat = FLAT_CONFIG_NAMES.filter(exists);
68+
const legacy = LEGACY_CONFIG_NAMES.filter(exists);
69+
const custom = legacy.filter((f) => normalize(
70+
fs.readFileSync(path.join(pluginPath, f), 'utf8')) !== normalize(STOCK_LEGACY_CONFIG));
71+
const stock = legacy.filter((f) => !custom.includes(f));
72+
const result: EslintConfigResult = {removed: [], wroteFlatConfig: false, usesFlatConfig: false};
73+
74+
const remove = (f: string, why: string) => {
75+
logger.warn(`${f} ${why}; ${autoFix ? 'removing it' : 'please remove it'}`);
76+
if (autoFix) fs.rmSync(path.join(pluginPath, f));
77+
result.removed.push(f);
78+
};
79+
80+
if (flat.length > 0) {
81+
for (const f of stock) remove(f, `is the stock legacy ESLint config and ${flat[0]} exists`);
82+
if (custom.length > 0) {
83+
logger.warn(`${custom.join(', ')} is a customised legacy ESLint config that ESLint 9 ` +
84+
`ignores; move any rules it still needs into ${flat[0]} and delete it by hand`);
85+
}
86+
result.usesFlatConfig = true;
87+
return result;
88+
}
89+
90+
if (custom.length > 0) {
91+
logger.warn(`${custom.join(', ')} is a customised legacy ESLint config; ` +
92+
'move it to eslint.config.mjs by hand (ESLint 9 ignores it)');
93+
return result;
94+
}
95+
96+
for (const f of stock) remove(f, 'is the stock legacy ESLint config');
97+
logger.warn(`eslint.config.mjs not found; ${autoFix ? 'adding' : 'please add'} the template copy`);
98+
if (autoFix) fs.writeFileSync(path.join(pluginPath, 'eslint.config.mjs'), flatTemplate);
99+
result.wroteFlatConfig = true;
100+
result.usesFlatConfig = true;
101+
return result;
102+
};
103+
104+
// The devDependencies a flat-config plugin is missing or has below
105+
// FLAT_CONFIG_DEV_DEPS. Ranges that are not valid semver are left alone.
106+
export const flatConfigDevDepBumps = (devDeps: {[pkg: string]: string} = {}) => {
107+
const want: {[pkg: string]: string} = {};
108+
for (const [pkg, ver] of Object.entries(FLAT_CONFIG_DEV_DEPS)) {
109+
const got = devDeps[pkg];
110+
if (got == null) {
111+
want[pkg] = ver;
112+
} else if (semver.validRange(got) != null &&
113+
semver.lt(semver.minVersion(got)!, semver.minVersion(ver)!)) {
114+
want[pkg] = ver;
115+
}
116+
}
117+
return want;
118+
};
119+
120+
// Plugin CI takes its pnpm version from core's package.json, so a plugin's own
121+
// pnpm pin only makes the plugin run an older (or different) pnpm than core.
122+
// Returns true if the pin was found (and, with autoFix, removed from pkg).
123+
export const dropPnpmPin = (pkg: any, autoFix: boolean, logger: Logger): boolean => {
124+
let found = false;
125+
if (typeof pkg.packageManager === 'string' && pkg.packageManager.startsWith('pnpm@')) {
126+
logger.warn(`package.json pins ${pkg.packageManager} via packageManager; plugin CI uses ` +
127+
`core's pnpm, so ${autoFix ? 'removing it' : 'please remove it'}`);
128+
if (autoFix) delete pkg.packageManager;
129+
found = true;
130+
}
131+
if (pkg.devEngines?.packageManager?.name === 'pnpm') {
132+
// devEngines can carry other settings, so only point it out.
133+
logger.warn('package.json pins pnpm via devEngines.packageManager; plugin CI uses ' +
134+
"core's pnpm, please remove it by hand");
135+
}
136+
return found;
137+
};

0 commit comments

Comments
 (0)