entryModuleIdentifiers.forEach(entryModuleIdentifier => { if (!entryModuleIdentifier.parent) { return; } if (entryModuleIdentifier.parent.kind !== ts.SyntaxKind.CallExpression && entryModuleIdentifier.parent.kind !== ts.SyntaxKind.PropertyAssignment) { return; } if (entryModuleIdentifier.parent.kind === ts.SyntaxKind.CallExpression) { // Figure out if it's a `platformDynamicServer().bootstrapModule(AppModule)` call. const callExpr = entryModuleIdentifier.parent; if (callExpr.expression.kind === ts.SyntaxKind.PropertyAccessExpression) { const propAccessExpr = callExpr.expression; if (!(propAccessExpr.name.text === 'bootstrapModule' && propAccessExpr.expression.kind === ts.SyntaxKind.CallExpression)) { return; } const bootstrapModuleIdentifier = propAccessExpr.name; const innerCallExpr = propAccessExpr.expression; if (!(innerCallExpr.expression.kind === ts.SyntaxKind.Identifier && innerCallExpr.expression.text === 'platformDynamicServer')) { return; } const platformDynamicServerIdentifier = innerCallExpr.expression; const idPlatformServer = ts.createUniqueName('__NgCli_bootstrap_'); const idNgFactory = ts.createUniqueName('__NgCli_bootstrap_'); // Add the transform operations. ops.push( // Replace the entry module import. ...insert_import_1.insertStarImport(sourceFile, idNgFactory, factoryModulePath), new interfaces_1.ReplaceNodeOperation(sourceFile, entryModuleIdentifier, ts.createPropertyAccess(idNgFactory, ts.createIdentifier(factoryClassName))), // Replace the platformBrowserDynamic import. ...insert_import_1.insertStarImport(sourceFile, idPlatformServer, '@angular/platform-server'), new interfaces_1.ReplaceNodeOperation(sourceFile, platformDynamicServerIdentifier, ts.createPropertyAccess(idPlatformServer, 'platformServer')), new interfaces_1.ReplaceNodeOperation(sourceFile, bootstrapModuleIdentifier, ts.createIdentifier('bootstrapModuleFactory'))); } else if (callExpr.expression.kind === ts.SyntaxKind.Identifier) { // Figure out if it is renderModule const identifierExpr = callExpr.expression; if (identifierExpr.text !== 'renderModule') { return; } const renderModuleIdentifier = identifierExpr; const idPlatformServer = ts.createUniqueName('__NgCli_bootstrap_'); const idNgFactory = ts.createUniqueName('__NgCli_bootstrap_'); ops.push( // Replace the entry module import. ...insert_import_1.insertStarImport(sourceFile, idNgFactory, factoryModulePath), new interfaces_1.ReplaceNodeOperation(sourceFile, entryModuleIdentifier, ts.createPropertyAccess(idNgFactory, ts.createIdentifier(factoryClassName))), // Replace the renderModule import. ...insert_import_1.insertStarImport(sourceFile, idPlatformServer, '@angular/platform-server'), new interfaces_1.ReplaceNodeOperation(sourceFile, renderModuleIdentifier, ts.createPropertyAccess(idPlatformServer, 'renderModuleFactory'))); } } else if (entryModuleIdentifier.parent.kind === ts.SyntaxKind.PropertyAssignment) { // This is for things that accept a module as a property in a config object // .ie the express engine const idNgFactory = ts.createUniqueName('__NgCli_bootstrap_'); ops.push(...insert_import_1.insertStarImport(sourceFile, idNgFactory, factoryModulePath), new interfaces_1.ReplaceNodeOperation(sourceFile, entryModuleIdentifier, ts.createPropertyAccess(idNgFactory, ts.createIdentifier(factoryClassName)))); } });
entryModuleIdentifiers.forEach(entryModuleIdentifier => { // Figure out if it's a `platformBrowserDynamic().bootstrapModule(AppModule)` call. if (!(entryModuleIdentifier.parent && entryModuleIdentifier.parent.kind === ts.SyntaxKind.CallExpression)) { return; } const callExpr = entryModuleIdentifier.parent; if (callExpr.expression.kind !== ts.SyntaxKind.PropertyAccessExpression) { return; } const propAccessExpr = callExpr.expression; if (propAccessExpr.name.text !== 'bootstrapModule' || propAccessExpr.expression.kind !== ts.SyntaxKind.CallExpression) { return; } const bootstrapModuleIdentifier = propAccessExpr.name; const innerCallExpr = propAccessExpr.expression; if (!(innerCallExpr.expression.kind === ts.SyntaxKind.Identifier && innerCallExpr.expression.text === 'platformBrowserDynamic')) { return; } const platformBrowserDynamicIdentifier = innerCallExpr.expression; const idPlatformBrowser = ts.createUniqueName('__NgCli_bootstrap_'); const idNgFactory = ts.createUniqueName('__NgCli_bootstrap_'); // Add the transform operations. const factoryClassName = entryModule.className + 'NgFactory'; const factoryModulePath = normalizedEntryModulePath + '.ngfactory'; ops.push( // Replace the entry module import. ...insert_import_1.insertStarImport(sourceFile, idNgFactory, factoryModulePath), new interfaces_1.ReplaceNodeOperation(sourceFile, entryModuleIdentifier, ts.createPropertyAccess(idNgFactory, ts.createIdentifier(factoryClassName))), // Replace the platformBrowserDynamic import. ...insert_import_1.insertStarImport(sourceFile, idPlatformBrowser, '@angular/platform-browser'), new interfaces_1.ReplaceNodeOperation(sourceFile, platformBrowserDynamicIdentifier, ts.createPropertyAccess(idPlatformBrowser, 'platformBrowser')), new interfaces_1.ReplaceNodeOperation(sourceFile, bootstrapModuleIdentifier, ts.createIdentifier('bootstrapModuleFactory'))); // Save the import identifiers that we replaced for removal. removedEntryModuleIdentifiers.push(entryModuleIdentifier); removedPlatformBrowserDynamicIdentifier.push(platformBrowserDynamicIdentifier); });