dape icon indicating copy to clipboard operation
dape copied to clipboard

Extending an existing configuration (NPM, Node debugging)

Open MinallW opened this issue 1 year ago • 1 comments

Hello Dape Team!,

I'm using dape for NodeJS backend service debugging, it works flawlessly. These two commands work for me:

js-debug-node :cwd "~/Projects/accounting-service/" - dist/app/index.js

Which I used previously, but I would have the build the program so that the index.js in dist would be with the latest code, so I moved to using a different method with NPM:

js-debug-node :cwd "~/Projects/accounting-service/" :runtimeArgs ["run-script" "start"] :runtimeExecutable "npm"

So, as to save this configuration as mine and have it available, I'm copying the same commands that are defined in js-debug-node from dape-configs. Which is like this:

   ...
    ,@(let ((js-debug
             `( ensure ,(lambda (config)
                          (dape-ensure-command config)
                          (when-let ((runtime-executable
                                      (dape-config-get config :runtimeExecutable)))
                            (dape--ensure-executable runtime-executable))
                          (let ((dap-debug-server-path
                                 (car (plist-get config 'command-args))))
                            (unless (file-exists-p dap-debug-server-path)
                              (user-error "File %S does not exist" dap-debug-server-path))))
                command "node"
                command-args (,(expand-file-name
                                (file-name-concat dape-adapter-dir
                                                  "js-debug"
                                                  "src"
                                                  "dapDebugServer.js"))
                              :autoport)
                port :autoport)))
        `((js-debug-node
           modes (js-mode js-ts-mode)
           ,@js-debug
           :type "pwa-node"
           :cwd dape-cwd
           :program dape-buffer-default
           :console "internalConsole")

So, I'm writing my config like this:

(use-package dape
   :config
  (setq dape-buffer-window-arrangement 'right)
  (add-hook 'dape-compile-hook 'kill-buffer)
  (add-hook 'dape-display-source-hook 'pulse-momentary-highlight-one-line)
  (add-to-list 'dape-configs
  `(moveecar-service-debug
    modes (js-ts-mode typescript-ts-mode)
    :command "node"
    :command-args '("js-debug" "src" "dapDebugServer.js")
    :type "pwa-node"
    :cwd dape-cwd
    :runtimeExecutable "npm"
    :runtimeArgs ["run-script" "start"]
    :program dape-buffer-default
    :console "internalConsole"
    :command-env (APP_ENV "dev/something-dev" IS_MM_SERVER "true"))))

Now, when I call moveecar-service-debug as a config template, it errors with  Wrong type argument: stringp, nil. I'm not sure how I should extend a configuration that does work.

MinallW avatar Dec 18 '24 14:12 MinallW

Hey!

Dape fails to start the adapter because it looks for command rather then :command.

Wrong type argument: stringp, nil is an terrible error message, I'll see if I can do something about it.

(add-to-list 'dape-configs
             `(moveecar-service-debug
               modes (js-mode js-ts-mode typescript-ts-mode)
               command "node"
               command-args (,(expand-file-name
                               (file-name-concat dape-adapter-dir
                                                 "js-debug"
                                                 "src"
                                                 "dapDebugServer.js")))
               :type "pwa-node"
               :cwd dape-cwd
               :runtimeExecutable "npm"
               :runtimeArgs ["run-script" "start"]
               :program dape-buffer-default
               :console "internalConsole"
               :env (:APP_ENV "dev/something-dev" :IS_MM_SERVER "true")))

The command and command-args need to be a non keyword symbols (should not begin with :).

The following is a bit shorter, by reusing js-debug-node.

(add-to-list 'dape-configs
             `(moveecar-service-debug
               modes (js-ts-mode typescript-ts-mode)
               ,@(alist-get 'js-debug-node dape-configs)
               :runtimeExecutable "npm"
               :runtimeArgs ["run-script" "start"]
               :env (:APP_ENV "dev/something-dev" :IS_MM_SERVER "true")))

Another way is to use dape-command (see M-x describe-variable dape-command), where we can add (js-debug-node :cwd "~/Projects/accounting-service/" :runtimeArgs ["run-script" "start"] :runtimeExecutable "npm") as a dir local variable with add-dir-local-variable.

svaante avatar Dec 23 '24 22:12 svaante

Thanks!

MinallW avatar May 12 '25 13:05 MinallW