@npmcli/arborist 5.6.1 → 5.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,23 +5,24 @@ const localeCompare = require('@isaacs/string-locale-compare')('en')
5
5
 
6
6
  const add = ({ pkg, add, saveBundle, saveType }) => {
7
7
  for (const { name, rawSpec } of add) {
8
+ let addSaveType = saveType
8
9
  // if the user does not give us a type, we infer which type(s)
9
10
  // to keep based on the same order of priority we do when
10
11
  // building the tree as defined in the _loadDeps method of
11
12
  // the node class.
12
- if (!saveType) {
13
- saveType = inferSaveType(pkg, name)
13
+ if (!addSaveType) {
14
+ addSaveType = inferSaveType(pkg, name)
14
15
  }
15
16
 
16
- if (saveType === 'prod') {
17
+ if (addSaveType === 'prod') {
17
18
  // a production dependency can only exist as production (rpj ensures it
18
19
  // doesn't coexist w/ optional)
19
20
  deleteSubKey(pkg, 'devDependencies', name, 'dependencies')
20
21
  deleteSubKey(pkg, 'peerDependencies', name, 'dependencies')
21
- } else if (saveType === 'dev') {
22
+ } else if (addSaveType === 'dev') {
22
23
  // a dev dependency may co-exist as peer, or optional, but not production
23
24
  deleteSubKey(pkg, 'dependencies', name, 'devDependencies')
24
- } else if (saveType === 'optional') {
25
+ } else if (addSaveType === 'optional') {
25
26
  // an optional dependency may co-exist as dev (rpj ensures it doesn't
26
27
  // coexist w/ prod)
27
28
  deleteSubKey(pkg, 'peerDependencies', name, 'optionalDependencies')
@@ -31,23 +32,23 @@ const add = ({ pkg, add, saveBundle, saveType }) => {
31
32
  deleteSubKey(pkg, 'optionalDependencies', name, 'peerDependencies')
32
33
  }
33
34
 
34
- const depType = saveTypeMap.get(saveType)
35
+ const depType = saveTypeMap.get(addSaveType)
35
36
 
36
37
  pkg[depType] = pkg[depType] || {}
37
38
  if (rawSpec !== '' || pkg[depType][name] === undefined) {
38
39
  pkg[depType][name] = rawSpec || '*'
39
40
  }
40
- if (saveType === 'optional') {
41
+ if (addSaveType === 'optional') {
41
42
  // Affordance for previous npm versions that require this behaviour
42
43
  pkg.dependencies = pkg.dependencies || {}
43
44
  pkg.dependencies[name] = pkg.optionalDependencies[name]
44
45
  }
45
46
 
46
- if (saveType === 'peer' || saveType === 'peerOptional') {
47
+ if (addSaveType === 'peer' || addSaveType === 'peerOptional') {
47
48
  const pdm = pkg.peerDependenciesMeta || {}
48
- if (saveType === 'peer' && pdm[name] && pdm[name].optional) {
49
+ if (addSaveType === 'peer' && pdm[name] && pdm[name].optional) {
49
50
  pdm[name].optional = false
50
- } else if (saveType === 'peerOptional') {
51
+ } else if (addSaveType === 'peerOptional') {
51
52
  pdm[name] = pdm[name] || {}
52
53
  pdm[name].optional = true
53
54
  pkg.peerDependenciesMeta = pdm
@@ -59,7 +60,7 @@ const add = ({ pkg, add, saveBundle, saveType }) => {
59
60
  }
60
61
  }
61
62
 
62
- if (saveBundle && saveType !== 'peer' && saveType !== 'peerOptional') {
63
+ if (saveBundle && addSaveType !== 'peer' && addSaveType !== 'peerOptional') {
63
64
  // keep it sorted, keep it unique
64
65
  const bd = new Set(pkg.bundleDependencies || [])
65
66
  bd.add(name)
@@ -9,6 +9,7 @@ const semver = require('semver')
9
9
  const debug = require('../debug.js')
10
10
  const walkUp = require('walk-up-path')
11
11
  const log = require('proc-log')
12
+ const hgi = require('hosted-git-info')
12
13
 
13
14
  const { dirname, resolve, relative } = require('path')
14
15
  const { depth: dfwalk } = require('treeverse')
@@ -638,10 +639,15 @@ module.exports = cls => class Reifier extends cls {
638
639
  // and no 'bundled: true' setting.
639
640
  // Do the best with what we have, or else remove it from the tree
640
641
  // entirely, since we can't possibly reify it.
641
- const res = node.resolved ? `${node.name}@${this[_registryResolved](node.resolved)}`
642
- : node.packageName && node.version
643
- ? `${node.packageName}@${node.version}`
644
- : null
642
+ let res = null
643
+ if (node.resolved) {
644
+ const registryResolved = this[_registryResolved](node.resolved)
645
+ if (registryResolved) {
646
+ res = `${node.name}@${registryResolved}`
647
+ }
648
+ } else if (node.packageName && node.version) {
649
+ res = `${node.packageName}@${node.version}`
650
+ }
645
651
 
646
652
  // no idea what this thing is. remove it from the tree.
647
653
  if (!res) {
@@ -718,12 +724,20 @@ module.exports = cls => class Reifier extends cls {
718
724
  // ${REGISTRY} or something. This has to be threaded through the
719
725
  // Shrinkwrap and Node classes carefully, so for now, just treat
720
726
  // the default reg as the magical animal that it has been.
721
- const resolvedURL = new URL(resolved)
727
+ const resolvedURL = hgi.parseUrl(resolved)
728
+
729
+ if (!resolvedURL) {
730
+ // if we could not parse the url at all then returning nothing
731
+ // here means it will get removed from the tree in the next step
732
+ return
733
+ }
734
+
722
735
  if ((this.options.replaceRegistryHost === resolvedURL.hostname)
723
736
  || this.options.replaceRegistryHost === 'always') {
724
737
  // this.registry always has a trailing slash
725
- resolved = `${this.registry.slice(0, -1)}${resolvedURL.pathname}${resolvedURL.searchParams}`
738
+ return `${this.registry.slice(0, -1)}${resolvedURL.pathname}${resolvedURL.searchParams}`
726
739
  }
740
+
727
741
  return resolved
728
742
  }
729
743
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/arborist",
3
- "version": "5.6.1",
3
+ "version": "5.6.3",
4
4
  "description": "Manage node_modules trees",
5
5
  "dependencies": {
6
6
  "@isaacs/string-locale-compare": "^1.1.0",
@@ -16,6 +16,7 @@
16
16
  "bin-links": "^3.0.3",
17
17
  "cacache": "^16.1.3",
18
18
  "common-ancestor-path": "^1.0.1",
19
+ "hosted-git-info": "^5.2.1",
19
20
  "json-parse-even-better-errors": "^2.3.1",
20
21
  "json-stringify-nice": "^1.1.4",
21
22
  "minimatch": "^5.1.0",
@@ -42,7 +43,7 @@
42
43
  },
43
44
  "devDependencies": {
44
45
  "@npmcli/eslint-config": "^3.1.0",
45
- "@npmcli/template-oss": "3.8.0",
46
+ "@npmcli/template-oss": "4.8.0",
46
47
  "benchmark": "^2.1.4",
47
48
  "chalk": "^4.1.0",
48
49
  "minify-registry-metadata": "^2.1.0",
@@ -52,16 +53,13 @@
52
53
  },
53
54
  "scripts": {
54
55
  "test": "tap",
55
- "posttest": "npm run lint",
56
+ "posttest": "node ../.. run lint",
56
57
  "snap": "tap",
57
58
  "postsnap": "npm run lintfix",
58
59
  "test-proxy": "ARBORIST_TEST_PROXY=1 tap --snapshot",
59
- "preversion": "npm test",
60
- "postversion": "npm publish",
61
- "prepublishOnly": "git push origin --follow-tags",
62
60
  "eslint": "eslint",
63
61
  "lint": "eslint \"**/*.js\"",
64
- "lintfix": "npm run lint -- --fix",
62
+ "lintfix": "node ../.. run lint -- --fix",
65
63
  "benchmark": "node scripts/benchmark.js",
66
64
  "benchclean": "rm -rf scripts/benchmark/*/",
67
65
  "npmclilint": "npmcli-lint",
@@ -96,13 +94,18 @@
96
94
  "--no-warnings",
97
95
  "--no-deprecation"
98
96
  ],
99
- "timeout": "360"
97
+ "timeout": "360",
98
+ "nyc-arg": [
99
+ "--exclude",
100
+ "tap-snapshots/**"
101
+ ]
100
102
  },
101
103
  "engines": {
102
104
  "node": "^12.13.0 || ^14.15.0 || >=16.0.0"
103
105
  },
104
106
  "templateOSS": {
105
107
  "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
106
- "version": "3.8.0"
108
+ "version": "4.8.0",
109
+ "content": "../../scripts/template-oss/index.js"
107
110
  }
108
111
  }