Skip to content

Commit

Permalink
Fix pnp support when cache dir is outside working dir
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Oct 25, 2023
1 parent 3e098fd commit 2509a69
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
21 changes: 11 additions & 10 deletions code/lib/core-server/src/presets/common-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down
19 changes: 10 additions & 9 deletions code/lib/core-server/src/utils/server-statics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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-')) {
Expand Down

0 comments on commit 2509a69

Please sign in to comment.