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(cli)!: add --write-transformed option, disable source write back by default #2948

Merged
merged 5 commits into from
Aug 9, 2023

Conversation

brofrain
Copy link
Contributor

@brofrain brofrain commented Aug 5, 2023

Hello,
this humble PR adds --update-source --write-transformed flag for @unocss/cli used to toggle overwriting source files with transformed code. It is enabled by default to preserve the current behavior, but can be disabled in case another tool takes care of transforming utility classes on the HTML side.

Background:
I'm trying to make UnoCSS work with Rust frameworks preferably without trade-offs like dropping Variant Groups. I've made a little macro for that purpose and hopefully it will evolve someday to be executed on a WASM bundler side rather than polluting source code.
Regardless of the final approach to rendering valid HTML classes, keeping the source files not-transformed is desirable. Otherwise the Variant Groups feature isn't really much of use :)

@netlify
Copy link

netlify bot commented Aug 5, 2023

Deploy Preview for unocss ready!

Name Link
🔨 Latest commit 1a2f92d
🔍 Latest deploy log https://app.netlify.com/sites/unocss/deploys/64d39497bc754700084dba47
😎 Deploy Preview https://deploy-preview-2948--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -21,6 +21,7 @@ export async function startCli(cwd = process.cwd(), argv = process.argv, options
})
.option('-c, --config [file]', 'Config file')
.option('-w, --watch', 'Watch for file changes')
.option('--update-source', 'Update source files with transformed utilities', { default: true })
Copy link
Member

Choose a reason for hiding this comment

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

I feel this was a dangerous default we picked. I'd be happy to name it as --write-transformed and default to false.

Copy link
Contributor Author

@brofrain brofrain Aug 7, 2023

Choose a reason for hiding this comment

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

Thanks!
I've updated the flag and made sure that files transformed with directive transformer are also covered by tests.

@brofrain brofrain requested a review from antfu August 8, 2023 12:58
@antfu antfu changed the title feat(cli): allow to disable updating source files feat(cli)!: add --write-transformed option, disable source write back by default Aug 9, 2023
@antfu antfu enabled auto-merge August 9, 2023 13:15
@antfu antfu added this pull request to the merge queue Aug 9, 2023
Merged via the queue into unocss:main with commit 631a255 Aug 9, 2023
10 checks passed
@lvjiaxuan
Copy link
Contributor

Would it be better to output transformed files instead of overwriting source files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants