Skip to content

feat: support npm specifiers in extends - #1332

Merged
dsherret merged 13 commits into
mainfrom
feat/npm-extends
Oct 10, 2026
Merged

dsherret merged 13 commits into
mainfrom
feat/npm-extends

Conversation

@dsherret

@dsherret dsherret commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Adds support for npm: specifiers in extends, the same as plugins has.

{
  "extends": [
    // resolved from node_modules
    "npm:@scope/dprint-config",
    "npm:@scope/dprint-config/markdown",
    // downloaded from the npm registry
    "npm:@scope/[email protected]",
    "npm:@scope/[email protected]/markdown"
  ]
}

Behavior

  • No version (npm:name): looks the package up in node_modules walking up from the extending config file's directory. The result is a local file, so this is the same as extending node_modules/name/file.json by path today.
  • Exact version (npm:[email protected]): downloads the package from the npm registry into the existing npm cache directory (shared with npm plugins, honoring .npmrc/NPM_CONFIG_REGISTRY). Cached packages are used without any network requests. This is remote configuration, so its includes and non-Wasm plugins are ignored.
  • Main configuration file (no path): the first of the "." entry in the package.json's exports, the package.json's main when it's a JSON file, or a dprint.json/dprint.jsonc at the package root.
  • Sub path (npm:name/markdown): looked up in the package.json's exports, otherwise it's the path of a file in the package. For conditional exports the dprint and default conditions are matched; a target outside a dprint condition is only used when it's a .json/.jsonc file.
  • A config file from a registry package can extend other files in the package by relative path, other versioned npm: specifiers, and http(s) URLs. It can't extend ~/, file:, or absolute paths, nor paths that leave the package.
  • npm plugins listed in a registry config use the extending project's directory for .npmrc and node_modules lookups.

npm cache changes

All npm registry packages now go through one function (ensure_npm_package_extracted): plugin packages, extended config packages, and the per-platform package a process plugin's plugin.json references.

  • A name@version already in the npm cache is reused without any network requests, and is only downloaded once per process when several plugins or extends entries need it at the same time.
  • The tarball's checksum is recorded in a .dprint-npm-meta.json file inside the package's directory. It's written before the directory is renamed into place, so a directory and its checksum always appear together. A checksum in a plugin specifier or plugin.json is verified against it. A directory without one (ex. from an older dprint) is downloaded again.
  • A package that fails a checksum is removed from the cache so it's downloaded again next time.
  • A process plugin's per-platform executable is run in place from the npm cache instead of being unpacked into the plugin's own cache directory. The plugin cache metadata records the package's expected checksum and it's compared against the directory's on every cache hit, since the directory is shared.
  • Scoped packages are stored at @scope/name@version instead of @scope__name@version, and a registry at a path on its host gets its own directory.
  • forget also removes the per-platform package a process plugin runs from.

Other changes

  • The extends entries of a config are fetched in parallel, then merged in order.
  • Resolving a config reads each .npmrc, npm package and package.json once no matter how many npm: extends use it.
  • Circular extends now error (ex. Circular extends detected: /a.json -> /b.json -> /a.json) instead of looping forever. This applies to every kind of extends, not only npm.
  • exports resolution follows subpath patterns (ex. "./*": "./configs/*.json") and null targets.
  • npm specifiers reject : in the package name and sub path and a trailing . in the version. On Windows these replaced or aliased the directory they were joined to. This applies to npm plugin specifiers too.
  • Unix permission bits from a tarball are masked to 0o755.

Not included

  • Glob support in extends (the other half of the issue).
  • Checksums on extends npm specifiers (they error).
  • Relative plugin paths (ex. ./plugin.wasm) in a config file from a registry package still error.

Closes #1284

Allows extending configuration files published in an npm package:

- `npm:name` and `npm:name/sub/path` resolve from node_modules
- `npm:[email protected]` and `npm:[email protected]/sub/path` download the package
  from the npm registry and are treated as remote configuration

The file is found via the `exports` or `main` of the package's
package.json, or a dprint.json at the root of the package.

Closes #1284
@dsherret
dsherret merged commit 1c50e1c into main Oct 10, 2026
22 checks passed
@dsherret
dsherret deleted the feat/npm-extends branch October 10, 2026 23:32
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.

Make extends nicer to use

1 participant