atom-node-debugger icon indicating copy to clipboard operation
atom-node-debugger copied to clipboard

Use package.json 's main file instead of current opened file

Open dotlouis opened this issue 8 years ago • 8 comments

Hi, I just discovered this package and although nodeJs debuggers are at the beginning, I think this one is pretty cool.

Anyway I usually run the same file (server.js) over and over again so it would be cool to be able to specify it somewhere so I don't have to open said file each time I run the debugger.

Just a quick thought: You could not simply add a package setting for it, because the default file would likely change between projects. So maybe you could use the package.json 's main property to figure out the main file. Cheers.

dotlouis avatar Nov 25 '15 17:11 dotlouis

Hi,

Thanks for your feedback. I like the idea but how to find the right package.json?

codecontemplator avatar Nov 26 '15 19:11 codecontemplator

Well, I'm not sure I understand the question. There is usually only one package.json in the top level directory. if you excludes node_modules/ and bower_components/ you should probably find the right one pretty easily.

However another probleme arises if the project doesn't have a main property (not likely) or no package.json (even less so). What you could do is add a command (via the command palette) to execute the last debugged file.

dotlouis avatar Nov 27 '15 11:11 dotlouis

Thanks for the idea, although many packages like browserify and some other packages which related to "build the project" to tell the "builder" how to process the project files, I still don't quite sure that adding the debugging options to "package.json" is a really good idea. Few things cross over my mind are:

  1. the option for the atom-node-debugger is too atom/debugger specific.
  2. debugging is not related to the "build" project.
  3. Not everyone using the same options in the debugger, and the debugging configurations shouldn't checkin to the repos

Don't know if these points make sense :)

kiddkai avatar Nov 27 '15 11:11 kiddkai

In a package.json file, the main property points to the application's entry point. So, when working on a module, this is what you get when you require() this module. And for standalone applications (i.e. Express-based apps), this usually points to the file which actually starts the whole server.

In both cases, this is where you want to start when initiating a debugging session.

Finding the package.json file should be pretty easy - it should reside in the currently open project's root (I am sure Atom has an API for obtaining this path).

What's even more interesting, if the package.json contains a main property, you can start the server/module by simply doing:

node --debug .

And Node will figure out the entry point itself (assuming that package.json is located in current working directory).

Edge cases

  • If there's no main property, Node will try to start with index.js. If that does not exist, it will bail out. Not sure what we should do here in this case, maybe just fall back to current behaviour.
  • If there's no package.json file, you can fall back to current behaviour.

robertrossmann avatar Nov 27 '15 22:11 robertrossmann

@kiddkai I think you are right in general concerning storage of debug options. The atom project-manager package improves the project support for atom so that a project can store custom options. This would be a nice way to store debug options but I am not convinced that it is worth taking that dependency,

However, digging up the startup file from the package.json could be be viewed as just a way to find a good default like @Alaneor suggests (I think).

Does this make sense?

codecontemplator avatar Nov 30 '15 21:11 codecontemplator

atom supports multiple root folders, so how would you know which opened source folder to look in?

petemill avatar Apr 02 '16 23:04 petemill

Good point. Some ideas:

  • Ask - load up all the package.json files from opened folders and present a dialog box to ask the user which project to debug
  • Default to first folder in the list

robertrossmann avatar Apr 02 '16 23:04 robertrossmann

Personally, I often work with multiple folders as separate components of a platform. Each is an individual app that I need to run as part of the platform. I would want to be able to run / debug / attach to any of these at any given time. Ideally, atom-node-debugger would know about them all, and how to attach to each one.

petemill avatar Apr 02 '16 23:04 petemill