Skip to content
Merged
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
5 changes: 4 additions & 1 deletion controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ var getScriptPageTasks = function (aOptions) {

// Show which libraries hosted on the site a script uses
if (!script.isLib && script.uses && script.uses.length > 0) {
script.usesLibs = true;
script.libs = [];
tasks.push(function (aCallback) {
Script.find({
Expand All @@ -161,6 +160,10 @@ var getScriptPageTasks = function (aOptions) {

script.libs = aScriptLibraryList;
script.libs = _.map(script.libs, modelParser.parseScript);

if (script.libs.length > 0) {
script.usesLibs = true;
}
aCallback();
});
});
Expand Down
21 changes: 15 additions & 6 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,12 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
var isLibrary = typeof aMeta === 'string';
var libraries = [];
var requires = null;
var match = null;
var collaborators = null;
var libraryRegex = new RegExp('^https?:\/\/' +
(isPro ?
'openuserjs\.org' : 'localhost:8080') +
'\/(?:libs\/src|src\/libs)\/(.+?\/.+?\.js)$', '');
var rLibrary = new RegExp(
'^(?:(?:(?:https?:)?\/\/' +
(isPro ? 'openuserjs\.org' : 'localhost:8080') +
')?\/(?:libs\/src|src\/libs)\/)?(.*?)([^\/]*\.js)$', '');

if (!aMeta) { return aCallback(null); }

Expand Down Expand Up @@ -307,8 +308,16 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
}

requires.forEach(function (aRequire) {
var match = libraryRegex.exec(aRequire);
if (match && match[1]) { libraries.push(match[1]); }
match = rLibrary.exec(aRequire);
if (match) {
if (!match[1]) {
match[1] = aUser.name + '/';
}

if (!/\.user\.js$/.test(match[2])) {
libraries.push(match[1] + match[2]);
}
}
});
}
} else {
Expand Down