@@ -11,6 +11,8 @@ import {readFileSync} from 'fs';
11
11
12
12
import { AbsoluteFsPath } from '../../src/ngtsc/path' ;
13
13
14
+ import { ConsoleLogger , LogLevel } from './logging/console_logger' ;
15
+ import { Logger } from './logging/logger' ;
14
16
import { hasBeenProcessed , markAsProcessed } from './packages/build_marker' ;
15
17
import { DependencyHost } from './packages/dependency_host' ;
16
18
import { DependencyResolver } from './packages/dependency_resolver' ;
@@ -23,6 +25,7 @@ import {InPlaceFileWriter} from './writing/in_place_file_writer';
23
25
import { NewEntryPointFileWriter } from './writing/new_entry_point_file_writer' ;
24
26
25
27
28
+
26
29
/**
27
30
* The options to configure the ngcc compiler.
28
31
*/
@@ -50,6 +53,10 @@ export interface NgccOptions {
50
53
* Whether to create new entry-points bundles rather than overwriting the original files.
51
54
*/
52
55
createNewEntryPointFormats ?: boolean ;
56
+ /**
57
+ * Provide a logger that will be called with log messages.
58
+ */
59
+ logger ?: Logger ;
53
60
}
54
61
55
62
const SUPPORTED_FORMATS : EntryPointFormat [ ] = [ 'esm5' , 'esm2015' ] ;
@@ -62,13 +69,14 @@ const SUPPORTED_FORMATS: EntryPointFormat[] = ['esm5', 'esm2015'];
62
69
*
63
70
* @param options The options telling ngcc what to compile and how.
64
71
*/
65
- export function mainNgcc (
66
- { basePath, targetEntryPointPath, propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES ,
67
- compileAllFormats = true , createNewEntryPointFormats = false } : NgccOptions ) : void {
68
- const transformer = new Transformer ( basePath ) ;
72
+ export function mainNgcc ( { basePath, targetEntryPointPath,
73
+ propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES ,
74
+ compileAllFormats = true , createNewEntryPointFormats = false ,
75
+ logger = new ConsoleLogger ( LogLevel . info ) } : NgccOptions ) : void {
76
+ const transformer = new Transformer ( logger , basePath ) ;
69
77
const host = new DependencyHost ( ) ;
70
- const resolver = new DependencyResolver ( host ) ;
71
- const finder = new EntryPointFinder ( resolver ) ;
78
+ const resolver = new DependencyResolver ( logger , host ) ;
79
+ const finder = new EntryPointFinder ( logger , resolver ) ;
72
80
const fileWriter = getFileWriter ( createNewEntryPointFormats ) ;
73
81
74
82
const absoluteTargetEntryPointPath = targetEntryPointPath ?
@@ -112,7 +120,7 @@ export function mainNgcc(
112
120
113
121
if ( hasBeenProcessed ( entryPointPackageJson , property ) ) {
114
122
compiledFormats . add ( formatPath ) ;
115
- console . warn ( `Skipping ${ entryPoint . name } : ${ property } (already compiled).` ) ;
123
+ logger . info ( `Skipping ${ entryPoint . name } : ${ property } (already compiled).` ) ;
116
124
continue ;
117
125
}
118
126
@@ -123,16 +131,16 @@ export function mainNgcc(
123
131
entryPoint . path , formatPath , entryPoint . typings , isCore , property , format ,
124
132
compiledFormats . size === 0 ) ;
125
133
if ( bundle ) {
126
- console . warn ( `Compiling ${ entryPoint . name } : ${ property } as ${ format } ` ) ;
134
+ logger . info ( `Compiling ${ entryPoint . name } : ${ property } as ${ format } ` ) ;
127
135
const transformedFiles = transformer . transform ( bundle ) ;
128
136
fileWriter . writeBundle ( entryPoint , bundle , transformedFiles ) ;
129
137
compiledFormats . add ( formatPath ) ;
130
138
} else {
131
- console . warn (
139
+ logger . warn (
132
140
`Skipping ${ entryPoint . name } : ${ format } (no valid entry point file for this format).` ) ;
133
141
}
134
142
} else if ( ! compileAllFormats ) {
135
- console . warn ( `Skipping ${ entryPoint . name } : ${ property } (already compiled).` ) ;
143
+ logger . info ( `Skipping ${ entryPoint . name } : ${ property } (already compiled).` ) ;
136
144
}
137
145
138
146
// Either this format was just compiled or its underlying format was compiled because of a
0 commit comments