Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
} catch (error) {
// this is a weird bugfix, somehow 'node-pre-gyp' is polluting the npmLog header
npmLog.heading = '';
if (error instanceof Error) {
if (error.error) {
logger.error(error.error);
} else if (error.stats && error.stats.compilation.errors) {
error.stats.compilation.errors.forEach(e => logger.plain(e));
} else {
logger.error(error);
}
}
logger.line();
logger.warn(
error.close
? dedent`
FATAL broken build!, will close the process,
Fix the error below and restart storybook.
`
: dedent`
Broken build, fix the error above.
You may need to refresh the browser.
`
);
logger.line();
if (options.smokeTest || (error && error.close)) {
process.exit(1);
}
}
export function applyAngularCliWebpackConfig(baseConfig: any, cliWebpackConfigOptions: any) {
if (!cliWebpackConfigOptions) {
return baseConfig;
}
if (!isBuildAngularInstalled()) {
logger.info('=> Using base config because @angular-devkit/build-angular is not installed.');
return baseConfig;
}
const cliParts = getAngularCliParts(cliWebpackConfigOptions);
if (!cliParts) {
logger.warn('=> Failed to get angular-cli webpack config.');
return baseConfig;
}
logger.info('=> Get angular-cli webpack config.');
const { cliCommonConfig, cliStyleConfig } = cliParts;
// Don't use storybooks styling rules because we have to use rules created by @angular-devkit/build-angular
// because @angular-devkit/build-angular created rules have include/exclude for global style files.
const rulesExcludingStyles = filterOutStylingRules(baseConfig);
// cliStyleConfig.entry adds global style files to the webpack context
// todo add type for acc
const entry = [
...baseConfig.entry,
...Object.values(cliStyleConfig.entry).reduce((acc: any, item) => acc.concat(item), []),
const start = async ({ configFiles, callOptions, cliOptions: cliOptionsRaw }: StartOptions) => {
logger.warn('experimental mono config mode enabled');
setTitle('storybook');
// filter the env options
const envOptions = cleanEnvOptions(process.env);
// filter the cli options
const cliOptions = cleanCliOptions(cliOptionsRaw);
const manager = builder.create(
{
command: 'watch',
type: 'manager',
},
{
envOptions,
if (pathIsNotResolved) {
const content = fs.readFileSync(reactScriptsScriptPath, 'utf8');
const packagePathMatch = content.match(
/"\$basedir[\\/]([^\s]+?[\\/]bin[\\/]react-scripts\.js")/i
);
if (packagePathMatch && packagePathMatch.length > 1) {
reactScriptsScriptPath = path.join(
appDirectory,
'/node_modules/.bin/',
packagePathMatch[1]
);
}
}
} catch (e) {
logger.warn(`Error occured during react-scripts package path resolving: ${e}`);
}
reactScriptsPath = path.join(reactScriptsScriptPath, '../..');
const scriptsPkgJson = path.join(reactScriptsPath, 'package.json');
if (!fs.existsSync(scriptsPkgJson)) {
reactScriptsPath = 'react-scripts';
}
return reactScriptsPath;
}
(err, stats) => {
managerTotalTime = process.hrtime(startTime);
if (!resolved && (err || stats.hasErrors())) {
const error = new Error('Manager build is broken');
error.error = err;
error.close = true;
error.stats = stats;
logger.line();
logger.line();
try {
previewReject(error);
previewProcess.close();
logger.warn('force closed preview build');
} catch (e) {
logger.warn('Unable to close preview build!');
}
logger.line();
reject(error);
} else {
resolve(stats);
}
}
);
preset: rest,
options: presetOptions,
},
];
}
throw new Error(dedent`
${input} is not a valid preset
`);
} catch (e) {
const warning =
level > 0
? ` Failed to load preset: ${JSON.stringify(input)} on level ${level}`
: ` Failed to load preset: ${JSON.stringify(input)}`;
logger.warn(warning);
logger.error(e);
return [];
}
}
stats.toJson(managerConfig.stats).warnings.forEach(e => logger.warn(e));
export async function getProperties(
preset: P.PresetFn | P.PresetRef | P.Preset
): Promise {
switch (typeof preset) {
case 'string': {
return import(preset);
}
case 'function': {
return preset();
}
case 'object': {
return preset;
}
default: {
logger.warn(`
preset should be a string (P.PresetRef), function (P.PresetFn), or an object (P.Preset).
The provided value did not match, therefore it was skipped.
`);
return {};
}
}
}