@systemfsoftware/arethetypeswrong-cli 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,86 @@
1
+ import { Context, Effect, Layer, Schema } from "effect";
2
+ import * as Command from "effect/unstable/cli/Command";
3
+ import * as Option from "effect/Option";
4
+ import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
5
+ import "effect/FileSystem";
6
+ import "effect/Path";
7
+ import "effect/Terminal";
8
+ //#region src/Filesystem.schema.d.ts
9
+ declare const FileNotFoundError_base: Schema.Class<FileNotFoundError, Schema.TaggedStruct<"FileNotFoundError", {
10
+ readonly filePath: Schema.String;
11
+ }>, import("effect/Cause").YieldableError>;
12
+ declare class FileNotFoundError extends FileNotFoundError_base {}
13
+ //#endregion
14
+ //#region src/FilesystemAdapter.d.ts
15
+ interface FilesystemService {
16
+ readonly fileExists: (filePath: string) => Effect.Effect<boolean, never>;
17
+ readonly isDirectory: (filePath: string) => Effect.Effect<boolean, never>;
18
+ readonly readUtf8: (filePath: string) => Effect.Effect<string, FileNotFoundError>;
19
+ readonly readBytes: (filePath: string) => Effect.Effect<Uint8Array, FileNotFoundError>;
20
+ readonly deleteFile: (filePath: string) => Effect.Effect<void, never>;
21
+ readonly resolve: (...segments: readonly string[]) => string;
22
+ readonly join: (...segments: readonly string[]) => string;
23
+ }
24
+ declare const CliFilesystem_base: Context.ServiceClass<CliFilesystem, "@systemfsoftware/arethetypeswrong-cli/filesystem.adapter/Filesystem", FilesystemService>;
25
+ declare class CliFilesystem extends CliFilesystem_base {}
26
+ //#endregion
27
+ //#region src/PackRunner.schema.d.ts
28
+ declare const PackRunnerFailed_base: Schema.Class<PackRunnerFailed, Schema.TaggedStruct<"PackRunnerFailed", {
29
+ readonly message: Schema.String;
30
+ readonly cause: Schema.optional<Schema.Unknown>;
31
+ }>, import("effect/Cause").YieldableError>;
32
+ /** A failed `npm pack`, carrying the spawn failure it came from. */
33
+ declare class PackRunnerFailed extends PackRunnerFailed_base {}
34
+ //#endregion
35
+ //#region src/PackRunnerAdapter.d.ts
36
+ interface PackResult {
37
+ readonly tarballPath: string;
38
+ }
39
+ interface PackRunnerService {
40
+ readonly pack: (cwd: string) => Effect.Effect<PackResult, PackRunnerFailed, ChildProcessSpawner>;
41
+ }
42
+ declare const PackRunner_base: Context.ServiceClass<PackRunner, "@systemfsoftware/arethetypeswrong-cli/pack-runner.adapter/PackRunner", PackRunnerService>;
43
+ declare class PackRunner extends PackRunner_base {}
44
+ //#endregion
45
+ //#region src/StdinAdapter.d.ts
46
+ interface StdinService {
47
+ readonly confirm: (question: string) => Effect.Effect<boolean, never>;
48
+ }
49
+ declare const Stdin_base: Context.ServiceClass<Stdin, "@systemfsoftware/arethetypeswrong-cli/stdin.adapter/Stdin", StdinService>;
50
+ declare class Stdin extends Stdin_base {}
51
+ //#endregion
52
+ //#region src/TerminalAdapter.d.ts
53
+ interface TerminalWriteSink {
54
+ readonly write: (text: string) => Effect.Effect<void, never>;
55
+ }
56
+ interface TerminalService {
57
+ readonly stdout: TerminalWriteSink;
58
+ readonly stderr: TerminalWriteSink;
59
+ readonly isTty: boolean;
60
+ readonly env: NodeJS.ProcessEnv;
61
+ readonly exit: (code: number) => Effect.Effect<never, never>;
62
+ }
63
+ declare const Terminal_base: Context.ServiceClass<Terminal, "@systemfsoftware/arethetypeswrong-cli/terminal.adapter/Terminal", TerminalService>;
64
+ declare class Terminal extends Terminal_base {}
65
+ //#endregion
66
+ //#region src/AttwHandler.d.ts
67
+ declare const attwCommand: Command.Command<"attw", {
68
+ readonly fileOrDirectory: Option.Option<string>;
69
+ readonly pack: boolean;
70
+ readonly fromNpm: boolean;
71
+ readonly definitelyTyped: Option.Option<string>;
72
+ readonly format: "ascii" | "auto" | "json" | "table" | "table-flipped";
73
+ readonly quiet: boolean;
74
+ readonly entrypoints: Option.Option<readonly string[]>;
75
+ readonly includeEntrypoints: Option.Option<readonly string[]>;
76
+ readonly excludeEntrypoints: Option.Option<readonly string[]>;
77
+ readonly entrypointsLegacy: boolean;
78
+ readonly ignoreRules: Option.Option<readonly string[]>;
79
+ readonly profile: "esm-only" | "node16" | "strict";
80
+ readonly summary: boolean;
81
+ readonly emoji: boolean;
82
+ readonly color: boolean;
83
+ readonly registry: string;
84
+ }, {}, never, import("effect/unstable/process/ChildProcessSpawner").ChildProcessSpawner | CliFilesystem | PackRunner | Stdin | Terminal>;
85
+ //#endregion
86
+ export { attwCommand };
@@ -0,0 +1,2 @@
1
+ import { t as attwCommand } from "./AttwHandler-CidnXJbU.mjs";
2
+ export { attwCommand };
package/dist/main.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/dist/main.mjs ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+ import { a as FilesystemLive, i as PackRunnerLive, n as TerminalLive, r as StdinLive, t as attwCommand } from "./AttwHandler-CidnXJbU.mjs";
3
+ import { layer } from "@effect/platform-node-shared/NodeChildProcessSpawner";
4
+ import { layer as layer$1 } from "@effect/platform-node-shared/NodeFileSystem";
5
+ import { layer as layer$2 } from "@effect/platform-node-shared/NodePath";
6
+ import { layer as layer$3 } from "@effect/platform-node-shared/NodeStdio";
7
+ import { layer as layer$4 } from "@effect/platform-node-shared/NodeTerminal";
8
+ import { runMain } from "@effect/platform-node/NodeRuntime";
9
+ import { ConfigProvider, Effect, Layer } from "effect";
10
+ import { layer as layer$5 } from "effect/unstable/cli/CliConfig";
11
+ import * as Command from "effect/unstable/cli/Command";
12
+ import * as fs from "node:fs/promises";
13
+ import * as path from "node:path";
14
+ //#region src/AttwConfigExecutor.ts
15
+ /**
16
+ * Read `.attw.json` if the working directory has one. A missing or malformed
17
+ * file is not an error: the CLI's flags are the source of truth and the file
18
+ * only supplies defaults, so an unreadable candidate is skipped.
19
+ */
20
+ const readAttwConfigJson = async () => {
21
+ const cwd = process.cwd();
22
+ for (const candidate of [".attw.json", path.join(cwd, ".attw.json")]) try {
23
+ const buf = await fs.readFile(candidate, "utf8");
24
+ return JSON.parse(buf);
25
+ } catch {
26
+ continue;
27
+ }
28
+ return null;
29
+ };
30
+ const configProviderEffect = Effect.promise(async () => {
31
+ const json = await readAttwConfigJson();
32
+ if (json === null) return ConfigProvider.fromUnknown({});
33
+ return ConfigProvider.fromUnknown(json);
34
+ });
35
+ /**
36
+ * The file's keys are read exactly as written. `constantCase` used to wrap this
37
+ * provider, which rewrites the *lookup path* into `SCREAMING_SNAKE_CASE` to
38
+ * bridge camelCase names to environment variables — so every camelCase key in a
39
+ * `.attw.json` became unreachable, and the file was parsed and then ignored.
40
+ *
41
+ * `layerAdd` rather than `layer`, because `layer` replaces the provider
42
+ * outright: the file would have silenced environment configuration instead of
43
+ * supplying defaults beneath it.
44
+ */
45
+ const AttwConfigFileLayer = ConfigProvider.layerAdd(configProviderEffect);
46
+ //#endregion
47
+ //#region src/main.ts
48
+ const cliConfigLayer = Layer.provideMerge(layer$5(), AttwConfigFileLayer);
49
+ const main = Command.runWith(attwCommand, { version: "1.1.1" });
50
+ const cliLayer = Layer.mergeAll(TerminalLive, FilesystemLive, StdinLive);
51
+ const nodeBase = Layer.mergeAll(layer$1, layer$2, layer$4, layer$3);
52
+ const nodeSpawnerLayer = layer.pipe(Layer.provide(nodeBase));
53
+ const nodeRuntime = Layer.mergeAll(nodeBase, nodeSpawnerLayer, PackRunnerLive.pipe(Layer.provide(nodeSpawnerLayer)));
54
+ const provided = main(process.argv.slice(2)).pipe(Effect.withLogSpan("attw")).pipe(Effect.provide(Layer.provideMerge(Layer.mergeAll(cliLayer, cliConfigLayer), nodeRuntime)));
55
+ runMain(provided);
56
+ //#endregion
57
+ export {};
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@systemfsoftware/arethetypeswrong-cli",
3
- "version": "1.1.0",
4
- "description": "A CLI tool for arethetypeswrong.github.io — forked under systemfsoftware",
5
- "author": "Andrew Branch & ej-shafran (forked by systemfsoftware)",
6
- "license": "MIT",
3
+ "version": "2.0.0",
4
+ "description": "A CLI tool for arethetypeswrong.github.io — owned and maintained by systemfsoftware",
5
+ "author": "Ryan Lee <drdgvhbh@gmail.com>",
6
+ "license": "Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "https://github.com/systemfsoftware/systemfsoftware.git",
@@ -14,48 +14,48 @@
14
14
  "LICENSE"
