statusboard icon indicating copy to clipboard operation
statusboard copied to clipboard

[query] need a descendant operator that can specify type

Open lukekarrys opened this issue 2 years ago • 3 comments

Problem Statement

In the npm/cli repo the following query should return an empty set since none of the direct dependents are .dev deps:

npm query ':root > #npm-package-arg.dev'
# should also apply to this
node . query ':root > .dev > #npm-package-arg'

Current Behavior

In the current implementation both :root and .dev are collected separately so it returns:

[
  {
    "name": "npm-package-arg",
    "version": "10.1.0",
    "location": "node_modules/npm-package-arg",
    "path": "/Users/lukekarrys/projects/npm/cli/node_modules/npm-package-arg",
    "from": [
      "node_modules/init-package-json",
      "node_modules/npm-pick-manifest",
      "node_modules/npm-registry-fetch",
      "node_modules/pacote",
      "node_modules/@npmcli/template-oss",
      "mock-registry",
      "workspaces/libnpmexec",
      "workspaces/libnpmaccess",
      "workspaces/libnpmdiff",
      "workspaces/libnpmpack",
      "workspaces/libnpmpublish",
      "workspaces/arborist",
      ""
    ],
    "to": [
      "node_modules/hosted-git-info",
      "node_modules/proc-log",
      "node_modules/semver",
      "node_modules/validate-npm-package-name"
    ],
    "dev": false,
    "inBundle": true,
    "deduped": false,
    "overridden": false,
    "queryContext": {}
  }
]

Expected Behavior

It should return [] since npm-package-arg is only a direct .prod dependency

lukekarrys avatar Dec 15 '22 21:12 lukekarrys

This seems like a docs/education issue. .dev does not mean "In the devDependencies of something in the current set" it means "It is in the tree because of something in the root's devDependencies"

It seems what you are trying to query is all of the entries in devDependencies?

wraithgar avatar Jan 09 '23 16:01 wraithgar

there's some improvement to be made for the .dev selector in general i think. we don't have a way to get only direct devDependencies and we also don't have a way to get every node that exists exclusively as a devdep

wraithgar avatar Jan 09 '23 16:01 wraithgar

What we really need is a descendant operator to allow us to specify the edges out types. root > :dep(dev) would be everything in the root package's devDependencies for example

wraithgar avatar Jan 09 '23 17:01 wraithgar