| 
									
										
										
										
											2018-07-16 08:54:16 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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
 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-05-25 21:34:40 +01:00
										 |  |  | import * as ts from 'typescript'; | 
					
						
							| 
									
										
										
										
											2019-06-06 20:22:32 +01:00
										 |  |  | import {AbsoluteFsPath, NgtscCompilerHost, absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system'; | 
					
						
							|  |  |  | import {TestFile} from '../../../src/ngtsc/file_system/testing'; | 
					
						
							|  |  |  | import {BundleProgram, makeBundleProgram} from '../../src/packages/bundle_program'; | 
					
						
							| 
									
										
										
										
											2019-05-25 17:46:07 +01:00
										 |  |  | import {EntryPoint, EntryPointFormat, EntryPointJsonProperty} from '../../src/packages/entry_point'; | 
					
						
							| 
									
										
										
										
											2018-11-25 21:40:25 +00:00
										 |  |  | import {EntryPointBundle} from '../../src/packages/entry_point_bundle'; | 
					
						
							| 
									
										
										
										
											2019-06-06 20:22:32 +01:00
										 |  |  | import {NgccSourcesCompilerHost} from '../../src/packages/ngcc_compiler_host'; | 
					
						
							| 
									
										
										
										
											2018-07-16 08:54:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-25 17:46:07 +01:00
										 |  |  | export function makeTestEntryPoint( | 
					
						
							|  |  |  |     entryPointName: string, packageName: string = entryPointName): EntryPoint { | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     name: entryPointName, | 
					
						
							|  |  |  |     packageJson: {name: entryPointName}, | 
					
						
							|  |  |  |     package: absoluteFrom(`/node_modules/${packageName}`), | 
					
						
							|  |  |  |     path: absoluteFrom(`/node_modules/${entryPointName}`), | 
					
						
							|  |  |  |     typings: absoluteFrom(`/node_modules/${entryPointName}/index.d.ts`), | 
					
						
							|  |  |  |     compiledByAngular: true, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-25 21:40:25 +00:00
										 |  |  | /** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param format The format of the bundle. | 
					
						
							|  |  |  |  * @param files The source files to include in the bundle. | 
					
						
							|  |  |  |  * @param dtsFiles The typings files to include the bundle. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export function makeTestEntryPointBundle( | 
					
						
							| 
									
										
										
										
											2019-05-25 17:46:07 +01:00
										 |  |  |     packageName: string, formatProperty: EntryPointJsonProperty, format: EntryPointFormat, | 
					
						
							|  |  |  |     isCore: boolean, srcRootNames: AbsoluteFsPath[], | 
					
						
							|  |  |  |     dtsRootNames?: AbsoluteFsPath[]): EntryPointBundle { | 
					
						
							|  |  |  |   const entryPoint = makeTestEntryPoint(packageName); | 
					
						
							| 
									
										
										
										
											2019-06-06 20:22:32 +01:00
										 |  |  |   const src = makeTestBundleProgram(srcRootNames[0], isCore); | 
					
						
							|  |  |  |   const dts = dtsRootNames ? makeTestDtsBundleProgram(dtsRootNames[0], isCore) : null; | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |   const isFlatCore = isCore && src.r3SymbolsFile === null; | 
					
						
							| 
									
										
										
										
											2019-05-25 17:46:07 +01:00
										 |  |  |   return { | 
					
						
							|  |  |  |     entryPoint, | 
					
						
							|  |  |  |     formatProperty, | 
					
						
							|  |  |  |     format, | 
					
						
							|  |  |  |     rootDirs: [absoluteFrom('/')], src, dts, isCore, isFlatCore | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2018-12-17 16:17:38 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-11-25 21:40:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 20:22:32 +01:00
										 |  |  | export function makeTestBundleProgram( | 
					
						
							|  |  |  |     path: AbsoluteFsPath, isCore: boolean = false): BundleProgram { | 
					
						
							|  |  |  |   const fs = getFileSystem(); | 
					
						
							|  |  |  |   const entryPointPath = fs.dirname(path); | 
					
						
							| 
									
										
										
										
											2019-05-25 21:34:40 +01:00
										 |  |  |   const rootDir = fs.dirname(entryPointPath); | 
					
						
							|  |  |  |   const options: ts.CompilerOptions = | 
					
						
							|  |  |  |       {allowJs: true, maxNodeModuleJsDepth: Infinity, checkJs: false, rootDir, rootDirs: [rootDir]}; | 
					
						
							| 
									
										
										
										
											2019-06-06 20:22:32 +01:00
										 |  |  |   const host = new NgccSourcesCompilerHost(fs, options, entryPointPath); | 
					
						
							|  |  |  |   return makeBundleProgram(fs, isCore, path, 'r3_symbols.js', options, host); | 
					
						
							| 
									
										
										
										
											2018-07-16 08:54:16 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-10-01 11:10:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 20:22:32 +01:00
										 |  |  | export function makeTestDtsBundleProgram( | 
					
						
							|  |  |  |     path: AbsoluteFsPath, isCore: boolean = false): BundleProgram { | 
					
						
							|  |  |  |   const fs = getFileSystem(); | 
					
						
							|  |  |  |   const options = {}; | 
					
						
							|  |  |  |   const host = new NgtscCompilerHost(fs, options); | 
					
						
							|  |  |  |   return makeBundleProgram(fs, isCore, path, 'r3_symbols.d.ts', options, host); | 
					
						
							| 
									
										
										
										
											2018-09-30 20:53:25 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 20:22:32 +01:00
										 |  |  | export function convertToDirectTsLibImport(filesystem: TestFile[]) { | 
					
						
							| 
									
										
										
										
											2018-10-01 11:10:55 +01:00
										 |  |  |   return filesystem.map(file => { | 
					
						
							|  |  |  |     const contents = | 
					
						
							|  |  |  |         file.contents | 
					
						
							|  |  |  |             .replace( | 
					
						
							|  |  |  |                 `import * as tslib_1 from 'tslib';`, | 
					
						
							|  |  |  |                 `import { __decorate, __metadata, __read, __values, __param, __extends, __assign } from 'tslib';`) | 
					
						
							| 
									
										
										
										
											2018-09-30 20:53:25 +01:00
										 |  |  |             .replace(/tslib_1\./g, ''); | 
					
						
							| 
									
										
										
										
											2018-10-01 11:10:55 +01:00
										 |  |  |     return {...file, contents}; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-28 20:47:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 20:22:32 +01:00
										 |  |  | export function getRootFiles(testFiles: TestFile[]): AbsoluteFsPath[] { | 
					
						
							|  |  |  |   return testFiles.filter(f => f.isRoot !== false).map(f => absoluteFrom(f.name)); | 
					
						
							| 
									
										
										
										
											2019-04-28 20:47:57 +01:00
										 |  |  | } |