Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some visual notices for script minification issues #890

Merged
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
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ if (minify && !isDbg) {
app.use(function(aReq, aRes, aNext) {
var pathname = aReq._parsedUrl.pathname;

// If a userscript or libary...
// If a userscript or library...
if (/(\.user|\.meta)?\.js$/.test(pathname) && /^\/(meta|install|src)\//.test(pathname)) {
aRes._skip = true; // ... skip using release minification
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ exports.sendScript = function (aReq, aRes, aNext) {
if (!/\.min(\.user)?\.js$/.test(aReq._parsedUrl.pathname)) {
aStream.pipe(aRes);
} else {
// Otherwise set some defaults per script request in *express-minify* via *UglifyJS2*
// Otherwise set some defaults per script request via *UglifyJS2*
// and try minifying output

aStream.on('data', function (aData) {
Expand Down Expand Up @@ -486,7 +486,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
var match = null;
var rLibrary = new RegExp(
'^(?:(?:(?:https?:)?\/\/' +
(isPro ? 'openuserjs\.org' : 'localhost:8080') +
(isPro ? 'openuserjs\.org' : 'localhost:' + (process.env.PORT || 8080)) +
')?\/(?:libs\/src|src\/libs)\/)?(.*?)([^\/]*\.js)$', '');
var libraries = [];

Expand Down
31 changes: 31 additions & 0 deletions libs/modelParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ var parseScript = function (aScriptData) {
var icon = null;
var supportURL = null;

var downloadURL = null;
var rAlternateDownload = null;

// Temporaries
var htmlStub = null;

Expand Down Expand Up @@ -163,6 +166,34 @@ var parseScript = function (aScriptData) {
}
}

// Download Url
downloadURL = findMeta(script.meta, 'UserScript.downloadURL.0.value');
if (downloadURL) {
rAlternateDownload = new RegExp(
'^https?://(?:openuserjs\.org|localhost:' + (process.env.PORT || 8080) +
')/(?:install|src/scripts)/' +
script.installName.replace(/\.user\.js$/, '.min.user.js'));

try {
downloadURL = decodeURIComponent(downloadURL);

} catch (aE) {
script.hasInvalidDownloadURL = true;
script.showMinficationNotices = true;
}

if (!rAlternateDownload.test(downloadURL)) {
script.hasAlternateDownloadURL = true;
script.showMinficationNotices = true;
}
}

// OpenUserJS metadata block checks
if (findMeta(script.meta, 'OpenUserJS.unstableMinify.0.value')) {
script.hasUnstableMinify = true;
script.showMinficationNotices = true;
}

//
script.fullName = script.author.name + '/' + script.name; // GitHub-like name

Expand Down
4 changes: 3 additions & 1 deletion public/pegjs/blockOpenUserJS.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Test the generated parser with some input for PEG.js site at http://pegjs.org/on
// ==OpenUserJS==
// @author Marti
// @collaborator sizzle
// @unstableMinify Some reason
// ==/OpenUserJS==

*/
Expand Down Expand Up @@ -37,7 +38,8 @@ non_newline = $[^\n]+
item1 =
key:
(
'author'
'author' /
'unstableMinify'
)
whitespace
value: non_newline
Expand Down
21 changes: 20 additions & 1 deletion views/includes/scriptPageHeader.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,27 @@ <h2 class="page-heading">
<ul class="dropdown-menu">
<li>
<div class="btn-group btn-group-justified">
<a href="{{{script.scriptInstallPageXUrl}}}.min.user.js" class="btn btn-warning" title="EXPERIMENTAL"><i class="fa fa-fw fa-download"></i> Install with minification</a>
<a href="{{{script.scriptInstallPageXUrl}}}.min.user.js" class="btn btn-{{#script.showMinficationNotices}}warning{{/script.showMinficationNotices}}{{^script.showMinficationNotices}}primary{{/script.showMinficationNotices}}" title="EXPERIMENTAL INSTALLATION FORKING"><i class="fa fa-fw fa-download"></i> Install with minification</a>
</div>
{{#script.showMinficationNotices}}
<div class="alert alert-warning" role="alert">
{{#script.hasInvalidDownloadURL}}
<p>
<i class="fa fa-fw fa-exclamation"></i> Invalid download target
<p>
{{/script.hasInvalidDownloadURL}}
{{#script.hasUnstableMinify}}
<p>
<i class="fa fa-fw fa-exclamation-triangle"></i> The script author suggests that minification of this script may be unstable.
<p>
{{/script.hasUnstableMinify}}
{{#script.hasAlternateDownloadURL}}
<p>
<i class="fa fa-fw fa-exclamation-triangle"></i> Alternate download target.
</p>
{{/script.hasAlternateDownloadURL}}
</div>
{{/script.showMinficationNotices}}
</li>
<li role="separator" class="divider"></li>
<li><a href="/about/Userscript-Beginners-HOWTO"><em class="fa fa-fw fa-file-text-o"></em> Userscript Beginners HOWTO</a></li>
Expand Down