Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usedImages May be Empty When Using Windows #9

Open
jeremy-harnois opened this issue Dec 4, 2020 · 9 comments
Open

usedImages May be Empty When Using Windows #9

jeremy-harnois opened this issue Dec 4, 2020 · 9 comments

Comments

@jeremy-harnois
Copy link

The use of '/' with _().split() doesn't always split file paths properly on Windows. This results in usedImages being empty and all images being deleted. I believe using path.sep would be better.

@PostmanZero
Copy link

Hey, do you have any solution for that?

@rickysullivan
Copy link
Owner

I'll take a look soon. Haven't used this package (or gulp) in a number of years.

@PostmanZero
Copy link

Thank you, I'm looking forward to it!

@PostmanZero
Copy link

So I can replace '/' with path.sep and the deletion of files will work on Widows?
return _.includes(usedImageNames, _(path).split('/').last());

@jeremy-harnois
Copy link
Author

I ultimately didn't use this plugin because I also ran in to #10, so I don't have a working project using path.sep to confirm. But IIRC—and there's only one split()—yes, that's the change.

@rickysullivan
Copy link
Owner

I haven't had the time to spin up a new project. I tried adding some basic unit tests to the repo. But I have no idea how to test gulp. The idea was to use the tests to assert these use cases and to modify the source against the tests.

@PostmanZero
Copy link

PostmanZero commented Mar 4, 2022

Cramp replacement
return _.includes(usedImageNames, _(path).split('/').last());
on
return _.includes(usedImageNames, _(path).split(path.sep).last());
still delete all images. I don't know what else to do and need this removal mechanism. :/

@PostmanZero
Copy link

Okay, looks like it works like this on Windows:
return _.includes(usedImageNames, _(path).split('/').last());
on
return _.includes(usedImageNames, _(path).split('\\' || '/').last());
Can anyone confirm that it will also work on macOS?

@jeremy-harnois
Copy link
Author

/ should work across platforms. I wonder if lodash is messing with things somehow.

still delete all images

My reference to path.sep is a link to Node's path API. In this particular instance, there's already a path variable from the enclosing function's arguments, so you can't just use path.sep without some additional work like require()ing that API.

Can anyone confirm that it will also work on macOS?

It's unlikely since '\\' || '/' will always return '\\' because it's not falsey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants