Skip to content

Commit ba8541e

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.
1 parent 0363da2 commit ba8541e

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) ?? ''),
@@ -258,7 +269,6 @@ export async function normalizeOptions(
258269
serviceWorker,
259270
poll,
260271
polyfills,
261-
preserveSymlinks,
262272
statsJson,
263273
stylePreprocessorOptions,
264274
subresourceIntegrity,
@@ -289,8 +299,7 @@ export async function normalizeOptions(
289299
poll,
290300
progress,
291301
externalPackages,
292-
// If not explicitly set, default to the Node.js process argument
293-
preserveSymlinks: preserveSymlinks ?? process.execArgv.includes('--preserve-symlinks'),
302+
preserveSymlinks,
294303
stylePreprocessorOptions,
295304
subresourceIntegrity,
296305
serverEntryPoint,

0 commit comments

Comments
 (0)