Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I run npx arethetypeswrong (CLI for library authors) #15

Closed
brainkim opened this issue Mar 22, 2023 · 25 comments
Closed

Can I run npx arethetypeswrong (CLI for library authors) #15

brainkim opened this issue Mar 22, 2023 · 25 comments

Comments

@brainkim
Copy link

brainkim commented Mar 22, 2023

Can I run npx are-the-types-wrong in my library, or pointed to a package.json, or to an npm URL, or a project, and

be told if I am doing it right

so I don’t have to read that long README.md 🙈

@brainkim brainkim changed the title Can I run npx arethetypeswrong Can I run npx arethetypeswrong Mar 22, 2023
@andrewbranch
Copy link
Collaborator

No, but I’d like to make a CLI eventually.

@jasikpark
Copy link

maybe via https://github.com/natemoo-re/clack? 🧐

@brainkim brainkim changed the title Can I run npx arethetypeswrong Can I run npx arethetypeswrong (CLI for library authors) Mar 22, 2023
@andrewbranch
Copy link
Collaborator

Have you seen the web UI of this project? clack looks way too pretty 🤪

@markerikson
Copy link

FYI, a couple weeks ago I was working on a CLI tool that uses the React ink CLI renderer to generate a table equivalent to what's on the website, with the goal of using it in a GH Action job:

image

I'm picking up with that work now.

Might be something that can be rolled over into an actual attw CLI tool!

@markerikson
Copy link

markerikson commented Mar 25, 2023

I just got this working, and added it to Redux Toolkit's "check published artifact in CI" job:

reduxjs/redux-toolkit#3294

edit

And now I've got that suite of examples being used over in the redux-thunk repo as well, including the attw check:

reduxjs/redux-thunk#342

@andrewbranch
Copy link
Collaborator

That looks great! I would take a PR for it. I have some vague ideas for making the CLI experience different from the web experience, but since it’s low on my priority list, I’d be happy to run with this in the meantime since a few people have asked for it.

I think the only thing I would need to add for the minimum bar is a severity system and a way to expect or ignore violations (for exit code purposes). I’ve had to tell people a few times already that the info the site shows you is just information and there are cases where it’s ok for a package not to show all green checks. Being ESM-only is an important enough compatibility restriction to show in the tool, but by showing it I don’t mean to prescribe that no package should ever be ESM-only.

@fubhy
Copy link

fubhy commented Apr 3, 2023

Just found this (thanks @karlhorky), and indeed, a CLI and/or github action would be absolutely wonderful. Would also be great to get a README badge for this so projects can p[roudly show off their standard compliance!

@markerikson
Copy link

Yeah, I'm pretty sure that the code I've got in https://github.com/reduxjs/redux-toolkit/tree/master/examples/publish-ci/are-the-types-wrong can be turned into both a standalone CI tool and a Github Action pretty straightforwardly!

But someone else needs to do it :) I've got entirely too many other things on my mind atm.

@fubhy
Copy link

fubhy commented Apr 3, 2023

Happy to take over if you don't mind. It'd be a few days before I can get to it too but I think this would be immensely useful!

@fubhy
Copy link

fubhy commented Apr 5, 2023

