Skip to content

Commit 2e007b7

Browse files
committed
refactor(@angular-devkit/build-angular): update SASS worker to provide fromImport.
Since sass 1.33.0, an importer can determine whether it’s being called from an `@import` rule by checking `this.fromImport`. This API, is now being used by `sass-loader` version 12.
1 parent 85e8b59 commit 2e007b7

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

packages/angular_devkit/build_angular/src/sass/sass-service.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,17 @@ export class SassWorkerImplementation {
173173

174174
mainImporterPort.on(
175175
'message',
176-
({ id, url, prev }: { id: number; url: string; prev: string }) => {
176+
({
177+
id,
178+
url,
179+
prev,
180+
fromImport,
181+
}: {
182+
id: number;
183+
url: string;
184+
prev: string;
185+
fromImport: boolean;
186+
}) => {
177187
const request = this.requests.get(id);
178188
if (!request?.importers) {
179189
mainImporterPort.postMessage(null);
@@ -183,7 +193,7 @@ export class SassWorkerImplementation {
183193
return;
184194
}
185195

186-
this.processImporters(request.importers, url, prev)
196+
this.processImporters(request.importers, url, prev, fromImport)
187197
.then((result) => {
188198
mainImporterPort.postMessage(result);
189199
})
@@ -207,12 +217,13 @@ export class SassWorkerImplementation {
207217
importers: Iterable<Importer>,
208218
url: string,
209219
prev: string,
220+
fromImport: boolean,
210221
): Promise<ImporterReturnType> {
211222
let result = null;
212223
for (const importer of importers) {
213224
result = await new Promise<ImporterReturnType>((resolve) => {
214225
// Importers can be both sync and async
215-
const innerResult = importer(url, prev, resolve);
226+
const innerResult = importer.call({ fromImport }, url, prev, resolve);
216227
if (innerResult !== undefined) {
217228
resolve(innerResult);
218229
}

packages/angular_devkit/build_angular/src/sass/worker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ parentPort.on('message', (message: RenderRequestMessage | InitMessage) => {
6565
// This process must be synchronous from the perspective of dart-sass. The `Atomics`
6666
// functions combined with the shared memory `importSignal` and the Node.js
6767
// `receiveMessageOnPort` function are used to ensure synchronous behavior.
68-
options.importer = (url, prev) => {
68+
options.importer = function (url, prev) {
6969
Atomics.store(importerSignal, 0, 0);
70-
workerImporterPort.postMessage({ id, url, prev });
70+
// `this.fromImport` was added in dart-sass in 1.33.0, `@types/sass` doesn't include it yet.
71+
const { fromImport } = this as { fromImport: boolean };
72+
workerImporterPort.postMessage({ id, url, prev, fromImport });
7173
Atomics.wait(importerSignal, 0, 0);
7274

7375
return receiveMessageOnPort(workerImporterPort)?.message as ImporterReturnType;

0 commit comments

Comments
 (0)