Skip to content
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

Extending an existing configuration (NPM, Node debugging) #184

Open
MinallW opened this issue Dec 18, 2024 · 1 comment
Open

Extending an existing configuration (NPM, Node debugging) #184

MinallW opened this issue Dec 18, 2024 · 1 comment

Comments

@MinallW
Copy link

MinallW commented Dec 18, 2024

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.

@svaante
Copy link
Owner

svaante commented Dec 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants