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

feat: support sass field in package.json #647

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
1 change: 1 addition & 0 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function sassLoader(content) {
// Supported since v4.27.0
if (this.getResolve) {
resolve = this.getResolve({
mainFields: ['sass', 'main'],
extensions: ['.scss', '.sass', '.css'],
});
}
Expand Down
2 changes: 2 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ implementations.forEach((implementation) => {
},
}
));
it('should resolve sass field correctly', () =>
execTest(`import-sass-field`));
});
describe('custom importers', () => {
it('should use custom importer', () =>
Expand Down
2 changes: 2 additions & 0 deletions test/node_modules/sass-sass-field/nested/style.sass

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

12 changes: 12 additions & 0 deletions test/node_modules/sass-sass-field/package.json

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-sass-field/nested/style.scss

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

12 changes: 12 additions & 0 deletions test/node_modules/scss-sass-field/package.json

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

1 change: 1 addition & 0 deletions test/sass/import-sass-field.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "~sass-sass-field"
1 change: 1 addition & 0 deletions test/scss/import-sass-field.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "~scss-sass-field";
22 changes: 22 additions & 0 deletions test/tools/createSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ function createSpec(ext) {
basePath,
path.resolve(testFolder, ext, 'another', `alias.${ext}`)
);
const pathToScssSassField = path.relative(
basePath,
path.resolve(
testFolder,
'node_modules',
'scss-sass-field',
'nested',
'style.scss'
)
);
const pathToSASSSassField = path.relative(
basePath,
path.resolve(
testFolder,
'node_modules',
'sass-sass-field',
'nested',
'style.sass'
)
);

fs.readdirSync(path.join(testFolder, ext))
.filter(
Expand All @@ -57,6 +77,8 @@ function createSpec(ext) {
if (/\.css$/.test(url) === false) {
// eslint-disable-next-line no-param-reassign
url = url
.replace(/^~scss-sass-field/, pathToScssSassField)
.replace(/^~sass-sass-field/, pathToSASSSassField)
.replace(/^~bootstrap-sass/, pathToBootstrap)
.replace(/^~@org\/pkg/, pathToScopedNpmPkg)
.replace(/^~module/, pathToModule)
Expand Down