Skip to content

fix: prefer scss, sass and css extension in resolving #645

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

Merged
merged 1 commit into from
Dec 14, 2018
Merged
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
2 changes: 1 addition & 1 deletion .nycrc
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@
@import "~module";
/* @import "~another"; */
@import "~another";
/* @import "~@org/style"; */
// Should prefer `scss`
@import "~@org/style";