Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix importing files with dots #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,3 @@ rules:
- always
- propertyName: false
singleValue: false

13 changes: 9 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Configuration options are documented at:
# http://docs.travis-ci.com/user/languages/javascript-with-nodejs/
language: node_js
node_js:
- "0.10"
- node
- '0.10'
- '0.12'
- '4.0'
- '4.1'
- '5.0'
- iojs
before_install:
before_script:
- npm install -g bower
- cd tests
- cd test
- bower install -f
- cd ..
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var importOnce = function importOnce(data, done) {
* they leave off the partial prefix and the suffix.
* This code creates the possible extensions, whether it is a partial
* and whether it is a directory index file having those
* same possible variations. If the import contains an extension,
* same possible variations. If the import contains a valid extension,
* then it is left alone.
*
**/
Expand All @@ -51,6 +51,8 @@ var getFileNames = function getFileNames(abstractName) {
directory,
basename;

// If the name has a Sass extension, treat it as a path to a real file, and as a fallback
// look for the same file with a prefix.
if ([ '.scss', '.sass' ].indexOf(path.extname(abstractName)) !== -1) {
directory = path.dirname(abstractName);
basename = path.basename(abstractName);
Expand All @@ -59,9 +61,11 @@ var getFileNames = function getFileNames(abstractName) {
names.push(path.join(directory, prefix + basename));
});
}
else if (path.extname(abstractName)) {
// If the name has a different valid extension, treat it as a path to a real file.
else if ([ '.css', '.json', '.yaml' ].indexOf(path.extname(abstractName)) !== -1) {
names.push(abstractName);
}
// Otherwise, the name is abstract and all variants should be searched.
else {
directory = path.dirname(abstractName);
basename = path.basename(abstractName);
Expand Down Expand Up @@ -308,7 +312,7 @@ var importer = function importer(uri, prev, done) {
file = path.resolve(path.dirname(prev), makeFsPath(uri));
raf(uri, file, function (err, data) {
if (err) {
console.log(err.toString());
console.log(err.toString()); // eslint-disable-line no-console
done({});
}
else {
Expand All @@ -319,7 +323,7 @@ var importer = function importer(uri, prev, done) {
else {
raf(uri, process.cwd(), function (err, data) {
if (err) {
console.log(err.toString());
console.log(err.toString()); // eslint-disable-line no-console
done({});
}
else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Custom importer for node-sass that only allows a file to be imported once. Includes additional import bonuses including importing CSS files directly into Sass, automagic Bower imports, the ability to import an `index` file from within a folder name, and the ability to import JSON and YAML files as Sass maps. Inspired by Eyeglass.",
"main": "index.js",
"scripts": {
"test": "cd tests && ../node_modules/.bin/mocha ./"
"test": "mocha"
},
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions test/.bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "../bower_components"
}
2 changes: 1 addition & 1 deletion tests/bower.json → test/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"license": "MIT",
"devDependencies": {
"bootstrap": "~3.3.4",
"bootstrap": "3.3.4",
"sass-toolkit": "~2.9.0",
"breakpoint-sass": "~2.5.0"
}
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions test/css/import-with-dot.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.some-class-in-dotted-file {
color: blue; }
Loading