react-email 4.0.8 → 4.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/cli/index.mjs +205 -180
- package/dist/preview/.next/BUILD_ID +1 -1
- package/dist/preview/.next/app-build-manifest.json +14 -14
- package/dist/preview/.next/build-manifest.json +2 -2
- package/dist/preview/.next/next-minimal-server.js.nft.json +1 -1
- package/dist/preview/.next/next-server.js.nft.json +1 -1
- package/dist/preview/.next/prerender-manifest.json +3 -3
- package/dist/preview/.next/server/app/_not-found/page.js +1 -1
- package/dist/preview/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/dist/preview/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/preview/.next/server/app/page.js +1 -1
- package/dist/preview/.next/server/app/page.js.nft.json +1 -1
- package/dist/preview/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/preview/.next/server/app/preview/[...slug]/page.js +137 -75
- package/dist/preview/.next/server/app/preview/[...slug]/page.js.nft.json +1 -1
- package/dist/preview/.next/server/app/preview/[...slug]/page_client-reference-manifest.js +1 -1
- package/dist/preview/.next/server/chunks/267.js +14 -0
- package/dist/preview/.next/server/chunks/346.js +1 -0
- package/dist/preview/.next/server/chunks/{886.js → 775.js} +3 -3
- package/dist/preview/.next/server/pages/500.html +1 -1
- package/dist/preview/.next/server/server-reference-manifest.js +1 -1
- package/dist/preview/.next/server/server-reference-manifest.json +1 -1
- package/dist/preview/.next/static/chunks/33-ff3f70a80570ecda.js +1 -0
- package/dist/preview/.next/static/chunks/416-9c899340cfaa07d4.js +1 -0
- package/dist/preview/.next/static/chunks/516-2716d86d2f8b9000.js +1 -0
- package/dist/preview/.next/static/chunks/{587-2b8de61789f0fd1b.js → 587-0644242ce9489212.js} +1 -1
- package/dist/preview/.next/static/chunks/app/{layout-a3d4e7b4de277118.js → layout-2726a60e293495d3.js} +1 -1
- package/dist/preview/.next/static/chunks/app/{page-0ee3a37f3a3f6f17.js → page-1d98e2313c60dd77.js} +1 -1
- package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-c77ff9f2bb1709b3.js +1 -0
- package/dist/preview/.next/static/chunks/f33a14d2-a04f3be0523bd1fa.js +6 -0
- package/dist/preview/.next/static/css/6f42d128f111d7fa.css +3 -0
- package/dist/preview/.next/trace +27 -27
- package/package.json +44 -46
- package/src/actions/email-validation/check-compatibility.ts +1 -1
- package/src/actions/email-validation/check-images.spec.tsx +1 -1
- package/src/actions/email-validation/check-links.spec.tsx +1 -1
- package/src/actions/email-validation/quick-fetch.ts +1 -1
- package/src/actions/render-email-by-path.tsx +6 -6
- package/src/app/preview/[...slug]/preview.tsx +1 -1
- package/src/components/toolbar.tsx +1 -0
- package/src/contexts/emails.tsx +1 -3
- package/src/contexts/fragment-identifier.tsx +3 -1
- package/src/contexts/preview.tsx +1 -3
- package/src/hooks/use-email-rendering-result.ts +18 -5
- package/src/hooks/use-hot-reload.ts +1 -1
- package/src/utils/__snapshots__/get-email-component.spec.ts.snap +1 -1
- package/src/utils/caniemail/ast/get-object-variables.ts +1 -1
- package/src/utils/caniemail/tailwind/generate-tailwind-rules.ts +1 -1
- package/src/utils/caniemail/tailwind/get-tailwind-config.ts +1 -1
- package/src/utils/caniemail/tailwind/get-tailwind-metadata.ts +1 -1
- package/src/utils/contains-email-template.spec.ts +107 -0
- package/src/utils/contains-email-template.ts +33 -0
- package/src/utils/get-email-component.ts +16 -1
- package/src/utils/get-emails-directory-metadata.ts +24 -13
- package/src/utils/index.ts +2 -2
- package/src/utils/run-bundled-code.ts +1 -1
- package/tailwind.config.ts +2 -1
- package/tsconfig.json +1 -1
- package/dist/cli/index.d.mts +0 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +0 -1320
- package/dist/index.js +0 -1234
- package/dist/preview/.next/server/chunks/265.js +0 -1
- package/dist/preview/.next/server/chunks/840.js +0 -14
- package/dist/preview/.next/static/chunks/246-e7336e2929971f63.js +0 -1
- package/dist/preview/.next/static/chunks/539-6e9405ecdc007bb7.js +0 -1
- package/dist/preview/.next/static/chunks/853-a01d49f63a859f3d.js +0 -1
- package/dist/preview/.next/static/chunks/afa401a5-55858bf5265319eb.js +0 -6
- package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-cab7e5e69e3b91e2.js +0 -1
- package/dist/preview/.next/static/css/67e57230289273a9.css +0 -3
- /package/dist/preview/.next/static/{t22IN7aANTezJAJOfFnv- → 3apYH6rky7aNn7g4RIJp5}/_buildManifest.js +0 -0
- /package/dist/preview/.next/static/{t22IN7aANTezJAJOfFnv- → 3apYH6rky7aNn7g4RIJp5}/_ssgManifest.js +0 -0
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-email",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.9",
|
|
4
4
|
"description": "A live preview of your emails right in your browser.",
|
|
5
5
|
"bin": {
|
|
6
|
-
"email": "./dist/cli/index.
|
|
6
|
+
"email": "./dist/cli/index.mjs"
|
|
7
7
|
},
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": {
|
|
@@ -19,70 +19,68 @@
|
|
|
19
19
|
"node": ">=18.0.0"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@babel/parser": "7.
|
|
23
|
-
"@babel/traverse": "7.
|
|
24
|
-
"chalk": "
|
|
25
|
-
"chokidar": "4.0.3",
|
|
26
|
-
"commander": "
|
|
27
|
-
"debounce": "2.0.0",
|
|
28
|
-
"esbuild": "0.25.0",
|
|
29
|
-
"glob": "
|
|
30
|
-
"log-symbols": "
|
|
31
|
-
"mime-types": "
|
|
32
|
-
"next": "15.2.4",
|
|
33
|
-
"normalize-path": "3.0.0",
|
|
34
|
-
"ora": "
|
|
35
|
-
"socket.io": "4.8.1"
|
|
22
|
+
"@babel/parser": "^7.27.0",
|
|
23
|
+
"@babel/traverse": "^7.27.0",
|
|
24
|
+
"chalk": "^5.0.0",
|
|
25
|
+
"chokidar": "^4.0.3",
|
|
26
|
+
"commander": "^13.0.0",
|
|
27
|
+
"debounce": "^2.0.0",
|
|
28
|
+
"esbuild": "^0.25.0",
|
|
29
|
+
"glob": "^11.0.0",
|
|
30
|
+
"log-symbols": "^7.0.0",
|
|
31
|
+
"mime-types": "^3.0.0",
|
|
32
|
+
"next": "^15.2.4",
|
|
33
|
+
"normalize-path": "^3.0.0",
|
|
34
|
+
"ora": "^8.0.0",
|
|
35
|
+
"socket.io": "^4.8.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@babel/core": "7.26.10",
|
|
39
|
-
"@lottiefiles/dotlottie-react": "0.
|
|
40
|
-
"@radix-ui/colors": "
|
|
41
|
-
"@radix-ui/react-collapsible": "1.1.
|
|
42
|
-
"@radix-ui/react-dropdown-menu": "2.1.
|
|
43
|
-
"@radix-ui/react-popover": "1.1.
|
|
44
|
-
"@radix-ui/react-slot": "1.
|
|
45
|
-
"@radix-ui/react-tabs": "1.1.
|
|
46
|
-
"@radix-ui/react-toggle-group": "1.1.
|
|
47
|
-
"@radix-ui/react-tooltip": "1.
|
|
48
|
-
"@swc/core": "1.
|
|
39
|
+
"@lottiefiles/dotlottie-react": "0.13.3",
|
|
40
|
+
"@radix-ui/colors": "3.0.0",
|
|
41
|
+
"@radix-ui/react-collapsible": "1.1.7",
|
|
42
|
+
"@radix-ui/react-dropdown-menu": "2.1.10",
|
|
43
|
+
"@radix-ui/react-popover": "1.1.10",
|
|
44
|
+
"@radix-ui/react-slot": "1.2.0",
|
|
45
|
+
"@radix-ui/react-tabs": "1.1.7",
|
|
46
|
+
"@radix-ui/react-toggle-group": "1.1.6",
|
|
47
|
+
"@radix-ui/react-tooltip": "1.2.3",
|
|
48
|
+
"@swc/core": "1.11.21",
|
|
49
49
|
"@types/babel__core": "7.20.5",
|
|
50
|
-
"@types/babel__traverse": "
|
|
50
|
+
"@types/babel__traverse": "7.20.7",
|
|
51
51
|
"@types/fs-extra": "11.0.1",
|
|
52
52
|
"@types/mime-types": "2.1.4",
|
|
53
|
-
"@types/node": "22.
|
|
53
|
+
"@types/node": "22.14.1",
|
|
54
54
|
"@types/normalize-path": "3.0.2",
|
|
55
55
|
"@types/react": "19.0.10",
|
|
56
56
|
"@types/react-dom": "19.0.4",
|
|
57
57
|
"@types/webpack": "5.28.5",
|
|
58
|
-
"
|
|
59
|
-
"autoprefixer": "10.4.20",
|
|
58
|
+
"autoprefixer": "10.4.21",
|
|
60
59
|
"clsx": "2.1.1",
|
|
61
|
-
"framer-motion": "12.
|
|
60
|
+
"framer-motion": "12.7.5",
|
|
62
61
|
"jiti": "2.4.2",
|
|
63
62
|
"json5": "2.2.3",
|
|
64
63
|
"module-punycode": "npm:punycode@2.3.1",
|
|
65
|
-
"node-html-parser": "
|
|
66
|
-
"postcss": "8.
|
|
67
|
-
"prettier-plugin-tailwindcss": "0.6.6",
|
|
64
|
+
"node-html-parser": "7.0.1",
|
|
65
|
+
"postcss": "8.5.3",
|
|
68
66
|
"pretty-bytes": "6.1.1",
|
|
69
|
-
"prism-react-renderer": "2.1
|
|
67
|
+
"prism-react-renderer": "2.4.1",
|
|
70
68
|
"react": "19.0.0",
|
|
71
69
|
"react-dom": "19.0.0",
|
|
72
|
-
"sharp": "0.
|
|
73
|
-
"socket.io-client": "4.8.
|
|
74
|
-
"sonner": "
|
|
75
|
-
"source-map-js": "1.
|
|
70
|
+
"sharp": "0.34.1",
|
|
71
|
+
"socket.io-client": "4.8.1",
|
|
72
|
+
"sonner": "2.0.3",
|
|
73
|
+
"source-map-js": "1.2.1",
|
|
76
74
|
"spamc": "0.0.5",
|
|
77
|
-
"stacktrace-parser": "0.1.
|
|
78
|
-
"tailwind-merge": "
|
|
75
|
+
"stacktrace-parser": "0.1.11",
|
|
76
|
+
"tailwind-merge": "3.2.0",
|
|
79
77
|
"tailwindcss": "3.4.0",
|
|
80
|
-
"tsup": "
|
|
81
|
-
"tsx": "4.
|
|
82
|
-
"typescript": "5.8.
|
|
78
|
+
"tsup": "8.4.0",
|
|
79
|
+
"tsx": "4.19.3",
|
|
80
|
+
"typescript": "5.8.3",
|
|
83
81
|
"use-debounce": "10.0.4",
|
|
84
|
-
"zod": "3.24.
|
|
85
|
-
"@react-email/components": "0.0.
|
|
82
|
+
"zod": "3.24.3",
|
|
83
|
+
"@react-email/components": "0.0.37"
|
|
86
84
|
},
|
|
87
85
|
"scripts": {
|
|
88
86
|
"build": "tsup-node && node ./scripts/build-preview-server.mjs && pnpm install --frozen-lockfile",
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { parse } from '@babel/parser';
|
|
3
3
|
import traverse from '@babel/traverse';
|
|
4
4
|
import {
|
|
5
|
-
type SourceLocation,
|
|
6
5
|
convertLocationIntoObject,
|
|
7
6
|
getObjectVariables,
|
|
7
|
+
type SourceLocation,
|
|
8
8
|
} from '../../utils/caniemail/ast/get-object-variables';
|
|
9
9
|
import type { StylePropertyUsage } from '../../utils/caniemail/ast/get-used-style-properties';
|
|
10
10
|
import {
|
|
@@ -3,7 +3,7 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import logSymbols from 'log-symbols';
|
|
6
|
-
import ora from 'ora';
|
|
6
|
+
import ora, { type Ora } from 'ora';
|
|
7
7
|
import { isBuilding, isPreviewDevelopment } from '../app/env';
|
|
8
8
|
import { getEmailComponent } from '../utils/get-email-component';
|
|
9
9
|
import { improveErrorWithSourceMap } from '../utils/improve-error-with-sourcemap';
|
|
@@ -35,7 +35,7 @@ export const renderEmailByPath = async (
|
|
|
35
35
|
const timeBeforeEmailRendered = performance.now();
|
|
36
36
|
|
|
37
37
|
const emailFilename = path.basename(emailPath);
|
|
38
|
-
let spinner:
|
|
38
|
+
let spinner: Ora | undefined;
|
|
39
39
|
if (!isBuilding && !isPreviewDevelopment) {
|
|
40
40
|
spinner = ora({
|
|
41
41
|
text: `Rendering email template ${emailFilename}\n`,
|
|
@@ -76,11 +76,11 @@ export const renderEmailByPath = async (
|
|
|
76
76
|
|
|
77
77
|
const reactMarkup = await fs.promises.readFile(emailPath, 'utf-8');
|
|
78
78
|
|
|
79
|
-
const
|
|
80
|
-
let timeForConsole = `${
|
|
81
|
-
if (
|
|
79
|
+
const millisecondsToRendered = performance.now() - timeBeforeEmailRendered;
|
|
80
|
+
let timeForConsole = `${millisecondsToRendered.toFixed(0)}ms`;
|
|
81
|
+
if (millisecondsToRendered <= 450) {
|
|
82
82
|
timeForConsole = chalk.green(timeForConsole);
|
|
83
|
-
} else if (
|
|
83
|
+
} else if (millisecondsToRendered <= 1000) {
|
|
84
84
|
timeForConsole = chalk.yellow(timeForConsole);
|
|
85
85
|
} else {
|
|
86
86
|
timeForConsole = chalk.red(timeForConsole);
|
|
@@ -8,8 +8,8 @@ import { useDebouncedCallback } from 'use-debounce';
|
|
|
8
8
|
import { Topbar } from '../../../components';
|
|
9
9
|
import { CodeContainer } from '../../../components/code-container';
|
|
10
10
|
import {
|
|
11
|
-
ResizableWrapper,
|
|
12
11
|
makeIframeDocumentBubbleEvents,
|
|
12
|
+
ResizableWrapper,
|
|
13
13
|
} from '../../../components/resizable-wrapper';
|
|
14
14
|
import { Send } from '../../../components/send';
|
|
15
15
|
import { useToolbarState } from '../../../components/toolbar';
|
|
@@ -104,6 +104,7 @@ const ToolbarInner = ({
|
|
|
104
104
|
});
|
|
105
105
|
|
|
106
106
|
if (!isBuilding) {
|
|
107
|
+
// biome-ignore lint/correctness/useHookAtTopLevel: This is fine since isBuilding does not change at runtime
|
|
107
108
|
useEffect(() => {
|
|
108
109
|
(async () => {
|
|
109
110
|
const lintingRows = await loadLinting();
|
package/src/contexts/emails.tsx
CHANGED
|
@@ -32,9 +32,7 @@ export const EmailsProvider = (props: {
|
|
|
32
32
|
useState<EmailsDirectory>(props.initialEmailsDirectoryMetadata);
|
|
33
33
|
|
|
34
34
|
if (!isBuilding) {
|
|
35
|
-
// this will not change on runtime so it doesn't violate
|
|
36
|
-
// the rules of hooks
|
|
37
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
35
|
+
// biome-ignore lint/correctness/useHookAtTopLevel: this will not change on runtime so it doesn't violate the rules of hooks
|
|
38
36
|
useHotreload(async () => {
|
|
39
37
|
const metadata = await getEmailsDirectoryMetadataAction(
|
|
40
38
|
props.initialEmailsDirectoryMetadata.absolutePath,
|
|
@@ -18,7 +18,9 @@ export const useFragmentIdentifier = () => {
|
|
|
18
18
|
|
|
19
19
|
export const FragmentIdentifierProvider = ({
|
|
20
20
|
children,
|
|
21
|
-
}: {
|
|
21
|
+
}: {
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
}) => {
|
|
22
24
|
const [fragmentIdentifier, setFragmentIdentifier] = useState<string>();
|
|
23
25
|
const pathname = usePathname();
|
|
24
26
|
const searchParams = useSearchParams();
|
package/src/contexts/preview.tsx
CHANGED
|
@@ -50,9 +50,7 @@ export const PreviewProvider = ({
|
|
|
50
50
|
);
|
|
51
51
|
|
|
52
52
|
if (!isBuilding) {
|
|
53
|
-
// this will not change on runtime so it doesn't violate
|
|
54
|
-
// the rules of hooks
|
|
55
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
53
|
+
// biome-ignore lint/correctness/useHookAtTopLevel: this will not change on runtime so it doesn't violate the rules of hooks
|
|
56
54
|
useHotreload((changes) => {
|
|
57
55
|
const changeForThisEmail = changes.find((change) =>
|
|
58
56
|
change.filename.includes(emailSlug),
|
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
renderEmailByPath,
|
|
6
6
|
} from '../actions/render-email-by-path';
|
|
7
7
|
import { isBuilding } from '../app/env';
|
|
8
|
+
import { useEmails } from '../contexts/emails';
|
|
9
|
+
import { containsEmailTemplate } from '../utils/contains-email-template';
|
|
8
10
|
import { useHotreload } from './use-hot-reload';
|
|
9
11
|
|
|
10
12
|
export const useEmailRenderingResult = (
|
|
@@ -15,20 +17,31 @@ export const useEmailRenderingResult = (
|
|
|
15
17
|
serverEmailRenderedResult,
|
|
16
18
|
);
|
|
17
19
|
|
|
20
|
+
const { emailsDirectoryMetadata } = useEmails();
|
|
21
|
+
|
|
18
22
|
if (!isBuilding) {
|
|
19
|
-
//
|
|
23
|
+
// biome-ignore lint/correctness/useHookAtTopLevel: This is fine since isBuilding does not change at runtime
|
|
20
24
|
useHotreload(async (changes) => {
|
|
21
25
|
for await (const change of changes) {
|
|
22
|
-
const
|
|
26
|
+
const relativePathForChangedFile =
|
|
23
27
|
// ex: apple-receipt.tsx
|
|
24
28
|
// it will be the path relative to the emails directory, so it is already
|
|
25
29
|
// going to be equivalent to the slug
|
|
26
30
|
change.filename;
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
if (
|
|
33
|
+
!containsEmailTemplate(
|
|
34
|
+
relativePathForChangedFile,
|
|
35
|
+
emailsDirectoryMetadata,
|
|
36
|
+
)
|
|
37
|
+
) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const pathForChangedEmail = await getEmailPathFromSlug(
|
|
42
|
+
relativePathForChangedFile,
|
|
43
|
+
);
|
|
30
44
|
|
|
31
|
-
// We always render the email template here so that we can allow
|
|
32
45
|
const newRenderingResult = await renderEmailByPath(
|
|
33
46
|
pathForChangedEmail,
|
|
34
47
|
true,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`getEmailComponent() > with a demo email template 1`] = `"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html dir="ltr" lang="en"><head><link rel="preload" as="image" href="/static/vercel-logo.png"/><link rel="preload" as="image" href="/static/vercel-user.png"/><link rel="preload" as="image" href="/static/vercel-arrow.png"/><link rel="preload" as="image" href="/static/vercel-team.png"/><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/><meta name="x-apple-disable-message-reformatting"/><!--$--></head><body style="
|
|
3
|
+
exports[`getEmailComponent() > with a demo email template 1`] = `"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html dir="ltr" lang="en"><head><link rel="preload" as="image" href="/static/vercel-logo.png"/><link rel="preload" as="image" href="/static/vercel-user.png"/><link rel="preload" as="image" href="/static/vercel-arrow.png"/><link rel="preload" as="image" href="/static/vercel-team.png"/><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/><meta name="x-apple-disable-message-reformatting"/><!--$--></head><body style="margin-left:auto;margin-right:auto;margin-top:auto;margin-bottom:auto;background-color:rgb(255,255,255);padding-left:0.5rem;padding-right:0.5rem;font-family:ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji""><div style="display:none;overflow:hidden;line-height:1px;opacity:0;max-height:0;max-width:0">Join Alan on Vercel<div> </div></div><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-left:auto;margin-right:auto;margin-top:40px;margin-bottom:40px;max-width:465px;border-radius:0.25rem;border-width:1px;border-color:rgb(234,234,234);border-style:solid;padding:20px"><tbody><tr style="width:100%"><td><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-top:32px"><tbody><tr><td><img alt="Vercel Logo" height="37" src="/static/vercel-logo.png" style="margin-left:auto;margin-right:auto;margin-top:0px;margin-bottom:0px;display:block;outline:none;border:none;text-decoration:none" width="40"/></td></tr></tbody></table><h1 style="margin-left:0px;margin-right:0px;margin-top:30px;margin-bottom:30px;padding:0px;text-align:center;font-weight:400;font-size:24px;color:rgb(0,0,0)">Join <strong>Enigma</strong> on <strong>Vercel</strong></h1><p style="font-size:14px;color:rgb(0,0,0);line-height:24px;margin-top:16px;margin-bottom:16px">Hello <!-- -->alanturing<!-- -->,</p><p style="font-size:14px;color:rgb(0,0,0);line-height:24px;margin-top:16px;margin-bottom:16px"><strong>Alan</strong> (<a href="mailto:alan.turing@example.com" style="color:rgb(37,99,235);text-decoration-line:none" target="_blank">alan.turing@example.com</a>) has invited you to the <strong>Enigma</strong> team on<!-- --> <strong>Vercel</strong>.</p><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation"><tbody><tr><td><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation"><tbody style="width:100%"><tr style="width:100%"><td align="right" data-id="__react-email-column"><img alt="alanturing's profile picture" height="64" src="/static/vercel-user.png" style="border-radius:9999px;display:block;outline:none;border:none;text-decoration:none" width="64"/></td><td align="center" data-id="__react-email-column"><img alt="Arrow indicating invitation" height="9" src="/static/vercel-arrow.png" style="display:block;outline:none;border:none;text-decoration:none" width="12"/></td><td align="left" data-id="__react-email-column"><img alt="Enigma team logo" height="64" src="/static/vercel-team.png" style="border-radius:9999px;display:block;outline:none;border:none;text-decoration:none" width="64"/></td></tr></tbody></table></td></tr></tbody></table><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-top:32px;margin-bottom:32px;text-align:center"><tbody><tr><td><a href="https://vercel.com" style="border-radius:0.25rem;background-color:rgb(0,0,0);padding-left:1.25rem;padding-right:1.25rem;padding-top:0.75rem;padding-bottom:0.75rem;text-align:center;font-weight:600;font-size:12px;color:rgb(255,255,255);text-decoration-line:none;line-height:100%;text-decoration:none;display:inline-block;max-width:100%;mso-padding-alt:0px;padding:12px 20px 12px 20px" target="_blank"><span><!--[if mso]><i style="mso-font-width:500%;mso-text-raise:18" hidden>  </i><![endif]--></span><span style="max-width:100%;display:inline-block;line-height:120%;mso-padding-alt:0px;mso-text-raise:9px">Join the team</span><span><!--[if mso]><i style="mso-font-width:500%" hidden>  ​</i><![endif]--></span></a></td></tr></tbody></table><p style="font-size:14px;color:rgb(0,0,0);line-height:24px;margin-top:16px;margin-bottom:16px">or copy and paste this URL into your browser:<!-- --> <a href="https://vercel.com" style="color:rgb(37,99,235);text-decoration-line:none" target="_blank">https://vercel.com</a></p><hr style="margin-left:0px;margin-right:0px;margin-top:26px;margin-bottom:26px;width:100%;border-width:1px;border-color:rgb(234,234,234);border-style:solid;border:none;border-top:1px solid #eaeaea"/><p style="color:rgb(102,102,102);font-size:12px;line-height:24px;margin-top:16px;margin-bottom:16px">This invitation was intended for<!-- --> <span style="color:rgb(0,0,0)">alanturing</span>. This invite was sent from <span style="color:rgb(0,0,0)">204.13.186.218</span> <!-- -->located in<!-- --> <span style="color:rgb(0,0,0)">São Paulo, Brazil</span>. If you were not expecting this invitation, you can ignore this email. If you are concerned about your account's safety, please reply to this email to get in touch with us.</p></td></tr></tbody></table><!--/$--></body></html>"`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Root, Rule } from 'postcss';
|
|
2
1
|
import postcss from 'postcss';
|
|
2
|
+
import type { Root, Rule } from 'postcss';
|
|
3
3
|
import evaluateTailwindFunctions from 'tailwindcss/lib/lib/evaluateTailwindFunctions';
|
|
4
4
|
import { generateRules as rawGenerateRules } from 'tailwindcss/lib/lib/generateRules';
|
|
5
5
|
import type { JitContext } from 'tailwindcss/lib/lib/setupContextUtils';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import type { Node } from '@babel/traverse';
|
|
4
3
|
import traverse from '@babel/traverse';
|
|
4
|
+
import type { Node } from '@babel/traverse';
|
|
5
5
|
import * as esbuild from 'esbuild';
|
|
6
6
|
import type { Config as TailwindOriginalConfig } from 'tailwindcss';
|
|
7
7
|
import type { AST } from '../../../actions/email-validation/check-compatibility';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import traverse from '@babel/traverse';
|
|
2
2
|
import type { JitContext } from 'tailwindcss/lib/lib/setupContextUtils';
|
|
3
3
|
import type { AST } from '../../../actions/email-validation/check-compatibility';
|
|
4
|
-
import { type TailwindConfig
|
|
4
|
+
import { getTailwindConfig, type TailwindConfig } from './get-tailwind-config';
|
|
5
5
|
import { setupTailwindContext } from './setup-tailwind-context';
|
|
6
6
|
|
|
7
7
|
export const getTailwindMetadata = async (
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import {
|
|
3
|
+
containsEmailTemplate,
|
|
4
|
+
removeFilenameExtension,
|
|
5
|
+
} from './contains-email-template';
|
|
6
|
+
|
|
7
|
+
describe('removeFilenameExtension()', async () => {
|
|
8
|
+
it('should work with a single .', () => {
|
|
9
|
+
expect(removeFilenameExtension('email-template.tsx')).toBe(
|
|
10
|
+
'email-template',
|
|
11
|
+
);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should work with an example test file', () => {
|
|
15
|
+
expect(removeFilenameExtension('email-template.spec.tsx')).toBe(
|
|
16
|
+
'email-template.spec',
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should do nothing when there is no extension', () => {
|
|
21
|
+
expect(removeFilenameExtension('email-template')).toBe('email-template');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('containsEmailTemplate()', async () => {
|
|
26
|
+
const emailsDirectoryPath = path.resolve(
|
|
27
|
+
__dirname,
|
|
28
|
+
'../../../../apps/demo/emails',
|
|
29
|
+
);
|
|
30
|
+
const directory = {
|
|
31
|
+
absolutePath: emailsDirectoryPath,
|
|
32
|
+
directoryName: 'emails',
|
|
33
|
+
relativePath: '',
|
|
34
|
+
emailFilenames: [],
|
|
35
|
+
subDirectories: [
|
|
36
|
+
{
|
|
37
|
+
absolutePath: `${emailsDirectoryPath}/magic-links`,
|
|
38
|
+
directoryName: 'magic-links',
|
|
39
|
+
relativePath: 'magic-links',
|
|
40
|
+
emailFilenames: [
|
|
41
|
+
'aws-verify-email',
|
|
42
|
+
'linear-login-code',
|
|
43
|
+
'notion-magic-link',
|
|
44
|
+
'plaid-verify-identity',
|
|
45
|
+
'raycast-magic-link',
|
|
46
|
+
'slack-confirm',
|
|
47
|
+
],
|
|
48
|
+
subDirectories: [],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
absolutePath: `${emailsDirectoryPath}/newsletters`,
|
|
52
|
+
directoryName: 'newsletters',
|
|
53
|
+
relativePath: 'newsletters',
|
|
54
|
+
emailFilenames: [
|
|
55
|
+
'codepen-challengers',
|
|
56
|
+
'google-play-policy-update',
|
|
57
|
+
'stack-overflow-tips',
|
|
58
|
+
],
|
|
59
|
+
subDirectories: [],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
absolutePath: `${emailsDirectoryPath}/notifications`,
|
|
63
|
+
directoryName: 'notifications',
|
|
64
|
+
relativePath: 'notifications',
|
|
65
|
+
emailFilenames: [
|
|
66
|
+
'github-access-token',
|
|
67
|
+
'papermark-year-in-review',
|
|
68
|
+
'vercel-invite-user',
|
|
69
|
+
'yelp-recent-login',
|
|
70
|
+
],
|
|
71
|
+
subDirectories: [],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
absolutePath: `${emailsDirectoryPath}/receipts`,
|
|
75
|
+
directoryName: 'receipts',
|
|
76
|
+
relativePath: 'receipts',
|
|
77
|
+
emailFilenames: ['apple-receipt', 'nike-receipt'],
|
|
78
|
+
subDirectories: [],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
absolutePath: `${emailsDirectoryPath}/reset-password`,
|
|
82
|
+
directoryName: 'reset-password',
|
|
83
|
+
relativePath: 'reset-password',
|
|
84
|
+
emailFilenames: ['dropbox-reset-password', 'twitch-reset-password'],
|
|
85
|
+
subDirectories: [],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
absolutePath: `${emailsDirectoryPath}/reviews`,
|
|
89
|
+
directoryName: 'reviews',
|
|
90
|
+
relativePath: 'reviews',
|
|
91
|
+
emailFilenames: ['airbnb-review', 'amazon-review'],
|
|
92
|
+
subDirectories: [],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
absolutePath: `${emailsDirectoryPath}/welcome`,
|
|
96
|
+
directoryName: 'welcome',
|
|
97
|
+
relativePath: 'welcome',
|
|
98
|
+
emailFilenames: ['koala-welcome', 'netlify-welcome', 'stripe-welcome'],
|
|
99
|
+
subDirectories: [],
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
expect(containsEmailTemplate('welcome/koala-welcome', directory)).toBe(true);
|
|
104
|
+
expect(containsEmailTemplate('welcome/missing-template', directory)).toBe(
|
|
105
|
+
false,
|
|
106
|
+
);
|
|
107
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { EmailsDirectory } from './get-emails-directory-metadata';
|
|
2
|
+
|
|
3
|
+
export const removeFilenameExtension = (filename: string): string => {
|
|
4
|
+
const parts = filename.split('.');
|
|
5
|
+
|
|
6
|
+
if (parts.length > 1) {
|
|
7
|
+
return parts.slice(0, -1).join('.');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return filename;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const containsEmailTemplate = (
|
|
14
|
+
relativeEmailPath: string,
|
|
15
|
+
directory: EmailsDirectory,
|
|
16
|
+
) => {
|
|
17
|
+
const remainingSegments = relativeEmailPath
|
|
18
|
+
.replace(directory.relativePath, '')
|
|
19
|
+
.split('/')
|
|
20
|
+
.filter(Boolean);
|
|
21
|
+
if (remainingSegments.length === 1) {
|
|
22
|
+
const emailFilename = removeFilenameExtension(remainingSegments[0]!);
|
|
23
|
+
return directory.emailFilenames.includes(emailFilename);
|
|
24
|
+
}
|
|
25
|
+
const subDirectory = directory.subDirectories.find(
|
|
26
|
+
(sub) => sub.relativePath === remainingSegments[0],
|
|
27
|
+
);
|
|
28
|
+
if (subDirectory === undefined) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return containsEmailTemplate(relativeEmailPath, subDirectory);
|
|
33
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import type { render } from '@react-email/components';
|
|
3
|
-
import { type BuildFailure, type OutputFile
|
|
3
|
+
import { type BuildFailure, build, type OutputFile } from 'esbuild';
|
|
4
4
|
import type React from 'react';
|
|
5
5
|
import type { RawSourceMap } from 'source-map-js';
|
|
6
6
|
import { z } from 'zod';
|
|
@@ -106,6 +106,21 @@ export const getEmailComponent = async (
|
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
if (typeof parseResult.data.default !== 'function') {
|
|
110
|
+
return {
|
|
111
|
+
error: improveErrorWithSourceMap(
|
|
112
|
+
new Error(
|
|
113
|
+
`The email component at ${emailPath} does not contain a default exported function`,
|
|
114
|
+
{
|
|
115
|
+
cause: parseResult.error,
|
|
116
|
+
},
|
|
117
|
+
),
|
|
118
|
+
emailPath,
|
|
119
|
+
sourceMapToEmail,
|
|
120
|
+
),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
109
124
|
const { data: componentModule } = parseResult;
|
|
110
125
|
|
|
111
126
|
return {
|
|
@@ -2,25 +2,33 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
|
|
5
|
-
const isFileAnEmail = (fullPath: string): boolean => {
|
|
6
|
-
|
|
5
|
+
const isFileAnEmail = async (fullPath: string): Promise<boolean> => {
|
|
6
|
+
let fileHandle: fs.promises.FileHandle;
|
|
7
|
+
try {
|
|
8
|
+
fileHandle = await fs.promises.open(fullPath, 'r');
|
|
9
|
+
} catch (exception) {
|
|
10
|
+
console.warn(exception);
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const stat = await fileHandle.stat();
|
|
7
14
|
|
|
8
|
-
if (stat.isDirectory())
|
|
15
|
+
if (stat.isDirectory()) {
|
|
16
|
+
await fileHandle.close();
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
9
19
|
|
|
10
20
|
const { ext } = path.parse(fullPath);
|
|
11
21
|
|
|
12
|
-
if (!['.js', '.tsx', '.jsx'].includes(ext))
|
|
13
|
-
|
|
14
|
-
// This is to avoid a possible race condition where the file doesn't exist anymore
|
|
15
|
-
// once we are checking if it is an actual email, this couuld cause issues that
|
|
16
|
-
// would be very hard to debug and find out the why of it happening.
|
|
17
|
-
if (!fs.existsSync(fullPath)) {
|
|
22
|
+
if (!['.js', '.tsx', '.jsx'].includes(ext)) {
|
|
23
|
+
await fileHandle.close();
|
|
18
24
|
return false;
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
// check with a heuristic to see if the file has at least
|
|
22
28
|
// a default export (ES6) or module.exports (CommonJS) or named exports (MDX)
|
|
23
|
-
const fileContents =
|
|
29
|
+
const fileContents = await fileHandle.readFile('utf8');
|
|
30
|
+
|
|
31
|
+
await fileHandle.close();
|
|
24
32
|
|
|
25
33
|
// Check for ES6 export default syntax
|
|
26
34
|
const hasES6DefaultExport = /\bexport\s+default\b/gm.test(fileContents);
|
|
@@ -80,10 +88,13 @@ export const getEmailsDirectoryMetadata = async (
|
|
|
80
88
|
withFileTypes: true,
|
|
81
89
|
});
|
|
82
90
|
|
|
83
|
-
const
|
|
84
|
-
.
|
|
91
|
+
const isEmailPredicates = await Promise.all(
|
|
92
|
+
dirents.map((dirent) =>
|
|
85
93
|
isFileAnEmail(path.join(absolutePathToEmailsDirectory, dirent.name)),
|
|
86
|
-
)
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
const emailFilenames = dirents
|
|
97
|
+
.filter((_, i) => isEmailPredicates[i])
|
|
87
98
|
.map((dirent) =>
|
|
88
99
|
keepFileExtensions
|
|
89
100
|
? dirent.name
|
package/src/utils/index.ts
CHANGED