15
15
  ],
16
16
  "bin": {
17
- "attw": "./dist/index.mjs"
18
- },
19
- "exports": {
20
- "./package.json": "./package.json",
21
- "./internal/getExitCode": "./dist/getExitCode.mjs",
22
- "./internal/render": "./dist/render/index.mjs"
17
+ "attw": "./dist/main.mjs"
23
18
  },
24
19
  "publishConfig": {
25
- "access": "public"
20
+ "access": "public",
21
+ "provenance": true
26
22
  },
27
23
  "type": "module",
28
24
  "dependencies": {
29
- "chalk": "^4.1.2",
30
- "cli-table3": "^0.6.3",
31
- "commander": "^10.0.1",
32
- "marked": "^9.1.2",
33
- "marked-terminal": "^7.1.0",
34
- "semver": "^7.5.4",
35
- "@systemfsoftware/arethetypeswrong-core": "1.0.7"
25
+ "@effect/platform-node": "^4.0.0-rc.108",
26
+ "@effect/platform-node-shared": "^4.0.0-rc.108",
27
+ "effect": "4.0.0-rc.108",
28
+ "@systemfsoftware/arethetypeswrong-core": "2.0.0"
36
29
  },
37
30
  "devDependencies": {
38
- "@types/marked": "^5.0.0",
39
- "@types/marked-terminal": "^3.1.3",
31
+ "@effect/vitest": "4.0.0-rc.108",
40
32
  "@types/node": "^24",
41
- "@types/semver": "^7.5.3",
33
+ "fast-check": "^4",
34
+ "oxlint": "^1.77.0",
42
35
  "rimraf": "^6.1.3",
43
- "ts-expose-internals": "^5.6.0",
44
- "tsdown": "^0.22.9",
36
+ "testcontainers": "^12.1.0",
37
+ "tsdown": "^0.22.14",
45
38
  "vite-tsconfig-paths": "^6.1.1",
46
- "vitest": "^4",
47
- "@systemfsoftware/vitest-config": "^0.1.0",
48
- "@systemfsoftware/tsconfig": "^1.2.6"
39
+ "vitest": "^4.1.10",
40
+ "@systemfsoftware/effect-schema-law": "^0.7.0",
41
+ "@systemfsoftware/effect-schema-vite": "^1.5.2",
42
+ "@systemfsoftware/oxlint-config": "^0.1.0",
43
+ "@systemfsoftware/oxlint-plugin-effect-dmmf": "^2.0.0",
44
+ "@systemfsoftware/effect-gherkin-spec": "^1.0.0",
45
+ "@systemfsoftware/tsconfig": "^1.3.2",
46
+ "@systemfsoftware/vitest-config": "^0.1.0"
49
47
  },
