Some fixes

This commit is contained in:
Tom Coleman 2021-10-05 12:18:01 +11:00
parent 3eef669c4f
commit 9b8dab666c
2 changed files with 15 additions and 16 deletions

View File

@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import { toRequireContext } from '@storybook/core-common';
import { toRequireContext, StoriesEntry, normalizeStoriesEntry } from '@storybook/core-common';
import registerRequireContextHook from 'babel-plugin-require-context-hook/register';
import global from 'global';
import { AnyFramework, ArgsEnhancer, ArgTypesEnhancer, DecoratorFunction } from '@storybook/csf';
@ -52,15 +52,17 @@ function getConfigPathParts(input: string): Output {
if (main) {
const { stories = [] } = jest.requireActual(main);
output.stories = stories.map(
(pattern: string | { path: string; recursive: boolean; match: string }) => {
const { path: basePath, recursive, match } = toRequireContext(pattern);
const regex = new RegExp(match);
output.stories = stories.map((entry: StoriesEntry) => {
const specifier = normalizeStoriesEntry(entry, {
configDir,
workingDir: process.cwd(),
});
// eslint-disable-next-line no-underscore-dangle
return global.__requireContext(configDir, basePath, recursive, regex);
}
);
const { path: basePath, recursive, match } = toRequireContext(specifier);
// eslint-disable-next-line no-underscore-dangle
return global.__requireContext(configDir, basePath, recursive, match);
});
}
return output;

View File

@ -70,15 +70,12 @@ export async function buildStaticStandalone(options: CLIOptions & LoadOptions &
const features = await presets.apply<StorybookConfig['features']>('features');
if (features?.buildStoriesJson || features?.storyStoreV7) {
const stories = normalizeStories(await presets.apply('stories'), {
const directories = {
configDir: options.configDir,
workingDir: process.cwd(),
});
await extractStoriesJson(
path.join(options.outputDir, 'stories.json'),
stories,
options.configDir
);
};
const stories = normalizeStories(await presets.apply('stories'), directories);
await extractStoriesJson(path.join(options.outputDir, 'stories.json'), stories, directories);
}
const fullOptions: Options = {