 This should be run whenever your `doom!' block, or a module autoload file, is
 modified."
   (interactive)
-  (let ((default-directory doom-emacs-dir)
-        (targets
-         (file-expand-wildcards
-          (expand-file-name "autoload/*.el" doom-core-dir))))
-    (dolist (path (doom-module-load-path))
-      (let ((auto-dir  (expand-file-name "autoload" path))
-            (auto-file (expand-file-name "autoload.el" path)))
+  (let* ((default-directory doom-emacs-dir)
+         (doom-modules (doom-modules))
+         (targets
+          (file-expand-wildcards
+           (expand-file-name "autoload/*.el" doom-core-dir)))
+         (enabled-targets (copy-sequence targets))
+         case-fold-search)
+    (dolist (path (doom-module-load-path t))
+      (let* ((auto-dir  (expand-file-name "autoload" path))
+             (auto-file (expand-file-name "autoload.el" path))
+             (module    (doom-module-from-path auto-file))
+             (module-p  (or (doom-module-p (car module) (cdr module))
+                            (file-equal-p path doom-private-dir))))
         (when (file-exists-p auto-file)
-          (push auto-file targets))
-        (when (file-directory-p auto-dir)
-          (dolist (file (doom-files-in auto-dir :match "\\.el$" :full t))
-            (push file targets)))))
+          (push auto-file targets)
+          (if module-p (push auto-file enabled-targets)))
+        (dolist (file (doom-files-in auto-dir :match "\\.el$" :full t))
+          (push file targets)
+          (if module-p (push file enabled-targets)))))
     (if (and (not force-p)
              (not doom-emacs-changed-p)
              (file-exists-p doom-autoload-file)

it exists."
  (cl-check-type file string)
  (when (file-exists-p file)
    (delete-file file)
    (ignore-errors (delete-file (byte-compile-dest-file file)))
    (message "Deleted old %s" (file-name-nondirectory file))))

                           return t))))
      (ignore (print! (green "Doom package autoloads is up-to-date"))
              (doom-initialize-autoloads doom-package-autoload-file))
    (let (case-fold-search)
      (doom-delete-autoloads-file doom-package-autoload-file)
      (with-temp-file doom-package-autoload-file
        (doom--generate-header 'doom//reload-package-autoloads)
        (save-excursion
          ;; Cache the important and expensive-to-initialize state here.
          (doom--generate-var-cache)
          (print! (green "✓ Cached package state"))
          ;; Loop through packages and concatenate all their autoloads files.
          (doom--generate-package-autoloads)
          (print! (green "✓ Package autoloads included")))
        ;; Remove `load-path' and `auto-mode-alist' modifications (most of them,
        ;; at least); they are cached later, so all those membership checks are
        ;; unnecessary overhead.
        (doom--cleanup-package-autoloads)
        (print! (green "✓ Removed load-path/auto-mode-alist entries"))))
    (doom--byte-compile-file doom-package-autoload-file)
    (when (and noninteractive (not (daemonp)))
