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

[FEATURE] Install a package as a sole project #1578

Closed
jfoclpf opened this issue Jul 29, 2020 · 19 comments
Closed

[FEATURE] Install a package as a sole project #1578

jfoclpf opened this issue Jul 29, 2020 · 19 comments
Labels
Enhancement new feature or improvement Release 6.x work is associated with a specific npm 6 release

Comments

@jfoclpf
Copy link

jfoclpf commented Jul 29, 2020

What / Why

Imagine you have a big project with a lot of npm dependencies, but which is not supposed to have dependants, that is, a sole single project from which no other packages are supposed to depend on. An exemple is the npm package autocosts, 54 dependencies and 0 dependants.

When I install this package on a new machine or newly created directory, the file/directory structure becomes:

package-lock.json
node_modules/
 autocosts/
   node_modules/

When

When I run npm install <package> on an empty directory or a new machine

How

Current Behavior

It makes this folder/file structure with no package.json for the current package

package-lock.json
node_modules/
 autocosts/
   node_modules/

Then if I want to start the server npm start an error occurs, that is, the command npm i autocosts && npm start does not work

Expected Behavior

The folder structure should just be with an extra option npm i autocosts --sole

(files of package)
package.json
package-lock.json
node_modules/
other_dirs/

Basically I'm requesting an extra option to make it possible to install everything directly in the current directory

@ljharb
Copy link
Contributor

ljharb commented Jul 29, 2020

npm start is a development script - you're only supposed to run that when developing a project, which usually means you've git cloned it. npm install is for dependencies - something you run or require, but not something you run scripts in.

@ljharb
Copy link
Contributor

ljharb commented Jul 29, 2020

iow, that particular package does not have correct instructions; "apps" (like that one) should not be installed in this way unless they provide a binary; the proper instructions would be to tell people to clone the repo.

@jfoclpf
Copy link
Author

jfoclpf commented Jul 29, 2020 via email

@ljharb
Copy link
Contributor

ljharb commented Jul 29, 2020

Step 1: clone the repo
Step 2: npm install
Step 3: npm start.

That's the way it's usually done as far as I'm aware.

@jfoclpf
Copy link
Author

jfoclpf commented Jul 29, 2020

In that case I'd rather have
Step 1: npm install package
Step 2: cd node_modules/package
Step 3: npm start

Less programs to run. Furthermore in theory it's possible to have npm packages with no github projects attached

@ljharb
Copy link
Contributor

ljharb commented Jul 29, 2020

Sure, it's possible, but it's a very unidiomatic way to use npm, and cding into node_modules - what should be a black box - is not a good practice.

@jfoclpf
Copy link
Author

jfoclpf commented Jul 29, 2020

Wouldn't be simpler to have an extra option?

Step 1: npm install package --{app|sole}
Step 3: npm start

If the npm repository has already all the files I need, why do I need to fetch them in github?

@ljharb
Copy link
Contributor

ljharb commented Jul 29, 2020

Because npm start is for an app - which needs dev deps. If you want a runnable binary, use "bin" and not "start".

@jfoclpf
Copy link
Author

jfoclpf commented Jul 30, 2020 via email

@jfoclpf
Copy link
Author

jfoclpf commented Jul 30, 2020

Step 1: clone the repo
Step 2: npm install
Step 3: npm start.

That's the way it's usually done as far as I'm aware.

Why should I fetch files from two different places?

@ljharb
Copy link
Contributor

ljharb commented Jul 30, 2020

"an app which needs to start a server" works just fine as a binary.

@jfoclpf
Copy link
Author

jfoclpf commented Jul 30, 2020 via email

@ljharb
Copy link
Contributor

ljharb commented Jul 30, 2020

You put it anywhere you want, as long as "bin" in package.json points to it.

By "binary" i don't mean a binary file, i just mean an executable node JS file. So, whatever your node script does, that's what your "binary" would do.

@jfoclpf
Copy link
Author

jfoclpf commented Aug 10, 2020

Hi @ljharb
I was checking the bin option in package.json and I still don't get how that can solve my problem. Such bin will be put in the folder node_modules/.bin/ but when the user installs the package from scratch by doing npm i autocosts, he has no access to the bins.

Therefore the question remains: how does a user install a sole npm project (i.e. with dependencies but no dependants) on a new machine or an empty directory, without the need to fetch the files from github since they are already in the npm repository?

@jfoclpf
Copy link
Author

jfoclpf commented Aug 10, 2020

@ljharb I updated my request
#1578 (comment)

@jfoclpf
Copy link
Author

jfoclpf commented Aug 10, 2020

@ljharb
it's not the option I like the most, thus I requested this feature, but eventually I used your initial suggestion:
https://github.com/jfoclpf/autocosts#try-it-on-your-machine

Thanks anyway

@ljharb
Copy link
Contributor

ljharb commented Aug 10, 2020

The user would invoke your package in either npx or an npm run-script.

@jfoclpf
Copy link
Author

jfoclpf commented Aug 10, 2020 via email

@darcyclarke darcyclarke added Enhancement new feature or improvement Release 6.x work is associated with a specific npm 6 release labels Oct 30, 2020
@darcyclarke
Copy link
Contributor

npm v6 is no longer in active development; We will continue to push security releases to v6 at our team's discretion as-per our Support Policy.

If your bug is preproducible on v7, please re-file this issue using our new issue template.

If your issue was a feature request, please consider opening a new RRFC or RFC. If your issue was a question or other idea that was not CLI-specific, consider opening a discussion on our feedback repo

Closing: This is an automated message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement new feature or improvement Release 6.x work is associated with a specific npm 6 release
Projects
None yet
Development

No branches or pull requests

3 participants