Skip to content

Commit

Permalink
Use babel standalone package (#723)
Browse files Browse the repository at this point in the history
Though it isn't recommended, MDX often finds itself
being used on the client or other environmentts where
bundler configuration might not be customizable.

This switches to babel standalone to allow for better
support for those scenarios.

Before actually merging this it might be worthwhile to
add some benchmarking to ensure that this doesn't introduce
a performance regression (I'm not sure how standalone
works internally).

---

Closes #704
  • Loading branch information
johno authored Sep 10, 2019
1 parent aecd7f5 commit f20a83e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/mdx/mdx-hast-to-jsx.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {transformSync} = require('@babel/core')
const {transform} = require('@babel/standalone')
const styleToObject = require('style-to-object')
const camelCaseCSS = require('camelcase-css')
const uniq = require('lodash.uniq')
Expand Down Expand Up @@ -102,7 +102,7 @@ MDXContent.isMDXComponent = true`

// Check JSX nodes against imports
const babelPluginExptractImportNamesInstance = new BabelPluginExtractImportNames()
transformSync(importStatements, {
transform(importStatements, {
configFile: false,
babelrc: false,
plugins: [
Expand All @@ -116,7 +116,7 @@ MDXContent.isMDXComponent = true`
const babelPluginApplyMdxPropInstance = new BabelPluginApplyMdxProp()
const babelPluginApplyMdxPropToExportsInstance = new BabelPluginApplyMdxProp()

const fnPostMdxTypeProp = transformSync(fn, {
const fnPostMdxTypeProp = transform(fn, {
configFile: false,
babelrc: false,
plugins: [
Expand All @@ -126,7 +126,7 @@ MDXContent.isMDXComponent = true`
]
}).code

const exportStatementsPostMdxTypeProps = transformSync(exportStatements, {
const exportStatementsPostMdxTypeProps = transform(exportStatements, {
configFile: false,
babelrc: false,
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion packages/mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"mdx-hast-to-jsx.js"
],
"dependencies": {
"@babel/core": "7.6.0",
"@babel/plugin-syntax-jsx": "7.2.0",
"@babel/plugin-syntax-object-rest-spread": "7.2.0",
"@babel/standalone": "7.6.0",
"@mdx-js/util": "^1.4.5",
"babel-plugin-apply-mdx-type-prop": "^1.4.5",
"babel-plugin-extract-import-names": "^1.4.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/remark-mdx/extract-imports-and-exports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {transformSync} = require('@babel/core')
const {transform} = require('@babel/standalone')
const declare = require('@babel/helper-plugin-utils').declare

const syntaxJsxPlugin = require('@babel/plugin-syntax-jsx')
Expand Down Expand Up @@ -48,7 +48,7 @@ const partitionString = (str, indices) =>
module.exports = (value, vfile) => {
const instance = new BabelPluginExtractImportsAndExports()

transformSync(value, {
transform(value, {
plugins: [syntaxJsxPlugin, proposalObjectRestSpreadPlugin, instance.plugin],
filename: vfile.path,
configFile: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/remark-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"extract-imports-and-exports.js"
],
"dependencies": {
"@babel/core": "7.6.0",
"@babel/helper-plugin-utils": "7.0.0",
"@babel/plugin-proposal-object-rest-spread": "7.5.5",
"@babel/plugin-syntax-jsx": "7.2.0",
"@babel/standalone": "^7.5.5",
"@mdx-js/util": "^1.4.5",
"is-alphabetical": "1.0.3",
"remark-parse": "7.0.1",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,11 @@
dependencies:
regenerator-runtime "^0.12.0"

"@babel/standalone@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/standalone/-/standalone-7.5.5.tgz#9d3143f6078ff408db694a4254bd6f03c5c33962"
integrity sha512-YIp5taErC4uvp4d5urJtWMui3cpvZt83x57l4oVJNvFtDzumf3pMgRmoTSpGuEzh1yzo7jHhg3mbQmMhmKPbjA==

"@babel/template@^7.0.0 <7.4.0":
version "7.2.2"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.2.2.tgz#005b3fdf0ed96e88041330379e0da9a708eb2907"
Expand Down

0 comments on commit f20a83e

Please sign in to comment.