Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular-devkit/build-angular): avoid native realpath in application builder #26453

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -258,7 +269,6 @@ export async function normalizeOptions(
serviceWorker,
poll,
polyfills,
preserveSymlinks,
statsJson,
stylePreprocessorOptions,
subresourceIntegrity,
Expand Down Expand Up @@ -289,8 +299,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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
PluginBuild,
} from 'esbuild';
import assert from 'node:assert';
import { realpath } from 'node:fs/promises';
import { realpathSync } from 'node:fs';
import * as path from 'node:path';
import { maxWorkers } from '../../../utils/environment-options';
import { JavaScriptTransformer } from '../javascript-transformer';
Expand Down Expand Up @@ -61,8 +61,11 @@ export function createCompilerPlugin(
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.
// 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
try {
tsconfigPath = await realpath(tsconfigPath);
tsconfigPath = realpathSync(tsconfigPath);
clydin marked this conversation as resolved.
Show resolved Hide resolved
} catch {}
}

Expand Down