Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing duplicate and circular dependencies #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/minipack.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,23 @@ function createGraph(entry) {
// into an absolute one by joining it with the path to the directory of
// the parent asset.
const absolutePath = path.join(dirname, relativePath);

// Check if dependency is already added as asset in the queue and skip create process.
let child = queue.find(asset => asset.filename === absolutePath);

// Parse the asset, read its content, and extract its dependencies.
const child = createAsset(absolutePath);
if (!child) {
// Parse the asset, read its content, and extract its dependencies.
child = createAsset(absolutePath);

// We push the child asset into the queue so its dependencies
// will also be iterated over and parsed.
queue.push(child);
}

// It's essential for us to know that `asset` depends on `child`. We
// express that relationship by adding a new property to the `mapping`
// object with the id of the child.
asset.mapping[relativePath] = child.id;

// Finally, we push the child asset into the queue so its dependencies
// will also be iterated over and parsed.
queue.push(child);
});
}

Expand Down