Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/famous-pandas-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@react-email/preview-server": patch
"react-email": patch
---

fallback to not text coloring for Node.js < 20
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import fs from 'node:fs';
import path from 'node:path';
import { styleText } from 'node:util';
import logSymbols from 'log-symbols';
import ora, { type Ora } from 'ora';
import {
Expand All @@ -15,6 +14,7 @@ import { convertStackWithSourceMap } from '../utils/convert-stack-with-sourcemap
import { createJsxRuntime } from '../utils/create-jsx-runtime';
import { getEmailComponent } from '../utils/get-email-component';
import { registerSpinnerAutostopping } from '../utils/register-spinner-autostopping';
import { styleText } from '../utils/style-text';
import type { ErrorObject } from '../utils/types/error-object';

export interface RenderedEmailMetadata {
Expand Down
11 changes: 11 additions & 0 deletions packages/preview-server/src/utils/style-text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Centralized fallback for Node versions (<20.12.0) without util.styleText.
* Returns the original text when styleText is unavailable.
*/
import * as nodeUtil from 'node:util';

type StyleTextFunction = (style: string, text: string) => string;

export const styleText: StyleTextFunction = (nodeUtil as any).styleText
? (nodeUtil as any).styleText
: (_: string, text: string) => text;
2 changes: 1 addition & 1 deletion packages/react-email/src/utils/preview/start-dev-server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import http from 'node:http';
import path from 'node:path';
import url from 'node:url';
import { styleText } from 'node:util';
import { createJiti } from 'jiti';
import logSymbols from 'log-symbols';
import ora from 'ora';
import { registerSpinnerAutostopping } from '../../utils/register-spinner-autostopping.js';
import { getPreviewServerLocation } from '../get-preview-server-location.js';
import { packageJson } from '../packageJson.js';
import { styleText } from '../style-text.js';
import { getEnvVariablesForPreviewApp } from './get-env-variables-for-preview-app.js';
import { serveStaticFile } from './serve-static-file.js';

Expand Down
11 changes: 11 additions & 0 deletions packages/react-email/src/utils/style-text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Centralized fallback for Node versions (<20.12.0) without util.styleText.
* Returns the original text when styleText is unavailable.
*/
import * as nodeUtil from 'node:util';

type StyleTextFunction = (style: string, text: string) => string;

export const styleText: StyleTextFunction = (nodeUtil as any).styleText
? (nodeUtil as any).styleText
: (_: string, text: string) => text;
Loading