UNPKG

15.7 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.addInitialNavigation = exports.getImportOfIdentifier = exports.findImport = exports.getOutputPath = exports.stripTsExtension = exports.getProject = void 0;
11const schematics_1 = require("@angular-devkit/schematics");
12const utility_1 = require("@schematics/angular/utility");
13const ts = require("typescript");
14async function getProject(host, projectName) {
15 const workspace = await (0, utility_1.readWorkspace)(host);
16 const project = workspace.projects.get(projectName);
17 if (!project || project.extensions.projectType !== 'application') {
18 throw new schematics_1.SchematicsException(`Universal requires a project type of 'application'.`);
19 }
20 return project;
21}
22exports.getProject = getProject;
23function stripTsExtension(file) {
24 return file.replace(/\.ts$/, '');
25}
26exports.stripTsExtension = stripTsExtension;
27async function getOutputPath(host, projectName, target) {
28 // Generate new output paths
29 const project = await getProject(host, projectName);
30 const serverTarget = project.targets.get(target);
31 if (!serverTarget || !serverTarget.options) {
32 throw new schematics_1.SchematicsException(`Cannot find 'options' for ${projectName} ${target} target.`);
33 }
34 const { outputPath } = serverTarget.options;
35 if (typeof outputPath !== 'string') {
36 throw new schematics_1.SchematicsException(`outputPath for ${projectName} ${target} target is not a string.`);
37 }
38 return outputPath;
39}
40exports.getOutputPath = getOutputPath;
41function findImport(sourceFile, moduleName, symbolName) {
42 // Only look through the top-level imports.
43 for (const node of sourceFile.statements) {
44 if (!ts.isImportDeclaration(node) ||
45 !ts.isStringLiteral(node.moduleSpecifier) ||
46 node.moduleSpecifier.text !== moduleName) {
47 continue;
48 }
49 const namedBindings = node.importClause && node.importClause.namedBindings;
50 if (!namedBindings || !ts.isNamedImports(namedBindings)) {
51 continue;
52 }
53 if (namedBindings.elements.some((element) => element.name.text === symbolName)) {
54 return namedBindings;
55 }
56 }
57 return null;
58}
59exports.findImport = findImport;
60/** Gets import information about the specified identifier by using the Type checker. */
61function getImportOfIdentifier(typeChecker, node) {
62 const symbol = typeChecker.getSymbolAtLocation(node);
63 if (!symbol || !symbol.declarations.length) {
64 return null;
65 }
66 const decl = symbol.declarations[0];
67 if (!ts.isImportSpecifier(decl)) {
68 return null;
69 }
70 const importDecl = decl.parent.parent.parent;
71 if (!ts.isStringLiteral(importDecl.moduleSpecifier)) {
72 return null;
73 }
74 return {
75 // Handles aliased imports: e.g. "import {Component as myComp} from ...";
76 name: decl.propertyName ? decl.propertyName.text : decl.name.text,
77 importModule: importDecl.moduleSpecifier.text,
78 node: importDecl,
79 };
80}
81exports.getImportOfIdentifier = getImportOfIdentifier;
82function addInitialNavigation(node) {
83 const existingOptions = node.arguments[1];
84 // If the user has explicitly set initialNavigation, we respect that
85 if (existingOptions &&
86 existingOptions.properties.some((exp) => ts.isPropertyAssignment(exp) &&
87 ts.isIdentifier(exp.name) &&
88 exp.name.text === 'initialNavigation')) {
89 return node;
90 }
91 const enabledLiteral = ts.factory.createStringLiteral('enabledBlocking');
92 // TypeScript will emit the Node with double quotes.
93 // In schematics we usually write code with a single quotes
94 // eslint-disable-next-line @typescript-eslint/no-explicit-any
95 enabledLiteral.singleQuote = true;
96 const initialNavigationProperty = ts.factory.createPropertyAssignment('initialNavigation', enabledLiteral);
97 const routerOptions = existingOptions
98 ? ts.factory.updateObjectLiteralExpression(existingOptions, ts.factory.createNodeArray([...existingOptions.properties, initialNavigationProperty]))
99 : ts.factory.createObjectLiteralExpression([initialNavigationProperty], true);
100 const args = [node.arguments[0], routerOptions];
101 return ts.factory.createCallExpression(node.expression, node.typeArguments, args);
102}
103exports.addInitialNavigation = addInitialNavigation;
104//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9tb2R1bGVzL2V4cHJlc3MtZW5naW5lL3NjaGVtYXRpY3MvdXRpbHM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