Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(electron): correct next config codemod pattern matching (#11228)

Innei06cb019b8e51
diff --git a/scripts/electronWorkflow/modifiers/nextConfig.mts b/scripts/electronWorkflow/modifiers/nextConfig.mts
index f1c24bfc618..a37ed48c40b 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 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: '' });
}
- // 3. Remove spread element
+ // 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',