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(karma-webpack): don't include the os.tmpdir (output.publicPath) #338

Merged

Conversation

pat841
Copy link
Contributor

@pat841 pat841 commented Aug 27, 2018

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior? (You can also link to an open issue here)

This fixes issue #333 where a worker would fail to load due to a CORS issue. This change does NOT affect the write path for the webpack build, but the public path reflected in something like <base href="/_karma_webpack/">.

What is the new behavior?

The os.tmpdir() is stripped from the webpack's publicPath so that async assets are loaded correctly from a common domain avoiding CORS issues.

Does this PR introduce a breaking change?

  • Yes
  • No

If this PR contains a breaking change, please describe the following...

  • Impact:
  • Migration path for existing applications:
  • Github Issue(s) this is regarding:

Other information:

@jsf-clabot
Copy link

jsf-clabot commented Aug 27, 2018

CLA assistant check
All committers have signed the CLA.

@michael-ciniawsky michael-ciniawsky changed the title fix(karma-webpack): dont include the os.tmpdir in the webpack public … fix(karma-webpack): don't include the os.tmpdir in the publicPath Aug 29, 2018
@@ -69,7 +69,7 @@ function Plugin(
// Must have the common _karma_webpack_ prefix on path here to avoid
// https://github.com/webpack/webpack/issues/645
webpackOptions.output.path = path.join(os.tmpdir(), '_karma_webpack_', indexPath, '/')
webpackOptions.output.publicPath = path.join(os.tmpdir(), '_karma_webpack_', publicPath, '/')
webpackOptions.output.publicPath = path.join('/_karma_webpack_', publicPath, '/')
Copy link
Contributor

@michael-ciniawsky michael-ciniawsky Aug 29, 2018

Choose a reason for hiding this comment

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

That is simply incorrect right (in general)? Resulting in async chunks loading to fail? I'm only an admin here with limited knowledge about the current needs of a karma setup, so I need to rely on your help here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"That is simply incorrect right (in general)?" What do you mean by that? I believe this has been broken since PR #279 but has flown under the radar since it only breaks assets with strict CORS checking.

@JayCanuck
Copy link

JayCanuck commented Aug 30, 2018

Just wanted to add my 2cents here. Since #279 karma-webpack has been broken for myself and colleagues on Windows (Windows was resolving C:/.... into file://C:/ urls and failing for XHR). Was going to create a new issue but saw this PR. Looks like this patch fixes that issue flawlessly too. All tests resume passing with this PR branch.
Edit: looks like there's a related issue of others seeing the same Windows ajax issues that this PR solves #317

@lsphillips
Copy link

I was about to submit a PR, good thing I checked first :-).

Would really like to see this merged as soon as possible as this makes this project unusable for Windows users, especially as code splitting is a common practice these days.

@michael-ciniawsky michael-ciniawsky changed the title fix(karma-webpack): don't include the os.tmpdir in the publicPath fix(karma-webpack): don't include os.tmpdir in the publicPath Aug 31, 2018
@michael-ciniawsky
Copy link
Contributor

cc @rynclark

@ryanclark
Copy link
Collaborator

LGTM after conflicts are resolved

@michael-ciniawsky michael-ciniawsky changed the base branch from next to master September 1, 2018 04:03
@michael-ciniawsky michael-ciniawsky changed the title fix(karma-webpack): don't include os.tmpdir in the publicPath fix(karma-webpack): don't include os.tmpdir (options.publicPath) Sep 1, 2018
@pat841 pat841 force-pushed the feature/webpack-path-fix branch from 65fec5d to 49bdae1 Compare September 3, 2018 16:24
@pat841 pat841 force-pushed the feature/webpack-path-fix branch from 49bdae1 to bac4676 Compare September 3, 2018 16:31
@pat841
Copy link
Contributor Author

pat841 commented Sep 3, 2018

@rynclark Should be all set.

@JayCanuck
Copy link

JayCanuck commented Sep 3, 2018

@rynclark Tests are failing for me with the latest commit. Looks to be because path.join is used on webpackMiddlewareOptions.publicPath, which on Windows results in backslashes (\) and that backslash-based path fails to match the forward-slash (/) requests. Can you modify that line to be a static '/_karma_webpack_/' like it was before the rebase?

@pat841
Copy link
Contributor Author

pat841 commented Sep 3, 2018

@JayCanuck Yeah I was unsure about using path.join() for that reason but wanted to stay within the re-base updates. @rynclark Can I remove the path.join() calls around publicPath setters?

@JayCanuck
Copy link

At least in local testing, it looks like the webpackOptions.output.publicPath = path.join(... is fine and webpack handles backslashes correctly, but for handing request public path (and all the things that it extends to), the path.join(...) on webpackMiddlewareOptions.publicPath seems to be the key problem on Windows and needs forward slashes.

@pat841
Copy link
Contributor Author

pat841 commented Sep 3, 2018

Theres also the option of .replace(/\\/g, '/');

@JayCanuck
Copy link

That's true, yea, though that feels like having the unnecessary path.join and replace operations for unneeded processing compared to an equivalent static string.

@michael-ciniawsky
Copy link
Contributor

@pat841 Please leave it as is within this PR. It is a bug introduced by another recent PR and this ideally should to be adressed separately

Copy link
Contributor

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

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

@pat841 Thx

@pat841
Copy link
Contributor Author

pat841 commented Sep 4, 2018

@michael-ciniawsky Would you like me to create a new PR for the Windows fix based off of this branch?

Copy link
Contributor

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

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

Rubberstamp LGTM

@pat841 Thx

@michael-ciniawsky michael-ciniawsky merged commit 66f4cd7 into codymikol:master Sep 7, 2018
@michael-ciniawsky michael-ciniawsky changed the title fix(karma-webpack): don't include os.tmpdir (options.publicPath) fix(karma-webpack): don't include the os.tmpdir (output.publicPath) Sep 7, 2018
@michael-ciniawsky
Copy link
Contributor

Released in 4.0.0-rc.2 🎉

@johnnyreilly
Copy link

johnnyreilly commented Sep 24, 2018

I've just tested 4.0.0-rc.2 on Windows; still a problem I'm afraid. It's what we use in ts-loader for our execution test pack.

You can see this PR upgrades from 2.0.6 to 4.0.0-rc2 and then experiences issues:

TypeStrong/ts-loader#840

Linux is fine; Windows is not. The failing tests all relate to code splitting / dynamic imports.

I'll open a new issue to track this and link back.

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

Successfully merging this pull request may close these issues.

8 participants