Skip to content

Commit 8d9d0dc

Browse files
committed
Fixed: relative import based on path option
Close #14 Ref #15
1 parent 4af6770 commit 8d9d0dc

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,19 @@ function resolveFilename(name, root, paths, source) {
261261
catch (e) {
262262
// fix to try relative files on windows with "./"
263263
// if it's look like it doesn't start with a relative path already
264-
if (name.match(/^\.\.?/)) {throw e}
265-
file = resolve.sync("./" + name, resolveOpts)
264+
// if (name.match(/^\.\.?/)) {throw e}
265+
try {
266+
file = resolve.sync("./" + name, resolveOpts)
267+
}
268+
catch (e) {
269+
// LAST HOPE
270+
if (!paths.some(function(dir) {
271+
file = path.join(dir, name)
272+
return fs.existsSync(file)
273+
})) {
274+
throw e
275+
}
276+
}
266277
}
267278

268279
return path.normalize(file)

test/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,14 @@ test("@import callback", function(t) {
108108
})
109109
})
110110

111-
test("import relative files without from option in postcss.process", function(t) {
112-
postcss()
113-
.use(atImport({
114-
path: "test/fixtures/imports/relative"
115-
}))
116-
.process(read("fixtures/imports/relative/import"))
111+
test("import relative files using path option only", function(t) {
112+
var base = " content{}"
113+
t.equal(
114+
postcss()
115+
.use(atImport({path: "test/fixtures/imports/relative"}))
116+
.process(read("fixtures/imports/relative/import") + base)
117+
.css.trim(),
118+
read("fixtures/imports/bar") + base
119+
)
117120
t.end()
118121
})

0 commit comments

Comments
 (0)