diff --git a/code/lib/core-server/src/presets/common-preset.ts b/code/lib/core-server/src/presets/common-preset.ts index 347713e03aaf..39511aef6be4 100644 --- a/code/lib/core-server/src/presets/common-preset.ts +++ b/code/lib/core-server/src/presets/common-preset.ts @@ -17,7 +17,7 @@ import type { StorybookConfig, } from '@storybook/types'; import { printConfig, readConfig, readCsf } from '@storybook/csf-tools'; -import { join } from 'path'; +import { join, isAbsolute } from 'path'; import { dedent } from 'ts-dedent'; import fetch from 'node-fetch'; import type { Channel } from '@storybook/channels'; @@ -61,15 +61,16 @@ export const favicon = async ( const lists = await Promise.all( statics.map(async (dir) => { const results = []; - const relativeDir = staticDirsValue - ? getDirectoryFromWorkingDir({ - configDir: options.configDir, - workingDir: process.cwd(), - directory: dir, - }) - : dir; - - const { staticPath, targetEndpoint } = await parseStaticDir(relativeDir); + const normalizedDir = + staticDirsValue && !isAbsolute(dir) + ? getDirectoryFromWorkingDir({ + configDir: options.configDir, + workingDir: process.cwd(), + directory: dir, + }) + : dir; + + const { staticPath, targetEndpoint } = await parseStaticDir(normalizedDir); if (targetEndpoint === '/') { const url = 'favicon.svg'; diff --git a/code/lib/core-server/src/utils/server-statics.ts b/code/lib/core-server/src/utils/server-statics.ts index 19d569cfcc06..ca0f8c55e354 100644 --- a/code/lib/core-server/src/utils/server-statics.ts +++ b/code/lib/core-server/src/utils/server-statics.ts @@ -6,7 +6,7 @@ import chalk from 'chalk'; import type { Router } from 'express'; import express from 'express'; import { pathExists } from 'fs-extra'; -import path, { basename } from 'path'; +import path, { basename, isAbsolute } from 'path'; import isEqual from 'lodash/isEqual.js'; import { dedent } from 'ts-dedent'; @@ -30,14 +30,15 @@ export async function useStatics(router: Router, options: Options) { await Promise.all( statics.map(async (dir) => { try { - const relativeDir = staticDirs - ? getDirectoryFromWorkingDir({ - configDir: options.configDir, - workingDir: process.cwd(), - directory: dir, - }) - : dir; - const { staticDir, staticPath, targetEndpoint } = await parseStaticDir(relativeDir); + const normalizedDir = + staticDirs && !isAbsolute(dir) + ? getDirectoryFromWorkingDir({ + configDir: options.configDir, + workingDir: process.cwd(), + directory: dir, + }) + : dir; + const { staticDir, staticPath, targetEndpoint } = await parseStaticDir(normalizedDir); // Don't log for the internal static dir if (!targetEndpoint.startsWith('/sb-')) {