Skip to content

Commit

Permalink
fix: watch mode not emitted transformed DTS files
Browse files Browse the repository at this point in the history
It appears that `builder.emitNextAffectedFile` causes the afterDeclaration transformer not to run which causes the DTS files to be emitted without Angular metadata.

Closes #2664 and closes angular/angular-cli#25706
  • Loading branch information
alan-agius4 committed Aug 29, 2023
1 parent 8edb94f commit a799883
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 22 deletions.
Expand Up @@ -54,7 +54,6 @@ function analyseEntryPoint(graph: BuildGraph, entryPoint: EntryPointNode, entryP
moduleResolutionCache,
undefined,
undefined,
undefined,
analysesSourcesFileCache,
);

Expand Down
16 changes: 1 addition & 15 deletions src/lib/ngc/compile-source-files.ts
Expand Up @@ -33,13 +33,11 @@ export async function compileSourceFiles(
);
}

const emittedFiles = new Set<string>();
const tsCompilerHost = cacheCompilerHost(
graph,
entryPoint,
tsConfigOptions,
moduleResolutionCache,
emittedFiles,
stylesheetProcessor,
inlineStyleLanguage,
);
Expand Down Expand Up @@ -188,28 +186,16 @@ export async function compileSourceFiles(
log.msg(formatDiagnostics(errorDiagnostics));
}

const transformers = angularCompiler.prepareEmit().transformers;
if ('getSemanticDiagnosticsOfNextAffectedFile' in builder) {
// TypeScript will loop until there are no more affected files in the program
while (builder.emitNextAffectedFile(undefined, undefined, undefined, transformers)) {
// empty
}
}

if (errorDiagnostics.length) {
throw new Error(formatDiagnostics(errorDiagnostics));
}

const transformers = angularCompiler.prepareEmit().transformers;
for (const sourceFile of builder.getSourceFiles()) {
if (ignoreForEmit.has(sourceFile)) {
continue;
}

if (emittedFiles.has(sourceFile.fileName)) {
angularCompiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
continue;
}

if (angularCompiler.incrementalCompilation.safeToSkipEmit(sourceFile)) {
continue;
}
Expand Down
6 changes: 0 additions & 6 deletions src/lib/ts/cache-compiler-host.ts
Expand Up @@ -18,7 +18,6 @@ export function cacheCompilerHost(
entryPoint: EntryPointNode,
compilerOptions: CompilerOptions,
moduleResolutionCache: ts.ModuleResolutionCache,
emittedFiles?: Set<string>,
stylesheetProcessor?: StylesheetProcessor,
inlineStyleLanguage?: NgPackageConfig['inlineStyleLanguage'],
sourcesFileCache: FileCache = entryPoint.cache.sourcesFileCache,
Expand Down Expand Up @@ -104,7 +103,6 @@ export function cacheCompilerHost(
}

sourceFiles.forEach(source => {
emittedFiles?.add(source.fileName);
const cache = sourcesFileCache.getOrCreate(source.fileName);
if (!cache.declarationFileName) {
cache.declarationFileName = ensureUnixPath(fileName);
Expand All @@ -127,10 +125,6 @@ export function cacheCompilerHost(
version,
map,
});

sourceFiles.forEach(source => {
emittedFiles?.add(source.fileName);
});
}

compilerHost.writeFile.call(this, fileName, data, writeByteOrderMark, onError, sourceFiles);
Expand Down

0 comments on commit a799883

Please sign in to comment.