Javascript SDK of WoopChain protocol
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
sdk/scripts/jest/transformer.js

29 lines
1.0 KiB

const path = require('path')
const babel = require('@babel/core')
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction')
const babelOptions = require('../babel/babel.test.config.js')
// Use require.resolve to be resilient to file moves, npm updates, etc
const pathToBabel = path.join(require.resolve('@babel/core'), '../', '../', 'package.json')
const pathToBabelrc = path.join(__dirname, '../babel/babel.test.config.js')
module.exports = {
process(src, filePath) {
if (!filePath.match(/\/third_party\//)) {
const isTestFile = !!filePath.match(/\/__test__\//)
const concatOptions = Object.assign(
babelOptions,
{ filename: path.relative(process.cwd(), filePath) },
isTestFile
? {
plugins: babelOptions.plugins
}
: {}
)
const result = babel.transformSync(src, concatOptions)
return result.code
}
return src
},
getCacheKey: createCacheKeyFunction([__filename, pathToBabel, pathToBabelrc])
}