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

bug(windows): native command execution syntax doesn’t work for npm/npx package #1474

Open
Kristinita opened this issue Jan 10, 2024 · 2 comments

Comments

@Kristinita
Copy link

Kristinita commented Jan 10, 2024

1. Summary

I can’t run the CoffeeLint npm/npx package command using the native fd syntax for commands execution. I get errors:

[fd error]: Command not found: coffeelint

[fd error]: Command not found: npx

2. Reproducibility

I don’t reproduce the problem and get expected behavior if I use:

  1. Ubuntu instead of Windows.

  2. fd + xargs instead of built-in fd command execution.

  3. fd to run the Chocolatey and pip/pipenv packages instead of npm/npx package.

    # [INFO] All these commands works as expected for me on Windows
    
    # [INFO] pip/pipenv packages
    fd --extension py --exec bashate
    fd --extension py --exec pipenv run bashate
    fd --extension py --exec pylint
    fd --extension py --exec pipenv run pylint
    
    # [INFO] Chocolatey packages
    fd --extension sh --exec shellcheck
    fd --extension xml --exec xmllint --noout
    fd --extension html --exec tidy --markup 0

3. MCVE

AppVeyor build for this configuration.

3.1. Files

2 files KiraFirst.coffee and KiraSecond.coffee without any content.

fd --extension coffee

KiraFirst.coffee
KiraSecond.coffee

3.2. Install

# [INFO] Install fd via Chocolatey
- choco install fd --yes

# [INFO] Install CoffeeLint globally and locally via npm
- npm install --global @coffeelint/cli
- npm install --save-dev @coffeelint/cli

3.3. Commands

CoffeeLint doesn’t support glob pattern out of the box, to run it recursively requires tools like fd.

# [INFO] Run global CoffeeLint
- fd --extension coffee --exec coffeelint
- fd --print0 --extension coffee | xargs --null coffeelint

# [INFO] Run local CoffeeLint
- fd --print0 --extension coffee | xargs --null npx coffeelint
- fd --extension coffee --exec npx coffeelint

3.4. Behavior

3.4.1. Expected — Ubuntu

Travis CI build:

$ fd --extension coffee --exec coffeelint

  ✓ KiraFirst.coffee

✓ Ok! » 0 errors and 0 warnings in 1 file

  ✓ KiraSecond.coffee

✓ Ok! » 0 errors and 0 warnings in 1 file

The command "fd --extension coffee --exec coffeelint" exited with 0.

1.00s


$ fd --extension coffee --exec npx coffeelint

  ✓ KiraSecond.coffee

✓ Ok! » 0 errors and 0 warnings in 1 file

  ✓ KiraFirst.coffee

✓ Ok! » 0 errors and 0 warnings in 1 file

The command "fd --extension coffee --exec npx coffeelint" exited with 0.

0.16s


$ fd --print0 --extension coffee | xargs --null coffeelint

  ✓ KiraFirst.coffee

  ✓ KiraSecond.coffee

✓ Ok! » 0 errors and 0 warnings in 2 files

The command "fd --print0 --extension coffee | xargs --null coffeelint" exited with 0.

0.57s


$ fd --print0 --extension coffee | xargs --null npx coffeelint

  ✓ KiraFirst.coffee

  ✓ KiraSecond.coffee

✓ Ok! » 0 errors and 0 warnings in 2 files

The command "fd --print0 --extension coffee | xargs --null npx coffeelint" exited with 0.

All 4 commands successfully launched.

3.4.2. Undesirable — Windows

AppVeyor CI build:

fd --extension coffee --exec coffeelint
[fd error]: Command not found: coffeelint
[fd error]: Command not found: coffeelint
Command exited with code 1

fd --print0 --extension coffee | xargs --null coffeelint
  ✓ KiraFirst.coffee
  ✓ KiraSecond.coffee
✓ Ok! » 0 errors and 0 warnings in 2 files

fd --print0 --extension coffee | xargs --null npx coffeelint
  ✓ KiraFirst.coffee
  ✓ KiraSecond.coffee
✓ Ok! » 0 errors and 0 warnings in 2 files

fd --extension coffee --exec npx coffeelint
[fd error]: Command not found: npx
[fd error]: Command not found: npx
Command exited with code 1

CoffeeLint launched successfully if I use xargs, but failed to launch if I use the native fd syntax for commands execution.

4. Environment

  1. Operating system:

    1. Local — Windows 11 Version 10.0.22621.2861
    2. AppVeyor — Windows Server 2019
  2. fd 9.0.0

  3. Node.js

    1. Local — 21.5.0
    2. AppVeyor — 21.2.0
  4. npx

    1. Local — 10.2.5
    2. AppVeyor — 10.2.3
  5. CoffeeLint 5.2.11

Thanks.

@tavianator
Copy link
Collaborator

tavianator commented Jan 13, 2024

See rust-lang/rust#37519 for some history about the behaviour of Command::spawn() on Windows. One useful suggestion from that issue is the which crate, which provides command resolution behaviour that may be closer to what CMD/PowerShell actually does to resolve executables.

Which xargs implementation are you using? Never mind, I see it's from git bash

@Kristinita
Copy link
Author

Kristinita commented Mar 2, 2024

Type: Additional information

1. xargs + npx on Windows without WSL

When I run fd + npx CoffeeLint on Windows 11 without WSL, I get this output:

fd --print0 --extension coffee | xargs --null npx coffeelint
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore

I don’t reproduce this behavior on continuous integration services perhaps because CIs have WSL pre-installed.

I think that WSL — too big dependency to run npx commands, and that it would be nice if Windows users without WSL could run npx commands use fd.

2. xargs implementation

Which xargs implementation are you using?

I added this information to my AppVeyor build. Yes, I used the xargs command from Git for Windows.

I can’t resolve the WSL problem when I also use the xargs command from Cygwin 3.5.1:

where xargs
D:\Chocolatey\tools\cygwin\bin\xargs.exe

D:\Chocolatey\tools\cygwin\bin\xargs.exe --version
xargs (GNU findutils) 4.9.0
Packaged by Cygwin (4.9.0-1)
Copyright (C) 2022 Free Software Foundation, Inc.

fd --print0 --extension coffee | D:\Chocolatey\tools\cygwin\bin\xargs.exe --null npx coffeelint
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore

Thanks.

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

No branches or pull requests

2 participants