Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

npm start defaults don't match npm init -y defaults #10313

Closed
ashleygwilliams opened this issue Nov 8, 2015 · 5 comments
Closed

npm start defaults don't match npm init -y defaults #10313

ashleygwilliams opened this issue Nov 8, 2015 · 5 comments

Comments

@ashleygwilliams
Copy link
Contributor

npm init -y sets main as index.js in the package.json
npm start assumes a server.js

there's an implicit assumption in my head, that npm start will assume main.
these should probably tell a coherent story?

so maybe:
A. npm init -y should set main to server.js
B. npm start looks for a index.js
C. npm start looks for something by default, but will let main override it

not sure what i prefer. i usually have a server.js in the root that consumes some index.js in a src or app directory , so A matches how i dev, but i wonder if we shouldn't do some research or thinking on what we think is the most reasonable default. C is by far the best one IMO, but requires more work that touches more things.

p.s. this was discovered while working on the docs: https://github.com/npm/docs/pull/436

@othiym23
Copy link
Contributor

othiym23 commented Nov 9, 2015

A. breaks the alignment of npm init with the Node module loader (which defaults to load index.js when you require('packagename'), and is probably a nonstarter for that reason.
B. or C. are both feasible (I favor B over C, because it's simpler), but both are semver-major breaking changes. We don't know how many people are relying on this implicit behavior today, and have no way to know just by looking at the registry. So, in order to avoid breaking people's deployments, we'll need to make sure this is advertised as a breaking change. Tagging to the 4.x milestone as a result.

@othiym23 othiym23 added this to the 4.x milestone Nov 9, 2015
@othiym23
Copy link
Contributor

othiym23 commented Nov 9, 2015

Probably npm start should default to server.js, fall back to main if no server.js exists, and then fall back to index.js. I think this is still a semver-major change, though, as something that affects tools that are beyond our visibility as maintainers.

@zkat
Copy link
Contributor

zkat commented Nov 17, 2015

I feel pretty fine with the way it is right now, and it actually feels pretty good for libraries that have both an API and a server (which is more common than you'd think) -- I do think that we could definitely put more effort into making people aware of this dichotomy so they can take advantage of it more.

@zkat
Copy link
Contributor

zkat commented Nov 17, 2015

Example: kmanion/senpai#3, and I think they had a pretty good reaction to it once it was clarified.

Your strange conventions are making some sense. :)
@strand

@othiym23
Copy link
Contributor

There's a consensus about what the defaults should be, and at the same time there's very little chance that the CLI team is going to have the cycles to get to this within the next 6-12 months, so I'm going to close this for now. Anyone interested in patching this behavior (hint hint @ashleygwilliams) should be aware that the defaulting behavior that points to server.js actually lives in read-package-json (it probably shouldn't, so pulling that out would be a useful change on its own), so changing this behavior is likely to be a two-part process of patching read-package-json and then including the patched version of that in npm. Thanks for getting the ball rolling with this, @ashleygwilliams!

@iarna iarna removed this from the 4.x milestone Oct 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants