Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/resolvers/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports = {
read (file) {
let u = url.parse(file.url);

if (process.browser && !u.protocol) {
if (typeof window !== "undefined" && !u.protocol) {
// Use the protocol of the current page
u.protocol = url.parse(location.href).protocol;
}
Expand Down
11 changes: 6 additions & 5 deletions lib/util/url.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"use strict";

let isWindows = /^win/.test(process.platform),
forwardSlashPattern = /\//g,
let forwardSlashPattern = /\//g,
protocolPattern = /^(\w{2,}):\/\//i,
url = module.exports,
jsonPointerSlash = /~1/g,
jsonPointerTilde = /~0/g;

const isWindows = typeof process !== "undefined" && process.platform === "win32";

// RegExp patterns to URL-encode special characters in local filesystem paths
let urlEncodePatterns = [
/\?/g, "%3F",
Expand Down Expand Up @@ -45,7 +46,7 @@ exports.resolve = function resolve (from, to) {
* @returns {string}
*/
exports.cwd = function cwd () {
if (process.browser) {
if (typeof window !== "undefined") {
return location.href;
}

Expand Down Expand Up @@ -144,7 +145,7 @@ exports.isHttp = function isHttp (path) {
}
else if (protocol === undefined) {
// There is no protocol. If we're running in a browser, then assume it's HTTP.
return process.browser;
return typeof window !== "undefined";
}
else {
// It's some other protocol, such as "ftp://", "mongodb://", etc.
Expand All @@ -160,7 +161,7 @@ exports.isHttp = function isHttp (path) {
* @returns {boolean}
*/
exports.isFileSystemPath = function isFileSystemPath (path) {
if (process.browser) {
if (typeof window !== "undefined") {
// We're running in a browser, so assume that all paths are URLs.
// This way, even relative paths will be treated as URLs rather than as filesystem paths
return false;
Expand Down