50
48
  "engines": {
51
- "node": ">=22"
49
+ "node": ">=24"
52
50
  },
53
51
  "scripts": {
54
52
  "build": "tsdown",
55
53
  "clean": "rimraf dist",
56
54
  "typecheck": "tsc --noEmit --incremental",
57
- "format": "dprint fmt",
55
+ "attw": "node ./dist/main.mjs --pack .",
56
+ "lint": "f=${OXLINT_FORMAT:-${AGENT:+agent}}; oxlint . --format=${f:-default}",
58
57
  "test": "vitest run",
59
- "test:run": "vitest run --coverage"
58
+ "test:run": "vitest run --coverage",
59
+ "test:contract": "vitest run --config vitest.contract.config.ts"
60
60
  }
61
61
  }
@@ -1,6 +0,0 @@
1
- import { n as RenderOptions } from "./index-BRUs6L5O.js";
2
- import { CheckResult } from "@systemfsoftware/arethetypeswrong-core";
3
- //#region src/getExitCode.d.ts
4
- declare function getExitCode(analysis: CheckResult, opts?: RenderOptions): number;
5
- //#endregion
6
- export { getExitCode };
@@ -1,14 +0,0 @@
1
- import { n as problemFlags } from "./problemUtils-DrDcGcsf.mjs";
2
- //#region src/getExitCode.ts
3
- function getExitCode(analysis, opts) {
4
- if (!analysis.types) return 0;
5
- const ignoreRules = opts?.ignoreRules ?? [];
6
- const ignoreResolutions = opts?.ignoreResolutions ?? [];
7
- return analysis.problems.some((problem) => {
8
- const notRuleIgnored = !ignoreRules.includes(problemFlags[problem.kind]);
9
- const notResolutionIgnored = "resolutionKind" in problem ? !ignoreResolutions.includes(problem.resolutionKind) : true;
10
- return notRuleIgnored && notResolutionIgnored;
11
- }) ? 1 : 0;
12
- }
13
- //#endregion
14
- export { getExitCode };
@@ -1,36 +0,0 @@
1
- import * as core from "@systemfsoftware/arethetypeswrong-core";
2
- //#region src/problemUtils.d.ts
3
- declare const problemFlags: {
4
- readonly NoResolution: 'no-resolution';
5
- readonly UntypedResolution: 'untyped-resolution';
6
- readonly FalseCJS: 'false-cjs';
7
- readonly FalseESM: 'false-esm';
8
- readonly CJSResolvesToESM: 'cjs-resolves-to-esm';
9
- readonly FallbackCondition: 'fallback-condition';
10
- readonly CJSOnlyExportsDefault: 'cjs-only-exports-default';
11
- readonly NamedExports: 'named-exports';
12
- readonly FalseExportDefault: 'false-export-default';
13
- readonly MissingExportEquals: 'missing-export-equals';
14
- readonly UnexpectedModuleSyntax: 'unexpected-module-syntax';
15
- readonly InternalResolutionError: 'internal-resolution-error';
16
- };
17
- declare const resolutionKinds: Record<core.ResolutionKind, string>;
18
- //#endregion
19
- //#region src/render/typed.d.ts
20
- declare function typed(analysis: core.Analysis, { emoji, summary, format, ignoreRules, ignoreResolutions }: RenderOptions): Promise<string>;
21
- //#endregion
22
- //#region src/render/untyped.d.ts
23
- declare function untyped(analysis: core.UntypedResult): string;
24
- //#endregion
25
- //#region src/render/index.d.ts
26
- type Format = 'auto' | 'table' | 'table-flipped' | 'ascii' | 'json';
27
- interface RenderOptions {
28
- ignoreRules?: (typeof problemFlags)[keyof typeof problemFlags][];
29
- ignoreResolutions?: (keyof typeof resolutionKinds)[];
30
- format?: Format;
31
- color?: boolean;
32
- summary?: boolean;
33
- emoji?: boolean;
34
- }
35
- //#endregion
36
- export { typed as i, RenderOptions as n, untyped as r, Format as t };
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { };
package/dist/index.mjs DELETED
@@ -1,199 +0,0 @@
1
- #!/usr/bin/env node
2
- import { n as problemFlags } from "./problemUtils-DrDcGcsf.mjs";
3
- import { getExitCode } from "./getExitCode.mjs";
4
- import { n as typed, t as untyped } from "./render-CTRBsIjQ.mjs";
5
- import * as core from "@systemfsoftware/arethetypeswrong-core";
6
- import { groupProblemsByKind, parsePackageSpec } from "@systemfsoftware/arethetypeswrong-core/utils";
7
- import { versions } from "@systemfsoftware/arethetypeswrong-core/versions";
8
- import chalk from "chalk";
9
- import { execSync } from "child_process";
10
- import { Option, program } from "commander";
11
- import { readFile, stat, unlink } from "fs/promises";
12
- import { createRequire } from "module";
13
- import path from "path";
14
- import readline from "readline";
15
- import { major, minor } from "semver";
16
- import { Writable } from "stream";
17
- import { Readable } from "node:stream";
18
- //#region src/profiles.ts
19
- const profiles = {
20
- strict: { ignoreResolutions: [] },
21
- node16: { ignoreResolutions: ["node10"] },
22
- "esm-only": { ignoreResolutions: ["node10", "node16-cjs"] }
23
- };
24
- /**
25
- * Merges the profile with the provided options
26
- *
27
- * @param profileKey - name of the profile to apply
28
- * @param opts - options to apply the profile to
29
- */
30
- function applyProfile(profileKey, opts) {
31
- const profile = profiles[profileKey];
32
- opts.ignoreResolutions = (opts.ignoreResolutions ?? []).concat(profile.ignoreResolutions);
33
- }
34
- //#endregion
35
- //#region src/readConfig.ts
36
- async function readConfig(program, alternate = ".attw.json") {
37
- try {
38
- const results = await readFile(alternate, "utf8");
39
- if (!results) return;
40
- const opts = JSON.parse(results);
41
- for (let key in opts) {
42
- if (key === "configPath") program.error(`cannot set "configPath" within ${alternate}`, { code: "INVALID_OPTION" });
43
- const value = opts[key];
44
- if (key === "ignoreRules") {
45
- if (!Array.isArray(value)) program.error(`error: config option 'ignoreRules' should be an array.`);
46
- const invalid = value.find((rule) => !Object.values(problemFlags).includes(rule));
47
- if (invalid) program.error(`error: config option 'ignoreRules' argument '${invalid}' is invalid. Allowed choices are ${Object.values(problemFlags).join(", ")}.`);
48
- }
49
- if (key === "profile") {
50
- if (typeof value !== "string") program.error(`error: config option 'profile' should be a string.`);
51
- if (!(value in profiles)) program.error(`error: config option 'profile' argument '${value}' is invalid. Allowed choices are ${Object.keys(profiles).join(", ")}.`);
52
- }
53
- if (Array.isArray(value)) {
54
- const opt = program.getOptionValue(key);
55
- if (Array.isArray(opt)) {
56
- program.setOptionValueWithSource(key, [...opt, ...value], "config");
57
- continue;
58
- }
59
- }
60
- if (key !== "help" && key !== "version") program.setOptionValueWithSource(key, opts[key], "config");
61
- }
62
- } catch (error) {
63
- if (!error || typeof error !== "object" || !("code" in error) || !("message" in error)) program.error("unknown error while reading config file", { code: "UNKNOWN" });
64
- else if (error.code !== "ENOENT") program.error(`error while reading config file:\n${error.message}`);
65
- }
66
- }
67
- //#endregion
68
- //#region src/write.ts
69
- async function write(data, out) {
70
- return new Promise((resolve, reject) => {
71
- const stream = new Readable({ read() {
72
- this.push(data);
73
- this.push("\n");
74
- this.push(null);
75
- } });
76
- stream.on("data", (chunk) => {
77
- out.write(chunk);
78
- });
79
- stream.on("end", () => {
80
- resolve();
81
- });
82
- out.on("error", (err) => {
83
- reject(err);
84
- });
85
- });
86
- }
87
- //#endregion
88
- //#region src/index.ts
89
- const version = createRequire(import.meta.url)("../package.json").version;
90
- const formats = Object.keys({
91
- auto: true,
92
- json: true,
93
- ascii: true,
94
- table: true,
95
- "table-flipped": true
96
- });
97
- program.addHelpText("before", `ATTW CLI (v${version})\n`).addHelpText("after", `\ncore: v${versions.core}, typescript: v${versions.typescript}`).version(`cli: v${version}\ncore: v${versions.core}\ntypescript: v${versions.typescript}`).name("attw").description(`${chalk.bold.blue("Are the Types Wrong?")} attempts to analyze npm package contents for issues with their TypeScript types,
98
- particularly ESM-related module resolution issues.`).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").addOption(new Option("--definitely-typed [version]", "Specify the version range of @types to use").default(true)).option("--no-definitely-typed", "Don't include @types").addOption(new Option("-f, --format <format>", "Specify the print format").choices(formats).default("auto")).option("-q, --quiet", "Don't print anything to STDOUT (overrides all other options)").option("--entrypoints <entrypoints...>", "Specify an exhaustive list of entrypoints to check. The package root is `\".\" Specifying this option disables automatic entrypoint discovery, and overrides the `--include-entrypoints` and `--exclude-entrypoints` options.").option("--include-entrypoints <entrypoints...>", "Specify entrypoints to check in addition to automatically discovered ones.").option("--exclude-entrypoints <entrypoints...>", "Specify entrypoints to exclude from checking.").option("--entrypoints-legacy", "In packages without the `exports` field, every file is an entry point. Specifying this option only takes effect when no entrypoints are automatically detected, or explicitly provided with other options.").addOption(new Option("--ignore-rules <rules...>", "Specify rules to ignore").choices(Object.values(problemFlags)).default([])).addOption(new Option("--profile <profile>", "Specify analysis profile").choices(Object.keys(profiles)).default("strict")).option("--summary, --no-summary", "Whether to print summary information about the different errors").option("--emoji, --no-emoji", "Whether to use any emojis").option("--color, --no-color", "Whether to use any colors (the FORCE_COLOR env variable is also available)").option("--config-path <path>", "Path to config file (default: ./.attw.json)").action(async (fileOrDirectory = ".") => {
99
- const opts = program.opts();
100
- await readConfig(program, opts.configPath);
101
- if (opts.profile) applyProfile(opts.profile, opts);
102
- let out = process.stdout;
103
- if (opts.quiet) out = new class extends Writable {
104
- _write(_chunk, _encoding, callback) {
105
- callback();
106
- }
107
- }();
108
- if (!opts.color) process.env.FORCE_COLOR = "0";
109
- let analysis;
110
- let deleteTgz;
111
- const dtIsPath = typeof opts.definitelyTyped === "string" && (opts.definitelyTyped.includes("/") || opts.definitelyTyped.includes("\\") || opts.definitelyTyped.endsWith(".tgz") || opts.definitelyTyped.endsWith(".tar.gz"));
112
- if (opts.fromNpm) {
113
- if (opts.pack) program.error("--pack and --from-npm cannot be used together");
114
- try {
115
- const result = parsePackageSpec(fileOrDirectory);
116
- if (result.status === "error") program.error(result.error);
117
- else {
118
- let pkg;
119
- if (dtIsPath) {
120
- const dtPackage = core.createPackageFromTarballData(new Uint8Array(await readFile(opts.definitelyTyped)));
121
- const pkgVersion = result.data.versionKind === "none" ? `${major(dtPackage.packageVersion)}.${minor(dtPackage.packageVersion)}` : result.data.version;
122
- pkg = (await core.createPackageFromNpm(`${result.data.name}@${pkgVersion}`)).mergedWithTypes(dtPackage);
123
- } else pkg = await core.createPackageFromNpm(`${result.data.name}@${result.data.version}`, { definitelyTyped: opts.definitelyTyped });
124
- analysis = await core.checkPackage(pkg, {
125
- entrypoints: opts.entrypoints,
126
- includeEntrypoints: opts.includeEntrypoints,
127
- excludeEntrypoints: opts.excludeEntrypoints,
128
- entrypointsLegacy: opts.entrypointsLegacy
129
- });
130
- }
131
- } catch (error) {
132
- if (error instanceof Error && "code" in error) program.error(`error while fetching package:\n${error.message}`, { code: "" + error.code });
133
- handleError(error, "checking package");
134
- }
135
- } else try {
136
- let fileName = fileOrDirectory;
137
- if (await stat(fileOrDirectory).then((stat) => !stat.isFile()).catch(() => false)) {
138
- 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)}.`);
139
- if (!opts.pack) {
140
- if (!process.stdout.isTTY) program.error("Specifying a directory requires the --pack option to confirm that running `npm pack` is ok.");
141
- const rl = readline.createInterface(process.stdin, process.stdout);
142
- const answer = await new Promise((resolve) => {
143
- rl.question(`Run \`npm pack\`? (Pass -P/--pack to skip) (Y/n) `, resolve);
144
- });
145
- rl.close();
146
- if (answer.trim() && !answer.trim().toLowerCase().startsWith("y")) process.exit(1);
147
- }
148
- const manifest = JSON.parse(await readFile(path.join(fileOrDirectory, "package.json"), { encoding: "utf8" }));
149
- fileName = deleteTgz = path.join(fileOrDirectory, `${manifest.name.replace("@", "").replace("/", "-")}-${manifest.version}.tgz`);
150
- execSync("npm pack", {
151
- cwd: fileOrDirectory,
152
- encoding: "utf8",
153
- stdio: "ignore"
154
- });
155
- }
156
- const file = await readFile(fileName);
157
- const data = new Uint8Array(file);
158
- const pkg = dtIsPath ? core.createPackageFromTarballData(data).mergedWithTypes(core.createPackageFromTarballData(new Uint8Array(await readFile(opts.definitelyTyped)))) : core.createPackageFromTarballData(data);
159
- analysis = await core.checkPackage(pkg, {
160
- entrypoints: opts.entrypoints,
161
- includeEntrypoints: opts.includeEntrypoints,
162
- excludeEntrypoints: opts.excludeEntrypoints,
163
- entrypointsLegacy: opts.entrypointsLegacy
164
- });
165
- } catch (error) {
166
- handleError(error, "checking file");
167
- }
168
- if (opts.format === "json") {
169
- const result = { analysis };
170
- if (analysis.types) result.problems = groupProblemsByKind(analysis.problems);
171
- await write(JSON.stringify(result, void 0, 2), out);
172
- if (deleteTgz) await unlink(deleteTgz);
173
- const exitCode = getExitCode(analysis, opts);
174
- if (exitCode) process.exit(exitCode);
175
- return;
176
- }
177
- await write("", out);
178
- if (analysis.types) {
179
- await write(await typed(analysis, opts), out);
180
- process.exitCode = getExitCode(analysis, opts);
181
- } else await write(untyped(analysis), out);
182
- if (deleteTgz) await unlink(deleteTgz);
183
- });
184
- program.parse(process.argv);
185
- function handleError(error, title) {
186
- if (error && typeof error === "object" && "message" in error) program.error(`error while ${title}:\n${error.message}`, {
187
- exitCode: 3,
188
- code: "code" in error && typeof error.code === "string" ? error.code : "UNKNOWN"
189
- });
190
- program.error(`unknown error while ${title}`, {
191
- code: "UNKNOWN",
192
- exitCode: 3
193
- });
194
- }
195
- process.on("unhandledRejection", (error) => {
196
- handleError(error, "checking package");
197
- });
198
- //#endregion
199
- export {};
@@ -1,29 +0,0 @@
1
- import "@systemfsoftware/arethetypeswrong-core";
2
- //#region src/problemUtils.ts
3
- const problemFlags = {
4
- NoResolution: "no-resolution",
5
- UntypedResolution: "untyped-resolution",
6
- FalseCJS: "false-cjs",
7
- FalseESM: "false-esm",
8
- CJSResolvesToESM: "cjs-resolves-to-esm",
9
- FallbackCondition: "fallback-condition",
10
- CJSOnlyExportsDefault: "cjs-only-exports-default",
11
- NamedExports: "named-exports",
12
- FalseExportDefault: "false-export-default",
13
- MissingExportEquals: "missing-export-equals",
14
- UnexpectedModuleSyntax: "unexpected-module-syntax",
15
- InternalResolutionError: "internal-resolution-error"
16
- };
17
- const resolutionKinds = {
18
- node10: "node10",
19
- "node16-cjs": "node16 (from CJS)",
20
- "node16-esm": "node16 (from ESM)",
21
- bundler: "bundler"
22
- };
23
- const moduleKinds = {
24
- 1: "(CJS)",
25
- 99: "(ESM)",
26
- "": ""
27
- };
28
- //#endregion
29
- export { problemFlags as n, resolutionKinds as r, moduleKinds as t };
@@ -1,2 +0,0 @@
1
- import { i as typed, n as RenderOptions, r as untyped, t as Format } from "../index-BRUs6L5O.js";
2
- export { Format, RenderOptions, typed, untyped };
@@ -1,2 +0,0 @@
1
- import { n as typed, t as untyped } from "../render-CTRBsIjQ.mjs";
2
- export { typed, untyped };