From df51260143e03c6037a98605e733edd75054b8ac Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Wed, 30 Jul 2014 15:13:13 +0200 Subject: [PATCH 1/5] Don't add an empty stylesheet to the bundle if there are no CSS files --- tools/bundler.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/bundler.js b/tools/bundler.js index b42b5b8f2a..5eb2fe7466 100644 --- a/tools/bundler.js +++ b/tools/bundler.js @@ -837,6 +837,9 @@ _.extend(ClientTarget.prototype, { // Overwrite the CSS files list with the new concatenated file var stringifiedCss = CssTools.stringifyCss(self._cssAstCache, { sourcemap: true }); + if (! stringifiedCss.code) + return; + self.css = [new File({ data: new Buffer(stringifiedCss.code, 'utf8') })]; // Add the contents of the input files to the source map of the new file @@ -884,9 +887,10 @@ _.extend(ClientTarget.prototype, { minifiedCss = minifiers.CssTools.minifyCss(allCss); } - - self.css = [new File({ data: new Buffer(minifiedCss, 'utf8') })]; - self.css[0].setUrlToHash(".css", "?meteor_css_resource=true"); + if (!! minifiedCss) { + self.css = [new File({ data: new Buffer(minifiedCss, 'utf8') })]; + self.css[0].setUrlToHash(".css", "?meteor_css_resource=true"); + } }, // Output the finished target to disk From 955e3a881aafcedb0c0ceae61798942837503b76 Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Wed, 10 Sep 2014 01:57:19 +0200 Subject: [PATCH 2/5] Fix CSS injection client code The method to remove old stylesheets wasn't called in case the new stylesheet list was empty --- packages/autoupdate/autoupdate_client.js | 31 ++++++++++++++---------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/autoupdate/autoupdate_client.js b/packages/autoupdate/autoupdate_client.js index d780df1c85..21d6fd2823 100644 --- a/packages/autoupdate/autoupdate_client.js +++ b/packages/autoupdate/autoupdate_client.js @@ -107,13 +107,13 @@ Autoupdate._retrySubscription = function () { } }; - var attachStylesheetLink = function (newLink) { - var removeOldLinks = _.after(newCss.length, function () { - _.each(oldLinks, function (oldLink) { - oldLink.parentNode.removeChild(oldLink); - }); + var removeOldLinks = _.after(newCss.length, function () { + _.each(oldLinks, function (oldLink) { + oldLink.parentNode.removeChild(oldLink); }); + }); + var attachStylesheetLink = function (newLink) { document.getElementsByTagName("head").item(0).appendChild(newLink); waitUntilCssLoads(newLink, function () { @@ -121,14 +121,19 @@ Autoupdate._retrySubscription = function () { }); }; - _.each(newCss, function (css) { - var newLink = document.createElement("link"); - newLink.setAttribute("rel", "stylesheet"); - newLink.setAttribute("type", "text/css"); - newLink.setAttribute("class", "__meteor-css__"); - newLink.setAttribute("href", css.url); - attachStylesheetLink(newLink); - }); + if (newCss.length !== 0) { + _.each(newCss, function (css) { + var newLink = document.createElement("link"); + newLink.setAttribute("rel", "stylesheet"); + newLink.setAttribute("type", "text/css"); + newLink.setAttribute("class", "__meteor-css__"); + newLink.setAttribute("href", css.url); + attachStylesheetLink(newLink); + }); + } else { + removeOldLinks(); + } + } else if (doc._id === 'version' && doc.version !== autoupdateVersion) { handle && handle.stop(); From 03a53fef6328882ad2a2c2df8f9c140219c9a6b7 Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Wed, 10 Sep 2014 02:23:01 +0200 Subject: [PATCH 3/5] Fix css hot code push self test Previous tests assumed that there were at least one stylesheet, which is no more true --- .../css-injection-test/css-injection-test.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/tests/apps/css-injection-test/css-injection-test.js b/tools/tests/apps/css-injection-test/css-injection-test.js index c78d3f3bdd..89eb2f3c5b 100644 --- a/tools/tests/apps/css-injection-test/css-injection-test.js +++ b/tools/tests/apps/css-injection-test/css-injection-test.js @@ -3,10 +3,20 @@ if (Meteor.isClient) { return $(document.body).css('background-color'); }; + var linkHref = function () { + var links = document.getElementsByTagName('link'); + if (links.length > 0) { + return links[0].href; + } else { + return null; + } + } + Meteor.startup(function () { Meteor.call("clientLoad"); var numCssChanges = 0; var oldBackgroundColor = backgroundColor(); + var oldLinkHref = linkHref(); Meteor.call("newStylesheet", numCssChanges, oldBackgroundColor); var waitingForCssReloadToComplete = false; Meteor.setInterval(function () { @@ -19,10 +29,10 @@ if (Meteor.isClient) { // give the client some time to load the new css var handle = Meteor.setInterval(function () { - var numberLinks = document.getElementsByTagName('link').length; - if (numberLinks === 1) { - // numberLinks will be 1 once the old css link is removed. + var newLinkHref = linkHref(); + if (newLinkHref !== oldLinkHref) { oldBackgroundColor = backgroundColor(); + oldLinkHref = newLinkHref; Meteor.call("newStylesheet", ++numCssChanges, oldBackgroundColor); waitingForCssReloadToComplete = false; Meteor.clearInterval(handle); From 05507080f628b80b2da87c900a06451ca1ba1f60 Mon Sep 17 00:00:00 2001 From: Sashko Stubailo Date: Wed, 10 Sep 2014 09:46:30 -0700 Subject: [PATCH 4/5] Make JSDoc like 100 times faster by searching files with grep first --- scripts/admin/jsdoc/docdata-jsdoc-template/publish.js | 2 +- scripts/admin/jsdoc/jsdoc.sh | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/admin/jsdoc/docdata-jsdoc-template/publish.js b/scripts/admin/jsdoc/docdata-jsdoc-template/publish.js index 3c5ba95571..87cd41fba2 100644 --- a/scripts/admin/jsdoc/docdata-jsdoc-template/publish.js +++ b/scripts/admin/jsdoc/docdata-jsdoc-template/publish.js @@ -12,7 +12,7 @@ /** * Get a tag dictionary from the tags field on the object, for custom fields * like package - * @param {JSDoc object} data The thing you get in the TaffyDB from JSDoc + * @param {JSDocData} data The thing you get in the TaffyDB from JSDoc * @return {Object} Keys are the parameter names, values are the values. */ var getTagDict = function (data) { diff --git a/scripts/admin/jsdoc/jsdoc.sh b/scripts/admin/jsdoc/jsdoc.sh index 65a2e6713a..98f5f97c42 100755 --- a/scripts/admin/jsdoc/jsdoc.sh +++ b/scripts/admin/jsdoc/jsdoc.sh @@ -5,10 +5,12 @@ cd $(dirname $0) cd ../../.. TOPDIR=$(pwd) +INFINITY=10000 + cd $TOPDIR -${TOPDIR}/dev_bundle/bin/node \ +git grep -al "@summary" | xargs -L ${INFINITY} -t \ + ${TOPDIR}/dev_bundle/bin/node \ ${TOPDIR}/dev_bundle/lib/node_modules/.bin/jsdoc \ -t "${TOPDIR}/scripts/admin/jsdoc/docdata-jsdoc-template" \ - -c "${TOPDIR}/scripts/admin/jsdoc/jsdoc-conf.json" \ - -r "${TOPDIR}/packages" "${TOPDIR}/tools" + -c "${TOPDIR}/scripts/admin/jsdoc/jsdoc-conf.json" \ No newline at end of file From c69447b03ce5e30b21ebb763bbdc7f3d340551b7 Mon Sep 17 00:00:00 2001 From: Sashko Stubailo Date: Wed, 10 Sep 2014 09:54:26 -0700 Subject: [PATCH 5/5] Add comment explaining change --- scripts/admin/jsdoc/jsdoc.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/admin/jsdoc/jsdoc.sh b/scripts/admin/jsdoc/jsdoc.sh index 98f5f97c42..223479c083 100755 --- a/scripts/admin/jsdoc/jsdoc.sh +++ b/scripts/admin/jsdoc/jsdoc.sh @@ -9,6 +9,9 @@ INFINITY=10000 cd $TOPDIR +# Call git grep to find all js files with the appropriate comment tags, +# and only then pass it to JSDoc which will parse the JS files. +# This is a whole lot faster than calling JSDoc recursively. git grep -al "@summary" | xargs -L ${INFINITY} -t \ ${TOPDIR}/dev_bundle/bin/node \ ${TOPDIR}/dev_bundle/lib/node_modules/.bin/jsdoc \