storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
84.7k stars 9.33k forks source link

npx sb init doesn't work #17923

Closed airtonix closed 2 years ago

airtonix commented 2 years ago

image

but sb is actually :

thing on git master [x!+?] via nodejs v16.6.1 took 2s 
x npx sb init --help      

sb version 0.12.20
Usage: sb [options] file ...
   or: sb [options] -{c|i} COMMAND
Send file(s) with ZMODEM/YMODEM/XMODEM protocol
    (X) = option applies to XMODEM only
    (Y) = option applies to YMODEM only
    (Z) = option applies to ZMODEM only
  -+, --append                append to existing destination file (Z)
  -2, --twostop               use 2 stop bits
  -4, --try-4k                go up to 4K blocksize
      --start-4k              start with 4K blocksize (doesn't try 8)
  -8, --try-8k                go up to 8K blocksize
      --start-8k              start with 8K blocksize
  -a, --ascii                 ASCII transfer (change CR/LF to LF)
  -b, --binary                binary transfer
  -B, --bufsize N             buffer N bytes (N==auto: buffer whole file)
  -c, --command COMMAND       execute remote command COMMAND (Z)
  -C, --command-tries N       try N times to execute a command (Z)
  -d, --dot-to-slash          change '.' to '/' in pathnames (Y/Z)
      --delay-startup N       sleep N seconds before doing anything
  -e, --escape                escape all control characters (Z)
  -E, --rename                force receiver to rename files it already has
  -f, --full-path             send full pathname (Y/Z)
  -i, --immediate-command CMD send remote CMD, return immediately (Z)
  -h, --help                  print this usage message
  -k, --1k                    send 1024 byte packets (X)
  -L, --packetlen N           limit subpacket length to N bytes (Z)
  -l, --framelen N            limit frame length to N bytes (l>=L) (Z)
  -m, --min-bps N             stop transmission if BPS below N
  -M, --min-bps-time N          for at least N seconds (default: 120)
  -n, --newer                 send file if source newer (Z)
  -N, --newer-or-longer       send file if source newer or longer (Z)
  -o, --16-bit-crc            use 16 bit CRC instead of 32 bit CRC (Z)
  -O, --disable-timeouts      disable timeout code, wait forever
  -p, --protect               protect existing destination file (Z)
  -r, --resume                resume interrupted file transfer (Z)
  -R, --restricted            restricted, more secure mode
  -q, --quiet                 quiet (no progress reports)
  -s, --stop-at {HH:MM|+N}    stop transmission at HH:MM or in N seconds
      --tcp                   build a TCP connection to transmit files
      --tcp-server            open socket, wait for connection
  -u, --unlink                unlink file after transmission
  -U, --unrestrict            turn off restricted mode (if allowed to)
  -v, --verbose               be verbose, provide debugging information
  -w, --windowsize N          Window is N bytes (Z)
  -X, --xmodem                use XMODEM protocol
  -y, --overwrite             overwrite existing files
  -Y, --overwrite-or-skip     overwrite existing files, else skip
      --ymodem                use YMODEM protocol
  -Z, --zmodem                use ZMODEM protocol

short options use the same arguments as the long ones
airtonix commented 2 years ago

Why did you guys remove the steps to manually install storybook into a project.

so ways to fix this problem:

airtonix commented 2 years ago

so it turns out that the storybook team naively expected no one else on earth to publish a package providing a binary called sb...

for those who want to run the sb command properly:

npx --package @storybook/cli  sb init

https://github.com/storybookjs/storybook/tree/next/lib/cli

shilman commented 2 years ago

@airtonix any chance you can figure out which package is installing the binary called sb?

airtonix commented 2 years ago

@shilman There might be a way utilising vscodes javascript debugging tool and breakpoints in npx itself... not heaps hopeful on this outcome.

even if we discover who it was... it feels like a thing that will keep happening, since NPM.js only protects against package name squatting.

shilman commented 2 years ago

@airtonix what version of npm are you running?

So far I'm not able to reproduce this. We do own the npm package called sb, which is how this currently works for most users.

shilman commented 2 years ago

What if you run:

more ./node_modules/.bin/sb
airtonix commented 2 years ago

@shilman yeah but doesn't npx works like this ?

so in my case Fedora 34 provides a /usr/bin/sb:

$ yum provides /usr/bin/sb
...snips butt loads of dnf update spam...

lrzsz-0.12.20-53.fc34.x86_64 : The lrz and lsz modem communications programs
Repo        : @System
Matched from:
Filename    : /usr/bin/sb

lrzsz-0.12.20-53.fc34.x86_64 : The lrz and lsz modem communications programs
Repo        : fedora
Matched from:
Filename    : /usr/bin/sb

But it illustrates a problem with the documentation:

airtonix commented 2 years ago

yep, earlier i didn't have @storybook/cli installed, but now that I do, npx sb ... always uses the cli you created.

if i step outside of the repo or clear my npm cache (I think), then npx goes back to resolving sb from /usr/bin/sb

shilman commented 2 years ago

@airtonix when I run:

$ which ncdu
/usr/local/bin/ncdu

However, when I run:

$ npx ncdu
Need to install the following packages:
  ncdu
Ok to proceed? (y)
...

It downloads and installs https://www.npmjs.com/package/ncdu, which is a different program.

EDIT: it looks like it downloads the package and then perhaps executes the existing binary from /usr/local/bin 🤦

airtonix commented 2 years ago

@shilman have you ever downloaded that package before?

airtonix commented 2 years ago

i'm spinning up a newly created directory with a version of node i've never used before via asdf and wiping my ~/.npm

airtonix commented 2 years ago

i think the easiest way to avoid this annoying behaviour and time sink it would bring for you is to update documentation so that any mention of npx sb ... is changed to npx --package @storybook/cli sb ...

airtonix commented 2 years ago

i can't reproduce anymore is keeps wanting to correctly install an sb package

shilman commented 2 years ago

Yeah, we also have the package storybook, so I think we're going to switch to that instead:

npx storybook init

This will have the same problem, if somebody installs a binary called storybook in their path. But I think that's a much lower possibility than sb, which looks like it's a built-in utility in some linux distributions

airtonix commented 2 years ago

@shilman did you want to leave this issue open? or are you actioning this somewhere else ?

shilman commented 2 years ago

Tracking at #17934 and closing this. Thanks so much @airtonix for helping debug this!!! 🙏

shilman commented 2 years ago

@airtonix if you type npx sb@latest init does that fix it?