Skip to content

Commit

Permalink
fix: deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito committed Apr 14, 2021
1 parent a48a770 commit 9a2f117
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
10 changes: 6 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import LessError from "./LessError";
async function lessLoader(source) {
const options = this.getOptions(schema);
const callback = this.async();
const lessOptions = getLessOptions(this, options);
const webpackContextSymbol = Symbol("loaderContext");
const lessOptions = getLessOptions(this, {
...options,
webpackContextSymbol,
});
const useSourceMap =
typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap;

Expand Down Expand Up @@ -44,9 +48,7 @@ async function lessLoader(source) {
return;
}

if ("webpackLoaderContext" in less) {
delete less.webpackLoaderContext;
}
delete less[webpackContextSymbol];

const { css, imports } = result;

Expand Down
29 changes: 15 additions & 14 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,27 @@ function getLessOptions(loaderContext, loaderOptions) {
lessOptions.plugins.unshift(createWebpackLessPlugin(loaderContext));
}

const webpackContextDeprecated = util.deprecate(
(context) => context,
"less.webpackLoaderContext is deprecated and will be removed in next major release. Instead use pluginManager.webpackLoaderContext (https://webpack.js.org/loaders/less-loader/#plugins)"
);

lessOptions.plugins.unshift({
install(lessProcessor, pluginManager) {
// eslint-disable-next-line no-param-reassign
pluginManager.webpackLoaderContext = loaderContext;

// Todo remove in next major release
if (typeof lessProcessor.webpackLoaderContext === "undefined") {
Object.defineProperty(lessProcessor, "webpackLoaderContext", {
configurable: true,
// Todo remove in next major release `lessProcessor[webpackContextSymbol]`
const { webpackContextSymbol } = options;

get() {
return webpackContextDeprecated(loaderContext);
},
});
}
// eslint-disable-next-line no-param-reassign
lessProcessor[webpackContextSymbol] = loaderContext;

Object.defineProperty(lessProcessor, "webpackLoaderContext", {
configurable: true,

get() {
util.deprecate(() => {},
"less.webpackLoaderContext is deprecated and will be removed in next major release. Instead use pluginManager.webpackLoaderContext (https://webpack.js.org/loaders/less-loader/#plugins)")();

return lessProcessor[webpackContextSymbol];
},
});
},
});

Expand Down

0 comments on commit 9a2f117

Please sign in to comment.