Skip to content

Commit 7747495

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular-devkit/build-angular): use workspace real path when not preserving symlinks
When not preserving symlinks (the default), the workspace root path should be converted to the real path on the filesystem to ensure that resolution of all other path-based build options reflects the actual location of the files. This ensures that typescript and esbuild resolve files in a consistent manner and avoids hard to diagnose errors involving missing files at build time. (cherry picked from commit ba8541e)
1 parent 0634a4e commit 7747495

File tree

1 file changed

+13
-4
lines changed
  • packages/angular_devkit/build_angular/src/builders/application

1 file changed

+13
-4
lines changed

packages/angular_devkit/build_angular/src/builders/application/options.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import { BuilderContext } from '@angular-devkit/architect';
1010
import type { Plugin } from 'esbuild';
11+
import { realpathSync } from 'node:fs';
1112
import { access, constants } from 'node:fs/promises';
1213
import { createRequire } from 'node:module';
1314
import path from 'node:path';
@@ -83,7 +84,17 @@ export async function normalizeOptions(
8384
options: ApplicationBuilderInternalOptions,
8485
plugins?: Plugin[],
8586
) {
86-
const workspaceRoot = context.workspaceRoot;
87+
// If not explicitly set, default to the Node.js process argument
88+
const preserveSymlinks =
89+
options.preserveSymlinks ?? process.execArgv.includes('--preserve-symlinks');
90+
91+
// Setup base paths based on workspace root and project information
92+
const workspaceRoot = preserveSymlinks
93+
? context.workspaceRoot
94+
: // NOTE: promises.realpath should not be used here since it uses realpath.native which
95+
// can cause case conversion and other undesirable behavior on Windows systems.
96+
// ref: https://github.com/nodejs/node/issues/7726
97+
realpathSync(context.workspaceRoot);
8798
const projectMetadata = await context.getProjectMetadata(projectName);
8899
const projectRoot = normalizeDirectoryPath(
89100
path.join(workspaceRoot, (projectMetadata.root as string | undefined) ?? ''),
@@ -244,7 +255,6 @@ export async function normalizeOptions(
244255
serviceWorker,
245256
poll,
246257
polyfills,
247-
preserveSymlinks,
248258
statsJson,
249259
stylePreprocessorOptions,
250260
subresourceIntegrity,
@@ -275,8 +285,7 @@ export async function normalizeOptions(
275285
poll,
276286
progress,
277287
externalPackages,
278-
// If not explicitly set, default to the Node.js process argument
279-
preserveSymlinks: preserveSymlinks ?? process.execArgv.includes('--preserve-symlinks'),
288+
preserveSymlinks,
280289
stylePreprocessorOptions,
281290
subresourceIntegrity,
282291
serverEntryPoint,

0 commit comments

Comments
 (0)