react-email icon indicating copy to clipboard operation
react-email copied to clipboard

Preserve folders inside "Email" Folder // Folder & Items Removed

Open Bugs5382 opened this issue 2 years ago • 9 comments

So I am working on creating "templates" around emails generated. Your classic parent, child components. So I have this structure:

image

but when it's compiled only the "files" inside the root folder emails:

image

... is created. I wouldn't be looking to "preview" or "export" the template so on the page:

image

this is correct that only "end-new-incident.tsx" shows up.

Bugs5382 avatar Feb 07 '23 15:02 Bugs5382

Can you try the latest version?

bukinoshita avatar Feb 07 '23 21:02 bukinoshita

the old version cpy: 8.1.2 won't keep the folder structure, I think upgrading it to the latest v9.0 would be better.

lxzxl avatar Feb 08 '23 09:02 lxzxl

Can you try the latest version?

Will update today and report back...

Bugs5382 avatar Feb 08 '23 14:02 Bugs5382

@bukinoshita Updated to "react-email": "^1.7.11" and did a npm clean, etc. still same result.

image

It also put the static files in the same directory as well....

Bugs5382 avatar Feb 08 '23 14:02 Bugs5382

Same issue.

I'm trying to update [email protected].

akagire avatar Feb 09 '23 03:02 akagire

cpy uses ESM does it break anything? And the people that are not using ESM, they need to start supporting ESM?

bukinoshita avatar Feb 09 '23 03:02 bukinoshita

@bastiaanv Can help take a look on this, looks like the static files is displayed in the sidebar right now

bukinoshita avatar Feb 09 '23 04:02 bukinoshita

@bukinoshita This problem is cpy's default behavior has changed.

Possibly this PR https://github.com/resendlabs/react-email/pull/428 changes the latest referenced cpy document.

This PR's purpose is keep emails directories structure on Next.js for preview.

But the latest version of react-email does not keep the directory structure because cpy copies the files and flattens them like that https://github.com/resendlabs/react-email/issues/447#issue-1574535542. It is probably not the expected behavior.

However, this is [email protected]'s correct behavior. So this issue can be solved by updating cpy to 9.0.1.

This is reproduce repository for cpy's behavior of these versions.

v8.1.2 https://github.com/Akagire/cpyTest

v9.0.1 https://github.com/Akagire/cpyTest/tree/cpy-901

index.{c,m}js just do copy slug to dest .

v8.1.2's dest is be flatten. But v9.0.1's dest keeps the structure.

But this fix has another problem. cpy has switched to pure ESM since version 9 so it needs to change the static import (built CJS files that use require) migrate to dynamic import ( built cjs files that use await import ).

This is my requested PR's purpose. https://github.com/resendlabs/react-email/pull/454

We have another option that detach cpy or use another one or implement copy process original.

Finally, IMHO, react-email doesn't need to support ESM right now. For reason, according to this data https://github.com/wooorm/npm-esm-vs-cjs CommonJS is still the de-facto standard module system.

Fortunately, CommonJS can import ESM modules like my PR, and cpy code only used in command/dev.ts that is Next.js(for preview) preparation, so it probably won't affect other processes. (I think readability is worse than CommonJS library importing...)

On the other hand, as you can see previously mentioned esm-vs-cjs data, ESM library and dual packaging libraries share are growing up day by day. Perhaps someday need support ESM, but not now, at least for me.

akagire avatar Feb 09 '23 07:02 akagire

Ah yes, I see the problem. My bad, did not check the version of spy we were using. PR #454 looks good to me, hate the syntax used (but no other option available I guess). We could also switch to cpy-cli, then we can use shell and we do not need to think about ESM or CommonJS.

bastiaanv avatar Feb 09 '23 16:02 bastiaanv

That would be great solution I think at least for now.

bukinoshita avatar Feb 09 '23 19:02 bukinoshita

@Akagire Let's try doing something like @bastiaanv mentioned in that PR?

bukinoshita avatar Feb 10 '23 02:02 bukinoshita

I made a PR that uses shelljs to replace cpy completely, as an alternative for #454. Would like to hear what you guys think of it

bastiaanv avatar Feb 10 '23 07:02 bastiaanv

@bukinoshita @bastiaanv I'm sorry for confirm yours comments late :bow:

hate the syntax

Honesty, me too! And #460 is good solution too. I like it.

akagire avatar Feb 10 '23 10:02 akagire

looks good here!

Bugs5382 avatar Feb 10 '23 16:02 Bugs5382

Still not working for me in 1.10.0

tomaszczura avatar Dec 20 '23 12:12 tomaszczura