Skip to content

Commit

Permalink
No longer handle previewEntries in the vite builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Sep 9, 2022
1 parent 9823ef0 commit 1335697
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
7 changes: 3 additions & 4 deletions code/lib/builder-vite/src/codegen-iframe-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import type { ExtendedOptions } from './types';
export async function generateIframeScriptCode(options: ExtendedOptions) {
const { presets } = options;
const frameworkName = await getFrameworkName(options);
const presetEntries = await presets.apply('config', [], options);
const previewEntries = await presets.apply('previewEntries', [], options);
const absolutePreviewEntries = previewEntries.map((entry) =>
const configField = await presets.apply('config', [], options);
const absoluteConfigField = configField.map((entry) =>
isAbsolute(entry) ? entry : resolve(entry)
);
const configEntries = [...presetEntries, ...absolutePreviewEntries].filter(Boolean);
const configEntries = [...absoluteConfigField].filter(Boolean);

const absoluteFilesToImport = (files: string[], name: string) =>
files
Expand Down
7 changes: 3 additions & 4 deletions code/lib/builder-vite/src/codegen-modern-iframe-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ export async function generateModernIframeScriptCode(options: ExtendedOptions) {
const frameworkName = await getFrameworkName(options);

const previewOrConfigFile = loadPreviewOrConfigFile({ configDir });
const presetEntries = await presets.apply('config', [], options);
const previewEntries = await presets.apply('previewEntries', [], options);
const absolutePreviewEntries = [...presetEntries, ...previewEntries].map((entry) =>
const configField = await presets.apply('config', [], options);
const absoluteConfigField = [...configField].map((entry) =>
isAbsolute(entry) ? entry : resolve(entry)
);
const configEntries = [...absolutePreviewEntries, previewOrConfigFile]
const configEntries = [...absoluteConfigField, previewOrConfigFile]
.filter(Boolean)
.map((configEntry) => transformAbsPath(configEntry as string));

Expand Down
15 changes: 8 additions & 7 deletions scripts/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import prompts from 'prompts';
import type { AbortController } from 'node-abort-controller';
import command from 'execa';
import dedent from 'ts-dedent';

import { createOptions, getOptionsOrPrompt, OptionValues } from './utils/options';
import { executeCLIStep } from './utils/cli-step';
Expand All @@ -23,7 +24,6 @@ import { ConfigFile, readConfig, writeConfig } from '../code/lib/csf-tools';
import { babelParse } from '../code/lib/csf-tools/src/babelParse';
import TEMPLATES from '../code/lib/cli/src/repro-templates';
import { servePackages } from './utils/serve-packages';
import dedent from 'ts-dedent';

type Template = keyof typeof TEMPLATES;
const templates: Template[] = Object.keys(TEMPLATES) as any;
Expand Down Expand Up @@ -255,6 +255,11 @@ function forceViteRebuilds(mainConfig: ConfigFile) {
);
}

function addConfigEntries(mainConfig: ConfigFile, paths: string[]) {
const config = mainConfig.getFieldValue(['config']) as string[];
mainConfig.setFieldValue(['config'], [...(config || []), ...paths]);
}

// paths are of the form 'renderers/react', 'addons/actions'
async function addStories(paths: string[], { mainConfig }: { mainConfig: ConfigFile }) {
// Add `stories` entries of the form
Expand Down Expand Up @@ -289,11 +294,10 @@ async function addStories(paths: string[], { mainConfig }: { mainConfig: ConfigF
)
);

const config = mainConfig.getFieldValue(['config']) as string[];
const extraConfig = extraPreviewAndExistence
.filter(([, exists]) => exists)
.map(([p]) => path.join('..', '..', 'code', p));
mainConfig.setFieldValue(['config'], [...(config || []), ...extraConfig]);
addConfigEntries(mainConfig, extraConfig);
}

type Workspace = { name: string; location: string };
Expand Down Expand Up @@ -379,10 +383,7 @@ export async function sandbox(optionValues: OptionValues<typeof options>) {
path.join(codeDir, rendererPath, 'template', 'components'),
path.resolve(cwd, storiesPath, 'components')
);
mainConfig.setFieldValue(
['previewEntries'],
[`.${path.sep}${path.join(storiesPath, 'components')}`]
);
addConfigEntries(mainConfig, [`.${path.sep}${path.join(storiesPath, 'components')}`]);

// Link in the stories from the store, the renderer and the addons
const storiesToAdd = [] as string[];
Expand Down

0 comments on commit 1335697

Please sign in to comment.