Skip to content

Commit

Permalink
Add dependency message support (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanZim authored Nov 9, 2016
1 parent cf61eaf commit 3a96059
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
16 changes: 15 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ function resolveImportId(
state
) {
var atRule = stmt.node
var base = atRule.source && atRule.source.input && atRule.source.input.file
var sourceFile
if (atRule.source && atRule.source.input && atRule.source.input.file) {
sourceFile = atRule.source.input.file
}
var base = sourceFile
? path.dirname(atRule.source.input.file)
: options.root

Expand All @@ -227,6 +231,16 @@ function resolveImportId(
if (!Array.isArray(resolved)) {
resolved = [ resolved ]
}

// Add dependency messages:
resolved.forEach(function(file) {
result.messages.push({
type: "dependency",
file: file,
parent: sourceFile,
})
})

return Promise.all(resolved.map(function(file) {
return loadImportContent(
result,
Expand Down
28 changes: 28 additions & 0 deletions test/callback.js → test/import-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,31 @@ test("should have a callback shortcut for webpack", t => {
)
})
})

test("should add dependency message for each import", t => {
return postcss()
.use(atImport({
path: "fixtures/imports",
}))
.process(readFileSync("fixtures/media-import.css"), {
from: "fixtures/media-import.css",
})
.then((result) => {
var deps = result.messages.filter(
message => message.type === "dependency"
)
var expected = [
{
type: "dependency",
file: resolve("fixtures/imports/media-import-level-2.css"),
parent: resolve("fixtures/media-import.css"),
},
{
type: "dependency",
file: resolve("fixtures/imports/media-import-level-3.css"),
parent: resolve("fixtures/imports/media-import-level-2.css"),
},
]
t.deepEqual(deps, expected)
})
})

0 comments on commit 3a96059

Please sign in to comment.