From 06cb019b8e51a5cc7060b94a13d3ca44d0175ad8 Mon Sep 17 00:00:00 2001 From: Innei Date: Mon, 5 Jan 2026 14:29:52 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(electron):=20correct=20next?= =?UTF-8?q?=20config=20codemod=20pattern=20matching=20(#11228)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use findAll with kind: 'pair' instead of find with pattern for redirects - Add webVitalsAttribution removal logic - Improve pattern matching to handle spacing variations - Add invariant checks for better error handling 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude --- .../electronWorkflow/modifiers/nextConfig.mts | 54 ++++++++++++++----- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/scripts/electronWorkflow/modifiers/nextConfig.mts b/scripts/electronWorkflow/modifiers/nextConfig.mts index f1c24bfc61..a37ed48c40 100644 --- a/scripts/electronWorkflow/modifiers/nextConfig.mts +++ b/scripts/electronWorkflow/modifiers/nextConfig.mts @@ -40,13 +40,19 @@ export const modifyNextConfig = async (TEMP_DIR: string) => { } // 1. Remove redirects - const redirectsPair = nextConfigDecl.find({ - rule: { - pattern: 'redirects: $A', - }, - }); - if (redirectsPair) { - const range = redirectsPair.range(); + const redirectsPair = nextConfigDecl + .findAll({ + rule: { + kind: 'pair', + }, + }) + .find((node) => { + const text = node.text(); + return text.startsWith('redirects:') || text.startsWith('redirects :'); + }); + invariant(redirectsPair, '[modifyNextConfig] redirects pair not found'); + { + const range = redirectsPair!.range(); edits.push({ end: range.end.index, start: range.start.index, text: '' }); } @@ -61,18 +67,39 @@ export const modifyNextConfig = async (TEMP_DIR: string) => { const text = node.text(); return text.startsWith('async headers') || text.startsWith('headers'); }); - if (headersMethod) { - const range = headersMethod.range(); + invariant(headersMethod, '[modifyNextConfig] headers method not found'); + { + const range = headersMethod!.range(); edits.push({ end: range.end.index, start: range.start.index, text: '' }); } - // 3. Remove spread element + // 3. Remove webVitalsAttribution + const webVitalsPair = nextConfigDecl + .findAll({ + rule: { + kind: 'pair', + }, + }) + .find((node) => { + const text = node.text(); + return ( + text.startsWith('webVitalsAttribution:') || text.startsWith('webVitalsAttribution :') + ); + }); + invariant(webVitalsPair, '[modifyNextConfig] webVitalsAttribution pair not found'); + { + const range = webVitalsPair!.range(); + edits.push({ end: range.end.index, start: range.start.index, text: '' }); + } + + // 4. Remove spread element const spreads = nextConfigDecl.findAll({ rule: { kind: 'spread_element', }, }); + // eslint-disable-next-line unicorn/consistent-function-scoping const isObjectLevelSpread = (node: any) => node.parent()?.kind() === 'object'; const standaloneSpread = spreads.find((node) => { @@ -84,12 +111,13 @@ export const modifyNextConfig = async (TEMP_DIR: string) => { const objectLevelSpread = standaloneSpread ? null : spreads.find(isObjectLevelSpread); const spreadToRemove = standaloneSpread || objectLevelSpread; - if (spreadToRemove) { - const range = spreadToRemove.range(); + invariant(spreadToRemove, '[modifyNextConfig] spread element not found'); + { + const range = spreadToRemove!.range(); edits.push({ end: range.end.index, start: range.start.index, text: '' }); } - // 4. Inject/force output: 'export' + // 5. Inject/force output: 'export' const outputPair = nextConfigDecl.find({ rule: { pattern: 'output: $A',