1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const path_1 = require("path");
|
4 | const ts = require("typescript");
|
5 | const transformers_1 = require("@ngtools/webpack/src/transformers");
|
6 | const ast_utils_1 = require("../utils/ast-utils");
|
7 | const transformers_utils_1 = require("../utils/transformers-utils");
|
8 | function nsReplaceBootstrap(getNgCompiler) {
|
9 | const shouldTransform = (fileName) => !fileName.endsWith('.ngfactory.ts') && !fileName.endsWith('.ngstyle.ts');
|
10 | const getTypeChecker = () => getNgCompiler().typeChecker;
|
11 | const standardTransform = function (sourceFile) {
|
12 | const ops = [];
|
13 | const entryModule = transformers_utils_1.getResolvedEntryModule(getNgCompiler());
|
14 | if (!shouldTransform(sourceFile.fileName) || !entryModule) {
|
15 | return ops;
|
16 | }
|
17 |
|
18 | const entryModuleIdentifiers = transformers_1.collectDeepNodes(sourceFile, ts.SyntaxKind.Identifier)
|
19 | .filter(identifier => identifier.text === entryModule.className);
|
20 | if (entryModuleIdentifiers.length === 0) {
|
21 | return [];
|
22 | }
|
23 | const relativeEntryModulePath = path_1.relative(path_1.dirname(sourceFile.fileName), entryModule.path);
|
24 | const normalizedEntryModulePath = `./${relativeEntryModulePath}`.replace(/\\/g, '/');
|
25 |
|
26 | entryModuleIdentifiers.forEach(entryModuleIdentifier => {
|
27 |
|
28 | if (!(entryModuleIdentifier.parent
|
29 | && entryModuleIdentifier.parent.kind === ts.SyntaxKind.CallExpression)) {
|
30 | return;
|
31 | }
|
32 | const bootstrapCallExpr = entryModuleIdentifier.parent;
|
33 | if (bootstrapCallExpr.expression.kind !== ts.SyntaxKind.PropertyAccessExpression) {
|
34 | return;
|
35 | }
|
36 | const bootstrapPropAccessExpr = bootstrapCallExpr.expression;
|
37 | if (bootstrapPropAccessExpr.name.text !== 'bootstrapModule'
|
38 | || bootstrapPropAccessExpr.expression.kind !== ts.SyntaxKind.CallExpression) {
|
39 | return;
|
40 | }
|
41 | const nsPlatformCallExpr = bootstrapPropAccessExpr.expression;
|
42 | if (!(ast_utils_1.getExpressionName(nsPlatformCallExpr.expression) === 'platformNativeScriptDynamic')) {
|
43 | return;
|
44 | }
|
45 | const idPlatformNativeScript = ts.createUniqueName('__NgCli_bootstrap_1');
|
46 | const idNgFactory = ts.createUniqueName('__NgCli_bootstrap_2');
|
47 | const firstNode = transformers_1.getFirstNode(sourceFile);
|
48 |
|
49 | const factoryClassName = entryModule.className + 'NgFactory';
|
50 | const factoryModulePath = normalizedEntryModulePath + '.ngfactory';
|
51 | const newBootstrapPropAccessExpr = ts.getMutableClone(bootstrapPropAccessExpr);
|
52 | const newNsPlatformCallExpr = ts.getMutableClone(bootstrapPropAccessExpr.expression);
|
53 | newNsPlatformCallExpr.expression = ts.createPropertyAccess(idPlatformNativeScript, 'platformNativeScript');
|
54 | newBootstrapPropAccessExpr.expression = newNsPlatformCallExpr;
|
55 | newBootstrapPropAccessExpr.name = ts.createIdentifier("bootstrapModuleFactory");
|
56 | const newBootstrapCallExpr = ts.getMutableClone(bootstrapCallExpr);
|
57 | newBootstrapCallExpr.expression = newBootstrapPropAccessExpr;
|
58 | newBootstrapCallExpr.arguments = ts.createNodeArray([
|
59 | ts.createPropertyAccess(idNgFactory, ts.createIdentifier(factoryClassName))
|
60 | ]);
|
61 | ops.push(
|
62 |
|
63 |
|
64 | ...transformers_1.insertStarImport(sourceFile, idPlatformNativeScript, 'nativescript-angular/platform-static', firstNode, true),
|
65 |
|
66 |
|
67 | ...transformers_1.insertStarImport(sourceFile, idNgFactory, factoryModulePath, firstNode, true),
|
68 |
|
69 |
|
70 |
|
71 | new transformers_1.ReplaceNodeOperation(sourceFile, bootstrapCallExpr, newBootstrapCallExpr));
|
72 | });
|
73 | return ops;
|
74 | };
|
75 | return transformers_1.makeTransform(standardTransform, getTypeChecker);
|
76 | }
|
77 | exports.nsReplaceBootstrap = nsReplaceBootstrap;
|
78 |
|
\ | No newline at end of file |