Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for ESM module transpilation #2273

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const ESM = process.env.ESM === 'true'

module.exports = {
presets: [['@babel/env', {
targets: { node: '10' },
include: ['transform-classes'],
...(ESM ? { modules: false } : {}),
}]],
plugins: [
'@babel/proposal-class-properties',
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"private": true,
"scripts": {
"build:watch": "lerna run build --parallel -- -- -w",
"build": "lerna run build --parallel --ignore mjml-browser",
"build": "yarn run build:cjs && yarn run build:esm",
"build:cjs": "lerna run build --parallel --ignore mjml-browser",
"build:esm": "cross-env ESM=true lerna run build:esm --parallel --ignore mjml-browser --ignore mjml-cli --ignore mjml-migrate",
"build-browser": "cd packages/mjml-browser && yarn build",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
Expand All @@ -22,6 +24,7 @@
"babel-eslint": "^10.1.0",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-lodash": "^3.3.4",
"cross-env": "^7.0.3",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-config-prettier": "^6.11.0",
Expand Down
12 changes: 9 additions & 3 deletions packages/mjml-accordion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "mjml-accordion",
"description": "mjml-accordion",
"version": "4.9.3",
"main": "lib/index.js",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"exports": {
"imports": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"files": [
"lib"
],
Expand All @@ -18,7 +23,8 @@
"homepage": "https://mjml.io",
"scripts": {
"clean": "rimraf lib",
"build": "babel src --out-dir lib --root-mode upward"
"build": "babel src --out-dir lib/cjs --root-mode upward",
"build:esm": "babel src --out-dir lib/esm --root-mode upward"
},
"dependencies": {
"@babel/runtime": "^7.8.7",
Expand All @@ -29,4 +35,4 @@
"@babel/cli": "^7.8.4",
"rimraf": "^3.0.2"
}
}
}
2 changes: 1 addition & 1 deletion packages/mjml-accordion/src/AccordionElement.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BodyComponent } from 'mjml-core'
import { find } from 'lodash'
import conditionalTag from 'mjml-core/lib/helpers/conditionalTag'
import conditionalTag from 'mjml-core/lib/esm/helpers/conditionalTag'
import AccordionText from './AccordionText'
import AccordionTitle from './AccordionTitle'

Expand Down
2 changes: 1 addition & 1 deletion packages/mjml-accordion/src/AccordionTitle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BodyComponent } from 'mjml-core'
import conditionalTag from 'mjml-core/lib/helpers/conditionalTag'
import conditionalTag from 'mjml-core/lib/esm/helpers/conditionalTag'

export default class MjAccordionTitle extends BodyComponent {
static componentName = 'mj-accordion-title'
Expand Down
12 changes: 9 additions & 3 deletions packages/mjml-body/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "mjml-body",
"description": "mjml-body",
"version": "4.9.3",
"main": "lib/index.js",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"exports": {
"imports": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"files": [
"lib"
],
Expand All @@ -18,7 +23,8 @@
"homepage": "https://mjml.io",
"scripts": {
"clean": "rimraf lib",
"build": "babel src --out-dir lib --root-mode upward"
"build": "babel src --out-dir lib/cjs --root-mode upward",
"build:esm": "babel src --out-dir lib/esm --root-mode upward"
},
"dependencies": {
"@babel/runtime": "^7.8.7",
Expand All @@ -29,4 +35,4 @@
"@babel/cli": "^7.8.4",
"rimraf": "^3.0.2"
}
}
}
12 changes: 9 additions & 3 deletions packages/mjml-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "mjml-button",
"description": "mjml-button",
"version": "4.9.3",
"main": "lib/index.js",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"exports": {
"imports": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"files": [
"lib"
],
Expand All @@ -18,7 +23,8 @@
"homepage": "https://mjml.io",
"scripts": {
"clean": "rimraf lib",
"build": "babel src --out-dir lib --root-mode upward"
"build": "babel src --out-dir lib/cjs --root-mode upward",
"build:esm": "babel src --out-dir lib/esm --root-mode upward"
},
"dependencies": {
"@babel/runtime": "^7.8.7",
Expand All @@ -29,4 +35,4 @@
"@babel/cli": "^7.8.4",
"rimraf": "^3.0.2"
}
}
}
2 changes: 1 addition & 1 deletion packages/mjml-button/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BodyComponent } from 'mjml-core'

