75lb / command-line-usage

A simple, data-driven module for creating a usage guide.
MIT License
210 stars 36 forks source link

Deno runtime not supported #40

Closed ulken closed 1 year ago

ulken commented 1 year ago

Due to https://github.com/denoland/deno/issues/13321, the library fails with

error: Uncaught TypeError: chalk.underline.bold is not a function
    at ContentSection.header (file:///Users/ulken/Library/Caches/deno/npm/registry.npmjs.org/command-line-usage/6.1.3/lib/section.js:23:32)

The version of chalk used is really old. Please consider upgrading to at least 4.X, where the issue above is fixed. If you want to take the step to ESM, you might want to take it to 5.X+ even.

If you're up for it, let me know if you want me to help out in any way.

PS. Even if you have no intention of supporting Deno, I think it would still be worth to upgrade Chalk to a more modern (and safer) version.

75lb commented 1 year ago

Hi, could you send some simple instructions on how to reproduce this please..

ulken commented 1 year ago

Hi, could you send some simple instructions on how to reproduce this please..

Sure thing. Would you prefer a sandbox or instructions how to reproduce it locally?

75lb commented 1 year ago

instructions on how to reproduce it locally please..

ulken commented 1 year ago

Got it! I'll get back to you.

ulken commented 1 year ago
  1. Install Deno
  2. mkdir cli-usage-deno && cd $_
  3. deno init
  4. Replace contents of main.ts with
    
    import cliUsage from "npm:command-line-usage";

if (import.meta.main) { console.log(cliUsage([ { header: "Deno CLI usage", content: "Best thing ever" } ])); }


5. `deno run --allow-read --allow-env main.ts` (could also pass `--allow-all` if you prefer)

Let me know if you get stuck on something.
ulken commented 1 year ago

Let me know if a PR would help.

75lb commented 1 year ago

I had a look last night, chalk v5 is ESM only, meaning the command-line-usage project would need to be upgraded to a ESM project ("type": "module").. which is fine, but it would also still need to support CJS as we don't have an "ESM only" policy on these projects meaning rollup would need to be introduced to build a CJS option, which is fine too but it's probably not as quick a fix as you were hoping

75lb commented 1 year ago

also, the tagged template support was removed from chalk v5.. this library uses that feature to give users the ability to colour usage docs, e.g. some {red important} text.. so a bit of extra work required there too..

ulken commented 1 year ago

Right, which is why I wrote:

Please consider upgrading to at least 4.X, where the issue above is fixed. If you want to take the step to ESM, you might want to take it to 5.X+ even.

From the Chalk README:

IMPORTANT: Chalk 5 is ESM. If you want to use Chalk with TypeScript or a build tool, you will probably want to use Chalk 4 for now.

and

It's totally fine to stay on Chalk v4. It's been stable for years.

I.e v4 should solve the problem equally well.

ulken commented 1 year ago

also, the tagged template support was removed from chalk v5.. this library uses that feature to give users the ability to colour usage docs, e.g. some {red important} text.. so a bit of extra work required there too..

Moved to a separate package, though, so shouldn't be too bad?

75lb commented 1 year ago

i thought the Deno fix was from chalk v5.2 onward.. may be wrong..

ulken commented 1 year ago

i thought the Deno fix was from chalk v5.2 onward.. may be wrong..

To my understanding, this is the crucial fix, introduced in 4.0.0.

If so, 4.1.2 should cut it.

Other problems might show up further down the road, though. I can give it a try, if you'd like.

75lb commented 1 year ago

since implementing this fix will introduce a breaking change to command-line-usage, we might as upgrade all deps to all latest versions (v5, not v4 chalk) and rewrite the project as ESM.. that way we can squeeze as many breaking upgrades into the next release as possible.. since this update will result in changes right across the project (in /examples and /test too) I will do it this time.. otherwise, yes I'd welcome your PR..

ulken commented 1 year ago

All right, by all means. Thank you for taking the leap. You know where to find me. Good luck!

75lb commented 1 year ago

I've published a beta version for testing.. please update your import with the following and give it a try..

import cliUsage from "npm:command-line-usage@next"
ulken commented 1 year ago

Hey, look at that!

Screenshot 2023-02-14 at 16 50 53

For unknown reason, the formatting is not displayed in Warp, but that is on them (works in Hyper and Terminal.app)...

https://app.warp.dev/block/nvpi0MT2iXS45OmFaVQyjT

Is it erroneously thinking it's piped and strips the formatting? Idk. Don't bother.

75lb commented 1 year ago

I'm about to move this out of beta and make it live, please let me know if there are any further deno issues I might not know about.. Cheers!

75lb commented 1 year ago

Released in v7.0.0

ulken commented 1 year ago

Cool! Will do 👍