HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-172-31-4-197 6.8.0-1036-aws #38~22.04.1-Ubuntu SMP Fri Aug 22 15:44:33 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/api-parametros/node_modules/@nestjs/cli/lib/compiler/plugins/plugin-metadata-generator.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginMetadataGenerator = void 0;
const constants_1 = require("../swc/constants");
const type_checker_host_1 = require("../swc/type-checker-host");
const typescript_loader_1 = require("../typescript-loader");
const plugin_metadata_printer_1 = require("./plugin-metadata-printer");
/**
 * Generates plugins metadata by traversing the AST of the project.
 * @example
 * ```ts
 * const generator = new PluginMetadataGenerator();
 * generator.generate({
 *  visitors: [
 *    new ReadonlyVisitor({ introspectComments: true, pathToSource: __dirname }),
 *  ],
 *  outputDir: __dirname,
 *  watch: true,
 *  tsconfigPath: 'tsconfig.build.json',
 * });
 * ```
 */
class PluginMetadataGenerator {
    constructor() {
        this.pluginMetadataPrinter = new plugin_metadata_printer_1.PluginMetadataPrinter();
        this.typeCheckerHost = new type_checker_host_1.TypeCheckerHost();
        this.typescriptLoader = new typescript_loader_1.TypeScriptBinaryLoader();
        this.tsBinary = this.typescriptLoader.load();
    }
    generate(options) {
        const { tsconfigPath, visitors, tsProgramRef, outputDir, watch, filename, printDiagnostics = true, } = options;
        if (visitors.length === 0) {
            return;
        }
        if (tsProgramRef) {
            return this.traverseAndPrintMetadata(tsProgramRef, visitors, outputDir, filename);
        }
        const onTypeCheckOrProgramInit = (program) => {
            this.traverseAndPrintMetadata(program, visitors, outputDir, filename);
            if (printDiagnostics) {
                const tsBinary = this.typescriptLoader.load();
                const diagnostics = tsBinary.getPreEmitDiagnostics(program);
                if (diagnostics.length > 0) {
                    const formatDiagnosticsHost = {
                        getCanonicalFileName: (path) => path,
                        getCurrentDirectory: tsBinary.sys.getCurrentDirectory,
                        getNewLine: () => tsBinary.sys.newLine,
                    };
                    console.log();
                    console.log(tsBinary.formatDiagnosticsWithColorAndContext(diagnostics, formatDiagnosticsHost));
                }
                else {
                    console.log(constants_1.FOUND_NO_ISSUES_GENERATING_METADATA);
                }
            }
        };
        this.typeCheckerHost.run(tsconfigPath, {
            watch,
            onTypeCheck: onTypeCheckOrProgramInit,
            onProgramInit: onTypeCheckOrProgramInit,
        });
    }
    traverseAndPrintMetadata(programRef, visitors, outputDir, filename) {
        for (const sourceFile of programRef.getSourceFiles()) {
            if (!sourceFile.isDeclarationFile) {
                visitors.forEach((visitor) => visitor.visit(programRef, sourceFile));
            }
        }
        let typeImports = {};
        const collectedMetadata = {};
        visitors.forEach((visitor) => {
            collectedMetadata[visitor.key] = visitor.collect();
            typeImports = {
                ...typeImports,
                ...visitor.typeImports,
            };
        });
        this.pluginMetadataPrinter.print(collectedMetadata, typeImports, {
            outputDir,
            filename,
        }, this.tsBinary);
    }
}
exports.PluginMetadataGenerator = PluginMetadataGenerator;