UNPKG

@storm-software/build-tools

Version:

A comprehensive set of tools for building and managing projects within a Storm workspace. Includes builders such as rollup, rolldown, tsup, and unbuild, along with various utilities.

81 lines (78 loc) 2.18 kB
import { findWorkspaceRoot } from "./chunk-TFYTC3YL.mjs"; import { correctPaths, joinPaths } from "./chunk-MXKJT3OE.mjs"; import { writeDebug } from "./chunk-R2HS3O2S.mjs"; // src/utilities/get-entry-points.ts import { glob } from "glob"; var getEntryPoints = async (config, projectRoot, sourceRoot, entry, emitOnAll = false) => { const workspaceRoot = config.workspaceRoot || findWorkspaceRoot(); const entryPoints = []; if (entry) { if (typeof entry === "string") { entryPoints.push(entry); } else if (Array.isArray(entry)) { entryPoints.push(...entry); } else { entryPoints.push(...Object.values(entry)); } } if (emitOnAll) { entryPoints.push( joinPaths(workspaceRoot, sourceRoot || projectRoot, "**/*.{ts,tsx}") ); } const results = await Promise.all( entryPoints.map(async (entryPoint) => { const paths = []; if (entryPoint.includes("*")) { const files = await glob(entryPoint, { withFileTypes: true, ignore: ["**/node_modules/**"] }); paths.push( ...files.reduce((ret, filePath) => { const result = correctPaths( joinPaths(filePath.path, filePath.name).replaceAll(correctPaths(workspaceRoot), "").replaceAll(correctPaths(projectRoot), "") ); if (result) { writeDebug( `Trying to add entry point ${result} at "${joinPaths( filePath.path, filePath.name )}"`, config ); if (!paths.includes(result)) { paths.push(result); } } return ret; }, []) ); } else { writeDebug(`Trying to add entry point ${entryPoint}"`, config); if (!paths.includes(entryPoint)) { paths.push(entryPoint); } } return paths; }) ); return results.filter(Boolean).reduce((ret, result) => { result.forEach((res) => { if (res && !ret.includes(res)) { ret.push(res); } }); return ret; }, []); }; export { getEntryPoints };