Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: webpack-contrib/sass-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v13.3.0
Choose a base ref
...
head repository: webpack-contrib/sass-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v13.3.1
Choose a head ref
  • 3 commits
  • 9 files changed
  • 2 contributors

Commits on May 25, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1f99474 View commit details

Commits on May 28, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ed6f313 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6e2bfaa View commit details
Showing with 165 additions and 202 deletions.
  1. +8 −0 CHANGELOG.md
  2. +2 −2 package-lock.json
  3. +1 −1 package.json
  4. +0 −36 src/SassError.js
  5. +0 −17 src/SassWarning.js
  6. +16 −6 src/index.js
  7. +30 −32 src/utils.js
  8. +10 −10 test/__snapshots__/implementation-option.test.js.snap
  9. +98 −98 test/__snapshots__/loader.test.js.snap
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [13.3.1](https://github.com/webpack-contrib/sass-loader/compare/v13.3.0...v13.3.1) (2023-05-28)


### Bug Fixes

* error handling better ([#1141](https://github.com/webpack-contrib/sass-loader/issues/1141)) ([1f99474](https://github.com/webpack-contrib/sass-loader/commit/1f9947441ae95f7bd396886ec7a7d0ecbe939f8c))
* warnings and errors serialization ([#1142](https://github.com/webpack-contrib/sass-loader/issues/1142)) ([ed6f313](https://github.com/webpack-contrib/sass-loader/commit/ed6f3136f067e4c863077cb0d6c89c7ea8638bf8))

## [13.3.0](https://github.com/webpack-contrib/sass-loader/compare/v13.2.2...v13.3.0) (2023-05-22)


4 changes: 2 additions & 2 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-loader",
"version": "13.3.0",
"version": "13.3.1",
"description": "Sass loader for webpack",
"license": "MIT",
"repository": "webpack-contrib/sass-loader",
36 changes: 0 additions & 36 deletions src/SassError.js

This file was deleted.

17 changes: 0 additions & 17 deletions src/SassWarning.js

This file was deleted.

22 changes: 16 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@ import {
getModernWebpackImporter,
getCompileFn,
normalizeSourceMap,
errorFactory,
} from "./utils";
import SassError from "./SassError";

/**
* The sass-loader makes node-sass and dart-sass available to webpack modules.
@@ -21,10 +21,13 @@ import SassError from "./SassError";
async function loader(content) {
const options = this.getOptions(schema);
const callback = this.async();
const implementation = getSassImplementation(this, options.implementation);

if (!implementation) {
callback();
let implementation;

try {
implementation = getSassImplementation(this, options.implementation);
} catch (error) {
callback(error);

return;
}
@@ -59,7 +62,14 @@ async function loader(content) {
}
}

const compile = getCompileFn(implementation, options);
let compile;

try {
compile = getCompileFn(implementation, options);
} catch (error) {
callback(error);
return;
}

let result;

@@ -77,7 +87,7 @@ async function loader(content) {
this.addDependency(path.normalize(error.file));
}

callback(new SassError(error));
callback(errorFactory(error));

return;
}
62 changes: 30 additions & 32 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@ import path from "path";
import { klona } from "klona/full";
import async from "neo-async";

import SassWarning from "./SassWarning";

function getDefaultSassImplementation() {
let sassImplPkg = "sass";

@@ -36,43 +34,24 @@ function getSassImplementation(loaderContext, implementation) {
let resolvedImplementation = implementation;

if (!resolvedImplementation) {
try {
resolvedImplementation = getDefaultSassImplementation();
} catch (error) {
loaderContext.emitError(error);

return;
}
resolvedImplementation = getDefaultSassImplementation();
}

if (typeof resolvedImplementation === "string") {
try {
// eslint-disable-next-line import/no-dynamic-require, global-require
resolvedImplementation = require(resolvedImplementation);
} catch (error) {
loaderContext.emitError(error);

// eslint-disable-next-line consistent-return
return;
}
// eslint-disable-next-line import/no-dynamic-require, global-require
resolvedImplementation = require(resolvedImplementation);
}

const { info } = resolvedImplementation;

if (!info) {
loaderContext.emitError(new Error("Unknown Sass implementation."));

return;
throw new Error("Unknown Sass implementation.");
}

const infoParts = info.split("\t");

if (infoParts.length < 2) {
loaderContext.emitError(
new Error(`Unknown Sass implementation "${info}".`)
);

return;
throw new Error(`Unknown Sass implementation "${info}".`);
}

const [implementationName] = infoParts;
@@ -88,9 +67,7 @@ function getSassImplementation(loaderContext, implementation) {
return resolvedImplementation;
}

loaderContext.emitError(
new Error(`Unknown Sass implementation "${implementationName}".`)
);
throw new Error(`Unknown Sass implementation "${implementationName}".`);
}

/**
@@ -190,9 +167,12 @@ async function getSassOptions(
}

if (needEmitWarning) {
loaderContext.emitWarning(
new SassWarning(builtMessage, loggerOptions)
);
const warning = new Error(builtMessage);

warning.name = "SassWarning";
warning.stack = null;

loaderContext.emitWarning(warning);
} else {
logger.warn(builtMessage);
}
@@ -802,6 +782,23 @@ function normalizeSourceMap(map, rootContext) {
return newMap;
}

function errorFactory(error) {
let message;

if (error.formatted) {
message = error.formatted.replace(/^Error: /, "");
} else {
// Keep original error if `sassError.formatted` is unavailable
({ message } = error);
}

const obj = new Error(message, { cause: error });

obj.stack = null;

return obj;
}

export {
getSassImplementation,
getSassOptions,
@@ -811,4 +808,5 @@ export {
getCompileFn,
normalizeSourceMap,
isSupportedFibers,
errorFactory,
};
20 changes: 10 additions & 10 deletions test/__snapshots__/implementation-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ exports[`implementation option not specify: warnings 1`] = `[]`;

exports[`implementation option should not swallow an error when trying to load a sass implementation: errors 1`] = `
[
"ModuleError: Module Error (from ../src/cjs.js):
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Some error",
]
`;
@@ -47,43 +47,43 @@ exports[`implementation option should not swallow an error when trying to load a

exports[`implementation option should throw an error on an unknown sass implementation: errors 1`] = `
[
"ModuleError: Module Error (from ../src/cjs.js):
Unknown Sass implementation "strange-sass".",
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Error: Unknown Sass implementation "strange-sass".",
]
`;

exports[`implementation option should throw an error on an unknown sass implementation: warnings 1`] = `[]`;

exports[`implementation option should throw an error when the "info" is unparseable: errors 1`] = `
[
"ModuleError: Module Error (from ../src/cjs.js):
Unknown Sass implementation "asdfj".",
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Error: Unknown Sass implementation "asdfj".",
]
`;

exports[`implementation option should throw an error when the "info" is unparseable: warnings 1`] = `[]`;

exports[`implementation option should throw error when the "info" does not exist: errors 1`] = `
[
"ModuleError: Module Error (from ../src/cjs.js):
Unknown Sass implementation.",
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Error: Unknown Sass implementation.",
]
`;

exports[`implementation option should throw error when the "info" does not exist: warnings 1`] = `[]`;

exports[`implementation option should throw error when unresolved package: errors 1`] = `
[
"ModuleError: Module Error (from ../src/cjs.js):
Cannot find module 'unresolved' from 'src/utils.js'",
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Error: Cannot find module 'unresolved' from 'src/utils.js'",
]
`;

exports[`implementation option should throw error when unresolved package: warnings 1`] = `[]`;

exports[`implementation option should try to load using valid order: errors 1`] = `
[
"ModuleError: Module Error (from ../src/cjs.js):
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Some error sass",
]
`;
Loading