Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arethetypeswrong/cli

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arethetypeswrong/cli - npm Package Compare versions

Comparing version 0.3.0 to 0.4.1

49

dist/index.js
#!/usr/bin/env node
import * as core from "@arethetypeswrong/core";
import { groupProblemsByKind, parsePackageSpec } from "@arethetypeswrong/core/utils";
import { versions } from "@arethetypeswrong/core/versions";
import chalk from "chalk";
import { execSync } from "child_process";
import { Option, program } from "commander";
import chalk from "chalk";
import { readFile } from "fs/promises";
import { readFile, stat, unlink } from "fs/promises";
import { createRequire } from "module";
import { FetchError } from "node-fetch";
import { createRequire } from "module";
import path from "path";
import readline from "readline/promises";
import { problemFlags } from "./problemUtils.js";
import { readConfig } from "./readConfig.js";
import * as render from "./render/index.js";
import { readConfig } from "./readConfig.js";
import { problemFlags } from "./problemUtils.js";
import { groupProblemsByKind } from "@arethetypeswrong/core/utils";
const packageJson = createRequire(import.meta.url)("../package.json");

@@ -23,3 +26,4 @@ const version = packageJson.version;

particularly ESM-related module resolution issues.`)
.argument("<file-name>", "the file to check; by default a path to a .tar.gz file, unless --from-npm is set")
.argument("[file-directory-or-package-spec]", "the packed .tgz, or directory containing package.json with --pack, or package spec with --from-npm")
.option("-P, --pack", "run `npm pack` in the specified directory and delete the resulting .tgz file afterwards")
.option("-p, --from-npm", "read from the npm registry instead of a local file")

@@ -33,3 +37,3 @@ .addOption(new Option("-f, --format <format>", "specify the print format").choices(formats).default("table"))

.option("--config-path <path>", "path to config file (default: ./.attw.json)")
.action(async (fileName) => {
.action(async (fileOrDirectory = ".") => {
var _a;

@@ -46,5 +50,9 @@ const opts = program.opts();

let analysis;
let deleteTgz;
if (opts.fromNpm) {
if (opts.pack) {
program.error("--pack and --from-npm cannot be used together");
}
try {
const result = core.parsePackageSpec(fileName);
const result = parsePackageSpec(fileOrDirectory);
if (result.status === "error") {

@@ -66,2 +74,22 @@ program.error(result.error);

try {
let fileName = fileOrDirectory;
if (await stat(fileOrDirectory)
.then((stat) => !stat.isFile())
.catch(() => false)) {
if (!(await stat(path.join(fileOrDirectory, "package.json")).catch(() => false))) {
program.error(`Specified directory must contain a package.json. No package.json found in ${path.resolve(fileOrDirectory)}.`);
}
if (!opts.pack) {
if (!process.stdout.isTTY) {
program.error("Specifying a directory requires the --pack option to confirm that running `npm pack` is ok.");
}
const rl = readline.createInterface(process.stdin, process.stdout);
const answer = await rl.question(`Run \`npm pack\`? (Pass -P/--pack to skip) (Y/n) `);
rl.close();
if (answer.trim() && !answer.trim().toLowerCase().startsWith("y")) {
process.exit(1);
}
}
fileName = deleteTgz = path.resolve(fileOrDirectory, execSync("npm pack", { cwd: fileOrDirectory, encoding: "utf8", stdio: "pipe" }).trim());
}
const file = await readFile(fileName);

@@ -95,2 +123,5 @@ const data = new Uint8Array(file);

}
if (deleteTgz) {
await unlink(deleteTgz);
}
});

@@ -97,0 +128,0 @@ program.parse(process.argv);

4

package.json
{
"name": "@arethetypeswrong/cli",
"version": "0.3.0",
"version": "0.4.1",
"description": "A CLI tool for arethetypeswrong.github.io",

@@ -48,3 +48,3 @@ "author": "Andrew Branch & ej-shafran",

"dependencies": {
"@arethetypeswrong/core": "0.3.0",
"@arethetypeswrong/core": "0.4.1",
"chalk": "^4.1.2",

@@ -51,0 +51,0 @@ "cli-table3": "^0.6.3",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc