Skip to content

Feat: Rules - rules.raw() API supports #231#232

Merged
github-actions[bot] merged 1 commit intomainfrom
rules-raw
Aug 21, 2025
Merged

Feat: Rules - rules.raw() API supports #231#232
github-actions[bot] merged 1 commit intomainfrom
rules-raw

Conversation

@black7375
Copy link
Contributor

@black7375 black7375 commented Aug 21, 2025

Description

Implement rules.raw() API

Related Issue

Summary by CodeRabbit

  • New Features

    • Added rules.raw(): a non-breaking passthrough API that returns the provided options while preserving existing rules(...) behavior.
  • Tests

    • Expanded test coverage to validate rules.raw() behavior and TypeScript type correctness.
  • Chores

    • Added a changeset documenting the new public API and a minor version bump for the css package.

Additional context

Checklist

@changeset-bot
Copy link

changeset-bot bot commented Aug 21, 2025

🦋 Changeset detected

Latest commit: c268326

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@mincho-js/css Minor
@mincho-js/react Patch
@mincho-js/vite Patch
react-babel Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Aug 21, 2025

Walkthrough

Adds a non-breaking rules.raw() passthrough and refactors the rules export to Object.assign(rulesImpl, { raw: rulesRaw }); runtime rules(...) behavior is unchanged. Tests added to validate rules.raw and its TypeScript signatures.

Changes

Cohort / File(s) Summary
Rules API refactor
packages/css/src/rules/index.ts
Renamed exported implementation to rulesImpl; added rulesRaw function; public export now rules = Object.assign(rulesImpl, { raw: rulesRaw }), exposing rules.raw as a passthrough returning the provided options.
Tests for rules.raw
tests/...
Added describe.concurrent("rules.raw()") tests validating runtime passthrough and TypeScript typings via assertType (imported from import.meta.vitest).
Release notes / changeset
.changeset/plenty-turkeys-retire.md
New changeset documenting a minor bump and the new public API rules.raw().

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant Rules as rules (export)
  participant Impl as rulesImpl
  participant Raw as rules.raw

  Note over Rules,Impl: Existing callable export preserved
  Dev->>Rules: rules(options)
  Rules->>Impl: invoke implementation
  Impl-->>Dev: result

  Note over Raw: New passthrough API (returns options)
  Dev->>Raw: rules.raw(options)
  Raw-->>Dev: options
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

enhancement

Poem

I hop through code with tiny paws,
A raw path opens without a pause.
Rules still run where carrots lie,
Peek beneath — the options sigh.
🥕🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rules-raw

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Contributor

Triggered from #232 by @​black7375.

Checking if we can fast forward main (216f6e1) to rules-raw (f117959).

Target branch (main):

