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

feat!: parseNi etc. now return ResolvedCommand object instead of string, migrate to tinyexec #231

Merged
merged 9 commits into from
Aug 27, 2024

Conversation

userquin
Copy link
Member

@userquin userquin commented Aug 15, 2024

Description

This PR

  • parseNi, parseNr etc programmatic APIs now returns ResolvedCommand object instead of plain string
  • replaces @jsdevtools/ez-spawn with tinyexec using x arguments (split command using space).

🚨🚨 DO NOT RELEASE YET WE NEED TO DO SOME EXTERNAL TESTS 🚨🚨

Linked Issues

Additional context

Copy link

pkg-pr-new bot commented Aug 15, 2024

commit: 4514af5

pnpm add https://pkg.pr.new/antfu-collective/ni/@antfu/ni@231

Open in Stackblitz

@benmccann
Copy link
Contributor

We should probably wait for tinylibs/tinyexec#29 to be resolved first, but besides that it looks good to me

src/runner.ts Outdated
@@ -140,5 +148,12 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
return
}

await ezspawn(command, { stdio: 'inherit', cwd })
const [xCommand, ...xArguments] = command.split(' ')
Copy link
Member

@antfu antfu Aug 15, 2024

Choose a reason for hiding this comment

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

I don't think it's safe to use split, as you might have edge cases like run "foo bar", we would either need to complete change how we compose the commands (use array instead of string), or we need tinyexec to support parsing string commands

Copy link
Member Author

@userquin userquin Aug 15, 2024

Choose a reason for hiding this comment

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

This should be easy since we have the original arguments, I'll change it tmr.

package.json Outdated Show resolved Hide resolved
@benmccann benmccann mentioned this pull request Aug 21, 2024
package.json Outdated Show resolved Hide resolved
src/detect.ts Outdated Show resolved Hide resolved
@antfu antfu changed the title chore: use tinyexec feat!: parseN.. now returns ResolvedCommand object instead of string, migreate to tinyexec Aug 26, 2024
@antfu
Copy link
Member

antfu commented Aug 26, 2024

Made some refactoring and upgraded package-manager-detector, LGTM now

src/utils.ts Outdated
const VOLTA_PREFIX = 'volta run'
const hasVoltaCommand = cmdExists('volta')
return hasVoltaCommand ? VOLTA_PREFIX : ''
export function isVoltaExists(): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

doesVoltaExist might be a bit more grammatically correct name

Copy link
Member

Choose a reason for hiding this comment

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

I don't think identifiers are valid English sentences, which grammar doesn't always apply (it can be read as an abbr of "is it true that volta exists in current directory?"). I tend to use is prefix to describe functions that return boolean.

Copy link
Contributor

Choose a reason for hiding this comment

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

fair enough. might be able to make it isVoltaInstalled or isVoltaPresent or something like that if you wanted to keep the is prefix and make it a bit more grammatical

anyway, this PR looks good to me. this was the only thing I noticed

@antfu antfu changed the title feat!: parseN.. now returns ResolvedCommand object instead of string, migreate to tinyexec feat!: parseNi etc. now return ResolvedCommand object instead of string, migrate to tinyexec Aug 27, 2024
@antfu antfu merged commit 3d32313 into main Aug 27, 2024
4 checks passed
@antfu antfu deleted the userquin/use-tinyexec branch August 27, 2024 01:05
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.

3 participants