Skip to content

Commit 2b937db

Browse files
clydinangular-robot[bot]
authored andcommitted
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.
1 parent 8daf3a5 commit 2b937db

File tree

1 file changed

+21
-5
lines changed
  • packages/angular_devkit/build_angular/src/builders/browser-esbuild

1 file changed

+21
-5
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/options.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@ export async function normalizeOptions(
3636
) {
3737
const workspaceRoot = context.workspaceRoot;
3838
const projectMetadata = await context.getProjectMetadata(projectName);
39-
const projectRoot = path.join(workspaceRoot, (projectMetadata.root as string | undefined) ?? '');
40-
const projectSourceRoot = path.join(
41-
workspaceRoot,
42-
(projectMetadata.sourceRoot as string | undefined) ?? 'src',
39+
const projectRoot = normalizeDirectoryPath(
40+
path.join(workspaceRoot, (projectMetadata.root as string | undefined) ?? ''),
41+
);
42+
const projectSourceRoot = normalizeDirectoryPath(
43+
path.join(workspaceRoot, (projectMetadata.sourceRoot as string | undefined) ?? 'src'),
4344
);
4445

4546
const cacheOptions = normalizeCacheOptions(projectMetadata, workspaceRoot);
4647

4748
const mainEntryPoint = path.join(workspaceRoot, options.main);
4849
const tsconfig = path.join(workspaceRoot, options.tsConfig);
49-
const outputPath = path.join(workspaceRoot, options.outputPath);
50+
const outputPath = normalizeDirectoryPath(path.join(workspaceRoot, options.outputPath));
5051
const optimizationOptions = normalizeOptimization(options.optimization);
5152
const sourcemapOptions = normalizeSourceMaps(options.sourceMap ?? false);
5253
const assets = options.assets?.length
@@ -222,3 +223,18 @@ function findTailwindConfigurationFile(
222223

223224
return undefined;
224225
}
226+
227+
/**
228+
* Normalize a directory path string.
229+
* Currently only removes a trailing slash if present.
230+
* @param path A path string.
231+
* @returns A normalized path string.
232+
*/
233+
function normalizeDirectoryPath(path: string): string {
234+
const last = path[path.length - 1];
235+
if (last === '/' || last === '\\') {
236+
return path.slice(0, -1);
237+
}
238+
239+
return path;
240+
}

0 commit comments

Comments
 (0)