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: check for http in baseUrl #993

Merged
merged 2 commits into from
Sep 7, 2020
Merged

fix: check for http in baseUrl #993

merged 2 commits into from
Sep 7, 2020

Conversation

stefanfrede
Copy link
Contributor

path.posix.join can't be used with URLs.

Changes

See #989.

Testing

I tested it locally and set-up a repl to replicate the problem:
https://repl.it/@stefanfrede/snowpack-webpack-jsdom#index.js

`path.posix.join` can't be used with URLs.
@stefanfrede stefanfrede requested a review from a team as a code owner September 4, 2020 07:11
@vercel vercel bot temporarily deployed to Preview September 4, 2020 07:11 Inactive
@vercel
Copy link

vercel bot commented Sep 4, 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/reyjhyr2i
✅ Preview: Canceled

[update for fb90d10 canceled]

Copy link
Owner

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

Oh nice! Good catch. Yea, we do this inside of Snowpack, but it looks like we forgot to inside of this plugin. @drwpow has been talking about a "common utils" library for plugin authors, a function that could do this and handle URLs automatically feels like it could fit in that bucket (we need it ourselves, internally)

1 small comment to resolve before merging, but overall LGTM

@@ -67,7 +68,9 @@ function emitHTMLFiles({ doms, jsEntries, stats, baseUrl, buildDirectory }) {

for (const jsFile of jsFiles) {
const scriptEl = dom.window.document.createElement("script");
scriptEl.src = path.posix.join(baseUrl, jsFile);
scriptEl.src = baseUrl.startsWith('http')
Copy link
Owner

Choose a reason for hiding this comment

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

In other parts of the codebase, we've done if (url.parse(resolvedImportUrl).protocol) { which is slightly more general than just checking for http. Would love to see that here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had a look at how to implement url.parse(resolvedImportUrl).protocol to resolve the URL and as far as I can tell I have to import some stuff which needs some configuration where I have no clue how to get it inside the plugin context.

Mainly this part: https://github.com/pikapkg/snowpack/blob/master/snowpack/src/commands/dev.ts#L554.

I get the feeling that this would involve some bigger refactorings.

Copy link
Owner

Choose a reason for hiding this comment

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

I made the change that I was picturing, hopefully that's more clear / no big refactoring required at this point.

@vercel vercel bot temporarily deployed to Preview September 7, 2020 16:38 Inactive
Copy link
Owner

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

LGTM

@FredKSchott FredKSchott merged commit 0d2d4cf into FredKSchott:master Sep 7, 2020
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.

2 participants