1- import { readFileSync } from 'fs' ;
1+ import { promises as fs } from 'fs' ;
22import { resolve } from 'path' ;
3- import process from 'process' ;
3+ import { env } from 'process' ;
44import alias from '@rollup/plugin-alias' ;
55import commonjs from '@rollup/plugin-commonjs' ;
66import json from '@rollup/plugin-json' ;
@@ -17,26 +17,29 @@ import getLicenseHandler from './build-plugins/generate-license-file';
1717import replaceBrowserModules from './build-plugins/replace-browser-modules' ;
1818import { version } from './package.json' ;
1919
20- const commitHash = ( function ( ) {
20+ async function getBanner ( ) : Promise < string > {
21+ let commitHash : string ;
22+
2123 try {
22- return readFileSync ( '.commithash' , 'utf-8 ' ) ;
24+ commitHash = await fs . readFile ( '.commithash' , 'utf8 ' ) ;
2325 } catch {
24- return 'unknown' ;
26+ commitHash = 'unknown' ;
2527 }
26- } ) ( ) ;
2728
28- const { SOURCE_DATE_EPOCH } = process . env ;
29- const now = new Date ( SOURCE_DATE_EPOCH ? 1000 * + SOURCE_DATE_EPOCH : Date . now ( ) ) . toUTCString ( ) ;
29+ const date = new Date (
30+ env . SOURCE_DATE_EPOCH ? 1000 * + env . SOURCE_DATE_EPOCH : Date . now ( )
31+ ) . toUTCString ( ) ;
3032
31- const banner = `/*
33+ return `/*
3234 @license
3335 Rollup.js v${ version }
34- ${ now } - commit ${ commitHash }
36+ ${ date } - commit ${ commitHash }
3537
3638 https://github.com/rollup/rollup
3739
3840 Released under the MIT License.
3941*/` ;
42+ }
4043
4144const onwarn : WarningHandlerWithDefault = warning => {
4245 // eslint-disable-next-line no-console
@@ -75,8 +78,12 @@ const nodePlugins = [
7578 typescript ( )
7679] ;
7780
78- export default ( command : Record < string , unknown > ) : RollupOptions | RollupOptions [ ] => {
81+ export default async function (
82+ command : Record < string , unknown >
83+ ) : Promise < RollupOptions | RollupOptions [ ] > {
84+ const banner = await getBanner ( ) ;
7985 const { collectLicenses, writeLicense } = getLicenseHandler ( ) ;
86+
8087 const commonJSBuild : RollupOptions = {
8188 // 'fsevents' is a dependency of 'chokidar' that cannot be bundled as it contains binary code
8289 external : [ 'fsevents' ] ,
@@ -150,4 +157,4 @@ export default (command: Record<string, unknown>): RollupOptions | RollupOptions
150157 } ;
151158
152159 return [ commonJSBuild , esmBuild , browserBuilds ] ;
153- } ;
160+ }
0 commit comments