refactor(ivy): ngcc - remove `formatProperty` from `EntryPointBundle` (#32052)

Remove the `formatProperty` property from the `EntryPointBundle`
interface, because the property is not directly related to that type.

It was only used in one place, when calling `fileWriter.writeBundle()`,
but we can pass `formatProperty` directrly to `writeBundle()`.

PR Close #32052
This commit is contained in:
George Kalpakas 2019-08-08 02:19:52 +03:00 committed by Alex Rickabaugh
parent ef12e10e59
commit ed70f73794
19 changed files with 194 additions and 155 deletions

View File

@ -166,13 +166,12 @@ export function mainNgcc(
} }
const bundle = makeEntryPointBundle( const bundle = makeEntryPointBundle(
fileSystem, entryPoint, formatPath, isCore, formatProperty, format, processDts, fileSystem, entryPoint, formatPath, isCore, format, processDts, pathMappings, true);
pathMappings, true);
logger.info(`Compiling ${entryPoint.name} : ${formatProperty} as ${format}`); logger.info(`Compiling ${entryPoint.name} : ${formatProperty} as ${format}`);
const transformedFiles = transformer.transform(bundle); const transformedFiles = transformer.transform(bundle);
fileWriter.writeBundle(entryPoint, bundle, transformedFiles); fileWriter.writeBundle(entryPoint, bundle, transformedFiles, formatProperty);
onTaskCompleted(task, TaskProcessingOutcome.Processed); onTaskCompleted(task, TaskProcessingOutcome.Processed);
}; };

View File

