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 9754815
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions packages/builder-vite/codegen-iframe-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,43 @@ 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)
try {
// these were added in 6.5, but we support 6.4 as well.
var {addArgs, addArgTypes} = await import('@storybook/client-api');
} catch (err) {
// ignore error
}
configs.forEach(config => {
Object.keys(config).forEach(async (key) => {
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 9754815

Please sign in to comment.