Skip to content

Commit

Permalink
fix: prefer scss, sass and css extensions in resolving (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Dec 14, 2018
1 parent 2adcca3 commit f524223
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .nycrc
Expand Up @@ -9,6 +9,6 @@
"lines": 97,
"statements": 97,
"functions": 100,
"branches": 90,
"branches": 89,
"check-coverage": true
}
23 changes: 8 additions & 15 deletions .travis.yml
Expand Up @@ -8,28 +8,21 @@ jobs:
fast_finish: true
allow_failures:
- env: WEBPACK_VERSION=canary
- node_js: 9
include:
- &test-latest
stage: Webpack latest
node_js: 6
env: WEBPACK_VERSION=latest JOB_PART=test
script: npm run travis:$JOB_PART
- <<: *test-latest
node_js: 8
- node_js: 6
env: WEBPACK_VERSION=latest JOB_PART=lint
script: npm run travis:$JOB_PART
- <<: *test-latest
node_js: 8
- node_js: 6
env: WEBPACK_VERSION=latest JOB_PART=test
script: npm run travis:$JOB_PART
- node_js: 8
env: WEBPACK_VERSION=latest JOB_PART=coverage
script: npm run travis:$JOB_PART
after_success: 'bash <(curl -s https://codecov.io/bash)'
- stage: Webpack canary
node_js: 8
env: WEBPACK_VERSION=4.0.0 JOB_PART=test
- node_js: 10
env: WEBPACK_VERSION=latest JOB_PART=test
script: npm run travis:$JOB_PART
- stage: NodeJS Next
node_js: 9
- node_js: 11
env: WEBPACK_VERSION=latest JOB_PART=test
script: npm run travis:$JOB_PART
before_install:
Expand Down
15 changes: 10 additions & 5 deletions lib/loader.js
Expand Up @@ -35,14 +35,19 @@ function sassLoader(content) {
);
}

let resolve = pify(this.resolve);

// Supported since v4.27.0
if (this.getResolve) {
resolve = this.getResolve({
extensions: ['.scss', '.sass', '.css'],
});
}

const options = normalizeOptions(
this,
content,
webpackImporter(
resourcePath,
pify(this.resolve.bind(this)),
addNormalizedDependency
)
webpackImporter(resourcePath, resolve, addNormalizedDependency)
);

// Skip empty files, otherwise it will stop webpack, see issue #21
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/index.test.js
Expand Up @@ -295,7 +295,7 @@ implementations.forEach((implementation) => {
// This number needs to be updated if imports.scss or any dependency of that changes.
// Node Sass includes a duplicate entry, Dart Sass does not.
sourceMap.sources.should.have.length(
implementation === nodeSass ? 11 : 10
implementation === nodeSass ? 12 : 11
);
sourceMap.sources.forEach((sourcePath) =>
fs.existsSync(path.resolve(sourceMap.sourceRoot, sourcePath))
Expand Down
1 change: 1 addition & 0 deletions test/node_modules/@org/style.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/node_modules/@org/style.scss

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/node_modules/scss/style.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/node_modules/scss/style.scss

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/sass/imports.sass
Expand Up @@ -24,3 +24,5 @@
@import ~module
/* @import ~another */
@import ~another
// Should prefer `scss`
@import "~@org/style"
3 changes: 3 additions & 0 deletions test/scss/imports.scss
Expand Up @@ -24,3 +24,6 @@
@import "~module";
/* @import "~another"; */
@import "~another";
/* @import "~@org/style"; */
// Should prefer `scss`
@import "~@org/style";

0 comments on commit f524223

Please sign in to comment.