Welcome to mirror list, hosted at ThFree Co, Russian Federation.

deepest-nesting-target.js « test « arborist « workspaces - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5ea186fdb7852e1eb29eca06ad1c04f82dc615df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const t = require('tap')
const Node = require('../lib/node.js')
const Link = require('../lib/link.js')
const deepestNestingTarget = require('../lib/deepest-nesting-target.js')

// root -> (a, b, file:target) PEER(p)
// a -> (x) PEER(p)
// b -> PEER(p)
// target -> (a, b, file:/outer) PEER(p)
// /outer -> (a, b) PEER(p)
//
// p can be placed under the root (because project root), or any of the
// 'x' nodes (because no peer dep), or in the /outer node (no resolve parent)
// Any other place is not allowed, because of peer dependencies.

const tree = new Node({
  path: '/some/path',
  pkg: {
    name: 'root',
    dependencies: {
      a: '',
      b: '',
      link: 'file:target',
    } },
  fsChildren: [
    {
      path: '/some/path/target',
      pkg: {
        name: 'link',
        version: '1.2.3',
        peerDependencies: { p: '' },
        dependencies: {
          a: '',
          b: '',
          outerlink: 'file:/other/path',
        },
      },
      children: [
        {
          pkg: {
            name: 'a',
            version: '1.2.3',
            dependencies: { x: '' },
            peerDependencies: { p: '' },
          },
          children: [{ pkg: { name: 'x', version: '1.2.3' } }],
        },
        { pkg: { name: 'b', version: '1.2.3', peerDependencies: { p: '' } } },
      ],
    },
  ],
  children: [
    {
      pkg: {
        name: 'a',
        version: '1.2.3',
        dependencies: { x: '' },
        peerDependencies: { p: '' },
      },
      children: [{ pkg: { name: 'x', version: '1.2.3' } }],
    },
    { pkg: { name: 'b', version: '1.2.3', peerDependencies: { p: '' } } },
  ],
})

const a = tree.children.get('a')
const x = a.children.get('x')
const b = tree.children.get('b')

const inner = tree.inventory.get('target')
const innerLink = new Link({
  parent: tree,
  name: 'link',
  target: inner,
})
t.equal(inner, innerLink.target, 'gut check')
t.equal(innerLink, tree.children.get('link'), 'gut check')
const innerA = inner.children.get('a')
const innerX = innerA.children.get('x')
const innerB = inner.children.get('b')

// the target of the outer link dep. it can hold p, but b cannot
const outer = new Node({
  path: '/other/path',
  pkg: {
    name: 'other',
    version: '1.2.3',
    peerDependencies: { p: '' },
    dependencies: { a: '', b: '' },
  },
  children: [
    {
      pkg: {
        name: 'a',
        version: '1.2.3',
        dependencies: { x: '' },
        peerDependencies: { p: '' },
      },
      children: [{ pkg: { name: 'x', version: '1.2.3' } }],
    },
    { pkg: { name: 'b', version: '1.2.3', peerDependencies: { p: '' } } },
  ],
})
const outerA = outer.children.get('a')
const outerX = outerA.children.get('x')
const outerB = outer.children.get('b')

const outerLink = new Link({
  parent: inner,
  name: 'outerlink',
  target: outer,
})
t.equal(outer, tree.inventory.get('../../other/path'), 'gut check')
t.equal(outer, outerLink.target, 'gut check')
t.equal(outerLink, inner.children.get('outerlink'), 'gut check')

t.equal(deepestNestingTarget(tree, 'p'), tree)
t.equal(deepestNestingTarget(a, 'p'), tree)
t.equal(deepestNestingTarget(b, 'p'), tree)
t.equal(deepestNestingTarget(x, 'p'), x)
t.equal(deepestNestingTarget(inner, 'p'), tree)
t.equal(deepestNestingTarget(innerA, 'p'), tree)
t.equal(deepestNestingTarget(innerB, 'p'), tree)
t.equal(deepestNestingTarget(innerX, 'p'), innerX)
t.equal(deepestNestingTarget(outer, 'p'), outer)
t.equal(deepestNestingTarget(outerA, 'p'), outer)
t.equal(deepestNestingTarget(outerB, 'p'), outer)
t.equal(deepestNestingTarget(outerX, 'p'), outerX)