flush()

in tsc/tsc.js [66:108]


        flush(callback) {
            // this is a tsc internal switch.
            // https://github.com/Microsoft/TypeScript/blob/194c2bc2ca806f5f1014113329e33207f683037c/src/compiler/emitter.ts#L81
            options["listEmittedFiles"] = true;

            if (options.sourceRoot) {
                options.sourceRoot = path.resolve(options.sourceRoot);
            }

            const program = ts.createProgram(Object.values(files).map((file) => file.path), options);
            const emitResult = program.emit();
            const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
            const basePath = path.resolve(".");

            /** @type {boolean} */
            let hasError = false;

            allDiagnostics.forEach(diagnostic => {
                hasError = hasError || diagnostic.category === ts.DiagnosticCategory.Error;
                logDiagnostic(diagnostic, basePath);
            });

            if (hasError || emitResult.emitSkipped) {
                callback(new Error("Typescript compilation failed."));
                return;
            }

            if (emitResult.emittedFiles && emitResult.emittedFiles.length > 0) {
                emitResult.emittedFiles.forEach((emittedFilePath) => {
                    const emittedFileId = path.relative(options.outDir || ".", emittedFilePath);

                    if (emittedFileId in files) {
                        files[emittedFileId].path = emittedFilePath;

                        this.push(files[emittedFileId]);
                    } else {
                        this.push(vinyl(emittedFilePath, options.outDir));
                    }
                });
            }

            callback();
        },