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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading