Merge pull request +13569 from c9/revert-13568-revert-13542-none-dont-strip-copyright-comments

Fix "make static" for outplan
pull/290/head
Lennart C. L. Kats 2016-04-21 13:42:17 +02:00
commit 95a5f59141
2 zmienionych plików z 35 dodań i 8 usunięć

Wyświetl plik

@ -113,6 +113,7 @@ module.exports = function(mains, opts) {
}
function setModuleSource(mod, src, cb) {
src = src.replace(/\r\n/g, "\n"); // normalize windows newlines
if (cache)
cache.files[mod.file] = src;
mod.source = src;
@ -345,13 +346,14 @@ function removeUseStrict(module) {
module.source = module.source.replace(/['"]use strict['"];/g, "");
}
var commentRe = /^(;)?(?:\s*(?:\/\/.+\n|\/\*(?:[^*]|\*(?!\/))*\*\/))+(?: *\n)?/gm;
function removeLicenceComments(module) {
if (/\.(js|jsx|css|less)/.test(module.path))
module.source = module.source.replace(/(?:(;)|\n|^)\s*\/\*[\d\D]*?\*\/|(\n|^)\s*\/\/.*/g, "$1");
module.source = module.source.replace(commentRe, "$1");
}
function removeLicenceCommentsKeepLines(module) {
if (/\.(js|jsx|css|less)/.test(module.path)) {
module.source = module.source.replace(/(?:(;)|\n|^)\s*\/\*[\d\D]*?\*\/|\n\s*\/\/.*/g, function(cm, start) {
module.source = module.source.replace(commentRe, function(cm, start) {
return (start||"") + cm.replace(/.+/g, "");
});
}
@ -391,8 +393,8 @@ function wrapUMD(module) {
+ ' $build_deps$.module.define(name, [], function() { return $build_deps$.module.exports });\n'
+ ' }\n'
+ '}\n'
+ 'define.amd = true;'
+ module.source
+ 'define.amd = true;\n'
+ module.source + '\n'
+ '});';
}
@ -410,4 +412,7 @@ function quote(str) {
}
module.exports.resolveModulePath = resolveModulePath;
module.exports.getSubmodules = getSubmodules;
module.exports.resolveModulePath = resolveModulePath;
module.exports.removeLicenceComments = removeLicenceComments;
module.exports.removeLicenceCommentsKeepLines = removeLicenceCommentsKeepLines;

Wyświetl plik

@ -17,7 +17,7 @@ require("amd-loader");
var build, options, pathConfig;
describe("The Module", function(){
describe("The build module", function(){
this.timeout(60000);
beforeEach(function(next) {
@ -63,7 +63,7 @@ describe("The Module", function(){
});
});
it("test compile less", function(done) {
it("should compile less", function(done) {
build.buildSkin("ssh", "dark", pathConfig, function(err, result) {
if (err) return done(err);
@ -71,6 +71,28 @@ describe("The Module", function(){
assert(code);
done(err);
});
});
it("should remove comments", function(done) {
var removeLicenceComments = require("architect-build/module-deps").removeLicenceComments;
function remove(src) {
var module = { source: "" + src, path: ".js" };
removeLicenceComments(module);
return module.source;
}
assert.equal(remove("" + function() {
// 1
var a;
/***/ // hello
var x; // not removed
/* asd
*/
x += "he/*ll*/o" + a;
}) , function() {
var a;
var x; // not removed
x += "he/*ll*/o" + a;
});
done();
});
});