Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function generateExport() {
const cosmosConfig = getCosmosConfig();
const { rootPath, outputPath, publicPath, publicUrl } = cosmosConfig;
const webpack = silentImport(rootPath, 'webpack');
if (!webpack) {
console.warn('[Cosmos] webpack dependency missing!');
console.log('Install using "yarn add webpack" or "npm install webpack"');
return;
}
const userWebpackConfig = getUserWebpackConfig(cosmosConfig);
const loaderWebpackConfig = enhanceWebpackConfig({
webpack,
userWebpackConfig,
shouldExport: true
});
// Copy static files first, so that the built index.html overrides the its
// template file (in case the static assets are served from the root path)
if (publicPath) {
NODE_ENV: JSON.stringify(shouldExport ? 'production' : 'development'),
PUBLIC_URL: JSON.stringify(removeTrailingSlash(publicUrl))
}
}),
new webpack.DefinePlugin({
COSMOS_CONFIG: JSON.stringify({
// Config options that are available inside the client bundle. Warning:
// Must be serializable!
containerQuerySelector
})
}),
getNoErrorsPlugin(webpack)
];
if (!alreadyHasPlugin(webpackConfig, 'HtmlWebpackPlugin')) {
const HtmlWebpackPlugin = silentImport(rootPath, 'html-webpack-plugin');
if (HtmlWebpackPlugin) {
plugins = [
...plugins,
new HtmlWebpackPlugin({
title: 'React Cosmos',
filename: '_loader.html'
})
];
}
}
if (hot && !shouldExport) {
if (!alreadyHasPlugin(webpackConfig, 'HotModuleReplacementPlugin')) {
plugins = [...plugins, new webpack.HotModuleReplacementPlugin()];
}
// React.componentDidCatch https://github.com/facebook/react/issues/10441
devtool: 'cheap-module-source-map',
resolve: {
// Warning: webpack 1.x expects ['', '.js', '.jsx']
extensions: ['.js', '.jsx']
},
module: {
// Note: `module.rules` only works with webpack >=2.x. For 1.x
// compatibility a custom webpack config (with module.loaders) is required
rules
},
plugins
};
// Add mode option for webpack 4+
const webpack = silentImport(rootPath, 'webpack');
if (webpack.version && parseInt(webpack.version, 10) >= 4) {
// Disallow non dev/prod environments, like "test" inside Jest, because
// they are not supported by webpack
const mode =
process.env.NODE_ENV === 'production' ? 'production' : 'development';
config = {
...config,
mode,
optimization: {
// Cosmos reads component names at run-time, so it is crucial to not
// minify even when building with production env (ie. when exporting)
// https://github.com/react-cosmos/react-cosmos/issues/701
minimize: false
}
export function getWebpack(rootDir: string) {
const userWebpack = importFrom.silent(rootDir, 'webpack');
if (!userWebpack) {
console.warn('[Cosmos] webpack dependency missing!');
console.log(
'Install using "yarn add --dev webpack" or "npm install --save-dev webpack"'
);
return;
}
return userWebpack;
}
console.log(`[Cosmos] Nice! You're using ${generatedConfigFor}`);
console.log('[Cosmos] Generated a tailored config file for your setup');
}
}
const cosmosConfig = getCosmosConfig();
const { next, rootPath, publicUrl } = cosmosConfig;
if (cosmosConfig.proxies) {
console.warn('[Cosmos] Warning: config.proxies is deprecated!');
console.warn(
'Please check latest proxy docs: https://github.com/react-cosmos/react-cosmos#proxies'
);
}
const webpack = silentImport(rootPath, 'webpack');
if (!webpack) {
console.warn('[Cosmos] webpack dependency missing!');
console.log('Install using "yarn add webpack" or "npm install webpack"');
return () => {};
}
const userWebpackConfig = getUserWebpackConfig(cosmosConfig);
const app = createServerApp({
cosmosConfig,
playgroundOpts: getPlaygroundOpts(cosmosConfig)
});
const { server, startServer, stopServer } = createServer(cosmosConfig, app);
const publicPath = getPublicPath(cosmosConfig, userWebpackConfig);
if (publicPath) {
module.exports.loadConfig = (appDirectory) => {
const packageJson = importFrom.silent(appDirectory, './package.json');
if (!packageJson) {
return null;
}
const { haste } = packageJson;
if (!haste) {
return null;
}
return haste;
};
export function getHtmlWebpackPlugin(rootDir: string) {
return importFrom.silent(
rootDir,
'html-webpack-plugin'
);
}
;(Array.isArray(engine) ? engine : [engine]).some(eng => {
if (typeof eng === 'string') {
resolved =
(from && importFrom.silent(path.dirname(path.resolve(from)), eng)) ||
importFrom.silent(process.cwd(), eng)
if (resolved?.__esModule) resolved = resolved.default
} else {
resolved = eng
}
return resolved
})
allowUnsafeNewFunction(() => {
esformatter = importFrom.silent(path.dirname(fp), 'esformatter') || require('esformatter');
});
module.exports = ({releaseRules}, {cwd}) => {
let loadedReleaseRules;
if (releaseRules) {
loadedReleaseRules =
typeof releaseRules === 'string'
? importFrom.silent(__dirname, releaseRules) || importFrom(cwd, releaseRules)
: releaseRules;
if (!Array.isArray(loadedReleaseRules)) {
throw new TypeError('Error in commit-analyzer configuration: "releaseRules" must be an array of rules');
}
loadedReleaseRules.forEach(rule => {
if (!rule || isUndefined(rule.release)) {
throw new Error('Error in commit-analyzer configuration: rules must be an object with a "release" property');
} else if (!RELEASE_TYPES.includes(rule.release) && rule.release !== null && rule.release !== false) {
throw new Error(
`Error in commit-analyzer configuration: "${
rule.release
}" is not a valid release type. Valid values are: ${JSON.stringify(RELEASE_TYPES)}`
);
}