This has helped me so much already. I still got quite a few question marks around how things work in some scenarios, for instance that which @markerikson is also describing with publishing of CJS & ESM in parallel. My situation is slightly different though because I'm trying to stay as close as possible to tsc and avoid bundlers entirely (ultimately, I still believe (or hope?) that libraries generally just don't (or shouldn't) need bundlers at all).

Anyways, thanks for putting this together @andrewbranch and for starting that CLI @markerikson. I can't promise when I can get to it yet (probably right after easter), but I'll definitely turn this into a github action & standalone cli. Will report back here.

@timostamm
Copy link

This is fantastic. I think it's an excellent idea to make use of TypeScripts understanding of module resolution. Thanks for the work @andrewbranch!

A CLI with a meaningful exit code and the option to ignore violations would be very helpful. I would love to run this in CI, either by giving a path to a package, or by doing an npm pack first myself.

Ignoring violations by ProblemKind, and optionally narrowing to a specific ResolutionKind and entrypoint seems useful.

@timostamm
Copy link

Here is a small piece of code that does the analysis on a package in the local file system instead of a tarball: https://gist.github.com/timostamm/3797825096a418b1f4c97d979e2d4ae7

Running npm pack sure has advantages, but I figured it might be easier to get started with this (and not have to think about different package managers).

@mesqueeb
Copy link

I'd love to use the cli as well. @fubhy are you still interested? Would be so awesome

@ej-shafran
Copy link
Contributor

If no one is working on the CLI I'd love to take it on 😃

Or, if work is still being done, I'd love to help! @timostamm @fubhy

@fubhy
Copy link

fubhy commented May 29, 2023

Sorry I completely forgot about this. I don't have time for it in the next few weeks so feel free to take it on! <3

@markerikson
Copy link

@ej-shafran @fubhy fwiw as far as I'm concerned the CLI is basically written already :)

https://github.com/reduxjs/redux-toolkit/blob/e92993813a95d9165e0df77cf52573d6021a6fa8/examples/publish-ci/are-the-types-wrong/main.tsx

Someone needs to take that and officially publish it as a package or something. (Probably with @timostamm 's changes for analyzing a package.json?)

@ej-shafran
Copy link
Contributor

@markerikson wish I'd seen that this morning 😆

I've opened a WIP PR with what I've done already - I'll take a look at your work when I have a minute and see what I can apply from it

@markerikson
Copy link

@ej-shafran yep, feel free to grab whatever looks useful out of that!

Biggest thing I noticed from a quick glance is you're using a table lib or something, and I used the ink React CLI renderer.

Looking forward to whatever gets pulled together and published!

@NullVoxPopuli
Copy link

NullVoxPopuli commented May 29, 2023

woah, happy to see all this progress (even as recent as 3 hours ago!)

I'm using turborepo to lint my packages:

    "_:lint": {
      "outputs": [],
      "dependsOn": ["lint:js", "lint:hbs", "lint:prettier", "lint:types", "lint:package"]
    },
    "lint:js": { "outputs": [] }, // eslint
    "lint:hbs": { "outputs": [] }, // ember-template-lint
    "lint:prettier": { "outputs": [] }, 
    "lint:types": { "outputs": [], "dependsOn": ["^build"] }, // tsc / glint
    "lint:package": { "outputs": [], "dependsOn": ["build"] }, // publint

I'm super excited to add a lint:published-types in there than defers to the arethetypeswrong CLI <3

ya'll are awesome 🥳

@andrewbranch
Copy link
Collaborator

@ej-shafran’s PR at #26 looks really awesome! I just put up my initial review with some suggestions about config options and thoughts on --ignore. I’d encourage anyone interested in using it to take a look and weigh in if you have feedback!

@andrewbranch
Copy link
Collaborator

@arethetypeswrong/cli is published 🥳

Thanks @ej-shafran!

@mesqueeb
Copy link

mesqueeb commented Jun 4, 2023

@andrewbranch will you add something to the readme ? I'd love to know how to use the CLI : )

@ej-shafran
Copy link
Contributor

@mesqueeb I do think adding something to the README would be nice, but for the meanwhile you can look at the packages/cli folder, or just:

https://www.npmjs.com/package/@arethetypeswrong/cli

@kleinfreund
Copy link

kleinfreund commented Jun 4, 2023

You can run the CLI in a local project like this:

npx @arethetypeswrong/cli $(npm pack)

This seems to work in a Linux shell but also Windows PowerShell (haven't tried any others).

A nice improvement would be to automate the npm pack step and maybe also the removal of the created package file.

Thank you for the work on this :)

@wojtekmaj
Copy link
Contributor

wojtekmaj commented Jul 26, 2023

For folks using Yarn:

yarn pack && yarn dlx @arethetypeswrong/cli package.tgz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests