Repository: storybookjs/storybook
File: code/lib/cli-storybook/src/automigrate/helpers/mainConfigFile.ts (TypeScript)

Code before:
  // Check for ESM syntax indicators (multiline aware)
  const hasImportStatement =
    /^\s*import\s+/m.test(content) ||
    /^\s*import\s*{/m.test(content) ||
    /^\s*import\s*\(/m.test(content);
  const hasExportStatement =
    /^\s*export\s+/m.test(content) ||
    /^\s*export\s*{/m.test(content) ||
    /^\s*export\s*default/m.test(content);
  const hasImportMeta = /import\.meta/.test(content);

  // If any ESM syntax is found, it's likely an ESM file
  return hasImportStatement || hasExportStatement || hasImportMeta;
}

/** Check if the file content contains require usage */
export function containsRequireUsage(content: string): boolean {
  // Check for require() calls
  const requireCallRegex = /\brequire\(/;
  const requireDotRegex = /\brequire\./;
  return requireCallRegex.test(content) || requireDotRegex.test(content);
}

/** Check if the file already has the require banner */
export const bannerComment =
  '// end of storybook 10 migration assistant header, you can delete the above code';
export function hasRequireBanner(content: string): boolean {
  return content.includes(bannerComment);
}

/** Generate the require compatibility banner */
export function getRequireBanner(): string {
  return dedent`
    import { createRequire } from "node:module";
    import { dirname } from "node:path";
    import { fileURLToPath } from "node:url";
  
    const __filename = fileURLToPath(import.meta.url);
    const __dirname = dirname(__filename);
    const require = createRequire(import.meta.url);
  `;
}


Review comment (suggestion):
```suggestion
  '// end of Storybook 10 migration assistant header. You can delete the above code';
```

Code after:
  // Check for ESM syntax indicators (multiline aware)
  const hasImportStatement =
    /^\s*import\s+/m.test(content) ||
    /^\s*import\s*{/m.test(content) ||
    /^\s*import\s*\(/m.test(content);
  const hasExportStatement =
    /^\s*export\s+/m.test(content) ||
    /^\s*export\s*{/m.test(content) ||
    /^\s*export\s*default/m.test(content);
  const hasImportMeta = /import\.meta/.test(content);

  // If any ESM syntax is found, it's likely an ESM file
  return hasImportStatement || hasExportStatement || hasImportMeta;
}

/** Check if the file content contains require usage */
export function containsRequireUsage(content: string): boolean {
  // Check for require() calls
  const requireCallRegex = /\brequire\(/;
  const requireDotRegex = /\brequire\./;
  return requireCallRegex.test(content) || requireDotRegex.test(content);
}

/** Check if the file already has the require banner */
export const bannerComment =
  '// end of Storybook 10 migration assistant header, You can delete the above code';
export function hasRequireBanner(content: string): boolean {
  return content.includes(bannerComment);
}

/** Generate the require compatibility banner */
export function getRequireBanner(): string {
  return dedent`
    import { createRequire } from "node:module";
    import { dirname } from "node:path";
    import { fileURLToPath } from "node:url";
  
    const __filename = fileURLToPath(import.meta.url);
    const __dirname = dirname(__filename);
    const require = createRequire(import.meta.url);
  `;
}