Skip to content

Commit e612d42

Browse files
authored
🤖 Merge PR DefinitelyTyped#74888 [mjml-core] Update mjml2html to return Promise<MJMLParseResults> for v5 by @qchuchu
1 parent 7a9e6b9 commit e612d42

7 files changed

Lines changed: 76 additions & 62 deletions

File tree

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import mjml2html = require("mjml-browser");
22

3-
const simple_test = mjml2html("<mjml>");
4-
const html = simple_test.html;
5-
const errors = simple_test.errors;
6-
let formattedMessage = errors[0].formattedMessage;
7-
formattedMessage = "force string test";
3+
async function tests() {
4+
const simple_test = await mjml2html("<mjml>");
5+
const html = simple_test.html;
6+
const errors = simple_test.errors;
7+
let formattedMessage = errors[0].formattedMessage;
8+
formattedMessage = "force string test";
89

9-
const minimalOptionsTest = mjml2html("<mjml>", { beautify: true });
10-
const validationLevelTest = mjml2html("<mjml>", { validationLevel: "strict" });
11-
const filePathTest = mjml2html("<mjml>", { filePath: "." });
10+
const minimalOptionsTest = await mjml2html("<mjml>", { beautify: true });
11+
const validationLevelTest = await mjml2html("<mjml>", { validationLevel: "strict" });
12+
const filePathTest = await mjml2html("<mjml>", { filePath: "." });
1213

13-
const jsonObject = { tagName: "mjml", attributes: { width: "100px" }, content: "test content" };
14-
const jsonObjectTest = mjml2html(jsonObject);
14+
const jsonObject = { tagName: "mjml", attributes: { width: "100px" }, content: "test content" };
15+
const jsonObjectTest = await mjml2html(jsonObject);
1516

16-
const minifyTest = mjml2html("<mjml", { minifyOptions: { minifyCSS: true } });
17-
const minifyAllTest = mjml2html("<mjml", {
18-
minifyOptions: { minifyCSS: true, collapseWhitespace: true, removeEmptyAttributes: true },
19-
});
17+
const minifyTest = await mjml2html("<mjml", { minifyOptions: { minifyCSS: true } });
18+
const minifyAllTest = await mjml2html("<mjml", {
19+
minifyOptions: { minifyCSS: true, collapseWhitespace: true, removeEmptyAttributes: true },
20+
});
21+
}

‎types/mjml-browser/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/mjml-browser",
4-
"version": "4.15.9999",
4+
"version": "5.0.9999",
55
"projects": [
66
"https://github.com/mjmlio/mjml",
77
"https://mjml.io"

‎types/mjml-core/index.d.ts‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
* The main parser for MJML.
33
* This version doesn't contain any of the core components registered in the 'mjml' package.
44
*/
5-
export default function mjml2html(input: string | MJMLJsonObject, options?: MJMLParsingOptions): MJMLParseResults;
5+
export default function mjml2html(
6+
input: string | MJMLJsonObject,
7+
options?: MJMLParsingOptions,
8+
): Promise<MJMLParseResults>;
69

710
/**
811
* Options passed as an object to the mjml2html function
@@ -25,28 +28,24 @@ export interface MJMLParsingOptions {
2528
keepComments?: boolean | undefined;
2629

2730
/**
28-
* @deprecated use js-beautify directly after processing the MJML
29-
*
30-
* Option to beautify the HTML output
31+
* Beautify the HTML output using prettier (parser: 'html', printWidth: 240).
32+
* Mutually exclusive with minify — if minify is true, beautify is skipped.
33+
* Note: the CLI defaults this to true; the programmatic API defaults to false.
3134
* default: false
3235
*/
3336
beautify?: boolean | undefined;
3437

3538
/**
36-
* @deprecated use html-minifier directly after processing the MJML
37-
*
38-
* Option to minify the HTML output
39-
*
39+
* Minify the HTML output using htmlnano (with cssnano-preset-lite for CSS).
40+
* Takes priority over beautify when both are true.
4041
* default: false
4142
*/
4243
minify?: boolean | undefined;
44+
4345
/**
44-
* @deprecated @see minify
45-
*
46-
* Options for html minifier, see mjml-cli documentation for more info
47-
* Passed directly to html-minifier as options
48-
*
49-
* default: @see htmlMinify usage in mjml-core/src/index.js
46+
* Options passed to htmlnano when minify is true.
47+
* The minifyCss field accepts false, true, 'lite', or a cssnano options object.
48+
* All htmlnano v3 options are accepted.
5049
*/
5150
minifyOptions?: MJMLMinifyOptions | undefined;
5251

@@ -113,8 +112,17 @@ export interface MJMLParsingOptions {
113112

114113
export interface MJMLMinifyOptions {
115114
collapseWhitespace?: boolean | undefined;
115+
/**
116+
* CSS minification options passed to cssnano-preset-lite.
117+
* Accepts false (disable), true/'lite' (use lite preset), or a cssnano options object.
118+
* @see https://cssnano.co/docs/presets
119+
*/
120+
minifyCss?: boolean | "lite" | { preset?: any; plugins?: any[]; configFile?: string } | undefined;
121+
/** @deprecated use minifyCss instead */
116122
minifyCSS?: boolean | undefined;
117123
removeEmptyAttributes?: boolean | undefined;
124+
minifyJs?: boolean | undefined;
125+
removeComments?: false | "safe" | "all" | undefined;
118126
}
119127

120128
export interface MJMLParseResults {

‎types/mjml-core/mjml-core-tests.ts‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import mjml2html, { BodyComponent, Component, HeadComponent, MJMLJsonObject, registerComponent } from "mjml-core";
22

3-
const simple_test = mjml2html("<mjml>");
4-
const html = simple_test.html;
5-
const errors = simple_test.errors;
6-
let formattedMessage = errors[0].formattedMessage;
7-
formattedMessage = "force string test";
8-
9-
const minimal_opts_test = mjml2html("<mjml>", { beautify: true });
10-
const validation_level_test = mjml2html("<mjml>", { validationLevel: "strict" });
11-
const filePath_test = mjml2html("<mjml>", { filePath: "." });
12-
13-
const jsonObject = { tagName: "mjml", attributes: { width: "100px" }, content: "test content" };
14-
const jsonObject_test = mjml2html(jsonObject);
15-
16-
const minify_opts_test = mjml2html("<mjml", { minifyOptions: { minifyCSS: true } });
17-
const minify_opts_all_test = mjml2html("<mjml", {
18-
minifyOptions: { minifyCSS: true, collapseWhitespace: true, removeEmptyAttributes: true },
19-
});
3+
async function tests() {
4+
const simple_test = await mjml2html("<mjml>");
5+
const html = simple_test.html;
6+
const errors = simple_test.errors;
7+
let formattedMessage = errors[0].formattedMessage;
8+
formattedMessage = "force string test";
9+
10+
const minimal_opts_test = await mjml2html("<mjml>", { beautify: true });
11+
const validation_level_test = await mjml2html("<mjml>", { validationLevel: "strict" });
12+
const filePath_test = await mjml2html("<mjml>", { filePath: "." });
13+
14+
const jsonObject = { tagName: "mjml", attributes: { width: "100px" }, content: "test content" };
15+
const jsonObject_test = await mjml2html(jsonObject);
16+
17+
const minify_opts_test = await mjml2html("<mjml", { minifyOptions: { minifyCSS: true } });
18+
const minify_opts_all_test = await mjml2html("<mjml", {
19+
minifyOptions: { minifyCSS: true, collapseWhitespace: true, removeEmptyAttributes: true },
20+
});
21+
}
2022

2123
class NewBodyComponent extends BodyComponent {
2224
render() {

‎types/mjml-core/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/mjml-core",
4-
"version": "4.15.9999",
4+
"version": "5.0.9999",
55
"projects": [
66
"https://mjml.io"
77
],

‎types/mjml/mjml-tests.ts‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import mjml2html = require("mjml");
22

3-
const simple_test = mjml2html("<mjml>");
4-
const html = simple_test.html;
5-
const errors = simple_test.errors;
6-
let formattedMessage = errors[0].formattedMessage;
7-
formattedMessage = "force string test";
3+
async function tests() {
4+
const simple_test = await mjml2html("<mjml>");
5+
const html = simple_test.html;
6+
const errors = simple_test.errors;
7+
let formattedMessage = errors[0].formattedMessage;
8+
formattedMessage = "force string test";
89

9-
const minimal_opts_test = mjml2html("<mjml>", { beautify: true });
10-
const validation_level_test = mjml2html("<mjml>", { validationLevel: "strict" });
11-
const filePath_test = mjml2html("<mjml>", { filePath: "." });
10+
const minimal_opts_test = await mjml2html("<mjml>", { beautify: true });
11+
const validation_level_test = await mjml2html("<mjml>", { validationLevel: "strict" });
12+
const filePath_test = await mjml2html("<mjml>", { filePath: "." });
1213

13-
const jsonObject = { tagName: "mjml", attributes: { width: "100px" }, content: "test content" };
14-
const jsonObject_test = mjml2html(jsonObject);
14+
const jsonObject = { tagName: "mjml", attributes: { width: "100px" }, content: "test content" };
15+
const jsonObject_test = await mjml2html(jsonObject);
1516

16-
const minify_opts_test = mjml2html("<mjml", { minifyOptions: { minifyCSS: true } });
17-
const minify_opts_all_test = mjml2html("<mjml", {
18-
minifyOptions: { minifyCSS: true, collapseWhitespace: true, removeEmptyAttributes: true },
19-
});
17+
const minify_opts_test = await mjml2html("<mjml", { minifyOptions: { minifyCSS: true } });
18+
const minify_opts_all_test = await mjml2html("<mjml", {
19+
minifyOptions: { minifyCSS: true, collapseWhitespace: true, removeEmptyAttributes: true },
20+
});
21+
}

‎types/mjml/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/mjml",
4-
"version": "4.7.9999",
4+
"version": "5.0.9999",
55
"projects": [
66
"https://github.com/mjmlio/mjml",
77
"https://mjml.io"

0 commit comments

Comments
 (0)