'use strict'

const rollup = require('rollup').rollup
const assign = require('object-assign')


function createPreprocessor (options, preconfig, logger) {

	const log = logger.create('preprocessor.rollup')

	let cache

	return (content, file, done) => {
		const config = assign({}, options, preconfig.options,
			{
				input: file.path,
				cache,
			}
		)

		rollup(config)
			.then(bundle => {
				cache = bundle
				return bundle.generate(config)
			})
			.then(generated => {
				let output = generated.code
				if (config.sourcemap === 'inline') {
					output += `\n//# sourceMappingURL=${generated.map.toUrl()}\n`
				}
				done(null, output)
			})
			.catch(error => {
				log.error('Error processing %s\n\n%s\n', file.path, error.message)
				done(error, null)
			})
	}
}

createPreprocessor.$inject = ['config.rollupPreprocessor', 'args', 'logger']

module.exports = {
	'preprocessor:rollup': ['factory', createPreprocessor],
}

@@ -7,16 +7,45 @@
 trict'%0A%0A
+const path = require('path')%0A
 const ro
@@ -166,16 +166,26 @@
 econfig,
+ basePath,
  logger)
@@ -704,24 +704,80 @@
 (error =%3E %7B%0A
+%09%09%09%09const location = path.relative(basePath, file.path)%0A
 %09%09%09%09log.erro
@@ -796,18 +796,20 @@
 cessing 
+%E2%80%9C
 %25s
+%E2%80%9D
 %5Cn%5Cn%25s%5Cn
@@ -811,25 +811,24 @@
 n%25s%5Cn', 
-file.path
+location
 , error.
@@ -936,16 +936,35 @@
  'args',
+ 'config.basePath',
  'logger

use relative file paths in error log output