ADD option-property 'presets' so preset-properties can respond to other presets && FIX problem with cra-preset

This commit is contained in:
Norbert de Langen 2019-12-06 11:03:18 +01:00
parent 7c5858c7f7
commit 214100aaf7
2 changed files with 11 additions and 11 deletions

View File

@ -6,11 +6,8 @@ import { applyCRAWebpackConfig, getReactScriptsPath, isReactScriptsInstalled } f
type Preset = string | { name: string };
// Disable the built-in preset if the new preset is detected.
const checkForNewPreset = (configDir: string) => {
const checkForNewPreset = (presets: Preset[]) => {
try {
// eslint-disable-next-line global-require, import/no-dynamic-require
const presets = require(path.resolve(configDir, 'presets.js'));
const hasNewPreset = presets.some((preset: Preset) => {
const presetName = typeof preset === 'string' ? preset : preset.name;
return presetName === '@storybook/preset-create-react-app';
@ -27,8 +24,11 @@ const checkForNewPreset = (configDir: string) => {
}
};
export function webpackFinal(config: Configuration, { configDir }: { configDir: string }) {
if (checkForNewPreset(configDir)) {
export function webpackFinal(
config: Configuration,
{ presets, configDir }: { presets: Preset[]; configDir: string }
) {
if (checkForNewPreset(presets)) {
return config;
}
if (!isReactScriptsInstalled()) {
@ -40,8 +40,8 @@ export function webpackFinal(config: Configuration, { configDir }: { configDir:
return applyCRAWebpackConfig(config, configDir);
}
export function managerWebpack(config: Configuration, { configDir }: { configDir: string }) {
if (!isReactScriptsInstalled() || checkForNewPreset(configDir)) {
export function managerWebpack(config: Configuration, { presets }: { presets: Preset[] }) {
if (!isReactScriptsInstalled() || checkForNewPreset(presets)) {
return config;
}
@ -53,8 +53,8 @@ export function managerWebpack(config: Configuration, { configDir }: { configDir
};
}
export function babelDefault(config: Configuration, { configDir }: { configDir: string }) {
if (!isReactScriptsInstalled() || checkForNewPreset(configDir)) {
export function babelDefault(config: Configuration, { presets }: { presets: Preset[] }) {
if (!isReactScriptsInstalled() || checkForNewPreset(presets)) {
return config;
}

View File

@ -100,7 +100,7 @@ function applyPresets(presets, extension, config, args) {
const context = {
extensionFn,
preset,
combinedOptions: { ...args, ...options },
combinedOptions: { ...args, ...options, presets },
};
return accumulationPromise.then(newConfig =>