From 7d9876a23cf3c40514632c71d4121dad59624b90 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Fri, 7 Apr 2023 09:01:21 -0400 Subject: [PATCH] fix(@angular-devkit/build-angular): ensure directories are properly ignored in esbuild builder When using the esbuild-based browser application builder in watch mode, the underlying file watcher based on chokidar would previously not fully ignore the output path if the path contained a trailing slash. To workaround this, directory paths based on supplied options are now normalized to remove any trailing slashes. --- .../src/builders/browser-esbuild/options.ts | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/options.ts b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/options.ts index d7049711340c..7f4f68bc4a4a 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/options.ts +++ b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/options.ts @@ -36,17 +36,18 @@ export async function normalizeOptions( ) { const workspaceRoot = context.workspaceRoot; const projectMetadata = await context.getProjectMetadata(projectName); - const projectRoot = path.join(workspaceRoot, (projectMetadata.root as string | undefined) ?? ''); - const projectSourceRoot = path.join( - workspaceRoot, - (projectMetadata.sourceRoot as string | undefined) ?? 'src', + const projectRoot = normalizeDirectoryPath( + path.join(workspaceRoot, (projectMetadata.root as string | undefined) ?? ''), + ); + const projectSourceRoot = normalizeDirectoryPath( + path.join(workspaceRoot, (projectMetadata.sourceRoot as string | undefined) ?? 'src'), ); const cacheOptions = normalizeCacheOptions(projectMetadata, workspaceRoot); const mainEntryPoint = path.join(workspaceRoot, options.main); const tsconfig = path.join(workspaceRoot, options.tsConfig); - const outputPath = path.join(workspaceRoot, options.outputPath); + const outputPath = normalizeDirectoryPath(path.join(workspaceRoot, options.outputPath)); const optimizationOptions = normalizeOptimization(options.optimization); const sourcemapOptions = normalizeSourceMaps(options.sourceMap ?? false); const assets = options.assets?.length @@ -222,3 +223,18 @@ function findTailwindConfigurationFile( return undefined; } + +/** + * Normalize a directory path string. + * Currently only removes a trailing slash if present. + * @param path A path string. + * @returns A normalized path string. + */ +function normalizeDirectoryPath(path: string): string { + const last = path[path.length - 1]; + if (last === '/' || last === '\\') { + return path.slice(0, -1); + } + + return path; +}