-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. The global in output file seems to be |
||
}; | ||
|
||
const rollupTemplate = fs.readFileSync('./iife-wrapper.js').toString(); | ||
const [ banner, footer ] = rollupTemplate.split('/*==ROLLUP_CONTENT==*/'); | ||
|
||
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 commentThe 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. |
||
output: [ | ||
{ | ||
name: 'Pretender', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { default as ParsedUrl } from 'url-parse'; | ||
|
||
/** | ||
* parseURL - decompose a URL into its parts | ||
* @param {String} url a URL | ||
|
@@ -16,32 +18,30 @@ | |
* } | ||
*/ | ||
export default function parseURL(url: string) { | ||
// TODO: something for when document isn't present... #yolo | ||
var anchor = document.createElement('a'); | ||
anchor.href = url; | ||
var parsedUrl = new ParsedUrl(url); | ||
|
||
if (!anchor.host) { | ||
if (!parsedUrl.host) { | ||
// 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 commentThe 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. |
||
} | ||
|
||
var pathname = anchor.pathname; | ||
var pathname = parsedUrl.pathname; | ||
if (pathname.charAt(0) !== '/') { | ||
pathname = '/' + pathname; // IE: prepend leading slash | ||
} | ||
|
||
var host = anchor.host; | ||
if (anchor.port === '80' || anchor.port === '443') { | ||
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 commentThe 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 |
||
} | ||
|
||
return { | ||
host: host, | ||
protocol: anchor.protocol, | ||
search: anchor.search, | ||
hash: anchor.hash, | ||
href: anchor.href, | ||
protocol: parsedUrl.protocol, | ||
search: parsedUrl.query, | ||
hash: parsedUrl.hash, | ||
href: parsedUrl.href, | ||
pathname: pathname, | ||
fullpath: pathname + (anchor.search || '') + (anchor.hash || '') | ||
fullpath: pathname + (parsedUrl.query || '') + (parsedUrl.hash || '') | ||
}; | ||
} |
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 indevDependencies
.