DEV Community

WH yang
WH yang

Posted on

Deno CLI Not Parsing Options After Target Files

Deno Overview

Deno is a JavaScript and TypeScript runtime built with Rust. It offers a better development experience with built-in tools like a linter, formatter, and test runner. Deno is also compatible with Node.js and npm.

Breaking Changes in Deno 3.0

In version 3.0, Deno introduced a change for command-line arguments. Users now need to put -- before their arguments to avoid confusion. You can find more details in these issues: Issue 31295 and Issue 30334.

Example from Version 2.5.6

Here’s how it worked in version 2.5.6:

  1. Command with --output ignored:
   ❯ deno compile --output output tests/testdata/compile/args.ts -- abcd
   Compile file:///Users/phillips/Repo/deno/tests/testdata/compile/args.ts to output

   Embedded Files

   output
   └── args.ts (224B)

   Files: 1.61KB
   Metadata: 1.29KB
   Remote modules: 12B
Enter fullscreen mode Exit fullscreen mode
  1. Command with -- correctly parsed:
   ❯ deno compile tests/testdata/compile/args.ts --output output -- abcd
   Compile file:///Users/phillips/Repo/deno/tests/testdata/compile/args.ts to args

   Embedded Files

   args
   └── args.ts (224B)

   Files: 1.63KB
   Metadata: 1.31KB
   Remote modules: 12B
Enter fullscreen mode Exit fullscreen mode

In the second example, the --output option was ignored and treated as an argument, which was not what users expected.

Fixing the Issue

A PR was made to fix this issue in version 2.5.6. The change removed a line of code that caused everything after the .ts or .js file to be considered an argument. Instead, it added a new rule to make sure anything after -- is treated as an argument for the script.

A test case was also created to check that arguments after -- are parsed correctly. However, it didn’t test if options after the target file would affect execution, as seen in Issue 30334:

deno compile main.ts --output output
Enter fullscreen mode Exit fullscreen mode

To address this, I submitted another PR to add a test case ensuring that the order of arguments doesn’t affect the execution result.

Conclusion

My journey through these issues and pull requests was quite interesting. When I joined the project, Issue 31295 was already open. I tried to help, but my question led the maintainer to realize the issue had been solved. I discovered another related issue that lacked a test case, which allowed me to contribute in a way I hadn’t planned, but it was still enjoyable!

Top comments (0)