-
-
Notifications
You must be signed in to change notification settings - Fork 36
chore: rework content
updates
#75
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
Conversation
commit: |
Just had a quick look through and this really feels good. Those changes totally make sense and the don't produce the overhead i initially expected. |
content
updatescontent
updates
@@ -161,10 +164,10 @@ export const adder = defineAdder({ | |||
|
|||
const fallback = common.expressionFromString('defineConfig({})'); | |||
const { value: exportDefault } = exports.defaultExport(ast, fallback); | |||
if (exportDefault.type !== 'CallExpression') return; | |||
if (exportDefault.type !== 'CallExpression') return content; |
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.
there were some places like this where I had to do return content
, but I wonder if it wouldn't be better to allow undefined
in the return type so that we could do a simple return;
to skip editing the file
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.
sure, i think we can do that. i believe we (currently) could accomplish the same effect by returning an empty string as well
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.
on second thought, is this really all that bad? i feel like allowing undefined
to be returned could lead to a lot of fuckups (i.e. people forgetting to return the content after manipulation)
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.
true. it did save me from that a few times. I suppose we can always make that change in the future. Once we have tests it should provide some more protection
closes #33
This PR reworks how the
content
method operates in adders. Defined files are assumed to be text files and require the modified content to be returned. A series of parsers and code generators will also be provided as helpers. This approach should be far more flexible and allows for surgical updates to existing code.Here's an example svelte component:
Apply the following adder manipulation:
Output (only the contents of
<script>
and<style>
have changed):For the moment, only the
tailwindcss
adder has been migrated, hence the TSC errors