Skip to content

Commit 4138fde

Browse files
committed
fixup! fix(@angular/build): ensure Sass importers return global Promise instances
1 parent 54583ea commit 4138fde

2 files changed

Lines changed: 1 addition & 39 deletions

File tree

‎packages/angular/build/src/tools/esbuild/stylesheets/sass-language_spec.ts‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -342,26 +342,12 @@ describe('sass-language', () => {
342342
}
343343
}
344344

345-
const nonRebasingCompiler = new SassCompiler(false);
346345
globalThis.Promise = ZoneLikePromise as unknown as PromiseConstructor;
347346
try {
348347
const application = await compile(buttonStylesheet);
349348
expect(application).toContain('content: "project";');
350-
351-
const nonRebasingResult = await nonRebasingCompiler.compileStringAsync("@use 'theme';", {
352-
importers: [
353-
{
354-
findFileUrl: async (url) =>
355-
url === 'theme'
356-
? pathToFileURL(join(projectRoot, 'node_modules', 'theme', '_index.scss'))
357-
: null,
358-
},
359-
],
360-
});
361-
expect(nonRebasingResult.css).toContain('content: "project";');
362349
} finally {
363350
globalThis.Promise = originalPromise;
364-
await nonRebasingCompiler.close();
365351
}
366352
});
367353
});

‎packages/angular/build/src/tools/sass/sass-service.ts‎

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ function isFileImporter(value: Importers): value is FileImporter {
3737
return 'findFileUrl' in value;
3838
}
3939

40-
function resolvePromise<T>(value: T | Promise<T>): T | Promise<T> {
41-
return value && typeof value === 'object' && 'then' in value ? Promise.resolve(value) : value;
42-
}
43-
4440
/**
4541
* A Sass renderer implementation that uses the persistent Dart Sass embedded compiler
4642
* daemon (`sass-embedded`) communicating over standard input/output with protocol buffers,
@@ -115,27 +111,7 @@ export class SassCompiler {
115111
const compiler = await this.#ensureAsyncCompiler();
116112

117113
if (!this.rebase) {
118-
return compiler.compileStringAsync(source, {
119-
...options,
120-
importers: options.importers?.map((importer) => {
121-
if (isFileImporter(importer)) {
122-
return {
123-
...importer,
124-
findFileUrl: (url, context) => resolvePromise(importer.findFileUrl(url, context)),
125-
};
126-
}
127-
128-
if ('canonicalize' in importer) {
129-
return {
130-
...importer,
131-
canonicalize: (url, context) => resolvePromise(importer.canonicalize(url, context)),
132-
load: (canonicalUrl) => resolvePromise(importer.load(canonicalUrl)),
133-
};
134-
}
135-
136-
return importer;
137-
}),
138-
});
114+
return compiler.compileStringAsync(source, options);
139115
}
140116

141117
const { functions, importers, importer, url, logger, ...serializableOptions } = options;

0 commit comments

Comments
 (0)