Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: styled-engine new internals #220

Merged
merged 16 commits into from
Sep 3, 2024
Merged
10 changes: 3 additions & 7 deletions apps/pigment-css-next-app/next.config.js
romgrk marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// eslint-ignore-next-line import/no-unresolved
const { withPigment } = require('@pigment-css/nextjs-plugin');
const { experimental_extendTheme: extendTheme } = require('@mui/material/styles');
// eslint-ignore-next-line @typescript-eslint/naming-convention
const { internal_styledEngineMockup } = require('@pigment-css/react');

/**
* @typedef {import('@pigment-css/nextjs-plugin').PigmentOptions} PigmentOptions
Expand Down Expand Up @@ -118,13 +120,7 @@ const pigmentOptions = {
...context,
require: (id) => {
if (id === '@mui/styled-engine' || id === '@mui/styled-engine-sc') {
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed here. I'll clean this up separately since it's not a package.

__esModule: true,
default: () => () => () => null,
internal_processStyles: () => {},
keyframes: () => '',
css: () => '',
};
return internal_styledEngineMockup;
}
return context.require(id);
},
Expand Down
1 change: 1 addition & 0 deletions packages/pigment-css-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export { default as createUseThemeProps } from './createUseThemeProps';
export { default as internal_createExtendSxProp } from './createExtendSxProp';
export { default as useTheme } from './useTheme';
export { default as globalCss } from './globalCss';
export { default as internal_styledEngineMockup } from './styledEngineMockup';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be part of the public api (base module export) but can come from a path like @pigment-css/react/internal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the convention for internal_createExtendSxProp right above. I'll move it to a new internal folder.

13 changes: 13 additions & 0 deletions packages/pigment-css-react/src/styledEngineMockup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Replicates `@mui/styled-engine` internals for the plugins to swap the runtime.
*/

export default {
__esModule: true,
default: () => () => () => null,
internal_mutateStyles: () => {},
internal_processStyles: () => {},
internal_serializeStyles: (x: any) => x,
keyframes: () => '',
css: () => '',
};
9 changes: 2 additions & 7 deletions packages/pigment-css-unplugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
type PluginCustomOptions,
} from '@pigment-css/react/utils';
import type { ResolvePluginInstance } from 'webpack';
import { internal_styledEngineMockup } from '@pigment-css/react';

import { handleUrlReplacement, type AsyncResolver } from './utils';

Expand Down Expand Up @@ -87,13 +88,7 @@ const addMaterialUIOverriedContext = (originalContext: Record<string, unknown>)
const originalRequire = originalContext.require as (id: string) => any;
const newRequire = (id: string) => {
if (id === '@mui/styled-engine' || id === '@mui/styled-engine-sc') {
return {
__esModule: true,
default: () => () => () => null,
internal_processStyles: () => {},
keyframes: () => '',
css: () => '',
};
return internal_styledEngineMockup;
}
return originalRequire(id);
};
Expand Down
9 changes: 2 additions & 7 deletions packages/pigment-css-vite-plugin/src/vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
type IFileReporterOptions,
} from '@wyw-in-js/transform';
import { matchAdapterPath, type PluginCustomOptions } from '@pigment-css/react/utils';
import { internal_styledEngineMockup } from '@pigment-css/react';

export type VitePluginOptions = {
debug?: IFileReporterOptions | false | null | undefined;
Expand All @@ -45,13 +46,7 @@ const addMaterialUIOverriedContext = (originalContext: Record<string, unknown>)
const originalRequire = originalContext.require as (id: string) => any;
const newRequire = (id: string) => {
if (id === '@mui/styled-engine' || id === '@mui/styled-engine-sc') {
return {
__esModule: true,
default: () => () => () => null,
internal_processStyles: () => {},
keyframes: () => '',
css: () => '',
};
return internal_styledEngineMockup;
}
return originalRequire(id);
};
Expand Down
Loading