Skip to content

Commit c3b2cf2

Browse files
committed
feat: add fallback for util.styleText on Node <20.12.0
1 parent 9315a33 commit c3b2cf2

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

packages/preview-server/src/actions/render-email-by-path.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import fs from 'node:fs';
44
import path from 'node:path';
5-
import { styleText } from 'node:util';
65
import logSymbols from 'log-symbols';
76
import ora, { type Ora } from 'ora';
87
import {
@@ -15,6 +14,7 @@ import { convertStackWithSourceMap } from '../utils/convert-stack-with-sourcemap
1514
import { createJsxRuntime } from '../utils/create-jsx-runtime';
1615
import { getEmailComponent } from '../utils/get-email-component';
1716
import { registerSpinnerAutostopping } from '../utils/register-spinner-autostopping';
17+
import { styleText } from '../utils/style-text';
1818
import type { ErrorObject } from '../utils/types/error-object';
1919

2020
export interface RenderedEmailMetadata {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Centralized fallback for Node versions (<20.12.0) without util.styleText.
3+
* Returns the original text when styleText is unavailable.
4+
*/
5+
import * as nodeUtil from 'node:util';
6+
7+
type StyleTextFunction = (style: string, text: string) => string;
8+
9+
export const styleText: StyleTextFunction = (nodeUtil as any).styleText
10+
? (nodeUtil as any).styleText
11+
: (_: string, text: string) => text;

packages/react-email/src/utils/preview/start-dev-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import http from 'node:http';
22
import path from 'node:path';
33
import url from 'node:url';
4-
import { styleText } from 'node:util';
54
import { createJiti } from 'jiti';
65
import logSymbols from 'log-symbols';
76
import ora from 'ora';
87
import { registerSpinnerAutostopping } from '../../utils/register-spinner-autostopping.js';
98
import { getPreviewServerLocation } from '../get-preview-server-location.js';
109
import { packageJson } from '../packageJson.js';
10+
import { styleText } from '../style-text.js';
1111
import { getEnvVariablesForPreviewApp } from './get-env-variables-for-preview-app.js';
1212
import { serveStaticFile } from './serve-static-file.js';
1313

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Centralized fallback for Node versions (<20.12.0) without util.styleText.
3+
* Returns the original text when styleText is unavailable.
4+
*/
5+
import * as nodeUtil from 'node:util';
6+
7+
type StyleTextFunction = (style: string, text: string) => string;
8+
9+
export const styleText: StyleTextFunction = (nodeUtil as any).styleText
10+
? (nodeUtil as any).styleText
11+
: (_: string, text: string) => text;

0 commit comments

Comments
 (0)