From 79c959d8b143d949cb12c7132d3969f9d25563ef Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Wed, 23 Nov 2022 23:46:04 +0000 Subject: [PATCH] Allow Sass compilation to restart after `gulp dev` errors --- package-lock.json | 126 ++++++++++++++++++++++++---------- package.json | 1 + tasks/gulp/compile-assets.mjs | 18 ++++- tasks/task-arguments.mjs | 1 + 4 files changed, 108 insertions(+), 38 deletions(-) diff --git a/package-lock.json b/package-lock.json index b5ceca263e..b61b0a0753 100644 --- a/package-lock.json +++ b/package-lock.json @@ -39,6 +39,7 @@ "minimatch": "^5.1.0", "node-sass": "^8.0.0", "nunjucks": "^3.2.3", + "plugin-error": "^2.0.0", "postcss": "^8.4.19", "postcss-pseudo-classes": "^0.2.1", "postcss-scss": "^4.0.5", @@ -10489,6 +10490,48 @@ "vinyl-sourcemaps-apply": "^0.2.1" } }, + "node_modules/gulp-better-rollup/node_modules/arr-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/arr-union/-/arr-union-2.1.0.tgz", + "integrity": "sha512-t5db90jq+qdgk8aFnxEkjqta0B/GHrM1pxzuuZz2zWsOXc5nKu3t+76s/PQBA8FTcM/ipspIH9jWG4OxCBc2eA==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/gulp-better-rollup/node_modules/extend-shallow": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-1.1.4.tgz", + "integrity": "sha512-L7AGmkO6jhDkEBBGWlLtftA80Xq8DipnrRPr0pyi7GQLXkaq9JYA4xF4z6qnadIC6euiTDKco0cGSU9muw+WTw==", + "dependencies": { + "kind-of": "^1.1.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/gulp-better-rollup/node_modules/kind-of": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", + "integrity": "sha512-aUH6ElPnMGon2/YkxRIigV32MOpTVcoXQ1Oo8aYn40s+sJ3j+0gFZsT8HKDcxNy7Fi9zuquWtGaGAahOdv5p/g==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/gulp-better-rollup/node_modules/plugin-error": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/plugin-error/-/plugin-error-0.1.2.tgz", + "integrity": "sha512-WzZHcm4+GO34sjFMxQMqZbsz3xiNEgonCskQ9v+IroMmYgk/tas8dG+Hr2D6IbRPybZ12oWpzE/w3cGJ6FJzOw==", + "dependencies": { + "ansi-cyan": "^0.1.1", + "ansi-red": "^0.1.1", + "arr-diff": "^1.0.1", + "arr-union": "^2.0.1", + "extend-shallow": "^1.1.2" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/gulp-better-rollup/node_modules/replace-ext": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-1.0.1.tgz", @@ -10855,6 +10898,14 @@ "node": ">=0.10.0" } }, + "node_modules/gulp-plumber/node_modules/arr-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/arr-union/-/arr-union-2.1.0.tgz", + "integrity": "sha512-t5db90jq+qdgk8aFnxEkjqta0B/GHrM1pxzuuZz2zWsOXc5nKu3t+76s/PQBA8FTcM/ipspIH9jWG4OxCBc2eA==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/gulp-plumber/node_modules/chalk": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", @@ -10870,6 +10921,40 @@ "node": ">=0.10.0" } }, + "node_modules/gulp-plumber/node_modules/extend-shallow": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-1.1.4.tgz", + "integrity": "sha512-L7AGmkO6jhDkEBBGWlLtftA80Xq8DipnrRPr0pyi7GQLXkaq9JYA4xF4z6qnadIC6euiTDKco0cGSU9muw+WTw==", + "dependencies": { + "kind-of": "^1.1.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/gulp-plumber/node_modules/kind-of": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", + "integrity": "sha512-aUH6ElPnMGon2/YkxRIigV32MOpTVcoXQ1Oo8aYn40s+sJ3j+0gFZsT8HKDcxNy7Fi9zuquWtGaGAahOdv5p/g==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/gulp-plumber/node_modules/plugin-error": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/plugin-error/-/plugin-error-0.1.2.tgz", + "integrity": "sha512-WzZHcm4+GO34sjFMxQMqZbsz3xiNEgonCskQ9v+IroMmYgk/tas8dG+Hr2D6IbRPybZ12oWpzE/w3cGJ6FJzOw==", + "dependencies": { + "ansi-cyan": "^0.1.1", + "ansi-red": "^0.1.1", + "arr-diff": "^1.0.1", + "arr-union": "^2.0.1", + "extend-shallow": "^1.1.2" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/gulp-plumber/node_modules/strip-ansi": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", @@ -17971,45 +18056,14 @@ } }, "node_modules/plugin-error": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/plugin-error/-/plugin-error-0.1.2.tgz", - "integrity": "sha512-WzZHcm4+GO34sjFMxQMqZbsz3xiNEgonCskQ9v+IroMmYgk/tas8dG+Hr2D6IbRPybZ12oWpzE/w3cGJ6FJzOw==", - "dependencies": { - "ansi-cyan": "^0.1.1", - "ansi-red": "^0.1.1", - "arr-diff": "^1.0.1", - "arr-union": "^2.0.1", - "extend-shallow": "^1.1.2" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/plugin-error/node_modules/arr-union": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/arr-union/-/arr-union-2.1.0.tgz", - "integrity": "sha512-t5db90jq+qdgk8aFnxEkjqta0B/GHrM1pxzuuZz2zWsOXc5nKu3t+76s/PQBA8FTcM/ipspIH9jWG4OxCBc2eA==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/plugin-error/node_modules/extend-shallow": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-1.1.4.tgz", - "integrity": "sha512-L7AGmkO6jhDkEBBGWlLtftA80Xq8DipnrRPr0pyi7GQLXkaq9JYA4xF4z6qnadIC6euiTDKco0cGSU9muw+WTw==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/plugin-error/-/plugin-error-2.0.0.tgz", + "integrity": "sha512-o4bwIOmuFwUg2MU6xt7plGEQY3YyENx6kvwaFZBrUpamA91FdS9w3U+pU0y4OuDoBQe+jf3RLGSfQebSRBEVsQ==", "dependencies": { - "kind-of": "^1.1.0" + "ansi-colors": "^1.0.1" }, "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/plugin-error/node_modules/kind-of": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", - "integrity": "sha512-aUH6ElPnMGon2/YkxRIigV32MOpTVcoXQ1Oo8aYn40s+sJ3j+0gFZsT8HKDcxNy7Fi9zuquWtGaGAahOdv5p/g==", - "engines": { - "node": ">=0.10.0" + "node": ">=10.13.0" } }, "node_modules/posix-character-classes": { diff --git a/package.json b/package.json index 6cebea9d8e..08cb68103b 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "minimatch": "^5.1.0", "node-sass": "^8.0.0", "nunjucks": "^3.2.3", + "plugin-error": "^2.0.0", "postcss": "^8.4.19", "postcss-pseudo-classes": "^0.2.1", "postcss-scss": "^4.0.5", diff --git a/tasks/gulp/compile-assets.mjs b/tasks/gulp/compile-assets.mjs index 4ce8f8d214..b1340f0a1f 100644 --- a/tasks/gulp/compile-assets.mjs +++ b/tasks/gulp/compile-assets.mjs @@ -12,12 +12,13 @@ import uglify from 'gulp-uglify' import merge from 'merge-stream' import minimatch from 'minimatch' import nodeSass from 'node-sass' +import PluginError from 'plugin-error' import slash from 'slash' import configPaths from '../../config/paths.js' import { getListing } from '../../lib/file-helper.js' import { componentNameToJavaScriptModuleName } from '../../lib/helper-functions.js' -import { destination, isDist, isPackage } from '../task-arguments.mjs' +import { destination, isDev, isDist, isPackage } from '../task-arguments.mjs' const sass = gulpSass(nodeSass) @@ -82,9 +83,22 @@ compileStylesheets.displayName = 'compile:scss' */ function compileStylesheet (stream, options = {}) { return stream - .pipe(plumber()) + .pipe(plumber(function (cause) { + const error = new PluginError('gulp-sass', cause.messageFormatted) + error.showProperties = false + + // Gulp continue (watch) + if (isDev) { + console.error(error.toString()) + return this.emit('end') + } + + // Gulp exit with error + return stream.emit('error', error) + })) .pipe(sass(options)) .pipe(postcss()) + .pipe(plumber.stop()) } /** diff --git a/tasks/task-arguments.mjs b/tasks/task-arguments.mjs index 48fb9987a6..f6fa76971c 100644 --- a/tasks/task-arguments.mjs +++ b/tasks/task-arguments.mjs @@ -35,3 +35,4 @@ export const destination = destPath export const isPackage = target === 'package' export const isPublic = target === 'public' export const isDist = target === 'dist' +export const isDev = isPublic && tasks.includes('dev')