Skip to content

Commit

Permalink
fix(client): regression over injection of extensions declared under `…
Browse files Browse the repository at this point in the history
…config.injectFileTypes`

Added a fallback to legacy behaviour to account for this - fixes #1488
  • Loading branch information
shakyShane committed Jan 9, 2018
1 parent 55127fe commit f957956
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 18 deletions.
130 changes: 125 additions & 5 deletions client/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/dist/index.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/index.min.js.map

Large diffs are not rendered by default.

30 changes: 26 additions & 4 deletions client/lib/code-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ const log = nanlogger("Browsersync", { colors: { magenta: "#0F2634" } });
const reloader = new Reloader(window, log, Timer);

const options = {
tagNames: {
"css": "link",
"jpg": "img",
"jpeg": "img",
"png": "img",
"svg": "img",
"gif": "img",
"js": "script"
},
attrs: {
"link": "href",
"img": "src",
"script": "src"
},
blacklist: [
// never allow .map files through
function(incoming) {
Expand All @@ -27,6 +41,11 @@ const current = function() {
* @param {BrowserSync} bs
*/
sync.init = function(bs) {

if (bs.options.tagNames) {
options.tagNames = bs.options.tagNames;
}

if (bs.options.scrollRestoreTechnique === "window.name") {
sync.saveScrollInName(emitter);
} else {
Expand Down Expand Up @@ -136,18 +155,21 @@ sync.reload = function(bs) {
return;
}

var options = bs.options;

if (data.url || !options.injectChanges) {
if (data.url || !bs.options.injectChanges) {
sync.reloadBrowser(true);
}

if (data.basename && data.ext) {

if (sync.isBlacklisted(data)) {
return;
}

reloader.reload(data.path, { liveCSS: true, liveImg: true });
reloader.reload(data, {
...options,
liveCSS: true,
liveImg: true
});
}
};
};
Expand Down
38 changes: 38 additions & 0 deletions client/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,41 @@ export const numberOfMatchingSegments = function(path1, path2) {

export const pathsMatch = (path1, path2) =>
numberOfMatchingSegments(path1, path2) > 0;

export function getLocation(url: string) {
var location = document.createElement("a");
location.href = url;

if (location.host === "") {
location.href = location.href;
}

return location;
}

/**
* @param {string} search
* @param {string} key
* @param {string} suffix
*/
export function updateSearch(search, key, suffix) {

if (search === "") {
return "?" + suffix;
}

return "?" + search
.slice(1)
.split("&")
.map(function (item) {
return item.split("=");
})
.filter(function (tuple) {
return tuple[0] !== key;
})
.map(function (item) {
return [item[0], item[1]].join("=");
})
.concat(suffix)
.join("&");
};

0 comments on commit f957956

Please sign in to comment.