diff --git a/node_modules/architect-build/module-deps.js b/node_modules/architect-build/module-deps.js index 77718e8d..c9a592c6 100644 --- a/node_modules/architect-build/module-deps.js +++ b/node_modules/architect-build/module-deps.js @@ -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; \ No newline at end of file +module.exports.getSubmodules = getSubmodules; +module.exports.resolveModulePath = resolveModulePath; +module.exports.removeLicenceComments = removeLicenceComments; +module.exports.removeLicenceCommentsKeepLines = removeLicenceCommentsKeepLines; \ No newline at end of file diff --git a/plugins/c9.static/build_test.js b/plugins/c9.static/build_test.js index 73c7e33f..7dd15bed 100755 --- a/plugins/c9.static/build_test.js +++ b/plugins/c9.static/build_test.js @@ -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(); }); }); \ No newline at end of file