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.

npm install opt-cli
INSTALL
IMPORT
SIG · OPT-CLI
O
opt-cli
devopsjavascriptv1.6.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

opt
const opt = require('opt-cli');
import opt from 'opt-cli'; import { opt } from 'opt-cli';
This package is a CommonJS module and does not support native ESM import syntax.
testOptIn
opt.testOptIn('rule-name');
import { testOptIn } from 'opt-cli';
Methods are accessed as properties of the default `opt` export, not as named exports.
getExplicitOpts
opt.getExplicitOpts();
import { getExplicitOpts } from 'opt-cli';
Methods are accessed as properties of the default `opt` export, not as named exports.

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 issues
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`.
fix
Use CommonJS `const opt = require('opt-cli');` in CJS files, or consider a build step (e.g., Babel, Webpack) for ESM projects that need to consume CJS packages.
affects: >=1.0.0
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.
fix
Evaluate the necessity of this package. For new projects, consider modern alternatives or implement similar logic manually. For existing projects, be aware of the lack of maintenance and potential security implications.
affects: >=1.6.0
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.
fix
Thoroughly test `opt-cli` against your target Node.js version. If issues arise, a manual fork and fix, or migration to an alternative, may be necessary.
affects: >=1.0.0
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.
fix
Upgrade to `opt-cli` version 1.5.0 or later immediately. Given the project's abandoned status, further security issues will not be patched.
affects: <1.5.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` in an ES Module context, or `import` syntax in a CommonJS context.
fix
Ensure your file is treated as CommonJS (e.g., `.js` file without `"type": "module"` in `package.json`, or explicitly `.cjs` extension) when using `require`. If your project is ESM, `opt-cli` cannot be directly imported; consider a wrapper or alternative.
TypeError: Cannot read properties of undefined (reading 'testOptIn')
This error typically means the `opt` variable is `undefined` or not correctly resolved, indicating a failure to import the module or that `require('opt-cli')` did not return the expected object.
fix
Verify `opt-cli` is correctly installed (`npm list opt-cli`). Ensure the `require('opt-cli')` statement is at the top level of your CommonJS module. Check that the file where `require` is used is indeed treated as CommonJS.
Error: ENOENT: no such file or directory, open '.opt-in'
The `opt-cli` library expects `.opt-in` or `.opt-out` files to exist in the current working directory, or a `config.opt` entry in `package.json`, and one of these was not found or accessible.
fix
Ensure the `.opt-in` or `.opt-out` files are present in the root of your project (or `process.cwd()`). Verify file permissions allow Node.js to read them. Alternatively, specify rules within the `config.opt` field of your `package.json`.
Upgrade
Version history
1.6.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources