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 ) ) ;
@@ -157,7 +168,9 @@ function determineCompacting(type = true) {
157168 switch ( type ) {
158169 case true : // default
159170 case "compact" :
160- return require ( "rollup-plugin-cleanup" ) ( ) ;
171+ var plugin = "rollup-plugin-cleanup" ; // eslint-disable-line no-var
172+ debug ( "plugin:" , plugin ) ;
173+ return require ( plugin ) ( ) ;
161174 case "minify" :
162175 var options = { compress : false , mangle : false } ; // eslint-disable-line no-var
163176 break ;
@@ -168,8 +181,10 @@ function determineCompacting(type = true) {
168181 abort ( `unknown compacting option ${ type } ` ) ;
169182 }
170183
171- let { terser } = loadExtension ( "rollup-plugin-terser" ,
172- "failed to activate minification" , "faucet-pipeline-jsmin" ) ;
184+ plugin = "rollup-plugin-terser" ;
185+ let { terser } = loadExtension ( plugin , "failed to activate minification" ,
186+ "faucet-pipeline-jsmin" ) ;
187+ debug ( "plugin:" , plugin , options ) ;
173188 return terser ( options ) ;
174189}
175190
0 commit comments