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: add dart-sass support default #626

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 15 additions & 1 deletion lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,21 @@ function sassLoader(content) {
return;
}

const render = getRenderFuncFromSassImpl(options.implementation || require("node-sass"));
const render = getRenderFuncFromSassImpl(options.implementation || (() => {
let sassImplPkg = "node-sass";

try {
require.resolve("node-sass");
} catch (error) {
try {
require.resolve("sass");
sassImplPkg = "sass";
} catch (error) {
sassImplPkg = "node-sass";
}
}
return require(sassImplPkg);
})());

render(options, (err, result) => {
if (err) {
Expand Down
25 changes: 24 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ implementations.forEach(implementation => {
const originalResolve = module._resolveFilename;

module._resolveFilename = function (filename) {
if (!filename.match(/node-sass/)) {
if (!filename.match(/^(node-sass|sass)$/)) {
return originalResolve.apply(this, arguments);
}
const err = new Error("Some error");
Expand All @@ -316,6 +316,29 @@ implementations.forEach(implementation => {
done();
});
});
it("should not swallow errors when trying to load dart-sass", (done) => {
mockRequire.reRequire(pathToSassLoader);
const module = require("module");
const originalResolve = module._resolveFilename;

module._resolveFilename = function (filename) {
if (!filename.match(/^(node-sass|sass)$/)) {
return originalResolve.apply(this, arguments);
}
const err = new Error("Some error");

err.code = "MODULE_NOT_FOUND";
throw err;
};
runWebpack({
entry: pathToSassLoader + "!" + pathToErrorFile
}, { implementation: null }, (err) => {
module._resolveFilename = originalResolve;
mockRequire.reRequire("sass");
err.message.should.match(/Some error/);
done();
});
});
it("should output a message when the Sass info is unparseable", (done) => {
mockRequire.reRequire(pathToSassLoader);
runWebpack({
Expand Down