MCPcopy Create free account
hub / github.com/nodejs/node / workspaceMock

Function workspaceMock

deps/npm/test/fixtures/mock-npm.js:432–475  ·  view source on GitHub ↗
(t, opts)

Source from the content-addressed store, hash-verified

430}
431
432function workspaceMock (t, opts) {
433 const toObject = [(a, c) => ({ ...a, ...c }), {}]
434 const { workspaces: workspacesDef, ...rest } = { clean: true, ...opts }
435 const workspaces = Object.fromEntries(Object.entries(workspacesDef).map(([name, ws]) => {
436 return [name, Object.fromEntries(Object.entries(ws).map(([wsPackageDep, wsPackageDepOpts]) => {
437 return [wsPackageDep, { ...rest, ...wsPackageDepOpts }]
438 }))]
439 }))
440 const root = 'workspace-root'
441 const version = '1.0.0'
442 const names = Object.keys(workspaces)
443 const ws = Object.entries(workspaces).map(([name, _ws]) => dependencyDetails(name, { ws: _ws }))
444 const deps = ws.map(({ depsMap }) => depsMap).flat()
445 const tarballs = deps.map(w => w.tarballDir).reduce(...toObject)
446 const symlinks = names
447 .map((name) => ({ [name]: t.fixture('symlink', `../${name}`) })).reduce(...toObject)
448 const hoisted = deps.filter(d => d.hoist).map(w => w.dirtyOrCleanDir).reduce(...toObject)
449 const workspaceFolders = ws.map(w => w.packageDir).reduce(...toObject)
450 const packageJSON = { name: root, version, workspaces: names }
451 const packageLockJSON = ({
452 name: root,
453 version,
454 lockfileVersion: 3,
455 requires: true,
456 packages: {
457 '': { name: root, version, workspaces: names },
458 ...deps.filter(d => d.hoist).map(d => d.packageLockEntry).reduce(...toObject),
459 ...ws.map(d => d.packageLockEntry).flat().reduce(...toObject),
460 ...ws.map(d => d.packageLockLink).flat().reduce(...toObject),
461 ...ws.map(d => d.packageLockLocal).flat().reduce(...toObject),
462 ...deps.filter(d => !d.hoist).map(d => d.packageLockEntry).reduce(...toObject),
463 },
464 })
465 return {
466 tarballs,
467 node_modules: {
468 ...hoisted,
469 ...symlinks,
470 },
471 'package-lock.json': JSON.stringify(packageLockJSON),
472 'package.json': JSON.stringify(packageJSON),
473 ...workspaceFolders,
474 }
475}
476
477module.exports = setupMockNpm
478module.exports.load = setupMockNpm

Callers 2

install.jsFile · 0.85
ci.jsFile · 0.85

Calls 6

dependencyDetailsFunction · 0.85
reduceMethod · 0.80
mapMethod · 0.65
keysMethod · 0.65
filterMethod · 0.65
entriesMethod · 0.45

Tested by

no test coverage detected