Skip to content

Commit 131cd23

Browse files
clydindgp1130
authored andcommitted
fix(@angular-devkit/build-angular): prevent relative import failure with Less in esbuild builder
When using the esbuild-based browser application builder, relative Less imports could cause a fatal exception. This has now been corrected. (cherry picked from commit 57f0be7)
1 parent 4994a4a commit 131cd23

File tree

1 file changed

+16
-18
lines changed
  • packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets

1 file changed

+16
-18
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/less-plugin.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,23 @@ async function compileString(
8686
environment: Less.Environment,
8787
): Promise<Less.FileLoadResult> {
8888
// Attempt direct loading as a relative path to avoid resolution overhead
89-
const directResult = this.loadFileSync(filename, currentDirectory, options, environment);
90-
if ('contents' in directResult) {
91-
return directResult;
89+
try {
90+
return await super.loadFile(filename, currentDirectory, options, environment);
91+
} catch (error) {
92+
// Attempt a full resolution if not found
93+
const fullResult = await resolver(filename, {
94+
kind: 'import-rule',
95+
resolveDir: currentDirectory,
96+
});
97+
if (fullResult.path) {
98+
return {
99+
filename: fullResult.path,
100+
contents: await readFile(fullResult.path, 'utf-8'),
101+
};
102+
}
103+
// Otherwise error by throwing the failing direct result
104+
throw error;
92105
}
93-
94-
// Attempt a full resolution if not found
95-
const fullResult = await resolver(filename, {
96-
kind: 'import-rule',
97-
resolveDir: currentDirectory,
98-
});
99-
if (fullResult.path) {
100-
return {
101-
filename: fullResult.path,
102-
contents: await readFile(fullResult.path, 'utf-8'),
103-
};
104-
}
105-
106-
// Otherwise error by throwing the failing direct result
107-
throw directResult.error;
108106
}
109107
})();
110108

0 commit comments

Comments
 (0)