-
Notifications
You must be signed in to change notification settings - Fork 238
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
RFC: npm debug
command
#618
Closed
Closed
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b284060
RFC: 'npm debug' command. Initial draft.
about-code 37f8cb9
Fix some typos. Precision.
about-code 19941ce
Precision
about-code b43a455
Wording
about-code 6680f73
Prior Art: refer to 'npx debug'
about-code 245e63e
Merge branch 'npm:main' into main
about-code a4d528f
Propose algorithms using GIVEN THEN scheme.
about-code c4bd675
Wording
about-code 7491691
fix typo.
about-code f50e78b
fix: handling of 'main' property
about-code 6ed32eb
Consider packages with a `bin` object property and multiple executables
about-code 1351331
link to spec of package.json#main
about-code 70c0a01
Clarify: what about packages with both a bin and a main that want to …
about-code File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# `npm debug` command | ||
|
||
## Summary | ||
|
||
This RFC proposes an `npm debug` command to simplify debugging npm packages. | ||
|
||
## Motivation | ||
|
||
When developing | ||
|
||
1. an executable npm package with a `bin` entry in `package.json` | ||
1. a package with a `main` entry script in `package.json` | ||
1. a tool configuration for an executable tool installed to `node_modules` | ||
1. a multi-package workspace project | ||
|
||
then without editor or IDE support there's only the `node --inspect` or `node --inspect-brk` command for starting a debug session for a JavaScript file. Since `node` has no inherent knowledge of an *npm package* its commands require typing a complete path to the JavaScript file that is meant to be debugged. | ||
|
||
## Detailed Explanation | ||
|
||
This RFC proposes an `npm debug` command to simplify debugging npm packages. | ||
|
||
## Rationale and Alternatives | ||
|
||
**Rationale:** Make debugging npm packages easier. | ||
|
||
**Alternatives:** | ||
|
||
1. `node --inspect` or `node --inspect-brk` | ||
- operates on a single JavaScript file and often requires lengthy command lines to specify the path of the target script file | ||
- can not use NPM package metadata | ||
2. editor or IDE support | ||
- requires an editor or IDE | ||
- typically requires creating or configuring a tool-specific launch configuration | ||
|
||
The `npm debug` command facilitates npm's `package.json` manifest to simplify launching a debug session for packaged JavaScripts. | ||
|
||
## Implementation | ||
|
||
When applicable an `npm debug` command should be as consistent as possible with existing commands like `npm run`, `npm exec` or `npm test` in terms of | ||
|
||
- naming of arguments the commands share, | ||
- script or package selection, | ||
- current working directory | ||
- etc. | ||
|
||
For example, it may share a similar synopsis like `npm exec`. Further to remain consistent the new command's `argv` MAY be separated from the debugged script's `script-argv` using `' -- '` (dashes enclosed in spaces). | ||
|
||
### Expected Behavior | ||
|
||
An `npm debug` command is supposed to launch a debug session which halts debugging until a remote debugger connects using `node --inspect-brk`. Subject to discussion, the following algorithms are being proposed when `npm debug` is *issued within a package directory*. Each step is supposed to be applied in the order given until `END.`. | ||
|
||
*Algorithm 1* | ||
|
||
~~~ | ||
npm debug | ||
~~~ | ||
|
||
1. GIVEN a `script.debug` property is present in `package.json` | ||
- THEN run the run-script similar to how `npm start` would run `script.start`. END. | ||
- ELSE continue | ||
1. GIVEN a `bin` property is present in `package.json` | ||
- THEN launch a debug session for the script referred to by the `bin` property using `node --inspect-brk <bin-script> <script-argv>`. END. | ||
- ELSE continue | ||
1. GIVEN a `main` property is present in `package.json` | ||
- THEN launch a debug session for the script referred to by the `main` property using `node --inspect-brk <main-script> <script-argv>`. END. | ||
- ELSE continue | ||
1. EXIT with an `npm ERR!`. END. | ||
|
||
*Algorithm 2* | ||
|
||
~~~ | ||
npm debug <package> | ||
~~~ | ||
|
||
1. GIVEN a search in all `workspaces` finds a target package `<package>` | ||
- THEN apply *Algorithm 1* with the target package's `package.json`. END. | ||
- ELSE continue | ||
1. GIVEN a non-recursive search in `node_modules` finds a target package `<package>` | ||
- THEN apply *Algorithm 1* with the target package's `package.json`. END. | ||
- ELSE continue | ||
1. EXIT with an `npm ERR!`. END. | ||
|
||
*Algorithm 3* | ||
|
||
~~~ | ||
npm debug <package> --workspaces | ||
~~~ | ||
|
||
1. GIVEN a search in `workspaces`, only, finds a target package `<package>` | ||
- THEN apply *Algorithm 1* with the target package's `package.json`. END. | ||
- ELSE continue | ||
1. EXIT with an `npm ERR!`. END. | ||
|
||
*Algorithm 4* | ||
|
||
~~~ | ||
npm debug <package> --workspace=X | ||
~~~ | ||
|
||
1. GIVEN a search in workspace `X`, only, finds a package `<package>` | ||
- THEN apply *Algorithm 1* with the target package's `package.json`. END. | ||
- ELSE continue | ||
1. EXIT with an `npm ERR!`. END. | ||
|
||
## Prior Art | ||
|
||
There are other development lifecycle commands like | ||
|
||
- `npm start` | ||
- `npm test` | ||
- `npm publish` | ||
- `npm run` | ||
|
||
but none for debugging in particular. | ||
|
||
- `npx debug` would install [debug](https://npmjs.com/package/debug). Though, that package focuses on entering/providing a "debug mode" for scripts that may be run with node but not within a node debugger session. | ||
|
||
## Unresolved Questions and Bikeshedding | ||
|
||
- Do proposed algorithms assist in implementing the RFC? Or should they be discussed separately within an issue? After all consistency with `npm run` or `npm exec` are more important than following any of the proposed algorithms, strictly. | ||
- Include searching `workspaces` before `node_modules` in Algorithm 2 when no `--workspaces` argument is given? |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about packages with both a bin and a main that want to debug both?
(i realize it's a bad practice now to have both in the same package, but there's lots of older packages that do)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the following options:
bin
. Require a--main
switch to allow for debuggingmain
.main
. Require a--bin
switch to allow for debuggingbin
.--main
or--bin
argument innpm debug
sargv
Consequences
--main
and--bin
argument, since a--bin
argument seems to be necessary for the case of multiplebin
executables, anyways.--main
argument and just require a--bin
CLI argument. The latter seems to be necessary for the case of multiple executables (update on this, follows)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update 70c0a01 decides for 1 and would allow users to be explicit about whether to debug
main
orbin
.Given they provided both
--bin
and--main
or none at all then--bin
would take precedence:... executes a packages
bin
script if apackage.json
has abin
and amain
script.