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/web.enelar.com.co/node_modules/nx/src/command-line/graph/graph.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateGraph = void 0;
const crypto_1 = require("crypto");
const fs_1 = require("fs");
const fs_extra_1 = require("fs-extra");
const http = require("http");
const minimatch = require("minimatch");
const node_url_1 = require("node:url");
const open = require("open");
const path_1 = require("path");
const perf_hooks_1 = require("perf_hooks");
const configuration_1 = require("../../config/configuration");
const fileutils_1 = require("../../utils/fileutils");
const output_1 = require("../../utils/output");
const workspace_root_1 = require("../../utils/workspace-root");
const client_1 = require("../../daemon/client/client");
const typescript_1 = require("../../plugins/js/utils/typescript");
const operators_1 = require("../../project-graph/operators");
const project_graph_1 = require("../../project-graph/project-graph");
const create_task_graph_1 = require("../../tasks-runner/create-task-graph");
const all_file_data_1 = require("../../utils/all-file-data");
const command_line_utils_1 = require("../../utils/command-line-utils");
const native_1 = require("../../native");
const transform_objects_1 = require("../../native/transform-objects");
const affected_1 = require("../affected/affected");
const nx_deps_cache_1 = require("../../project-graph/nx-deps-cache");
const task_hasher_1 = require("../../hasher/task-hasher");
const create_task_hasher_1 = require("../../hasher/create-task-hasher");
// maps file extention to MIME types
const mimeType = {
    '.ico': 'image/x-icon',
    '.html': 'text/html',
    '.js': 'text/javascript',
    '.json': 'application/json',
    '.css': 'text/css',
    '.png': 'image/png',
    '.jpg': 'image/jpeg',
    '.wav': 'audio/wav',
    '.mp3': 'audio/mpeg',
    '.svg': 'image/svg+xml',
    '.pdf': 'application/pdf',
    '.doc': 'application/msword',
    '.eot': 'appliaction/vnd.ms-fontobject',
    '.ttf': 'aplication/font-sfnt',
};
function buildEnvironmentJs(exclude, watchMode, localMode, depGraphClientResponse, taskGraphClientResponse, expandedTaskInputsReponse, sourceMapsResponse) {
    let environmentJs = `window.exclude = ${JSON.stringify(exclude)};
  window.watch = ${!!watchMode};
  window.environment = 'release';
  window.localMode = '${localMode}';

  window.appConfig = {
    showDebugger: false,
    showExperimentalFeatures: false,
    workspaces: [
      {
        id: 'local',
        label: 'local',
        projectGraphUrl: 'project-graph.json',
        taskGraphUrl: 'task-graph.json',
        taskInputsUrl: 'task-inputs.json',
        sourceMapsUrl: 'source-maps.json'
      }
    ],
    defaultWorkspaceId: 'local',
  };
  `;
    if (localMode === 'build') {
        environmentJs += `window.projectGraphResponse = ${JSON.stringify(depGraphClientResponse)};
    `;
        environmentJs += `window.taskGraphResponse = ${JSON.stringify(taskGraphClientResponse)};
    `;
        environmentJs += `window.expandedTaskInputsResponse = ${JSON.stringify(expandedTaskInputsReponse)};`;
        environmentJs += `window.sourceMapsResponse = ${JSON.stringify(sourceMapsResponse)};`;
    }
    else {
        environmentJs += `window.projectGraphResponse = null;`;
        environmentJs += `window.taskGraphResponse = null;`;
        environmentJs += `window.expandedTaskInputsResponse = null;`;
        environmentJs += `window.sourceMapsResponse = null;`;
    }
    return environmentJs;
}
function projectExists(projects, projectToFind) {
    return (projects.find((project) => project.name === projectToFind) !== undefined);
}
function hasPath(graph, target, node, visited) {
    if (target === node)
        return true;
    for (let d of graph.dependencies[node] || []) {
        if (visited.indexOf(d.target) > -1)
            continue;
        visited.push(d.target);
        if (hasPath(graph, target, d.target, visited))
            return true;
    }
    return false;
}
function filterGraph(graph, focus, exclude) {
    let projectNames = Object.values(graph.nodes).map((project) => project.name);
    let filteredProjectNames;
    if (focus !== null) {
        filteredProjectNames = new Set();
        projectNames.forEach((p) => {
            const isInPath = hasPath(graph, p, focus, []) || hasPath(graph, focus, p, []);
            if (isInPath) {
                filteredProjectNames.add(p);
            }
        });
    }
    else {
        filteredProjectNames = new Set(projectNames);
    }
    if (exclude.length !== 0) {
        exclude.forEach((p) => filteredProjectNames.delete(p));
    }
    let filteredGraph = {
        nodes: {},
        dependencies: {},
    };
    filteredProjectNames.forEach((p) => {
        filteredGraph.nodes[p] = graph.nodes[p];
        filteredGraph.dependencies[p] = graph.dependencies[p];
    });
    return filteredGraph;
}
async function generateGraph(args, affectedProjects) {
    if (Array.isArray(args.targets) &&
        args.targets.length > 1 &&
        args.file &&
        !(args.file === 'stdout' || args.file.endsWith('.json'))) {
        output_1.output.warn({
            title: 'Showing Multiple Targets is not supported yet',
            bodyLines: [
                `Only the task graph for "${args.targets[0]}" tasks will be shown`,
            ],
        });
    }
    if (args.view === 'project-details' && !args.focus) {
        output_1.output.error({
            title: `The project details view requires the --focus option.`,
        });
        process.exit(1);
    }
    if (args.view === 'project-details' && (args.targets || args.affected)) {
        output_1.output.error({
            title: `The project details view can only be used with the --focus option.`,
            bodyLines: [
                `You passed ${args.targets ? '--targets ' : ''}${args.affected ? '--affected ' : ''}`,
            ],
        });
        process.exit(1);
    }
    // TODO: Graph Client should support multiple targets
    const target = Array.isArray(args.targets && args.targets.length >= 1)
        ? args.targets[0]
        : args.targets;
    const { projectGraph: rawGraph, sourceMaps } = await (0, project_graph_1.createProjectGraphAndSourceMapsAsync)({
        exitOnError: true,
    });
    let prunedGraph = (0, operators_1.pruneExternalNodes)(rawGraph);
    const projects = Object.values(prunedGraph.nodes);
    projects.sort((a, b) => {
        return a.name.localeCompare(b.name);
    });
    if (args.focus) {
        if (!projectExists(projects, args.focus)) {
            output_1.output.error({
                title: `Project to focus does not exist.`,
                bodyLines: [`You provided --focus=${args.focus}`],
            });
            process.exit(1);
        }
    }
    if (args.affected) {
        affectedProjects = (await (0, affected_1.getAffectedGraphNodes)((0, command_line_utils_1.splitArgsIntoNxArgsAndOverrides)(args, 'affected', { printWarnings: true }, (0, configuration_1.readNxJson)()).nxArgs, rawGraph)).map((n) => n.name);
    }
    if (args.exclude) {
        const invalidExcludes = [];
        args.exclude.forEach((project) => {
            if (!projectExists(projects, project)) {
                invalidExcludes.push(project);
            }
        });
        if (invalidExcludes.length > 0) {
            output_1.output.error({
                title: `The following projects provided to --exclude do not exist:`,
                bodyLines: invalidExcludes,
            });
            process.exit(1);
        }
    }
    let html = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../core/graph/index.html'), 'utf-8');
    prunedGraph = filterGraph(prunedGraph, args.focus || null, args.exclude || []);
    if (args.file) {
        // stdout is a magical constant that doesn't actually write a file
        if (args.file === 'stdout') {
            console.log(JSON.stringify(await createJsonOutput(prunedGraph, rawGraph, args.projects, args.targets), null, 2));
            process.exit(0);
        }
        const workspaceFolder = workspace_root_1.workspaceRoot;
        const ext = (0, path_1.extname)(args.file);
        const fullFilePath = (0, path_1.isAbsolute)(args.file)
            ? args.file
            : (0, path_1.join)(workspaceFolder, args.file);
        const fileFolderPath = (0, path_1.dirname)(fullFilePath);
        if (ext === '.html') {
            const assetsFolder = (0, path_1.join)(fileFolderPath, 'static');
            const assets = [];
            (0, fs_extra_1.copySync)((0, path_1.join)(__dirname, '../../core/graph'), assetsFolder, {
                filter: (_src, dest) => {
                    const isntHtml = !/index\.html/.test(dest);
                    if (isntHtml && dest.includes('.')) {
                        assets.push(dest);
                    }
                    return isntHtml;
                },
            });
            const { projectGraphClientResponse } = await createProjectGraphAndSourceMapClientResponse(affectedProjects);
            const taskGraphClientResponse = await createTaskGraphClientResponse();
            const taskInputsReponse = await createExpandedTaskInputResponse(taskGraphClientResponse, projectGraphClientResponse);
            const environmentJs = buildEnvironmentJs(args.exclude || [], args.watch, !!args.file && args.file.endsWith('html') ? 'build' : 'serve', projectGraphClientResponse, taskGraphClientResponse, taskInputsReponse, sourceMaps);
            html = html.replace(/src="/g, 'src="static/');
            html = html.replace(/href="styles/g, 'href="static/styles');
            html = html.replace('<base href="/" />', '');
            html = html.replace(/type="module"/g, '');
            (0, fs_1.writeFileSync)(fullFilePath, html);
            (0, fs_1.writeFileSync)((0, path_1.join)(assetsFolder, 'environment.js'), environmentJs);
            output_1.output.success({
                title: `HTML output created in ${fileFolderPath}`,
                bodyLines: [fileFolderPath, ...assets],
            });
        }
        else if (ext === '.json') {
            (0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(fullFilePath));
            const json = await createJsonOutput(prunedGraph, rawGraph, args.projects, args.targets);
            json.affectedProjects = affectedProjects;
            json.criticalPath = affectedProjects;
            (0, fileutils_1.writeJsonFile)(fullFilePath, json);
            output_1.output.warn({
                title: 'JSON output contains deprecated fields:',
                bodyLines: [
                    '- affectedProjects',
                    '- criticalPath',
                    '',
                    'These fields will be removed in Nx 18. If you need to see which projects were affected, use `nx show projects --affected`.',
                ],
            });
            output_1.output.success({
                title: `JSON output created in ${fileFolderPath}`,
                bodyLines: [fullFilePath],
            });
        }
        else {
            output_1.output.error({
                title: `Please specify a filename with either .json or .html extension.`,
                bodyLines: [`You provided --file=${args.file}`],
            });
            process.exit(1);
        }
        process.exit(0);
    }
    else {
        const environmentJs = buildEnvironmentJs(args.exclude || [], args.watch, !!args.file && args.file.endsWith('html') ? 'build' : 'serve');
        const { app, url } = await startServer(html, environmentJs, args.host || '127.0.0.1', args.port || 4211, args.watch, affectedProjects, args.focus, args.groupByFolder, args.exclude);
        url.pathname = args.view;
        if (args.focus) {
            url.pathname += '/' + args.focus;
        }
        if (target) {
            url.pathname += '/' + target;
        }
        if (args.all) {
            url.pathname += '/all';
        }
        else if (args.projects) {
            url.searchParams.append('projects', args.projects.map((projectName) => projectName).join(' '));
        }
        else if (args.affected) {
            url.pathname += '/affected';
        }
        if (args.groupByFolder) {
            url.searchParams.append('groupByFolder', 'true');
        }
        output_1.output.success({
            title: `Project graph started at ${url.toString()}`,
        });
        if (args.open) {
            open(url.toString());
        }
        return new Promise((res) => {
            app.once('close', res);
        });
    }
}
exports.generateGraph = generateGraph;
async function startServer(html, environmentJs, host, port = 4211, watchForchanges = false, affected = [], focus = null, groupByFolder = false, exclude = []) {
    let unregisterFileWatcher;
    if (watchForchanges) {
        unregisterFileWatcher = await createFileWatcher();
    }
    const { projectGraphClientResponse, sourceMapResponse } = await createProjectGraphAndSourceMapClientResponse(affected);
    currentProjectGraphClientResponse = projectGraphClientResponse;
    currentProjectGraphClientResponse.focus = focus;
    currentProjectGraphClientResponse.groupByFolder = groupByFolder;
    currentProjectGraphClientResponse.exclude = exclude;
    const app = http.createServer(async (req, res) => {
        // parse URL
        const parsedUrl = new node_url_1.URL(req.url, `http://${host}:${port}`);
        // extract URL path
        // Avoid https://en.wikipedia.org/wiki/Directory_traversal_attack
        // e.g curl --path-as-is http://localhost:9000/../fileInDanger.txt
        // by limiting the path to current directory only
        const sanitizePath = (0, path_1.basename)(parsedUrl.pathname);
        if (sanitizePath === 'project-graph.json') {
            res.writeHead(200, { 'Content-Type': 'application/json' });
            res.end(JSON.stringify(currentProjectGraphClientResponse));
            return;
        }
        if (sanitizePath === 'task-graph.json') {
            res.writeHead(200, { 'Content-Type': 'application/json' });
            res.end(JSON.stringify(await createTaskGraphClientResponse()));
            return;
        }
        if (sanitizePath === 'task-inputs.json') {
            perf_hooks_1.performance.mark('task input generation:start');
            const taskId = parsedUrl.searchParams.get('taskId');
            res.writeHead(200, { 'Content-Type': 'application/json' });
            const inputs = await getExpandedTaskInputs(taskId);
            perf_hooks_1.performance.mark('task input generation:end');
            res.end(JSON.stringify({ [taskId]: inputs }));
            perf_hooks_1.performance.measure('task input generation', 'task input generation:start', 'task input generation:end');
            return;
        }
        if (sanitizePath === 'source-maps.json') {
            res.writeHead(200, { 'Content-Type': 'application/json' });
            res.end(JSON.stringify(currentSourceMapsClientResponse));
            return;
        }
        if (sanitizePath === 'currentHash') {
            res.writeHead(200, { 'Content-Type': 'application/json' });
            res.end(JSON.stringify({ hash: currentProjectGraphClientResponse.hash }));
            return;
        }
        if (sanitizePath === 'environment.js') {
            res.writeHead(200, { 'Content-Type': 'application/javascript' });
            res.end(environmentJs);
            return;
        }
        let pathname = (0, path_1.join)(__dirname, '../../core/graph/', sanitizePath);
        // if the file is not found or is a directory, return index.html
        if (!(0, fs_1.existsSync)(pathname) || (0, fs_1.statSync)(pathname).isDirectory()) {
            res.writeHead(200, { 'Content-Type': 'text/html' });
            res.end(html);
            return;
        }
        try {
            const data = (0, fs_1.readFileSync)(pathname);
            const ext = (0, path_1.parse)(pathname).ext;
            res.setHeader('Content-type', mimeType[ext] || 'text/plain');
            res.end(data);
        }
        catch (err) {
            res.statusCode = 500;
            res.end(`Error getting the file: ${err}.`);
        }
    });
    const handleTermination = async (exitCode) => {
        if (unregisterFileWatcher) {
            unregisterFileWatcher();
        }
        process.exit(exitCode);
    };
    process.on('SIGINT', () => handleTermination(128 + 2));
    process.on('SIGTERM', () => handleTermination(128 + 15));
    return new Promise((res) => {
        app.listen(port, host, () => {
            res({ app, url: new node_url_1.URL(`http://${host}:${port}`) });
        });
    });
}
let currentProjectGraphClientResponse = {
    hash: null,
    projects: [],
    dependencies: {},
    fileMap: {},
    layout: {
        appsDir: '',
        libsDir: '',
    },
    affected: [],
    focus: null,
    groupByFolder: false,
    exclude: [],
};
let currentSourceMapsClientResponse = {};
function debounce(fn, time) {
    let timeout;
    return (...args) => {
        if (timeout) {
            clearTimeout(timeout);
        }
        timeout = setTimeout(() => fn(...args), time);
    };
}
function createFileWatcher() {
    return client_1.daemonClient.registerFileWatcher({ watchProjects: 'all', includeGlobalWorkspaceFiles: true }, debounce(async (error, changes) => {
        if (error === 'closed') {
            output_1.output.error({ title: `Watch error: Daemon closed the connection` });
            process.exit(1);
        }
        else if (error) {
            output_1.output.error({ title: `Watch error: ${error?.message ?? 'Unknown'}` });
        }
        else if (changes !== null && changes.changedFiles.length > 0) {
            output_1.output.note({ title: 'Recalculating project graph...' });
            const { projectGraphClientResponse, sourceMapResponse } = await createProjectGraphAndSourceMapClientResponse();
            if (projectGraphClientResponse.hash !==
                currentProjectGraphClientResponse.hash) {
                output_1.output.note({ title: 'Graph changes updated.' });
                currentProjectGraphClientResponse = projectGraphClientResponse;
                currentSourceMapsClientResponse = sourceMapResponse;
            }
            else {
                output_1.output.note({ title: 'No graph changes found.' });
            }
        }
    }, 500));
}
async function createProjectGraphAndSourceMapClientResponse(affected = []) {
    perf_hooks_1.performance.mark('project graph watch calculation:start');
    const { projectGraph, sourceMaps } = await (0, project_graph_1.createProjectGraphAndSourceMapsAsync)({ exitOnError: true });
    let graph = (0, operators_1.pruneExternalNodes)(projectGraph);
    let fileMap = (0, nx_deps_cache_1.readFileMapCache)().fileMap.projectFileMap;
    perf_hooks_1.performance.mark('project graph watch calculation:end');
    perf_hooks_1.performance.mark('project graph response generation:start');
    const layout = (0, configuration_1.workspaceLayout)();
    const projects = Object.values(graph.nodes);
    const dependencies = graph.dependencies;
    const hasher = (0, crypto_1.createHash)('sha256');
    hasher.update(JSON.stringify({ layout, projects, dependencies }));
    const hash = hasher.digest('hex');
    perf_hooks_1.performance.mark('project graph response generation:end');
    perf_hooks_1.performance.measure('project graph watch calculation', 'project graph watch calculation:start', 'project graph watch calculation:end');
    perf_hooks_1.performance.measure('project graph response generation', 'project graph response generation:start', 'project graph response generation:end');
    return {
        projectGraphClientResponse: {
            ...currentProjectGraphClientResponse,
            hash,
            layout,
            projects,
            dependencies,
            affected,
            fileMap,
        },
        sourceMapResponse: sourceMaps,
    };
}
async function createTaskGraphClientResponse(pruneExternal = false) {
    let graph;
    if (pruneExternal) {
        graph = (0, operators_1.pruneExternalNodes)(await (0, project_graph_1.createProjectGraphAsync)({ exitOnError: true }));
    }
    else {
        graph = await (0, project_graph_1.createProjectGraphAsync)({ exitOnError: true });
    }
    const nxJson = (0, configuration_1.readNxJson)();
    perf_hooks_1.performance.mark('task graph generation:start');
    const taskGraphs = getAllTaskGraphsForWorkspace(nxJson, graph);
    perf_hooks_1.performance.mark('task graph generation:end');
    const planner = new native_1.HashPlanner(nxJson, (0, native_1.transferProjectGraph)((0, transform_objects_1.transformProjectGraphForRust)(graph)));
    perf_hooks_1.performance.mark('task hash plan generation:start');
    const plans = {};
    for (const individualTaskGraph of Object.values(taskGraphs.taskGraphs)) {
        for (const task of Object.values(individualTaskGraph.tasks)) {
            if (plans[task.id]) {
                continue;
            }
            plans[task.id] = planner.getPlans([task.id], individualTaskGraph)[task.id];
        }
    }
    perf_hooks_1.performance.mark('task hash plan generation:end');
    perf_hooks_1.performance.measure('task graph generation', 'task graph generation:start', 'task graph generation:end');
    perf_hooks_1.performance.measure('task hash plan generation', 'task hash plan generation:start', 'task hash plan generation:end');
    return {
        ...taskGraphs,
        plans,
    };
}
async function createExpandedTaskInputResponse(taskGraphClientResponse, depGraphClientResponse) {
    perf_hooks_1.performance.mark('task input static generation:start');
    const allWorkspaceFiles = await (0, all_file_data_1.allFileData)();
    const response = {};
    Object.entries(taskGraphClientResponse.plans).forEach(([key, inputs]) => {
        const [project] = key.split(':');
        const expandedInputs = expandInputs(inputs, depGraphClientResponse.projects.find((p) => p.name === project), allWorkspaceFiles, depGraphClientResponse);
        response[key] = expandedInputs;
    });
    perf_hooks_1.performance.mark('task input static generation:end');
    perf_hooks_1.performance.measure('task input static generation', 'task input static generation:start', 'task input static generation:end');
    return response;
}
function getAllTaskGraphsForWorkspace(nxJson, projectGraph) {
    const defaultDependencyConfigs = (0, create_task_graph_1.mapTargetDefaultsToDependencies)(nxJson.targetDefaults);
    const taskGraphs = {};
    const taskGraphErrors = {};
    // TODO(cammisuli): improve performance here. Cache results or something.
    for (const projectName in projectGraph.nodes) {
        const project = projectGraph.nodes[projectName];
        const targets = Object.keys(project.data.targets ?? {});
        targets.forEach((target) => {
            const taskId = createTaskId(projectName, target);
            try {
                taskGraphs[taskId] = (0, create_task_graph_1.createTaskGraph)(projectGraph, defaultDependencyConfigs, [projectName], [target], undefined, {});
            }
            catch (err) {
                taskGraphs[taskId] = {
                    tasks: {},
                    dependencies: {},
                    roots: [],
                };
                taskGraphErrors[taskId] = err.message;
            }
            const configurations = Object.keys(project.data.targets[target]?.configurations || {});
            if (configurations.length > 0) {
                configurations.forEach((configuration) => {
                    const taskId = createTaskId(projectName, target, configuration);
                    try {
                        taskGraphs[taskId] = (0, create_task_graph_1.createTaskGraph)(projectGraph, defaultDependencyConfigs, [projectName], [target], configuration, {});
                    }
                    catch (err) {
                        taskGraphs[taskId] = {
                            tasks: {},
                            dependencies: {},
                            roots: [],
                        };
                        taskGraphErrors[taskId] = err.message;
                    }
                });
            }
        });
    }
    return { taskGraphs, errors: taskGraphErrors };
}
function createTaskId(projectId, targetId, configurationId) {
    if (configurationId) {
        return `${projectId}:${targetId}:${configurationId}`;
    }
    else {
        return `${projectId}:${targetId}`;
    }
}
async function getExpandedTaskInputs(taskId) {
    const [project] = taskId.split(':');
    const taskGraphResponse = await createTaskGraphClientResponse(false);
    const allWorkspaceFiles = await (0, all_file_data_1.allFileData)();
    const inputs = taskGraphResponse.plans[taskId];
    if (inputs) {
        return expandInputs(inputs, currentProjectGraphClientResponse.projects.find((p) => p.name === project), allWorkspaceFiles, currentProjectGraphClientResponse);
    }
    return {};
}
function expandInputs(inputs, project, allWorkspaceFiles, depGraphClientResponse) {
    const projectNames = depGraphClientResponse.projects.map((p) => p.name);
    const workspaceRootInputs = [];
    const projectRootInputs = [];
    const externalInputs = [];
    const otherInputs = [];
    inputs.forEach((input) => {
        if (input.startsWith('{workspaceRoot}')) {
            workspaceRootInputs.push(input);
            return;
        }
        const maybeProjectName = input.split(':')[0];
        if (projectNames.includes(maybeProjectName)) {
            projectRootInputs.push(input);
            return;
        }
        if (input === 'ProjectConfiguration' ||
            input === 'TsConfig' ||
            input === 'AllExternalDependencies') {
            otherInputs.push(input);
            return;
        }
        // there shouldn't be any other imports in here, but external ones are always going to have a modifier in front
        if (input.includes(':')) {
            externalInputs.push(input);
            return;
        }
    });
    const workspaceRootsExpanded = workspaceRootInputs.flatMap((input) => {
        const matches = [];
        const withoutWorkspaceRoot = input.substring(16);
        const matchingFile = allWorkspaceFiles.find((t) => t.file === withoutWorkspaceRoot);
        if (matchingFile) {
            matches.push(matchingFile.file);
        }
        else {
            allWorkspaceFiles
                .filter((f) => minimatch(f.file, withoutWorkspaceRoot))
                .forEach((f) => {
                matches.push(f.file);
            });
        }
        return matches;
    });
    const otherInputsExpanded = otherInputs.map((input) => {
        if (input === 'TsConfig') {
            return (0, path_1.relative)(workspace_root_1.workspaceRoot, (0, typescript_1.getRootTsConfigPath)());
        }
        if (input === 'ProjectConfiguration') {
            return depGraphClientResponse.fileMap[project.name].find((file) => file.file === `${project.data.root}/project.json` ||
                file.file === `${project.data.root}/package.json`).file;
        }
        return input;
    });
    const projectRootsExpanded = projectRootInputs
        .map((input) => {
        const fileSetProjectName = input.split(':')[0];
        const fileSetProject = depGraphClientResponse.projects.find((p) => p.name === fileSetProjectName);
        const fileSets = input.replace(`${fileSetProjectName}:`, '').split(',');
        const projectInputExpanded = {
            [fileSetProject.name]: (0, task_hasher_1.filterUsingGlobPatterns)(fileSetProject.data.root, depGraphClientResponse.fileMap[fileSetProject.name], fileSets).map((f) => f.file),
        };
        return projectInputExpanded;
    })
        .reduce((curr, acc) => {
        for (let key in curr) {
            acc[key] = curr[key];
        }
        return acc;
    }, {});
    return {
        general: [...workspaceRootsExpanded, ...otherInputsExpanded],
        ...projectRootsExpanded,
        external: externalInputs,
    };
}
async function createJsonOutput(prunedGraph, rawGraph, projects, targets) {
    const response = {
        graph: prunedGraph,
    };
    if (targets?.length) {
        const nxJson = (0, configuration_1.readNxJson)();
        const defaultDependencyConfigs = (0, create_task_graph_1.mapTargetDefaultsToDependencies)(nxJson.targetDefaults);
        const taskGraph = (0, create_task_graph_1.createTaskGraph)(rawGraph, defaultDependencyConfigs, projects, targets, undefined, {});
        const hasher = (0, create_task_hasher_1.createTaskHasher)(rawGraph, (0, configuration_1.readNxJson)());
        let tasks = Object.values(taskGraph.tasks);
        const hashes = await hasher.hashTasks(tasks, taskGraph);
        response.tasks = taskGraph;
        response.taskPlans = tasks.reduce((acc, task, index) => {
            acc[task.id] = Object.keys(hashes[index].details.nodes).sort();
            return acc;
        }, {});
    }
    return response;
}