PlasmoHQ / plasmo

🧩 The Browser Extension Framework
https://www.plasmo.com
MIT License
10.14k stars 350 forks source link

[BUG] presence of the src folder causes unexpected behaviour #836

Open monarchwadia opened 9 months ago

monarchwadia commented 9 months ago

Thank you for the amazing work on this MUCH-needed framework.. Plasmo is amazing and makes my job a lot easier :-)

Actual behaviour

When an empty /src is present, Plasmo ignores all of the root-level entrypoints such as /sidepanel.tsx, /popup.tsx, /options.tsx, causing the manifest to be empty of any entrypoints. It shows a non-descriptive WARN in the console when this is the case.

image

Expected behaviour / suggested fix

When /src is present, but some root-level entrypoints also exist (such as /sidepanel.tsx, /popup.tsx, /options.tsx), Plasmo should throw up a more descriptive warning that aids in quick debugging... something like the following maybe...:

When the "/src" folder exists, all entrypoints should exist within "/src". However, we found the following entrypoints in your "/" folder: ["/sidepanel.tsx", "/popup.tsx", "/options.tsx"]. These will be ignored and will not be added to the manifest file. In order to fix this issue, please ensure that all your entrypoints are in the "/src" folder, or delete the "/src" folder altogether.

Impact of bug

When encountered, this issue is a showstopper for any POC or exploratory work that is trying out Plasmo as a possible framework. Most likely, fixing this bug will result in an uptick in adoption.

I spent a few hours spinning my wheels today on this. I'm pretty sure it discouraged me from using Plasmo the first time I encountered it, and that was for a commercial project (we went back to their homegrown solution).... I wonder how many developers silently quit on Plasmo because of this one.

Additional anecdotal description of impact

After seeing the existing non-descriptive WARN message, my extension stopped working completely --- no popup would show up. When I checked the manifest file, it did not show the popup declaration at all. Same for sidebar, options, etc... everything just disappeared. This was very confusing because everything was fine before. I rm -rf'd all my node_modules, the .plasmo/ directory, the build/ directory, and did pnpm store prune. I even did a git checkout HEAD^ and the issue still persisted. Eventually, I cloned my repo locally and things seemed to work fine... until they stopped working all of a sudden yet again.

This causes a lot of confusion, because oftentimes a developer will have created /src/components and is still expecting to be working on root-level /popup.tsx but with the presence of the src folder all of these are ignored. To make matters worse, git doesn't always delete empty folders, and so even doing a git checkout HEAD^ will not solve the issue for the developer.

Thank you

Thank you again for the amazing plugin, I hope this bug report helps make it even better :-)

Version

Latest

What OS are you seeing the problem on?

Windows

What browsers are you seeing the problem on?

Chrome, Firefox

Relevant log output

No response

(OPTIONAL) Contribution

Code of Conduct

monarchwadia commented 9 months ago

If you show me what to do in a bit of detail, I can dedicate a couple extra cycles to fix this for you. I know that the existing WARN originates in cli/plasmo/src/features/manifest-factory/create-manifest.ts:48, however, I am not sure what the right way to check for the existence of entrypoints would be.

Now that I'm thinking about it... It might be harder for you to explain it to me than to just fix it yourself :-) But the offer still stands.