mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-05 06:41:17 +08:00
Log error in index
This commit is contained in:
parent
1b99fc225d
commit
978a0f53b6
@ -103,6 +103,9 @@ export class StoryIndexGenerator {
|
||||
// - the preview changes [not yet implemented]
|
||||
private lastIndex?: StoryIndex;
|
||||
|
||||
// Same as the above but for the error case
|
||||
private lastError?: Error;
|
||||
|
||||
constructor(
|
||||
public readonly specifiers: NormalizedStoriesSpecifier[],
|
||||
public readonly options: {
|
||||
@ -487,48 +490,56 @@ export class StoryIndexGenerator {
|
||||
|
||||
async getIndex() {
|
||||
if (this.lastIndex) return this.lastIndex;
|
||||
if (this.lastError) throw this.lastError;
|
||||
|
||||
// Extract any entries that are currently missing
|
||||
// Pull out each file's stories into a list of stories, to be composed and sorted
|
||||
const storiesList = await this.ensureExtracted();
|
||||
|
||||
const firstError = storiesList.find((entry) => entry.type === 'error');
|
||||
if (firstError) throw (firstError as ErrorEntry).err;
|
||||
try {
|
||||
const firstError = storiesList.find((entry) => entry.type === 'error');
|
||||
if (firstError) throw (firstError as ErrorEntry).err;
|
||||
|
||||
const sorted = await this.sortStories(storiesList as IndexEntry[]);
|
||||
const sorted = await this.sortStories(storiesList as IndexEntry[]);
|
||||
|
||||
let compat = sorted;
|
||||
if (this.options.storiesV2Compatibility) {
|
||||
const titleToStoryCount = Object.values(sorted).reduce((acc, story) => {
|
||||
acc[story.title] = (acc[story.title] || 0) + 1;
|
||||
return acc;
|
||||
}, {} as Record<ComponentTitle, number>);
|
||||
let compat = sorted;
|
||||
if (this.options.storiesV2Compatibility) {
|
||||
const titleToStoryCount = Object.values(sorted).reduce((acc, story) => {
|
||||
acc[story.title] = (acc[story.title] || 0) + 1;
|
||||
return acc;
|
||||
}, {} as Record<ComponentTitle, number>);
|
||||
|
||||
// @ts-expect-error (Converted from ts-ignore)
|
||||
compat = Object.entries(sorted).reduce((acc, entry) => {
|
||||
const [id, story] = entry;
|
||||
if (story.type === 'docs') return acc;
|
||||
// @ts-expect-error (Converted from ts-ignore)
|
||||
compat = Object.entries(sorted).reduce((acc, entry) => {
|
||||
const [id, story] = entry;
|
||||
if (story.type === 'docs') return acc;
|
||||
|
||||
acc[id] = {
|
||||
...story,
|
||||
kind: story.title,
|
||||
story: story.name,
|
||||
parameters: {
|
||||
__id: story.id,
|
||||
docsOnly: titleToStoryCount[story.title] === 1 && story.name === 'Page',
|
||||
fileName: story.importPath,
|
||||
},
|
||||
};
|
||||
return acc;
|
||||
}, {} as Record<StoryId, V2CompatIndexEntry>);
|
||||
acc[id] = {
|
||||
...story,
|
||||
kind: story.title,
|
||||
story: story.name,
|
||||
parameters: {
|
||||
__id: story.id,
|
||||
docsOnly: titleToStoryCount[story.title] === 1 && story.name === 'Page',
|
||||
fileName: story.importPath,
|
||||
},
|
||||
};
|
||||
return acc;
|
||||
}, {} as Record<StoryId, V2CompatIndexEntry>);
|
||||
}
|
||||
|
||||
this.lastIndex = {
|
||||
v: 4,
|
||||
entries: compat,
|
||||
};
|
||||
|
||||
return this.lastIndex;
|
||||
} catch (err) {
|
||||
this.lastError = err;
|
||||
logger.warn(`🚨 Couldn't fetch index`);
|
||||
logger.warn(this.lastError.stack);
|
||||
throw this.lastError;
|
||||
}
|
||||
|
||||
this.lastIndex = {
|
||||
v: 4,
|
||||
entries: compat,
|
||||
};
|
||||
|
||||
return this.lastIndex;
|
||||
}
|
||||
|
||||
invalidate(specifier: NormalizedStoriesSpecifier, importPath: Path, removed: boolean) {
|
||||
@ -567,6 +578,7 @@ export class StoryIndexGenerator {
|
||||
cache[absolutePath] = false;
|
||||
}
|
||||
this.lastIndex = null;
|
||||
this.lastError = null;
|
||||
}
|
||||
|
||||
async getStorySortParameter() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user