@ -10,7 +10,7 @@ import {AbsoluteFsPath, FileSystem, absoluteFrom} from '../../../src/ngtsc/file_
import {NgtscCompilerHost} from '../../../src/ngtsc/file_system/src/compiler_host'; import {NgtscCompilerHost} from '../../../src/ngtsc/file_system/src/compiler_host';
import {PathMappings} from '../utils'; import {PathMappings} from '../utils';
import {BundleProgram, makeBundleProgram} from './bundle_program'; import {BundleProgram, makeBundleProgram} from './bundle_program';
import {EntryPoint, EntryPointFormat, EntryPointJsonProperty} from './entry_point'; import {EntryPoint, EntryPointFormat} from './entry_point';
import {NgccSourcesCompilerHost} from './ngcc_compiler_host'; import {NgccSourcesCompilerHost} from './ngcc_compiler_host';
/** /**
@ -19,7 +19,6 @@ import {NgccSourcesCompilerHost} from './ngcc_compiler_host';
*/ */
export interface EntryPointBundle { export interface EntryPointBundle {
entryPoint: EntryPoint; entryPoint: EntryPoint;
formatProperty: EntryPointJsonProperty;
format: EntryPointFormat; format: EntryPointFormat;
isCore: boolean; isCore: boolean;
isFlatCore: boolean; isFlatCore: boolean;
@ -34,7 +33,6 @@ export interface EntryPointBundle {
* @param entryPoint The entry-point that contains the bundle. * @param entryPoint The entry-point that contains the bundle.
* @param formatPath The path to the source files for this bundle. * @param formatPath The path to the source files for this bundle.
* @param isCore This entry point is the Angular core package. * @param isCore This entry point is the Angular core package.
* @param formatProperty The property in the package.json that holds the formatPath.
* @param format The underlying format of the bundle. * @param format The underlying format of the bundle.
* @param transformDts Whether to transform the typings along with this bundle. * @param transformDts Whether to transform the typings along with this bundle.
* @param pathMappings An optional set of mappings to use when compiling files. * @param pathMappings An optional set of mappings to use when compiling files.
@ -43,8 +41,8 @@ export interface EntryPointBundle {
*/ */
export function makeEntryPointBundle( export function makeEntryPointBundle(
fs: FileSystem, entryPoint: EntryPoint, formatPath: string, isCore: boolean, fs: FileSystem, entryPoint: EntryPoint, formatPath: string, isCore: boolean,
formatProperty: EntryPointJsonProperty, format: EntryPointFormat, transformDts: boolean, format: EntryPointFormat, transformDts: boolean, pathMappings?: PathMappings,
pathMappings?: PathMappings, mirrorDtsFromSrc: boolean = false): EntryPointBundle { mirrorDtsFromSrc: boolean = false): EntryPointBundle {
// Create the TS program and necessary helpers. // Create the TS program and necessary helpers.
const options: ts.CompilerOptions = { const options: ts.CompilerOptions = {
allowJs: true, allowJs: true,
@ -69,7 +67,7 @@ export function makeEntryPointBundle(
null; null;
const isFlatCore = isCore && src.r3SymbolsFile === null; const isFlatCore = isCore && src.r3SymbolsFile === null;
return {entryPoint, format, formatProperty, rootDirs, isCore, isFlatCore, src, dts}; return {entryPoint, format, rootDirs, isCore, isFlatCore, src, dts};
} }
function computePotentialDtsFilesFromJsFiles( function computePotentialDtsFilesFromJsFiles(

View File

@ -6,7 +6,7 @@
* Use of this source code is governed by an MIT-style license that can be * Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {EntryPoint} from '../packages/entry_point'; import {EntryPoint, EntryPointJsonProperty} from '../packages/entry_point';
import {EntryPointBundle} from '../packages/entry_point_bundle'; import {EntryPointBundle} from '../packages/entry_point_bundle';
import {FileToWrite} from '../rendering/utils'; import {FileToWrite} from '../rendering/utils';
@ -14,6 +14,7 @@ import {FileToWrite} from '../rendering/utils';
* Responsible for writing out the transformed files to disk. * Responsible for writing out the transformed files to disk.
*/ */
export interface FileWriter { export interface FileWriter {
writeBundle(entryPoint: EntryPoint, bundle: EntryPointBundle, transformedFiles: FileToWrite[]): writeBundle(
void; entryPoint: EntryPoint, bundle: EntryPointBundle, transformedFiles: FileToWrite[],
formatProperty: EntryPointJsonProperty): void;
} }

View File

@ -7,7 +7,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {FileSystem, absoluteFrom, dirname} from '../../../src/ngtsc/file_system'; import {FileSystem, absoluteFrom, dirname} from '../../../src/ngtsc/file_system';
import {EntryPoint} from '../packages/entry_point'; import {EntryPoint, EntryPointJsonProperty} from '../packages/entry_point';
import {EntryPointBundle} from '../packages/entry_point_bundle'; import {EntryPointBundle} from '../packages/entry_point_bundle';
import {FileToWrite} from '../rendering/utils'; import {FileToWrite} from '../rendering/utils';
import {FileWriter} from './file_writer'; import {FileWriter} from './file_writer';
@ -19,7 +19,9 @@ import {FileWriter} from './file_writer';
export class InPlaceFileWriter implements FileWriter { export class InPlaceFileWriter implements FileWriter {
constructor(protected fs: FileSystem) {} constructor(protected fs: FileSystem) {}
writeBundle(_entryPoint: EntryPoint, _bundle: EntryPointBundle, transformedFiles: FileToWrite[]) { writeBundle(
_entryPoint: EntryPoint, _bundle: EntryPointBundle, transformedFiles: FileToWrite[],
_formatProperty?: EntryPointJsonProperty) {
transformedFiles.forEach(file => this.writeFileAndBackup(file)); transformedFiles.forEach(file => this.writeFileAndBackup(file));
} }

View File

@ -25,12 +25,14 @@ const NGCC_DIRECTORY = '__ivy_ngcc__';
* `InPlaceFileWriter`). * `InPlaceFileWriter`).
*/ */
export class NewEntryPointFileWriter extends InPlaceFileWriter { export class NewEntryPointFileWriter extends InPlaceFileWriter {
writeBundle(entryPoint: EntryPoint, bundle: EntryPointBundle, transformedFiles: FileToWrite[]) { writeBundle(
entryPoint: EntryPoint, bundle: EntryPointBundle, transformedFiles: FileToWrite[],
formatProperty: EntryPointJsonProperty) {
// The new folder is at the root of the overall package // The new folder is at the root of the overall package
const ngccFolder = join(entryPoint.package, NGCC_DIRECTORY); const ngccFolder = join(entryPoint.package, NGCC_DIRECTORY);
this.copyBundle(bundle, entryPoint.package, ngccFolder); this.copyBundle(bundle, entryPoint.package, ngccFolder);
transformedFiles.forEach(file => this.writeFile(file, entryPoint.package, ngccFolder)); transformedFiles.forEach(file => this.writeFile(file, entryPoint.package, ngccFolder));
this.updatePackageJson(entryPoint, bundle.formatProperty, ngccFolder); this.updatePackageJson(entryPoint, formatProperty, ngccFolder);
} }
protected copyBundle( protected copyBundle(

View File

@ -96,8 +96,7 @@ runInEachFileSystem(() => {
loadTestFiles(testFiles); loadTestFiles(testFiles);
loadFakeCore(getFileSystem()); loadFakeCore(getFileSystem());
const rootFiles = getRootFiles(testFiles); const rootFiles = getRootFiles(testFiles);
const bundle = const bundle = makeTestEntryPointBundle('test-package', 'esm2015', false, rootFiles);
makeTestEntryPointBundle('test-package', 'es2015', 'esm2015', false, rootFiles);
program = bundle.src.program; program = bundle.src.program;
const reflectionHost = const reflectionHost =
@ -373,4 +372,4 @@ class MockMigration implements Migration {
this.log.push(`${this.name}:${clazz.name.text}`); this.log.push(`${this.name}:${clazz.name.text}`);
return null; return null;
} }
} }

View File

@ -330,7 +330,7 @@ runInEachFileSystem(() => {
loadTestFiles(TEST_PROGRAM); loadTestFiles(TEST_PROGRAM);
loadTestFiles(TEST_DTS_PROGRAM); loadTestFiles(TEST_DTS_PROGRAM);
const bundle = makeTestEntryPointBundle( const bundle = makeTestEntryPointBundle(
'test-package', 'esm2015', 'esm2015', false, getRootFiles(TEST_PROGRAM), 'test-package', 'esm2015', false, getRootFiles(TEST_PROGRAM),
getRootFiles(TEST_DTS_PROGRAM)); getRootFiles(TEST_DTS_PROGRAM));
program = bundle.src.program; program = bundle.src.program;
dtsProgram = bundle.dts; dtsProgram = bundle.dts;

View File

@ -236,8 +236,7 @@ runInEachFileSystem(() => {
loadTestFiles(jsProgram); loadTestFiles(jsProgram);
loadTestFiles(dtsProgram); loadTestFiles(dtsProgram);
const {src: {program}, dts} = makeTestEntryPointBundle( const {src: {program}, dts} = makeTestEntryPointBundle(
'test-package', 'esm2015', 'esm2015', false, getRootFiles(jsProgram), 'test-package', 'esm2015', false, getRootFiles(jsProgram), getRootFiles(dtsProgram));
getRootFiles(dtsProgram));
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts); const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker(), dts);
const referencesRegistry = new NgccReferencesRegistry(host); const referencesRegistry = new NgccReferencesRegistry(host);
const analyzer = new PrivateDeclarationsAnalyzer(host, referencesRegistry); const analyzer = new PrivateDeclarationsAnalyzer(host, referencesRegistry);

View File

@ -72,7 +72,7 @@ runInEachFileSystem(() => {
it('should check for switchable markers in all the files of the program', () => { it('should check for switchable markers in all the files of the program', () => {
loadTestFiles(TEST_PROGRAM); loadTestFiles(TEST_PROGRAM);
const bundle = makeTestEntryPointBundle( const bundle = makeTestEntryPointBundle(
'test', 'esm2015', 'esm2015', false, [_('/node_modules/test/entrypoint.js')]); 'test', 'esm2015', false, [_('/node_modules/test/entrypoint.js')]);
const program = bundle.src.program; const program = bundle.src.program;
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
const analyzer = new SwitchMarkerAnalyzer(host, bundle.entryPoint.package); const analyzer = new SwitchMarkerAnalyzer(host, bundle.entryPoint.package);
@ -103,7 +103,7 @@ runInEachFileSystem(() => {
it('should ignore files that are outside the package', () => { it('should ignore files that are outside the package', () => {
loadTestFiles(TEST_PROGRAM); loadTestFiles(TEST_PROGRAM);
const bundle = makeTestEntryPointBundle( const bundle = makeTestEntryPointBundle(
'test', 'esm2015', 'esm2015', false, [_('/node_modules/test/entrypoint.js')]); 'test', 'esm2015', false, [_('/node_modules/test/entrypoint.js')]);
const program = bundle.src.program; const program = bundle.src.program;
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
const analyzer = new SwitchMarkerAnalyzer(host, bundle.entryPoint.package); const analyzer = new SwitchMarkerAnalyzer(host, bundle.entryPoint.package);
@ -114,4 +114,4 @@ runInEachFileSystem(() => {
}); });
}); });
}); });
}); });

View File

@ -9,7 +9,7 @@ import * as ts from 'typescript';
import {AbsoluteFsPath, NgtscCompilerHost, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system'; import {AbsoluteFsPath, NgtscCompilerHost, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
import {TestFile} from '../../../src/ngtsc/file_system/testing'; import {TestFile} from '../../../src/ngtsc/file_system/testing';
import {BundleProgram, makeBundleProgram} from '../../src/packages/bundle_program'; import {BundleProgram, makeBundleProgram} from '../../src/packages/bundle_program';
import {EntryPoint, EntryPointFormat, EntryPointJsonProperty} from '../../src/packages/entry_point'; import {EntryPoint, EntryPointFormat} from '../../src/packages/entry_point';
import {EntryPointBundle} from '../../src/packages/entry_point_bundle'; import {EntryPointBundle} from '../../src/packages/entry_point_bundle';
import {NgccSourcesCompilerHost} from '../../src/packages/ngcc_compiler_host'; import {NgccSourcesCompilerHost} from '../../src/packages/ngcc_compiler_host';
@ -32,19 +32,13 @@ export function makeTestEntryPoint(
* @param dtsFiles The typings files to include the bundle. * @param dtsFiles The typings files to include the bundle.
*/ */
export function makeTestEntryPointBundle( export function makeTestEntryPointBundle(
packageName: string, formatProperty: EntryPointJsonProperty, format: EntryPointFormat, packageName: string, format: EntryPointFormat, isCore: boolean, srcRootNames: AbsoluteFsPath[],
isCore: boolean, srcRootNames: AbsoluteFsPath[],
dtsRootNames?: AbsoluteFsPath[]): EntryPointBundle { dtsRootNames?: AbsoluteFsPath[]): EntryPointBundle {
const entryPoint = makeTestEntryPoint(packageName); const entryPoint = makeTestEntryPoint(packageName);
const src = makeTestBundleProgram(srcRootNames[0], isCore); const src = makeTestBundleProgram(srcRootNames[0], isCore);
const dts = dtsRootNames ? makeTestDtsBundleProgram(dtsRootNames[0], isCore) : null; const dts = dtsRootNames ? makeTestDtsBundleProgram(dtsRootNames[0], isCore) : null;
const isFlatCore = isCore && src.r3SymbolsFile === null; const isFlatCore = isCore && src.r3SymbolsFile === null;
return { return {entryPoint, format, rootDirs: [absoluteFrom('/')], src, dts, isCore, isFlatCore};
entryPoint,
formatProperty,
format,
rootDirs: [absoluteFrom('/')], src, dts, isCore, isFlatCore
};
} }
export function makeTestBundleProgram( export function makeTestBundleProgram(

View File

@ -161,7 +161,7 @@ runInEachFileSystem(() => {
loadFakeCore(getFileSystem()); loadFakeCore(getFileSystem());
const errors: ts.Diagnostic[] = []; const errors: ts.Diagnostic[] = [];
const rootFiles = getRootFiles(testFiles); const rootFiles = getRootFiles(testFiles);
const bundle = makeTestEntryPointBundle('test-package', 'es2015', 'esm2015', false, rootFiles); const bundle = makeTestEntryPointBundle('test-package', 'esm2015', false, rootFiles);
const program = bundle.src.program; const program = bundle.src.program;
const reflectionHost = const reflectionHost =

View File

@ -144,8 +144,7 @@ runInEachFileSystem(() => {
typings: absoluteFrom('/node_modules/test/index.d.ts'), typings: absoluteFrom('/node_modules/test/index.d.ts'),
compiledByAngular: true, compiledByAngular: true,
}; };
const esm5bundle = const esm5bundle = makeEntryPointBundle(fs, entryPoint, './index.js', false, 'esm5', true);
makeEntryPointBundle(fs, entryPoint, './index.js', false, 'esm5', 'esm5', true);
expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName)) expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName))
.toEqual(jasmine.arrayWithExactContents([ .toEqual(jasmine.arrayWithExactContents([
@ -192,7 +191,7 @@ runInEachFileSystem(() => {
compiledByAngular: true, compiledByAngular: true,
}; };
const esm5bundle = makeEntryPointBundle( const esm5bundle = makeEntryPointBundle(
fs, entryPoint, './index.js', false, 'esm5', 'esm5', /* transformDts */ true, fs, entryPoint, './index.js', false, 'esm5', /* transformDts */ true,
/* pathMappings */ undefined, /* mirrorDtsFromSrc */ true); /* pathMappings */ undefined, /* mirrorDtsFromSrc */ true);
expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName)) expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName))
.toContain(absoluteFrom('/node_modules/test/internal.js')); .toContain(absoluteFrom('/node_modules/test/internal.js'));
@ -213,7 +212,7 @@ runInEachFileSystem(() => {
compiledByAngular: true, compiledByAngular: true,
}; };
const esm5bundle = makeEntryPointBundle( const esm5bundle = makeEntryPointBundle(
fs, entryPoint, './index.js', false, 'esm5', 'esm5', /* transformDts */ true, fs, entryPoint, './index.js', false, 'esm5', /* transformDts */ true,
/* pathMappings */ undefined, /* mirrorDtsFromSrc */ false); /* pathMappings */ undefined, /* mirrorDtsFromSrc */ false);
expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName)) expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName))
.toContain(absoluteFrom('/node_modules/test/internal.js')); .toContain(absoluteFrom('/node_modules/test/internal.js'));

View File

@ -149,8 +149,7 @@ exports.D = D;
loadTestFiles([file]); loadTestFiles([file]);
const fs = getFileSystem(); const fs = getFileSystem();
const logger = new MockLogger(); const logger = new MockLogger();
const bundle = const bundle = makeTestEntryPointBundle('test-package', 'commonjs', false, [file.name]);
makeTestEntryPointBundle('test-package', 'module', 'commonjs', false, [file.name]);
const typeChecker = bundle.src.program.getTypeChecker(); const typeChecker = bundle.src.program.getTypeChecker();
const host = new CommonJsReflectionHost(logger, false, bundle.src.program, bundle.src.host); const host = new CommonJsReflectionHost(logger, false, bundle.src.program, bundle.src.host);
const referencesRegistry = new NgccReferencesRegistry(host); const referencesRegistry = new NgccReferencesRegistry(host);

View File

@ -61,8 +61,7 @@ function createTestRenderer(
const fs = getFileSystem(); const fs = getFileSystem();
const isCore = packageName === '@angular/core'; const isCore = packageName === '@angular/core';
const bundle = makeTestEntryPointBundle( const bundle = makeTestEntryPointBundle(
'test-package', 'es2015', 'esm2015', isCore, getRootFiles(files), 'test-package', 'esm2015', isCore, getRootFiles(files), dtsFiles && getRootFiles(dtsFiles));
dtsFiles && getRootFiles(dtsFiles));
const typeChecker = bundle.src.program.getTypeChecker(); const typeChecker = bundle.src.program.getTypeChecker();
const host = new Esm2015ReflectionHost(logger, isCore, typeChecker, bundle.dts); const host = new Esm2015ReflectionHost(logger, isCore, typeChecker, bundle.dts);
const referencesRegistry = new NgccReferencesRegistry(host); const referencesRegistry = new NgccReferencesRegistry(host);

View File

@ -26,7 +26,7 @@ function setup(file: {name: AbsoluteFsPath, contents: string}) {
loadTestFiles([file]); loadTestFiles([file]);
const fs = getFileSystem(); const fs = getFileSystem();
const logger = new MockLogger(); const logger = new MockLogger();
const bundle = makeTestEntryPointBundle('test-package', 'module', 'esm5', false, [file.name]); const bundle = makeTestEntryPointBundle('test-package', 'esm5', false, [file.name]);
const typeChecker = bundle.src.program.getTypeChecker(); const typeChecker = bundle.src.program.getTypeChecker();
const host = new Esm5ReflectionHost(logger, false, typeChecker); const host = new Esm5ReflectionHost(logger, false, typeChecker);
const referencesRegistry = new NgccReferencesRegistry(host); const referencesRegistry = new NgccReferencesRegistry(host);

View File

@ -31,8 +31,7 @@ function setup(files: TestFile[], dtsFiles?: TestFile[]) {
} }
const logger = new MockLogger(); const logger = new MockLogger();
const bundle = makeTestEntryPointBundle( const bundle = makeTestEntryPointBundle(
'test-package', 'es2015', 'esm2015', false, getRootFiles(files), 'test-package', 'esm2015', false, getRootFiles(files), dtsFiles && getRootFiles(dtsFiles)) !;
dtsFiles && getRootFiles(dtsFiles)) !;
const typeChecker = bundle.src.program.getTypeChecker(); const typeChecker = bundle.src.program.getTypeChecker();
const host = new Esm2015ReflectionHost(logger, false, typeChecker, bundle.dts); const host = new Esm2015ReflectionHost(logger, false, typeChecker, bundle.dts);
const referencesRegistry = new NgccReferencesRegistry(host); const referencesRegistry = new NgccReferencesRegistry(host);

View File

@ -63,8 +63,7 @@ function createTestRenderer(
const fs = getFileSystem(); const fs = getFileSystem();
const isCore = packageName === '@angular/core'; const isCore = packageName === '@angular/core';
const bundle = makeTestEntryPointBundle( const bundle = makeTestEntryPointBundle(
'test-package', 'es2015', 'esm2015', isCore, getRootFiles(files), 'test-package', 'esm2015', isCore, getRootFiles(files), dtsFiles && getRootFiles(dtsFiles));
dtsFiles && getRootFiles(dtsFiles));
const typeChecker = bundle.src.program.getTypeChecker(); const typeChecker = bundle.src.program.getTypeChecker();
const host = new Esm2015ReflectionHost(logger, isCore, typeChecker, bundle.dts); const host = new Esm2015ReflectionHost(logger, isCore, typeChecker, bundle.dts);
const referencesRegistry = new NgccReferencesRegistry(host); const referencesRegistry = new NgccReferencesRegistry(host);

View File

@ -25,7 +25,7 @@ function setup(file: TestFile) {
loadTestFiles([file]); loadTestFiles([file]);
const fs = getFileSystem(); const fs = getFileSystem();
const logger = new MockLogger(); const logger = new MockLogger();
const bundle = makeTestEntryPointBundle('test-package', 'esm5', 'esm5', false, [file.name]); const bundle = makeTestEntryPointBundle('test-package', 'esm5', false, [file.name]);
const src = bundle.src; const src = bundle.src;
const host = new UmdReflectionHost(logger, false, src.program, src.host); const host = new UmdReflectionHost(logger, false, src.program, src.host);
const referencesRegistry = new NgccReferencesRegistry(host); const referencesRegistry = new NgccReferencesRegistry(host);

View File

@ -95,13 +95,16 @@ runInEachFileSystem(() => {
}); });
it('should write the modified files to a new folder', () => { it('should write the modified files to a new folder', () => {
fileWriter.writeBundle(entryPoint, esm5bundle, [ fileWriter.writeBundle(
{ entryPoint, esm5bundle,
path: _('/node_modules/test/esm5.js'), [
contents: 'export function FooTop() {} // MODIFIED' {
}, path: _('/node_modules/test/esm5.js'),
{path: _('/node_modules/test/esm5.js.map'), contents: 'MODIFIED MAPPING DATA'}, contents: 'export function FooTop() {} // MODIFIED'
]); },
{path: _('/node_modules/test/esm5.js.map'), contents: 'MODIFIED MAPPING DATA'},
],
'module');
expect(fs.readFile(_('/node_modules/test/__ivy_ngcc__/esm5.js'))) expect(fs.readFile(_('/node_modules/test/__ivy_ngcc__/esm5.js')))
.toEqual('export function FooTop() {} // MODIFIED'); .toEqual('export function FooTop() {} // MODIFIED');
expect(fs.readFile(_('/node_modules/test/esm5.js'))).toEqual('export function FooTop() {}'); expect(fs.readFile(_('/node_modules/test/esm5.js'))).toEqual('export function FooTop() {}');
@ -111,12 +114,15 @@ runInEachFileSystem(() => {
}); });
it('should also copy unmodified files in the program', () => { it('should also copy unmodified files in the program', () => {
fileWriter.writeBundle(entryPoint, esm2015bundle, [ fileWriter.writeBundle(
{ entryPoint, esm2015bundle,
path: _('/node_modules/test/es2015/foo.js'), [
contents: 'export class FooTop {} // MODIFIED' {
}, path: _('/node_modules/test/es2015/foo.js'),
]); contents: 'export class FooTop {} // MODIFIED'
},
],
'es2015');
expect(fs.readFile(_('/node_modules/test/__ivy_ngcc__/es2015/foo.js'))) expect(fs.readFile(_('/node_modules/test/__ivy_ngcc__/es2015/foo.js')))
.toEqual('export class FooTop {} // MODIFIED'); .toEqual('export class FooTop {} // MODIFIED');
expect(fs.readFile(_('/node_modules/test/es2015/foo.js'))) expect(fs.readFile(_('/node_modules/test/es2015/foo.js')))
@ -128,22 +134,28 @@ runInEachFileSystem(() => {
}); });
it('should update the package.json properties', () => { it('should update the package.json properties', () => {
fileWriter.writeBundle(entryPoint, esm5bundle, [ fileWriter.writeBundle(
{ entryPoint, esm5bundle,
path: _('/node_modules/test/esm5.js'), [
contents: 'export function FooTop() {} // MODIFIED' {
}, path: _('/node_modules/test/esm5.js'),
]); contents: 'export function FooTop() {} // MODIFIED'
},
],
'module');
expect(loadPackageJson(fs, '/node_modules/test')).toEqual(jasmine.objectContaining({ expect(loadPackageJson(fs, '/node_modules/test')).toEqual(jasmine.objectContaining({
module_ivy_ngcc: '__ivy_ngcc__/esm5.js', module_ivy_ngcc: '__ivy_ngcc__/esm5.js',
})); }));
fileWriter.writeBundle(entryPoint, esm2015bundle, [ fileWriter.writeBundle(
{ entryPoint, esm2015bundle,
path: _('/node_modules/test/es2015/foo.js'), [
contents: 'export class FooTop {} // MODIFIED' {
}, path: _('/node_modules/test/es2015/foo.js'),
]); contents: 'export class FooTop {} // MODIFIED'
},
],
'es2015');
expect(loadPackageJson(fs, '/node_modules/test')).toEqual(jasmine.objectContaining({ expect(loadPackageJson(fs, '/node_modules/test')).toEqual(jasmine.objectContaining({
module_ivy_ngcc: '__ivy_ngcc__/esm5.js', module_ivy_ngcc: '__ivy_ngcc__/esm5.js',
es2015_ivy_ngcc: '__ivy_ngcc__/es2015/index.js', es2015_ivy_ngcc: '__ivy_ngcc__/es2015/index.js',
@ -151,13 +163,16 @@ runInEachFileSystem(() => {
}); });
it('should overwrite and backup typings files', () => { it('should overwrite and backup typings files', () => {
fileWriter.writeBundle(entryPoint, esm2015bundle, [ fileWriter.writeBundle(
{ entryPoint, esm2015bundle,
path: _('/node_modules/test/index.d.ts'), [
contents: 'export declare class FooTop {} // MODIFIED' {
}, path: _('/node_modules/test/index.d.ts'),
{path: _('/node_modules/test/index.d.ts.map'), contents: 'MODIFIED MAPPING DATA'}, contents: 'export declare class FooTop {} // MODIFIED'
]); },
{path: _('/node_modules/test/index.d.ts.map'), contents: 'MODIFIED MAPPING DATA'},
],
'es2015');
expect(fs.readFile(_('/node_modules/test/index.d.ts'))) expect(fs.readFile(_('/node_modules/test/index.d.ts')))
.toEqual('export declare class FooTop {} // MODIFIED'); .toEqual('export declare class FooTop {} // MODIFIED');
expect(fs.readFile(_('/node_modules/test/index.d.ts.__ivy_ngcc_bak'))) expect(fs.readFile(_('/node_modules/test/index.d.ts.__ivy_ngcc_bak')))
@ -184,24 +199,30 @@ runInEachFileSystem(() => {
}); });
it('should write the modified file to a new folder', () => { it('should write the modified file to a new folder', () => {
fileWriter.writeBundle(entryPoint, esm5bundle, [ fileWriter.writeBundle(
{ entryPoint, esm5bundle,
path: _('/node_modules/test/a/esm5.js'), [
contents: 'export function FooA() {} // MODIFIED' {
}, path: _('/node_modules/test/a/esm5.js'),
]); contents: 'export function FooA() {} // MODIFIED'
},
],
'module');
expect(fs.readFile(_('/node_modules/test/__ivy_ngcc__/a/esm5.js'))) expect(fs.readFile(_('/node_modules/test/__ivy_ngcc__/a/esm5.js')))
.toEqual('export function FooA() {} // MODIFIED'); .toEqual('export function FooA() {} // MODIFIED');
expect(fs.readFile(_('/node_modules/test/a/esm5.js'))).toEqual('export function FooA() {}'); expect(fs.readFile(_('/node_modules/test/a/esm5.js'))).toEqual('export function FooA() {}');
}); });
it('should also copy unmodified files in the program', () => { it('should also copy unmodified files in the program', () => {
fileWriter.writeBundle(entryPoint, esm2015bundle, [ fileWriter.writeBundle(
{ entryPoint, esm2015bundle,
path: _('/node_modules/test/a/es2015/foo.js'), [
contents: 'export class FooA {} // MODIFIED' {
}, path: _('/node_modules/test/a/es2015/foo.js'),
]); contents: 'export class FooA {} // MODIFIED'
},
],
'es2015');
expect(fs.readFile(_('/node_modules/test/__ivy_ngcc__/a/es2015/foo.js'))) expect(fs.readFile(_('/node_modules/test/__ivy_ngcc__/a/es2015/foo.js')))
.toEqual('export class FooA {} // MODIFIED'); .toEqual('export class FooA {} // MODIFIED');
expect(fs.readFile(_('/node_modules/test/a/es2015/foo.js'))) expect(fs.readFile(_('/node_modules/test/a/es2015/foo.js')))
@ -213,22 +234,28 @@ runInEachFileSystem(() => {
}); });
it('should update the package.json properties', () => { it('should update the package.json properties', () => {
fileWriter.writeBundle(entryPoint, esm5bundle, [ fileWriter.writeBundle(
{ entryPoint, esm5bundle,
path: _('/node_modules/test/a/esm5.js'), [
contents: 'export function FooA() {} // MODIFIED' {
}, path: _('/node_modules/test/a/esm5.js'),
]); contents: 'export function FooA() {} // MODIFIED'
},
],
'module');
expect(loadPackageJson(fs, '/node_modules/test/a')).toEqual(jasmine.objectContaining({ expect(loadPackageJson(fs, '/node_modules/test/a')).toEqual(jasmine.objectContaining({
module_ivy_ngcc: '../__ivy_ngcc__/a/esm5.js', module_ivy_ngcc: '../__ivy_ngcc__/a/esm5.js',
})); }));
fileWriter.writeBundle(entryPoint, esm2015bundle, [ fileWriter.writeBundle(
{ entryPoint, esm2015bundle,
path: _('/node_modules/test/a/es2015/foo.js'), [
contents: 'export class FooA {} // MODIFIED' {
}, path: _('/node_modules/test/a/es2015/foo.js'),
]); contents: 'export class FooA {} // MODIFIED'
},
],
'es2015');
expect(loadPackageJson(fs, '/node_modules/test/a')).toEqual(jasmine.objectContaining({ expect(loadPackageJson(fs, '/node_modules/test/a')).toEqual(jasmine.objectContaining({
module_ivy_ngcc: '../__ivy_ngcc__/a/esm5.js', module_ivy_ngcc: '../__ivy_ngcc__/a/esm5.js',
es2015_ivy_ngcc: '../__ivy_ngcc__/a/es2015/index.js', es2015_ivy_ngcc: '../__ivy_ngcc__/a/es2015/index.js',
@ -236,12 +263,15 @@ runInEachFileSystem(() => {
}); });
it('should overwrite and backup typings files', () => { it('should overwrite and backup typings files', () => {
fileWriter.writeBundle(entryPoint, esm2015bundle, [ fileWriter.writeBundle(
{ entryPoint, esm2015bundle,
path: _('/node_modules/test/a/index.d.ts'), [
contents: 'export declare class FooA {} // MODIFIED' {
}, path: _('/node_modules/test/a/index.d.ts'),
]); contents: 'export declare class FooA {} // MODIFIED'
},
],
'es2015');
expect(fs.readFile(_('/node_modules/test/a/index.d.ts'))) expect(fs.readFile(_('/node_modules/test/a/index.d.ts')))
.toEqual('export declare class FooA {} // MODIFIED'); .toEqual('export declare class FooA {} // MODIFIED');
expect(fs.readFile(_('/node_modules/test/a/index.d.ts.__ivy_ngcc_bak'))) expect(fs.readFile(_('/node_modules/test/a/index.d.ts.__ivy_ngcc_bak')))
@ -262,12 +292,15 @@ runInEachFileSystem(() => {
}); });
it('should write the modified file to a new folder', () => { it('should write the modified file to a new folder', () => {
fileWriter.writeBundle(entryPoint, esm5bundle, [ fileWriter.writeBundle(
{ entryPoint, esm5bundle,
path: _('/node_modules/test/lib/esm5.js'), [
contents: 'export function FooB() {} // MODIFIED' {
}, path: _('/node_modules/test/lib/esm5.js'),
]); contents: 'export function FooB() {} // MODIFIED'
},
],
'module');
expect(fs.readFile(_('/node_modules/test/__ivy_ngcc__/lib/esm5.js'))) expect(fs.readFile(_('/node_modules/test/__ivy_ngcc__/lib/esm5.js')))
.toEqual('export function FooB() {} // MODIFIED'); .toEqual('export function FooB() {} // MODIFIED');
expect(fs.readFile(_('/node_modules/test/lib/esm5.js'))) expect(fs.readFile(_('/node_modules/test/lib/esm5.js')))
@ -275,12 +308,15 @@ runInEachFileSystem(() => {
}); });
it('should also copy unmodified files in the program', () => { it('should also copy unmodified files in the program', () => {
fileWriter.writeBundle(entryPoint, esm2015bundle, [ fileWriter.writeBundle(
{ entryPoint, esm2015bundle,
path: _('/node_modules/test/lib/es2015/foo.js'), [
contents: 'export class FooB {} // MODIFIED' {
}, path: _('/node_modules/test/lib/es2015/foo.js'),
]); contents: 'export class FooB {} // MODIFIED'
},
],
'es2015');
expect(fs.readFile(_('/node_modules/test/__ivy_ngcc__/lib/es2015/foo.js'))) expect(fs.readFile(_('/node_modules/test/__ivy_ngcc__/lib/es2015/foo.js')))
.toEqual('export class FooB {} // MODIFIED'); .toEqual('export class FooB {} // MODIFIED');
expect(fs.readFile(_('/node_modules/test/lib/es2015/foo.js'))) expect(fs.readFile(_('/node_modules/test/lib/es2015/foo.js')))
@ -293,43 +329,55 @@ runInEachFileSystem(() => {
it('should not copy typings files within the package (i.e. from a different entry-point)', it('should not copy typings files within the package (i.e. from a different entry-point)',
() => { () => {
fileWriter.writeBundle(entryPoint, esm2015bundle, [ fileWriter.writeBundle(
{ entryPoint, esm2015bundle,
path: _('/node_modules/test/lib/es2015/foo.js'), [
contents: 'export class FooB {} // MODIFIED' {
}, path: _('/node_modules/test/lib/es2015/foo.js'),
]); contents: 'export class FooB {} // MODIFIED'
},
],
'es2015');
expect(fs.exists(_('/node_modules/test/__ivy_ngcc__/a/index.d.ts'))).toEqual(false); expect(fs.exists(_('/node_modules/test/__ivy_ngcc__/a/index.d.ts'))).toEqual(false);
}); });
it('should not copy files outside of the package', () => { it('should not copy files outside of the package', () => {
fileWriter.writeBundle(entryPoint, esm2015bundle, [ fileWriter.writeBundle(
{ entryPoint, esm2015bundle,
path: _('/node_modules/test/lib/es2015/foo.js'), [
contents: 'export class FooB {} // MODIFIED' {
}, path: _('/node_modules/test/lib/es2015/foo.js'),
]); contents: 'export class FooB {} // MODIFIED'
},
],
'es2015');
expect(fs.exists(_('/node_modules/test/other/index.d.ts'))).toEqual(false); expect(fs.exists(_('/node_modules/test/other/index.d.ts'))).toEqual(false);
expect(fs.exists(_('/node_modules/test/events/events.js'))).toEqual(false); expect(fs.exists(_('/node_modules/test/events/events.js'))).toEqual(false);
}); });
it('should update the package.json properties', () => { it('should update the package.json properties', () => {
fileWriter.writeBundle(entryPoint, esm5bundle, [ fileWriter.writeBundle(
{ entryPoint, esm5bundle,
path: _('/node_modules/test/lib/esm5.js'), [
contents: 'export function FooB() {} // MODIFIED' {
}, path: _('/node_modules/test/lib/esm5.js'),
]); contents: 'export function FooB() {} // MODIFIED'
},
],
'module');
expect(loadPackageJson(fs, '/node_modules/test/b')).toEqual(jasmine.objectContaining({ expect(loadPackageJson(fs, '/node_modules/test/b')).toEqual(jasmine.objectContaining({
module_ivy_ngcc: '../__ivy_ngcc__/lib/esm5.js', module_ivy_ngcc: '../__ivy_ngcc__/lib/esm5.js',
})); }));
fileWriter.writeBundle(entryPoint, esm2015bundle, [ fileWriter.writeBundle(
{ entryPoint, esm2015bundle,
path: _('/node_modules/test/lib/es2015/foo.js'), [
contents: 'export class FooB {} // MODIFIED' {
}, path: _('/node_modules/test/lib/es2015/foo.js'),
]); contents: 'export class FooB {} // MODIFIED'
},
],
'es2015');
expect(loadPackageJson(fs, '/node_modules/test/b')).toEqual(jasmine.objectContaining({ expect(loadPackageJson(fs, '/node_modules/test/b')).toEqual(jasmine.objectContaining({
module_ivy_ngcc: '../__ivy_ngcc__/lib/esm5.js', module_ivy_ngcc: '../__ivy_ngcc__/lib/esm5.js',
es2015_ivy_ngcc: '../__ivy_ngcc__/lib/es2015/index.js', es2015_ivy_ngcc: '../__ivy_ngcc__/lib/es2015/index.js',
@ -337,12 +385,15 @@ runInEachFileSystem(() => {
}); });
it('should overwrite and backup typings files', () => { it('should overwrite and backup typings files', () => {
fileWriter.writeBundle(entryPoint, esm2015bundle, [ fileWriter.writeBundle(
{ entryPoint, esm2015bundle,
path: _('/node_modules/test/typings/index.d.ts'), [
contents: 'export declare class FooB {} // MODIFIED' {
}, path: _('/node_modules/test/typings/index.d.ts'),
]); contents: 'export declare class FooB {} // MODIFIED'
},
],
'es2015');
expect(fs.readFile(_('/node_modules/test/typings/index.d.ts'))) expect(fs.readFile(_('/node_modules/test/typings/index.d.ts')))
.toEqual('export declare class FooB {} // MODIFIED'); .toEqual('export declare class FooB {} // MODIFIED');
expect(fs.readFile(_('/node_modules/test/typings/index.d.ts.__ivy_ngcc_bak'))) expect(fs.readFile(_('/node_modules/test/typings/index.d.ts.__ivy_ngcc_bak')))
@ -356,7 +407,6 @@ runInEachFileSystem(() => {
fs: FileSystem, entryPoint: EntryPoint, formatProperty: EntryPointJsonProperty, fs: FileSystem, entryPoint: EntryPoint, formatProperty: EntryPointJsonProperty,
format: EntryPointFormat): EntryPointBundle { format: EntryPointFormat): EntryPointBundle {
return makeEntryPointBundle( return makeEntryPointBundle(
fs, entryPoint, entryPoint.packageJson[formatProperty] !, false, formatProperty, format, fs, entryPoint, entryPoint.packageJson[formatProperty] !, false, format, true);
true);
} }
}); });