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

Allow non-cell files name end with Cell #554

Merged
merged 4 commits into from
May 21, 2020

Conversation

gfpacheco
Copy link
Contributor

@gfpacheco gfpacheco commented May 16, 2020

I just came across this issue today when I wanted to create a component called TableCell, but got this error:

Failed to compile.

./src/components/TableCell/TableCell.js
Module build failed (from ../node_modules/babel-loader/lib/index.js):
SyntaxError: .../web/src/components/TableCell/TableCell.js: Only one default export allowed per module. (13:0)

  11 | export default TableCell;
  12 | 
> 13 | export default withCell({  })
     | ^

Then I realized since my component name ends with Cell RedwoodJS was trying to make its cell magic.

This PR addresses that by checking if there's already an export default in the file before processing with cell loader.

@peterp
Copy link
Contributor

peterp commented May 18, 2020

Thanks for this! I hadn't really considered that someone might name something else <Name>Cell.js, but it's obvious in retrospect.

I wonder if we could be a bit more explicit about this, maybe using a pragma mark. Something like: // redwood-disable cell, or /* redwood-disable cell */

@mojombo
Copy link
Contributor

mojombo commented May 18, 2020

@peterp I don't know if being explicit here is the best approach. It seems like something we could easily auto-detect, whether based on an default export or on whether a QUERY was being exported. It seems like something computers are good at figuring out. =)

@gfpacheco
Copy link
Contributor Author

I like @mojombo's suggestion, maybe we could check both presence of export default and absence of export const QUERY to make sure it's not a dev's mistake.

If @peterp agrees I'll update the PR

@peterp
Copy link
Contributor

peterp commented May 18, 2020

@mojombo Yeah, you're right.

It does seem like an almost impossible set of circumstances that need to conspire that would make a person export QUERY, a default component and name something <Name>Cell and not want it to be a Cell.

My hope is that 10 years from now someone does that, finds this comments, and it reaches #1 on Hacker News.

And this is in no way to say that I don't agree with your suggestion. I just think it would be funny.

@gfpacheco
Copy link
Contributor Author

I just rebased this branch with master and had to run yarn lint --fix to pass CI tests.

It would be great if this was included in the 0.7.0 release.

@peterp peterp added this to the next release milestone May 21, 2020
@peterp peterp merged commit ba7407f into redwoodjs:master May 21, 2020
@thedavidprice
Copy link
Contributor

@gfpacheco Gah! Apologies this didn’t make it into v0.7.

Any luck with the canary versions? Also, you can do yarn rw upgrade --tag canary now as well. Hope something in there helps you out.

Thanks again for your continuing contributions!

@gfpacheco
Copy link
Contributor Author

Don't worry, it's an easy workaround, I just named my file TableCel.js with a single L. I'll test the canary build later

@gfpacheco
Copy link
Contributor Author

Hey guys, it's still not working on canary, do I have to do anything else than upgrading?

I just wanted to point out that I'm a total newbie when it comes to babel loader and plugin development, that said:

I tried changing the files inside node_modules manually, adding console.logs, but nothing seems to have an effect.

I even saw that aside from the loader we also have a babel-plugin-redwood-cell and I'm not sure the cell-loader is even used anywhere.

I tried the local development also without success.

I just don't know what else to do.

@thedavidprice
Copy link
Contributor

@gfpacheco Oh man, just a perfect storm of bad timing. First we missed including this in v0.7. Then our GH Action to auto-publish canaries broke today #588 So most likely the canary you've been using does not include the changes you need.

I just manually released 0.7.1-canary.8 moments ago. Give it another try?

@gfpacheco
Copy link
Contributor Author

Still no luck. The changes are there, they just don't seem to have an effect, neither does anything I do to those files (call-loader.js and babel-plugin-redwood-cell.js) inside the node_modules folder. I tried commenting entire functions to see if the Cell file would come out unchanged, but that didn't happen, I still get the double default export error.

@peterp
Copy link
Contributor

peterp commented May 25, 2020

@gfpacheco I've fixed this over here: #597

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.

4 participants