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 Windows Proxy bug #565

Merged
merged 1 commit into from
Jul 1, 2020
Merged

Fix Windows Proxy bug #565

merged 1 commit into from
Jul 1, 2020

Conversation

drwpow
Copy link
Collaborator

@drwpow drwpow commented Jul 1, 2020

Changes

Following this PR in create-snowpack-app that uncovered a bug where proxied resources had backslashes when built on Windows. This PR fixes that.

Testing

@drwpow drwpow requested a review from a team as a code owner July 1, 2020 18:36
@vercel
Copy link

vercel bot commented Jul 1, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/8pq4m8otf
✅ Preview: https://snowpack-git-drwpow-resource-test.pikapkg.vercel.app

@drwpow drwpow changed the title Add Preact build test Add test to fix resource proxy resolution Jul 1, 2020
@drwpow drwpow changed the title Add test to fix resource proxy resolution Fix Windows Proxy bug Jul 1, 2020
),
),
format(readFileSync(path.join(entry.path1, entry.name1), {encoding: 'utf8'})),
format(readFileSync(path.join(entry.path2, entry.name2), {encoding: 'utf8'})),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Opinionated test runner cleanup 🤷 Ran across this while making sure there wasn’t any Windows-specific fixes in the runner itself

@drwpow drwpow requested a review from FredKSchott July 1, 2020 19:08
@@ -368,7 +368,7 @@ export async function command(commandOptions: CommandOptions) {
for (const proxiedFileLoc of allProxiedFiles) {
const proxiedCode = await fs.readFile(proxiedFileLoc, {encoding: 'utf8'});
const proxiedExt = path.extname(proxiedFileLoc);
const proxiedUrl = proxiedFileLoc.substr(buildDirectoryLoc.length);
const proxiedUrl = proxiedFileLoc.substr(buildDirectoryLoc.length).replace(/\\/g, '/'); // replace backslashes on Windows
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the solution here… but how do we feel about it?

Copy link
Owner

Choose a reason for hiding this comment

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

+1! We do this in a couple of other places, I don't hate it.

There are npm packages for converting any file path to a valid URL. In a future PR, we should look into using one of those for everthing that we do.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to pull it into a util function if it's used in multiple places and would help self document with the function name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

+1 for this. Something to mark “this is an import meant for the browser so we definitely don’t need backslashes.” We could also theoretically do things like URL escaping, but hopefully we’ll never need that.

@drwpow drwpow merged commit 2999d64 into master Jul 1, 2020
@drwpow drwpow deleted the drwpow/resource-test branch July 1, 2020 19:18
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.

None yet

3 participants