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

Don't show non-important warnings for other packages #31

Closed
wants to merge 16 commits into from
Closed
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
/node_modules
builds
.idea
/coverage
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ important:
packing algorithm to evenly distribute the modules among these
bundles.

- ``manifest``: For application packages, instructs the optimizer to
- ``appcache``: For application packages, instructs the optimizer to
generate an appcache manifest. The manifest will contain all of the
resources in an all used packages except those explicitly excluded
in each package. The `manifest` property can be either `true` or an
in each package. The `appcache` property can be either `true` or an
object with additional configuration for manifests.

- ``fallback`` is an object that causes the browser to redirect
Expand All @@ -238,10 +238,10 @@ important:

- ``exclude``: A list of glob patterns for files and directory trees
in the package, relative to the package root, that must not be
included in a production build and its manifest. These exclusions
may include ``*`` for zero or more wild card characters in a file
name, ``?`` for a single wild card character in a file name, or
``**`` for recursive directory traversal.
included in a production build and its appcache manifest. These
exclusions may include ``*`` for zero or more wild card characters
in a file name, ``?`` for a single wild card character in a file
name, or ``**`` for recursive directory traversal.

{
"exclude": [
Expand Down
22 changes: 11 additions & 11 deletions lib/manifest.js → lib/appcache.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ require("collections/shim"); // Object.map, et al
var File = require("./file");
var URL = require("url2");

module.exports = manifest;
function manifest(appPackage, config) {
var manifestConfig = appPackage.packageDescription.manifest;
if (!manifestConfig)
module.exports = appcache;
function appcache(appPackage, config) {
var appcacheConfig = appPackage.packageDescription.appcache;
if (!appcacheConfig)
return;
// coerce the manifest to {fallback, network}
if (typeof manifestConfig === "boolean")
manifestConfig = {};
// coerce the appcache to {fallback, network}
if (typeof appcacheConfig === "boolean")
appcacheConfig = {};

var locations = Object.keys(config.files).sort();
var manifest = locations.map(function (location) {
var appcache = locations.map(function (location) {
var file = config.files[location];
return URL.relative(appPackage.buildLocation, file.buildLocation);
});
Expand All @@ -25,10 +25,10 @@ function manifest(appPackage, config) {
lines.push("#hash " + appPackage.hash);

// MANIFEST:
lines.push.apply(lines, manifest);
lines.push.apply(lines, appcache);

// FALLBACK:
var fallback = manifestConfig.fallback || {};
var fallback = appcacheConfig.fallback || {};
if (Object.keys(fallback).length) {
lines.push("");
lines.push("FALLBACK:");
Expand All @@ -54,7 +54,7 @@ function manifest(appPackage, config) {
utf8: content,
buildLocation: URL.resolve(appPackage.buildLocation, "manifest.appcache")
});
config.out.log("Manifest: " + file.buildLocation);
config.out.log("Appcache manifest: " + file.buildLocation);
config.files[file.buildLocation] = file;
}

10 changes: 5 additions & 5 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var relocate = require("./relocate");
var reconfigure = require("./reconfigure");
var transform = require("./transform");
var bundle = require("./bundle");
var manifest = require("./manifest");
var appcache = require("./appcache");
var write = require("./write");
var link = require("./link");

Expand Down Expand Up @@ -41,15 +41,15 @@ function build(location, config) {
// respect includes
})
.then(function () {
// TODO creates a manifest.appcache
return manifest(package, config);
// creates a manifest.appcache
return appcache(package, config);
})
.then(function () {
return write(package, config);
})
.then(function () {
return link(package, config);
})
})
});
});
}

25 changes: 13 additions & 12 deletions lib/bundle/montage.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,24 @@ function loadMontageScript(element, file, config) {
// loaded at each stage of bundling
var applicationLocation = file.package.location;
var montageLocation = file.package.getPackage({name: "montage"}).location;
return MontageBootstrap.loadPackage(montageLocation, config)
.then(function (montagePackage) {
return Promise.all([
"core/event/event-manager",
"core/deserializer",
"core/event/binding",
].map(montagePackage.deepLoad))
.then(function () {
return montagePackage.loadPackage(applicationLocation)
return MontageBootstrap.loadPackage(applicationLocation, config)
.then(function (applicationPackage) {
return applicationPackage.loadPackage(montageLocation)
.then(function (montagePackage) {
return Promise.all([
"core/core",
"core/event/event-manager",
"core/serialization/deserializer/montage-reviver",
"core/logger"
].map(montagePackage.deepLoad));
})
.then(function (applicationPackage) {
.then(function () {
return Promise.fcall(function () {
return applicationPackage.deepLoad(file.relativeLocation)
.fail(function (error) {
error.message = "Can't find dependencies of HTML application " + JSON.stringify(file.location) + " because " + error.message;
throw error;
})
});
})
.then(function () {
if (element.hasAttribute("data-module")) {
Expand All @@ -94,7 +95,7 @@ function loadMontageScript(element, file, config) {
}
})
.thenResolve(applicationPackage);
})
});
});
}

Expand Down
13 changes: 7 additions & 6 deletions lib/minify-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ POSSIBILITY OF SUCH DAMAGE.
</copyright> */

var UGLIFY = require("uglify-js");
var PARSER = UGLIFY.parser;
var PROCESS = UGLIFY.uglify;

// Prevent Uglify writing directly to the console
UGLIFY.AST_Node.warn_function = null;

module.exports = uglify;
function uglify(source, fileName) {
var ast = PARSER.parse(source); // parse code and get the initial AST
ast = PROCESS.ast_mangle(ast); // get a new AST with mangled names
ast = PROCESS.ast_squeeze(ast); // get an AST with compression optimizations
return PROCESS.gen_code(ast); // compressed code here
return UGLIFY.minify(source, {
fromString: true,
warnings: false
}).code;
}

12 changes: 6 additions & 6 deletions lib/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ function read(location, config) {
})
.then(function () {
return hashDependencies(package);
})
});
})
.then(function () {
verifyVersions(package);
return package;
})
})
});
});
}

