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

feat: Create utils package to share logic across runtime and bundler #345

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

brijeshb42
Copy link
Contributor

@brijeshb42 brijeshb42 commented Dec 9, 2024

…packages

For reference, here's the next PR that uses this package.

This PR has the following utils -

  1. Pigment config base type (to be used across bundlers alongwith bundler specific keys)
  2. Processing of $$value keys in the css object to convert to css variables ---value
  3. Processing of variants, compoundVariants and defaultVariants keys
  4. valueToLiteral - Copied over from @pigment-css/react to convert JS values to equivalent AST.

Also, fixes tsconfig to used the latest config from core and updated the script to actually run typecheck in the CI which was not happening right now.

@brijeshb42 brijeshb42 added the @pigment-css/utils Specific to @pigment-css/utils package label Dec 9, 2024
@brijeshb42 brijeshb42 added this to the Road to v1 milestone Dec 9, 2024
@zannager zannager requested a review from mnajdova December 10, 2024 15:32
@brijeshb42 brijeshb42 force-pushed the v1/utils-package branch 6 times, most recently from e1c0ebc to 903cc78 Compare December 11, 2024 11:12
@@ -1,8 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true,
"target": "ES2015"
"skipLibCheck": true
Copy link
Member

Choose a reason for hiding this comment

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

Why was this required?

Copy link
Contributor Author

@brijeshb42 brijeshb42 Dec 20, 2024

Choose a reason for hiding this comment

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

Without it, it was typechecking for stuff inside unplugin package that does not affect our package.

../../node_modules/.pnpm/[email protected][email protected]/node_modules/unplugin/dist/index.d.mts(1,31): error TS2307: Cannot find module '@farmfe/core' or its corresponding type declarations.
      ../../node_modules/.pnpm/[email protected][email protected]/node_modules/unplugin/dist/index.d.mts(2,46): error TS2307: Cannot find module '@farmfe/core' or its corresponding type declarations.
      ../../node_modules/.pnpm/[email protected][email protected]/node_modules/unplugin/dist/index.d.mts(3,47): error TS2307: Cannot find module '@rspack/core/dist/config/zod' or its corresponding type declarations.
      ../../node_modules/.pnpm/[email protected][email protected]/node_modules/unplugin/dist/index.d.mts(7,45): error TS2307: Cannot find module 'rolldown/dist/types/plugin' or its corresponding type declarations.
      ../../node_modules/.pnpm/[email protected][email protected]/node_modules/unplugin/dist/index.d.mts(14,126): error TS2307: Cannot find module '@rspack/core' or its corresponding type declarations.
      ../../node_modules/.pnpm/[email protected][email protected]/node_modules/unplugin/dist/index.d.mts(15,66): error TS2307: Cannot find module '@rspack/core' or its corresponding type declarations.
      ../../node_modules/.pnpm/[email protected][email protected]/node_modules/unplugin/dist/index.d.mts(19,36): error TS2307: Cannot find module 'rolldown' or its corresponding type declarations.
      ../../node_modules/.pnpm/[email protected][email protected]/node_modules/unplugin/dist/index.d.mts(20,42): error TS2307: Cannot find module 'rolldown' or its corresponding type declarations.
       ELIFECYCLE  Command failed with exit code 2.

This check can be safely ignored since at the moment we don't care about farm/rolldown/rspack etc.

@@ -1,6 +1,6 @@
{
"name": "@pigment-css/theme",
"version": "0.0.27",
"version": "0.0.28",
Copy link
Member

Choose a reason for hiding this comment

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

We can bump the version during the release process.

"module": "build/index.mjs",
"types": "build/index.d.ts",
"author": "MUI Team",
"description": "Utilities to be used internally across Pigment CSS libraries.",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"description": "Utilities to be used internally across Pigment CSS libraries.",
"description": "Utilities to be used internally across different Pigment CSS packages.",

nit

/**
* Parses array expression string to AST for locating sourcemap points.
*/
export function parseArray(
Copy link
Member

Choose a reason for hiding this comment

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

Should we rename the file to parseArray.ts, or at least to parseExpressions.ts (plural) if we plan to add more things.

>;
defaultVariants?: Record<string, string | number>;
};
type BaseStyleObject = ExtendedStyleObj & Record<string, string | object>;
Copy link
Member

Choose a reason for hiding this comment

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

Don't we miss here the CSS template string type?

},
},
variables: {
'--var-1': [style[`.cls1`].color, 0],
Copy link
Member

Choose a reason for hiding this comment

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

Where would this style[`.cls1`].color be defined?

Comment on lines +13 to +14
$$hello: 'world',
$hello1: 'world',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$$hello: 'world',
$hello1: 'world',
$$hello: 'world',
$hello1: 'world',

What's the difference betweem $ and $$?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@pigment-css/utils Specific to @pigment-css/utils package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants