Skip to content

Commit 480eb3e

Browse files
clydinangular-robot[bot]
authored andcommitted
fix(@angular-devkit/build-angular): use preserveSymlinks option for tsconfigs in esbuild builder
When using the esbuild-based browser application builder, the tsconfig path will now be properly converted to the realpath when the `preserveSymlinks` option is disabled (the default). This ensures that TypeScript source files will be properly matched with the bundler's resolved paths when symlinks are used and the `preserveSymlinks` option is not enabled. This is needed to properly support the use of bazel with rules_js.
1 parent 5645fc8 commit 480eb3e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/compiler-plugin.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
PluginBuild,
1717
} from 'esbuild';
1818
import * as assert from 'node:assert';
19+
import { realpath } from 'node:fs/promises';
1920
import { platform } from 'node:os';
2021
import * as path from 'node:path';
2122
import { pathToFileURL } from 'node:url';
@@ -167,6 +168,16 @@ export function createCompilerPlugin(
167168
async setup(build: PluginBuild): Promise<void> {
168169
let setupWarnings: PartialMessage[] | undefined = [];
169170

171+
const preserveSymlinks = build.initialOptions.preserveSymlinks;
172+
let tsconfigPath = pluginOptions.tsconfig;
173+
if (!preserveSymlinks) {
174+
// Use the real path of the tsconfig if not preserving symlinks.
175+
// This ensures the TS source file paths are based on the real path of the configuration.
176+
try {
177+
tsconfigPath = await realpath(tsconfigPath);
178+
} catch {}
179+
}
180+
170181
// Initialize a worker pool for JavaScript transformations
171182
const javascriptTransformer = new JavaScriptTransformer(pluginOptions, maxWorkers);
172183

@@ -251,7 +262,7 @@ export function createCompilerPlugin(
251262
const {
252263
affectedFiles,
253264
compilerOptions: { allowJs },
254-
} = await compilation.initialize(pluginOptions.tsconfig, hostOptions, (compilerOptions) => {
265+
} = await compilation.initialize(tsconfigPath, hostOptions, (compilerOptions) => {
255266
if (
256267
compilerOptions.target === undefined ||
257268
compilerOptions.target < ts.ScriptTarget.ES2022
@@ -285,6 +296,7 @@ export function createCompilerPlugin(
285296
inlineSourceMap: pluginOptions.sourcemap,
286297
mapRoot: undefined,
287298
sourceRoot: undefined,
299+
preserveSymlinks,
288300
};
289301
});
290302
shouldTsIgnoreJs = !allowJs;

packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ function createCodeBundleOptions(
395395
externalDependencies,
396396
target,
397397
inlineStyleLanguage,
398+
preserveSymlinks,
398399
browsers,
399400
tailwindConfiguration,
400401
},

0 commit comments

Comments
 (0)