Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): prevent relative import failure w…
Browse files Browse the repository at this point in the history
…ith 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)
  • Loading branch information
clydin authored and dgp1130 committed May 4, 2023
1 parent 4994a4a commit 131cd23
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,23 @@ async function compileString(
environment: Less.Environment,
): Promise<Less.FileLoadResult> {
// Attempt direct loading as a relative path to avoid resolution overhead
const directResult = this.loadFileSync(filename, currentDirectory, options, environment);
if ('contents' in directResult) {
return directResult;
try {
return await super.loadFile(filename, currentDirectory, options, environment);
} catch (error) {
// Attempt a full resolution if not found
const fullResult = await resolver(filename, {
kind: 'import-rule',
resolveDir: currentDirectory,
});
if (fullResult.path) {
return {
filename: fullResult.path,
contents: await readFile(fullResult.path, 'utf-8'),
};
}
// Otherwise error by throwing the failing direct result
throw error;
}

// Attempt a full resolution if not found
const fullResult = await resolver(filename, {
kind: 'import-rule',
resolveDir: currentDirectory,
});
if (fullResult.path) {
return {
filename: fullResult.path,
contents: await readFile(fullResult.path, 'utf-8'),
};
}

// Otherwise error by throwing the failing direct result
throw directResult.error;
}
})();

Expand Down

0 comments on commit 131cd23

Please sign in to comment.