@storm-software/workspace-tools
Version:
Tools for managing a Storm workspace, including various Nx generators and executors for common development tasks.
117 lines (103 loc) • 5.65 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunkD2PV33E5js = require('./chunk-D2PV33E5.js');
var _chunkWCTC7R27js = require('./chunk-WCTC7R27.js');
var _chunkCQDBLKPFjs = require('./chunk-CQDBLKPF.js');
// src/executors/napi/executor.ts
var _jiti = require('jiti');
var _fileutils = require('nx/src/utils/fileutils');
async function napiExecutor(options, context, config) {
const jiti = _jiti.createJiti.call(void 0, config.workspaceRoot, {
fsCache: config.skipCache ? false : _chunkCQDBLKPFjs.joinPaths.call(void 0,
config.workspaceRoot,
config.directories.cache || "node_modules/.cache/storm",
"jiti"
),
interopDefault: true
});
const { NapiCli } = await jiti.import(
jiti.esmResolve("@napi-rs/cli")
);
if (!_optionalChain([context, 'access', _ => _.projectGraph, 'optionalAccess', _2 => _2.nodes, 'access', _3 => _3[_nullishCoalesce(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 = _optionalChain([context, 'access', _4 => _4.projectGraph, 'optionalAccess', _5 => _5.nodes, 'access', _6 => _6[_nullishCoalesce(context.projectName, () => ( ""))], 'access', _7 => _7.data, 'access', _8 => _8.root]);
const packageJson = _chunkCQDBLKPFjs.joinPaths.call(void 0, _nullishCoalesce(projectRoot, () => ( ".")), "package.json");
if (!_fileutils.fileExists.call(void 0, packageJson)) {
throw new Error(`Could not find package.json at ${packageJson}`);
}
const napi = new NapiCli();
const normalizedOptions = { ...options };
const metadata = _chunkD2PV33E5js.cargoMetadata.call(void 0, );
normalizedOptions.targetDir = options.targetDir || _optionalChain([metadata, 'optionalAccess', _9 => _9.target_directory]) || _chunkCQDBLKPFjs.joinPaths.call(void 0, config.workspaceRoot, "dist", "target");
normalizedOptions.outputDir = options.outputPath;
normalizedOptions.packageJsonPath = options.packageJsonPath || packageJson;
if (options.cwd) {
normalizedOptions.cwd = _chunkCQDBLKPFjs.correctPaths.call(void 0, options.cwd);
} else {
normalizedOptions.cwd = _chunkCQDBLKPFjs.correctPaths.call(void 0, projectRoot);
const absoluteProjectRoot = _chunkCQDBLKPFjs.joinPaths.call(void 0,
config.workspaceRoot,
projectRoot || "."
);
if (normalizedOptions.outputDir) {
normalizedOptions.outputDir = _chunkCQDBLKPFjs.relative.call(void 0,
absoluteProjectRoot,
_chunkCQDBLKPFjs.correctPaths.call(void 0,
_chunkCQDBLKPFjs.isAbsolute.call(void 0, normalizedOptions.outputDir) ? normalizedOptions.outputDir : _chunkCQDBLKPFjs.joinPaths.call(void 0, config.workspaceRoot, normalizedOptions.outputDir)
)
);
}
if (normalizedOptions.packageJsonPath) {
normalizedOptions.packageJsonPath = _chunkCQDBLKPFjs.relative.call(void 0,
absoluteProjectRoot,
_chunkCQDBLKPFjs.correctPaths.call(void 0,
_chunkCQDBLKPFjs.isAbsolute.call(void 0, normalizedOptions.packageJsonPath) ? normalizedOptions.packageJsonPath : _chunkCQDBLKPFjs.joinPaths.call(void 0, config.workspaceRoot, normalizedOptions.packageJsonPath)
)
);
}
if (normalizedOptions.configPath) {
normalizedOptions.configPath = _chunkCQDBLKPFjs.relative.call(void 0,
absoluteProjectRoot,
_chunkCQDBLKPFjs.correctPaths.call(void 0,
_chunkCQDBLKPFjs.isAbsolute.call(void 0, normalizedOptions.configPath) ? normalizedOptions.configPath : _chunkCQDBLKPFjs.joinPaths.call(void 0, config.workspaceRoot, normalizedOptions.configPath)
)
);
}
if (normalizedOptions.manifestPath) {
normalizedOptions.manifestPath = _chunkCQDBLKPFjs.relative.call(void 0,
absoluteProjectRoot,
_chunkCQDBLKPFjs.correctPaths.call(void 0,
_chunkCQDBLKPFjs.isAbsolute.call(void 0, normalizedOptions.manifestPath) ? normalizedOptions.manifestPath : _chunkCQDBLKPFjs.joinPaths.call(void 0, 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 = _chunkWCTC7R27js.withRunExecutor.call(void 0,
"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;
}
}
}
);
exports.napiExecutor = napiExecutor; exports.executor_default = executor_default;