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

Add support for Deno shortcuts and wildcards #508

Merged

Conversation

mahtaran
Copy link
Contributor

With the release of Deno 2, I figured I'd have a look if the amazing shortcut and wildcard features of this tool supported it. Sadly, they didn't. Luckily, adding it wasn't too difficult. One thing to note is that Deno uses its own deno.json file with what it calls 'tasks', but can also fall back on Node's scripts directive in the package.json.

For a cleaner reviewing process, I recommend looking at the individual commits, as it doesn't quite seem to understand I renamed some files.

Signed-off-by: Luka Leer <luka.leer@gmail.com>
Signed-off-by: Luka Leer <luka.leer@gmail.com>
@coveralls
Copy link

coveralls commented Oct 11, 2024

Coverage Status

coverage: 98.156% (-0.1%) from 98.263%
when pulling 9f7dad2 on mahtaran:feature/deno-wildcards-shortcuts
into 79b3290 on open-cli-tools:main.

@gustavohenke gustavohenke self-requested a review October 12, 2024 01:24
import { CommandInfo } from '../command';
import { CommandParser } from './command-parser';

const OMISSION = /\(!([^)]+)\)/;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a comment explaining what this Regexp does?
It isn't clear its intent unless you read the rest of the code and, even then, it's a bit confused.

Thanks in advance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was confused when I read it at first as well. Good catch, just added a comment. Do you think that clarifies it enough?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

I was just wondering why we'd need to look for ) in the script command?!

I guess most of the people (myself included) don't know we could use something like this deno task lint:*(!fix) as a valid command.

Perhaps, adding an example in the comment would help as well.

Copy link
Contributor Author

@mahtaran mahtaran Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour is currently already documented, though I do see how it could be difficult to find for someone less familiar with the tool. I do think this is a bit out of scope for this pull request, though, so perhaps it would be better to tackle this separately?

Signed-off-by: Luka Leer <luka.leer@gmail.com>
Copy link
Member

@gustavohenke gustavohenke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition, thank you!

commandInfo.command.match(/^(node|npm|yarn|pnpm|bun):(\S+)(.*)/) || [];
if (!cmdName) {
const [, prefix, script, args] =
/^(npm|yarn|pnpm|bun|node|deno):(\S+)(.*)/.exec(commandInfo.command) || [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, was there any advantage of changing from string.match to regexp.exec() here?
AFAICT both are generally equivalent, but maybe I'm missing something.

No dramas if it's just your preference :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly personal preference, yeah. From what I've heard, String.match() and RegExp.exec() function identically to each other if the global flag is not set, in fact, String.match() uses RegExp.exec() under the hood, so using the latter carries a very minor performance benefit with it.

@gustavohenke gustavohenke merged commit 64b7e2a into open-cli-tools:main Nov 4, 2024
21 checks passed
@mahtaran mahtaran deleted the feature/deno-wildcards-shortcuts branch November 8, 2024 02:29
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

Successfully merging this pull request may close these issues.

4 participants