This repository was archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 474
feat(express-engine): add ModuleMapLoaderModule to the app server imports during ng-add #1130
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC 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 | ||
| */ | ||
| import { SchematicsException, Tree } from '@angular-devkit/schematics'; | ||
| import * as ts from 'typescript'; | ||
| import {getSourceNodes} from '@schematics/angular/utility/ast-utils'; | ||
|
|
||
| export function findAppServerModuleExport(host: Tree, | ||
| mainPath: string): ts.ExportDeclaration | null { | ||
| const mainBuffer = host.read(mainPath); | ||
| if (!mainBuffer) { | ||
| throw new SchematicsException(`Main file (${mainPath}) not found`); | ||
| } | ||
| const mainText = mainBuffer.toString('utf-8'); | ||
| const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true); | ||
|
|
||
| const allNodes = getSourceNodes(source); | ||
|
|
||
| let exportDeclaration: ts.ExportDeclaration | null = null; | ||
|
|
||
| for (const node of allNodes) { | ||
|
|
||
| let exportDeclarationNode: ts.Node | null = node; | ||
|
|
||
| // Walk up the parent until ExportDeclaration is found. | ||
| while (exportDeclarationNode && exportDeclarationNode.parent | ||
| && exportDeclarationNode.parent.kind !== ts.SyntaxKind.ExportDeclaration) { | ||
| exportDeclarationNode = exportDeclarationNode.parent; | ||
| } | ||
|
|
||
| if (exportDeclarationNode !== null && | ||
| exportDeclarationNode.parent !== undefined && | ||
| exportDeclarationNode.parent.kind === ts.SyntaxKind.ExportDeclaration) { | ||
| exportDeclaration = exportDeclarationNode.parent as ts.ExportDeclaration; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return exportDeclaration; | ||
| } | ||
|
|
||
| export function findAppServerModulePath(host: Tree, mainPath: string): string { | ||
| const exportDeclaration = findAppServerModuleExport(host, mainPath); | ||
| if (!exportDeclaration) { | ||
| throw new SchematicsException('Could not find app server module export'); | ||
| } | ||
|
|
||
| const moduleSpecifier = exportDeclaration.moduleSpecifier.getText(); | ||
| return moduleSpecifier.substring(1, moduleSpecifier.length - 1); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.