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

calc-dep-flags.js « test « arborist « workspaces - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7e6d0679fba359a9317262654defa310bec0883f (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
const { resolve } = require('path')
const t = require('tap')
const calcDepFlags = require('../lib/calc-dep-flags.js')
const Node = require('../lib/node.js')
const Link = require('../lib/link.js')

const {
  normalizePath,
  printTree,
} = require('./fixtures/utils.js')

const cwd = normalizePath(process.cwd())
t.cleanSnapshot = s => s.split(cwd).join('{CWD}')

t.test('flag stuff', t => {
  const root = new Node({
    path: '/x',
    realpath: '/x',
    pkg: {
      dependencies: { prod: '' },
      devDependencies: { dev: '' },
      optionalDependencies: { optional: '' },
      peerDependencies: { peer: '' },
    },
  })

  new Node({
    pkg: {
      name: 'optional',
      version: '1.2.3',
      dependencies: { devoptional: '', missing: '' },
    },
    parent: root,
  })

  new Node({
    pkg: {
      name: 'devoptional',
      version: '1.2.3',
    },
    parent: root,
  })

  new Node({
    pkg: {
      name: 'extraneous',
    },
    parent: root,
  })

  new Node({
    pkg: {
      name: 'peer',
      version: '1.2.3',
      dependencies: { peerdep: '' },
    },
    parent: root,
  })

  new Node({
    pkg: {
      name: 'peerdep',
      version: '1.2.3',
    },
    parent: root,
  })

  new Node({
    pkg: {
      name: 'prod',
      version: '1.2.3',
      dependencies: { proddep: '' },
      peerDependencies: { metapeer: '' },
    },
    parent: root,
  })

  new Node({
    pkg: {
      name: 'metapeer',
      version: '1.2.3',
      dependencies: { metapeerdep: '' },
    },
    parent: root,
  })

  new Node({
    pkg: {
      name: 'metapeerdep',
      version: '1.2.3',
    },
    parent: root,
  })

  new Node({
    pkg: {
      name: 'proddep',
      version: '1.2.3',
      dependencies: { proddep: '' },
    },
    parent: root,
  })

  new Node({
    pkg: {
      name: 'dev',
      version: '1.2.3',
      dependencies: { devdep: '' },
    },
    parent: root,
  })

  const devdep = new Node({
    pkg: {
      name: 'devdep',
      version: '1.2.3',
      dependencies: { proddep: '', linky: '', devoptional: '' },
      optionalDependencies: { devandoptional: '' },
    },
    parent: root,
  })

  new Node({
    pkg: {
      name: 'devandoptional',
      version: '1.2.3',
    },
    parent: root,
  })

  const linky = new Link({
    pkg: {
      name: 'linky',
      version: '1.2.3',
      dependencies: { linklink: '' },
    },
    realpath: '/x/y/z',
    parent: devdep,
  })

  // a link dep depended upon by the target of a linked dep
  new Link({
    pkg: {
      name: 'linklink',
      version: '1.2.3',
    },
    realpath: '/l/i/n/k/link',
    parent: linky.target,
  })

  calcDepFlags(root)

  t.matchSnapshot(printTree(root), 'after')
  t.end()
})

t.test('no reset', async t => {
  const root = new Node({
    path: '/some/path',
    realpath: '/some/path',
    pkg: {
      dependencies: { foo: '' },
    },
  })
  const foo = new Node({ parent: root, pkg: { name: 'foo', version: '1.2.3' } })

  root.optional = false
  root.dev = true
  root.extraneous = false

  calcDepFlags(root, false)
  t.matchSnapshot(printTree(root), 'after')
  t.equal(root.dev, true, 'root.dev')
  t.equal(foo.dev, true, 'foo.dev')
  t.equal(root.optional, false, 'root.optional')
  t.equal(foo.optional, false, 'foo.optional')
  t.equal(root.extraneous, false, 'root.extraneous')
  t.equal(foo.extraneous, false, 'foo.extraneous')
})

t.test('set parents to not extraneous when visiting', t => {
  const root = new Node({
    path: '/some/path',
    realpath: '/some/path',
    pkg: {
      dependencies: {
        baz: 'file:node_modules/asdf/node_modules/baz',
        foo: 'file:bar/foo',
      },
    },
  })
  const bar = new Node({
    root,
    path: resolve(root.path, 'bar'),
  })
  const foo = new Node({
    root,
    path: resolve(bar.path, 'foo'),
    pkg: { name: 'foo', version: '1.2.3' },
  })
  const asdf = new Node({
    parent: root,
    pkg: { name: 'asdf', version: '1.2.3' },
  })
  const baz = new Node({
    parent: asdf,
    pkg: { name: 'baz', version: '1.2.3' },
  })
  const fooLink = new Link({
    name: 'foo',
    target: foo,
    parent: root,
    realpath: foo.path,
  })
  const bazLink = new Link({
    name: 'baz',
    target: baz,
    parent: root,
    realpath: baz.path,
  })

  t.matchSnapshot(printTree(root), 'before')
  calcDepFlags(root, true)
  t.matchSnapshot(printTree(root), 'after')

  t.equal(root.extraneous, false, 'root')
  t.equal(asdf.extraneous, false, 'asdf')
  t.equal(bar.extraneous, false, 'bar')
  t.equal(baz.extraneous, false, 'baz')
  t.equal(foo.extraneous, false, 'foo')
  t.equal(fooLink.extraneous, false, 'fooLink')
  t.equal(bazLink.extraneous, false, 'bazLink')

  t.equal(root.dev, false, 'root not dev')
  t.equal(asdf.dev, false, 'asdf not dev')
  t.equal(bar.dev, false, 'bar not dev')
  t.equal(baz.dev, false, 'baz not dev')
  t.equal(foo.dev, false, 'foo not dev')
  t.equal(fooLink.dev, false, 'fooLink not dev')
  t.equal(bazLink.dev, false, 'bazLink not dev')

  t.equal(root.optional, false, 'root not optional')
  t.equal(asdf.optional, false, 'asdf not optional')
  t.equal(bar.optional, false, 'bar not optional')
  t.equal(baz.optional, false, 'baz not optional')
  t.equal(foo.optional, false, 'foo not optional')
  t.equal(fooLink.optional, false, 'foolink not optional')
  t.equal(bazLink.optional, false, 'bazlink not optional')

  t.equal(root.peer, false, 'root not peer')
  t.equal(asdf.peer, false, 'asdf not peer')
  t.equal(bar.peer, false, 'bar not peer')
  t.equal(baz.peer, false, 'baz not peer')
  t.equal(foo.peer, false, 'foo not peer')
  t.equal(fooLink.peer, false, 'foolink not peer')
  t.equal(bazLink.peer, false, 'bazlink not peer')

  t.equal(root.devOptional, false, 'root not devOptional')
  t.equal(asdf.devOptional, false, 'asdf not devOptional')
  t.equal(bar.devOptional, false, 'bar not devOptional')
  t.equal(baz.devOptional, false, 'baz not devOptional')
  t.equal(foo.devOptional, false, 'foo not devOptional')
  t.equal(fooLink.devOptional, false, 'foolink not devOptional')
  t.equal(bazLink.devOptional, false, 'bazlink not devOptional')
  t.end()
})