Skip to content

Commit

Permalink
[core] Make sanity exec use same babel config as studio (#1322)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed May 24, 2019
1 parent 26e2469 commit 3130fef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
38 changes: 26 additions & 12 deletions packages/@sanity/core/src/actions/exec/babel.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import fs from 'fs'
import path from 'path'
import registerBabel from '@babel/register'

registerBabel({
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
]
]
})
function getConfig() {
try {
// eslint-disable-next-line no-sync
const content = fs.readFileSync(path.join(process.cwd(), '.babelrc'))
return JSON.parse(content)
} catch (err) {
return {
presets: [
require.resolve('@babel/preset-react'),
[
require.resolve('@babel/preset-env'),
{
targets: {
node: 'current'
}
}
]
],
plugins: [require.resolve('@babel/plugin-proposal-class-properties')]
}
}
}

registerBabel(getConfig())
4 changes: 2 additions & 2 deletions packages/@sanity/core/src/actions/exec/execScript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path')
const spawn = require('child_process').spawn
const path = require('path')
const fse = require('fs-extra')

module.exports = async args => {
Expand All @@ -17,7 +17,7 @@ module.exports = async args => {
}

const babel = require.resolve('./babel')
const loader = require.resolve('@sanity/plugin-loader/register')
const loader = require.resolve('./pluginLoader')
const nodeArgs = ['-r', babel, '-r', loader]
.concat(withToken ? ['-r', require.resolve('./configClient')] : [])
.concat(scriptPath)
Expand Down
3 changes: 3 additions & 0 deletions packages/@sanity/core/src/actions/exec/pluginLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const registerLoader = require('@sanity/plugin-loader')

registerLoader({basePath: process.cwd(), stubCss: true})

0 comments on commit 3130fef

Please sign in to comment.