watch-dependency-graph
Advanced tools
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", |
34
test.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') |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
8801
201