Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
const chai = require('chai');
require('@babel/register').default({
plugins: [
'@babel/plugin-transform-modules-commonjs',
'module:babel-plugin-dynamic-import-node',
],
});
require('yaml-hook/register');
enzyme.configure({
adapter: new Adapter(),
});
chai.use(require('chai-enzyme')());
// Mock an asset like Webpack's file-loader.
function mockAsset(modulePath) {
const path = require.resolve(modulePath);
envName: program.envName,
rootMode: program.rootMode,
// Commander will default the "--no-" arguments to true, but we want to
// leave them undefined so that @babel/core can handle the
// default-assignment logic on its own.
babelrc: program.babelrc === true ? undefined : program.babelrc,
};
for (const key of Object.keys(babelOptions)) {
if (babelOptions[key] === undefined) {
delete babelOptions[key];
}
}
register(babelOptions);
const replPlugin = ({ types: t }) => ({
visitor: {
ModuleDeclaration(path) {
throw path.buildCodeFrameError("Modules aren't supported in the REPL");
},
VariableDeclaration(path) {
if (path.node.kind !== "var") {
throw path.buildCodeFrameError(
"Only `var` variables are supported in the REPL",
);
}
},
Program(path) {
export default function babelRequire(path) {
register({ presets: [preset] })
// eslint-disable-next-line global-require, import/no-dynamic-require
const mod = require(path)
revert()
return mod
}
export default function getDevServer(config = {}) {
const staticPath = getStaticBasePath(config)
const app = getBaseServer(config)
const webpackConfig = config.webpack || getWebpackDevConfig(config)
// Serve an empty CSS file for the main stylesheet,
// as they are injected dynamically in development mode
app.get(`${staticPath}/css/main.css`, (req, res) => {
res.set('Content-Type', 'text/css')
res.send()
})
// Use babel-register in order to be able to load things like
// the document component, which can contain JSX etc
registerBabel()
// Apply the dev and hot middlewares to build/serve bundles on the fly
const compiler = webpack(webpackConfig)
app.use(
webpackDevMiddleware(compiler, {
logLevel: 'silent',
watchOptions: {
ignored: /node_modules/
},
publicPath: webpackConfig.output.publicPath
})
)
app.use(webpackHotMiddleware(compiler))
// Expose webpack compiler on server instance
import mhyConfig from '@/configs/mhy'
import babelConfig from '@/configs/babel'
import register from '@babel/register'
babelConfig.presets.find(p => p[0].includes('preset-env'))[1] = {
modules: 'commonjs',
targets: {
node: true,
browsers: false,
esmodules: true
}
}
babelConfig.extensions = ['.es6', '.es', '.jsx', '.js', '.mjs', '.ts', '.tsx']
babelConfig.cache = false
register(babelConfig)
addPath(path.resolve(process.cwd(), 'node_modules'))
addPath(path.resolve(__dirname, '../../node_modules'))
const alias = { ...mhyConfig.defaultAliases }
for (const [key, entry] of Object.entries(alias)) {
if (!fs.existsSync(entry)) {
alias[key] = path.resolve(process.cwd(), entry)
} else {
// Make sure it's a resolved path indeed
alias[key] = path.resolve(entry)
}
}
addAliases(alias)
const scriptKey = '--mhy-script'
const scriptIndex = process.argv.findIndex(v => v.includes(scriptKey))
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const ExtractCssPlugin = require('mini-css-extract-plugin');
const HtmlPlugin = require('html-webpack-plugin');
const HtmlSiblingChunksPlugin = require('html-webpack-include-sibling-chunks-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { Plugin: ShakePlugin } = require('webpack-common-shake');
const merge = require('webpack-merge');
const htmlMinifierOptions = require('./tasks/utils/htmlMinifierOptions');
const nodeEnv = process.env.NODE_ENV || 'development';
const isDemo = process.env.DEMO === '1';
const outputPackage = isDemo ? __dirname : path.join(__dirname, 'packages/u-wave-web-middleware');
// Compile src/ on the fly so we can use components etc. during build time.
require('@babel/register').default({
only: [
new RegExp(escapeStringRegExp(path.join(__dirname, 'src'))),
new RegExp(escapeStringRegExp(path.join(__dirname, 'tasks/webpack'))),
],
plugins: [
['@babel/plugin-transform-modules-commonjs', { lazy: true }],
],
});
// Most webpack configuration is in this file. A few things are split up to make the
// core stuff easier to grasp.
//
// Other parts of the build are in the ./tasks/webpack/ folder:
// - compileDependencies: Compiles dependencies that only ship ES2015+ to code that
// works in all our browser targets.
const compileDependencies = require('./tasks/webpack/compileDependencies').default;
export default function babelRequire(path) {
register({ presets: [preset] })
// eslint-disable-next-line global-require, import/no-dynamic-require
const mod = require(path)
revert()
return mod
}
const savedConsole = console;
const builtIn = Module.builtinModules.filter(i => {
switch (i) {
case "sys":
return false;
}
if (/^(?:v8|node-inspect)\//g.test(i)) return false;
return true;
});
let cache;
if (config.cache) {
registerCache.load();
cache = registerCache.get();
}
let babelOpts = config.babelOpts || {};
babelOpts = {
...babelOpts,
caller: {
name: "@effectful/debugger",
...(babelOpts.caller || {})
}
};
const log = (...args) => console.log(...args);
function mtime(filename) {
return +fs.statSync(filename).mtime;
const savedConsole = console;
const builtIn = Module.builtinModules.filter(i => {
switch (i) {
case "sys":
return false;
}
if (/^(?:v8|node-inspect)\//g.test(i)) return false;
return true;
});
let cache;
if (config.cache) {
registerCache.load();
cache = registerCache.get();
}
let babelOpts = config.babelOpts || {};
babelOpts = {
...babelOpts,
caller: {
name: "@effectful/debugger",
...(babelOpts.caller || {})
}
};
const log = (...args) => console.log(...args);
function mtime(filename) {
export function initPlugins(options) {
register();
options.plugins.forEach(async plugin => {
let [, pluginPath, pluginOptions] = plugin;
const pluginPackage = path.join(pluginPath, 'package.json');
let initFile;
if (!pluginOptions) {
pluginOptions = {};
plugin[2] = pluginOptions;
}
try {
initFile = path.join(pluginPath, require(pluginPackage).init);
} catch (error) {
initFile = path.resolve(path.join(pluginPath, 'init.js'));
}