The pkg-renaming rule automates migration of package names from Emotion 10 to Emotion 11, handling the comprehensive package restructuring and export changes.
Automatically migrates package imports from Emotion 10 naming to Emotion 11 structure.
/**
* Internal rule for Emotion 11 package migration codemods
* Handles comprehensive package renaming and export restructuring
*/
interface PkgRenamingRuleConfig {
name: "pkg-renaming";
fixable: true;
schema: never[]; // No configuration options - internal rule
messages: {
renamePackage: string;
exportChange: string;
emotionTheming: string;
};
}The rule handles these package migrations:
interface PackageMappings {
// Core emotion packages
"@emotion/core": "@emotion/react";
"emotion": "@emotion/css";
"emotion/macro": "@emotion/css/macro";
// Styled components
"@emotion/styled-base": "@emotion/styled/base";
// Testing and tooling
"jest-emotion": "@emotion/jest";
"babel-plugin-emotion": "@emotion/babel-plugin";
"eslint-plugin-emotion": "@emotion/eslint-plugin";
// Server-side rendering
"create-emotion-server": "@emotion/server/create-instance";
"create-emotion": "@emotion/css/create-instance";
"emotion-server": "@emotion/server";
// Theming
"emotion-theming": "@emotion/react";
}{
"rules": {
"@emotion/pkg-renaming": "error"
}
}Simple package renames:
// Before
import { css } from '@emotion/core';
import styled from '@emotion/styled-base';
// After (auto-fixed)
import { css } from '@emotion/react';
import styled from '@emotion/styled/base';Complex migration scenarios:
// Before
import emotion from 'emotion';
import { ThemeProvider } from 'emotion-theming';
// After (auto-fixed)
import emotion from '@emotion/css';
import { ThemeProvider } from '@emotion/react';The rule handles export restructuring for packages that changed their export patterns:
Default to named export migration:
// Before
import css from '@emotion/css';
// After (auto-fixed)
import { css } from '@emotion/react';With custom alias:
// Before
import emotionCss from '@emotion/css';
// After (auto-fixed)
import { css as emotionCss } from '@emotion/react';@emotion/core → @emotion/react
emotion → @emotion/css
emotion-theming → @emotion/react
@emotion/css and @emotion/css/macro:
css export in v11emotion-theming integration:
// Before
import createEmotionServer from 'emotion-server';
import createEmotion from 'create-emotion';
// After (auto-fixed)
import createEmotionServer from '@emotion/server';
import createEmotion from '@emotion/css/create-instance';Before (Emotion 10):
import styled from '@emotion/styled-base';
import { css, keyframes } from '@emotion/core';
import { ThemeProvider, useTheme } from 'emotion-theming';
import emotionCss from 'emotion';
import { matchers } from 'jest-emotion';After (auto-fixed to Emotion 11):
import styled from '@emotion/styled/base';
import { css, keyframes } from '@emotion/react';
import { ThemeProvider, useTheme } from '@emotion/react';
import { css as emotionCss } from '@emotion/react';
import { matchers } from '@emotion/jest';Disable this rule if:
This rule is designed as a comprehensive codemod for the Emotion 10 to 11 migration path.