Skip to content

Commit 717b07a

Browse files
committed
Add resolve tests
1 parent 84b2a0e commit 717b07a

39 files changed

+142
-61
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ Checkout [tests](test) for more examples.
9292
#### `root`
9393

9494
Type: `String`
95-
Default: `process.cwd()`
95+
Default: `process.cwd()` or _dirname of [the postcss `from`](https://github.com/postcss/postcss#node-source)_
9696

97-
Define the root where to resolve path (eg: place where `node_modules` are). Should not be used that much.
97+
Define the root where to resolve path (eg: place where `node_modules` are). Should not be used that much.
98+
_Note: nested `@import` will additionally benefit of the relative dirname of imported files._
9899

99100
#### `path`
100101

101102
Type: `String|Array`
102-
Default: `process.cwd()` or _dirname of [the postcss `from`](https://github.com/postcss/postcss#node-source)_
103+
Default: `[]`
103104

104-
A string or an array of paths in where to look for files.
105-
_Note: nested `@import` will additionally benefit of the relative dirname of imported files._
105+
A string or an array of paths in where to look for files.
106106

107107
#### `transform`
108108

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ function AtImport(options) {
2222
options.path = [ options.path ]
2323
}
2424

25+
if (!Array.isArray(options.path)) {
26+
options.path = []
27+
}
28+
2529
options.path = options.path.map(function(p) {
26-
return path.resolve(p)
30+
return path.resolve(options.root, p)
2731
})
2832

2933
return function(styles, result) {

lib/resolve-id.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ module.exports = function(id, base, options) {
4141
paths: paths,
4242
extensions: [ ".css" ],
4343
packageFilter: function processPackage(pkg) {
44-
pkg.main = pkg.style || "index.css"
44+
if (pkg.style) {
45+
pkg.main = pkg.style
46+
}
47+
else if (!pkg.main || !/\.css$/.test(pkg.main)) {
48+
pkg.main = "index.css"
49+
}
4550
return pkg
4651
},
4752
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@import "fake";
2+
@import "auto";
3+
@import "nest";
4+
@import "by-hand/style.css";
5+
@import "use-dep";
6+
@import "use-dep-too";
7+
@import "use-dep" screen;
8+
9+
@import "web-fake";
10+
@import "web-auto";
11+
@import "web-nest";
12+
@import "web-by-hand/style.css";
13+
@import "web-use-dep";
14+
@import "web-use-dep-too";
15+
@import "web-use-dep" screen;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
empty {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main-js {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"main": "main.js"
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style-mained {}

0 commit comments

Comments
 (0)