chromaui/chromatic-cli

Windows: Path normalisation for changedFiles/base path (TurboSnap)

Opened this issue · 0 comments

Bug report

I faced the issue that the TurboSnap functionality is not detecting changed stories on windows while it works on Mac. I traced the issue and detected following bugs:

  • When using the "trace" utility the path of changedFiles are not converted to posix, so providing paths with backslashes will not detect changed stories.
  • When using the "upload" utility with --only-changed the base dir is different between Mac and Windows, causing issue on Windows.

You can try it out by running node inside your repository and execute

Mac:

path = require('path');
path.posix.relative("/<your path to repository>", '') // prints ''

Windows:

path = require('path');
path.posix.relative("C:/<your path to repository>", '') // prints '../../../' << ../ depending on depth of repository

but without the hard drive letter it works fine

path = require('path');
path.posix.relative("<your path to repository>", '') // prints '' 

Tracing this to the root issue:

  • The base dir is defined in line 78 (current main) in getDependentStoryFiles.ts
    const baseDir = storybookBaseDir ? posix(storybookBaseDir) : path.posix.relative(rootPath, '');
    and this base dir behaves differently between Windows and Mac. The reason for this is that rootPath on Windows contains the hard drive letter (causing exactly the wrong relative path) as this path is not treated as an absolute path in posix due to not starting with '/'.
  • The root cause for having the hard driver letter included is related to line 77, a call to getRepositoryRoot which assumes to always have returned an absolute "posix" path, however the command git rev-parse --show-toplevel returns a posix path but with hard disk drive letter, which causes the issue.

Not sure whether there is other code as well that is affected by a similar issue.

Workaround:
Provide a relative --storybook-base-dir path (e.g., just "./") so that it works also on Windows