Skip to content

Commit 3aff733

Browse files
committed
Merge pull request #591 from Martii/Issue-502relativeLibs
Fix for relative libs Auto-merge
2 parents 09088c1 + ed22c97 commit 3aff733

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

controllers/script.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ var getScriptPageTasks = function (aOptions) {
151151

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

162161
script.libs = aScriptLibraryList;
163162
script.libs = _.map(script.libs, modelParser.parseScript);
163+
164+
if (script.libs.length > 0) {
165+
script.usesLibs = true;
166+
}
164167
aCallback();
165168
});
166169
});

controllers/scriptStorage.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,12 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
270270
var isLibrary = typeof aMeta === 'string';
271271
var libraries = [];
272272
var requires = null;
273+
var match = null;
273274
var collaborators = null;
274-
var libraryRegex = new RegExp('^https?:\/\/' +
275-
(isPro ?
276-
'openuserjs\.org' : 'localhost:8080') +
277-
'\/(?:libs\/src|src\/libs)\/(.+?\/.+?\.js)$', '');
275+
var rLibrary = new RegExp(
276+
'^(?:(?:(?:https?:)?\/\/' +
277+
(isPro ? 'openuserjs\.org' : 'localhost:8080') +
278+
')?\/(?:libs\/src|src\/libs)\/)?(.*?)([^\/]*\.js)$', '');
278279

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

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

309310
requires.forEach(function (aRequire) {
310-
var match = libraryRegex.exec(aRequire);
311-
if (match && match[1]) { libraries.push(match[1]); }
311+
match = rLibrary.exec(aRequire);
312+
if (match) {
313+
if (!match[1]) {
314+
match[1] = aUser.name + '/';
315+
}
316+
317+
if (!/\.user\.js$/.test(match[2])) {
318+
libraries.push(match[1] + match[2]);
319+
}
320+
}
312321
});
313322
}
314323
} else {

0 commit comments

Comments
 (0)