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(emotion): Add emotion #29

Conversation

IvanRodriCalleja
Copy link
Contributor

@IvanRodriCalleja IvanRodriCalleja commented Apr 23, 2022

  • Add emotion plugin from swc_emotion

TODO: Sourcemaps are deactivated right now until are fully supported. swc-project/swc#4282

Plugin can be used right now without sourcemaps (at the moment always use false)

@CLAassistant
Copy link

CLAassistant commented Apr 23, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor Author

@IvanRodriCalleja IvanRodriCalleja left a comment

Choose a reason for hiding this comment

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

If i am not wrong to have a fully working plugin, sourcemap needs to implement:
get_code_map
as_arg
to_writer

Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

@kwonoj is working on required apis

// Sourcemap is wrong at the moment, plugin has to use data.source_map but at
// the moment it is not fully supported and cant be converted to
// Arc<SourceMap>
let cm = Lrc::new(SourceMap::default());
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you want me to make a fix for that and have a working plugin without source maps or do you prefer to wait until source maps are supported in Plugins to finish the emotion plugin?

Copy link
Member

Choose a reason for hiding this comment

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

I don't have strong opinion about it, but this is simply wrong and it will panic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will it be correct?

let cm = Arc::new(SourceMap::default());

This is my first time writing Rust code and maybe i am doing a stupid question

Copy link
Member

Choose a reason for hiding this comment

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

No, the problem is not initialization.
It's wrong value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As i understand i should read the file and set the content as value of source map, right?

Copy link
Member

@kdy1 kdy1 Apr 26, 2022

Choose a reason for hiding this comment

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

No, it will not work because SourceMap is a set of files

@Brooooooklyn
Copy link
Member

What are the differences between this and https://github.com/vercel/next.js/tree/canary/packages/next-swc/crates/emotion ?

@kdy1
Copy link
Member

kdy1 commented Apr 26, 2022

This one depends on the one in the next.js repository

@ivan-rodriguez-ag
Copy link

This is just to publish as npm package and allow non NextJs applications to use the plugin. This is using the existing one from Next (the one you wrote). This plugin could be used by create-react-app users, custom webpack config users, etc

@IvanRodriCalleja
Copy link
Contributor Author

@kwonoj Once swc-project/swc#4781 is merged, is it possible to do the sourcemap conversion in order to pass it to the next-emotion plugin crate? Or is something missing?

@kwonoj
Copy link
Member

kwonoj commented May 24, 2022

I'm not clear if emotion plugin is sufficient with SourceMapper impl. If that's the case it'll be.

// Sourcemap is wrong at the moment, plugin has to use data.source_map but at
// the moment it is not fully supported and cant be converted to
// Arc<SourceMap>
let cm = Lrc::new(SourceMap::default());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kwonoj i have been trying to fix the problem with sourcemap but i don't find information about if it is possible to convert Arc<PluginSourceMapProxy> into Arc<SourceMap>, is there a way to convert?

I took a look to your code instrument plugin and i see you use Arc<SourceMapper> instead https://github.com/kwonoj/swc-coverage-instrument/blob/91f1972e50effc9bc8c02abf794da80f4b856f84/packages/swc-coverage-instrument/src/visitors/coverage_visitor.rs#L18. Should the next_emotion plugin use Arc<SourceMapper>? i made a try to change from Arc<SourceMap> to Arc<SourceMapper> in the next plugin and it seems to work (but in the configuration i don't know how to convert Arc<SourceMap> into Arc<SourceMapper>) https://github.com/vercel/next.js/blob/607ff2b3225ea9fab04b4fca07e4a609b05e8038/packages/next-swc/crates/core/src/lib.rs#L196

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you can't use concrete types to make compatible for plugin's proxy / customr transform both, reason sourcemapper is implemented for the plugin proxy.

@IvanRodriCalleja
Copy link
Contributor Author

@kdy1 kdy1 self-assigned this Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants