Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const mkdirp = require('mkdirp');
const babel = require('babel-core');
const UglifyJS = require("uglify-es");
const compatPlugin = require('babel-plugin-transform-proxy-compat');
const PolyfillBuilder = require('./polyfill-builder');
// -- File source dependencies ----------
const proxyCompat = fs.readFileSync(require.resolve('proxy-compat/dist/umd/proxy-compat.js'), 'utf8');
const babelHelpers = fs.readFileSync(require.resolve('babel-helpers-lwc/dist/engine-helpers.js'), 'utf8');
const polyfillsDir = path.resolve(__dirname, '../src/polyfills');
const polyfillList = fs.readdirSync(polyfillsDir);
const downgradeSrc = fs.readFileSync(path.resolve(__dirname, '../src/downgrade.js'));
const polyfillSources = polyfillList.reduce((src, p) => src + fs.readFileSync(path.join(polyfillsDir, p), 'utf8'), '');
// -- Config -----------------------------
const compatKeys = Object.values(compatPlugin.keys);
const compatOverrides = compatKeys.reduce((str, key) => `${str} var __${key} = window.Proxy.${key};`, '');
const dest = path.join(__dirname, '../dist/umd');
const babelConfig = {
babelrc: false,
plugins: [[compatPlugin, { resolveProxyCompat: { global: 'window.Proxy' } }]]
};
// -- Build -----------------------------
PolyfillBuilder()
.then(ecmaPolyfills => {
const { code : babelHelpersCompat } = babel.transform(babelHelpers, babelConfig);
const compatArtifactsSource = polyfillSources + ecmaPolyfills + babelHelpersCompat;
const compatSrc = [
'/* proxy-compat */',