Browse Source

Merge branch 'nodejs-program-args' of nico/Indium into master

master
Nicolas Petton 9 months ago
committed by Gitea
parent
commit
59f12cb1bc
5 changed files with 49 additions and 105 deletions
  1. +14
    -78
      doc/Indium.texi
  2. +9
    -2
      doc/Makefile
  3. +9
    -13
      indium-nodejs.el
  4. +8
    -4
      sphinx-doc/setup.rst
  5. +9
    -8
      test/unit/indium-nodejs-test.el

+ 14
- 78
doc/Indium.texi View File

@@ -3,7 +3,7 @@
@setfilename Indium.info
@documentencoding UTF-8
@ifinfo
@*Generated by Sphinx 1.8.4.@*
@*Generated by Sphinx 2.1.2.@*
@end ifinfo
@settitle Indium Documentation
@defindex ge
@@ -21,7 +21,7 @@

@copying
@quotation
Indium 2.1.4, Oct 22, 2019
Indium 2.1.4, Jan 16, 2020

Nicolas Petton

@@ -366,9 +366,13 @@ Example configuration:
@subsection NodeJS configuration options


@*command:
Nodejs command to start a new process. The @code{--inspect} flag will be
added automatically.
@*program:
Nodejs program to start a new process. The @code{--inspect} flag will be
added automatically. Expected type: string.


@*args:
Arguments passed to the program to debug. Expected type: string.


@*inspect-brk:
@@ -392,7 +396,8 @@ Here is an example configuration for debugging Gulp tasks:
@{
"name": "Gulp",
"type": "node",
"command": "node ./node_modules/gulp/bin/gulp.js",
"program": "node",
"args": "./node_modules/gulp/bin/gulp.js",
"inspect-brk": true
@}
]
@@ -491,7 +496,7 @@ instance, and the @code{remote-debugging-port} will not be set.
A REPL (Read Eval Print Loop) buffer is automatically open when a new Indium
connection is made (see @ref{d,,Getting up and running}).

@image{repl,,,,png}
@image{Indium-figures/repl,,,,png}

The REPL offers the following features:

@@ -511,7 +516,7 @@ Pretty printing and preview of printed values
Access to the object inspector (see @ref{20,,The inspector})
@end itemize

@image{repl2,,,,png}
@image{Indium-figures/repl2,,,,png}

@node Using the REPL,Code evaluation & context,Starting a REPL,The REPL
@anchor{repl using-the-repl}@anchor{21}
@@ -531,75 +536,6 @@ Access to the object inspector (see @ref{20,,The inspector})

Here is the list of available keybindings in a REPL buffer:


@multitable {xxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
@headitem

Keybinding

@tab

Description

@item

@code{RET}

@tab

Evaluate the current input. When the point is on a printed object, inspect the object.

@item

@code{C-RET}

@tab

Insert a newline.

@item

@code{C-c M-i}

@tab

Evaluate the current input and open an inspector on the result.

@item

@code{C-c C-o}

@tab

Clear the output.

@item

@code{C-c C-q}

@tab

Kill the REPL buffer and close the current connection.

@item

@code{M-n}

@tab

Insert the previous input in the history.

@item

@code{M-p}

@tab

Insert the next input in the history.

@end multitable


@node Reconnecting from the REPL buffer,,Keybindings,Using the REPL
@anchor{repl reconnecting-from-the-repl-buffer}@anchor{23}
@subsubsection Reconnecting from the REPL buffer
@@ -856,7 +792,7 @@ To inspect the result of the evaluation of an expression, press @code{C-c M-i}.
inspector buffer will pop up. You can also press @code{RET} or left click on
object links from the REPL buffer.

@image{inspector,,,,png}
@image{Indium-figures/inspector,,,,png}

@menu
* Using the inspector::


+ 9
- 2
doc/Makefile View File

@@ -18,13 +18,20 @@ pdf: $(addsuffix .pdf,$(ALLDOCS))

install-info: info
for f in *.info; do \
cp -t $(infodir) "$$f" && \
$(INSTALL_INFO) --info-dir=$(infodir) "$$f" ; \
mkdir -p $(infodir) && \
cp "$$f" $(infodir) && \
$(INSTALL_INFO) --info-dir=$(infodir) "$$f" && \
\
FIGURE_DIR="`basename \"$$f\" .info`-figures" && \
if [ -e "$$FIGURE_DIR" ]; then \
cp -r "$$FIGURE_DIR" $(infodir) ; \
fi; \
done

uninstall-info: info
for f in *.info; do \
rm -f "$(infodir)/$$f" ; \
rm -rf "$(infodir)/`basename '$$f' .info`-figures" && \
$(INSTALL_INFO) --delete --info-dir=$(infodir) "$$f" ; \
done



+ 9
- 13
indium-nodejs.el View File

@@ -46,12 +46,13 @@ it.
If the configuration setting `inspect-brk' is non-nil, break the
execution at the first statement."
(let-alist conf
(unless .command
(user-error "No NodeJS command specified in the .indium.json file"))
(unless .program
(user-error "No NodeJS program specified in the .indium.json file"))
(let* ((default-directory .resolvedRoot)
(filter (indium-nodejs--process-filter-function conf))
(command-with-flags (indium-nodejs--command-with-flags
.command
.program
.args
.inspect-brk
.port))
(process (make-process :name "indium-nodejs-process"
@@ -64,8 +65,10 @@ execution at the first statement."
(switch-to-buffer (process-buffer process)))))

(defun indium-nodejs--command-with-flags (command inspect-brk &optional port)
"Return COMMAND with flags to start the V8 inspector.
(defun indium-nodejs--command-with-flags (program args inspect-brk &optional port)
"Return a command string with flags to start the V8 inspector.

PROGRAM is the executable to run, with ARGS being the passed to the program.

If INSPECT-BRK is nil, use the `--inspect', use the
`--inspect-brk' flag otherwise.
@@ -74,14 +77,7 @@ If PORT is non-nil, start the debugging process on that port,
otherwise use Node's default port (9229)."
(let ((inspect-flag (if (eq inspect-brk t) " --inspect-brk" " --inspect"))
(inspect-port-flag (if port (format " --inspect-port=%s" port) "")))
(save-match-data
(if (string-match "\\<\\(babel-\\)?node\\>" command)
(replace-match (format "%s%s%s"
(match-string 0 command)
inspect-flag
inspect-port-flag)
nil nil command)
(user-error "Invalid command specified")))))
(format "%s%s%s %s" program inspect-flag inspect-port-flag args)))

(defun indium-nodejs--process-filter-function (conf)
"Return a process filter function for CONF.


+ 8
- 4
sphinx-doc/setup.rst View File

@@ -80,9 +80,12 @@ Example configuration::
NodeJS configuration options
----------------------------

:command:
Nodejs command to start a new process. The ``--inspect`` flag will be
added automatically.
:program:
Nodejs program to start a new process. The ``--inspect`` flag will be
added automatically. Expected type: string.

:args:
Arguments passed to the program to debug. Expected type: string.
:inspect-brk:
Whether Indium should break at the first statement (false by
@@ -101,7 +104,8 @@ Here is an example configuration for debugging Gulp tasks::
{
"name": "Gulp",
"type": "node",
"command": "node ./node_modules/gulp/bin/gulp.js",
"program": "node",
"args": "./node_modules/gulp/bin/gulp.js",
"inspect-brk": true
}
]


+ 9
- 8
test/unit/indium-nodejs-test.el View File

@@ -37,28 +37,29 @@
(spy-on #'indium-nodejs--command-with-flags)

(with-js2-file
(indium-launch-nodejs '((command . "node index.js")
(indium-launch-nodejs '((program . "node")
(args . "index.js")
(inspect-brk . t))))
(expect #'indium-nodejs--command-with-flags
:to-have-been-called-with "node index.js" t nil))
:to-have-been-called-with "node" "index.js" t nil))

(it "should append extra flags"
(expect (indium-nodejs--command-with-flags "node foo" nil)
(expect (indium-nodejs--command-with-flags "node" "foo" nil)
:to-equal "node --inspect foo")
(expect (indium-nodejs--command-with-flags "node foo" t)
(expect (indium-nodejs--command-with-flags "node" "foo" t)
:to-equal "node --inspect-brk foo")
;; Regression for GitHub issue #150
(expect (indium-nodejs--command-with-flags "ENV_VAR=\"VAL\" node foo" t)
(expect (indium-nodejs--command-with-flags "ENV_VAR=\"VAL\" node" "foo" t)
:to-equal "ENV_VAR=\"VAL\" node --inspect-brk foo"))

(it "should append extra the debugging port flag"
(expect (indium-nodejs--command-with-flags "node foo" nil 2000)
(expect (indium-nodejs--command-with-flags "node" "foo" nil 2000)
:to-equal "node --inspect --inspect-port=2000 foo")
(expect (indium-nodejs--command-with-flags "node foo" t 2000)
(expect (indium-nodejs--command-with-flags "node" "foo" t 2000)
:to-equal "node --inspect-brk --inspect-port=2000 foo"))

(it "should be able to launch with `babel-node'"
(expect (indium-nodejs--command-with-flags "babel-node foo" nil 2000)
(expect (indium-nodejs--command-with-flags "babel-node" "foo" nil 2000)
:to-equal "babel-node --inspect --inspect-port=2000 foo")))

(provide 'indium-nodejs-test)


Loading…
Cancel
Save