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

fix: correct path on Windows to create and delete typegen file #41

Merged

Conversation

batnyu
Copy link

@batnyu batnyu commented Jan 28, 2022

Hello Matt,

Thanks for your work on XState, it's amazing and inspiring!

On Windows, the typegen file is not generated. I followed the lead you wrote in the issue #40.
I fixed the issue on Windows. Unfortunately, I don't have a Mac, so I was unable to test on macOs. But maybe, it can help you.

I used vscode.Uri.parse to extract the path from the URI. But the result is prefixed with a slash that caused fs.writeFile to prefix the path with "C:". So I removed this slash with slice(1) and it works! (at least on Windows).

Thanks!


const newUri = vscode.Uri.file(
uri.replace(/\.([j,t])sx?$/, ".typegen.ts"),
const pathFromUri = vscode.Uri.parse(uri, true).path.slice(1);
Copy link
Member

Choose a reason for hiding this comment

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

Could you tell us how does your uri exactly looks like? this could help us reviewing this change and comparing with unix-style paths

Copy link
Author

Choose a reason for hiding this comment

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

You can see the different variables in this image :

image

Copy link
Author

Choose a reason for hiding this comment

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

When I remove the slice(1) from line 52, it throws an error when trying to write the file. C: is added somehow.

image

Copy link
Author

Choose a reason for hiding this comment

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

I tried my changes on a debian OS. It didn't work because I was removing the leading slash. I added a check to remove the leading slash only on Windows. I don't know if there is a cleaner way to handle this but now it works for both Windows and Unix

@mattpocock
Copy link
Contributor

mattpocock commented Jan 31, 2022

@batnyu Tested this locally on Mac OS, and it works! Since this is a critical fix for Windows, let's merge it and test on Unix later.

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

Successfully merging this pull request may close these issues.

3 participants