-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement css codemods for vue sfc files using postcss #156
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
base: main
Are you sure you want to change the base?
Conversation
- Add PostCSS-based CSS transformation API inspired by JSCodeshift - Support CSS, SCSS, and Less syntax parsing - Implement comprehensive transformation context with PostCSS AST access - Add support for Vue-specific features (scoped styles, deep selectors, CSS modules) - Create extensive test suite covering all major CSS transformation scenarios - Add three example transformations: * CSS class prefix addition with configurable prefix * Vue deep selector syntax conversion (:deep() to ::v-deep) * CSS color values to CSS custom properties conversion - Maintain backward compatibility with existing codebase 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #156 +/- ##
==========================================
+ Coverage 81.23% 82.66% +1.43%
==========================================
Files 22 22
Lines 1993 2060 +67
Branches 215 232 +17
==========================================
+ Hits 1619 1703 +84
+ Misses 369 351 -18
- Partials 5 6 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a PostCSS-based CSS transformation API for Vue SFCs, adds parser support for CSS/SCSS/Less, and provides examples and tests for common codemods.
- Define new types (
StyleTransformationFileInfo,StyleTransformationContext) and updateStyleTransformationsignature - Implement
transformStylerunner with PostCSS parsing, context creation, and result handling - Add comprehensive tests and real-world examples (class prefixing, Vue deep selector conversion, color variable conversion)
Reviewed Changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/types/StyleTransformation.ts | Added types for style transformation API |
| src/transformStyle.ts | Implemented the core CSS transformation runner |
| src/tests/transformStyle.spec.ts | Added tests covering CSS, SCSS, Less, return types, and errors |
| package.json | Registered PostCSS and related dependencies |
| examples/css-vue-deep-transform/transformation.cjs | Example for Vue deep/slotted selector conversion |
| examples/css-vue-deep-transform/Input.vue | Vue SFC demonstrating deep/slotted syntax |
| examples/css-prefix-classes/transformation.cjs | Example for CSS class prefix addition |
| examples/css-prefix-classes/Input.vue | Vue SFC demonstrating class prefix example |
| examples/css-color-variables/transformation.cjs | Example for converting color literals to CSS custom properties |
| examples/css-color-variables/Input.vue | Vue SFC with color variable declarations (has formatting issue) |
Comments suppressed due to low confidence (3)
src/transformStyle.ts:28
- [nitpick] Rename the
paramsparameter tooptionsto match theStyleTransformationsignature and improve consistency.
params: Options,
examples/css-color-variables/Input.vue:9
- The CSS rules are appended directly to the
<style>tag instead of inside the block. Split this into<style scoped>on its own line, followed by the:root { ... }block.
<style scoped>:root {
package.json:71
- These dependencies (
postcss-selector-parser,postcss-value-parser) are not used in the codebase. Consider removing them to keep the dependency list lean.
"postcss-selector-parser": "^7.1.0",
|
|
||
| // Transform class selectors | ||
| root.walkRules((rule) => { | ||
| rule.selector = rule.selector.replace(/\.([a-zA-Z][\w-]*)/g, (match, className) => { | ||
| // Don't prefix if it already has the prefix | ||
| if (className.startsWith(prefix.replace('-', ''))) { |
Copilot
AI
Jun 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Avoid calling prefix.replace('-', '') inside the loop on every rule. Compute the cleaned prefix once outside of root.walkRules for better clarity and slight performance gain.
| // Transform class selectors | |
| root.walkRules((rule) => { | |
| rule.selector = rule.selector.replace(/\.([a-zA-Z][\w-]*)/g, (match, className) => { | |
| // Don't prefix if it already has the prefix | |
| if (className.startsWith(prefix.replace('-', ''))) { | |
| const cleanedPrefix = prefix.replace('-', '') | |
| // Transform class selectors | |
| root.walkRules((rule) => { | |
| rule.selector = rule.selector.replace(/\.([a-zA-Z][\w-]*)/g, (match, className) => { | |
| // Don't prefix if it already has the prefix | |
| if (className.startsWith(cleanedPrefix)) { |
Closes #16
🤖 Generated with Claude Code