From 138d255af45209716b2c11ca549125a76219227e Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Wed, 8 Jun 2016 11:49:50 -0400 Subject: [PATCH] on second thoughts, dont auto-install. will cause problems in many cases --- bin/getRollupWatch.js | 43 --------------------------------- bin/handleError.js | 2 +- bin/runRollup.js | 55 +++++++++++++++++++++++-------------------- 3 files changed, 31 insertions(+), 69 deletions(-) delete mode 100644 bin/getRollupWatch.js diff --git a/bin/getRollupWatch.js b/bin/getRollupWatch.js deleted file mode 100644 index d830023..0000000 --- a/bin/getRollupWatch.js +++ /dev/null @@ -1,43 +0,0 @@ -var chalk = require( 'chalk' ); -var relative = require( 'require-relative' ); - -module.exports = function getRollupWatch () { - try { - watch = relative( 'rollup-watch', process.cwd() ); - return Promise.resolve( watch ); - } catch ( err ) { - if ( err.code === 'MODULE_NOT_FOUND' ) { - return installRollupWatch().then( () => { - return relative( 'rollup-watch', process.cwd() ); - }); - } else { - return Promise.reject( err ); - } - } -}; - -function installRollupWatch () { - console.error( 'rollup --watch depends on the rollup-watch package, which could not be found. You can install it globally with ' + chalk.cyan( 'npm install -g rollup-watch' ) + '. Do this now? ' + chalk.green.bold( '[y/n]' ) ); - - process.stdin.setEncoding( 'utf8' ); - - return new Promise( ( fulfil, reject ) => { - process.stdin.on( 'readable', function () { - var chunk = process.stdin.read(); - if ( !chunk ) return; - - if ( /^y(?:es)?$/i.test( chunk ) ) { - console.error( 'installing rollup-watch...' ); - child = require( 'child_process' ).exec( 'npm install --global rollup-watch', err => { - if ( err ) { - reject( err ); - } else { - fulfil(); - } - }); - } else { - reject( new Error( 'aborted' ) ); - } - }); - }); -} diff --git a/bin/handleError.js b/bin/handleError.js index 33ee847..21a100d 100644 --- a/bin/handleError.js +++ b/bin/handleError.js @@ -30,7 +30,7 @@ var handlers = { }, ROLLUP_WATCH_NOT_INSTALLED: function ( err ) { - console.error( chalk.red( 'failed to find or install rollup-watch' ) ); + console.error( chalk.red( 'rollup --watch depends on the rollup-watch package, which could not be found. You can install it globally (recommended) with ' ) + chalk.cyan( 'npm install -g rollup-watch' ) ); }, WATCHER_MISSING_INPUT_OR_OUTPUT: function ( err ) { diff --git a/bin/runRollup.js b/bin/runRollup.js index 91a3df4..20b6264 100644 --- a/bin/runRollup.js +++ b/bin/runRollup.js @@ -1,8 +1,8 @@ require( 'source-map-support' ).install(); var path = require( 'path' ); +var relative = require( 'require-relative' ); var handleError = require( './handleError' ); -var getRollupWatch = require( './getRollupWatch' ); var chalk = require( 'chalk' ); var rollup = require( '../' ); @@ -134,30 +134,35 @@ function execute ( options, command ) { handleError({ code: 'WATCHER_MISSING_INPUT_OR_OUTPUT' }); } - getRollupWatch() - .then( watch => { - const watcher = watch( rollup, options ); - - watcher.on( 'event', event => { - switch ( event.code ) { - case 'STARTING': - console.error( 'checking rollup-watch version...' ); - break; - - case 'BUILD_START': - console.error( 'bundling...' ); - break; - - case 'BUILD_END': - console.error( 'bundled in ' + event.duration + 'ms. Watching for changes...' ); - break; - - default: - console.error( 'unknown event', event ); - } - }); - }) - .catch( handleError ); + try { + var watch = relative( 'rollup-watch', process.cwd() ); + var watcher = watch( rollup, options ); + + watcher.on( 'event', event => { + switch ( event.code ) { + case 'STARTING': + console.error( 'checking rollup-watch version...' ); + break; + + case 'BUILD_START': + console.error( 'bundling...' ); + break; + + case 'BUILD_END': + console.error( 'bundled in ' + event.duration + 'ms. Watching for changes...' ); + break; + + default: + console.error( 'unknown event', event ); + } + }); + } catch ( err ) { + if ( err.code === 'MODULE_NOT_FOUND' ) { + err.code = 'ROLLUP_WATCH_NOT_INSTALLED'; + } + + handleError( err ); + } } else { bundle( options ).catch( handleError ); }