@angular/compiler-cli 21.0.0-next.9 → 21.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -455,7 +455,7 @@ import { compileDirectiveFromMetadata, makeBindingParser, ParseLocation, ParseSo
455
455
  // packages/compiler-cli/linker/src/file_linker/partial_linkers/util.js
456
456
  import { createMayBeForwardRefExpression, outputAst as o2 } from "@angular/compiler";
457
457
  import semver from "semver";
458
- var PLACEHOLDER_VERSION = "21.0.0-next.9";
458
+ var PLACEHOLDER_VERSION = "21.0.0-rc.0";
459
459
  function wrapReference(wrapped) {
460
460
  return { value: wrapped, type: wrapped };
461
461
  }
@@ -12,7 +12,7 @@ import {
12
12
  formatDiagnostics,
13
13
  performCompilation,
14
14
  readConfiguration
15
- } from "./chunk-SIOKS4LN.js";
15
+ } from "./chunk-ZOLVJRLX.js";
16
16
 
17
17
  // packages/compiler-cli/src/main.js
18
18
  import ts2 from "typescript";
@@ -0,0 +1,644 @@
1
+
2
+ import {createRequire as __cjsCompatRequire} from 'module';
3
+ const require = __cjsCompatRequire(import.meta.url);
4
+
5
+ import {
6
+ NgCompiler,
7
+ NgCompilerHost,
8
+ TrackedIncrementalBuildStrategy,
9
+ freshCompilationTicket,
10
+ incrementalFromCompilerTicket
11
+ } from "./chunk-ZOZ6XVF3.js";
12
+ import {
13
+ ActivePerfRecorder,
14
+ OptimizeFor,
15
+ PerfCheckpoint,
16
+ PerfEvent,
17
+ PerfPhase,
18
+ TsCreateProgramDriver,
19
+ replaceTsWithNgInErrors,
20
+ retagAllTsFiles
21
+ } from "./chunk-3CWKYDQ7.js";
22
+ import {
23
+ absoluteFrom,
24
+ createFileSystemTsReadDirectoryFn,
25
+ getFileSystem,
26
+ resolve
27
+ } from "./chunk-GWZQLAGK.js";
28
+
29
+ // packages/compiler-cli/src/transformers/api.js
30
+ var DEFAULT_ERROR_CODE = 100;
31
+ var UNKNOWN_ERROR_CODE = 500;
32
+ var SOURCE = "angular";
33
+ function isTsDiagnostic(diagnostic) {
34
+ return diagnostic != null && diagnostic.source !== "angular";
35
+ }
36
+ var EmitFlags;
37
+ (function(EmitFlags2) {
38
+ EmitFlags2[EmitFlags2["DTS"] = 1] = "DTS";
39
+ EmitFlags2[EmitFlags2["JS"] = 2] = "JS";
40
+ EmitFlags2[EmitFlags2["Metadata"] = 4] = "Metadata";
41
+ EmitFlags2[EmitFlags2["I18nBundle"] = 8] = "I18nBundle";
42
+ EmitFlags2[EmitFlags2["Codegen"] = 16] = "Codegen";
43
+ EmitFlags2[EmitFlags2["Default"] = 19] = "Default";
44
+ EmitFlags2[EmitFlags2["All"] = 31] = "All";
45
+ })(EmitFlags || (EmitFlags = {}));
46
+
47
+ // packages/compiler-cli/src/transformers/compiler_host.js
48
+ import ts from "typescript";
49
+ var wrapHostForTest = null;
50
+ function createCompilerHost({ options, tsHost = ts.createCompilerHost(options, true) }) {
51
+ if (wrapHostForTest !== null) {
52
+ tsHost = wrapHostForTest(tsHost);
53
+ }
54
+ return tsHost;
55
+ }
56
+
57
+ // packages/compiler-cli/src/ngtsc/program.js
58
+ import { HtmlParser, MessageBundle } from "@angular/compiler";
59
+ import ts3 from "typescript";
60
+
61
+ // packages/compiler-cli/src/transformers/i18n.js
62
+ import { Xliff, Xliff2, Xmb } from "@angular/compiler";
63
+ import * as path from "path";
64
+ function i18nGetExtension(formatName) {
65
+ const format = formatName.toLowerCase();
66
+ switch (format) {
67
+ case "xmb":
68
+ return "xmb";
69
+ case "xlf":
70
+ case "xlif":
71
+ case "xliff":
72
+ case "xlf2":
73
+ case "xliff2":
74
+ return "xlf";
75
+ }
76
+ throw new Error(`Unsupported format "${formatName}"`);
77
+ }
78
+ function i18nExtract(formatName, outFile, host, options, bundle, pathResolve = path.resolve) {
79
+ formatName = formatName || "xlf";
80
+ const ext = i18nGetExtension(formatName);
81
+ const content = i18nSerialize(bundle, formatName, options);
82
+ const dstFile = outFile || `messages.${ext}`;
83
+ const dstPath = pathResolve(options.outDir || options.basePath, dstFile);
84
+ host.writeFile(dstPath, content, false, void 0, []);
85
+ return [dstPath];
86
+ }
87
+ function i18nSerialize(bundle, formatName, options) {
88
+ const format = formatName.toLowerCase();
89
+ let serializer;
90
+ switch (format) {
91
+ case "xmb":
92
+ serializer = new Xmb();
93
+ break;
94
+ case "xliff2":
95
+ case "xlf2":
96
+ serializer = new Xliff2();
97
+ break;
98
+ case "xlf":
99
+ case "xliff":
100
+ default:
101
+ serializer = new Xliff();
102
+ }
103
+ return bundle.write(serializer, getPathNormalizer(options.basePath));
104
+ }
105
+ function getPathNormalizer(basePath) {
106
+ return (sourcePath) => {
107
+ sourcePath = basePath ? path.relative(basePath, sourcePath) : sourcePath;
108
+ return sourcePath.split(path.sep).join("/");
109
+ };
110
+ }
111
+
112
+ // packages/compiler-cli/src/typescript_support.js
113
+ import ts2 from "typescript";
114
+
115
+ // packages/compiler-cli/src/version_helpers.js
116
+ function toNumbers(value) {
117
+ const suffixIndex = value.lastIndexOf("-");
118
+ return value.slice(0, suffixIndex === -1 ? value.length : suffixIndex).split(".").map((segment) => {
119
+ const parsed = parseInt(segment, 10);
120
+ if (isNaN(parsed)) {
121
+ throw Error(`Unable to parse version string ${value}.`);
122
+ }
123
+ return parsed;
124
+ });
125
+ }
126
+ function compareNumbers(a, b) {
127
+ const max = Math.max(a.length, b.length);
128
+ const min = Math.min(a.length, b.length);
129
+ for (let i = 0; i < min; i++) {
130
+ if (a[i] > b[i])
131
+ return 1;
132
+ if (a[i] < b[i])
133
+ return -1;
134
+ }
135
+ if (min !== max) {
136
+ const longestArray = a.length === max ? a : b;
137
+ const comparisonResult = a.length === max ? 1 : -1;
138
+ for (let i = min; i < max; i++) {
139
+ if (longestArray[i] > 0) {
140
+ return comparisonResult;
141
+ }
142
+ }
143
+ }
144
+ return 0;
145
+ }
146
+ function compareVersions(v1, v2) {
147
+ return compareNumbers(toNumbers(v1), toNumbers(v2));
148
+ }
149
+
150
+ // packages/compiler-cli/src/typescript_support.js
151
+ var MIN_TS_VERSION = "5.9.0";
152
+ var MAX_TS_VERSION = "6.0.0";
153
+ var tsVersion = ts2.version;
154
+ function checkVersion(version, minVersion, maxVersion) {
155
+ if (compareVersions(version, minVersion) < 0 || compareVersions(version, maxVersion) >= 0) {
156
+ throw new Error(`The Angular Compiler requires TypeScript >=${minVersion} and <${maxVersion} but ${version} was found instead.`);
157
+ }
158
+ }
159
+ function verifySupportedTypeScriptVersion() {
160
+ checkVersion(tsVersion, MIN_TS_VERSION, MAX_TS_VERSION);
161
+ }
162
+
163
+ // packages/compiler-cli/src/ngtsc/program.js
164
+ var NgtscProgram = class {
165
+ options;
166
+ compiler;
167
+ /**
168
+ * The primary TypeScript program, which is used for analysis and emit.
169
+ */
170
+ tsProgram;
171
+ host;
172
+ incrementalStrategy;
173
+ constructor(rootNames, options, delegateHost, oldProgram) {
174
+ this.options = options;
175
+ const perfRecorder = ActivePerfRecorder.zeroedToNow();
176
+ perfRecorder.phase(PerfPhase.Setup);
177
+ if (!options.disableTypeScriptVersionCheck) {
178
+ verifySupportedTypeScriptVersion();
179
+ }
180
+ if (options.compilationMode === "experimental-local") {
181
+ options.noEmitOnError = false;
182
+ }
183
+ const reuseProgram = oldProgram?.compiler.getCurrentProgram();
184
+ this.host = NgCompilerHost.wrap(delegateHost, rootNames, options, reuseProgram ?? null);
185
+ if (reuseProgram !== void 0) {
186
+ retagAllTsFiles(reuseProgram);
187
+ }
188
+ this.tsProgram = perfRecorder.inPhase(PerfPhase.TypeScriptProgramCreate, () => ts3.createProgram(this.host.inputFiles, options, this.host, reuseProgram));
189
+ perfRecorder.phase(PerfPhase.Unaccounted);
190
+ perfRecorder.memory(PerfCheckpoint.TypeScriptProgramCreate);
191
+ this.host.postProgramCreationCleanup();
192
+ const programDriver = new TsCreateProgramDriver(this.tsProgram, this.host, this.options, this.host.shimExtensionPrefixes);
193
+ this.incrementalStrategy = oldProgram !== void 0 ? oldProgram.incrementalStrategy.toNextBuildStrategy() : new TrackedIncrementalBuildStrategy();
194
+ const modifiedResourceFiles = /* @__PURE__ */ new Set();
195
+ if (this.host.getModifiedResourceFiles !== void 0) {
196
+ const strings = this.host.getModifiedResourceFiles();
197
+ if (strings !== void 0) {
198
+ for (const fileString of strings) {
199
+ modifiedResourceFiles.add(absoluteFrom(fileString));
200
+ }
201
+ }
202
+ }
203
+ let ticket;
204
+ if (oldProgram === void 0) {
205
+ ticket = freshCompilationTicket(
206
+ this.tsProgram,
207
+ options,
208
+ this.incrementalStrategy,
209
+ programDriver,
210
+ perfRecorder,
211
+ /* enableTemplateTypeChecker */
212
+ false,
213
+ /* usePoisonedData */
214
+ false
215
+ );
216
+ } else {
217
+ ticket = incrementalFromCompilerTicket(oldProgram.compiler, this.tsProgram, this.incrementalStrategy, programDriver, modifiedResourceFiles, perfRecorder);
218
+ }
219
+ this.compiler = NgCompiler.fromTicket(ticket, this.host);
220
+ }
221
+ getTsProgram() {
222
+ return this.tsProgram;
223
+ }
224
+ getReuseTsProgram() {
225
+ return this.compiler.getCurrentProgram();
226
+ }
227
+ getTsOptionDiagnostics(cancellationToken) {
228
+ return this.compiler.perfRecorder.inPhase(PerfPhase.TypeScriptDiagnostics, () => this.tsProgram.getOptionsDiagnostics(cancellationToken));
229
+ }
230
+ getTsSyntacticDiagnostics(sourceFile, cancellationToken) {
231
+ return this.compiler.perfRecorder.inPhase(PerfPhase.TypeScriptDiagnostics, () => {
232
+ const ignoredFiles = this.compiler.ignoreForDiagnostics;
233
+ let res;
234
+ if (sourceFile !== void 0) {
235
+ if (ignoredFiles.has(sourceFile)) {
236
+ return [];
237
+ }
238
+ res = this.tsProgram.getSyntacticDiagnostics(sourceFile, cancellationToken);
239
+ } else {
240
+ const diagnostics = [];
241
+ for (const sf of this.tsProgram.getSourceFiles()) {
242
+ if (!ignoredFiles.has(sf)) {
243
+ diagnostics.push(...this.tsProgram.getSyntacticDiagnostics(sf, cancellationToken));
244
+ }
245
+ }
246
+ res = diagnostics;
247
+ }
248
+ return res;
249
+ });
250
+ }
251
+ getTsSemanticDiagnostics(sourceFile, cancellationToken) {
252
+ if (this.options.compilationMode === "experimental-local") {
253
+ return [];
254
+ }
255
+ return this.compiler.perfRecorder.inPhase(PerfPhase.TypeScriptDiagnostics, () => {
256
+ const ignoredFiles = this.compiler.ignoreForDiagnostics;
257
+ let res;
258
+ if (sourceFile !== void 0) {
259
+ if (ignoredFiles.has(sourceFile)) {
260
+ return [];
261
+ }
262
+ res = this.tsProgram.getSemanticDiagnostics(sourceFile, cancellationToken);
263
+ } else {
264
+ const diagnostics = [];
265
+ for (const sf of this.tsProgram.getSourceFiles()) {
266
+ if (!ignoredFiles.has(sf)) {
267
+ diagnostics.push(...this.tsProgram.getSemanticDiagnostics(sf, cancellationToken));
268
+ }
269
+ }
270
+ res = diagnostics;
271
+ }
272
+ return res;
273
+ });
274
+ }
275
+ getNgOptionDiagnostics(cancellationToken) {
276
+ return this.compiler.getOptionDiagnostics();
277
+ }
278
+ getNgStructuralDiagnostics(cancellationToken) {
279
+ return [];
280
+ }
281
+ getNgSemanticDiagnostics(fileName, cancellationToken) {
282
+ let sf = void 0;
283
+ if (fileName !== void 0) {
284
+ sf = this.tsProgram.getSourceFile(fileName);
285
+ if (sf === void 0) {
286
+ return [];
287
+ }
288
+ }
289
+ if (sf === void 0) {
290
+ return this.compiler.getDiagnostics();
291
+ } else {
292
+ return this.compiler.getDiagnosticsForFile(sf, OptimizeFor.WholeProgram);
293
+ }
294
+ }
295
+ /**
296
+ * Ensure that the `NgCompiler` has properly analyzed the program, and allow for the asynchronous
297
+ * loading of any resources during the process.
298
+ *
299
+ * This is used by the Angular CLI to allow for spawning (async) child compilations for things
300
+ * like SASS files used in `styleUrls`.
301
+ */
302
+ loadNgStructureAsync() {
303
+ return this.compiler.analyzeAsync();
304
+ }
305
+ listLazyRoutes(entryRoute) {
306
+ return [];
307
+ }
308
+ emitXi18n() {
309
+ const ctx = new MessageBundle(new HtmlParser(), [], {}, this.options.i18nOutLocale ?? null, this.options.i18nPreserveWhitespaceForLegacyExtraction);
310
+ this.compiler.xi18n(ctx);
311
+ i18nExtract(this.options.i18nOutFormat ?? null, this.options.i18nOutFile ?? null, this.host, this.options, ctx, resolve);
312
+ }
313
+ emit(opts) {
314
+ if (opts !== void 0 && opts.emitFlags !== void 0 && opts.emitFlags & EmitFlags.I18nBundle) {
315
+ this.emitXi18n();
316
+ if (!(opts.emitFlags & EmitFlags.JS)) {
317
+ return {
318
+ diagnostics: [],
319
+ emitSkipped: true,
320
+ emittedFiles: []
321
+ };
322
+ }
323
+ }
324
+ const forceEmit = opts?.forceEmit ?? false;
325
+ this.compiler.perfRecorder.memory(PerfCheckpoint.PreEmit);
326
+ const res = this.compiler.perfRecorder.inPhase(PerfPhase.TypeScriptEmit, () => {
327
+ const { transformers } = this.compiler.prepareEmit();
328
+ const ignoreFiles = this.compiler.ignoreForEmit;
329
+ const emitCallback = opts?.emitCallback ?? defaultEmitCallback;
330
+ const writeFile = (fileName, data, writeByteOrderMark, onError, sourceFiles) => {
331
+ if (sourceFiles !== void 0) {
332
+ for (const writtenSf of sourceFiles) {
333
+ if (writtenSf.isDeclarationFile) {
334
+ continue;
335
+ }
336
+ this.compiler.incrementalCompilation.recordSuccessfulEmit(writtenSf);
337
+ }
338
+ }
339
+ this.host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
340
+ };
341
+ const customTransforms = opts && opts.customTransformers;
342
+ const beforeTransforms = transformers.before || [];
343
+ const afterDeclarationsTransforms = transformers.afterDeclarations;
344
+ if (customTransforms !== void 0 && customTransforms.beforeTs !== void 0) {
345
+ beforeTransforms.push(...customTransforms.beforeTs);
346
+ }
347
+ const emitResults = [];
348
+ for (const targetSourceFile of this.tsProgram.getSourceFiles()) {
349
+ if (targetSourceFile.isDeclarationFile || ignoreFiles.has(targetSourceFile)) {
350
+ continue;
351
+ }
352
+ if (!forceEmit && this.compiler.incrementalCompilation.safeToSkipEmit(targetSourceFile)) {
353
+ this.compiler.perfRecorder.eventCount(PerfEvent.EmitSkipSourceFile);
354
+ continue;
355
+ }
356
+ this.compiler.perfRecorder.eventCount(PerfEvent.EmitSourceFile);
357
+ emitResults.push(emitCallback({
358
+ targetSourceFile,
359
+ program: this.tsProgram,
360
+ host: this.host,
361
+ options: this.options,
362
+ emitOnlyDtsFiles: false,
363
+ writeFile,
364
+ customTransformers: {
365
+ before: beforeTransforms,
366
+ after: customTransforms && customTransforms.afterTs,
367
+ afterDeclarations: afterDeclarationsTransforms
368
+ }
369
+ }));
370
+ }
371
+ this.compiler.perfRecorder.memory(PerfCheckpoint.Emit);
372
+ return (opts && opts.mergeEmitResultsCallback || mergeEmitResults)(emitResults);
373
+ });
374
+ if (this.options.tracePerformance !== void 0) {
375
+ const perf = this.compiler.perfRecorder.finalize();
376
+ getFileSystem().writeFile(getFileSystem().resolve(this.options.tracePerformance), JSON.stringify(perf, null, 2));
377
+ }
378
+ return res;
379
+ }
380
+ getIndexedComponents() {
381
+ return this.compiler.getIndexedComponents();
382
+ }
383
+ /**
384
+ * Gets information for the current program that may be used to generate API
385
+ * reference documentation. This includes Angular-specific information, such
386
+ * as component inputs and outputs.
387
+ *
388
+ * @param entryPoint Path to the entry point for the package for which API
389
+ * docs should be extracted.
390
+ */
391
+ getApiDocumentation(entryPoint, privateModules) {
392
+ return this.compiler.getApiDocumentation(entryPoint, privateModules);
393
+ }
394
+ getEmittedSourceFiles() {
395
+ throw new Error("Method not implemented.");
396
+ }
397
+ };
398
+ var defaultEmitCallback = ({ program, targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers }) => program.emit(targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
399
+ function mergeEmitResults(emitResults) {
400
+ const diagnostics = [];
401
+ let emitSkipped = false;
402
+ const emittedFiles = [];
403
+ for (const er of emitResults) {
404
+ diagnostics.push(...er.diagnostics);
405
+ emitSkipped = emitSkipped || er.emitSkipped;
406
+ emittedFiles.push(...er.emittedFiles || []);
407
+ }
408
+ return { diagnostics, emitSkipped, emittedFiles };
409
+ }
410
+
411
+ // packages/compiler-cli/src/transformers/program.js
412
+ function createProgram({ rootNames, options, host, oldProgram }) {
413
+ return new NgtscProgram(rootNames, options, host, oldProgram);
414
+ }
415
+
416
+ // packages/compiler-cli/src/perform_compile.js
417
+ import ts5 from "typescript";
418
+
419
+ // packages/compiler-cli/src/transformers/util.js
420
+ import ts4 from "typescript";
421
+ function createMessageDiagnostic(messageText) {
422
+ return {
423
+ file: void 0,
424
+ start: void 0,
425
+ length: void 0,
426
+ category: ts4.DiagnosticCategory.Message,
427
+ messageText,
428
+ code: DEFAULT_ERROR_CODE,
429
+ source: SOURCE
430
+ };
431
+ }
432
+
433
+ // packages/compiler-cli/src/perform_compile.js
434
+ var defaultFormatHost = {
435
+ getCurrentDirectory: () => ts5.sys.getCurrentDirectory(),
436
+ getCanonicalFileName: (fileName) => fileName,
437
+ getNewLine: () => ts5.sys.newLine
438
+ };
439
+ function formatDiagnostics(diags, host = defaultFormatHost) {
440
+ if (diags && diags.length) {
441
+ return diags.map((diagnostic) => replaceTsWithNgInErrors(ts5.formatDiagnosticsWithColorAndContext([diagnostic], host))).join("");
442
+ } else {
443
+ return "";
444
+ }
445
+ }
446
+ function calcProjectFileAndBasePath(project, host = getFileSystem()) {
447
+ const absProject = host.resolve(project);
448
+ const projectIsDir = host.lstat(absProject).isDirectory();
449
+ const projectFile = projectIsDir ? host.join(absProject, "tsconfig.json") : absProject;
450
+ const projectDir = projectIsDir ? absProject : host.dirname(absProject);
451
+ const basePath = host.resolve(projectDir);
452
+ return { projectFile, basePath };
453
+ }
454
+ function readConfiguration(project, existingOptions, host = getFileSystem()) {
455
+ try {
456
+ const fs = getFileSystem();
457
+ const readConfigFile = (configFile) => ts5.readConfigFile(configFile, (file) => host.readFile(host.resolve(file)));
458
+ const readAngularCompilerOptions = (configFile, parentOptions = {}) => {
459
+ const { config: config2, error: error2 } = readConfigFile(configFile);
460
+ if (error2) {
461
+ return parentOptions;
462
+ }
463
+ const angularCompilerOptions = config2.angularCompilerOptions ?? config2.bazelOptions?.angularCompilerOptions;
464
+ let existingNgCompilerOptions = { ...angularCompilerOptions, ...parentOptions };
465
+ if (!config2.extends) {
466
+ return existingNgCompilerOptions;
467
+ }
468
+ const extendsPaths = typeof config2.extends === "string" ? [config2.extends] : config2.extends;
469
+ return [...extendsPaths].reverse().reduce((prevOptions, extendsPath) => {
470
+ const extendedConfigPath = getExtendedConfigPath(configFile, extendsPath, host, fs);
471
+ return extendedConfigPath === null ? prevOptions : readAngularCompilerOptions(extendedConfigPath, prevOptions);
472
+ }, existingNgCompilerOptions);
473
+ };
474
+ const { projectFile, basePath } = calcProjectFileAndBasePath(project, host);
475
+ const configFileName = host.resolve(host.pwd(), projectFile);
476
+ const { config, error } = readConfigFile(projectFile);
477
+ if (error) {
478
+ return {
479
+ project,
480
+ errors: [error],
481
+ rootNames: [],
482
+ options: {},
483
+ emitFlags: EmitFlags.Default
484
+ };
485
+ }
486
+ const existingCompilerOptions = {
487
+ genDir: basePath,
488
+ basePath,
489
+ ...readAngularCompilerOptions(configFileName),
490
+ ...existingOptions
491
+ };
492
+ const parseConfigHost = createParseConfigHost(host, fs);
493
+ const { options, errors, fileNames: rootNames, projectReferences } = ts5.parseJsonConfigFileContent(config, parseConfigHost, basePath, existingCompilerOptions, configFileName);
494
+ let emitFlags = EmitFlags.Default;
495
+ if (!(options["skipMetadataEmit"] || options["flatModuleOutFile"])) {
496
+ emitFlags |= EmitFlags.Metadata;
497
+ }
498
+ if (options["skipTemplateCodegen"]) {
499
+ emitFlags = emitFlags & ~EmitFlags.Codegen;
500
+ }
501
+ return { project: projectFile, rootNames, projectReferences, options, errors, emitFlags };
502
+ } catch (e) {
503
+ const errors = [
504
+ {
505
+ category: ts5.DiagnosticCategory.Error,
506
+ messageText: e.stack ?? e.message,
507
+ file: void 0,
508
+ start: void 0,
509
+ length: void 0,
510
+ source: "angular",
511
+ code: UNKNOWN_ERROR_CODE
512
+ }
513
+ ];
514
+ return { project: "", errors, rootNames: [], options: {}, emitFlags: EmitFlags.Default };
515
+ }
516
+ }
517
+ function createParseConfigHost(host, fs = getFileSystem()) {
518
+ return {
519
+ fileExists: host.exists.bind(host),
520
+ readDirectory: createFileSystemTsReadDirectoryFn(fs),
521
+ readFile: host.readFile.bind(host),
522
+ useCaseSensitiveFileNames: fs.isCaseSensitive()
523
+ };
524
+ }
525
+ function getExtendedConfigPath(configFile, extendsValue, host, fs) {
526
+ const result = getExtendedConfigPathWorker(configFile, extendsValue, host, fs);
527
+ if (result !== null) {
528
+ return result;
529
+ }
530
+ return getExtendedConfigPathWorker(configFile, `${extendsValue}.json`, host, fs);
531
+ }
532
+ function getExtendedConfigPathWorker(configFile, extendsValue, host, fs) {
533
+ if (extendsValue.startsWith(".") || fs.isRooted(extendsValue)) {
534
+ const extendedConfigPath = host.resolve(host.dirname(configFile), extendsValue);
535
+ if (host.exists(extendedConfigPath)) {
536
+ return extendedConfigPath;
537
+ }
538
+ } else {
539
+ const parseConfigHost = createParseConfigHost(host, fs);
540
+ const { resolvedModule } = ts5.nodeModuleNameResolver(extendsValue, configFile, { moduleResolution: ts5.ModuleResolutionKind.Node10, resolveJsonModule: true }, parseConfigHost);
541
+ if (resolvedModule) {
542
+ return absoluteFrom(resolvedModule.resolvedFileName);
543
+ }
544
+ }
545
+ return null;
546
+ }
547
+ function exitCodeFromResult(diags) {
548
+ if (!diags)
549
+ return 0;
550
+ if (diags.every((diag) => diag.category !== ts5.DiagnosticCategory.Error)) {
551
+ return 0;
552
+ }
553
+ return diags.some((d) => d.source === "angular" && d.code === UNKNOWN_ERROR_CODE) ? 2 : 1;
554
+ }
555
+ function performCompilation({ rootNames, options, host, oldProgram, emitCallback, mergeEmitResultsCallback, gatherDiagnostics = defaultGatherDiagnostics, customTransformers, emitFlags = EmitFlags.Default, forceEmit = false, modifiedResourceFiles = null }) {
556
+ let program;
557
+ let emitResult;
558
+ let allDiagnostics = [];
559
+ try {
560
+ if (!host) {
561
+ host = createCompilerHost({ options });
562
+ }
563
+ if (modifiedResourceFiles) {
564
+ host.getModifiedResourceFiles = () => modifiedResourceFiles;
565
+ }
566
+ program = createProgram({ rootNames, host, options, oldProgram });
567
+ const beforeDiags = Date.now();
568
+ allDiagnostics.push(...gatherDiagnostics(program));
569
+ if (options.diagnostics) {
570
+ const afterDiags = Date.now();
571
+ allDiagnostics.push(createMessageDiagnostic(`Time for diagnostics: ${afterDiags - beforeDiags}ms.`));
572
+ }
573
+ if (!hasErrors(allDiagnostics)) {
574
+ emitResult = program.emit({
575
+ emitCallback,
576
+ mergeEmitResultsCallback,
577
+ customTransformers,
578
+ emitFlags,
579
+ forceEmit
580
+ });
581
+ allDiagnostics.push(...emitResult.diagnostics);
582
+ return { diagnostics: allDiagnostics, program, emitResult };
583
+ }
584
+ return { diagnostics: allDiagnostics, program };
585
+ } catch (e) {
586
+ program = void 0;
587
+ allDiagnostics.push({
588
+ category: ts5.DiagnosticCategory.Error,
589
+ messageText: e.stack ?? e.message,
590
+ code: UNKNOWN_ERROR_CODE,
591
+ file: void 0,
592
+ start: void 0,
593
+ length: void 0
594
+ });
595
+ return { diagnostics: allDiagnostics, program };
596
+ }
597
+ }
598
+ function defaultGatherDiagnostics(program) {
599
+ const allDiagnostics = [];
600
+ function checkDiagnostics(diags) {
601
+ if (diags) {
602
+ allDiagnostics.push(...diags);
603
+ return !hasErrors(diags);
604
+ }
605
+ return true;
606
+ }
607
+ let checkOtherDiagnostics = true;
608
+ checkOtherDiagnostics = checkOtherDiagnostics && checkDiagnostics([...program.getTsOptionDiagnostics(), ...program.getNgOptionDiagnostics()]);
609
+ checkOtherDiagnostics = checkOtherDiagnostics && checkDiagnostics(program.getTsSyntacticDiagnostics());
610
+ checkOtherDiagnostics = checkOtherDiagnostics && checkDiagnostics([
611
+ ...program.getTsSemanticDiagnostics(),
612
+ ...program.getNgStructuralDiagnostics()
613
+ ]);
614
+ checkOtherDiagnostics = checkOtherDiagnostics && checkDiagnostics(program.getNgSemanticDiagnostics());
615
+ return allDiagnostics;
616
+ }
617
+ function hasErrors(diags) {
618
+ return diags.some((d) => d.category === ts5.DiagnosticCategory.Error);
619
+ }
620
+
621
+ export {
622
+ DEFAULT_ERROR_CODE,
623
+ UNKNOWN_ERROR_CODE,
624
+ SOURCE,
625
+ isTsDiagnostic,
626
+ EmitFlags,
627
+ createCompilerHost,
628
+ NgtscProgram,
629
+ createProgram,
630
+ createMessageDiagnostic,
631
+ formatDiagnostics,
632
+ calcProjectFileAndBasePath,
633
+ readConfiguration,
634
+ exitCodeFromResult,
635
+ performCompilation,
636
+ defaultGatherDiagnostics
637
+ };
638
+ /**
639
+ * @license
640
+ * Copyright Google LLC All Rights Reserved.
641
+ *
642
+ * Use of this source code is governed by an MIT-style license that can be
643
+ * found in the LICENSE file at https://angular.dev/license
644
+ */