Skip to content

Commit 4703ccc

Browse files
authored
fix: styled-engine new internals (#220)
1 parent 8ef7edd commit 4703ccc

File tree

7 files changed

+34
-14
lines changed

7 files changed

+34
-14
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/processors/
22
/utils/
3+
/internal/
34
LICENSE

packages/pigment-css-react/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"processors",
9999
"theme",
100100
"utils",
101+
"internal",
101102
"package.json",
102103
"styles.css",
103104
"LICENSE"
@@ -132,6 +133,15 @@
132133
"require": "./utils/index.js",
133134
"default": "./utils/index.js"
134135
},
136+
"./internal": {
137+
"types": "./internal/index.d.ts",
138+
"import": {
139+
"types": "./internal/index.d.mts",
140+
"default": "./internal/index.mjs"
141+
},
142+
"require": "./internal/index.js",
143+
"default": "./internal/index.js"
144+
},
135145
"./exports/*": {
136146
"default": "./exports/*.js"
137147
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as styledEngineMockup } from './styledEngineMockup';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Replicates `@mui/styled-engine` internals for the plugins to swap the runtime.
3+
*/
4+
5+
export default {
6+
__esModule: true,
7+
default: () => () => () => null,
8+
internal_mutateStyles: () => {},
9+
internal_processStyles: () => {},
10+
internal_serializeStyles: (x: any) => x,
11+
keyframes: () => '',
12+
css: () => '',
13+
};

packages/pigment-css-react/tsup.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ export default defineConfig([
5050
],
5151
outDir: 'utils',
5252
},
53+
{
54+
...baseConfig,
55+
entry: ['./src/internal/index.ts'],
56+
outDir: 'internal',
57+
},
5358
]);

packages/pigment-css-unplugin/src/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
type PluginCustomOptions,
2626
} from '@pigment-css/react/utils';
2727
import type { ResolvePluginInstance } from 'webpack';
28+
import { styledEngineMockup } from '@pigment-css/react/internal';
2829

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

@@ -87,13 +88,7 @@ const addMaterialUIOverriedContext = (originalContext: Record<string, unknown>)
8788
const originalRequire = originalContext.require as (id: string) => any;
8889
const newRequire = (id: string) => {
8990
if (id === '@mui/styled-engine' || id === '@mui/styled-engine-sc') {
90-
return {
91-
__esModule: true,
92-
default: () => () => () => null,
93-
internal_processStyles: () => {},
94-
keyframes: () => '',
95-
css: () => '',
96-
};
91+
return styledEngineMockup;
9792
}
9893
return originalRequire(id);
9994
};

packages/pigment-css-vite-plugin/src/vite-plugin.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
type IFileReporterOptions,
2222
} from '@wyw-in-js/transform';
2323
import { matchAdapterPath, type PluginCustomOptions } from '@pigment-css/react/utils';
24+
import { styledEngineMockup } from '@pigment-css/react/internal';
2425

2526
export type VitePluginOptions = {
2627
debug?: IFileReporterOptions | false | null | undefined;
@@ -45,13 +46,7 @@ const addMaterialUIOverriedContext = (originalContext: Record<string, unknown>)
4546
const originalRequire = originalContext.require as (id: string) => any;
4647
const newRequire = (id: string) => {
4748
if (id === '@mui/styled-engine' || id === '@mui/styled-engine-sc') {
48-
return {
49-
__esModule: true,
50-
default: () => () => () => null,
51-
internal_processStyles: () => {},
52-
keyframes: () => '',
53-
css: () => '',
54-
};
49+
return styledEngineMockup;
5550
}
5651
return originalRequire(id);
5752
};

0 commit comments

Comments
 (0)