Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

watch-dependency-graph

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

watch-dependency-graph - npm Package Compare versions

Comparing version 2.0.0-beta.2 to 2.0.0-beta.3

56

index.js

@@ -18,22 +18,18 @@ const path = require('path')

files.forEach(require) // load modules
// remove old child entry from require.main (this file)
for (const file of files) {
module.children.splice(
module.children.findIndex(c => c.id === file),
1
)
}
const mostRecentChildren = []
// load entry modules as children of this module
files.forEach(require)
/**
* children[] keeps growing, so we need to grab the latest
* modules that match the entries
*
* reverse the children, pick the first that match
*/
for (const c of module.children.reverse()) {
if (files.includes(c.id)) mostRecentChildren.push(c)
if (mostRecentChildren.length === files.length) break
}
return mostRecentChildren
return module.children.filter(c => files.includes(c.id))
}
function walk (modules, context) {
const { ids, tree, entryPointer, parentPointer } = context
const { ids, tree, entryPointer, parentPointer, visitedTree = {} } = context

@@ -44,2 +40,5 @@ for (const mod of modules) {

const selfPointer = ids.indexOf(mod.id)
const safeEntryPointer =
entryPointer === undefined ? selfPointer : entryPointer
const entryFilename = ids[safeEntryPointer]

@@ -58,10 +57,4 @@ // setup

if (entryPointer === undefined) {
// must be an entry itself
leaf.entryPointers = [selfPointer]
} else if (
entryPointer !== undefined &&
!leaf.entryPointers.includes(entryPointer)
) {
leaf.entryPointers.push(entryPointer)
if (!leaf.entryPointers.includes(safeEntryPointer)) {
leaf.entryPointers.push(safeEntryPointer)
}

@@ -82,8 +75,15 @@

if (mod.children.length) {
if (!visitedTree[entryFilename]) {
visitedTree[entryFilename] = []
}
if (mod.children.length && !visitedTree[entryFilename].includes(mod.id)) {
visitedTree[entryFilename].push(mod.id)
walk(mod.children, {
ids,
tree,
entryPointer: entryPointer === undefined ? selfPointer : entryPointer,
parentPointer: selfPointer
entryPointer: safeEntryPointer,
parentPointer: selfPointer,
visitedTree
})

@@ -130,2 +130,4 @@ }

function bootstrap () {
debug('bootstrapping', entries)
ids = []

@@ -141,2 +143,4 @@ tree = {}

debug('modules', modules.length)
walk(modules, {

@@ -143,0 +147,0 @@ ids,

{
"name": "watch-dependency-graph",
"version": "2.0.0-beta.2",
"version": "2.0.0-beta.3",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -209,2 +209,35 @@ import fs from 'fs-extra'

test('handles circular deps', async () => {
const files = {
a: {
url: './circular/a.js',
content: `
import b from './b.js'
export default ''
`
},
b: {
url: './circular/b.js',
content: `
import a from './a.js'
export default ''
`
}
}
const fsx = fixtures.create(files)
const w = graph({ cwd: fixtures.getRoot() })
w.add([fsx.files.a, fsx.files.b])
await wait(DELAY)
const tree = w.tree
assert(tree[fsx.files.a].childrenPointers.includes(tree[fsx.files.b].pointer))
assert(tree[fsx.files.b].childrenPointers.includes(tree[fsx.files.a].pointer))
w.close()
fsx.cleanup()
})
test('handles inverse tree', async () => {

@@ -211,0 +244,0 @@ const files = {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc