Skip to content

feat(config): auto-detect doc-kit.config.mjs in the working directory#901

Open
AysajanE wants to merge 1 commit into
nodejs:mainfrom
AysajanE:northset/M-012
Open

feat(config): auto-detect doc-kit.config.mjs in the working directory#901
AysajanE wants to merge 1 commit into
nodejs:mainfrom
AysajanE:northset/M-012

Conversation

@AysajanE

Copy link
Copy Markdown

Problem

doc-kit generate only loads configuration when --config-file is passed explicitly — loadConfigFile returns {} otherwise. As raised in #897, most config-driven tools also detect a conventional config file automatically, so a valid doc-kit.config.mjs sitting in the project root is silently ignored today. That is an easy footgun for anyone who assumes the file is picked up.

Change

  • In createRunConfiguration, when no --config-file is provided, auto-detect a doc-kit.config.mjs in the current working directory and load it through the existing loader. An explicit --config-file still takes precedence, and when no file is present the configuration falls back to empty — unchanged behavior. No new dependency; a tight happy path, as the issue suggests.
  • Add unit tests covering auto-detection, explicit-path precedence, and the no-file fallback.

Checks (Node 22)

  • node --test --experimental-test-module-mocks src/utils/configuration/__tests__/index.test.mjs — 17 passing, including the new cases.

Fixes #897


Disclosure: this change was prepared with AI assistance and reviewed by me before submitting.
I ran the check(s) above in a network-isolated container and published a signed, re-runnable
record of that run, verifiable via GitHub artifact attestation:
https://northset-oss.github.io/verification-pilot/. Contributor self-run, not a maintainer verification.

Signed-off-by: Aysajan Eziz <aeziz@northset.ai>
@AysajanE AysajanE requested a review from a team as a code owner July 12, 2026 22:22
@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview Jul 12, 2026 10:23pm

Request Review

@cursor

cursor Bot commented Jul 12, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Small, localized change to config resolution with clear precedence rules and unit tests; no auth or data-handling impact.

Overview
doc-kit generate now picks up a root doc-kit.config.mjs without --config-file. When no config path is passed, createRunConfiguration checks join(process.cwd(), 'doc-kit.config.mjs') with existsSync and loads it through the existing loadConfigFile path; an explicit --config-file still wins, and missing files keep the prior empty-config behavior.

Tests mock existsSync to cover auto-detection, explicit-path precedence (no existence check), and the no-file fallback. A patch changeset documents the behavior.

Reviewed by Cursor Bugbot for commit a0bdd2d. Bugbot is set up for automated code reviews on this repo. Configure here.

'@node-core/doc-kit': patch
---

Automatically load `doc-kit.config.mjs` from the current working directory.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:
.config.js
.config.cjs
.config.json?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

their aren't supported by the code.
IMO we should also support ts, cts, mts as types strippable code

Comment on lines 135 to +141
*/
export const createRunConfiguration = async options => {
const config = await loadConfigFile(options.configFile);
const defaultConfigFile = join(process.cwd(), 'doc-kit.config.mjs');
const configFile =
options.configFile ??
(existsSync(defaultConfigFile) ? defaultConfigFile : undefined);
const config = await loadConfigFile(configFile);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logic here is wrong you should do something like this:

resolve configuration file:

  if --config option is provided:
    use the provided file
  else:
    search for a configuration file named:
      doc-kit.config.js
      doc-kit.config.cjs
      doc-kit.config.mjs
      doc-kit.config.ts
      doc-kit.config.cts
      doc-kit.config.mts

    use the first file that exists (following a defined priority)

  pass the resolved path to loadConfigFile()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — understood. I will replace the single .mjs probe with explicit --config-file precedence followed by discovery across the six names you listed, and add coverage for every extension plus the multiple-files case. Before I update the branch, should the order in your example (.js, .cjs, .mjs, .ts, .cts, .mts) also be the precedence when more than one exists? I will leave .json out unless you want it included.

@AugustinMauroy AugustinMauroy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding blocker since feature isn't correctly covered.

thanks @AysajanE for you effort here

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

Successfully merging this pull request may close these issues.

Consideration: detect doc-kit.config.mjs automatically

3 participants