Skip to content
This repository has been archived by the owner on May 1, 2022. It is now read-only.

fix(windows): normalize incoming paths to getDestPath #57

Merged

Conversation

moitias
Copy link
Contributor

@moitias moitias commented Feb 29, 2020

Which issue does this fix?

Closes #46

Describe the solution

Originally, the path separator/resolution issue was fixed in the watch mode but I missed that the fix indeed caused a regression on Windows during the initial build - my bad!

The regression was due to the glob package returning paths with forward slashes regardless of the platform (as documented), causing the initial build to fail on Windows and crashing when the build ended up in the wrong place (src/). Previously, this step would have worked as forward slashes were getting replaced correctly but backslashes returned through watch were not.

This solution uses Node standard library path.normalize to normalize the input paths to getDestPath, in order to always have the OS-specific path to do the regexp magic with.

I guess in the future, using the path package might open up a door to get rid of the regexp altogether and making the path generation more resilient?

This is due to the glob package returning paths with forward slashes regardless of the platform (see https://github.com/isaacs/node-glob#windows), causing the initial build to fail on Windows.
Copy link
Owner

@jacobdeichert jacobdeichert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moitias thanks so much for the fix! :)

@jacobdeichert jacobdeichert merged commit 303d810 into jacobdeichert:master Feb 29, 2020
@moitias
Copy link
Contributor Author

moitias commented Mar 1, 2020

No, thank you for svelvet - I had more fun coding over the weekend than I've had in a long time and most of it was down to the pretty smooth experience provided by svelvet, even at such an early stage!

@jacobdeichert
Copy link
Owner

Really glad to hear it's been working well for you!

@bernardoadc
Copy link

@moitias, i think path package wouldn't help eliminate regexp, since to change from src to dist you would have to split the string and rejoin again.

let p = srcPath.split(path.sep)
p[0] = 'dist'
return path.join(...p)

I don't think the [performance] (https://jsperf.com/split-join-vs-regex-replace) makes it worth it

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

Successfully merging this pull request may close these issues.

ENOENT import-map.json
3 participants