Skip to content

Commit dbacadd

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular/build): show unexpected Sass import resolution errors
When attempting to resolve a Sass import, failure to read the contents of a directory that is not caused by a non-existent directory will now cause an exception to be thrown. This prevents abnormal situations from being hidden during the build. A deprecated Sass interface was also replaced and was a type only change. (cherry picked from commit 7223c3f)
1 parent 41ae96e commit dbacadd

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/angular/build/src/tools/sass/rebasing-importer.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { readFileSync, readdirSync, statSync } from 'node:fs';
1212
import { basename, dirname, extname, join, relative } from 'node:path';
1313
import { fileURLToPath, pathToFileURL } from 'node:url';
1414
import type { CanonicalizeContext, Importer, ImporterResult, Syntax } from 'sass';
15+
import { assertIsError } from '../../utils/error';
1516
import { findUrls } from './lexer';
1617

1718
/**
@@ -224,8 +225,16 @@ export class RelativeUrlRebasingImporter extends UrlRebasingImporter {
224225
let entries;
225226
try {
226227
entries = readdirSync(directory, { withFileTypes: true });
227-
} catch {
228-
return null;
228+
} catch (error) {
229+
assertIsError(error);
230+
// If the containing directory does not exist return null to indicate it cannot be resolved
231+
if (error.code === 'ENOENT') {
232+
return null;
233+
}
234+
235+
throw new Error(`Error reading directory ["${directory}"] while resolving Sass import`, {
236+
cause: error,
237+
});
229238
}
230239

231240
foundDefaults = [];
@@ -236,7 +245,7 @@ export class RelativeUrlRebasingImporter extends UrlRebasingImporter {
236245
let isFile: boolean;
237246

238247
if (entry.isSymbolicLink()) {
239-
const stats = statSync(join(entry.path, entry.name));
248+
const stats = statSync(join(directory, entry.name));
240249
isDirectory = stats.isDirectory();
241250
isFile = stats.isFile();
242251
} else {

packages/angular/build/src/tools/sass/worker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
Exception,
1616
FileImporter,
1717
SourceSpan,
18-
StringOptionsWithImporter,
18+
StringOptions,
1919
compileString,
2020
} from 'sass';
2121
import {
@@ -43,7 +43,7 @@ interface RenderRequestMessage {
4343
/**
4444
* The Sass options to provide to the `dart-sass` compile function.
4545
*/
46-
options: Omit<StringOptionsWithImporter<'sync'>, 'url'> & { url: string };
46+
options: Omit<StringOptions<'sync'>, 'url'> & { url: string };
4747
/**
4848
* Indicates the request has a custom importer function on the main thread.
4949
*/

0 commit comments

Comments
 (0)