Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit a62d842

Browse files
committed
Fixes #4
1 parent 68687ba commit a62d842

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

main.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,38 @@ function normalizeImportSourceToFilePath(filePath, source) {
3333
return normalizeFilePath(normalized);
3434
}
3535

36+
function getImportAttributeType(attributes = []) {
37+
for(let node of attributes) {
38+
if(node.type === "ImportAttribute" && node.key.type === "Identifier" && node.key.name === "type") {
39+
return node.value.value;
40+
}
41+
}
42+
}
43+
3644
async function findByContents(contents, filePath, alreadyParsedSet) {
3745
// Should we use dependency-graph for these relationships?
3846
let sources = new Set();
47+
let nestedSources = new Set();
3948

4049
let ast = acorn.parse(contents, {sourceType: "module", ecmaVersion: "latest"});
50+
4151
for(let node of ast.body) {
4252
if(node.type === "ImportDeclaration" && isNonBareSpecifier(node.source.value)) {
53+
let importAttributeType = getImportAttributeType(node?.attributes);
4354
let normalized = normalizeImportSourceToFilePath(filePath, node.source.value);
44-
if(sources.has(normalized) || normalized === filePath) {
45-
continue;
46-
}
55+
if(normalized !== filePath) {
56+
sources.add(normalized);
4757

48-
sources.add(normalized);
58+
// Right now only `css` and `json` are valid but others might come later
59+
if(!importAttributeType) {
60+
nestedSources.add(normalized);
61+
}
62+
}
4963
}
5064
}
5165

5266
// Recurse for nested deps
53-
for(let source of sources) {
67+
for(let source of nestedSources) {
5468
let s = await find(source, alreadyParsedSet);
5569
for(let p of s) {
5670
if(sources.has(p) || p === filePath) {

test/stubs/imported.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{}
1+
{
2+
"foo": "bar"
3+
}

0 commit comments

Comments
 (0)