Skip to content

Commit

Permalink
fix: styled-engine new internals (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
romgrk authored Sep 3, 2024
1 parent 8ef7edd commit 4703ccc
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/pigment-css-react/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/processors/
/utils/
/internal/
LICENSE
10 changes: 10 additions & 0 deletions packages/pigment-css-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"processors",
"theme",
"utils",
"internal",
"package.json",
"styles.css",
"LICENSE"
Expand Down Expand Up @@ -132,6 +133,15 @@
"require": "./utils/index.js",
"default": "./utils/index.js"
},
"./internal": {
"types": "./internal/index.d.ts",
"import": {
"types": "./internal/index.d.mts",
"default": "./internal/index.mjs"
},
"require": "./internal/index.js",
"default": "./internal/index.js"
},
"./exports/*": {
"default": "./exports/*.js"
},
Expand Down
1 change: 1 addition & 0 deletions packages/pigment-css-react/src/internal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as styledEngineMockup } from './styledEngineMockup';
13 changes: 13 additions & 0 deletions packages/pigment-css-react/src/internal/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: () => '',
};
5 changes: 5 additions & 0 deletions packages/pigment-css-react/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ export default defineConfig([
],
outDir: 'utils',
},
{
...baseConfig,
entry: ['./src/internal/index.ts'],
outDir: 'internal',
},
]);
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 { styledEngineMockup } from '@pigment-css/react/internal';

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 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 { styledEngineMockup } from '@pigment-css/react/internal';

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 styledEngineMockup;
}
return originalRequire(id);
};
Expand Down

0 comments on commit 4703ccc

Please sign in to comment.