commit 216f6e113a5e357d6fd8a0abe7f02f058d2a62d5 (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Mon Jul 21 00:00:00 2025 +0900

    Fix: CSS - More strict required check `css.with()` #226

Pull request (rules-raw):

commit f117959708886a7cdd9a14aec091051fda57419d (pull_request/rules-raw)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Tue Jul 22 00:00:00 2025 +0900

    Feat: Rules - `rules.raw()` API supports #231

It is possible to fast forward main (216f6e1) to rules-raw (f117959). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to rules-raw.

@github-actions
Copy link
Contributor

Triggered from #232 by @​black7375.

Checking if we can fast forward main (216f6e1) to rules-raw (cfe50da).

Target branch (main):

commit 216f6e113a5e357d6fd8a0abe7f02f058d2a62d5 (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Mon Jul 21 00:00:00 2025 +0900

    Fix: CSS - More strict required check `css.with()` #226

Pull request (rules-raw):

commit cfe50dae04a387d0c8263b149aad41f435184d22 (pull_request/rules-raw)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Fri Aug 22 01:15:59 2025 +0900

    Feat: Rules - `rules.raw()` API supports #231

It is possible to fast forward main (216f6e1) to rules-raw (cfe50da). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to rules-raw.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/css/src/rules/index.ts (3)

188-194: Simplify generics for rulesRaw to a single identity generic

rulesRaw’s three generic parameters are unnecessary for preserving exact inference. Using a single generic that extends PatternOptions keeps literals intact while reducing complexity and compile time surface.

Apply this diff:

-function rulesRaw<
-  Variants extends VariantGroups | undefined = undefined,
-  ToggleVariants extends VariantDefinitions | undefined = undefined,
-  Props extends ComplexPropDefinitions<PropTarget> | undefined = undefined
->(options: PatternOptions<Variants, ToggleVariants, Props>) {
-  return options;
-}
+/** Identity helper to preserve literal inference of PatternOptions. */
+function rulesRaw<T extends PatternOptions<any, any, any>>(options: T): T {
+  return options;
+}

899-1026: Great coverage for rules.raw; add a couple of integration and type assertion cases

Strong start validating pass-through behavior. Consider adding:

  • defaultVariants + toggles via raw
  • mixing variants and toggles via raw
  • a direct type assertion that rules.raw is typed as typeof rulesRaw

Apply this diff (appends tests within the existing describe.concurrent("rules.raw()") block):

@@
   describe.concurrent("rules.raw()", () => {
     it("handles simple Rule properties", () => {
@@
       rules(ruleObj4); // Ensure it can be used with rules()
     });
+
+    it("preserves defaultVariants with toggles via raw", () => {
+      const obj = rules.raw({
+        defaultVariants: ["disabled"],
+        toggles: {
+          disabled: { textDecoration: "line-through" }
+        }
+      });
+      const result = rules(obj, debugId);
+      expect(result()).toMatch(className(debugId, `${debugId}_disabled_true`));
+      assert.hasAllKeys(result.classNames.variants, ["disabled"]);
+    });
+
+    it("combines variants and toggles via raw", () => {
+      const obj = rules.raw({
+        variants: {
+          size: {
+            small: { padding: 12 }
+          }
+        },
+        toggles: {
+          rounded: { borderRadius: 999 }
+        }
+      });
+      const result = rules(obj, debugId);
+      assert.hasAllKeys(result.classNames.variants, ["size", "rounded"]);
+      expect(result({ size: "small", rounded: true })).toMatch(
+        className(
+          debugId,
+          `${debugId}_size_small`,
+          `${debugId}_rounded_true`
+        )
+      );
+    });
+
+    it("exposes correct type for rules.raw", () => {
+      // Compile-time only: ensures the property is typed as the function itself
+      assertType<typeof rulesRaw>(rules.raw);
+    });
   });

196-199: Add explicit type annotation to the rules export

The rules export should be hardened with an explicit intersection type to cement the public API and prevent accidental widening in future refactors. Since rulesImpl isn’t referenced or imported anywhere else and the compat layer still exports rules as recipe, this change is safe and non-breaking.

You can apply the minimal update:

-export const rules = Object.assign(rulesImpl, {
-  raw: rulesRaw
-});
+export const rules: typeof rulesImpl & { raw: typeof rulesRaw } = Object.assign(
+  rulesImpl,
+  { raw: rulesRaw }
+);

Optional: if you’d like to preserve rulesImpl without mutation, wrap it before assignment:

- export const rules = Object.assign(rulesImpl, {
-   raw: rulesRaw
- });
+const rulesWrapped = ((...args) =>
+  (rulesImpl as unknown as (...a: typeof args) => ReturnType<typeof rulesImpl>)(...args)
+) as typeof rulesImpl;
+export const rules: typeof rulesImpl & { raw: typeof rulesRaw } = Object.assign(
+  rulesWrapped,
+  { raw: rulesRaw }
+);

— There are no other imports/usages of rulesImpl outside this file, and packages/css/src/compat.ts:42 still exports rules as recipe.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 216f6e1 and f117959.

📒 Files selected for processing (1)
  • packages/css/src/rules/index.ts (4 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: black7375
PR: mincho-js/mincho#113
File: packages/css/src/index.ts:33-33
Timestamp: 2024-10-09T13:00:38.449Z
Learning: `recipe` is properly exported from './rules' in `packages/css/src/rules/index.ts`.
📚 Learning: 2024-10-09T13:00:38.449Z
Learnt from: black7375
PR: mincho-js/mincho#113
File: packages/css/src/index.ts:33-33
Timestamp: 2024-10-09T13:00:38.449Z
Learning: `recipe` is properly exported from './rules' in `packages/css/src/rules/index.ts`.

Applied to files:

  • packages/css/src/rules/index.ts
📚 Learning: 2024-12-03T11:16:32.528Z
Learnt from: black7375
PR: mincho-js/mincho#134
File: packages/transform-to-vanilla/src/transform.ts:49-51
Timestamp: 2024-12-03T11:16:32.528Z
Learning: In projects that target both CommonJS and ES modules, adjusting the TypeScript `module` option may not be feasible. Therefore, using `ts-ignore` comments to suppress TypeScript errors related to `import.meta` is acceptable.

Applied to files:

  • packages/css/src/rules/index.ts
🧬 Code graph analysis (1)
packages/css/src/rules/index.ts (3)
packages/css/src/compat.ts (6)
  • VariantGroups (32-32)
  • VariantDefinitions (37-37)
  • ComplexPropDefinitions (35-35)
  • PropTarget (36-36)
  • PatternOptions (33-33)
  • rules (42-42)
packages/css/src/index.ts (6)
  • VariantGroups (35-35)
  • VariantDefinitions (40-40)
  • ComplexPropDefinitions (38-38)
  • PropTarget (39-39)
  • PatternOptions (36-36)
  • rules (29-29)
packages/css/src/rules/types.ts (5)
  • VariantGroups (49-49)
  • VariantDefinitions (40-40)
  • ComplexPropDefinitions (74-76)
  • PropTarget (72-72)
  • PatternOptions (176-191)
🔇 Additional comments (2)
packages/css/src/rules/index.ts (2)

50-61: LGTM: API split into rulesImpl and augmented rules preserves backward compatibility

Renaming the implementation to rulesImpl and keeping the public export as rules (callable) looks good. The generic signature and returned RuntimeFn remain intact. Nice, non-breaking extension path for adding rules.raw.


239-239: Confirmed: assertType is supported in Vitest v3.2.2

  • A scan of all package.json files shows Vitest is only declared once, at the repo root, as ^3.2.2.
    (script output: /home/jailuser/git/package.json → vitest ^3.2.2)
  • The Vitest v3.x API includes assertType as part of the testing assertions exposed via import.meta.vitest (vitest.dev).

No further changes to your test code are required. You may wish to ensure your TypeScript configuration includes the "vitest/importMeta" type definitions so that import.meta.vitest.assertType is properly recognized by the compiler.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
.changeset/plenty-turkeys-retire.md (1)

5-7: Fix markdownlint MD036: use a heading instead of bold text.

Switch the emphasized "New" to a proper heading to satisfy markdownlint and align with the repo’s style in other changesets.

-**New**
+### New
packages/css/src/rules/index.ts (3)

196-198: Pin the callable+property intersection type for rules to ensure stable inference across TS versions.

While Object.assign infers an intersection, being explicit avoids drift and IDE hiccups when navigating types.

-export const rules = Object.assign(rulesImpl, {
-  raw: rulesRaw
-});
+export const rules: typeof rulesImpl & { raw: typeof rulesRaw } =
+  Object.assign(rulesImpl, { raw: rulesRaw });

899-1027: Great coverage for rules.raw(); consider one more case to exercise function-based compoundVariants via raw.

You already cover base, variants, toggles, and props. Adding a function-form compoundVariants case via rules.raw() would mirror the rules() tests and verify generic inference holds through raw as well.

Here’s a minimal add-on you can drop into this block:

+    it("supports function-based compoundVariants via raw()", () => {
+      const variants = {
+        color: {
+          brand: { color: "#FFFFA0" },
+          accent: { color: "#FFE4B5" }
+        },
+        size: {
+          small: { padding: 12 },
+          medium: { padding: 16 },
+          large: { padding: 24 }
+        }
+      } as const;
+
+      const rawObj = rules.raw({
+        variants,
+        compoundVariants: ({ color, size }) => [
+          { condition: [color.brand, size.small], style: { fontSize: 16 } }
+        ]
+      });
+      // Type-level check still flows through raw()
+      assertType<
+        PatternOptions<
+          {
+            color: { brand: { color: string }; accent: { color: string } };
+            size: { small: { padding: number }; medium: { padding: number }; large: { padding: number } };
+          },
+          undefined,
+          undefined
+        >
+      >(rawObj);
+
+      const r = rules(rawObj, "raw_compound");
+      expect(r({ color: "brand", size: "small" })).toMatch(
+        className(
+          "raw_compound",
+          "raw_compound_color_brand",
+          "raw_compound_size_small",
+          "raw_compound_compound_0"
+        )
+      );
+    });

50-50: Keep rulesImpl Internal
To maintain a minimal public API surface and avoid encouraging consumers to depend on this internal helper, let’s remove the export keyword from rulesImpl.

• File needing update: packages/css/src/rules/index.ts (around line 50)
• Change:

-export function rulesImpl<
+function rulesImpl<

This ensures only the intended rules symbol is exported publicly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f117959 and cfe50da.

📒 Files selected for processing (2)
  • .changeset/plenty-turkeys-retire.md (1 hunks)
  • packages/css/src/rules/index.ts (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2024-10-09T13:00:38.449Z
Learnt from: black7375
PR: mincho-js/mincho#113
File: packages/css/src/index.ts:33-33
Timestamp: 2024-10-09T13:00:38.449Z
Learning: `recipe` is properly exported from './rules' in `packages/css/src/rules/index.ts`.

Applied to files:

  • packages/css/src/rules/index.ts
📚 Learning: 2024-12-03T11:16:32.528Z
Learnt from: black7375
PR: mincho-js/mincho#134
File: packages/transform-to-vanilla/src/transform.ts:49-51
Timestamp: 2024-12-03T11:16:32.528Z
Learning: In projects that target both CommonJS and ES modules, adjusting the TypeScript `module` option may not be feasible. Therefore, using `ts-ignore` comments to suppress TypeScript errors related to `import.meta` is acceptable.

Applied to files:

  • packages/css/src/rules/index.ts
🧬 Code graph analysis (2)
.changeset/plenty-turkeys-retire.md (1)
packages/css/src/css/index.ts (2)
  • cssRaw (109-111)
  • cssWithRaw (122-124)
packages/css/src/rules/index.ts (1)
packages/css/src/rules/types.ts (5)
  • VariantGroups (49-49)
  • VariantDefinitions (40-40)
  • ComplexPropDefinitions (74-76)
  • PropTarget (72-72)
  • PatternOptions (176-191)
🪛 markdownlint-cli2 (0.17.2)
.changeset/plenty-turkeys-retire.md

5-5: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🔇 Additional comments (2)
packages/css/src/rules/index.ts (2)

188-194: LGTM: rulesRaw generic passthrough preserves precise types.

The generic defaults and passthrough return enable strong inference and align with the existing cssRaw pattern. No runtime impact.


239-239: LGTM: assertType import ensures compile-time coverage for new rules.raw tests.

This is a clean way to validate types without affecting runtime.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
.changeset/plenty-turkeys-retire.md (2)

5-5: Fix markdownlint MD036: use a heading instead of bold text

The section label is styled with emphasis; switch to a heading to satisfy markdownlint and keep consistency with other notes.

-**New**
+## New

7-7: Enrich the release note to clarify scope and stability

Optional, but adding a short qualifier helps consumers scanning the changelog understand what “raw” does and that it’s additive/non‑breaking. Also consider referencing the related issue.

-- Add `rules.raw()` API
+- Add `rules.raw()` API (passthrough returning raw PatternOptions; non‑breaking).
+- See #231 for background.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between cfe50da and c268326.

📒 Files selected for processing (2)
  • .changeset/plenty-turkeys-retire.md (1 hunks)
  • packages/css/src/rules/index.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/css/src/rules/index.ts
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
.changeset/plenty-turkeys-retire.md

5-5: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🔇 Additional comments (2)
.changeset/plenty-turkeys-retire.md (2)

1-3: Changesets frontmatter looks correct for a minor bump

Package name and release type are well-formed for Changesets’ frontmatter.


2-2: Confirm “minor” aligns with your release policy for new public API

If this package is ≥1.0.0, “minor” for additive public API is correct per semver. If still <1.0.0 and you treat “minor” as potentially breaking, double‑check this matches your policy.

@black7375
Copy link
Contributor Author

/fast-forward

@github-actions
Copy link
Contributor

Triggered from #232 (comment) by @​black7375.

Trying to fast forward main (216f6e1) to rules-raw (c268326).

Target branch (main):

commit 216f6e113a5e357d6fd8a0abe7f02f058d2a62d5 (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Mon Jul 21 00:00:00 2025 +0900

    Fix: CSS - More strict required check `css.with()` #226

Pull request (rules-raw):

commit c268326ae498f7c2d1f0504d517fd4d340a1169f (pull_request/rules-raw)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Tue Jul 22 00:00:00 2025 +0900

    Feat: Rules - `rules.raw()` API supports #231

Fast forwarding main (216f6e1) to rules-raw (c268326).

$ git push origin c268326ae498f7c2d1f0504d517fd4d340a1169f:main
To https://github.com/mincho-js/mincho.git
   216f6e1..c268326  c268326ae498f7c2d1f0504d517fd4d340a1169f -> main

@github-actions github-actions bot merged commit c268326 into main Aug 21, 2025
11 of 12 checks passed
@github-actions github-actions bot deleted the rules-raw branch August 21, 2025 16:29
@github-actions github-actions bot mentioned this pull request Aug 21, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2025

Triggered from #232 by @​black7375.

Checking if we can fast forward main (c268326) to rules-raw (c268326).

Target branch (main):

commit c268326ae498f7c2d1f0504d517fd4d340a1169f (HEAD -> main, origin/main, pull_request/rules-raw)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Tue Jul 22 00:00:00 2025 +0900

    Feat: Rules - `rules.raw()` API supports #231

Pull request (rules-raw):

commit c268326ae498f7c2d1f0504d517fd4d340a1169f (HEAD -> main, origin/main, pull_request/rules-raw)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Tue Jul 22 00:00:00 2025 +0900

    Feat: Rules - `rules.raw()` API supports #231

It is possible to fast forward main (c268326) to rules-raw (c268326). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to rules-raw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant