Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): use preserveSymlinks option for t…
Browse files Browse the repository at this point in the history
…sconfigs 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.

(cherry picked from commit 480eb3e)
  • Loading branch information
clydin authored and alan-agius4 committed Apr 25, 2023
1 parent c62eacc commit eca366a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
PluginBuild,
} from 'esbuild';
import * as assert from 'node:assert';
import { realpath } from 'node:fs/promises';
import { platform } from 'node:os';
import * as path from 'node:path';
import { pathToFileURL } from 'node:url';
Expand Down Expand Up @@ -167,6 +168,16 @@ export function createCompilerPlugin(
async setup(build: PluginBuild): Promise<void> {
let setupWarnings: PartialMessage[] | undefined = [];

const preserveSymlinks = build.initialOptions.preserveSymlinks;
let tsconfigPath = pluginOptions.tsconfig;
if (!preserveSymlinks) {
// Use the real path of the tsconfig if not preserving symlinks.
// This ensures the TS source file paths are based on the real path of the configuration.
try {
tsconfigPath = await realpath(tsconfigPath);
} catch {}
}

// Initialize a worker pool for JavaScript transformations
const javascriptTransformer = new JavaScriptTransformer(pluginOptions, maxWorkers);

Expand Down Expand Up @@ -251,7 +262,7 @@ export function createCompilerPlugin(
const {
affectedFiles,
compilerOptions: { allowJs },
} = await compilation.initialize(pluginOptions.tsconfig, hostOptions, (compilerOptions) => {
} = await compilation.initialize(tsconfigPath, hostOptions, (compilerOptions) => {
if (
compilerOptions.target === undefined ||
compilerOptions.target < ts.ScriptTarget.ES2022
Expand Down Expand Up @@ -285,6 +296,7 @@ export function createCompilerPlugin(
inlineSourceMap: pluginOptions.sourcemap,
mapRoot: undefined,
sourceRoot: undefined,
preserveSymlinks,
};
});
shouldTsIgnoreJs = !allowJs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ function createCodeBundleOptions(
externalDependencies,
target,
inlineStyleLanguage,
preserveSymlinks,
browsers,
tailwindConfiguration,
},
Expand Down

0 comments on commit eca366a

Please sign in to comment.