Skip to content

Commit

Permalink
fix: add bin to package.json (#1508)
Browse files Browse the repository at this point in the history
<!-- 👋 Hi, thanks for sending a PR to TypeStat! 💖.
Please fill out all fields below and make sure each item is true and [x]
checked.
Otherwise we may not be able to review your PR. -->

## PR Checklist

- [x] Addresses an existing open issue: fixes #1496
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/TypeStat/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/TypeStat/blob/main/.github/CONTRIBUTING.md)
were taken :octocat:

## Overview

<!-- Description of what is changed and how the code change does that.
-->

I think it would be good idea to do alpha / experimental release after
this to check that everything is correct :)

---------

Co-authored-by: Josh Goldberg <[email protected]>
  • Loading branch information
rubiesonthesky and JoshuaKGoldberg authored Nov 29, 2024
1 parent 0d9c44e commit 84b3991
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ jobs:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- run: pnpm build
- run: node ./lib/index.js
- run: pnpm link .
- run: pnpm typestat

name: Build

Expand Down
3 changes: 2 additions & 1 deletion bin/typestat → bin/typestat.mjs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node

const { runCli } = require("../src/cli/runCli");
// eslint-disable-next-line n/no-missing-import
import { runCli } from "../lib/cli/runCli.js";

runCli(process.argv)
.then((resultStatus) => {
Expand Down
6 changes: 5 additions & 1 deletion knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"$schema": "https://unpkg.com/knip@latest/schema.json",
"entry": ["src/index.ts!", "test/**/*.ts!", "test/**/*.tsx!"],
"ignore": ["test/cases/fixes/importExtensions/*"],
"ignoreExportsUsedInFile": { "interface": true, "type": true },
"ignoreBinaries": ["typestat"],
"ignoreExportsUsedInFile": {
"interface": true,
"type": true
},
"project": ["src/**/*.ts!", "test/**/*.ts!", "test/**/*.tsx!"]
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
},
"type": "module",
"main": "./lib/index.js",
"bin": {
"typestat": "bin/typestat.mjs"
},
"files": [
"bin/typestat.mjs",
"lib/",
"package.json",
"LICENSE.md",
Expand Down
4 changes: 3 additions & 1 deletion src/initialization/initializeJavaScript/cleanups.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { prompt } from "enquirer";
import enquirer from "enquirer";

const prompt = enquirer.prompt;

export enum InitializationCleanups {
No = "No",
Expand Down
4 changes: 3 additions & 1 deletion src/initialization/initializeJavaScript/imports.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { prompt } from "enquirer";
import enquirer from "enquirer";

const prompt = enquirer.prompt;

export enum InitializationImports {
No = "No",
Expand Down
4 changes: 3 additions & 1 deletion src/initialization/initializeJavaScript/renames.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { prompt } from "enquirer";
import enquirer from "enquirer";

const prompt = enquirer.prompt;

export enum InitializationRenames {
Auto = "Rename files containing JSX to .tsx and others to .ts",
Expand Down
4 changes: 3 additions & 1 deletion src/initialization/initializeProject/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { prompt } from "enquirer";
import enquirer from "enquirer";
import * as fs from "fs";
import { glob } from "glob";

Expand All @@ -10,6 +10,8 @@ import {
TSConfigLocationSuggestion,
} from "./shared.js";

const prompt = enquirer.prompt;

export const initializeProject = async (): Promise<ProjectDescription> => {
const project = await initializeBuiltInProject();

Expand Down
4 changes: 3 additions & 1 deletion src/initialization/initializeProject/initializeNewProject.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { prompt } from "enquirer";
import enquirer from "enquirer";
import * as fs from "node:fs/promises";

import { ProjectDescription } from "./shared.js";

const prompt = enquirer.prompt;

const filePath = "./tsconfig.json";

export const initializeNewProject = async (): Promise<ProjectDescription> => {
Expand Down
4 changes: 3 additions & 1 deletion src/initialization/initializePurpose/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { prompt } from "enquirer";
import enquirer from "enquirer";
import * as fs from "fs";

const prompt = enquirer.prompt;

export enum InitializationPurpose {
ConvertJavaScript = "Convert my JavaScript files to TypeScript",
ImproveTypeScript = "Improve typings in my TypeScript files",
Expand Down
4 changes: 3 additions & 1 deletion src/initialization/initializeTypeScript/improvements.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { prompt } from "enquirer";
import enquirer from "enquirer";

const prompt = enquirer.prompt;

export enum InitializationImprovement {
MissingProperties = "Add missing property declarations to classes",
Expand Down
4 changes: 3 additions & 1 deletion src/initialization/initializeTypeScript/initializeTests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { prompt } from "enquirer";
import enquirer from "enquirer";

const prompt = enquirer.prompt;

const other = "other";
const none = "(none)";
Expand Down
4 changes: 3 additions & 1 deletion src/initialization/sources/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { prompt } from "enquirer";
import enquirer from "enquirer";
import * as fs from "node:fs/promises";

const prompt = enquirer.prompt;

import { ProjectDescription } from "../initializeProject/shared.js";

export interface InitializeSourcesSettings {
Expand Down
9 changes: 6 additions & 3 deletions src/options/findRawOptions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { readFileSync } from "node:fs";
import * as path from "node:path";

import { RawTypeStatOptions } from "./types.js";
Expand Down Expand Up @@ -31,15 +32,17 @@ export const findRawOptions = (

let filePath: string;
try {
filePath = require.resolve(resolutionPath);
filePath = path.resolve(resolutionPath);
} catch {
return configPath === resolutionPath
? `Could not find config file at '${configPath}'.`
: `Could not find config file at '${configPath}' (resolved to '${resolutionPath}').`;
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-var-requires
const allRawOptions = extractConfigAsRelative(filePath, require(filePath));
const rawOptions = JSON.parse(readFileSync(filePath, "utf-8")) as
| RawTypeStatOptions
| RawTypeStatOptions[];
const allRawOptions = extractConfigAsRelative(filePath, rawOptions);

return { allRawOptions, filePath };
};
Expand Down
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default defineConfig({
bundle: false,
clean: true,
dts: true,
entry: ["src/**/*.ts", "!src/**/*.test.*"],
entry: ["src/**/*.ts", "!src/**/*.test.*", "!src/tests/**"],
format: "esm",
outDir: "lib",
sourcemap: true,
Expand Down

0 comments on commit 84b3991

Please sign in to comment.