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 12 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
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 { styledEngineMockup } = require('@pigment-css/react/internal');

/**
* @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 styledEngineMockup;
}
return context.require(id);
},
Expand Down
9 changes: 9 additions & 0 deletions packages/pigment-css-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,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
Copy link
Contributor

Choose a reason for hiding this comment

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

You should also add this path to the exports in package.json

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've tried it but it wasn't enough, not sure how the different (tsconfig|tsup).* files interact, any advice to setup the build properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nevermind, I think I got it.

Copy link
Contributor

Choose a reason for hiding this comment

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

One last change needed is an entry it .gitignore and include internal in package.json's files key.

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: () => '',
};
7 changes: 7 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,11 @@ 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