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

Deno runtime not supported #40

Closed
ulken opened this issue Feb 13, 2023 · 19 comments
Closed

Deno runtime not supported #40

ulken opened this issue Feb 13, 2023 · 19 comments

Comments

@ulken
Copy link

ulken commented Feb 13, 2023

Due to denoland/deno#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
Copy link
Owner

75lb commented Feb 13, 2023

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

@ulken
Copy link
Author

ulken commented Feb 13, 2023

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
Copy link
Owner

75lb commented Feb 13, 2023

instructions on how to reproduce it locally please..

  • What pre-reqs do I need to install?
  • Post some code which fails
  • Post a command I can run to see it failing and then later run again to check the fix works..

@ulken
Copy link
Author

ulken commented Feb 13, 2023

Got it! I'll get back to you.

@ulken
Copy link
Author

ulken commented Feb 13, 2023

  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"
    }
  ]));
}
  1. 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
Copy link
Author

ulken commented Feb 14, 2023

Let me know if a PR would help.

@75lb
Copy link
Owner

75lb commented Feb 14, 2023

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
Copy link
Owner

75lb commented Feb 14, 2023

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
Copy link
Author

ulken commented Feb 14, 2023

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
Copy link
Author

ulken commented Feb 14, 2023

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
Copy link
Owner

75lb commented Feb 14, 2023

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

@ulken
Copy link
Author

ulken commented Feb 14, 2023

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
Copy link
Owner

75lb commented Feb 14, 2023

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
Copy link
Author

ulken commented Feb 14, 2023

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

@75lb
Copy link
Owner

75lb commented Feb 14, 2023

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
Copy link
Author

ulken commented Feb 14, 2023

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
Copy link
Owner

75lb commented Mar 5, 2023

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
Copy link
Owner

75lb commented Mar 5, 2023

Released in v7.0.0

@75lb 75lb closed this as completed Mar 5, 2023
@ulken
Copy link
Author

ulken commented Mar 5, 2023

Cool! Will do 👍

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

No branches or pull requests

2 participants