UNPKG

@storm-software/unbuild

Version:

A package containing `unbuild` utilities for building Storm Software libraries and applications

63 lines (58 loc) 2.66 kB
import { writeTrace } from "./chunk-WH7FLZNL.js"; import { __name } from "./chunk-3GQAWCBQ.js"; // src/plugins/tsc.ts import { readCachedProjectGraph } from "@nx/devkit"; import { calculateProjectBuildableDependencies } from "@nx/js/src/utils/buildable-libs-utils"; import { getHelperDependency, HelperDependency } from "@nx/js/src/utils/compiler-helper-dependency"; import ts2Plugin from "rollup-plugin-typescript2"; // src/utilities/helpers.ts import { joinPathFragments } from "@nx/devkit"; import { computeCompilerOptionsPaths } from "@nx/js/src/utils/buildable-libs-utils"; import { dirname, extname } from "node:path"; import { pathToFileURL } from "node:url"; import ts from "typescript"; async function loadConfig(configPath) { if (!/\.(js|mjs)$/.test(extname(configPath))) { throw new Error("Unsupported config file format"); } return import(pathToFileURL(configPath).toString()).then((config) => config.default); } __name(loadConfig, "loadConfig"); async function createTsCompilerOptions(config, tsConfigPath, projectRoot, dependencies) { const tsConfigFile = ts.readConfigFile(joinPathFragments(config.workspaceRoot, projectRoot, tsConfigPath), ts.sys.readFile); const tsConfig = ts.parseJsonConfigFileContent(tsConfigFile.config, ts.sys, dirname(joinPathFragments(config.workspaceRoot, projectRoot, tsConfigPath))); const compilerOptions = { rootDir: projectRoot, declaration: true, paths: computeCompilerOptionsPaths(tsConfig, dependencies ?? []) }; writeTrace(compilerOptions, config); return compilerOptions; } __name(createTsCompilerOptions, "createTsCompilerOptions"); // src/plugins/tsc.ts var tscPlugin = /* @__PURE__ */ __name(async (options) => { const projectGraph = readCachedProjectGraph(); const result = calculateProjectBuildableDependencies(void 0, projectGraph, options.config.workspaceRoot, options.projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true); let dependencies = result.dependencies; const tsLibDependency = getHelperDependency(HelperDependency.tsc, options.tsconfig, dependencies, projectGraph, true); if (tsLibDependency) { dependencies = dependencies.filter((deps) => deps.name !== tsLibDependency.name); dependencies.push(tsLibDependency); } const compilerOptions = await createTsCompilerOptions(options.config, options.tsconfig, options.projectRoot, dependencies); return ts2Plugin({ check: options.declaration !== false, tsconfig: options.tsconfig, tsconfigOverride: compilerOptions }); }, "tscPlugin"); export { loadConfig, createTsCompilerOptions, tscPlugin };