wclr / yalc

Work with yarn/npm packages locally like a boss.
MIT License
5.52k stars 146 forks source link

`yalc add` on Mac can (rarely) fail with ENOTDIR invalid cwd, treating .DS_Store as a version directory. #203

Open AlanSl opened 1 year ago

AlanSl commented 1 year ago

I saw this for the first time today on running yalc add on several packages in a new repo (MacOS 11.6.8). All the packages worked except one, which gave this error:

Error: ENOTDIR invalid cwd /Users/alan/.yalc/packages/{package_name}/.DS_Store at Glob._readdirError (/Users/alan/.npm/_npx/8971ede65c5d814d/node_modules/glob/glob.js:589:21) at /Users/alan/.npm/_npx/8971ede65c5d814d/node_modules/glob/glob.js:550:12 at FSReqCallback.oncomplete (node:fs:188:23) { path: '/Users/alan/.yalc/packages/{package_name}/.DS_Store', code: 'ENOTDIR' }

Deleting the Mac OS generated .DS_Store file in the Yalc package directory (the one that contains all the yalc-published versions) fixed this.

It's strange because:

AlanSl commented 1 year ago

I think I've figured it out - I can replicate it by causing a yalc package directory to have a .DS_Store file with a creation date more recent than any of the version directories.

Example replication steps (on a Mac):

So it looks like the problem is, the function yalc add uses to find the latest version is just taking all the contents of the directory, getting the most recent, and assuming it's a version directory. 99% of the time this works fine, but if for whatever reason some system file like .DS_Store comes to be the most recent item in the directory, this crash happens.

Suggested fix: filter the array of directory contents to be only directories before finding the newest and cding into it.

yevgeniy-belov commented 1 year ago

@AlanSl Did you find a workaround for this issue?

AlanSl commented 1 year ago

Not really. It might be possible to work around by forcing the version folders to have a more recent created date than .DS_Store, e.g. by deleting the published versions then yalc publish again?

yevgeniy-belov commented 1 year ago

Not really. It might be possible to work around by forcing the version folders to have a more recent created date than .DS_Store, e.g. by deleting the published versions then yalc publish again?

Yeah, it might work but it feels like it's going to be cumbersome and unstable... Im wondering if there is a fork addressing this.