Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): use workspace real path when not …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
clydin authored and alan-agius4 committed Nov 23, 2023
1 parent 0634a4e commit 7747495
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { BuilderContext } from '@angular-devkit/architect';
import type { Plugin } from 'esbuild';
import { realpathSync } from 'node:fs';
import { access, constants } from 'node:fs/promises';
import { createRequire } from 'node:module';
import path from 'node:path';
Expand Down Expand Up @@ -83,7 +84,17 @@ export async function normalizeOptions(
options: ApplicationBuilderInternalOptions,
plugins?: Plugin[],
) {
const workspaceRoot = context.workspaceRoot;
// If not explicitly set, default to the Node.js process argument
const preserveSymlinks =
options.preserveSymlinks ?? process.execArgv.includes('--preserve-symlinks');

// Setup base paths based on workspace root and project information
const workspaceRoot = preserveSymlinks
? context.workspaceRoot
: // NOTE: promises.realpath should not be used here since it uses realpath.native which
// can cause case conversion and other undesirable behavior on Windows systems.
// ref: https://github.com/nodejs/node/issues/7726
realpathSync(context.workspaceRoot);
const projectMetadata = await context.getProjectMetadata(projectName);
const projectRoot = normalizeDirectoryPath(
path.join(workspaceRoot, (projectMetadata.root as string | undefined) ?? ''),
Expand Down Expand Up @@ -244,7 +255,6 @@ export async function normalizeOptions(
serviceWorker,
poll,
polyfills,
preserveSymlinks,
statsJson,
stylePreprocessorOptions,
subresourceIntegrity,
Expand Down Expand Up @@ -275,8 +285,7 @@ export async function normalizeOptions(
poll,
progress,
externalPackages,
// If not explicitly set, default to the Node.js process argument
preserveSymlinks: preserveSymlinks ?? process.execArgv.includes('--preserve-symlinks'),
preserveSymlinks,
stylePreprocessorOptions,
subresourceIntegrity,
serverEntryPoint,
Expand Down

0 comments on commit 7747495

Please sign in to comment.