From e612d42ac2b8dadd8e1f7f0ded86a1641c3a8ebf Mon Sep 17 00:00:00 2001 From: Quentin Churet <45853629+qchuchu@users.noreply.github.com> Date: Mon, 20 Apr 2026 20:06:36 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#74888=20[mjml-core?= =?UTF-8?q?]=20Update=20mjml2html=20to=20return=20Promise=20for=20v5=20by=20@qchuchu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/mjml-browser/mjml-browser-tests.ts | 30 +++++++++++--------- types/mjml-browser/package.json | 2 +- types/mjml-core/index.d.ts | 36 +++++++++++++++--------- types/mjml-core/mjml-core-tests.ts | 36 +++++++++++++----------- types/mjml-core/package.json | 2 +- types/mjml/mjml-tests.ts | 30 +++++++++++--------- types/mjml/package.json | 2 +- 7 files changed, 76 insertions(+), 62 deletions(-) diff --git a/types/mjml-browser/mjml-browser-tests.ts b/types/mjml-browser/mjml-browser-tests.ts index da744000efb08c..7114de2e422eaa 100644 --- a/types/mjml-browser/mjml-browser-tests.ts +++ b/types/mjml-browser/mjml-browser-tests.ts @@ -1,19 +1,21 @@ import mjml2html = require("mjml-browser"); -const simple_test = mjml2html(""); -const html = simple_test.html; -const errors = simple_test.errors; -let formattedMessage = errors[0].formattedMessage; -formattedMessage = "force string test"; +async function tests() { + const simple_test = await mjml2html(""); + const html = simple_test.html; + const errors = simple_test.errors; + let formattedMessage = errors[0].formattedMessage; + formattedMessage = "force string test"; -const minimalOptionsTest = mjml2html("", { beautify: true }); -const validationLevelTest = mjml2html("", { validationLevel: "strict" }); -const filePathTest = mjml2html("", { filePath: "." }); + const minimalOptionsTest = await mjml2html("", { beautify: true }); + const validationLevelTest = await mjml2html("", { validationLevel: "strict" }); + const filePathTest = await mjml2html("", { filePath: "." }); -const jsonObject = { tagName: "mjml", attributes: { width: "100px" }, content: "test content" }; -const jsonObjectTest = mjml2html(jsonObject); + const jsonObject = { tagName: "mjml", attributes: { width: "100px" }, content: "test content" }; + const jsonObjectTest = await mjml2html(jsonObject); -const minifyTest = mjml2html("; /** * Options passed as an object to the mjml2html function @@ -25,28 +28,24 @@ export interface MJMLParsingOptions { keepComments?: boolean | undefined; /** - * @deprecated use js-beautify directly after processing the MJML - * - * Option to beautify the HTML output + * Beautify the HTML output using prettier (parser: 'html', printWidth: 240). + * Mutually exclusive with minify — if minify is true, beautify is skipped. + * Note: the CLI defaults this to true; the programmatic API defaults to false. * default: false */ beautify?: boolean | undefined; /** - * @deprecated use html-minifier directly after processing the MJML - * - * Option to minify the HTML output - * + * Minify the HTML output using htmlnano (with cssnano-preset-lite for CSS). + * Takes priority over beautify when both are true. * default: false */ minify?: boolean | undefined; + /** - * @deprecated @see minify - * - * Options for html minifier, see mjml-cli documentation for more info - * Passed directly to html-minifier as options - * - * default: @see htmlMinify usage in mjml-core/src/index.js + * Options passed to htmlnano when minify is true. + * The minifyCss field accepts false, true, 'lite', or a cssnano options object. + * All htmlnano v3 options are accepted. */ minifyOptions?: MJMLMinifyOptions | undefined; @@ -113,8 +112,17 @@ export interface MJMLParsingOptions { export interface MJMLMinifyOptions { collapseWhitespace?: boolean | undefined; + /** + * CSS minification options passed to cssnano-preset-lite. + * Accepts false (disable), true/'lite' (use lite preset), or a cssnano options object. + * @see https://cssnano.co/docs/presets + */ + minifyCss?: boolean | "lite" | { preset?: any; plugins?: any[]; configFile?: string } | undefined; + /** @deprecated use minifyCss instead */ minifyCSS?: boolean | undefined; removeEmptyAttributes?: boolean | undefined; + minifyJs?: boolean | undefined; + removeComments?: false | "safe" | "all" | undefined; } export interface MJMLParseResults { diff --git a/types/mjml-core/mjml-core-tests.ts b/types/mjml-core/mjml-core-tests.ts index c0ad94c9272608..136797a3a4255e 100644 --- a/types/mjml-core/mjml-core-tests.ts +++ b/types/mjml-core/mjml-core-tests.ts @@ -1,22 +1,24 @@ import mjml2html, { BodyComponent, Component, HeadComponent, MJMLJsonObject, registerComponent } from "mjml-core"; -const simple_test = mjml2html(""); -const html = simple_test.html; -const errors = simple_test.errors; -let formattedMessage = errors[0].formattedMessage; -formattedMessage = "force string test"; - -const minimal_opts_test = mjml2html("", { beautify: true }); -const validation_level_test = mjml2html("", { validationLevel: "strict" }); -const filePath_test = mjml2html("", { filePath: "." }); - -const jsonObject = { tagName: "mjml", attributes: { width: "100px" }, content: "test content" }; -const jsonObject_test = mjml2html(jsonObject); - -const minify_opts_test = mjml2html(""); + const html = simple_test.html; + const errors = simple_test.errors; + let formattedMessage = errors[0].formattedMessage; + formattedMessage = "force string test"; + + const minimal_opts_test = await mjml2html("", { beautify: true }); + const validation_level_test = await mjml2html("", { validationLevel: "strict" }); + const filePath_test = await mjml2html("", { filePath: "." }); + + const jsonObject = { tagName: "mjml", attributes: { width: "100px" }, content: "test content" }; + const jsonObject_test = await mjml2html(jsonObject); + + const minify_opts_test = await mjml2html(""); -const html = simple_test.html; -const errors = simple_test.errors; -let formattedMessage = errors[0].formattedMessage; -formattedMessage = "force string test"; +async function tests() { + const simple_test = await mjml2html(""); + const html = simple_test.html; + const errors = simple_test.errors; + let formattedMessage = errors[0].formattedMessage; + formattedMessage = "force string test"; -const minimal_opts_test = mjml2html("", { beautify: true }); -const validation_level_test = mjml2html("", { validationLevel: "strict" }); -const filePath_test = mjml2html("", { filePath: "." }); + const minimal_opts_test = await mjml2html("", { beautify: true }); + const validation_level_test = await mjml2html("", { validationLevel: "strict" }); + const filePath_test = await mjml2html("", { filePath: "." }); -const jsonObject = { tagName: "mjml", attributes: { width: "100px" }, content: "test content" }; -const jsonObject_test = mjml2html(jsonObject); + const jsonObject = { tagName: "mjml", attributes: { width: "100px" }, content: "test content" }; + const jsonObject_test = await mjml2html(jsonObject); -const minify_opts_test = mjml2html("