MCPcopy Create free account
hub / github.com/npm/cli / suite

Function suite

workspaces/arborist/scripts/benchmark/reify.js:19–107  ·  view source on GitHub ↗
(suite, { registry, cache })

Source from the content-addressed store, hash-verified

17]
18
19const suite = async (suite, { registry, cache }) => {
20 // setup two folders, one with a hidden lockfile, one without
21 await Promise.all(folders.map(f => mkdir(f, { recursive: true })))
22
23 const dependencies = {
24 'flow-parser': '0.114.0',
25 'flow-remove-types': '2.114.0',
26 ink: '2.6.0',
27 tap: '14.10.5',
28 }
29
30 let packageLock = null
31
32 const promises = []
33
34 // do it one time so that we have it in the shared cache
35 // and benchmark the case where we don't have anything to do
36 // this doesn't get pushed into promises, because we need it
37 // before we do the other ones, so we can write the lockfile.
38 {
39 const path = resolve(dir, 'full')
40 process.stderr.write('reify setup ' + basename(path))
41 const arb = new Arborist({
42 registry,
43 cache,
44 path,
45 })
46 writeFileSync(resolve(arb.path, 'package.json'), JSON.stringify({
47 name: basename(path),
48 version: '1.0.0',
49 dependencies,
50 }))
51 await arb.reify()
52 // grab this so we can make setup faster
53 packageLock = require(resolve(path, 'package-lock.json'))
54 }
55
56 // just reify them all fast. we'll remove the bits we don't want later.
57 for (const path of folders) {
58 // already did this one
59 if (path === resolve(dir, 'full')) {
60 continue
61 }
62 const arb = new Arborist({
63 registry,
64 cache,
65 path,
66 })
67 writeFileSync(resolve(path, 'package.json'), JSON.stringify({
68 name: basename(path),
69 version: '1.0.0',
70 dependencies,
71 }))
72 writeFileSync(resolve(path, 'package-lock.json'), JSON.stringify(packageLock))
73 if (!/empty/.test(path)) {
74 promises.push(arb.reify().then(() => process.stderr.write(' ' + basename(path))))
75 } else {
76 process.stderr.write(' ' + basename(path))

Callers

nothing calls this directly

Calls 5

reifyMethod · 0.95
resolveFunction · 0.85
pushMethod · 0.80
writeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected