Skip to content

Commit 87a4f25

Browse files
fix: deprecation warning (#415)
1 parent a48a770 commit 87a4f25

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import LessError from "./LessError";
99
async function lessLoader(source) {
1010
const options = this.getOptions(schema);
1111
const callback = this.async();
12-
const lessOptions = getLessOptions(this, options);
12+
const webpackContextSymbol = Symbol("loaderContext");
13+
const lessOptions = getLessOptions(this, {
14+
...options,
15+
webpackContextSymbol,
16+
});
1317
const useSourceMap =
1418
typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap;
1519

@@ -44,9 +48,7 @@ async function lessLoader(source) {
4448
return;
4549
}
4650

47-
if ("webpackLoaderContext" in less) {
48-
delete less.webpackLoaderContext;
49-
}
51+
delete less[webpackContextSymbol];
5052

5153
const { css, imports } = result;
5254

src/utils.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,26 +182,27 @@ function getLessOptions(loaderContext, loaderOptions) {
182182
lessOptions.plugins.unshift(createWebpackLessPlugin(loaderContext));
183183
}
184184

185-
const webpackContextDeprecated = util.deprecate(
186-
(context) => context,
187-
"less.webpackLoaderContext is deprecated and will be removed in next major release. Instead use pluginManager.webpackLoaderContext (https://webpack.js.org/loaders/less-loader/#plugins)"
188-
);
189-
190185
lessOptions.plugins.unshift({
191186
install(lessProcessor, pluginManager) {
192187
// eslint-disable-next-line no-param-reassign
193188
pluginManager.webpackLoaderContext = loaderContext;
194189

195-
// Todo remove in next major release
196-
if (typeof lessProcessor.webpackLoaderContext === "undefined") {
197-
Object.defineProperty(lessProcessor, "webpackLoaderContext", {
198-
configurable: true,
190+
// Todo remove in next major release `lessProcessor[webpackContextSymbol]`
191+
const { webpackContextSymbol } = options;
199192

200-
get() {
201-
return webpackContextDeprecated(loaderContext);
202-
},
203-
});
204-
}
193+
// eslint-disable-next-line no-param-reassign
194+
lessProcessor[webpackContextSymbol] = loaderContext;
195+
196+
Object.defineProperty(lessProcessor, "webpackLoaderContext", {
197+
configurable: true,
198+
199+
get() {
200+
util.deprecate(() => {},
201+
"less.webpackLoaderContext is deprecated and will be removed in next major release. Instead use pluginManager.webpackLoaderContext (https://webpack.js.org/loaders/less-loader/#plugins)")();
202+
203+
return lessProcessor[webpackContextSymbol];
204+
},
205+
});
205206
},
206207
});
207208

0 commit comments

Comments
 (0)