Fix csf-plugin to load "pre" & async for perf

This commit is contained in:
Michael Shilman 2022-10-31 23:58:41 +08:00
parent 6bbe7f3cd8
commit d0cddf51d3

View File

@ -1,5 +1,5 @@
import { createUnplugin } from 'unplugin';
import fs from 'fs';
import fs from 'fs/promises';
import { loadCsf, enrichCsf, formatCsf } from '@storybook/csf-tools';
export interface CsfPluginOptions {
@ -14,11 +14,12 @@ const logger = console;
export const unplugin = createUnplugin<CsfPluginOptions>((options) => {
return {
name: 'unplugin-csf',
enforce: 'pre',
loadInclude(id) {
return STORIES_REGEX.test(id);
},
load(fname) {
const code = fs.readFileSync(fname, 'utf-8');
async load(fname) {
const code = await fs.readFile(fname, 'utf-8');
try {
const csf = loadCsf(code, { makeTitle: (userTitle) => userTitle || 'default' }).parse();
enrichCsf(csf);