refactor(ivy): ngcc - extract file writing out into a class (#29092)

This is in preparation of having different file writing strategies.

PR Close #29092
This commit is contained in:
Pete Bacon Darwin
2019-03-20 13:47:59 +00:00
committed by Matias Niemelä
parent a827bc2e3a
commit 849b327986
6 changed files with 159 additions and 17 deletions

View File

@ -18,6 +18,8 @@ import {EntryPointFormat, EntryPointJsonProperty, SUPPORTED_FORMAT_PROPERTIES, g
import {makeEntryPointBundle} from './packages/entry_point_bundle';
import {EntryPointFinder} from './packages/entry_point_finder';
import {Transformer} from './packages/transformer';
import {FileWriter} from './writing/file_writer';
import {InPlaceFileWriter} from './writing/in_place_file_writer';
/**
@ -62,6 +64,7 @@ export function mainNgcc({basePath, targetEntryPointPath,
const host = new DependencyHost();
const resolver = new DependencyResolver(host);
const finder = new EntryPointFinder(resolver);
const fileWriter = getFileWriter();
const absoluteTargetEntryPointPath = targetEntryPointPath ?
AbsoluteFsPath.from(resolve(basePath, targetEntryPointPath)) :
@ -116,7 +119,8 @@ export function mainNgcc({basePath, targetEntryPointPath,
compiledFormats.size === 0);
if (bundle) {
console.warn(`Compiling ${entryPoint.name} : ${property} as ${format}`);
transformer.transform(bundle);
const transformedFiles = transformer.transform(bundle);
fileWriter.writeBundle(entryPoint, bundle, transformedFiles);
compiledFormats.add(formatPath);
} else {
console.warn(
@ -139,3 +143,7 @@ export function mainNgcc({basePath, targetEntryPointPath,
}
});
}
function getFileWriter(): FileWriter {
return new InPlaceFileWriter();
}