Socket
Socket
Sign inDemoInstall

@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.0.3 to 0.1.0

16

dist/index.js

@@ -12,2 +12,3 @@ #!/usr/bin/env node

import { problemFlags } from "./problemUtils.js";
import { groupProblemsByKind } from "@arethetypeswrong/core/utils";
const packageJson = createRequire(import.meta.url)("../package.json");

@@ -73,8 +74,7 @@ const version = packageJson.version;

const result = { analysis };
if (analysis.containsTypes) {
result.problems = core.groupByKind(core.getProblems(analysis));
if (analysis.types) {
result.problems = groupProblemsByKind(analysis.problems);
}
console.log(JSON.stringify(result));
if (analysis.containsTypes &&
core.getProblems(analysis).some((problem) => { var _a; return !((_a = opts.ignoreRules) === null || _a === void 0 ? void 0 : _a.includes(problem.kind)); }))
if (analysis.types && analysis.problems.some((problem) => { var _a; return !((_a = opts.ignoreRules) === null || _a === void 0 ? void 0 : _a.includes(problem.kind)); }))
process.exit(1);

@@ -84,7 +84,7 @@ return;

console.log();
if (analysis.containsTypes) {
if (analysis.types) {
await render.typed(analysis, opts);
if (analysis.containsTypes &&
core.getProblems(analysis).some((problem) => { var _a; return !((_a = opts.ignoreRules) === null || _a === void 0 ? void 0 : _a.includes(problem.kind)); }))
process.exit(1);
if (analysis.types && analysis.problems.some((problem) => { var _a; return !((_a = opts.ignoreRules) === null || _a === void 0 ? void 0 : _a.includes(problem.kind)); })) {
process.exitCode = 1;
}
}

@@ -91,0 +91,0 @@ else {

@@ -12,48 +12,5 @@ import * as core from "@arethetypeswrong/core";

FalseExportDefault: "false-export-default",
UnexpectedESMSyntax: "unexpected-esm-syntax",
UnexpectedCJSSyntax: "unexpected-cjs-syntax",
UnexpectedModuleSyntax: "unexpected-module-syntax",
InternalResolutionError: "internal-resolution-error",
};
export const problemEmoji = {
Wildcard: "❓",
NoResolution: "💀",
UntypedResolution: "🚫",
FalseCJS: "🎭",
FalseESM: "👺",
CJSResolvesToESM: "⚠️",
FallbackCondition: "🐛",
CJSOnlyExportsDefault: "🤨",
FalseExportDefault: "❗️",
UnexpectedESMSyntax: "🚭",
UnexpectedCJSSyntax: "🚱",
};
export const withEmoji = {
Wildcard: `${problemEmoji.Wildcard} Unable to check`,
NoResolution: `${problemEmoji.NoResolution} Failed to resolve`,
UntypedResolution: `${problemEmoji.UntypedResolution} No types`,
FalseCJS: `${problemEmoji.FalseCJS} Masquerading as CJS`,
FalseESM: `${problemEmoji.FalseESM} Masquerading as ESM`,
CJSResolvesToESM: `${problemEmoji.CJSResolvesToESM} ESM (dynamic import only)`,
FallbackCondition: `${problemEmoji.FallbackCondition} Used fallback condition`,
CJSOnlyExportsDefault: `${problemEmoji.CJSOnlyExportsDefault} CJS default export`,
FalseExportDefault: `${problemEmoji.FalseExportDefault} Incorrect default export`,
UnexpectedESMSyntax: `${problemEmoji.UnexpectedESMSyntax} Unexpected ESM syntax`,
UnexpectedCJSSyntax: `${problemEmoji.UnexpectedCJSSyntax} Unexpected CJS syntax`,
};
export const noEmoji = {
Wildcard: `Unable to check`,
NoResolution: `Failed to resolve`,
UntypedResolution: `No types`,
FalseCJS: `Masquerading as CJS`,
FalseESM: `Masquerading as ESM`,
CJSResolvesToESM: `ESM (dynamic import only)`,
FallbackCondition: `Used fallback condition`,
CJSOnlyExportsDefault: `CJS default export`,
FalseExportDefault: `Incorrect default export`,
UnexpectedESMSyntax: `Unexpected ESM syntax`,
UnexpectedCJSSyntax: `Unexpected CJS syntax`,
};
export const problemShortDescriptions = {
emoji: withEmoji,
noEmoji: noEmoji,
};
export const resolutionKinds = {

@@ -60,0 +17,0 @@ node10: "node10",

import * as core from "@arethetypeswrong/core";
import { allResolutionKinds } from "@arethetypeswrong/core/utils";
import { allResolutionKinds, groupProblemsByKind } from "@arethetypeswrong/core/utils";
import chalk from "chalk";
import Table, {} from "cli-table3";
import chalk from "chalk";
import { moduleKinds, problemEmoji, resolutionKinds, problemShortDescriptions, problemFlags } from "../problemUtils.js";
import { marked } from "marked";
import { filterProblems, problemAffectsEntrypoint, problemKindInfo } from "@arethetypeswrong/core/problems";
import { moduleKinds, problemFlags, resolutionKinds } from "../problemUtils.js";
import { tableFlipped } from "./tableFlipped.js";
import TerminalRenderer from "marked-terminal";
export async function typed(analysis, opts) {
const problems = core
.getProblems(analysis)
.filter((problem) => !opts.ignoreRules || !opts.ignoreRules.includes(problem.kind));
const subpaths = Object.keys(analysis.entrypointResolutions);
const problems = analysis.problems.filter((problem) => !opts.ignoreRules || !opts.ignoreRules.includes(problem.kind));
const grouped = groupProblemsByKind(problems);
const subpaths = Object.keys(analysis.entrypoints);
marked.setOptions({
// @ts-expect-error the types are wrong (haha)
renderer: new TerminalRenderer(),
mangle: false,
headerIds: false,
});
if (opts.ignoreRules && opts.ignoreRules.length) {

@@ -18,18 +26,12 @@ console.log(chalk.gray(` (ignoring rules: ${opts.ignoreRules

if (opts.summary) {
const summaries = core.summarizeProblems(problems, analysis);
const defaultSummary = !opts.emoji ? " No problems found" : " No problems found 🌟";
const summaryTexts = summaries.map((summary) => {
return summary.messages
.map((message) => {
const messageText = message.messageText.split(". ").join(".\n ");
if (!opts.emoji)
return ` ${messageText}`;
return ` ${problemEmoji[summary.kind]} ${messageText}`;
})
.join("\n");
const defaultSummary = marked(!opts.emoji ? " No problems found" : " No problems found 🌟");
const summaryTexts = Object.keys(grouped).map((kind) => {
const emoji = opts.emoji ? `${problemKindInfo[kind].emoji} ` : "";
const description = marked(problemKindInfo[kind].description);
return `${emoji}${description}`;
});
console.log((summaryTexts.join("\n\n") || defaultSummary) + "\n");
console.log(summaryTexts.join("") || defaultSummary);
}
const entrypoints = subpaths.map((s) => {
const hasProblems = problems.some((p) => p.entrypoint === s);
const hasProblems = problems.some((p) => problemAffectsEntrypoint(p, s, analysis));
const color = hasProblems ? "redBright" : "greenBright";

@@ -51,7 +53,9 @@ if (s === ".")

var _a;
const problemsForCell = problems.filter((problem) => problem.entrypoint === subpath && problem.resolutionKind === kind);
const resolution = analysis.entrypointResolutions[subpath][kind].resolution;
const descriptions = problemShortDescriptions[!opts.emoji ? "noEmoji" : "emoji"];
if (problemsForCell.length) {
return problemsForCell.map((problem) => descriptions[problem.kind]).join("\n");
const problemsForCell = groupProblemsByKind(filterProblems(problems, analysis, { entrypoint: subpath, resolutionKind: kind }));
const resolution = analysis.entrypoints[subpath].resolutions[kind].resolution;
const kinds = Object.keys(problemsForCell);
if (kinds.length) {
return kinds
.map((kind) => (opts.emoji ? `${problemKindInfo[kind].emoji} ` : "") + problemKindInfo[kind].shortDescription)
.join("\n");
}

@@ -75,7 +79,9 @@ const jsonResult = !opts.emoji ? "OK (JSON)" : "🟢 (JSON)";

var _a;
const problemsForCell = problems.filter((problem) => problem.entrypoint === subpath && problem.resolutionKind === kind);
const resolution = analysis.entrypointResolutions[subpath][kind].resolution;
const descriptions = problemShortDescriptions[!opts.emoji ? "noEmoji" : "emoji"];
if (problemsForCell.length) {
return problemsForCell.map((problem) => descriptions[problem.kind]).join("\n");
const problemsForCell = groupProblemsByKind(filterProblems(problems, analysis, { entrypoint: subpath, resolutionKind: kind }));
const resolution = analysis.entrypoints[subpath].resolutions[kind].resolution;
const kinds = Object.keys(problemsForCell);
if (kinds.length) {
return kinds
.map((kind) => (opts.emoji ? `${problemKindInfo[kind].emoji} ` : "") + problemKindInfo[kind].shortDescription)
.join("\n");
}

@@ -82,0 +88,0 @@ const jsonResult = !opts.emoji ? "OK (JSON)" : "🟢 (JSON)";

{
"name": "@arethetypeswrong/cli",
"version": "0.0.3",
"version": "0.1.0",
"description": "A CLI tool for arethetypeswrong.github.io",
"author": "Andrew Branch & ej-shafran",
"contributors": [
{
"name": "Andrew Branch",
"url": "https://github.com/andrewbranch"
},
{
"name": "ej-shafran",
"url": "https://github.com/ej-shafran"
}
],
"license": "MIT",

@@ -25,3 +35,3 @@ "repository": {

"local:uninstall": "npm uninstall -g @arethetypeswrong/cli",
"build": "npm run local:uninstall && npm run tsc && npm run local:install",
"build": "npm run tsc",
"pretest": "tsc -b test",

@@ -32,2 +42,4 @@ "test": "node --test test/dist"

"devDependencies": {
"@types/marked": "^5.0.0",
"@types/marked-terminal": "^3.1.3",
"@types/node": "^20.2.5",

@@ -38,7 +50,9 @@ "@types/node-fetch": "^2.6.4",

"dependencies": {
"@arethetypeswrong/core": "0.0.8",
"@arethetypeswrong/core": "0.1.0",
"chalk": "^4.1.2",
"cli-table3": "^0.6.3",
"commander": "^10.0.1"
"commander": "^10.0.1",
"marked": "^5.1.0",
"marked-terminal": "^5.2.0"
}
}
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