Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set other manager-side constants in build #18728

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lib/builder-manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ const starter: StarterFunction = async function* starterGeneratorFn({

yield;

const html = await renderHTML(template, title, customHead, addonFiles, features, refs, logLevel);
const html = await renderHTML(
template,
title,
customHead,
addonFiles,
features,
refs,
logLevel,
options
);

yield;

Expand Down Expand Up @@ -162,7 +171,16 @@ const builder: BuilderFunction = async function* builderGeneratorFn({ startTime,
const managerFiles = copy(coreDirOrigin, coreDirTarget);
const addonFiles = readDeep(addonsDir);

const html = await renderHTML(template, title, customHead, addonFiles, features, refs, logLevel);
const html = await renderHTML(
template,
title,
customHead,
addonFiles,
features,
refs,
logLevel,
options
);

yield;

Expand Down
11 changes: 9 additions & 2 deletions lib/builder-manager/src/utils/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { readFile, pathExists } from 'fs-extra';

import { render } from 'ejs';

import type { Ref } from '@storybook/core-common';
import type { Options, Ref } from '@storybook/core-common';

import { readDeep } from './directory';

Expand Down Expand Up @@ -55,7 +55,8 @@ export const renderHTML = async (
files: ReturnType<typeof readDeep>,
features: Promise<Record<string, any>>,
refs: Promise<Record<string, Ref>>,
logLevel: Promise<string>
logLevel: Promise<string>,
{ versionCheck, releaseNotesData, docsMode, previewUrl, serverChannelUrl }: Options
) => {
const customHeadRef = await customHead;
const titleRef = await title;
Expand All @@ -72,6 +73,12 @@ export const renderHTML = async (
FEATURES: JSON.stringify(await features, null, 2),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem to apply('features') and await it several times unnecessarily throughout the code base, as we already do this:

const features = await presets.apply<StorybookConfig['features']>('features');
global.FEATURES = features;
const fullOptions: Options = {
...options,
presets,
features,
};

The same may be true for logLevel and refs, I'm not sure. I don't pretend to understand this code well enough to say.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evaluating the preset value once, and passing down the value might increase perf by a tiny bit, but at the cost of complexity.

Apply-ing a preset multiple times, is the intended behavior. But what we should do, at some point, is to enable memoization on it, so calling it multiple times with the same options, gets cached.

REFS: JSON.stringify(await refs, null, 2),
LOGLEVEL: JSON.stringify(await logLevel, null, 2),
// These two need to be double stringified because the UI expects a string
VERSIONCHECK: JSON.stringify(JSON.stringify(versionCheck), null, 2),
RELEASE_NOTES_DATA: JSON.stringify(JSON.stringify(releaseNotesData), null, 2),
DOCS_MODE: JSON.stringify(docsMode, null, 2), // global docs mode
PREVIEW_URL: JSON.stringify(previewUrl, null, 2), // global preview URL
SERVER_CHANNEL_URL: JSON.stringify(serverChannelUrl, null, 2),
},
head: customHeadRef ? await readFile(customHeadRef, 'utf8') : '',
});
Expand Down