@@ -27,10 +27,11 @@ module.exports = async function jetRunnerRollup({ testPath, config }) {
2727 ) ;
2828 if ( inputFile . hasError ) return inputFile . error ;
2929
30- const { pkgHook, formatHook, ...rollupConfig } = cfg ;
31- const hooks = {
32- pkgHook : typeof pkgHook === 'function' ? pkgHook : ( ) => { } ,
33- formatHook : typeof formatHook === 'function' ? formatHook : ( x ) => x ,
30+ const { hooks, ...rollupConfig } = cfg ;
31+ const allHooks = {
32+ onPkg : typeof hooks . onPkg === 'function' ? hooks . onPkg : ( ) => { } ,
33+ onFormat : typeof hooks . onFormat === 'function' ? hooks . onFormat : ( x ) => x ,
34+ onWrite : typeof hooks . onWrite === 'function' ? hooks . onWrite : ( x ) => x ,
3435 } ;
3536
3637 /** Rull that bundle */
@@ -58,48 +59,63 @@ module.exports = async function jetRunnerRollup({ testPath, config }) {
5859
5960 const outputFile = path . join ( pkgRoot , dist , path . basename ( opts . file ) ) ;
6061
61- return hooks . formatHook ( {
62+ return hooker ( allHooks . onFormat , {
6263 outputOptions : { ...opts , dist, file : outputFile } ,
63- testPath,
6464 pkgRoot,
65+ testPath,
66+ inputFile,
6567 } ) ;
6668 } ) ;
6769
70+ // console.log('all outputs:', await Promise.all(outputOptions));
6871 /** Write output file for each format */
6972 const res = await tryCatch ( inputFile , start , ( ) =>
7073 Promise . all (
71- outputOptions . map ( ( { outputOptions : outOpts } ) =>
72- bundle
73- . write ( outOpts )
74- /** If bundled without problems, print the output file filename */
75- . then ( async ( ) =>
76- pass ( {
77- start,
78- end : Date . now ( ) ,
79- test : {
80- path : outOpts . file ,
81- title : 'Rollup' ,
82- } ,
83- } ) ,
84- )
85- . catch ( ( err ) => {
86- /** If there is problem bundling, re-throw appending output filename */
87- err . outputFile = outOpts . file ;
88- throw err ;
89- } ) ,
90- ) ,
74+ outputOptions . map ( async ( ctx ) => {
75+ const { outputOptions : outOpts } = await ctx ;
76+
77+ const opts = await hooker ( allHooks . onWrite , {
78+ outputOptions : outOpts ,
79+ pkgRoot,
80+ testPath,
81+ inputFile,
82+ } ) ;
83+
84+ return (
85+ bundle
86+ . write ( opts . outputOptions )
87+ /** If bundled without problems, print the output file filename */
88+ . then ( async ( ) =>
89+ pass ( {
90+ start,
91+ end : Date . now ( ) ,
92+ test : {
93+ path : opts . outputOptions . file ,
94+ title : 'Rollup' ,
95+ } ,
96+ } ) ,
97+ )
98+ . catch ( ( err ) => {
99+ /** If there is problem bundling, re-throw appending output filename */
100+ err . outputFile = opts . outputOptions . file ;
101+ throw err ;
102+ } )
103+ ) ;
104+ } ) ,
91105 )
92106 /** Bundling process for each format completed successfuly */
93107 . then ( async ( testRes ) => {
94- await hooks . pkgHook ( {
108+ await hooker ( allHooks . onPkg , {
109+ jestConfig : config ,
95110 rollupConfig : {
96111 ...rollupConfig ,
97112 output : outputOptions ,
98113 } ,
99114 pkgRoot,
100115 testPath,
101- jestConfig : config ,
116+ inputFile ,
102117 } ) ;
118+
103119 return testRes ;
104120 } )
105121 /** Bundling for some of the formats failed */
@@ -216,3 +232,14 @@ function tryExtensions(filepath, config) {
216232
217233 return filepath + extension ;
218234}
235+
236+ async function hooker ( hookFn , options = { } ) {
237+ const hookResult = await hookFn ( { ...options } ) ;
238+ const res = { ...hookResult } ;
239+
240+ if ( res . outputOptions ) {
241+ return { ...options , ...res } ;
242+ }
243+
244+ return { ...options , outputOptions : res } ;
245+ }
0 commit comments