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 0.0.1 to 0.0.2

13

index.js

@@ -7,3 +7,3 @@ const path = require('path')

function walk(children, parentIndex, parentChildren, ids, register) {
function walk(children, parentIndex, parentChildren, ids, register, visited = []) {
for (const { id, children: childs } of children) {

@@ -22,4 +22,7 @@ // push to all files

// recurse
if (childs.length) walk(childs, parentIndex, register[id].children, ids, register)
// recurse, but only if we haven't walked these children yet
if (Boolean(childs.length && !visited.includes(id))) {
visited.push(id)
walk(childs, parentIndex, register[id].children, ids, register, visited)
}
}

@@ -31,3 +34,3 @@ }

const files = uniq(
inputs.flat(2).map(matched.sync).flat(2).map(f => require.resolve(path.join(process.cwd(), f)))
inputs.flat(2).map(matched.sync).flat(2).map(f => require.resolve(path.resolve(process.cwd(), f)))
)

@@ -117,3 +120,3 @@

walk(next.children, parentIndex, register[parentFile].children, ids, register)
events.emit('update', require.cache[ids[parentIndex]])
events.emit('update', ids[parentIndex])
}

@@ -120,0 +123,0 @@ })

{
"name": "watch-dependency-graph",
"version": "0.0.1",
"version": "0.0.2",
"description": "",

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

@@ -12,2 +12,3 @@ const fs = require('fs-extra')

childOfChildren: path.join(fixturesRoot, 'childOfChildren.js'),
commonDep: path.join(fixturesRoot, 'commonDep.js'),
childOfA: path.join(fixturesRoot, 'childOfA.js'),

@@ -22,6 +23,7 @@ childOfB: path.join(fixturesRoot, 'childOfB.js'),

fs.outputFileSync(fixtures.childOfChildren, `module.exports = {}`)
fs.outputFileSync(fixtures.commonDep, `module.exports = {}`)
fs.outputFileSync(fixtures.childOfA, `require('${fixtures.childOfChildren}')`)
fs.outputFileSync(fixtures.childOfB, `require('${fixtures.childOfChildren}')`)
fs.outputFileSync(fixtures.A, `import * as A from '${fixtures.childOfA}';`) // works with imports
fs.outputFileSync(fixtures.B, `require('${fixtures.childOfB}')`)
fs.outputFileSync(fixtures.A, `import * as A from '${fixtures.childOfA}';import * as commonDep from '${fixtures.commonDep}'`) // works with imports
fs.outputFileSync(fixtures.B, `require('${fixtures.childOfB}');require('${fixtures.commonDep}')`)
})

@@ -36,3 +38,3 @@

const instance = require('./')(['./fixtures/A.js', './fixtures/B.js'])
const close = instance.on('update', mod => updated.push(mod.id))
const close = instance.on('update', mod => updated.push(mod))

@@ -55,3 +57,3 @@ fs.outputFileSync(fixtures.A, fs.readFileSync(fixtures.A))

const instance = require('./')(['./fixtures/A.js', './fixtures/B.js'])
const close = instance.on('update', mod => updated.push(mod.id))
const close = instance.on('update', mod => updated.push(mod))

@@ -72,3 +74,3 @@ fs.outputFileSync(fixtures.childOfA, fs.readFileSync(fixtures.childOfA))

const instance = require('./')(['./fixtures/A.js', './fixtures/B.js'])
const close = instance.on('update', mod => updated.push(mod.id))
const close = instance.on('update', mod => updated.push(mod))

@@ -90,3 +92,3 @@ fs.outputFileSync(fixtures.childOfChildren, fs.readFileSync(fixtures.childOfChildren))

const instance = require('./')(['./fixtures/A.js', './fixtures/B.js'])
const close = instance.on('update', mod => updated.push(mod.id))
const close = instance.on('update', mod => updated.push(mod))

@@ -111,2 +113,22 @@ fs.outputFileSync(fixtures.childOfA, '') // remove child

test('ensure shared deps are both mapped to entries', async () => {
const { register, close } = require('./')(['./fixtures/A.js', './fixtures/B.js'])
assert(register[fixtures.commonDep].roots.length === 2)
await close()
})
test('handles circular deps', async () => {
fs.outputFileSync(fixtures.childOfA, `require('${fixtures.childOfChildren}');require('${fixtures.commonDep}')`)
await wait(DELAY)
const { register, close } = require('./')(['./fixtures/A.js', './fixtures/B.js'])
assert(register[fixtures.commonDep].roots.length === 2)
await close()
})
!(async function () {

@@ -113,0 +135,0 @@ console.time('test')

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