1- import { relative , resolve } from 'node:path ' ;
1+ import { join , relative } from 'pathe ' ;
22
33import { logger } from 'storybook/internal/node-logger' ;
44import type {
@@ -41,23 +41,14 @@ function getStoryIdsByAbsolutePath(
4141 workingDir : string
4242) : Map < string , Set < string > > {
4343 const storyIdsByFile = new Map < string , Set < string > > ( ) ;
44- const addStoryId = ( filePath : string , storyId : string ) => {
45- const storyIds = storyIdsByFile . get ( filePath ) ?? new Set < string > ( ) ;
46- storyIds . add ( storyId ) ;
47- storyIdsByFile . set ( filePath , storyIds ) ;
48- } ;
49-
5044 Object . values ( storyIndex . entries ) . forEach ( ( entry ) => {
51- if ( entry . type !== 'story' || entry . importPath . startsWith ( 'virtual:' ) ) {
52- return ;
45+ if ( entry . type === 'story' && ! entry . importPath . startsWith ( 'virtual:' ) ) {
46+ const filePath = join ( workingDir , entry . importPath ) ;
47+ const storyIds = storyIdsByFile . get ( filePath ) ?? new Set < string > ( ) ;
48+ storyIds . add ( entry . id ) ;
49+ storyIdsByFile . set ( filePath , storyIds ) ;
5350 }
54-
55- const absolutePath = resolve ( workingDir , entry . importPath ) ;
56- const normalizedAbsolutePath = normalizePath ( absolutePath ) ;
57- addStoryId ( absolutePath , entry . id ) ;
58- addStoryId ( normalizedAbsolutePath , entry . id ) ;
5951 } ) ;
60-
6152 return storyIdsByFile ;
6253}
6354
@@ -80,11 +71,6 @@ function mergeStatusValues(
8071 return nextValue ;
8172}
8273
83- function toRepoRelativePath ( repoRoot : string , filePath : string ) : string {
84- const relativePath = relative ( repoRoot , filePath ) ;
85- return relativePath . startsWith ( '\\\\?\\' ) ? relativePath : relativePath . replace ( / \\ / g, '/' ) ;
86- }
87-
8874/**
8975 * Coordinates change detection by listening to builder module-graph updates, resolving changed
9076 * files from git, mapping those changes to affected stories, and publishing the resulting story
@@ -255,12 +241,8 @@ export class ChangeDetectionService {
255241 this . options . storyIndexGeneratorPromise ,
256242 ] ) ;
257243
258- const changedFiles = new Set (
259- Array . from ( changes . changed ) . map ( ( filePath ) => normalizePath ( resolve ( repoRoot , filePath ) ) )
260- ) ;
261- const newFiles = new Set (
262- Array . from ( changes . new ) . map ( ( filePath ) => normalizePath ( resolve ( repoRoot , filePath ) ) )
263- ) ;
244+ const changedFiles = new Set ( Array . from ( changes . changed ) . map ( ( path ) => join ( repoRoot , path ) ) ) ;
245+ const newFiles = new Set ( Array . from ( changes . new ) . map ( ( path ) => join ( repoRoot , path ) ) ) ;
264246 const scannedFiles = new Set ( [ ...changedFiles , ...newFiles ] ) ;
265247 const normalizedModuleGraph = new Map < string , Set < ModuleNode > > ( ) ;
266248 moduleGraph . forEach ( ( nodes , filePath ) => {
@@ -302,7 +284,7 @@ export class ChangeDetectionService {
302284 storyIds . forEach ( ( storyId ) => {
303285 const existingStatus = statuses . get ( storyId ) ;
304286 const changedStoryFiles = new Set < string > ( existingStatus ?. data ?. changedFiles ?? [ ] ) ;
305- changedStoryFiles . add ( toRepoRelativePath ( repoRoot , changedFile ) ) ;
287+ changedStoryFiles . add ( relative ( repoRoot , changedFile ) ) ;
306288
307289 statuses . set ( storyId , {
308290 storyId,
0 commit comments