One more FAQ regarding why not an npm create.

master
Zed A. Shaw 1 year ago
parent 6278e47308
commit 1ef7198fcb
  1. 19
      README.md

@ -70,6 +70,25 @@ git clone https://git.learnjsthehardway.com/learn-javascript-the-hard-way/ljsthw
Some answers to questions I'm sure I'll receive.
## Why Not use npm init?
Because `npm` (as of version 9.1.2) requires any module that implements the create mechanism be registered at npmjs.com. Even though the documentation says that it won't when the module is installed "globally" it still checks in npmjs.com despite the module being installed locally. Additionally, even if it did work it doesn't buy you much and adds a ton of convolution to basically run a command.
For example, here's how `npm init` should work with this project:
```
npm install git+https://git.learnjsthehardway.com/learn-javascript-the-hard-way/create-ljsthw-bandolier.git
npm init ljsthw-bandolier
```
Why all the `create` words everywhere? Because npm's init system uses a strange naming convention to determine that a project is meant to generate other projects. When you run that final `npm init ljsthw-bandolier` command it just...runs `npm exec create-ljsthw-bandolier`, which is, you guessed it, just `npx create-ljsthw-bandolier`. It's quite literally doing nothing adding convoluted steps to run a simple command.
However, this doesn't even work. If you run the first `npm install` command, it works. If you then run the `npm init ljsthw-bandolier` command it fails because `npm` _tries to confirm that npmjs.com has a module named `create-ljsthw-bandolier`_. It's not supposed to do this because the project is actually installed, but it does anyway. Why? Because Microsoft probably told some manager over at npm to make the User Stonks go "up and to the right!"
After trying for weeks to figure out why this didn't work I just figured out that it was completely unnecessary. If a user installs a module, and that module has scripts in the `bin` portion of the `package.json` file, then they can just run the command with `npx`. It's even easier and cleaner than the stupid `create-` that talks to a `create-` that talks to npmjs.com to a `create-` script that...you get the idea.
`TLDR:` Because it's actually simpler to just install a module from a git repo that has a command the user can run.
## Why Not an npm Module?
The Bandolier is designed for _you_ to change it. You are expected to study the code, change it how you want, and learn how everything is made. Every component in The Bandolier is small, and not feature complete _on purpose_, as that gives you room to experiment. Placing the code directly in your own project gives you easy access, and _permission_ to make changes and see how it works.

Loading…
Cancel
Save