1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.setDependenciesTsConfigPaths = exports.initializeTsConfig = exports.createDefaultTsConfig = exports.readDefaultTsConfig = void 0;
|
4 | const ng = require("@angular/compiler-cli");
|
5 | const path = require("path");
|
6 | const ts = require("typescript");
|
7 | const log = require("../utils/log");
|
8 |
|
9 |
|
10 |
|
11 | function readDefaultTsConfig(fileName) {
|
12 | if (!fileName) {
|
13 | fileName = path.resolve(__dirname, 'conf', 'tsconfig.ngc.json');
|
14 | }
|
15 |
|
16 | const extraOptions = {
|
17 | moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
18 | target: ts.ScriptTarget.ES2015,
|
19 | experimentalDecorators: true,
|
20 |
|
21 | sourceMap: false,
|
22 | inlineSources: true,
|
23 | inlineSourceMap: true,
|
24 | outDir: '',
|
25 | declaration: true,
|
26 |
|
27 | enableResourceInlining: true,
|
28 |
|
29 | flatModuleId: 'AUTOGENERATED',
|
30 | flatModuleOutFile: 'AUTOGENERATED',
|
31 | };
|
32 | const config = ng.readConfiguration(fileName, extraOptions);
|
33 | const options = config.options;
|
34 |
|
35 |
|
36 | const transformDecorators = !options.enableIvy && options.annotationsAs !== 'decorators';
|
37 | if ((options.annotateForClosureCompiler || options.annotationsAs === 'static fields') && transformDecorators) {
|
38 |
|
39 |
|
40 |
|
41 | options.emitDecoratorMetadata = true;
|
42 | }
|
43 | return config;
|
44 | }
|
45 | exports.readDefaultTsConfig = readDefaultTsConfig;
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | function createDefaultTsConfig(values) {
|
52 | if (!values) {
|
53 | return readDefaultTsConfig();
|
54 | }
|
55 | else if (typeof values === 'string') {
|
56 | return readDefaultTsConfig(values);
|
57 | }
|
58 | else {
|
59 | return values;
|
60 | }
|
61 | }
|
62 | exports.createDefaultTsConfig = createDefaultTsConfig;
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | const initializeTsConfig = (defaultTsConfig, entryPoints) => {
|
68 | if (defaultTsConfig.errors.length > 0) {
|
69 | throw ng.formatDiagnostics(defaultTsConfig.errors);
|
70 | }
|
71 | entryPoints.forEach(currentEntryPoint => {
|
72 | const { entryPoint } = currentEntryPoint.data;
|
73 | log.debug(`Initializing tsconfig for ${entryPoint.moduleId}`);
|
74 | const basePath = path.dirname(entryPoint.entryFilePath);
|
75 |
|
76 | let tsConfig = JSON.parse(JSON.stringify(defaultTsConfig));
|
77 | const overrideOptions = {
|
78 | flatModuleId: entryPoint.moduleId,
|
79 | flatModuleOutFile: `${entryPoint.flatModuleFile}.js`,
|
80 | basePath,
|
81 | rootDir: basePath,
|
82 | sourceRoot: '',
|
83 | };
|
84 | tsConfig.rootNames = [entryPoint.entryFilePath];
|
85 | tsConfig.options = { ...tsConfig.options, ...overrideOptions };
|
86 | currentEntryPoint.data.tsConfig = tsConfig;
|
87 | });
|
88 | };
|
89 | exports.initializeTsConfig = initializeTsConfig;
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | function setDependenciesTsConfigPaths(parsedTsConfig, entryPoints, pointToSource = false) {
|
101 | const tsConfig = JSON.parse(JSON.stringify(parsedTsConfig));
|
102 |
|
103 | if (!tsConfig.options.paths) {
|
104 | tsConfig.options.paths = {};
|
105 | }
|
106 | for (let dep of entryPoints) {
|
107 | const { entryPoint } = dep.data;
|
108 | const { moduleId, destinationFiles, entryFilePath } = entryPoint;
|
109 | const mappedPath = [pointToSource ? entryFilePath : destinationFiles.declarations];
|
110 | if (!tsConfig.options.paths[moduleId]) {
|
111 | tsConfig.options.paths[moduleId] = mappedPath;
|
112 | }
|
113 | else {
|
114 | tsConfig.options.paths[moduleId].unshift(...mappedPath);
|
115 | }
|
116 | }
|
117 | return tsConfig;
|
118 | }
|
119 | exports.setDependenciesTsConfigPaths = setDependenciesTsConfigPaths;
|
120 |
|
\ | No newline at end of file |