Skip to content

Commit 17b7e1b

Browse files
alan-agius4clydin
authored andcommitted
fix(@angular-devkit/build-angular): issue warning when using deprecated tilde imports
With this change we add a warning when using deprecated tilde/`~` imports. (cherry picked from commit 9aab9ad)
1 parent 918418e commit 17b7e1b

File tree

1 file changed

+29
-1
lines changed
  • packages/angular_devkit/build_angular/src/webpack/configs

1 file changed

+29
-1
lines changed

packages/angular_devkit/build_angular/src/webpack/configs/styles.ts

+29-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import * as fs from 'fs';
1010
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
1111
import * as path from 'path';
12-
import { Configuration, RuleSetUseItem } from 'webpack';
12+
import { Configuration, RuleSetUseItem, WebpackError } from 'webpack';
1313
import { StyleElement } from '../../builders/browser/schema';
1414
import { SassWorkerImplementation } from '../../sass/sass-service';
1515
import { WebpackConfigOptions } from '../../utils/build-options';
@@ -112,11 +112,21 @@ export function getStylesConfig(wco: WebpackConfigOptions): Configuration {
112112
}
113113

114114
const sassImplementation = new SassWorkerImplementation();
115+
const sassTildeUsageMessage = new Set<string>();
116+
115117
extraPlugins.push({
116118
apply(compiler) {
117119
compiler.hooks.shutdown.tap('sass-worker', () => {
118120
sassImplementation.close();
119121
});
122+
123+
compiler.hooks.afterCompile.tap('sass-worker', (compilation) => {
124+
for (const message of sassTildeUsageMessage) {
125+
compilation.warnings.push(new WebpackError(message));
126+
}
127+
128+
sassTildeUsageMessage.clear();
129+
});
120130
},
121131
});
122132

@@ -274,6 +284,15 @@ export function getStylesConfig(wco: WebpackConfigOptions): Configuration {
274284
implementation: sassImplementation,
275285
sourceMap: true,
276286
sassOptions: {
287+
importer: (url: string, from: string) => {
288+
if (url.charAt(0) === '~') {
289+
sassTildeUsageMessage.add(
290+
`'${from}' imports '${url}' with a tilde. Usage of '~' in imports is deprecated.`,
291+
);
292+
}
293+
294+
return null;
295+
},
277296
// Prevent use of `fibers` package as it no longer works in newer Node.js versions
278297
fiber: false,
279298
// bootstrap-sass requires a minimum precision of 8
@@ -306,6 +325,15 @@ export function getStylesConfig(wco: WebpackConfigOptions): Configuration {
306325
implementation: sassImplementation,
307326
sourceMap: true,
308327
sassOptions: {
328+
importer: (url: string, from: string) => {
329+
if (url.charAt(0) === '~') {
330+
sassTildeUsageMessage.add(
331+
`'${from}' imports '${url}' with a tilde. Usage of '~' in imports is deprecated.`,
332+
);
333+
}
334+
335+
return null;
336+
},
309337
// Prevent use of `fibers` package as it no longer works in newer Node.js versions
310338
fiber: false,
311339
indentedSyntax: true,

0 commit comments

Comments
 (0)