22import chalk from 'chalk' ;
33import rollup , { type MergedRollupOptions } from 'rollup' ;
44import {
5- type BatchWarnings ,
65 type LoadConfigFile ,
76 loadConfigFile as _loadConfigFile ,
87} from 'rollup/loadConfigFile' ;
@@ -25,7 +24,9 @@ interface BuildPackageOptions {
2524/**
2625 * Builds packages using rollup for the current directory
2726 */
28- export function buildPackage ( { verbose } : BuildPackageOptions ) {
27+ export async function buildPackage ( {
28+ verbose,
29+ } : BuildPackageOptions ) : Promise < void > {
2930 const packageDir = process . cwd ( ) ;
3031
3132 const splitPath = packageDir . split ( '/' ) ;
@@ -36,61 +37,56 @@ export function buildPackage({ verbose }: BuildPackageOptions) {
3637 const rollupConfigPath = findRollupConfigFile ( packageName , { verbose } ) ;
3738
3839 // load the rollup config file, and run rollup
39- loadConfigFile ( rollupConfigPath , { } ) . then (
40- async ( {
41- options,
42- warnings,
43- } : {
44- options : Array < MergedRollupOptions > ;
45- warnings : BatchWarnings ;
46- } ) => {
47- verbose &&
48- console . log (
49- `Building ${ packageName } with the following config:` ,
50- options . map ( config => ( {
51- input : config . input ,
52- output : config . output [ 0 ] . dir ?? config . output [ 0 ] . file ,
53- } ) ) ,
54- ) ;
40+ const { options, warnings } = await loadConfigFile ( rollupConfigPath , { } ) ;
5541
56- if ( warnings . count > 0 ) {
57- if ( verbose ) {
58- // This prints all deferred warnings
59- warnings . flush ( ) ;
60- } else {
61- console . log (
62- warnings . count + ' build warnings. Run with `--verbose` for more' ,
63- ) ;
64- }
65- }
42+ if ( verbose ) {
43+ console . log (
44+ `Building ${ packageName } with the following config:` ,
45+ options . map ( config => ( {
46+ input : config . input ,
47+ output : config . output [ 0 ] . dir ?? config . output [ 0 ] . file ,
48+ } ) ) ,
49+ ) ;
50+ }
6651
67- for ( const optionsObj of options ) {
68- const config : MergedRollupOptions = {
69- ...optionsObj ,
70- logLevel : verbose ? 'debug' : 'warn' ,
71- } ;
52+ if ( warnings . count > 0 ) {
53+ if ( verbose ) {
54+ // This prints all deferred warnings
55+ warnings . flush ( ) ;
56+ } else {
57+ console . log (
58+ warnings . count + ' build warnings. Run with `--verbose` for more' ,
59+ ) ;
60+ }
61+ }
7262
73- // Log the bundle stats in verbose mode
74- if ( verbose ) {
75- config . plugins . push (
76- bundleStats ( {
77- html : false ,
78- json : false ,
79- compare : false ,
80- } ) ,
81- ) ;
82- }
63+ for ( const optionsObj of options ) {
64+ const config : MergedRollupOptions = {
65+ ...optionsObj ,
66+ logLevel : verbose ? 'debug' : 'warn' ,
67+ } ;
8368
84- const bundle = await rollup . rollup ( config ) ;
69+ // Log the bundle stats in verbose mode
70+ if ( verbose ) {
71+ config . plugins . push (
72+ bundleStats ( {
73+ html : false ,
74+ json : false ,
75+ compare : false ,
76+ } ) ,
77+ ) ;
78+ }
8579
86- verbose &&
87- console . log (
88- `${ chalk . bold ( optionsObj . input ) } > ${ chalk . bold (
89- optionsObj . output . map ( obj => obj . dir || obj . file ) ,
90- ) } `,
91- ) ;
92- await Promise . all ( optionsObj . output . map ( bundle . write ) ) ;
93- }
94- } ,
95- ) ;
80+ const bundle = await rollup . rollup ( config ) ;
81+
82+ if ( verbose ) {
83+ console . log (
84+ `${ chalk . bold ( optionsObj . input ) } > ${ chalk . bold (
85+ optionsObj . output . map ( obj => obj . dir || obj . file ) ,
86+ ) } `,
87+ ) ;
88+ }
89+
90+ await Promise . all ( optionsObj . output . map ( bundle . write ) ) ;
91+ }
9692}
0 commit comments