From 9290ea7a06b3662abd0a3126a5c2e7bf29d12f1c Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Wed, 10 Oct 2018 14:13:23 -0400 Subject: [PATCH 1/3] Ignore inline source maps when minifying CSS files. https://github.com/meteor/meteor/issues/10112#issuecomment-428646872 Further down in the mergeCss function, when we call CssTools.stringifyCss, we pass the following option: // don't try to read the referenced sourcemaps from the input inputSourcemaps: false Apparently this isn't enough to avoid reading inline source maps from the input file, so we should be a bit more aggressive about preventing postcss from picking up inline source maps. This change mostly affects .css files imported from node_modules, and possibly raw .css files in the application that happen to have inline sourceMappingURL= comments. For CSS output from compiler plugins like LESS and SCSS, we have a totally different mechanism of handling source maps, namely file.getSourceMap(). Should fix #10112. --- packages/standard-minifier-css/plugin/minify-css.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/standard-minifier-css/plugin/minify-css.js b/packages/standard-minifier-css/plugin/minify-css.js index bef5274b94..5a1b962b73 100644 --- a/packages/standard-minifier-css/plugin/minify-css.js +++ b/packages/standard-minifier-css/plugin/minify-css.js @@ -51,6 +51,11 @@ var hashFiles = Profile("hashFiles", function (files) { return hash.digest("hex"); }); +function disableSourceMappingURLs(css) { + return css.replace(/# sourceMappingURL=/g, + "# sourceMappingURL_DISABLED="); +} + // Lints CSS files and merges them into one file, fixing up source maps and // pulling any @import directives up to the top since the CSS spec does not // allow them to appear in the middle of a file. @@ -69,7 +74,8 @@ var mergeCss = Profile("mergeCss", function (css) { originals[filename] = file; try { var parseOptions = { source: filename, position: true }; - var ast = CssTools.parseCss(file.getContentsAsString(), parseOptions); + var css = disableSourceMappingURLs(file.getContentsAsString()); + var ast = CssTools.parseCss(css, parseOptions); ast.filename = filename; } catch (e) { if (e.reason) { From b7267b76a199ba651c3029b5ae7e30fba2f52d4f Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Wed, 10 Oct 2018 16:39:38 -0400 Subject: [PATCH 2/3] Use null for sourcesContent[i] if sources[i] unrecognized. Should help with #10112. --- packages/standard-minifier-css/plugin/minify-css.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/standard-minifier-css/plugin/minify-css.js b/packages/standard-minifier-css/plugin/minify-css.js index 5a1b962b73..da99c0cc1c 100644 --- a/packages/standard-minifier-css/plugin/minify-css.js +++ b/packages/standard-minifier-css/plugin/minify-css.js @@ -120,7 +120,8 @@ var mergeCss = Profile("mergeCss", function (css) { // Add the contents of the input files to the source map of the new file stringifiedCss.map.sourcesContent = stringifiedCss.map.sources.map(function (filename) { - return originals[filename].getContentsAsString(); + const file = originals[filename] || null; + return file && file.getContentsAsString(); }); // Compose the concatenated file's source map with source maps from the From 3f30d2208fe0dacfde9563d4dac1e37a45cba1bc Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Wed, 10 Oct 2018 16:40:22 -0400 Subject: [PATCH 3/3] Bump standard-minifier-css patch version to 1.5.1. --- packages/standard-minifier-css/package.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/standard-minifier-css/package.js b/packages/standard-minifier-css/package.js index 5dde075548..d9ea6588f0 100644 --- a/packages/standard-minifier-css/package.js +++ b/packages/standard-minifier-css/package.js @@ -1,6 +1,6 @@ Package.describe({ name: 'standard-minifier-css', - version: '1.5.0', + version: '1.5.1', summary: 'Standard css minifier used with Meteor apps by default.', documentation: 'README.md' });