1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | var desc = Object.getOwnPropertyDescriptor(m, k);
|
5 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6 | desc = { enumerable: true, get: function() { return m[k]; } };
|
7 | }
|
8 | Object.defineProperty(o, k2, desc);
|
9 | }) : (function(o, m, k, k2) {
|
10 | if (k2 === undefined) k2 = k;
|
11 | o[k2] = m[k];
|
12 | }));
|
13 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15 | }) : function(o, v) {
|
16 | o["default"] = v;
|
17 | });
|
18 | var __importStar = (this && this.__importStar) || function (mod) {
|
19 | if (mod && mod.__esModule) return mod;
|
20 | var result = {};
|
21 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22 | __setModuleDefault(result, mod);
|
23 | return result;
|
24 | };
|
25 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
26 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
27 | };
|
28 | Object.defineProperty(exports, "__esModule", { value: true });
|
29 | exports.setDependenciesTsConfigPaths = exports.initializeTsConfig = exports.defaultTsConfigPath = void 0;
|
30 | const path = __importStar(require("path"));
|
31 | const typescript_1 = __importDefault(require("typescript"));
|
32 | const load_esm_1 = require("../utils/load-esm");
|
33 | const log = __importStar(require("../utils/log"));
|
34 | exports.defaultTsConfigPath = path.join(__dirname, 'conf', 'tsconfig.ngc.json');
|
35 |
|
36 |
|
37 |
|
38 | async function readDefaultTsConfig(fileName = exports.defaultTsConfigPath) {
|
39 |
|
40 | const extraOptions = {
|
41 | target: typescript_1.default.ScriptTarget.ES2022,
|
42 |
|
43 | sourceMap: false,
|
44 | inlineSources: true,
|
45 | inlineSourceMap: true,
|
46 | outDir: '',
|
47 | declaration: true,
|
48 |
|
49 | enableResourceInlining: true,
|
50 |
|
51 | flatModuleId: 'AUTOGENERATED',
|
52 | flatModuleOutFile: 'AUTOGENERATED',
|
53 | };
|
54 | const { readConfiguration } = await (0, load_esm_1.ngCompilerCli)();
|
55 | return readConfiguration(fileName, extraOptions);
|
56 | }
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | async function createDefaultTsConfig(values) {
|
63 | if (!values) {
|
64 | return readDefaultTsConfig();
|
65 | }
|
66 | else if (typeof values === 'string') {
|
67 | return readDefaultTsConfig(values);
|
68 | }
|
69 | else {
|
70 | return values;
|
71 | }
|
72 | }
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | async function initializeTsConfig(defaultTsConfig, entryPoints) {
|
78 | const defaultTsConfigParsed = await createDefaultTsConfig(defaultTsConfig);
|
79 | if (defaultTsConfigParsed.errors.length > 0) {
|
80 | const { formatDiagnostics } = await (0, load_esm_1.ngCompilerCli)();
|
81 | throw new Error(formatDiagnostics(defaultTsConfigParsed.errors));
|
82 | }
|
83 | entryPoints.forEach(currentEntryPoint => {
|
84 | const { entryPoint } = currentEntryPoint.data;
|
85 | log.debug(`Initializing tsconfig for ${entryPoint.moduleId}`);
|
86 | const basePath = path.dirname(entryPoint.entryFilePath);
|
87 |
|
88 | const tsConfig = JSON.parse(JSON.stringify(defaultTsConfigParsed));
|
89 | const overrideOptions = {
|
90 | flatModuleId: entryPoint.moduleId,
|
91 | flatModuleOutFile: `${entryPoint.flatModuleFile}.js`,
|
92 | basePath,
|
93 | rootDir: basePath,
|
94 | sourceRoot: '',
|
95 | };
|
96 | tsConfig.rootNames = [entryPoint.entryFilePath];
|
97 | tsConfig.options = { ...tsConfig.options, ...overrideOptions };
|
98 | currentEntryPoint.data.tsConfig = tsConfig;
|
99 | });
|
100 | }
|
101 | exports.initializeTsConfig = initializeTsConfig;
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | function setDependenciesTsConfigPaths(parsedTsConfig, entryPoints, pointToSource = false) {
|
113 | const tsConfig = JSON.parse(JSON.stringify(parsedTsConfig));
|
114 |
|
115 | if (!tsConfig.options.paths) {
|
116 | tsConfig.options.paths = {};
|
117 | }
|
118 | for (const dep of entryPoints) {
|
119 | const { entryPoint } = dep.data;
|
120 | const { moduleId, destinationFiles, entryFilePath } = entryPoint;
|
121 | const mappedPath = [pointToSource ? entryFilePath : destinationFiles.declarations];
|
122 | if (!tsConfig.options.paths[moduleId]) {
|
123 | tsConfig.options.paths[moduleId] = mappedPath;
|
124 | }
|
125 | else {
|
126 | tsConfig.options.paths[moduleId].unshift(...mappedPath);
|
127 | }
|
128 | }
|
129 | return tsConfig;
|
130 | }
|
131 | exports.setDependenciesTsConfigPaths = setDependenciesTsConfigPaths;
|
132 |
|
\ | No newline at end of file |