🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@commitlint/cli

Package Overview
Dependencies
Maintainers
4
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commitlint/cli - npm Package Compare versions

Comparing version

to
19.8.1

2

cli.js
#!/usr/bin/env node
import './lib/cli.js';
import "./lib/cli.js";

@@ -1,119 +0,119 @@

import { createRequire } from 'node:module';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import util from 'node:util';
import lint from '@commitlint/lint';
import load, { resolveFromSilent, resolveGlobalSilent } from '@commitlint/load';
import read from '@commitlint/read';
import { x } from 'tinyexec';
import yargs from 'yargs';
import { CliError, ExitCode } from './cli-error.js';
import { createRequire } from "node:module";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import util from "node:util";
import lint from "@commitlint/lint";
import load, { resolveFromSilent, resolveGlobalSilent } from "@commitlint/load";
import read from "@commitlint/read";
import { x } from "tinyexec";
import yargs from "yargs";
import { CliError, ExitCode } from "./cli-error.js";
const require = createRequire(import.meta.url);
const __dirname = path.resolve(fileURLToPath(import.meta.url), '..');
const __dirname = path.resolve(fileURLToPath(import.meta.url), "..");
const dynamicImport = async (id) => {
const imported = await import(path.isAbsolute(id) ? pathToFileURL(id).toString() : id);
return ('default' in imported && imported.default) || imported;
return ("default" in imported && imported.default) || imported;
};
const pkg = require('../package.json');
const gitDefaultCommentChar = '#';
const pkg = require("../package.json");
const gitDefaultCommentChar = "#";
const cli = yargs(process.argv.slice(2))
.options({
color: {
alias: 'c',
alias: "c",
default: true,
description: 'toggle colored output',
type: 'boolean',
description: "toggle colored output",
type: "boolean",
},
config: {
alias: 'g',
description: 'path to the config file; result code 9 if config is missing',
type: 'string',
alias: "g",
description: "path to the config file; result code 9 if config is missing",
type: "string",
},
'print-config': {
choices: ['', 'text', 'json'],
description: 'print resolved config',
type: 'string',
"print-config": {
choices: ["", "text", "json"],
description: "print resolved config",
type: "string",
},
cwd: {
alias: 'd',
alias: "d",
default: process.cwd(),
defaultDescription: '(Working Directory)',
description: 'directory to execute in',
type: 'string',
defaultDescription: "(Working Directory)",
description: "directory to execute in",
type: "string",
},
edit: {
alias: 'e',
description: 'read last commit message from the specified file or fallbacks to ./.git/COMMIT_EDITMSG',
type: 'string',
alias: "e",
description: "read last commit message from the specified file or fallbacks to ./.git/COMMIT_EDITMSG",
type: "string",
},
env: {
alias: 'E',
description: 'check message in the file at path given by environment variable value',
type: 'string',
alias: "E",
description: "check message in the file at path given by environment variable value",
type: "string",
},
extends: {
alias: 'x',
description: 'array of shareable configurations to extend',
type: 'array',
alias: "x",
description: "array of shareable configurations to extend",
type: "array",
},
'help-url': {
alias: 'H',
type: 'string',
description: 'help url in error message',
"help-url": {
alias: "H",
type: "string",
description: "help url in error message",
},
from: {
alias: 'f',
description: 'lower end of the commit range to lint; applies if edit=false',
type: 'string',
alias: "f",
description: "lower end of the commit range to lint; applies if edit=false",
type: "string",
},
'from-last-tag': {
description: 'uses the last tag as the lower end of the commit range to lint; applies if edit=false and from is not set',
type: 'boolean',
"from-last-tag": {
description: "uses the last tag as the lower end of the commit range to lint; applies if edit=false and from is not set",
type: "boolean",
},
'git-log-args': {
"git-log-args": {
description: "additional git log arguments as space separated string, example '--first-parent --cherry-pick'",
type: 'string',
type: "string",
},
last: {
alias: 'l',
description: 'just analyze the last commit; applies if edit=false',
type: 'boolean',
alias: "l",
description: "just analyze the last commit; applies if edit=false",
type: "boolean",
},
format: {
alias: 'o',
description: 'output format of the results',
type: 'string',
alias: "o",
description: "output format of the results",
type: "string",
},
'parser-preset': {
alias: 'p',
description: 'configuration preset to use for conventional-commits-parser',
type: 'string',
"parser-preset": {
alias: "p",
description: "configuration preset to use for conventional-commits-parser",
type: "string",
},
quiet: {
alias: 'q',
alias: "q",
default: false,
description: 'toggle console output',
type: 'boolean',
description: "toggle console output",
type: "boolean",
},
to: {
alias: 't',
description: 'upper end of the commit range to lint; applies if edit=false',
type: 'string',
alias: "t",
description: "upper end of the commit range to lint; applies if edit=false",
type: "string",
},
verbose: {
alias: 'V',
type: 'boolean',
description: 'enable verbose output for reports without problems',
alias: "V",
type: "boolean",
description: "enable verbose output for reports without problems",
},
strict: {
alias: 's',
type: 'boolean',
description: 'enable strict mode; result code 2 for warnings, 3 for errors',
alias: "s",
type: "boolean",
description: "enable strict mode; result code 2 for warnings, 3 for errors",
},
})
.version('version', 'display version information', `${pkg.name}@${pkg.version}`)
.alias('v', 'version')
.help('help')
.alias('h', 'help')
.config('options', 'path to a JSON file or Common.js module containing CLI options', require)
.version("version", "display version information", `${pkg.name}@${pkg.version}`)
.alias("v", "version")
.help("help")
.alias("h", "help")
.config("options", "path to a JSON file or Common.js module containing CLI options", require)
.usage(`${pkg.name}@${pkg.version} - ${pkg.description}\n`)

@@ -136,7 +136,7 @@ .usage(`[input] reads from stdin if --edit, --env, --from and --to are omitted`)

async function stdin() {
let result = '';
let result = "";
if (process.stdin.isTTY) {
return result;
}
process.stdin.setEncoding('utf8');
process.stdin.setEncoding("utf8");
for await (const chunk of process.stdin) {

@@ -148,7 +148,7 @@ result += chunk;

async function resolveArgs(args) {
return typeof args.then === 'function' ? await args : args;
return typeof args.then === "function" ? await args : args;
}
async function main(args) {
const options = await resolveArgs(args);
if (typeof options.edit === 'undefined') {
if (typeof options.edit === "undefined") {
options.edit = false;

@@ -158,3 +158,3 @@ }

const flags = normalizeFlags(options);
if (typeof options['print-config'] === 'string') {
if (typeof options["print-config"] === "string") {
const loaded = await load(getSeed(flags), {

@@ -164,7 +164,7 @@ cwd: flags.cwd,

});
switch (options['print-config']) {
case 'json':
switch (options["print-config"]) {
case "json":
console.log(JSON.stringify(loaded));
return;
case 'text':
case "text":
default:

@@ -176,6 +176,6 @@ console.log(util.inspect(loaded, false, null, options.color));

const fromStdin = checkFromStdin(raw, flags);
if (Object.hasOwn(flags, 'last') &&
(Object.hasOwn(flags, 'from') || Object.hasOwn(flags, 'to') || flags.edit)) {
const err = new CliError('Please use the --last flag alone. The --last flag should not be used with --to or --from or --edit.', pkg.name);
cli.showHelp('log');
if (Object.hasOwn(flags, "last") &&
(Object.hasOwn(flags, "from") || Object.hasOwn(flags, "to") || flags.edit)) {
const err = new CliError("Please use the --last flag alone. The --last flag should not be used with --to or --from or --edit.", pkg.name);
cli.showHelp("log");
console.log(err.message);

@@ -189,15 +189,15 @@ throw err;

from: flags.from,
fromLastTag: flags['from-last-tag'],
fromLastTag: flags["from-last-tag"],
last: flags.last,
edit: flags.edit,
cwd: flags.cwd,
gitLogArgs: flags['git-log-args'],
gitLogArgs: flags["git-log-args"],
}));
const messages = (Array.isArray(input) ? input : [input])
.filter((message) => typeof message === 'string')
.filter((message) => message.trim() !== '')
.filter((message) => typeof message === "string")
.filter((message) => message.trim() !== "")
.filter(Boolean);
if (messages.length === 0 && !checkFromRepository(flags)) {
const err = new CliError('[input] is required: supply via stdin, or --env or --edit or --last or --from and --to', pkg.name);
cli.showHelp('log');
const err = new CliError("[input] is required: supply via stdin, or --env or --edit or --last or --from and --to", pkg.name);
cli.showHelp("log");
console.log(err.message);

@@ -233,6 +233,6 @@ throw err;

if (flags.edit) {
const result = x('git', ['config', 'core.commentChar']);
const result = x("git", ["config", "core.commentChar"]);
const output = await result;
if (result.exitCode && result.exitCode > 1) {
console.warn('Could not determine core.commentChar git configuration', output.stderr);
console.warn("Could not determine core.commentChar git configuration", output.stderr);
opts.parserOpts.commentChar = gitDefaultCommentChar;

@@ -248,3 +248,3 @@ }

if (Object.keys(loaded.rules).length === 0) {
let input = '';
let input = "";
if (results.length !== 0) {

@@ -259,8 +259,8 @@ input = results[0].input;

valid: false,
name: 'empty-rules',
name: "empty-rules",
message: [
'Please add rules to your `commitlint.config.js`',
' - Getting started guide: https://commitlint.js.org/guides/getting-started',
' - Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/src/index.ts',
].join('\n'),
"Please add rules to your `commitlint.config.js`",
" - Getting started guide: https://commitlint.js.org/guides/getting-started",
" - Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/src/index.ts",
].join("\n"),
},

@@ -285,3 +285,3 @@ ],

});
const helpUrl = flags['help-url']?.trim() || loaded.helpUrl;
const helpUrl = flags["help-url"]?.trim() || loaded.helpUrl;
const output = format(report, {

@@ -292,3 +292,3 @@ color: flags.color,

});
if (!flags.quiet && output !== '') {
if (!flags.quiet && output !== "") {
console.log(output);

@@ -321,6 +321,6 @@ }

function checkFromHistory(flags) {
return (typeof flags.from === 'string' ||
typeof flags['from-last-tag'] === 'boolean' ||
typeof flags.to === 'string' ||
typeof flags.last === 'boolean');
return (typeof flags.from === "string" ||
typeof flags["from-last-tag"] === "boolean" ||
typeof flags.to === "string" ||
typeof flags.last === "boolean");
}

@@ -344,6 +344,6 @@ function normalizeFlags(flags) {

// to .git/COMMIT_EDITMSG
if (edit === '') {
if (edit === "") {
return true;
}
if (typeof edit === 'boolean') {
if (typeof edit === "boolean") {
return edit;

@@ -356,11 +356,11 @@ }

// This has been superceded by the `-E GIT_PARAMS` / `-E HUSKY_GIT_PARAMS`
const isGitParams = edit === '$GIT_PARAMS' || edit === '%GIT_PARAMS%';
const isHuskyParams = edit === '$HUSKY_GIT_PARAMS' || edit === '%HUSKY_GIT_PARAMS%';
const isGitParams = edit === "$GIT_PARAMS" || edit === "%GIT_PARAMS%";
const isHuskyParams = edit === "$HUSKY_GIT_PARAMS" || edit === "%HUSKY_GIT_PARAMS%";
if (isGitParams || isHuskyParams) {
console.warn(`Using environment variable syntax (${edit}) in -e |\
--edit is deprecated. Use '{-E|--env} HUSKY_GIT_PARAMS instead'`);
if (isGitParams && 'GIT_PARAMS' in process.env) {
if (isGitParams && "GIT_PARAMS" in process.env) {
return process.env.GIT_PARAMS;
}
if ('HUSKY_GIT_PARAMS' in process.env) {
if ("HUSKY_GIT_PARAMS" in process.env) {
return process.env.HUSKY_GIT_PARAMS;

@@ -373,12 +373,12 @@ }

function getSeed(flags) {
const n = (flags.extends || []).filter((i) => typeof i === 'string');
const n = (flags.extends || []).filter((i) => typeof i === "string");
return n.length > 0
? { extends: n, parserPreset: flags['parser-preset'] }
: { parserPreset: flags['parser-preset'] };
? { extends: n, parserPreset: flags["parser-preset"] }
: { parserPreset: flags["parser-preset"] };
}
function selectParserOpts(parserPreset) {
if (typeof parserPreset !== 'object') {
if (typeof parserPreset !== "object") {
return undefined;
}
if (typeof parserPreset.parserOpts !== 'object') {
if (typeof parserPreset.parserOpts !== "object") {
return undefined;

@@ -389,3 +389,3 @@ }

function loadFormatter(config, flags) {
const moduleName = flags.format || config.formatter || '@commitlint/format';
const moduleName = flags.format || config.formatter || "@commitlint/format";
const modulePath = resolveFromSilent(moduleName, __dirname) ||

@@ -400,6 +400,6 @@ resolveFromSilent(moduleName, flags.cwd) ||

// Catch unhandled rejections globally
process.on('unhandledRejection', (reason, promise) => {
console.log('Unhandled Rejection at: Promise ', promise, ' reason: ', reason);
process.on("unhandledRejection", (reason, promise) => {
console.log("Unhandled Rejection at: Promise ", promise, " reason: ", reason);
throw reason;
});
//# sourceMappingURL=cli.js.map

@@ -9,9 +9,9 @@ export interface CliFlags {

help?: boolean;
'help-url'?: string;
"help-url"?: string;
from?: string;
'from-last-tag'?: boolean;
'git-log-args'?: string;
"from-last-tag"?: boolean;
"git-log-args"?: string;
last?: boolean;
format?: string;
'parser-preset'?: string;
"parser-preset"?: string;
quiet: boolean;

@@ -22,3 +22,3 @@ to?: string;

/** @type {'' | 'text' | 'json'} */
'print-config'?: string;
"print-config"?: string;
strict?: boolean;

@@ -25,0 +25,0 @@ _: (string | number)[];

{
"name": "@commitlint/cli",
"type": "module",
"version": "19.8.0",
"version": "19.8.1",
"description": "Lint your commit messages",

@@ -42,4 +42,4 @@ "files": [

"devDependencies": {
"@commitlint/test": "^19.8.0",
"@commitlint/utils": "^19.8.0",
"@commitlint/test": "^19.8.1",
"@commitlint/utils": "^19.8.1",
"@types/lodash.merge": "^4.6.8",

@@ -52,11 +52,11 @@ "@types/node": "^18.19.17",

"dependencies": {
"@commitlint/format": "^19.8.0",
"@commitlint/lint": "^19.8.0",
"@commitlint/load": "^19.8.0",
"@commitlint/read": "^19.8.0",
"@commitlint/types": "^19.8.0",
"tinyexec": "^0.3.0",
"@commitlint/format": "^19.8.1",
"@commitlint/lint": "^19.8.1",
"@commitlint/load": "^19.8.1",
"@commitlint/read": "^19.8.1",
"@commitlint/types": "^19.8.1",
"tinyexec": "^1.0.0",
"yargs": "^17.0.0"
},
"gitHead": "e82f05a737626bb69979d14564f5ff601997f679"
"gitHead": "3c302008cabeb0b08cd246b2417a51a9d745a918"
}

Sorry, the diff of this file is not supported yet