Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Adding support for rootURL option #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ function SRIHashAssets(inputNodes, options) {
}
}
}

if ('rootURL' in this.options) {
this._rootURL = new RegExp('^' + this.options.rootURL);
}
}

SRIHashAssets.prototype = Object.create(CachingWriter.prototype);
Expand Down Expand Up @@ -84,7 +88,6 @@ SRIHashAssets.prototype.addSRI = function addSRI(string, srcDir) {
var base = this.getBaseHREF(string);

return string.replace(SCRIPT_CHECK, function srcMatch(match) {

var src = match.match(SRC_CHECK);
var filePath;

Expand All @@ -94,6 +97,10 @@ SRIHashAssets.prototype.addSRI = function addSRI(string, srcDir) {

filePath = src[1];

if (plugin._rootURL) {
filePath = filePath.replace(plugin._rootURL, '');
}

return plugin.mungeOutput(match, filePath, base || srcDir);
}).replace(LINT_CHECK, function hrefMatch(match) {
var href = match.match(HREF_CHECK);
Expand All @@ -106,6 +113,10 @@ SRIHashAssets.prototype.addSRI = function addSRI(string, srcDir) {

filePath = href[1];

if (plugin._rootURL) {
filePath = filePath.replace(plugin._rootURL, '');
}

return plugin.mungeOutput(match, filePath, base || srcDir);
});
};
Expand Down