Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getBabelConfig(): Object {
// FIXME need to find a way to support other kind of babel configs.
const { config } = findBabelConfig.sync(resolveProject('.'));
if (config == null) {
return { presets: ['@reworkjs/core/babel-preset'] };
}
return config;
}
}
async function getImports(file, options) {
// Even though rollup-plugin-babel can autodiscover Babel configurations,
// here we want to use the same babel config for every module
const babelConfig =
options.babelConfig || findBabelConfig.sync(path.dirname(file)).file;
// https://rollupjs.org/guide/en#rollup-rollup
const inputOptions = {
external: [],
input: file,
plugins: [
nodeResolve({
extensions: defaultExtensions,
mainFields: options.resolveMainFields,
}),
babel({
include: options.include,
exclude: options.exclude,
extensions: defaultExtensions,
configFile: babelConfig,
}),
export default function getBabelConfig() {
// FIXME note: might break with Babel 7 due to new support for babelrc.js
const { config } = findBabelConfig.sync(resolveProject('.'));
if (config == null) {
return getDefaultBabelConfig();
}
// no need to load it, babel will do it on its own.
return null;
}
function genTempBabelConfig() {
const { config } = findBabelConfig.sync(ROOT);
const content = `module.exports = function (api) {
api.cache.never();
return ${JSON.stringify(config)}
};`;
outputFileSync(TEMP_BABEL_CONFIG, content);
}
export function getBabelConf() {
const { config } = findBabelConfig.sync(p.cwd());
if (!config) {
throw new Error(
'Couldn\'t find .babelrc or babel entry on package.json! You can specify custom config with "transformer". Please consult documentation.'
);
}
return config;
}
export const compile = async (code: string, { filename, modern, babelrc }: ScriptCompilerContext): Promise => {
const cwd = path.dirname(filename)
const file =
babelrc === false ?
null :
cache.get(cwd) ||
(require('find-babel-config')(cwd).then((res: any) => res.file))
cache.set(cwd, file)
const config: TransformOptions = {
filename,
presets: [
[
require.resolve('../babel/preset'),
{
modern
}
]
]
}
if (file) {