-
Notifications
You must be signed in to change notification settings - Fork 158
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
use url-parse
package as parsing fallback
#267
Conversation
👍 I'm in favor of this change – and I also think we should drop the |
b21ba0e
to
b9473c3
Compare
Mk, updated to use Any ideas? Am I missing something needed for including the url-parse package? EDIT: D'oh |
Ah. Maybe you can just map it and call it something else? |
b9473c3
to
9765b3e
Compare
Yeah, found another issue after that though w/ the new name not being available to the iife. Couldn't figure out how the other deps were working since I was doing the same thing as them. My best guess is that whatwg and the two bower deps had umd builds that exposed themselves on global but url-parse doesn't. Fix here is to tell rollup not to mark it as a EDIT why are the close and comment buttons so close to each other |
e88e03a
to
c2743bf
Compare
c2743bf
to
9b7382c
Compare
LGTM! I think we don't need to include url-parse in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this!
If we are going to include a polyfill for parsing url (probably only for IE), an alternative is to include core-js's URL polyfill. I did a size measurement with terser minified file:
- original pretender:
./dist/pretender.js 18.44 KB
./dist/pretender.es.js 16.26 KB
./dist/pretender.es.min.js 6.68 KB
url-parse
./dist/pretender.js 34.02 KB
./dist/pretender.es.js 31.77 KB
./dist/pretender.es.min.js 10.97 KB
import 'core-js/web/url';
./dist/pretender.js 103.7 KB
./dist/pretender.es.js 97.09 KB
./dist/pretender.es.min.js 34.1 KB
url-parse
seems to be a more reasonable alternative if core-js polyfill is too large. Otherwise I would prefer to polyfill with core-js so we can use standard URL.
@FLGMwt @samselikoff @stefanpenner Is size something you worry about? My use of Pretender is always in test so I don't actually care about the bloating size.
@@ -53,6 +53,7 @@ | |||
"dependencies": { | |||
"fake-xml-http-request": "^2.0.0", | |||
"route-recognizer": "^0.3.3", | |||
"url-parse": "^1.4.7", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To bundle url-parse
in the output file, url-parse
should lives in devDependencies
.
@@ -6,15 +6,16 @@ const fs = require('fs'); | |||
const globals = { | |||
'whatwg-fetch': 'FakeFetch', | |||
'fake-xml-http-request': 'FakeXMLHttpRequest', | |||
'route-recognizer': 'RouteRecognizer' | |||
'route-recognizer': 'RouteRecognizer', | |||
'url-parse': 'ParsedUrl' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global in output file seems to be urlParse
rather than ParsedUrl
.
module.exports = { | ||
input: 'src/index.ts', | ||
external: Object.keys(pkg.dependencies), | ||
// don't exclude url-parse because it does *not* provide a UMD bundle and needs to be included | ||
external: Object.keys(pkg.dependencies).filter(x => x !== 'url-parse'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This need to be changed when updating how this package is being bundled.
// eslint-disable-next-line no-self-assign | ||
anchor.href = anchor.href; // IE: load the host and protocol | ||
parsedUrl.href = parsedUrl.href; // IE: load the host and protocol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the comment was for IE quirks. This should be changed when moving away from anchor tag method.
host = anchor.hostname; // IE: remove default port | ||
var host = parsedUrl.host; | ||
if (parsedUrl.port === '80' || parsedUrl.port === '443') { | ||
host = parsedUrl.hostname; // IE: remove default port |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as my comment above. These seem to be addressing IE issue, we should have test coverage on the mentioned cases when moving to url-parse
.
Although there's no cross browser setup yet, but it's still worth adding test for this.
@xg-wang The reason we're bringing in If consumers need to polyfill ie11 behavior they should be able to use What do you think? |
And I agree it would be nice to get test coverage for ie11. But not exactly sure how. (I guess ie11 test coverage is more important for the iife build as folks using the es build will have a build step and should be able to use core-js on their own.) |
|
Oh I see – you're saying this PR could use the URL class instead of |
Oh sorry I'm not familiar with React Native, seems it's not implemented facebook/react-native#16434, and the WIP implementation just throws error https://github.com/facebook/react-native/blob/v0.60.5/Libraries/Blob/URL.js#L111. I think using |
Gotcha 👍 Ok so where does that leave us? (1) remove the ie11 comments (2) and what should we do about core js/ ie11? Are you wanting to ensure the iife build works in ie11, or that an Ember app does that's using the es build? |
@samselikoff https://github.com/unshiftio/url-parse#url-parse has a good test coverage. I'm thinking about bundling and versioning. Right now pretender is importing I think what would be easier to consume pretender is to export
I have a spike at xg-wang@0c17e6e @trek @stefanpenner what's your opinion on bundling? If this approach looks good to you I can create a PR, and @FLGMwt can just address my comments and this PR should be good to go. |
@xg-wang perhaps we can pick this up over in #269? We started work over there. Not sure if we need to switch from iife to umd. First question would be, who's using the iife? Supporting all these builds gets complex. I'm leaning more and more these days to focusing on esm build. The instructions on README for Pretender have said
but I'm pretty sure that's wrong, I believe the other dependencies would also need to be loaded, leading me to think nobody is using this, further leading me to think we should not commit to supporting a new UMD build (and definitely not two). It's just more work and the use cases get very complex very fast. In #269 we preserve the existing iife build and also swap Also looking at your commit, I don't think we want to treat |
@xg-wang want to chat about this in Discord, so we don't duplicate any more work? |
@samselikoff I think bundling the package is fine, the remaining work should be to address my comments above. @FLGMwt can you take a look? |
Can I pick up @FLGMwt 's work from here? |
Same as #219, hoping to get pretender working with React Native projects that don't have
document.createElement
available for URL parsing.url-parse
has a minimal minimal footprint and this won't affect other consumers. That said, I'm happy to rework it to not usedocument.createElement
at all and rely only onurl-parse
for consistency.As for the
self
reference that #219 offered, I've found that it's common for RN projects using browser-y libraries to use react-native-browser-polyfill to achieve something similar, so changes aren't necessary here. Otherwise, I can pull in the suggestion provided in #219 if that's preferred.Thanks : D