From afaf141041ba2fced5a7a4e6c594389d26508634 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Thu, 3 Nov 2022 16:18:45 -0400 Subject: [PATCH] Adjust builder-vite ssv6 --- code/lib/builder-vite/src/codegen-iframe-script.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/code/lib/builder-vite/src/codegen-iframe-script.ts b/code/lib/builder-vite/src/codegen-iframe-script.ts index 90b1315d06e..04e29c1a07f 100644 --- a/code/lib/builder-vite/src/codegen-iframe-script.ts +++ b/code/lib/builder-vite/src/codegen-iframe-script.ts @@ -1,9 +1,16 @@ import { isAbsolute, resolve } from 'path'; import { getRendererName } from '@storybook/core-common'; import { virtualPreviewFile, virtualStoriesFile } from './virtual-file-names'; -import { transformAbsPath } from './utils/transform-abs-path'; import type { ExtendedOptions } from './types'; +function resolveRelativePath(path: string) { + // resolve relative paths into absolute paths, but don't resolve "bare" imports + if (path?.startsWith('./') || path?.startsWith('../')) { + return resolve(path); + } + return path; +} + export async function generateIframeScriptCode(options: ExtendedOptions) { const { presets } = options; const rendererName = await getRendererName(options); @@ -15,7 +22,7 @@ export async function generateIframeScriptCode(options: ExtendedOptions) { const absoluteFilesToImport = (files: string[], name: string) => files - .map((el, i) => `import ${name ? `* as ${name}_${i} from ` : ''}'${transformAbsPath(el)}'`) + .map((el, i) => `import ${name ? `* as ${name}_${i} from ` : ''}'${resolveRelativePath(el)}'`) .join('\n'); const importArray = (name: string, length: number) =>