UNPKG

@storm-software/workspace-tools

Version:

Tools for managing a Storm workspace, including various Nx generators and executors for common development tasks.

117 lines (114 loc) 3.87 kB
import { cargoMetadata } from "./chunk-ZTN2676G.mjs"; import { withRunExecutor } from "./chunk-EYZGKQNH.mjs"; import { correctPaths, isAbsolute, joinPaths, relative } from "./chunk-TBW5MCN6.mjs"; // src/executors/napi/executor.ts import { createJiti } from "jiti"; import { fileExists } from "nx/src/utils/fileutils"; async function napiExecutor(options, context, config) { const jiti = createJiti(config.workspaceRoot, { fsCache: config.skipCache ? false : joinPaths( config.workspaceRoot, config.directories.cache || "node_modules/.cache/storm", "jiti" ), interopDefault: true }); const { NapiCli } = await jiti.import( jiti.esmResolve("@napi-rs/cli") ); if (!context.projectGraph?.nodes[context.projectName ?? ""]) { throw new Error( "The Napi Build process failed because the project could not be found in the project graph. Please run this command from a workspace root directory." ); } const projectRoot = context.projectGraph?.nodes[context.projectName ?? ""].data.root; const packageJson = joinPaths(projectRoot ?? ".", "package.json"); if (!fileExists(packageJson)) { throw new Error(`Could not find package.json at ${packageJson}`); } const napi = new NapiCli(); const normalizedOptions = { ...options }; const metadata = cargoMetadata(); normalizedOptions.targetDir = options.targetDir || metadata?.target_directory || joinPaths(config.workspaceRoot, "dist", "target"); normalizedOptions.outputDir = options.outputPath; normalizedOptions.packageJsonPath = options.packageJsonPath || packageJson; if (options.cwd) { normalizedOptions.cwd = correctPaths(options.cwd); } else { normalizedOptions.cwd = correctPaths(projectRoot); const absoluteProjectRoot = joinPaths( config.workspaceRoot, projectRoot || "." ); if (normalizedOptions.outputDir) { normalizedOptions.outputDir = relative( absoluteProjectRoot, correctPaths( isAbsolute(normalizedOptions.outputDir) ? normalizedOptions.outputDir : joinPaths(config.workspaceRoot, normalizedOptions.outputDir) ) ); } if (normalizedOptions.packageJsonPath) { normalizedOptions.packageJsonPath = relative( absoluteProjectRoot, correctPaths( isAbsolute(normalizedOptions.packageJsonPath) ? normalizedOptions.packageJsonPath : joinPaths(config.workspaceRoot, normalizedOptions.packageJsonPath) ) ); } if (normalizedOptions.configPath) { normalizedOptions.configPath = relative( absoluteProjectRoot, correctPaths( isAbsolute(normalizedOptions.configPath) ? normalizedOptions.configPath : joinPaths(config.workspaceRoot, normalizedOptions.configPath) ) ); } if (normalizedOptions.manifestPath) { normalizedOptions.manifestPath = relative( absoluteProjectRoot, correctPaths( isAbsolute(normalizedOptions.manifestPath) ? normalizedOptions.manifestPath : joinPaths(config.workspaceRoot, normalizedOptions.manifestPath) ) ); } } if (process.env.VERCEL) { return { success: true }; } const { task } = await napi.build(normalizedOptions); return { success: true, terminalOutput: await task }; } var executor_default = withRunExecutor( "Napi - Build Bindings", napiExecutor, { skipReadingConfig: false, hooks: { applyDefaultOptions: (options) => { options.outputPath ??= "{sourceRoot}"; options.toolchain ??= "stable"; options.dtsCache ??= true; options.platform ??= true; options.constEnum ??= false; options.verbose ??= false; options.jsBinding ??= "binding.js"; options.dts ??= "binding.d.ts"; return options; } } } ); export { napiExecutor, executor_default };