Skip to content

Commit

Permalink
Avoid top-level await
Browse files Browse the repository at this point in the history
  • Loading branch information
IanVS committed Jun 22, 2022
1 parent fca14d2 commit 7d828e3
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions packages/builder-vite/codegen-iframe-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ export async function generateIframeScriptCode(options: ExtendedOptions) {
// is loaded. That way our client-apis can assume the existence of the API+store
import { configure } from '${frameworkImportPath}';
import {
import * as clientApi from "@storybook/client-api";
import { logger } from '@storybook/client-logger';
${absoluteFilesToImport(configEntries, 'config')}
import * as preview from '${virtualPreviewFile}';
import { configStories } from '${virtualStoriesFile}';
const {
addDecorator,
addParameters,
addLoader,
addArgTypesEnhancer,
addArgsEnhancer,
setGlobalRender
} from '@storybook/client-api';
import { logger } from '@storybook/client-logger';
${absoluteFilesToImport(configEntries, 'config')}
import * as preview from '${virtualPreviewFile}';
import { configStories } from '${virtualStoriesFile}';
setGlobalRender,
} = clientApi;
const configs = [${importArray('config', configEntries.length).concat('preview.default').join(',')}].filter(Boolean)
Expand All @@ -49,17 +51,21 @@ export async function generateIframeScriptCode(options: ExtendedOptions) {
const value = config[key];
switch (key) {
case 'args': {
if (typeof addArgs !== 'undefined') {
return addArgs(value);
if (typeof clientApi.addArgs !== "undefined") {
return clientApi.addArgs(value);
} else {
return logger.warn('Could not add global args. Please open an issue in storybookjs/builder-vite.');
return logger.warn(
"Could not add global args. Please open an issue in storybookjs/builder-vite."
);
}
}
case 'argTypes': {
if (typeof addArgTypes !== 'undefined') {
return addArgTypes(value);
if (typeof clientApi.addArgTypes !== "undefined") {
return clientApi.addArgTypes(value);
} else {
return logger.warn('Could not add global argTypes. Please open an issue in storybookjs/builder-vite.');
return logger.warn(
"Could not add global argTypes. Please open an issue in storybookjs/builder-vite."
);
}
}
case 'decorators': {
Expand Down

0 comments on commit 7d828e3

Please sign in to comment.