mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-05 06:01:22 +08:00
Use serverRequire to load config file
This commit is contained in:
parent
d74511418d
commit
59ebee29f7
@ -1,4 +1,4 @@
|
||||
import { checkAddonOrder } from '@storybook/core-common';
|
||||
import { checkAddonOrder, serverRequire } from '@storybook/core-common';
|
||||
import path from 'path';
|
||||
|
||||
export const checkDocsLoaded = (configDir: string) => {
|
||||
@ -14,6 +14,6 @@ export const checkDocsLoaded = (configDir: string) => {
|
||||
configFile: path.isAbsolute(configDir)
|
||||
? path.join(configDir, 'main')
|
||||
: path.join(process.cwd(), configDir, 'main'),
|
||||
getConfig: (configFile) => import(configFile),
|
||||
getConfig: (configFile) => serverRequire(configFile),
|
||||
});
|
||||
};
|
||||
|
@ -49,6 +49,7 @@
|
||||
"@storybook/addon-viewport": "6.5.0-alpha.41",
|
||||
"@storybook/addons": "6.5.0-alpha.41",
|
||||
"@storybook/api": "6.5.0-alpha.41",
|
||||
"@storybook/core-common": "6.5.0-alpha.41",
|
||||
"@storybook/node-logger": "6.5.0-alpha.41",
|
||||
"core-js": "^3.8.2",
|
||||
"regenerator-runtime": "^0.13.7",
|
||||
|
@ -1,5 +1,6 @@
|
||||
import path, { join } from 'path';
|
||||
import { logger } from '@storybook/node-logger';
|
||||
import { serverRequire } from '@storybook/core-common';
|
||||
|
||||
interface PresetOptions {
|
||||
configDir?: string;
|
||||
@ -9,25 +10,12 @@ interface PresetOptions {
|
||||
}
|
||||
|
||||
const requireMain = (configDir: string) => {
|
||||
let main = {};
|
||||
const absoluteConfigDir = path.isAbsolute(configDir)
|
||||
? configDir
|
||||
: path.join(process.cwd(), configDir);
|
||||
const mainFile = path.join(absoluteConfigDir, 'main');
|
||||
try {
|
||||
// eslint-disable-next-line global-require,import/no-dynamic-require
|
||||
main = require(mainFile);
|
||||
} catch (err) {
|
||||
try {
|
||||
// Try finding a .cjs version of the main file
|
||||
const mainFileCjs = path.join(absoluteConfigDir, 'main.cjs');
|
||||
// eslint-disable-next-line global-require,import/no-dynamic-require
|
||||
main = require(mainFileCjs);
|
||||
} catch (cjsErr) {
|
||||
logger.warn(`Unable to find main.js or main.cjs: ${mainFile}`);
|
||||
}
|
||||
}
|
||||
return main;
|
||||
|
||||
return serverRequire(mainFile) ?? {};
|
||||
};
|
||||
|
||||
export function addons(options: PresetOptions = {}) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { checkAddonOrder } from '@storybook/core-common';
|
||||
import { checkAddonOrder, serverRequire } from '@storybook/core-common';
|
||||
import path from 'path';
|
||||
|
||||
export const checkActionsLoaded = (configDir: string) => {
|
||||
@ -14,6 +14,6 @@ export const checkActionsLoaded = (configDir: string) => {
|
||||
configFile: path.isAbsolute(configDir)
|
||||
? path.join(configDir, 'main')
|
||||
: path.join(process.cwd(), configDir, 'main'),
|
||||
getConfig: (configFile) => import(configFile),
|
||||
getConfig: (configFile) => serverRequire(configFile),
|
||||
});
|
||||
};
|
||||
|
@ -6527,6 +6527,7 @@ __metadata:
|
||||
"@storybook/addon-viewport": 6.5.0-alpha.41
|
||||
"@storybook/addons": 6.5.0-alpha.41
|
||||
"@storybook/api": 6.5.0-alpha.41
|
||||
"@storybook/core-common": 6.5.0-alpha.41
|
||||
"@storybook/node-logger": 6.5.0-alpha.41
|
||||
"@storybook/vue": 6.5.0-alpha.41
|
||||
"@types/jest": ^26.0.16
|
||||
|
Loading…
x
Reference in New Issue
Block a user