Registry / devops / opt-cli

opt-cli

JSON →
library1.6.0jsnpmunverified

opt-cli is a Node.js utility designed to conditionally execute CLI statements based on opt-in or opt-out rules. Its primary use case, as highlighted in its documentation, is for managing `ghooks` or similar pre-commit/pre-push scripts, allowing developers to enable or disable specific tasks without modifying `package.json` scripts directly. Rules are defined in `.opt-in` or `.opt-out` files in the project root, or via the `config.opt` field in `package.json`. The package has been stable at version 1.6.0 since October 2017, with no further releases or active development observed, indicating an abandoned status. It explicitly supports Node.js versions `>=4` and primarily functions as a CommonJS module, without apparent ESM support.

devops
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

This package is a CommonJS module and does not support native ESM import syntax.

const opt = require('opt-cli');

Methods are accessed as properties of the default `opt` export, not as named exports.

opt.testOptIn('rule-name');

Methods are accessed as properties of the default `opt` export, not as named exports.

opt.getExplicitOpts();

This example demonstrates how to use `opt-cli` programmatically to check opt-in and opt-out rules by simulating the creation of `.opt-in` and `.opt-out` files, and then using `testOptIn` and `testOptOut` methods. It also illustrates how to retrieve combined explicit configurations and suggests CLI usage.

const fs = require('fs'); const path = require('path'); const opt = require('opt-cli'); const optInFilePath = path.join(process.cwd(), '.opt-in'); const optOutFilePath = path.join(process.cwd(), '.opt-out'); async function runExample() { try { // Create a dummy .opt-in file for demonstration fs.writeFileSync(optInFilePath, 'pre-commit\nlint-check', 'utf8'); console.log(`Created ${optInFilePath} with rules: pre-commit, lint-check`); // Test opt-in for 'pre-commit' const shouldRunPreCommit = opt.testOptIn('pre-commit'); console.log(`Should 'pre-commit' task run (opt-in)? ${shouldRunPreCommit}`); // Expected: true // Test opt-in for 'test-task' (not in .opt-in) const shouldRunTestTask = opt.testOptIn('test-task'); console.log(`Should 'test-task' run (opt-in)? ${shouldRunTestTask}`); // Expected: false // Create a dummy .opt-out file for demonstration fs.writeFileSync(optOutFilePath, 'pre-push', 'utf8'); console.log(`Created ${optOutFilePath} with rule: pre-push`); // Test opt-out for 'pre-push' (meaning it is opted out, so it won't run) const shouldRunPrePush = opt.testOptOut('pre-push'); console.log(`Should 'pre-push' task run (opt-out)? ${shouldRunPrePush}`); // Expected: false // Test opt-out for 'build' (meaning it is not opted out, so it will run) const shouldRunBuild = opt.testOptOut('build'); console.log(`Should 'build' task run (opt-out)? ${shouldRunBuild}`); // Expected: true // Note: getExplicitOpts primarily reflects 'config.opt' in package.json, not file content directly console.log('\nDemonstrating CLI usage (run these in your terminal after installing opt-cli):'); console.log(`$ npx opt --in pre-commit --exec 'echo "Pre-commit task ran if opted in!"'`); console.log(`$ npx opt --out pre-push --exec 'echo "Pre-push task ran if NOT opted out!"'`); } catch (error) { console.error('An error occurred:', error); } finally { // Clean up dummy files if (fs.existsSync(optInFilePath)) { fs.unlinkSync(optInFilePath); console.log(`Removed ${optInFilePath}`); } if (fs.existsSync(optOutFilePath)) { fs.unlinkSync(optOutFilePath); console.log(`Removed ${optOutFilePath}`); } } } runExample();
opt --version
Debug
Known footguns
breakingThis package is a CommonJS module and is not compatible with native ES Modules (ESM) import syntax. Attempting to `import opt from 'opt-cli'` in an ESM context will result in a `ReferenceError`.
gotchaThe `opt-cli` project appears to be abandoned, with its last release (v1.6.0) in October 2017. This means it no longer receives updates for new features, bug fixes, or security patches, posing potential risks for long-term projects or compatibility with newer Node.js versions.
breakingWhile the package states `engines: {'node': '>=4'}`, newer Node.js versions (e.g., Node.js 14, 16, 18+) may introduce breaking changes or deprecations in core modules (like `child_process`) that this unmaintained package might not handle correctly, leading to unexpected behavior or runtime errors.
securityVersions of `opt-cli` prior to 1.5.0 contained a vulnerability in its CLI module. This was addressed in version 1.5.0. Ensure you are using `opt-cli` version 1.5.0 or higher to mitigate this known issue.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources