From e86570bc2a39020cb4a8f79dd2e6b94034c87253 Mon Sep 17 00:00:00 2001 From: notlee Date: Fri, 15 May 2020 16:53:53 +0100 Subject: [PATCH] Allow Sass sourcemaps to be disabled. For example, whilst running compilation tests: https://github.com/Financial-Times/origami-build-tools/pull/780 --- lib/tasks/build-sass.js | 4 +++- test/unit/tasks/build-sass.test.js | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/tasks/build-sass.js b/lib/tasks/build-sass.js index 345cc5a7..6650da1b 100644 --- a/lib/tasks/build-sass.js +++ b/lib/tasks/build-sass.js @@ -59,7 +59,9 @@ module.exports = function buildSass(config) { if (sassFile) { const destFolder = config.buildFolder || files.getBuildFolderPath(cwd); const dest = config.buildCss || 'main.css'; - const useSourceMaps = config.sourcemaps || true; + const useSourceMaps = typeof config.sourcemaps === 'boolean' ? + config.sourcemaps : + true; const sassData = getSassData(sassFile, { brand: config.brand, sassPrefix: config.sassPrefix, diff --git a/test/unit/tasks/build-sass.test.js b/test/unit/tasks/build-sass.test.js index 59765e5d..08a956c9 100644 --- a/test/unit/tasks/build-sass.test.js +++ b/test/unit/tasks/build-sass.test.js @@ -153,4 +153,27 @@ describe('Build Sass', function () { proclaim.include(result, 'div {\n color: blue;\n}'); }); }); + + it('should output source maps by default', function () { + return build({ + sass: 'demos/src/demo-scss/demo.scss' + }) + .then(function (result) { + const builtCss = fs.readFileSync('build/main.css', 'utf8'); + proclaim.include(builtCss, '/*# sourceMappingURL='); + proclaim.include(result, '/*# sourceMappingURL='); + }); + }); + + it('should not not output a source map when the sourcemaps option is false', function () { + return build({ + sass: 'demos/src/demo-scss/demo.scss', + sourcemaps: false + }) + .then(function (result) { + const builtCss = fs.readFileSync('build/main.css', 'utf8'); + proclaim.doesNotInclude(builtCss, '/*# sourceMappingURL='); + proclaim.doesNotInclude(result, '/*# sourceMappingURL='); + }); + }); });