mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-28 05:10:17 +08:00
detect user's react version
This commit is contained in:
parent
271fb46d48
commit
434223de42
@ -1,3 +1,4 @@
|
|||||||
|
import path from 'path';
|
||||||
import { TransformOptions } from '@babel/core';
|
import { TransformOptions } from '@babel/core';
|
||||||
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
|
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
|
||||||
import type { Configuration } from 'webpack';
|
import type { Configuration } from 'webpack';
|
||||||
@ -21,12 +22,17 @@ export async function babel(config: TransformOptions, options: StorybookOptions)
|
|||||||
plugins: [require.resolve('react-refresh/babel'), ...(config.plugins || [])],
|
plugins: [require.resolve('react-refresh/babel'), ...(config.plugins || [])],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
const storybookReactDirName = path.dirname(require.resolve('@storybook/react/package.json'));
|
||||||
|
// TODO: improve node_modules detection
|
||||||
|
const context = storybookReactDirName.includes('node_modules')
|
||||||
|
? path.join(storybookReactDirName, '../../') // Real life case, already in node_modules
|
||||||
|
: path.join(storybookReactDirName, '../../node_modules'); // SB Monorepo
|
||||||
|
|
||||||
export async function babelDefault(config: TransformOptions) {
|
export async function babelDefault(config: TransformOptions) {
|
||||||
let reactVersion;
|
let reactVersion;
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line global-require,import/no-dynamic-require
|
// eslint-disable-next-line global-require,import/no-dynamic-require
|
||||||
const reactPkg = require(require.resolve('react/package.json'));
|
const reactPkg = require(require.resolve('react/package.json', { paths: [context] }));
|
||||||
reactVersion = reactPkg.version;
|
reactVersion = reactPkg.version;
|
||||||
} catch {
|
} catch {
|
||||||
logger.warn('Unable to determine react version');
|
logger.warn('Unable to determine react version');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user