From be2f339fc4d07524d74342da2a1cd2b4639865ec Mon Sep 17 00:00:00 2001 From: erezrokah Date: Wed, 15 Jul 2020 13:01:39 +0300 Subject: [PATCH 1/2] fix(function-builder): report build errors --- src/commands/dev/index.js | 46 ++++++++++++++++++++++++------------ src/utils/serve-functions.js | 1 + 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/commands/dev/index.js b/src/commands/dev/index.js index 6771705f51c..b93984984fb 100644 --- a/src/commands/dev/index.js +++ b/src/commands/dev/index.js @@ -431,6 +431,33 @@ async function startDevServer(settings, log) { return ps } +const getBuildFunction = functionBuilder => + async function build() { + this.log( + `${NETLIFYDEVLOG} Function builder ${chalk.yellow(functionBuilder.builderName)} ${chalk.magenta( + 'building' + )} functions from ${chalk.yellow(functionBuilder.src)}` + ) + + try { + await functionBuilder.build() + this.log( + `${NETLIFYDEVLOG} Function builder ${chalk.yellow(functionBuilder.builderName)} ${chalk.green( + 'finished' + )} building functions from ${chalk.yellow(functionBuilder.src)}` + ) + } catch (error) { + const errorMessage = (error.stderr && error.stderr.toString()) || error.message + this.log( + `${NETLIFYDEVLOG} Function builder ${chalk.yellow(functionBuilder.builderName)} ${chalk.red( + 'failed' + )} building functions from ${chalk.yellow(functionBuilder.src)}${ + errorMessage ? ` with error:\n${errorMessage}` : '' + }` + ) + } + } + class DevCommand extends Command { async run() { this.log(`${NETLIFYDEV}`) @@ -492,21 +519,10 @@ class DevCommand extends Command { `${NETLIFYDEVWARN} This is a beta feature, please give us feedback on how to improve at https://github.com/netlify/cli/` ) - const debouncedBuild = debounce( - async () => { - this.log( - `${NETLIFYDEVLOG} Function builder ${chalk.yellow( - functionBuilder.builderName - )} building functions from ${chalk.yellow(functionBuilder.src)}` - ) - await functionBuilder.build() - }, - 300, - { - leading: true, - trailing: true, - } - ) + const debouncedBuild = debounce(getBuildFunction(functionBuilder).bind(this), 300, { + leading: true, + trailing: true, + }) await debouncedBuild() diff --git a/src/utils/serve-functions.js b/src/utils/serve-functions.js index b2c2c8d26b6..daea606b38c 100644 --- a/src/utils/serve-functions.js +++ b/src/utils/serve-functions.js @@ -108,6 +108,7 @@ function createHandler(dir) { Object.keys(require.cache).forEach(k => { delete require.cache[k] }) + console.log(`${NETLIFYDEVLOG} ${path} ${action}, successfully reloaded!`) } const watcher = chokidar.watch(dir, { ignored: /node_modules/ }) watcher.on('change', clearCache('modified')).on('unlink', clearCache('deleted')) From d1d14973a991d9f9b4fccb62375634884bb91869 Mon Sep 17 00:00:00 2001 From: erezrokah Date: Wed, 15 Jul 2020 13:13:47 +0300 Subject: [PATCH 2/2] fix(function-builder): improve log messages --- src/commands/dev/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/dev/index.js b/src/commands/dev/index.js index b93984984fb..78d95625f5d 100644 --- a/src/commands/dev/index.js +++ b/src/commands/dev/index.js @@ -436,7 +436,7 @@ const getBuildFunction = functionBuilder => this.log( `${NETLIFYDEVLOG} Function builder ${chalk.yellow(functionBuilder.builderName)} ${chalk.magenta( 'building' - )} functions from ${chalk.yellow(functionBuilder.src)}` + )} functions from directory ${chalk.yellow(functionBuilder.src)}` ) try { @@ -444,14 +444,14 @@ const getBuildFunction = functionBuilder => this.log( `${NETLIFYDEVLOG} Function builder ${chalk.yellow(functionBuilder.builderName)} ${chalk.green( 'finished' - )} building functions from ${chalk.yellow(functionBuilder.src)}` + )} building functions from directory ${chalk.yellow(functionBuilder.src)}` ) } catch (error) { const errorMessage = (error.stderr && error.stderr.toString()) || error.message this.log( `${NETLIFYDEVLOG} Function builder ${chalk.yellow(functionBuilder.builderName)} ${chalk.red( 'failed' - )} building functions from ${chalk.yellow(functionBuilder.src)}${ + )} building functions from directory ${chalk.yellow(functionBuilder.src)}${ errorMessage ? ` with error:\n${errorMessage}` : '' }` )