Repository navigation
feat: support npm specifiers in extends - #1332
Merged
Merged
Conversation
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
…running an executable in place
…ct circular extends
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds support for
npm:specifiers inextends, the same aspluginshas.{ "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
npm:name): looks the package up innode_moduleswalking up from the extending config file's directory. The result is a local file, so this is the same as extendingnode_modules/name/file.jsonby path today.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 itsincludesand non-Wasm plugins are ignored."."entry in the package.json'sexports, the package.json'smainwhen it's a JSON file, or adprint.json/dprint.jsoncat the package root.npm:name/markdown): looked up in the package.json'sexports, otherwise it's the path of a file in the package. For conditional exports thedprintanddefaultconditions are matched; a target outside adprintcondition is only used when it's a.json/.jsoncfile.npm:specifiers, and http(s) URLs. It can't extend~/,file:, or absolute paths, nor paths that leave the package..npmrcandnode_moduleslookups.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'splugin.jsonreferences.name@versionalready in the npm cache is reused without any network requests, and is only downloaded once per process when several plugins orextendsentries need it at the same time..dprint-npm-meta.jsonfile 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 orplugin.jsonis verified against it. A directory without one (ex. from an older dprint) is downloaded again.@scope/name@versioninstead of@scope__name@version, and a registry at a path on its host gets its own directory.forgetalso removes the per-platform package a process plugin runs from.Other changes
extendsentries of a config are fetched in parallel, then merged in order..npmrc, npm package and package.json once no matter how manynpm:extends use it.extendsnow error (ex.Circular extends detected: /a.json -> /b.json -> /a.json) instead of looping forever. This applies to every kind ofextends, not only npm.exportsresolution follows subpath patterns (ex."./*": "./configs/*.json") andnulltargets.: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.0o755.Not included
extends(the other half of the issue).extendsnpm specifiers (they error)../plugin.wasm) in a config file from a registry package still error.Closes #1284