import widthParser from 'mjml-core/lib/helpers/widthParser'
import widthParser from 'mjml-core/lib/esm/helpers/widthParser'

export default class MjButton extends BodyComponent {
static componentName = 'mj-button'
Expand Down
12 changes: 9 additions & 3 deletions packages/mjml-carousel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "mjml-carousel",
"description": "mjml-carousel",
"version": "4.9.3",
"main": "lib/index.js",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"exports": {
"imports": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"files": [
"lib"
],
Expand All @@ -18,7 +23,8 @@
"homepage": "https://mjml.io",
"scripts": {
"clean": "rimraf lib",
"build": "babel src --out-dir lib --root-mode upward"
"build": "babel src --out-dir lib/cjs --root-mode upward",
"build:esm": "babel src --out-dir lib/esm --root-mode upward"
},
"dependencies": {
"@babel/runtime": "^7.8.7",
Expand All @@ -29,4 +35,4 @@
"@babel/cli": "^7.8.4",
"rimraf": "^3.0.2"
}
}
}
2 changes: 1 addition & 1 deletion packages/mjml-carousel/src/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BodyComponent } from 'mjml-core'
import { range, repeat, min, map } from 'lodash'
import crypto from 'crypto'

import { msoConditionalTag } from 'mjml-core/lib/helpers/conditionalTag'
import { msoConditionalTag } from 'mjml-core/lib/esm/helpers/conditionalTag'

export default class MjCarousel extends BodyComponent {
static componentName = 'mj-carousel'
Expand Down
12 changes: 9 additions & 3 deletions packages/mjml-column/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "mjml-column",
"description": "mjml-column",
"version": "4.9.3",
"main": "lib/index.js",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"exports": {
"imports": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"files": [
"lib"
],
Expand All @@ -18,7 +23,8 @@
"homepage": "https://mjml.io",
"scripts": {
"clean": "rimraf lib",
"build": "babel src --out-dir lib --root-mode upward"
"build": "babel src --out-dir lib/cjs --root-mode upward",
"build:esm": "babel src --out-dir lib/esm --root-mode upward"
},
"dependencies": {
"@babel/runtime": "^7.8.7",
Expand All @@ -29,4 +35,4 @@
"@babel/cli": "^7.8.4",
"rimraf": "^3.0.2"
}
}
}
2 changes: 1 addition & 1 deletion packages/mjml-column/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BodyComponent } from 'mjml-core'

import widthParser from 'mjml-core/lib/helpers/widthParser'
import widthParser from 'mjml-core/lib/esm/helpers/widthParser'

export default class MjColumn extends BodyComponent {
static componentName = 'mj-column'
Expand Down
12 changes: 9 additions & 3 deletions packages/mjml-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "mjml-core",
"description": "mjml-core",
"version": "4.9.3",
"main": "lib/index.js",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"exports": {
"imports": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"files": [
"lib"
],
Expand All @@ -18,7 +23,8 @@
"homepage": "https://mjml.io",
"scripts": {
"clean": "rimraf lib",
"build": "babel src --out-dir lib --root-mode upward",
"build": "babel src --out-dir lib/cjs --root-mode upward",
"build:esm": "babel src --out-dir lib/esm --root-mode upward",
"test": "node ./tests/index.js"
},
"dependencies": {
Expand All @@ -38,4 +44,4 @@
"chai": "^4.1.1",
"rimraf": "^3.0.2"
}
}
}
2 changes: 1 addition & 1 deletion packages/mjml-core/tests/jsonToXml-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const chai = require('chai')
const jsonToXml = require('../lib/helpers/jsonToXML')
const jsonToXml = require('../lib/cjs/helpers/jsonToXML')

const json = {
line: 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/mjml-core/tests/mergeOutlookConditionnals-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const chai = require('chai')
const mergeOutlookConditionnals = require('../lib/helpers/mergeOutlookConditionnals')
const mergeOutlookConditionnals = require('../lib/cjs/helpers/mergeOutlookConditionnals')

const testValues = [
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/mjml-core/tests/shorthandParser-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const chai = require('chai')
const helper = require('../lib/helpers/shorthandParser')
const helper = require('../lib/cjs/helpers/shorthandParser')

const shorthandParser = helper && helper.default

Expand Down
2 changes: 1 addition & 1 deletion packages/mjml-core/tests/widthParser-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const chai = require('chai')
const widthParser = require('../lib/helpers/widthParser')
const widthParser = require('../lib/cjs/helpers/widthParser')

const testValues = [
{
Expand Down
12 changes: 9 additions & 3 deletions packages/mjml-divider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "mjml-divider",
"description": "mjml-divider",
"version": "4.9.3",
"main": "lib/index.js",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"exports": {
"imports": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"files": [
"lib"
],
Expand All @@ -18,7 +23,8 @@
"homepage": "https://mjml.io",
"scripts": {
"clean": "rimraf lib",
"build": "babel src --out-dir lib --root-mode upward"
"build": "babel src --out-dir lib/cjs --root-mode upward",
"build:esm": "babel src --out-dir lib/esm --root-mode upward"
},
"dependencies": {
"@babel/runtime": "^7.8.7",
Expand All @@ -29,4 +35,4 @@
"@babel/cli": "^7.8.4",
"rimraf": "^3.0.2"
}
}
}
2 changes: 1 addition & 1 deletion packages/mjml-divider/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BodyComponent } from 'mjml-core'

import widthParser from 'mjml-core/lib/helpers/widthParser'
import widthParser from 'mjml-core/lib/esm/helpers/widthParser'

export default class MjDivider extends BodyComponent {
static componentName = 'mj-divider'
Expand Down
12 changes: 9 additions & 3 deletions packages/mjml-group/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "mjml-group",
"description": "mjml-group",
"version": "4.9.3",
"main": "lib/index.js",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"exports": {
"imports": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"files": [
"lib"
],
Expand All @@ -18,7 +23,8 @@
"homepage": "https://mjml.io",
"scripts": {
"clean": "rimraf lib",
"build": "babel src --out-dir lib --root-mode upward"
"build": "babel src --out-dir lib/cjs --root-mode upward",
"build:esm": "babel src --out-dir lib/esm --root-mode upward"
},
"dependencies": {
"@babel/runtime": "^7.8.7",
Expand All @@ -29,4 +35,4 @@
"@babel/cli": "^7.8.4",
"rimraf": "^3.0.2"
}
}
}
2 changes: 1 addition & 1 deletion packages/mjml-group/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BodyComponent } from 'mjml-core'

import widthParser from 'mjml-core/lib/helpers/widthParser'
import widthParser from 'mjml-core/lib/esm/helpers/widthParser'

export default class MjGroup extends BodyComponent {
static componentName = 'mj-group'
Expand Down
12 changes: 9 additions & 3 deletions packages/mjml-head-attributes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "mjml-head-attributes",
"description": "mjml-head-attributes",
"version": "4.9.3",
"main": "lib/index.js",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"exports": {
"imports": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"files": [
"lib"
],
Expand All @@ -18,7 +23,8 @@
"homepage": "https://mjml.io",
"scripts": {
"clean": "rimraf lib",
"build": "babel src --out-dir lib --root-mode upward"
"build": "babel src --out-dir lib/cjs --root-mode upward",
"build:esm": "babel src --out-dir lib/esm --root-mode upward"
},
"dependencies": {
"@babel/runtime": "^7.8.7",
Expand All @@ -29,4 +35,4 @@
"@babel/cli": "^7.8.4",
"rimraf": "^3.0.2"
}
}
}
Loading