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.compileSourceFiles = void 0;
|
30 | const node_path_1 = require("node:path");
|
31 | const typescript_1 = __importDefault(require("typescript"));
|
32 | const nodes_1 = require("../ng-package/nodes");
|
33 | const cache_compiler_host_1 = require("../ts/cache-compiler-host");
|
34 | const load_esm_1 = require("../utils/load-esm");
|
35 | const log = __importStar(require("../utils/log"));
|
36 | async function compileSourceFiles(graph, tsConfig, moduleResolutionCache, options, extraOptions, stylesheetProcessor) {
|
37 | var _a, _b;
|
38 | const { NgtscProgram, formatDiagnostics } = await (0, load_esm_1.ngCompilerCli)();
|
39 | const { cacheDirectory, watch, cacheEnabled } = options;
|
40 | const tsConfigOptions = { ...tsConfig.options, ...extraOptions };
|
41 | const entryPoint = graph.find((0, nodes_1.isEntryPointInProgress)());
|
42 | const ngPackageNode = graph.find(nodes_1.isPackage);
|
43 | const inlineStyleLanguage = ngPackageNode.data.inlineStyleLanguage;
|
44 | const cacheDir = cacheEnabled && cacheDirectory;
|
45 | if (cacheDir) {
|
46 | (_a = tsConfigOptions.incremental) !== null && _a !== void 0 ? _a : (tsConfigOptions.incremental = true);
|
47 | (_b = tsConfigOptions.tsBuildInfoFile) !== null && _b !== void 0 ? _b : (tsConfigOptions.tsBuildInfoFile = (0, node_path_1.join)(cacheDir, `tsbuildinfo/${entryPoint.data.entryPoint.flatModuleFile}.tsbuildinfo`));
|
48 | }
|
49 | const tsCompilerHost = (0, cache_compiler_host_1.cacheCompilerHost)(graph, entryPoint, tsConfigOptions, moduleResolutionCache, stylesheetProcessor, inlineStyleLanguage);
|
50 | const cache = entryPoint.cache;
|
51 | const sourceFileCache = cache.sourcesFileCache;
|
52 | let usingBuildInfo = false;
|
53 | let oldBuilder = cache.oldBuilder;
|
54 | if (!oldBuilder && cacheDir) {
|
55 | oldBuilder = typescript_1.default.readBuilderProgram(tsConfigOptions, tsCompilerHost);
|
56 | usingBuildInfo = true;
|
57 | }
|
58 |
|
59 | const angularProgram = new NgtscProgram(tsConfig.rootNames, tsConfigOptions, tsCompilerHost, cache.oldNgtscProgram);
|
60 | const angularCompiler = angularProgram.compiler;
|
61 | const { ignoreForDiagnostics, ignoreForEmit } = angularCompiler;
|
62 |
|
63 |
|
64 | const typeScriptProgram = angularProgram.getTsProgram();
|
65 | (0, cache_compiler_host_1.augmentProgramWithVersioning)(typeScriptProgram);
|
66 | let builder;
|
67 | if (watch || cacheDir) {
|
68 | builder = cache.oldBuilder = typescript_1.default.createEmitAndSemanticDiagnosticsBuilderProgram(typeScriptProgram, tsCompilerHost, oldBuilder);
|
69 | cache.oldNgtscProgram = angularProgram;
|
70 | }
|
71 | else {
|
72 | builder = typescript_1.default.createEmitAndSemanticDiagnosticsBuilderProgram(typeScriptProgram, tsCompilerHost);
|
73 | }
|
74 |
|
75 | const affectedFiles = new Set();
|
76 |
|
77 | if ('getSemanticDiagnosticsOfNextAffectedFile' in builder) {
|
78 |
|
79 | while (true) {
|
80 | const result = builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, sourceFile => {
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | if (ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith('.ngtypecheck.ts')) {
|
87 |
|
88 |
|
89 | const originalFilename = sourceFile.fileName.slice(0, -15) + '.ts';
|
90 | const originalSourceFile = builder.getSourceFile(originalFilename);
|
91 | if (originalSourceFile) {
|
92 | affectedFiles.add(originalSourceFile);
|
93 | }
|
94 | return true;
|
95 | }
|
96 | return false;
|
97 | });
|
98 | if (!result) {
|
99 | break;
|
100 | }
|
101 | affectedFiles.add(result.affected);
|
102 | }
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | if (usingBuildInfo) {
|
108 | for (const sourceFile of builder.getSourceFiles()) {
|
109 | if (ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith('.ngtypecheck.ts')) {
|
110 |
|
111 |
|
112 | const originalFilename = sourceFile.fileName.slice(0, -15) + '.ts';
|
113 | const originalSourceFile = builder.getSourceFile(originalFilename);
|
114 | if (originalSourceFile) {
|
115 | affectedFiles.add(originalSourceFile);
|
116 | }
|
117 | }
|
118 | }
|
119 | }
|
120 | }
|
121 |
|
122 | const allDiagnostics = [
|
123 | ...angularCompiler.getOptionDiagnostics(),
|
124 | ...builder.getOptionsDiagnostics(),
|
125 | ...builder.getGlobalDiagnostics(),
|
126 | ];
|
127 |
|
128 |
|
129 | await angularCompiler.analyzeAsync();
|
130 |
|
131 | for (const sourceFile of builder.getSourceFiles()) {
|
132 | if (ignoreForDiagnostics.has(sourceFile)) {
|
133 | continue;
|
134 | }
|
135 | allDiagnostics.push(...builder.getDeclarationDiagnostics(sourceFile), ...builder.getSyntacticDiagnostics(sourceFile), ...builder.getSemanticDiagnostics(sourceFile));
|
136 |
|
137 | if (sourceFile.isDeclarationFile) {
|
138 | continue;
|
139 | }
|
140 |
|
141 |
|
142 | if (affectedFiles.has(sourceFile)) {
|
143 | const angularDiagnostics = angularCompiler.getDiagnosticsForFile(sourceFile, affectedFiles.size === 1 ? 0 : 1);
|
144 | allDiagnostics.push(...angularDiagnostics);
|
145 | sourceFileCache.updateAngularDiagnostics(sourceFile, angularDiagnostics);
|
146 | }
|
147 | }
|
148 | const otherDiagnostics = [];
|
149 | const errorDiagnostics = [];
|
150 | for (const diagnostic of allDiagnostics) {
|
151 | if (diagnostic.category === typescript_1.default.DiagnosticCategory.Error) {
|
152 | errorDiagnostics.push(diagnostic);
|
153 | }
|
154 | else {
|
155 | otherDiagnostics.push(diagnostic);
|
156 | }
|
157 | }
|
158 | if (otherDiagnostics.length) {
|
159 | log.msg(formatDiagnostics(errorDiagnostics));
|
160 | }
|
161 | if (errorDiagnostics.length) {
|
162 | throw new Error(formatDiagnostics(errorDiagnostics));
|
163 | }
|
164 | const transformers = angularCompiler.prepareEmit().transformers;
|
165 | if ('getSemanticDiagnosticsOfNextAffectedFile' in builder) {
|
166 | while (builder.emitNextAffectedFile((fileName, data, writeByteOrderMark, onError, sourceFiles) => {
|
167 | if (fileName.endsWith('.tsbuildinfo')) {
|
168 | tsCompilerHost.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
|
169 | }
|
170 | })) {
|
171 |
|
172 | }
|
173 | }
|
174 | for (const sourceFile of builder.getSourceFiles()) {
|
175 | if (ignoreForEmit.has(sourceFile)) {
|
176 | continue;
|
177 | }
|
178 | if (angularCompiler.incrementalCompilation.safeToSkipEmit(sourceFile)) {
|
179 | continue;
|
180 | }
|
181 | builder.emit(sourceFile, undefined, undefined, undefined, transformers);
|
182 | angularCompiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
|
183 | }
|
184 | }
|
185 | exports.compileSourceFiles = compileSourceFiles;
|
186 |
|
\ | No newline at end of file |