22"use strict" ;
33
44let generateTranspiler = require ( "./babel" ) ;
5+ let { debug } = require ( "../util" ) ;
56let { loadExtension, abort, repr } = require ( "faucet-pipeline-core/lib/util" ) ;
6- let commonjs = require ( "rollup-plugin-commonjs" ) ;
7- let nodeResolve = require ( "rollup-plugin-node-resolve" ) ;
7+ let COMMONJS = "rollup-plugin-commonjs" ;
8+ let commonjs = require ( COMMONJS ) ;
9+ let NODE_RESOLVE = "rollup-plugin-node-resolve" ;
10+ let nodeResolve = require ( NODE_RESOLVE ) ;
811
912let MODULE_FORMATS = { // maps faucet identifiers to Rollup identifiers
1013 esm : true ,
@@ -62,9 +65,11 @@ function generateConfig({ extensions = [], // eslint-disable-next-line indent
6265 if ( esnext || jsx ) {
6366 let transpiler = Object . assign ( { } , esnext , jsx ) ;
6467 if ( esnext ) {
68+ debug ( "ESNext transpilation" ) ;
6569 transpiler . esnext = true ;
6670 }
6771 if ( jsx ) {
72+ debug ( "JSX transpilation" ) ;
6873 // just to be safe, discard JSX-specifics on parent object
6974 delete transpiler . pragma ;
7075 delete transpiler . fragment ;
@@ -86,11 +91,15 @@ function generateConfig({ extensions = [], // eslint-disable-next-line indent
8691 plugins . push ( plugin ) ;
8792 }
8893 if ( typescript ) {
89- let ts = loadExtension ( "rollup-plugin-typescript2" ,
90- "failed to activate TypeScript" , "faucet-pipeline-typescript" ) ;
94+ debug ( "TypeScript transpilation" ) ;
95+ let plugin = "rollup-plugin-typescript2" ;
96+ let ts = loadExtension ( plugin , "failed to activate TypeScript" ,
97+ "faucet-pipeline-typescript" ) ;
9198 extensions . push ( ".ts" ) ;
9299 // TODO: provide defaults and abstractions for low-level options?
93- plugins . push ( typescript === true ? ts ( ) : ts ( typescript ) ) ;
100+ let config = typescript === true ? [ ] : [ typescript ] ; // spread arguments
101+ plugins . push ( ts ( ...config ) ) ;
102+ debug ( "plugin:" , plugin , ...config ) ;
94103 }
95104
96105 let resolve = {
@@ -100,11 +109,13 @@ function generateConfig({ extensions = [], // eslint-disable-next-line indent
100109 if ( extensions . length ) {
101110 resolve . extensions = [ ".js" ] . concat ( extensions ) ;
102111 }
112+ plugins . push ( nodeResolve ( resolve ) ) ;
113+ debug ( "plugin:" , NODE_RESOLVE , resolve ) ;
114+
115+ let _cfg = { include : "node_modules/**" } ;
116+ plugins . push ( commonjs ( _cfg ) ) ;
117+ debug ( "plugin:" , COMMONJS , _cfg ) ;
103118
104- plugins = plugins . concat ( [
105- nodeResolve ( resolve ) ,
106- commonjs ( { include : "node_modules/**" } )
107- ] ) ;
108119 if ( compact ) {
109120 cfg . compact = true ;
110121 plugins = plugins . concat ( determineCompacting ( compact ) ) ;
@@ -125,6 +136,7 @@ function generateConfig({ extensions = [], // eslint-disable-next-line indent
125136 cfg . globals = externals ;
126137 }
127138
139+ debug ( "Rollup configuration:" , cfg ) ;
128140 // distinguish between (roughly) read and write settings
129141 let read = [ "external" , "plugins" ] ;
130142 return Object . keys ( cfg ) . reduce ( ( memo , key ) => {
@@ -157,7 +169,9 @@ function determineCompacting(type = true) {
157169 switch ( type ) {
158170 case true : // default
159171 case "compact" :
160- return require ( "rollup-plugin-cleanup" ) ( ) ;
172+ var plugin = "rollup-plugin-cleanup" ; // eslint-disable-line no-var
173+ debug ( "plugin:" , plugin ) ;
174+ return require ( plugin ) ( ) ;
161175 case "minify" :
162176 var options = { compress : false , mangle : false } ; // eslint-disable-line no-var
163177 break ;
@@ -168,8 +182,10 @@ function determineCompacting(type = true) {
168182 abort ( `unknown compacting option ${ type } ` ) ;
169183 }
170184
171- let { terser } = loadExtension ( "rollup-plugin-terser" ,
172- "failed to activate minification" , "faucet-pipeline-jsmin" ) ;
185+ plugin = "rollup-plugin-terser" ;
186+ let { terser } = loadExtension ( plugin , "failed to activate minification" ,
187+ "faucet-pipeline-jsmin" ) ;
188+ debug ( "plugin:" , plugin , options ) ;
173189 return terser ( options ) ;
174190}
175191
0 commit comments