function verifyVersions(package) {
Expand Down Expand Up @@ -66,7 +66,7 @@ function loadDeepPackages(package, memo) {
var mappings = package.mappings || {};
return Promise.all(Object.keys(mappings).map(function (id) {
var mapping = mappings[id];
location = mapping.location;
var location = mapping.location;
if (!memo[location]) {
var loading = package.loadPackage(location)
.then(function (dependency) {
Expand All @@ -90,7 +90,7 @@ function readPackage(package, config, memo) {
// option variations
hashBuilder.update([
config.minify,
config.manifest,
config.appcache,
config.shared
].map(function (option) {
return option ? "1" : "0";
Expand Down Expand Up @@ -142,7 +142,7 @@ function readPackage(package, config, memo) {
})
.then(function () {
config.out.status();
})
});
}

function hashDependencies(package, memo) {
Expand Down
5 changes: 2 additions & 3 deletions lib/transform/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ function rebaseCss(css, file, config) {
try {
ast = CSSO.parse(css);
} catch (exception) {
config.out.warn("CSS parse error: " + file.path);
config.out.warn(exception.message);
config.out.warn("CSS parse error in " + file.path + ": " + exception.message);
return css;
}

Expand All @@ -34,7 +33,7 @@ function rebaseCss(css, file, config) {
// escaped by rebase
node[1] = value = ["raw"];
} else {
config.out.warn("Unknown URI type:", value);
config.out.warn("Unknown URI type in " + file.path + ": " + value);
continue;
}

Expand Down
12 changes: 8 additions & 4 deletions lib/transform/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ function transformHtml(file, config) {

function transformDocument(file, config) {
var appPackage = file.package.getPackage({main: true});
var manifestLocation = URL.resolve(appPackage.buildLocation, "manifest.appcache");
var appcacheLocation = URL.resolve(appPackage.buildLocation, "appcache.appcache");
visit(file.document, function (element) {
if (element.nodeType === Node.ELEMENT_NODE) {
rebaseAttribute(element, "href", file, config);
rebaseAttribute(element, "src", file, config);
if (element.tagName === "HTML" && appPackage.packageDescription.manifest) {
var relativeLocation = URL.relative(file.buildLocation, manifestLocation);
if (element.tagName === "HTML" && appPackage.packageDescription.appcache) {
var relativeLocation = URL.relative(file.buildLocation, appcacheLocation);
element.setAttribute("manifest", relativeLocation);
}
if (element.tagName === "STYLE") {
Expand Down Expand Up @@ -113,7 +113,11 @@ function rebaseScriptTag(element, file, config) {
element.removeAttribute("type");
}
if (config.minify) {
setText(element, minifyJavaScript(getText(element), file.path), file.document);
try {
setText(element, minifyJavaScript(getText(element), file.path), file.document);
} catch (exception) {
config.out.warn("JavaScript parse error in " + file.path + ": " + exception.message);
}
}
} else if (type === "text/m-objects") {
config.out.warn("Deprecated text/m-objects block in " + file.path + ". Use montage/serialization.");
Expand Down
32 changes: 14 additions & 18 deletions lib/transform/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@ var minifyJavaScript = require("../minify-javascript");
var jshint = require("../jshint").JSHINT;
var URL = require("url2");
var FS = require("q-io/fs");

var currentLocation = URL.format({
protocol: "file:",
slashes: true,
pathname: process.cwd() + "/"
});
function relativeToWorkingLocation(location) {
return URL.relative(currentLocation, location);
}
var relativeToWorkingLocation = require("../util").relativeToWorkingLocation;

module.exports = transformJavaScript;
function transformJavaScript(file, config) {
Expand All @@ -27,14 +19,18 @@ function transformJavaScript(file, config) {
var id = file.relativeLocation.replace(/\.js$/, "");
var dependencies = MontageRequire.parseDependencies(file.utf8);

if (id.toLowerCase() !== id) {
config.out.warn("Module file name should be all lower-case " + relativeToWorkingLocation(file.location));
}
dependencies.forEach(function (dependency) {
if (dependency.toLowerCase() !== dependency) {
config.out.warn("Module identifier " + JSON.stringify(dependency) + " should be lower-case in " + relativeToWorkingLocation(file.location));
// only warn for files in this package
if (file.package.location === config.location) {
if (id.toLowerCase() !== id) {
config.out.warn("Module file name should be all lower-case " + relativeToWorkingLocation(file.location));
}
});

dependencies.forEach(function (dependency) {
if (dependency.toLowerCase() !== dependency) {
config.out.warn("Module identifier " + JSON.stringify(dependency) + " should be lower-case in " + relativeToWorkingLocation(file.location));
}
});
}

var definedContent = (
"montageDefine(" +
Expand Down Expand Up @@ -65,14 +61,14 @@ function transformJavaScript(file, config) {
try {
file.utf8 = minifyJavaScript(file.utf8, file.path);
} catch (exception) {
config.out.warn("JavaScript parse error: " + relativeToWorkingLocation(file.location));
config.out.warn("JavaScript parse error in " + relativeToWorkingLocation(file.location) + ": " + exception.message);
}

// minify defined .load.js
try {
definedFile.utf8 = minifyJavaScript(definedFile.utf8, definedFile.path);
} catch (exception) {
config.out.warn("JavaScript parse error: " + definedFile.path);
config.out.warn("JavaScript parse error in " + definedFile.path + ": " + exception.message);
}

}
Expand Down
13 changes: 5 additions & 8 deletions lib/transform/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var File = require("../file");
var rebase = require("../rebase");
var minifyJavaScript = require("../minify-javascript");
var relativeToWorkingLocation = require("../util").relativeToWorkingLocation;

module.exports = transformJson;
function transformJson(file, config) {
Expand All @@ -16,6 +17,7 @@ function transformJson(file, config) {

var definedFile = new File({
utf8: definedContent,
path: file.path + ".load.js",
location: file.location + ".load.js",
relativeLocation: file.relativeLocation + ".load.js",
buildLocation: file.buildLocation + ".load.js",
Expand All @@ -31,23 +33,18 @@ function transformJson(file, config) {
file.utf8 = JSON.stringify(JSON.parse(file.utf8));
} catch (exception) {
if (exception instanceof SyntaxError) {
config.out.warn("JSON parse error: " + file.location);
config.out.warn("JSON parse error in " + relativeToWorkingLocation(file.location) + ": " + exception.message);
} else {
throw exception;
}
}

// minify created json.load.js
try {
definedFile.utf8 = minifyJavaScript(definedFile.utf8, definedFile.location);
definedFile.utf8 = minifyJavaScript(definedFile.utf8, definedFile.path);
} catch (exception) {
if (exception instanceof SyntaxError) {
config.out.warn("JSON parse error: " + definedFile.location);
} else {
throw exception;
}
config.out.warn("JSON parse error in " + definedFile.path + ": " + exception.message);
}

}
}

12 changes: 12 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var URL = require("url2");

var currentLocation = URL.format({
protocol: "file:",
slashes: true,
pathname: process.cwd() + "/"
});

exports.relativeToWorkingLocation = relativeToWorkingLocation;
function relativeToWorkingLocation(location) {
return URL.relative(currentLocation, location);
}
3 changes: 2 additions & 1 deletion optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ var URL = require("url2");
var build = require("./lib/build");
var spinner = require("./lib/spinner");

Error.stackTraceLimit = 50;
var Q = require("q");
Q.longStackJumpLimit = 0;

/**
* Optimize the package at the given location.
Expand Down
Loading