UNPKG

@nx/esbuild

Version:

The Nx Plugin for esbuild contains executors and generators that support building applications using esbuild

59 lines (58 loc) 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEntryPoints = getEntryPoints; const devkit_1 = require("@nx/devkit"); const fs = require("fs"); const path = require("path"); const tinyglobby_1 = require("tinyglobby"); function getEntryPoints(projectName, context, options = {}) { const entryPoints = options.initialEntryPoints ? new Set(options.initialEntryPoints) : new Set(); const seenProjects = new Set(); const findEntryPoints = (projectName, tsConfigFileName) => { if (seenProjects.has(projectName)) return; seenProjects.add(projectName); const project = context.projectGraph?.nodes[projectName]; if (!project) return; // Known files we generate from our generators. Only one of these should be used to build the project. const tsconfigCandidates = [ 'tsconfig.app.json', 'tsconfig.lib.json', 'tsconfig.json', ]; if (tsConfigFileName) tsconfigCandidates.unshift(tsConfigFileName); const foundTsConfig = tsconfigCandidates.find((f) => { try { return fs.statSync(path.join(project.data.root, f)).isFile(); } catch { return false; } }); // Workspace projects may not be a TS project, so skip reading source files if tsconfig is not found. if (foundTsConfig) { const tsconfig = (0, devkit_1.readJsonFile)(path.join(project.data.root, foundTsConfig)); const projectFiles = (0, tinyglobby_1.globSync)(tsconfig.include ?? [], { cwd: project.data.root, ignore: tsconfig.exclude ?? [], expandDirectories: false, }).map((f) => path.join(project.data.root, f)); projectFiles.forEach((f) => entryPoints.add(f)); options?.onProjectFilesMatched?.(projectName, projectFiles); } if (options.recursive) { const deps = context.projectGraph.dependencies[projectName]; deps.forEach((dep) => { if (context.projectGraph.nodes[dep.target]) { findEntryPoints(dep.target); } }); } }; findEntryPoints(projectName, options.initialTsConfigFileName); return Array.from(entryPoints); }