Skip to content

Commit

Permalink
fix relative import path stack
Browse files Browse the repository at this point in the history
  • Loading branch information
MoOx committed Oct 29, 2014
1 parent 1059bb1 commit 5725285
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
# 1.0.3 - 2014-10-29

- fix relative import path stack

# 1.0.2 - 2014-09-16

- Move ignored import at top & adjust related media queries, to make them work (fix [#2](https://github.com/postcss/postcss-import/issues/2))
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014, Maxime Thirouin, Jason Campbell & Kevin Mårtensson
Copyright (c) 2014 Maxime Thirouin, Jason Campbell & Kevin Mårtensson

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
14 changes: 8 additions & 6 deletions index.js
Expand Up @@ -95,19 +95,21 @@ function readAtImport(atRule, options, ignoredAtRules, media) {
atRule.removeSelf()
return
}

addInputToPath(options)
var resolvedFilename = resolveFilename(parsedAtImport.uri, options.path, atRule.source)

// parse imported file to get rules
var parseOptions = clone(options)

// add directory containing the @imported file in the paths
// to allow local import from this file
var dirname = path.dirname(resolvedFilename)
if (options.path.indexOf(dirname) === -1) {
options.path = options.path.slice()
options.path.unshift(dirname)
if (parseOptions.path.indexOf(dirname) === -1) {
parseOptions.path = parseOptions.path.slice()
parseOptions.path.unshift(dirname)
}

// parse imported file to get rules
var parseOptions = clone(options)
parseOptions.from = resolvedFilename
var fileContent = readFile(resolvedFilename, options.encoding, options.transform || function(value) { return value })
if (fileContent.trim() === "") {
Expand All @@ -117,7 +119,7 @@ function readAtImport(atRule, options, ignoredAtRules, media) {
var newStyles = postcss.parse(fileContent, parseOptions)

// recursion: import @import from imported file
parseStyles(newStyles, options, ignoredAtRules, parsedAtImport.media)
parseStyles(newStyles, parseOptions, ignoredAtRules, parsedAtImport.media)

// wrap rules if the @import have a media query
if (parsedAtImport.media && parsedAtImport.media.length) {
Expand Down
15 changes: 6 additions & 9 deletions package.json
Expand Up @@ -8,7 +8,7 @@
"postcss-plugins",
"import"
],
"author": "MoOx",
"author": "Maxime Thirouin",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -17,7 +17,6 @@
"files": [
"CHANGELOG.md",
"LICENSE",
"README.md",
"index.js"
],
"dependencies": {
Expand All @@ -27,15 +26,13 @@
},
"devDependencies": {
"css-whitespace": "^1.1.0",
"jscs": "^1.5.9",
"jshint": "^2.5.2",
"jshint-stylish": "^0.4.0",
"tap-colorize": "^1.2.0",
"tape": "^2.13.4"
"jscs": "^1.6.2",
"jshint": "^2.5.6",
"tape": "^3.0.0"
},
"scripts": {
"jscs": "jscs *.js **/*.js",
"jshint": "jshint . --exclude node_modules --reporter node_modules/jshint-stylish/stylish.js",
"test": "npm run jscs && npm run jshint && tape test | tap-colorize"
"jshint": "jshint . --exclude-path .gitignore",
"test": "npm run jscs && npm run jshint && npm run standalone && tape test"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/relative-to-source.css
@@ -1 +1 @@
@import "imports/foo.css";
@import "imports/foo.css";
2 changes: 2 additions & 0 deletions test/fixtures/relative.css
@@ -1,5 +1,7 @@
@import "relative/baz.css";

@import "qux.css";

foo {
foo: bar;
}
6 changes: 5 additions & 1 deletion test/fixtures/relative.expected.css
Expand Up @@ -6,6 +6,10 @@ baz {
foo: bar;
}

quux {
not: "relative/qux";
}

foo {
foo: bar;
}
}

0 comments on commit 5725285

Please sign in to comment.