Skip to content

Commit

Permalink
Merge pull request #4239 from alphagov/styles-watch-error
Browse files Browse the repository at this point in the history
Fix Review app Sass compile after error
  • Loading branch information
colinrotherham committed Sep 21, 2023
2 parents 298d35c + 089b280 commit 10b5b69
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
17 changes: 8 additions & 9 deletions shared/tasks/npm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ export async function run(name, args = [], options) {
throw new Error(`Task '${name}' not found in '${pkgPath}'`)
}
} catch (cause) {
const error = new Error(`Task for npm script '${name}' failed`, { cause })

// Skip errors by default to allow Gulp to resume tasks
if (['test', 'production'].includes(process.env.NODE_ENV)) {
throw new PluginError(`npm run ${name}`, error, {
showProperties: false,
showStack: false
})
// Skip Nodemon (SIGINT) exit or aborted task error codes
// https://github.com/open-cli-tools/concurrently/pull/359/files
if (cause.signal === 'SIGINT' || [130, 3221225786].includes(cause.code)) {
return
}

console.error(error.message)
throw new PluginError(`npm run ${name}`, cause, {
// Hide error properties already formatted by npm
showProperties: false
})
}
}

Expand Down
7 changes: 5 additions & 2 deletions shared/tasks/scripts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { loadConfigFile } from 'rollup/dist/loadConfigFile.js'
* Compile JavaScript task
*
* @param {string} pattern - Minimatch pattern
* @param {AssetEntry[1]} [options] - Asset options for script(s)
* @param {AssetEntry[1]} options - Asset options for script(s)
*/
export async function compile(pattern, options) {
const modulePaths = await getListing(pattern, {
Expand All @@ -21,7 +21,10 @@ export async function compile(pattern, options) {
await compileJavaScript([modulePath, options])
}
} catch (cause) {
throw new PluginError('shared/tasks/scripts', cause)
throw new PluginError(`scripts.compile('${pattern}')`, cause, {
// Show additional error properties from Babel etc
showProperties: true
})
}
}

Expand Down
9 changes: 6 additions & 3 deletions shared/tasks/styles.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { assets } from './index.mjs'
* Compile Sass to CSS task
*
* @param {string} pattern - Minimatch pattern
* @param {AssetEntry[1]} options - Asset options
* @param {AssetEntry[1]} options - Asset options for stylesheet(s)
*/
export async function compile(pattern, options) {
const modulePaths = await getListing(pattern, {
Expand All @@ -26,10 +26,13 @@ export async function compile(pattern, options) {

try {
for (const modulePath of modulePaths) {
compileStylesheet([modulePath, options])
await compileStylesheet([modulePath, options])
}
} catch (cause) {
throw new PluginError('shared/tasks/styles', cause)
throw new PluginError(`styles.compile('${pattern}')`, cause, {
// Hide error properties already formatted by Sass
showProperties: false
})
}
}

Expand Down

0 comments on commit 10b5b69

Please sign in to comment.