@npmcli/arborist 6.0.0 → 6.1.1

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.
@@ -345,7 +345,6 @@ module.exports = cls => class Builder extends cls {
345
345
  event,
346
346
  path,
347
347
  pkg,
348
- stdioString: true,
349
348
  stdio,
350
349
  env,
351
350
  scriptShell: this[_scriptShell],
@@ -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')
@@ -640,10 +641,15 @@ module.exports = cls => class Reifier extends cls {
640
641
  // and no 'bundled: true' setting.
641
642
  // Do the best with what we have, or else remove it from the tree
642
643
  // entirely, since we can't possibly reify it.
643
- const res = node.resolved ? `${node.name}@${this[_registryResolved](node.resolved)}`
644
- : node.packageName && node.version
645
- ? `${node.packageName}@${node.version}`
646
- : null
644
+ let res = null
645
+ if (node.resolved) {
646
+ const registryResolved = this[_registryResolved](node.resolved)
647
+ if (registryResolved) {
648
+ res = `${node.name}@${registryResolved}`
649
+ }
650
+ } else if (node.packageName && node.version) {
651
+ res = `${node.packageName}@${node.version}`
652
+ }
647
653
 
648
654
  // no idea what this thing is. remove it from the tree.
649
655
  if (!res) {
@@ -721,12 +727,20 @@ module.exports = cls => class Reifier extends cls {
721
727
  // ${REGISTRY} or something. This has to be threaded through the
722
728
  // Shrinkwrap and Node classes carefully, so for now, just treat
723
729
  // the default reg as the magical animal that it has been.
724
- const resolvedURL = new URL(resolved)
730
+ const resolvedURL = hgi.parseUrl(resolved)
731
+
732
+ if (!resolvedURL) {
733
+ // if we could not parse the url at all then returning nothing
734
+ // here means it will get removed from the tree in the next step
735
+ return
736
+ }
737
+
725
738
  if ((this.options.replaceRegistryHost === resolvedURL.hostname)
726
739
  || this.options.replaceRegistryHost === 'always') {
727
740
  // this.registry always has a trailing slash
728
- resolved = `${this.registry.slice(0, -1)}${resolvedURL.pathname}${resolvedURL.searchParams}`
741
+ return `${this.registry.slice(0, -1)}${resolvedURL.pathname}${resolvedURL.searchParams}`
729
742
  }
743
+
730
744
  return resolved
731
745
  }
732
746
 
@@ -1544,7 +1558,6 @@ module.exports = cls => class Reifier extends cls {
1544
1558
  event,
1545
1559
  path,
1546
1560
  pkg,
1547
- stdioString: true,
1548
1561
  stdio,
1549
1562
  scriptShell: this.options.scriptShell,
1550
1563
  })
package/lib/yarn-lock.js CHANGED
@@ -7,9 +7,8 @@
7
7
  // <key> <value>
8
8
  //
9
9
  // Assume that any key or value might be quoted, though that's only done
10
- // in practice if certain chars are in the string. Quoting unnecessarily
11
- // does not cause problems for yarn, so that's what we do when we write
12
- // it back.
10
+ // in practice if certain chars are in the string. When writing back, we follow
11
+ // Yarn's rules for quoting, to cause minimal friction.
13
12
  //
14
13
  // The data format would support nested objects, but at this time, it
15
14
  // appears that yarn does not use that for anything, so in the interest
@@ -33,10 +32,44 @@ const consistentResolve = require('./consistent-resolve.js')
33
32
  const { dirname } = require('path')
34
33
  const { breadth } = require('treeverse')
35
34
 
35
+ // Sort Yarn entries respecting the yarn.lock sort order
36
+ const yarnEntryPriorities = {
37
+ name: 1,
38
+ version: 2,
39
+ uid: 3,
40
+ resolved: 4,
41
+ integrity: 5,
42
+ registry: 6,
43
+ dependencies: 7,
44
+ }
45
+
46
+ const priorityThenLocaleCompare = (a, b) => {
47
+ if (!yarnEntryPriorities[a] && !yarnEntryPriorities[b]) {
48
+ return localeCompare(a, b)
49
+ }
50
+ /* istanbul ignore next */
51
+ return (yarnEntryPriorities[a] || 100) > (yarnEntryPriorities[b] || 100) ? 1 : -1
52
+ }
53
+
54
+ const quoteIfNeeded = val => {
55
+ if (
56
+ typeof val === 'boolean' ||
57
+ typeof val === 'number' ||
58
+ val.startsWith('true') ||
59
+ val.startsWith('false') ||
60
+ /[:\s\n\\",[\]]/g.test(val) ||
61
+ !/^[a-zA-Z]/g.test(val)
62
+ ) {
63
+ return JSON.stringify(val)
64
+ }
65
+
66
+ return val
67
+ }
68
+
36
69
  // sort a key/value object into a string of JSON stringified keys and vals
37
70
  const sortKV = obj => Object.keys(obj)
38
71
  .sort(localeCompare)
39
- .map(k => ` ${JSON.stringify(k)} ${JSON.stringify(obj[k])}`)
72
+ .map(k => ` ${quoteIfNeeded(k)} ${quoteIfNeeded(obj[k])}`)
40
73
  .join('\n')
41
74
 
42
75
  // for checking against previous entries
@@ -171,7 +204,7 @@ class YarnLock {
171
204
  toString () {
172
205
  return prefix + [...new Set([...this.entries.values()])]
173
206
  .map(e => e.toString())
174
- .sort(localeCompare).join('\n\n') + '\n'
207
+ .sort((a, b) => localeCompare(a.replace(/"/g, ''), b.replace(/"/g, ''))).join('\n\n') + '\n'
175
208
  }
176
209
 
177
210
  fromTree (tree) {
@@ -323,19 +356,14 @@ class YarnLockEntry {
323
356
  // sort objects to the bottom, then alphabetical
324
357
  return ([...this[_specs]]
325
358
  .sort(localeCompare)
326
- .map(JSON.stringify).join(', ') +
359
+ .map(quoteIfNeeded).join(', ') +
327
360
  ':\n' +
328
361
  Object.getOwnPropertyNames(this)
329
362
  .filter(prop => this[prop] !== null)
330
- .sort(
331
- (a, b) =>
332
- /* istanbul ignore next - sort call order is unpredictable */
333
- (typeof this[a] === 'object') === (typeof this[b] === 'object')
334
- ? localeCompare(a, b)
335
- : typeof this[a] === 'object' ? 1 : -1)
363
+ .sort(priorityThenLocaleCompare)
336
364
  .map(prop =>
337
365
  typeof this[prop] !== 'object'
338
- ? ` ${JSON.stringify(prop)} ${JSON.stringify(this[prop])}\n`
366
+ ? ` ${prop} ${prop === 'integrity' ? this[prop] : JSON.stringify(this[prop])}\n`
339
367
  : Object.keys(this[prop]).length === 0 ? ''
340
368
  : ` ${prop}:\n` + sortKV(this[prop]) + '\n')
341
369
  .join('')).trim()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/arborist",
3
- "version": "6.0.0",
3
+ "version": "6.1.1",
4
4
  "description": "Manage node_modules trees",
5
5
  "dependencies": {
6
6
  "@isaacs/string-locale-compare": "^1.1.0",
@@ -12,14 +12,15 @@
12
12
  "@npmcli/node-gyp": "^3.0.0",
13
13
  "@npmcli/package-json": "^3.0.0",
14
14
  "@npmcli/query": "^3.0.0",
15
- "@npmcli/run-script": "^5.0.0",
15
+ "@npmcli/run-script": "^6.0.0",
16
16
  "bin-links": "^4.0.1",
17
17
  "cacache": "^17.0.1",
18
18
  "common-ancestor-path": "^1.0.1",
19
+ "hosted-git-info": "^6.1.1",
19
20
  "json-parse-even-better-errors": "^3.0.0",
20
21
  "json-stringify-nice": "^1.1.4",
21
22
  "minimatch": "^5.1.0",
22
- "nopt": "^6.0.0",
23
+ "nopt": "^7.0.0",
23
24
  "npm-install-checks": "^6.0.0",
24
25
  "npm-package-arg": "^10.0.0",
25
26
  "npm-pick-manifest": "^8.0.1",
@@ -39,7 +40,7 @@
39
40
  },
40
41
  "devDependencies": {
41
42
  "@npmcli/eslint-config": "^4.0.0",
42
- "@npmcli/template-oss": "4.6.2",
43
+ "@npmcli/template-oss": "4.8.0",
43
44
  "benchmark": "^2.1.4",
44
45
  "chalk": "^4.1.0",
45
46
  "minify-registry-metadata": "^2.1.0",
@@ -101,7 +102,7 @@
101
102
  },
102
103
  "templateOSS": {
103
104
  "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
104
- "version": "4.6.2",
105
+ "version": "4.8.0",
105
106
  "content": "../../scripts/template-oss/index.js"
106
107
  }
107
108
  }